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; |
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; |
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, |
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')) |
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) { |
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 |
|
|
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 |
|
|
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=\""); |
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) { |
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 = { |