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; |
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 */ |
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; |
1511 |
return cfg; |
return cfg; |
1512 |
} |
} |
1513 |
|
|
1514 |
static void writeDefault(FILE * out, char * indent, |
static void writeDefault(FILE * out, char * indent, |
1515 |
char * separator, struct grubConfig * cfg) { |
char * separator, struct grubConfig * cfg) { |
1516 |
struct singleEntry * entry; |
struct singleEntry * entry; |
1517 |
struct singleLine * line; |
struct singleLine * line; |
1518 |
int i; |
int i; |
1519 |
|
|
1520 |
if (!cfg->defaultImage && cfg->flags == GRUB_CONFIG_NO_DEFAULT) return; |
if (!cfg->defaultImage && cfg->flags == GRUB_CONFIG_NO_DEFAULT) |
1521 |
|
return; |
1522 |
|
|
1523 |
if (cfg->defaultImage == DEFAULT_SAVED) |
if (cfg->defaultImage == DEFAULT_SAVED) |
1524 |
fprintf(out, "%sdefault%ssaved\n", indent, separator); |
fprintf(out, "%sdefault%ssaved\n", indent, separator); |
1542 |
fprintf(out, "%sset default=\"%d\"\n", indent, |
fprintf(out, "%sset default=\"%d\"\n", indent, |
1543 |
cfg->defaultImage); |
cfg->defaultImage); |
1544 |
} else { |
} else { |
1545 |
fprintf(out, "%sdefault%s%d\n", indent, separator, |
fprintf(out, "%sdefault%s%d\n", indent, separator, |
1546 |
cfg->defaultImage); |
cfg->defaultImage); |
1547 |
} |
} |
1548 |
} else { |
} else { |
1549 |
int image = cfg->defaultImage; |
int image = cfg->defaultImage; |
1550 |
|
|
1551 |
entry = cfg->entries; |
entry = cfg->entries; |
1552 |
while (entry && entry->skip) entry = entry->next; |
while (entry && entry->skip) |
1553 |
|
entry = entry->next; |
1554 |
|
|
1555 |
i = 0; |
i = 0; |
1556 |
while (entry && i < image) { |
while (entry && i < image) { |
1557 |
entry = entry->next; |
entry = entry->next; |
1558 |
|
|
1559 |
while (entry && entry->skip) entry = entry->next; |
while (entry && entry->skip) |
1560 |
|
entry = entry->next; |
1561 |
i++; |
i++; |
1562 |
} |
} |
1563 |
|
|
1564 |
if (!entry) return; |
if (!entry) |
1565 |
|
return; |
1566 |
|
|
1567 |
line = getLineByType(LT_TITLE, entry->lines); |
line = getLineByType(LT_TITLE, entry->lines); |
1568 |
|
|
1569 |
if (line && line->numElements >= 2) |
if (line && line->numElements >= 2) |
1570 |
fprintf(out, "%sdefault%s%s\n", indent, separator, |
fprintf(out, "%sdefault%s%s\n", indent, separator, |
1571 |
line->elements[1].item); |
line->elements[1].item); |
1572 |
else if (line && (line->numElements == 1) && |
else if (line && (line->numElements == 1) && |
1573 |
cfg->cfi->titleBracketed) { |
cfg->cfi->titleBracketed) { |
1574 |
fprintf(out, "%sdefault%s%s\n", indent, separator, |
char *title = extractTitle(cfg, line); |
1575 |
extractTitle(cfg, line)); |
if (title) { |
1576 |
|
fprintf(out, "%sdefault%s%s\n", indent, separator, title); |
1577 |
|
free(title); |
1578 |
|
} |
1579 |
} |
} |
1580 |
} |
} |
1581 |
} |
} |
4658 |
struct singleLine * line; |
struct singleLine * line; |
4659 |
struct singleEntry * entry; |
struct singleEntry * entry; |
4660 |
|
|
4661 |
if (config->defaultImage == -1) return 0; |
if (config->defaultImage == -1) |
4662 |
|
return 0; |
4663 |
if (config->defaultImage == DEFAULT_SAVED_GRUB2 && |
if (config->defaultImage == DEFAULT_SAVED_GRUB2 && |
4664 |
cfi->defaultIsSaved) |
cfi->defaultIsSaved) |
4665 |
config->defaultImage = 0; |
config->defaultImage = 0; |
4666 |
entry = findEntryByIndex(config, config->defaultImage); |
entry = findEntryByIndex(config, config->defaultImage); |
4667 |
if (!entry) return 0; |
if (!entry) |
4668 |
|
return 0; |
4669 |
|
|
4670 |
if (!configureGrub2) { |
if (!configureGrub2) { |
4671 |
line = getLineByType(LT_TITLE, entry->lines); |
char *title; |
4672 |
if (!line) return 0; |
line = getLineByType(LT_TITLE, entry->lines); |
4673 |
printf("%s\n", line->elements[1].item); |
if (!line) |
4674 |
|
return 0; |
4675 |
|
title = extractTitle(config, line); |
4676 |
|
if (!title) |
4677 |
|
return 0; |
4678 |
|
printf("%s\n", title); |
4679 |
|
free(title); |
4680 |
} else { |
} else { |
4681 |
char * title; |
char * title; |
4682 |
|
|
4683 |
dbgPrintf("This is GRUB2, default title is embeded in menuentry\n"); |
dbgPrintf("This is GRUB2, default title is embeded in menuentry\n"); |
4684 |
line = getLineByType(LT_MENUENTRY, entry->lines); |
line = getLineByType(LT_MENUENTRY, entry->lines); |
4685 |
if (!line) return 0; |
if (!line) |
4686 |
title = grub2ExtractTitle(line); |
return 0; |
4687 |
if (title) |
title = grub2ExtractTitle(line); |
4688 |
printf("%s\n", title); |
if (title) |
4689 |
|
printf("%s\n", title); |
4690 |
} |
} |
4691 |
return 0; |
return 0; |
4692 |
|
|