Magellan Linux

Diff of /tags/grubby-8_21/grubby.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1845 by niro, Mon Jul 2 12:59:39 2012 UTC revision 1846 by niro, Mon Jul 2 13:00:11 2012 UTC
# Line 243  const char *grub2FindConfig(struct confi Line 243  const char *grub2FindConfig(struct confi
243  }  }
244    
245  int sizeOfSingleLine(struct singleLine * line) {  int sizeOfSingleLine(struct singleLine * line) {
   int i;  
246    int count = 0;    int count = 0;
247    
248    for (i = 0; i < line->numElements; i++) {    for (int i = 0; i < line->numElements; i++) {
249      int indentSize = 0;      int indentSize = 0;
250    
251      count = count + strlen(line->elements[i].item);      count = count + strlen(line->elements[i].item);
# Line 573  static char * sdupprintf(const char *for Line 572  static char * sdupprintf(const char *for
572    
573  static struct keywordTypes * getKeywordByType(enum lineType_e type,  static struct keywordTypes * getKeywordByType(enum lineType_e type,
574        struct configFileInfo * cfi) {        struct configFileInfo * cfi) {
575      struct keywordTypes * kw;      for (struct keywordTypes *kw = cfi->keywords; kw->key; kw++) {
     for (kw = cfi->keywords; kw->key; kw++) {  
576   if (kw->type == type)   if (kw->type == type)
577      return kw;      return kw;
578      }      }
# Line 604  static char * getuuidbydev(char *device) Line 602  static char * getuuidbydev(char *device)
602    
603  static enum lineType_e getTypeByKeyword(char * keyword,  static enum lineType_e getTypeByKeyword(char * keyword,
604   struct configFileInfo * cfi) {   struct configFileInfo * cfi) {
605      struct keywordTypes * kw;      for (struct keywordTypes *kw = cfi->keywords; kw->key; kw++) {
     for (kw = cfi->keywords; kw->key; kw++) {  
606   if (!strcmp(keyword, kw->key))   if (!strcmp(keyword, kw->key))
607      return kw->type;      return kw->type;
608      }      }
# Line 692  static void lineInit(struct singleLine * Line 689  static void lineInit(struct singleLine *
689  }  }
690    
691  struct singleLine * lineDup(struct singleLine * line) {  struct singleLine * lineDup(struct singleLine * line) {
     int i;  
692      struct singleLine * newLine = malloc(sizeof(*newLine));      struct singleLine * newLine = malloc(sizeof(*newLine));
693    
694      newLine->indent = strdup(line->indent);      newLine->indent = strdup(line->indent);
# Line 702  struct singleLine * lineDup(struct singl Line 698  struct singleLine * lineDup(struct singl
698      newLine->elements = malloc(sizeof(*newLine->elements) *      newLine->elements = malloc(sizeof(*newLine->elements) *
699         newLine->numElements);         newLine->numElements);
700    
701      for (i = 0; i < newLine->numElements; i++) {      for (int i = 0; i < newLine->numElements; i++) {
702   newLine->elements[i].indent = strdup(line->elements[i].indent);   newLine->elements[i].indent = strdup(line->elements[i].indent);
703   newLine->elements[i].item = strdup(line->elements[i].item);   newLine->elements[i].item = strdup(line->elements[i].item);
704      }      }
# Line 711  struct singleLine * lineDup(struct singl Line 707  struct singleLine * lineDup(struct singl
707  }  }
708    
709  static void lineFree(struct singleLine * line) {  static void lineFree(struct singleLine * line) {
     int i;  
   
710      if (line->indent) free(line->indent);      if (line->indent) free(line->indent);
711    
712      for (i = 0; i < line->numElements; i++) {      for (int i = 0; i < line->numElements; i++) {
713   free(line->elements[i].item);   free(line->elements[i].item);
714   free(line->elements[i].indent);   free(line->elements[i].indent);
715      }      }
# Line 726  static void lineFree(struct singleLine * Line 720  static void lineFree(struct singleLine *
720    
721  static int lineWrite(FILE * out, struct singleLine * line,  static int lineWrite(FILE * out, struct singleLine * line,
722       struct configFileInfo * cfi) {       struct configFileInfo * cfi) {
     int i;  
   
723      if (fprintf(out, "%s", line->indent) == -1) return -1;      if (fprintf(out, "%s", line->indent) == -1) return -1;
724    
725      for (i = 0; i < line->numElements; i++) {      for (int i = 0; i < line->numElements; i++) {
726   /* Need to handle this, because we strip the quotes from   /* Need to handle this, because we strip the quotes from
727   * menuentry when read it. */   * menuentry when read it. */
728   if (line->type == LT_MENUENTRY && i == 1) {   if (line->type == LT_MENUENTRY && i == 1) {
# Line 836  static int getNextLine(char ** bufPtr, s Line 828  static int getNextLine(char ** bufPtr, s
828      if (*line->elements[0].item == '#') {      if (*line->elements[0].item == '#') {
829   char * fullLine;   char * fullLine;
830   int len;   int len;
  int i;  
831    
832   len = strlen(line->indent);   len = strlen(line->indent);
833   for (i = 0; i < line->numElements; i++)   for (int i = 0; i < line->numElements; i++)
834      len += strlen(line->elements[i].item) +      len += strlen(line->elements[i].item) +
835     strlen(line->elements[i].indent);     strlen(line->elements[i].indent);
836    
# Line 848  static int getNextLine(char ** bufPtr, s Line 839  static int getNextLine(char ** bufPtr, s
839   free(line->indent);   free(line->indent);
840   line->indent = fullLine;   line->indent = fullLine;
841    
842   for (i = 0; i < line->numElements; i++) {   for (int i = 0; i < line->numElements; i++) {
843      strcat(fullLine, line->elements[i].item);      strcat(fullLine, line->elements[i].item);
844      strcat(fullLine, line->elements[i].indent);      strcat(fullLine, line->elements[i].indent);
845      free(line->elements[i].item);      free(line->elements[i].item);
# Line 867  static int getNextLine(char ** bufPtr, s Line 858  static int getNextLine(char ** bufPtr, s
858   * elements up more   * elements up more
859   */   */
860   if (!isspace(kw->separatorChar)) {   if (!isspace(kw->separatorChar)) {
     int i;  
861      char indent[2] = "";      char indent[2] = "";
862      indent[0] = kw->separatorChar;      indent[0] = kw->separatorChar;
863      for (i = 1; i < line->numElements; i++) {      for (int i = 1; i < line->numElements; i++) {
864   char *p;   char *p;
  int j;  
865   int numNewElements;   int numNewElements;
866    
867   numNewElements = 0;   numNewElements = 0;
# Line 888  static int getNextLine(char ** bufPtr, s Line 877  static int getNextLine(char ** bufPtr, s
877      sizeof(*line->elements) * elementsAlloced);      sizeof(*line->elements) * elementsAlloced);
878   }   }
879    
880   for (j = line->numElements; j > i; j--) {   for (int j = line->numElements; j > i; j--) {
881   line->elements[j + numNewElements] = line->elements[j];   line->elements[j + numNewElements] = line->elements[j];
882   }   }
883   line->numElements += numNewElements;   line->numElements += numNewElements;
# Line 926  static struct grubConfig * readConfig(co Line 915  static struct grubConfig * readConfig(co
915      struct singleLine * last = NULL, * line, * defaultLine = NULL;      struct singleLine * last = NULL, * line, * defaultLine = NULL;
916      char * end;      char * end;
917      struct singleEntry * entry = NULL;      struct singleEntry * entry = NULL;
918      int i, len;      int len;
919      char * buf;      char * buf;
920    
921      if (!strcmp(inName, "-")) {      if (!strcmp(inName, "-")) {
# Line 989  static struct grubConfig * readConfig(co Line 978  static struct grubConfig * readConfig(co
978   }   }
979    
980   if (line->type == LT_SET_VARIABLE) {   if (line->type == LT_SET_VARIABLE) {
     int i;  
981      dbgPrintf("found 'set' command (%d elements): ", line->numElements);      dbgPrintf("found 'set' command (%d elements): ", line->numElements);
982      dbgPrintf("%s", line->indent);      dbgPrintf("%s", line->indent);
983      for (i = 0; i < line->numElements; i++)      for (int i = 0; i < line->numElements; i++)
984   dbgPrintf("\"%s\"%s", line->elements[i].item, line->elements[i].indent);   dbgPrintf("\"%s\"%s", line->elements[i].item, line->elements[i].indent);
985      dbgPrintf("\n");      dbgPrintf("\n");
986      struct keywordTypes *kwType = getKeywordByType(LT_DEFAULT, cfi);      struct keywordTypes *kwType = getKeywordByType(LT_DEFAULT, cfi);
# Line 1020  static struct grubConfig * readConfig(co Line 1008  static struct grubConfig * readConfig(co
1008       * This only applies to grub, but that's the only place we       * This only applies to grub, but that's the only place we
1009       * should find LT_MBMODULE lines anyway.       * should find LT_MBMODULE lines anyway.
1010       */       */
1011      struct singleLine * l;      for (struct singleLine *l = entry->lines; l; l = l->next) {
     for (l = entry->lines; l; l = l->next) {  
1012   if (l->type == LT_HYPER)   if (l->type == LT_HYPER)
1013      break;      break;
1014   else if (l->type == LT_KERNEL) {   else if (l->type == LT_KERNEL) {
# Line 1041  static struct grubConfig * readConfig(co Line 1028  static struct grubConfig * readConfig(co
1028   } else if (line->type == LT_TITLE && line->numElements > 1) {   } else if (line->type == LT_TITLE && line->numElements > 1) {
1029      /* make the title a single argument (undoing our parsing) */      /* make the title a single argument (undoing our parsing) */
1030      len = 0;      len = 0;
1031      for (i = 1; i < line->numElements; i++) {      for (int i = 1; i < line->numElements; i++) {
1032   len += strlen(line->elements[i].item);   len += strlen(line->elements[i].item);
1033   len += strlen(line->elements[i].indent);   len += strlen(line->elements[i].indent);
1034      }      }
1035      buf = malloc(len + 1);      buf = malloc(len + 1);
1036      *buf = '\0';      *buf = '\0';
1037    
1038      for (i = 1; i < line->numElements; i++) {      for (int i = 1; i < line->numElements; i++) {
1039   strcat(buf, line->elements[i].item);   strcat(buf, line->elements[i].item);
1040   free(line->elements[i].item);   free(line->elements[i].item);
1041    
# Line 1068  static struct grubConfig * readConfig(co Line 1055  static struct grubConfig * readConfig(co
1055      char *extras;      char *extras;
1056      char *title;      char *title;
1057    
1058      for (i = 1; i < line->numElements; i++) {      for (int i = 1; i < line->numElements; i++) {
1059   len += strlen(line->elements[i].item);   len += strlen(line->elements[i].item);
1060   len += strlen(line->elements[i].indent);   len += strlen(line->elements[i].indent);
1061      }      }
# Line 1080  static struct grubConfig * readConfig(co Line 1067  static struct grubConfig * readConfig(co
1067      *extras = '\0';      *extras = '\0';
1068    
1069      /* get title. */      /* get title. */
1070      for (i = 0; i < line->numElements; i++) {      for (int i = 0; i < line->numElements; i++) {
1071   if (!strcmp(line->elements[i].item, "menuentry"))   if (!strcmp(line->elements[i].item, "menuentry"))
1072      continue;      continue;
1073   if (isquote(*line->elements[i].item))   if (isquote(*line->elements[i].item))
# Line 1100  static struct grubConfig * readConfig(co Line 1087  static struct grubConfig * readConfig(co
1087    
1088      /* get extras */      /* get extras */
1089      int count = 0;      int count = 0;
1090      for (i = 0; i < line->numElements; i++) {      for (int i = 0; i < line->numElements; i++) {
1091   if (count >= 2) {   if (count >= 2) {
1092      strcat(extras, line->elements[i].item);      strcat(extras, line->elements[i].item);
1093      strcat(extras, line->elements[i].indent);      strcat(extras, line->elements[i].indent);
# Line 1221  static struct grubConfig * readConfig(co Line 1208  static struct grubConfig * readConfig(co
1208      cfg->defaultImage = strtol(defaultLine->elements[1].item, &end, 10);      cfg->defaultImage = strtol(defaultLine->elements[1].item, &end, 10);
1209      if (*end) cfg->defaultImage = -1;      if (*end) cfg->defaultImage = -1;
1210   } else if (defaultLine->numElements >= 2) {   } else if (defaultLine->numElements >= 2) {
1211      i = 0;      int i = 0;
1212      while ((entry = findEntryByIndex(cfg, i))) {      while ((entry = findEntryByIndex(cfg, i))) {
1213   for (line = entry->lines; line; line = line->next)   for (line = entry->lines; line; line = line->next)
1214      if (line->type == LT_TITLE) break;      if (line->type == LT_TITLE) break;

Legend:
Removed from v.1845  
changed lines
  Added in v.1846