Magellan Linux

Diff of /trunk/grubby/grubby.c

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

revision 2991 by niro, Thu Jun 30 10:34:31 2016 UTC revision 2992 by niro, Thu Jun 30 10:35:14 2016 UTC
# Line 429  char *grub2ExtractTitle(struct singleLin Line 429  char *grub2ExtractTitle(struct singleLin
429    
430      /* bail out if line does not start with menuentry */      /* bail out if line does not start with menuentry */
431      if (strcmp(line->elements[0].item, "menuentry"))      if (strcmp(line->elements[0].item, "menuentry"))
432        return NULL;   return NULL;
433    
434      i = 1;      i = 1;
435      current = line->elements[i].item;      current = line->elements[i].item;
# Line 438  char *grub2ExtractTitle(struct singleLin Line 438  char *grub2ExtractTitle(struct singleLin
438      /* if second word is quoted, strip the quotes and return single word */      /* if second word is quoted, strip the quotes and return single word */
439      if (isquote(*current) && isquote(current[current_len - 1])) {      if (isquote(*current) && isquote(current[current_len - 1])) {
440   char *tmp;   char *tmp;
441    
442   tmp = strdup(current);   tmp = strdup(current+1);
443   *(tmp + current_len - 1) = '\0';   if (!tmp)
444   return ++tmp;      return NULL;
445     tmp[strlen(tmp)-1] = '\0';
446     return tmp;
447      }      }
448    
449      /* if no quotes, return second word verbatim */      /* if no quotes, return second word verbatim */
# Line 454  char *grub2ExtractTitle(struct singleLin Line 456  char *grub2ExtractTitle(struct singleLin
456      char * result;      char * result;
457      /* need to ensure that ' does not match " as we search */      /* need to ensure that ' does not match " as we search */
458      char quote_char = *current;      char quote_char = *current;
459        
460      resultMaxSize = sizeOfSingleLine(line);      resultMaxSize = sizeOfSingleLine(line);
461      result = malloc(resultMaxSize);      result = malloc(resultMaxSize);
462      snprintf(result, resultMaxSize, "%s", ++current);      snprintf(result, resultMaxSize, "%s", ++current);
463        
464      i++;      i++;
465      for (; i < line->numElements; ++i) {      for (; i < line->numElements; ++i) {
466   current = line->elements[i].item;   current = line->elements[i].item;
# Line 4649  int main(int argc, const char ** argv) { Line 4651  int main(int argc, const char ** argv) {
4651   struct singleLine * line;   struct singleLine * line;
4652   struct singleEntry * entry;   struct singleEntry * entry;
4653    
4654   if (config->defaultImage == -1) return 0;   if (config->defaultImage == -1)
4655        return 0;
4656   if (config->defaultImage == DEFAULT_SAVED_GRUB2 &&   if (config->defaultImage == DEFAULT_SAVED_GRUB2 &&
4657   cfi->defaultIsSaved)   cfi->defaultIsSaved)
4658      config->defaultImage = 0;      config->defaultImage = 0;
4659   entry = findEntryByIndex(config, config->defaultImage);   entry = findEntryByIndex(config, config->defaultImage);
4660   if (!entry) return 0;   if (!entry)
4661     return 0;
4662    
4663   if (!configureGrub2) {   if (!configureGrub2) {
4664    line = getLineByType(LT_TITLE, entry->lines);      char *title;
4665    if (!line) return 0;      line = getLineByType(LT_TITLE, entry->lines);
4666    printf("%s\n", line->elements[1].item);      if (!line)
4667     return 0;
4668        title = extractTitle(config, line);
4669        if (!title)
4670     return 0;
4671        printf("%s\n", title);
4672        free(title);
4673   } else {   } else {
4674    char * title;      char * title;
4675    
4676    dbgPrintf("This is GRUB2, default title is embeded in menuentry\n");      dbgPrintf("This is GRUB2, default title is embeded in menuentry\n");
4677    line = getLineByType(LT_MENUENTRY, entry->lines);      line = getLineByType(LT_MENUENTRY, entry->lines);
4678    if (!line) return 0;      if (!line)
4679    title = grub2ExtractTitle(line);   return 0;
4680    if (title)      title = grub2ExtractTitle(line);
4681      printf("%s\n", title);      if (title)
4682     printf("%s\n", title);
4683   }   }
4684   return 0;   return 0;
4685    

Legend:
Removed from v.2991  
changed lines
  Added in v.2992