~ubuntu-branches/ubuntu/trusty/grub2/trusty-updates

« back to all changes in this revision

Viewing changes to util/grub-menulst2cfg.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-09-13 18:02:04 UTC
  • mfrom: (1.17.15 upstream)
  • mto: (17.6.27 experimental)
  • mto: This revision was merged to the branch mainline in revision 145.
  • Revision ID: package-import@ubuntu.com-20120913180204-mojnmocbimlom4im
Tags: upstream-2.00
ImportĀ upstreamĀ versionĀ 2.00

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <errno.h>
25
25
#include <grub/util/misc.h>
26
26
#include <grub/misc.h>
 
27
#include <grub/i18n.h>
27
28
 
28
29
int
29
30
main (int argc, char **argv)
34
35
  size_t bufsize = 0;
35
36
  char *suffix = xstrdup ("");
36
37
  int suffixlen = 0;
 
38
  const char *out_fname = 0;
37
39
 
38
40
  if (argc >= 2 && argv[1][0] == '-')
39
41
    {
40
 
      fprintf (stdout, "Usage: %s [INFILE [OUTFILE]]\n", argv[0]);
 
42
      fprintf (stdout, _("Usage: %s [INFILE [OUTFILE]]\n"), argv[0]);
41
43
      return 0;
42
44
    }
43
45
 
46
48
      in = fopen (argv[1], "r");
47
49
      if (!in)
48
50
        {
49
 
          fprintf (stderr, "Couldn't open %s for reading: %s\n",
 
51
          fprintf (stderr, _("cannot open `%s': %s"),
50
52
                   argv[1], strerror (errno));
51
53
          return 1;
52
54
        }
61
63
        {                                       
62
64
          if (in != stdin)
63
65
            fclose (in);
64
 
          fprintf (stderr, "Couldn't open %s for writing: %s\n",
 
66
          fprintf (stderr, _("cannot open `%s': %s"),
65
67
                   argv[2], strerror (errno));
66
68
          return 1;
67
69
        }
 
70
      out_fname = argv[2];
68
71
    }
69
72
  else
70
73
    out = stdout;
79
82
      {
80
83
        char *oldname = NULL;
81
84
        char *newsuffix;
82
 
        char *ptr;
83
 
 
84
 
        for (ptr = buf; *ptr && grub_isspace (*ptr); ptr++);
85
85
 
86
86
        oldname = entryname;
87
 
        parsed = grub_legacy_parse (ptr, &entryname, &newsuffix);
 
87
        parsed = grub_legacy_parse (buf, &entryname, &newsuffix);
88
88
        if (newsuffix)
89
89
          {
90
90
            suffixlen += strlen (newsuffix);
111
111
  if (entryname)
112
112
    fprintf (out, "}\n\n");
113
113
 
114
 
  fwrite (suffix, 1, suffixlen, out);
 
114
  if (fwrite (suffix, 1, suffixlen, out) != suffixlen)
 
115
    {
 
116
      if (out_fname)
 
117
        grub_util_error ("cannot write to `%s': %s",
 
118
                         out_fname, strerror (errno));
 
119
      else
 
120
        grub_util_error ("cannot write to the stdout: %s", strerror (errno));
 
121
    }
115
122
 
116
123
  free (buf);
117
124
  free (suffix);