--- trunk/grubby/grubby.c 2012/02/18 01:06:48 1747 +++ trunk/grubby/grubby.c 2012/04/16 17:46:40 1800 @@ -114,6 +114,7 @@ #define MAIN_DEFAULT (1 << 0) #define DEFAULT_SAVED -2 +#define DEFAULT_SAVED_GRUB2 -3 struct keywordTypes { char * key; @@ -264,6 +265,13 @@ return count; } +static int isquote(char q) +{ + if (q == '\'' || q == '\"') + return 1; + return 0; +} + char *grub2ExtractTitle(struct singleLine * line) { char * current; char * current_indent; @@ -280,55 +288,50 @@ current_len = strlen(current); /* if second word is quoted, strip the quotes and return single word */ - if ((*current == '\'') && (*(current + current_len - 1) == '\'')) { - char *tmp; - - tmp = strdup(current); - *(tmp + current_len - 1) = '\0'; - return ++tmp; + if (isquote(*current) && isquote(current[current_len - 1])) { + char *tmp; + + tmp = strdup(current); + *(tmp + current_len - 1) = '\0'; + return ++tmp; } /* if no quotes, return second word verbatim */ - if (*current != '\'') { - return current; - } + if (!isquote(*current)) + return current; /* second element start with a quote, so we have to find the element * whose last character is also quote (assuming it's the closing one) */ - if (*current == '\'') { - int resultMaxSize; - char * result; - - resultMaxSize = sizeOfSingleLine(line); - result = malloc(resultMaxSize); - snprintf(result, resultMaxSize, "%s", ++current); - - i++; - for (; i < line->numElements; ++i) { + int resultMaxSize; + char * result; + + resultMaxSize = sizeOfSingleLine(line); + result = malloc(resultMaxSize); + snprintf(result, resultMaxSize, "%s", ++current); + + i++; + for (; i < line->numElements; ++i) { current = line->elements[i].item; current_len = strlen(current); current_indent = line->elements[i].indent; current_indent_len = strlen(current_indent); strncat(result, current_indent, current_indent_len); - if (*(current + current_len - 1) != '\'') { - strncat(result, current, current_len); + if (!isquote(current[current_len-1])) { + strncat(result, current, current_len); } else { - strncat(result, current, current_len - 1); - break; + strncat(result, current, current_len - 1); + break; } - } - return result; } - - return NULL; + return result; } struct configFileInfo grub2ConfigType = { .findConfig = grub2FindConfig, .keywords = grub2Keywords, .defaultIsIndex = 1, - .defaultSupportSaved = 0, + .defaultSupportSaved = 1, .defaultIsVariable = 1, .entryStart = LT_MENUENTRY, .entryEnd = LT_ENTRY_END, @@ -1123,7 +1126,11 @@ dbgPrintf("defaultLine is %s\n", defaultLine ? "set" : "unset"); if (defaultLine) { - if (cfi->defaultIsVariable) { + if (defaultLine->numElements > 2 && + cfi->defaultSupportSaved && + !strncmp(defaultLine->elements[2].item,"\"${saved_entry}\"", 16)) { + cfg->defaultImage = DEFAULT_SAVED_GRUB2; + } else if (cfi->defaultIsVariable) { char *value = defaultLine->elements[2].item; while (*value && (*value == '"' || *value == '\'' || *value == ' ' || *value == '\t')) @@ -1180,6 +1187,8 @@ if (cfg->defaultImage == DEFAULT_SAVED) fprintf(out, "%sdefault%ssaved\n", indent, separator); + else if (cfg->defaultImage == DEFAULT_SAVED_GRUB2) + fprintf(out, "%sset default=\"${saved_entry}\"\n", indent); else if (cfg->defaultImage > -1) { if (cfg->cfi->defaultIsIndex) { if (cfg->cfi->defaultIsVariable) { @@ -1457,7 +1466,7 @@ { int slen; - if (!s && !s[0]) + if (!s || !s[0]) return 0; slen = strlen(s) - 1; @@ -1787,7 +1796,8 @@ /* defaultImage now points to what we'd like to use, but before any order changes */ - if (config->defaultImage == DEFAULT_SAVED) + if ((config->defaultImage == DEFAULT_SAVED) || + (config->defaultImage == DEFAULT_SAVED_GRUB2)) /* default is set to saved, we don't want to change it */ return; @@ -1918,6 +1928,17 @@ printf("%s%s", line->elements[i].item, line->elements[i].indent); printf("\n"); } + + line = getLineByType(LT_TITLE, entry->lines); + if (line) { + printf("title=%s\n", line->elements[1].item); + } else { + char * title; + line = getLineByType(LT_MENUENTRY, entry->lines); + title = grub2ExtractTitle(line); + if (title) + printf("title=%s\n", title); + } } int parseSysconfigGrub(int * lbaPtr, char ** bootPtr) { @@ -2172,13 +2193,6 @@ free(line); } -static int isquote(char q) -{ - if (q == '\'' || q == '\"') - return 1; - return 0; -} - static void requote(struct singleLine *tmplLine, struct configFileInfo * cfi) { struct singleLine newLine = {