Magellan Linux

Diff of /trunk/grubby/grubby.c

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

revision 1800 by niro, Mon Apr 16 17:46:40 2012 UTC revision 1801 by niro, Mon Apr 16 17:48:10 2012 UTC
# Line 731  static int lineWrite(FILE * out, struct Line 731  static int lineWrite(FILE * out, struct
731      if (fprintf(out, "%s", line->indent) == -1) return -1;      if (fprintf(out, "%s", line->indent) == -1) return -1;
732    
733      for (i = 0; i < line->numElements; i++) {      for (i = 0; i < line->numElements; i++) {
734     /* Need to handle this, because we strip the quotes from
735     * menuentry when read it. */
736     if (line->type == LT_MENUENTRY && i == 1) {
737        if(!isquote(*line->elements[i].item))
738     fprintf(out, "\'%s\'", line->elements[i].item);
739        else
740     fprintf(out, "%s", line->elements[i].item);
741        fprintf(out, "%s", line->elements[i].indent);
742    
743        continue;
744     }
745    
746   if (i == 1 && line->type == LT_KERNELARGS && cfi->argsInQuotes)   if (i == 1 && line->type == LT_KERNELARGS && cfi->argsInQuotes)
747      if (fputc('"', out) == EOF) return -1;      if (fputc('"', out) == EOF) return -1;
748    
# Line 1052  static struct grubConfig * readConfig(co Line 1064  static struct grubConfig * readConfig(co
1064      line->elements[line->numElements - 1].indent;      line->elements[line->numElements - 1].indent;
1065      line->elements[1].item = buf;      line->elements[1].item = buf;
1066      line->numElements = 2;      line->numElements = 2;
1067     } else if (line->type == LT_MENUENTRY && line->numElements > 3) {
1068        /* let --remove-kernel="TITLE=what" work */
1069        len = 0;
1070        char *extras;
1071        char *title;
1072    
1073        for (i = 1; i < line->numElements; i++) {
1074     len += strlen(line->elements[i].item);
1075     len += strlen(line->elements[i].indent);
1076        }
1077        buf = malloc(len + 1);
1078        *buf = '\0';
1079    
1080        /* allocate mem for extra flags. */
1081        extras = malloc(len + 1);
1082        *extras = '\0';
1083    
1084        /* get title. */
1085        for (i = 0; i < line->numElements; i++) {
1086     if (!strcmp(line->elements[i].item, "menuentry"))
1087        continue;
1088     if (isquote(*line->elements[i].item))
1089        title = line->elements[i].item + 1;
1090     else
1091        title = line->elements[i].item;
1092    
1093     len = strlen(title);
1094            if (isquote(title[len-1])) {
1095        strncat(buf, title,len-1);
1096        break;
1097     } else {
1098        strcat(buf, title);
1099        strcat(buf, line->elements[i].indent);
1100     }
1101        }
1102    
1103        /* get extras */
1104        int count = 0;
1105        for (i = 0; i < line->numElements; i++) {
1106     if (count == 2) {
1107        strcat(extras, line->elements[i].item);
1108        strcat(extras, line->elements[i].indent);
1109     }
1110    
1111     if (!strcmp(line->elements[i].item, "menuentry"))
1112        continue;
1113    
1114     /* count ' or ", there should be two in menuentry line. */
1115     if (isquote(*line->elements[i].item))
1116        count++;
1117    
1118     len = strlen(line->elements[i].item);
1119    
1120     if (isquote(line->elements[i].item[len -1]))
1121        count++;
1122    
1123     /* ok, we get the final ' or ", others are extras. */
1124                }
1125        line->elements[1].indent =
1126     line->elements[line->numElements - 2].indent;
1127        line->elements[1].item = buf;
1128        line->elements[2].indent =
1129     line->elements[line->numElements - 2].indent;
1130        line->elements[2].item = extras;
1131        line->numElements = 3;
1132   } else if (line->type == LT_KERNELARGS && cfi->argsInQuotes) {   } else if (line->type == LT_KERNELARGS && cfi->argsInQuotes) {
1133      /* Strip off any " which may be present; they'll be put back      /* Strip off any " which may be present; they'll be put back
1134         on write. This is one of the few (the only?) places that grubby         on write. This is one of the few (the only?) places that grubby
# Line 1061  static struct grubConfig * readConfig(co Line 1137  static struct grubConfig * readConfig(co
1137      if (line->numElements >= 2) {      if (line->numElements >= 2) {
1138   int last, len;   int last, len;
1139    
1140   if (*line->elements[1].item == '"')   if (isquote(*line->elements[1].item))
1141      memmove(line->elements[1].item, line->elements[1].item + 1,      memmove(line->elements[1].item, line->elements[1].item + 1,
1142      strlen(line->elements[1].item + 1) + 1);      strlen(line->elements[1].item + 1) + 1);
1143    
1144   last = line->numElements - 1;   last = line->numElements - 1;
1145   len = strlen(line->elements[last].item) - 1;   len = strlen(line->elements[last].item) - 1;
1146   if (line->elements[last].item[len] == '"')   if (isquote(line->elements[last].item[len]))
1147      line->elements[last].item[len] = '\0';      line->elements[last].item[len] = '\0';
1148      }      }
1149   }   }
# Line 1439  void printEntry(struct singleEntry * ent Line 1515  void printEntry(struct singleEntry * ent
1515      for (line = entry->lines; line; line = line->next) {      for (line = entry->lines; line; line = line->next) {
1516   fprintf(stderr, "DBG: %s", line->indent);   fprintf(stderr, "DBG: %s", line->indent);
1517   for (i = 0; i < line->numElements; i++) {   for (i = 0; i < line->numElements; i++) {
1518   fprintf(stderr, "%s%s",      /* Need to handle this, because we strip the quotes from
1519         * menuentry when read it. */
1520        if (line->type == LT_MENUENTRY && i == 1) {
1521     if(!isquote(*line->elements[i].item))
1522        fprintf(stderr, "\'%s\'", line->elements[i].item);
1523     else
1524        fprintf(stderr, "%s", line->elements[i].item);
1525     fprintf(stderr, "%s", line->elements[i].indent);
1526    
1527     continue;
1528        }
1529        
1530        fprintf(stderr, "%s%s",
1531      line->elements[i].item, line->elements[i].indent);      line->elements[i].item, line->elements[i].indent);
1532   }   }
1533   fprintf(stderr, "\n");   fprintf(stderr, "\n");
# Line 1655  struct singleEntry * findEntryByPath(str Line 1743  struct singleEntry * findEntryByPath(str
1743    
1744   if (!strncmp(kernel, "TITLE=", 6)) {   if (!strncmp(kernel, "TITLE=", 6)) {
1745      prefix = "";      prefix = "";
1746      checkType = LT_TITLE;      checkType = LT_TITLE|LT_MENUENTRY;
1747      kernel += 6;      kernel += 6;
1748   }   }
1749    
# Line 1671  struct singleEntry * findEntryByPath(str Line 1759  struct singleEntry * findEntryByPath(str
1759       checkType, line);       checkType, line);
1760   if (!line) break;  /* not found in this entry */   if (!line) break;  /* not found in this entry */
1761    
1762   if (line && line->numElements >= 2) {   if (line && line->type != LT_MENUENTRY &&
1763     line->numElements >= 2) {
1764      rootspec = getRootSpecifier(line->elements[1].item);      rootspec = getRootSpecifier(line->elements[1].item);
1765      if (!strcmp(line->elements[1].item +      if (!strcmp(line->elements[1].item +
1766   ((rootspec != NULL) ? strlen(rootspec) : 0),   ((rootspec != NULL) ? strlen(rootspec) : 0),
1767   kernel + strlen(prefix)))   kernel + strlen(prefix)))
1768   break;   break;
1769   }   }
1770     if(line->type == LT_MENUENTRY &&
1771     !strcmp(line->elements[1].item, kernel))
1772        break;
1773      }      }
1774    
1775      /* make sure this entry has a kernel identifier; this skips      /* make sure this entry has a kernel identifier; this skips
# Line 1769  void markRemovedImage(struct grubConfig Line 1861  void markRemovedImage(struct grubConfig
1861        const char * prefix) {        const char * prefix) {
1862      struct singleEntry * entry;      struct singleEntry * entry;
1863    
1864      if (!image) return;      if (!image)
1865     return;
1866    
1867        /* check and see if we're removing the default image */
1868        if (isdigit(*image)) {
1869     entry = findEntryByPath(cfg, image, prefix, NULL);
1870     if(entry)
1871        entry->skip = 1;
1872     return;
1873        }
1874    
1875      while ((entry = findEntryByPath(cfg, image, prefix, NULL)))      while ((entry = findEntryByPath(cfg, image, prefix, NULL)))
1876   entry->skip = 1;   entry->skip = 1;

Legend:
Removed from v.1800  
changed lines
  Added in v.1801