241 |
return configFiles[i]; |
return configFiles[i]; |
242 |
} |
} |
243 |
|
|
244 |
|
int sizeOfSingleLine(struct singleLine * line) { |
245 |
|
int i; |
246 |
|
int count = 0; |
247 |
|
|
248 |
|
for (i = 0; i < line->numElements; i++) { |
249 |
|
int indentSize = 0; |
250 |
|
|
251 |
|
count = count + strlen(line->elements[i].item); |
252 |
|
|
253 |
|
indentSize = strlen(line->elements[i].indent); |
254 |
|
if (indentSize > 0) |
255 |
|
count = count + indentSize; |
256 |
|
else |
257 |
|
/* be extra safe and add room for whitespaces */ |
258 |
|
count = count + 1; |
259 |
|
} |
260 |
|
|
261 |
|
/* room for trailing terminator */ |
262 |
|
count = count + 1; |
263 |
|
|
264 |
|
return count; |
265 |
|
} |
266 |
|
|
267 |
|
char *grub2ExtractTitle(struct singleLine * line) { |
268 |
|
char * current; |
269 |
|
char * current_indent; |
270 |
|
int current_len; |
271 |
|
int current_indent_len; |
272 |
|
int i; |
273 |
|
|
274 |
|
/* bail out if line does not start with menuentry */ |
275 |
|
if (strcmp(line->elements[0].item, "menuentry")) |
276 |
|
return NULL; |
277 |
|
|
278 |
|
i = 1; |
279 |
|
current = line->elements[i].item; |
280 |
|
current_len = strlen(current); |
281 |
|
|
282 |
|
/* if second word is quoted, strip the quotes and return single word */ |
283 |
|
if ((*current == '\'') && (*(current + current_len - 1) == '\'')) { |
284 |
|
char *tmp; |
285 |
|
|
286 |
|
tmp = strdup(current); |
287 |
|
*(tmp + current_len - 1) = '\0'; |
288 |
|
return ++tmp; |
289 |
|
} |
290 |
|
|
291 |
|
/* if no quotes, return second word verbatim */ |
292 |
|
if (*current != '\'') { |
293 |
|
return current; |
294 |
|
} |
295 |
|
|
296 |
|
/* second element start with a quote, so we have to find the element |
297 |
|
* whose last character is also quote (assuming it's the closing one) */ |
298 |
|
if (*current == '\'') { |
299 |
|
int resultMaxSize; |
300 |
|
char * result; |
301 |
|
|
302 |
|
resultMaxSize = sizeOfSingleLine(line); |
303 |
|
result = malloc(resultMaxSize); |
304 |
|
snprintf(result, resultMaxSize, "%s", ++current); |
305 |
|
|
306 |
|
i++; |
307 |
|
for (; i < line->numElements; ++i) { |
308 |
|
current = line->elements[i].item; |
309 |
|
current_len = strlen(current); |
310 |
|
current_indent = line->elements[i].indent; |
311 |
|
current_indent_len = strlen(current_indent); |
312 |
|
|
313 |
|
strncat(result, current_indent, current_indent_len); |
314 |
|
if (*(current + current_len - 1) != '\'') { |
315 |
|
strncat(result, current, current_len); |
316 |
|
} else { |
317 |
|
strncat(result, current, current_len - 1); |
318 |
|
break; |
319 |
|
} |
320 |
|
} |
321 |
|
return result; |
322 |
|
} |
323 |
|
|
324 |
|
return NULL; |
325 |
|
} |
326 |
|
|
327 |
struct configFileInfo grub2ConfigType = { |
struct configFileInfo grub2ConfigType = { |
328 |
.findConfig = grub2FindConfig, |
.findConfig = grub2FindConfig, |
329 |
.keywords = grub2Keywords, |
.keywords = grub2Keywords, |
3660 |
printf("%s\n", line->elements[1].item); |
printf("%s\n", line->elements[1].item); |
3661 |
|
|
3662 |
} else { |
} else { |
3663 |
int i; |
char * title; |
|
size_t len; |
|
|
char * start; |
|
|
char * tmp; |
|
3664 |
|
|
3665 |
dbgPrintf("This is GRUB2, default title is embeded in menuentry\n"); |
dbgPrintf("This is GRUB2, default title is embeded in menuentry\n"); |
3666 |
line = getLineByType(LT_MENUENTRY, entry->lines); |
line = getLineByType(LT_MENUENTRY, entry->lines); |
3667 |
if (!line) return 0; |
if (!line) return 0; |
3668 |
|
title = grub2ExtractTitle(line); |
3669 |
for (i = 0; i < line->numElements; i++) { |
if (title) |
3670 |
|
printf("%s\n", title); |
|
if (!strcmp(line->elements[i].item, "menuentry")) |
|
|
continue; |
|
|
|
|
|
if (*line->elements[i].item == '\'') |
|
|
start = line->elements[i].item + 1; |
|
|
else |
|
|
start = line->elements[i].item; |
|
|
|
|
|
len = strlen(start); |
|
|
if (*(start + len - 1) == '\'') { |
|
|
tmp = strdup(start); |
|
|
*(tmp + len - 1) = '\0'; |
|
|
printf("%s", tmp); |
|
|
free(tmp); |
|
|
break; |
|
|
} else { |
|
|
printf("%s ", start); |
|
|
} |
|
|
} |
|
|
printf("\n"); |
|
3671 |
} |
} |
3672 |
return 0; |
return 0; |
3673 |
|
|