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>
26 #include <grub/misc.h>
27 #include <grub/i18n.h>
30 main (int argc, char **argv)
33 char *entryname = NULL;
36 char *suffix = xstrdup ("");
38 const char *out_fname = 0;
40 grub_util_host_init (&argc, &argv);
42 if (argc >= 2 && argv[1][0] == '-')
44 fprintf (stdout, _("Usage: %s [INFILE [OUTFILE]]\n"), argv[0]);
50 in = grub_util_fopen (argv[1], "r");
53 fprintf (stderr, _("cannot open `%s': %s"),
54 argv[1], strerror (errno));
63 out = grub_util_fopen (argv[2], "w");
68 fprintf (stderr, _("cannot open `%s': %s"),
69 argv[2], strerror (errno));
81 if (getline (&buf, &bufsize, in) < 0)
89 parsed = grub_legacy_parse (buf, &entryname, &newsuffix);
92 suffixlen += strlen (newsuffix);
93 suffix = xrealloc (suffix, suffixlen + 1);
94 strcat (suffix, newsuffix);
96 if (oldname != entryname && oldname)
97 fprintf (out, "}\n\n");
98 if (oldname != entryname)
100 char *escaped = grub_legacy_escape (entryname, strlen (entryname));
101 fprintf (out, "menuentry \'%s\' {\n", escaped);
108 fprintf (out, "%s%s", entryname ? " " : "", parsed);
114 fprintf (out, "}\n\n");
116 if (fwrite (suffix, 1, suffixlen, out) != suffixlen)
119 grub_util_error ("cannot write to `%s': %s",
120 out_fname, strerror (errno));
122 grub_util_error ("cannot write to the stdout: %s", strerror (errno));