Magellan Linux

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

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

revision 1746 by niro, Sat Feb 18 01:06:20 2012 UTC revision 1800 by niro, Mon Apr 16 17:46:40 2012 UTC
# Line 114  struct singleEntry { Line 114  struct singleEntry {
114    
115  #define MAIN_DEFAULT    (1 << 0)  #define MAIN_DEFAULT    (1 << 0)
116  #define DEFAULT_SAVED       -2  #define DEFAULT_SAVED       -2
117    #define DEFAULT_SAVED_GRUB2 -3
118    
119  struct keywordTypes {  struct keywordTypes {
120      char * key;      char * key;
# Line 264  int sizeOfSingleLine(struct singleLine * Line 265  int sizeOfSingleLine(struct singleLine *
265    return count;    return count;
266  }  }
267    
268    static int isquote(char q)
269    {
270        if (q == '\'' || q == '\"')
271     return 1;
272        return 0;
273    }
274    
275  char *grub2ExtractTitle(struct singleLine * line) {  char *grub2ExtractTitle(struct singleLine * line) {
276      char * current;      char * current;
277      char * current_indent;      char * current_indent;
# Line 280  char *grub2ExtractTitle(struct singleLin Line 288  char *grub2ExtractTitle(struct singleLin
288      current_len = strlen(current);      current_len = strlen(current);
289    
290      /* if second word is quoted, strip the quotes and return single word */      /* if second word is quoted, strip the quotes and return single word */
291      if ((*current == '\'') && (*(current + current_len - 1) == '\'')) {      if (isquote(*current) && isquote(current[current_len - 1])) {
292        char *tmp;   char *tmp;
293    
294        tmp = strdup(current);   tmp = strdup(current);
295        *(tmp + current_len - 1) = '\0';   *(tmp + current_len - 1) = '\0';
296        return ++tmp;   return ++tmp;
297      }      }
298    
299      /* if no quotes, return second word verbatim */      /* if no quotes, return second word verbatim */
300      if (*current != '\'') {      if (!isquote(*current))
301        return current;   return current;
     }  
302    
303      /* second element start with a quote, so we have to find the element      /* second element start with a quote, so we have to find the element
304       * whose last character is also quote (assuming it's the closing one) */       * whose last character is also quote (assuming it's the closing one) */
305      if (*current == '\'') {      int resultMaxSize;
306        int resultMaxSize;      char * result;
307        char * result;      
308        resultMaxSize = sizeOfSingleLine(line);
309        resultMaxSize = sizeOfSingleLine(line);      result = malloc(resultMaxSize);
310        result = malloc(resultMaxSize);      snprintf(result, resultMaxSize, "%s", ++current);
311        snprintf(result, resultMaxSize, "%s", ++current);      
312        i++;
313        i++;      for (; i < line->numElements; ++i) {
       for (; i < line->numElements; ++i) {  
314   current = line->elements[i].item;   current = line->elements[i].item;
315   current_len = strlen(current);   current_len = strlen(current);
316   current_indent = line->elements[i].indent;   current_indent = line->elements[i].indent;
317   current_indent_len = strlen(current_indent);   current_indent_len = strlen(current_indent);
318    
319   strncat(result, current_indent, current_indent_len);   strncat(result, current_indent, current_indent_len);
320   if (*(current + current_len - 1) != '\'') {   if (!isquote(current[current_len-1])) {
321    strncat(result, current, current_len);      strncat(result, current, current_len);
322   } else {   } else {
323    strncat(result, current, current_len - 1);      strncat(result, current, current_len - 1);
324    break;      break;
325   }   }
       }  
       return result;  
326      }      }
327        return result;
     return NULL;  
328  }  }
329    
330  struct configFileInfo grub2ConfigType = {  struct configFileInfo grub2ConfigType = {
331      .findConfig = grub2FindConfig,      .findConfig = grub2FindConfig,
332      .keywords = grub2Keywords,      .keywords = grub2Keywords,
333      .defaultIsIndex = 1,      .defaultIsIndex = 1,
334      .defaultSupportSaved = 0,      .defaultSupportSaved = 1,
335      .defaultIsVariable = 1,      .defaultIsVariable = 1,
336      .entryStart = LT_MENUENTRY,      .entryStart = LT_MENUENTRY,
337      .entryEnd = LT_ENTRY_END,      .entryEnd = LT_ENTRY_END,
# Line 1123  static struct grubConfig * readConfig(co Line 1126  static struct grubConfig * readConfig(co
1126    
1127      dbgPrintf("defaultLine is %s\n", defaultLine ? "set" : "unset");      dbgPrintf("defaultLine is %s\n", defaultLine ? "set" : "unset");
1128      if (defaultLine) {      if (defaultLine) {
1129   if (cfi->defaultIsVariable) {          if (defaultLine->numElements > 2 &&
1130        cfi->defaultSupportSaved &&
1131        !strncmp(defaultLine->elements[2].item,"\"${saved_entry}\"", 16)) {
1132        cfg->defaultImage = DEFAULT_SAVED_GRUB2;
1133     } else if (cfi->defaultIsVariable) {
1134      char *value = defaultLine->elements[2].item;      char *value = defaultLine->elements[2].item;
1135      while (*value && (*value == '"' || *value == '\'' ||      while (*value && (*value == '"' || *value == '\'' ||
1136      *value == ' ' || *value == '\t'))      *value == ' ' || *value == '\t'))
# Line 1180  static void writeDefault(FILE * out, cha Line 1187  static void writeDefault(FILE * out, cha
1187    
1188      if (cfg->defaultImage == DEFAULT_SAVED)      if (cfg->defaultImage == DEFAULT_SAVED)
1189   fprintf(out, "%sdefault%ssaved\n", indent, separator);   fprintf(out, "%sdefault%ssaved\n", indent, separator);
1190        else if (cfg->defaultImage == DEFAULT_SAVED_GRUB2)
1191     fprintf(out, "%sset default=\"${saved_entry}\"\n", indent);
1192      else if (cfg->defaultImage > -1) {      else if (cfg->defaultImage > -1) {
1193   if (cfg->cfi->defaultIsIndex) {   if (cfg->cfi->defaultIsIndex) {
1194      if (cfg->cfi->defaultIsVariable) {      if (cfg->cfi->defaultIsVariable) {
# Line 1457  static int endswith(const char *s, char Line 1466  static int endswith(const char *s, char
1466  {  {
1467   int slen;   int slen;
1468    
1469   if (!s && !s[0])   if (!s || !s[0])
1470   return 0;   return 0;
1471   slen = strlen(s) - 1;   slen = strlen(s) - 1;
1472    
# Line 1787  void setDefaultImage(struct grubConfig * Line 1796  void setDefaultImage(struct grubConfig *
1796    
1797      /* defaultImage now points to what we'd like to use, but before any order      /* defaultImage now points to what we'd like to use, but before any order
1798         changes */         changes */
1799      if (config->defaultImage == DEFAULT_SAVED)      if ((config->defaultImage == DEFAULT_SAVED) ||
1800     (config->defaultImage == DEFAULT_SAVED_GRUB2))
1801        /* default is set to saved, we don't want to change it */        /* default is set to saved, we don't want to change it */
1802        return;        return;
1803    
# Line 1854  void displayEntry(struct singleEntry * e Line 1864  void displayEntry(struct singleEntry * e
1864          return;          return;
1865      }      }
1866    
1867      printf("kernel=%s\n", line->elements[1].item);      printf("kernel=%s%s\n", prefix, line->elements[1].item);
1868    
1869      if (line->numElements >= 3) {      if (line->numElements >= 3) {
1870   printf("args=\"");   printf("args=\"");
# Line 1918  void displayEntry(struct singleEntry * e Line 1928  void displayEntry(struct singleEntry * e
1928      printf("%s%s", line->elements[i].item, line->elements[i].indent);      printf("%s%s", line->elements[i].item, line->elements[i].indent);
1929   printf("\n");   printf("\n");
1930      }      }
1931    
1932        line = getLineByType(LT_TITLE, entry->lines);
1933        if (line) {
1934     printf("title=%s\n", line->elements[1].item);
1935        } else {
1936     char * title;
1937     line = getLineByType(LT_MENUENTRY, entry->lines);
1938     title = grub2ExtractTitle(line);
1939     if (title)
1940        printf("title=%s\n", title);
1941        }
1942  }  }
1943    
1944  int parseSysconfigGrub(int * lbaPtr, char ** bootPtr) {  int parseSysconfigGrub(int * lbaPtr, char ** bootPtr) {
# Line 2172  void removeLine(struct singleEntry * ent Line 2193  void removeLine(struct singleEntry * ent
2193      free(line);      free(line);
2194  }  }
2195    
 static int isquote(char q)  
 {  
     if (q == '\'' || q == '\"')  
  return 1;  
     return 0;  
 }  
   
2196  static void requote(struct singleLine *tmplLine, struct configFileInfo * cfi)  static void requote(struct singleLine *tmplLine, struct configFileInfo * cfi)
2197  {  {
2198      struct singleLine newLine = {      struct singleLine newLine = {

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