2
* GRUB -- GRand Unified Bootloader
3
* Copyright (C) 2010 Free Software Foundation, Inc.
5
* GRUB is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* GRUB is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
21
#include <grub/legacy_parse.h>
25
#include <grub/util/misc.h>
28
main (int argc, char **argv)
31
char *entryname = NULL;
34
char *suffix = xstrdup ("");
37
if (argc >= 2 && argv[1][0] == '-')
39
fprintf (stdout, "Usage: %s [INFILE [OUTFILE]]\n", argv[0]);
45
in = fopen (argv[1], "r");
48
fprintf (stderr, "Couldn't open %s for reading: %s\n",
49
argv[1], strerror (errno));
58
out = fopen (argv[2], "w");
63
fprintf (stderr, "Couldn't open %s for writing: %s\n",
64
argv[2], strerror (errno));
75
if (getline (&buf, &bufsize, in) < 0)
83
parsed = grub_legacy_parse (buf, &entryname, &newsuffix);
86
suffixlen += strlen (newsuffix);
87
suffix = xrealloc (suffix, suffixlen + 1);
88
strcat (suffix, newsuffix);
90
if (oldname != entryname && oldname)
91
fprintf (out, "}\n\n");
92
if (oldname != entryname)
94
char *escaped = grub_legacy_escape (entryname, strlen (entryname));
95
fprintf (out, "menuentry \'%s\' {\n", escaped);
102
fprintf (out, "%s%s", entryname ? " " : "", parsed);
108
fprintf (out, "}\n\n");
110
fwrite (suffix, 1, suffixlen, out);