* util/grub-mkfont.c: Migrate to argp.
* util/grub-mklayout.c: Likewise. * util/grub-mkpasswd-pbkdf2.c: Likewise. * util/grub-mkrelpath.c: Likewise. * util/grub-probe.c: Likewise. * util/grub-script-check.c: Likewise.
This commit is contained in:
parent
4459819a52
commit
8e1e4e3903
8 changed files with 632 additions and 596 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
2012-02-03 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
|
* util/grub-mkfont.c: Migrate to argp.
|
||||||
|
* util/grub-mklayout.c: Likewise.
|
||||||
|
* util/grub-mkpasswd-pbkdf2.c: Likewise.
|
||||||
|
* util/grub-mkrelpath.c: Likewise.
|
||||||
|
* util/grub-probe.c: Likewise.
|
||||||
|
* util/grub-script-check.c: Likewise.
|
||||||
|
|
||||||
2012-02-03 Vladimir Serbinenko <phcoder@gmail.com>
|
2012-02-03 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
* util/grub-reboot.in: Add missing datarootdir.
|
* util/grub-reboot.in: Add missing datarootdir.
|
||||||
|
|
|
@ -160,6 +160,7 @@ program = {
|
||||||
mansection = 1;
|
mansection = 1;
|
||||||
|
|
||||||
common = util/grub-mkrelpath.c;
|
common = util/grub-mkrelpath.c;
|
||||||
|
common = util/argp_common.c;
|
||||||
|
|
||||||
ldadd = libgrubmods.a;
|
ldadd = libgrubmods.a;
|
||||||
ldadd = libgrubgcry.a;
|
ldadd = libgrubgcry.a;
|
||||||
|
@ -173,6 +174,7 @@ program = {
|
||||||
mansection = 1;
|
mansection = 1;
|
||||||
|
|
||||||
common = util/grub-script-check.c;
|
common = util/grub-script-check.c;
|
||||||
|
common = util/argp_common.c;
|
||||||
|
|
||||||
ldadd = libgrubmods.a;
|
ldadd = libgrubmods.a;
|
||||||
ldadd = libgrubgcry.a;
|
ldadd = libgrubgcry.a;
|
||||||
|
@ -199,6 +201,7 @@ program = {
|
||||||
mansection = 1;
|
mansection = 1;
|
||||||
|
|
||||||
common = util/grub-mkpasswd-pbkdf2.c;
|
common = util/grub-mkpasswd-pbkdf2.c;
|
||||||
|
common = util/argp_common.c;
|
||||||
|
|
||||||
ldadd = libgrubmods.a;
|
ldadd = libgrubmods.a;
|
||||||
ldadd = libgrubgcry.a;
|
ldadd = libgrubgcry.a;
|
||||||
|
@ -268,6 +271,7 @@ program = {
|
||||||
mansection = 1;
|
mansection = 1;
|
||||||
common = util/grub-mkfont.c;
|
common = util/grub-mkfont.c;
|
||||||
common = grub-core/unidata.c;
|
common = grub-core/unidata.c;
|
||||||
|
common = util/argp_common.c;
|
||||||
|
|
||||||
cflags = '$(freetype_cflags)';
|
cflags = '$(freetype_cflags)';
|
||||||
|
|
||||||
|
@ -302,6 +306,7 @@ program = {
|
||||||
mansection = 8;
|
mansection = 8;
|
||||||
common = util/grub-probe.c;
|
common = util/grub-probe.c;
|
||||||
common = util/ieee1275/ofpath.c;
|
common = util/ieee1275/ofpath.c;
|
||||||
|
common = util/argp_common.c;
|
||||||
|
|
||||||
ldadd = libgrubmods.a;
|
ldadd = libgrubmods.a;
|
||||||
ldadd = libgrubgcry.a;
|
ldadd = libgrubgcry.a;
|
||||||
|
|
|
@ -30,7 +30,10 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <getopt.h>
|
|
||||||
|
#define _GNU_SOURCE 1
|
||||||
|
#include <argp.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include <ft2build.h>
|
#include <ft2build.h>
|
||||||
#include FT_FREETYPE_H
|
#include FT_FREETYPE_H
|
||||||
|
@ -94,60 +97,7 @@ struct grub_font_info
|
||||||
int num_glyphs;
|
int num_glyphs;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct option options[] =
|
static int font_verbosity;
|
||||||
{
|
|
||||||
{"output", required_argument, 0, 'o'},
|
|
||||||
{"name", required_argument, 0, 'n'},
|
|
||||||
{"index", required_argument, 0, 'i'},
|
|
||||||
{"range", required_argument, 0, 'r'},
|
|
||||||
{"size", required_argument, 0, 's'},
|
|
||||||
{"desc", required_argument, 0, 'd'},
|
|
||||||
{"asce", required_argument, 0, 'c'},
|
|
||||||
{"bold", no_argument, 0, 'b'},
|
|
||||||
{"no-bitmap", no_argument, 0, 0x100},
|
|
||||||
{"no-hinting", no_argument, 0, 0x101},
|
|
||||||
{"force-autohint", no_argument, 0, 'a'},
|
|
||||||
{"help", no_argument, 0, 'h'},
|
|
||||||
{"version", no_argument, 0, 'V'},
|
|
||||||
{"verbose", no_argument, 0, 'v'},
|
|
||||||
{"ascii-bitmaps", no_argument, 0, 0x102},
|
|
||||||
{"width-spec", no_argument, 0, 0x103},
|
|
||||||
{0, 0, 0, 0}
|
|
||||||
};
|
|
||||||
|
|
||||||
int font_verbosity;
|
|
||||||
|
|
||||||
static void
|
|
||||||
usage (int status)
|
|
||||||
{
|
|
||||||
if (status)
|
|
||||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
|
||||||
program_name);
|
|
||||||
else
|
|
||||||
printf (_("\
|
|
||||||
Usage: %s [OPTIONS] FONT_FILES\n\
|
|
||||||
\nOptions:\n\
|
|
||||||
-o, --output=FILE_NAME set output file name\n\
|
|
||||||
--ascii-bitmaps save only the ASCII bitmaps\n\
|
|
||||||
--width-spec create width summary file\n\
|
|
||||||
-i, --index=N set face index\n\
|
|
||||||
-r, --range=A-B[,C-D] set font range\n\
|
|
||||||
-n, --name=S set font family name\n\
|
|
||||||
-s, --size=N set font size\n\
|
|
||||||
-d, --desc=N set font descent\n\
|
|
||||||
-c, --asce=N set font ascent\n\
|
|
||||||
-b, --bold convert to bold font\n\
|
|
||||||
-a, --force-autohint force autohint\n\
|
|
||||||
--no-hinting disable hinting\n\
|
|
||||||
--no-bitmap ignore bitmap strikes when loading\n\
|
|
||||||
-h, --help display this message and exit\n\
|
|
||||||
-V, --version print version information and exit\n\
|
|
||||||
-v, --verbose print verbose messages\n\
|
|
||||||
\n\
|
|
||||||
Report bugs to <%s>.\n"), program_name, PACKAGE_BUGREPORT);
|
|
||||||
|
|
||||||
exit (status);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
add_pixel (grub_uint8_t **data, int *mask, int not_blank)
|
add_pixel (grub_uint8_t **data, int *mask, int not_blank)
|
||||||
|
@ -996,67 +946,82 @@ write_font_pf2 (struct grub_font_info *font_info, char *output_file)
|
||||||
fclose (file);
|
fclose (file);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static struct argp_option options[] = {
|
||||||
main (int argc, char *argv[])
|
{"output", 'o', N_("FILE"), 0, N_("set output file"), 0},
|
||||||
|
{"ascii-bitmaps", 0x102, 0, 0, N_("save only the ASCII bitmaps"), 0},
|
||||||
|
{"width-spec", 0x103, 0, 0, N_("create width summary file"), 0},
|
||||||
|
{"index", 'i', N_("NUM"), 0, N_("set face index"), 0},
|
||||||
|
{"range", 'r', N_("FROM-TO[,FROM-TO]"), 0, N_("set font range"), 0},
|
||||||
|
{"name", 'n', N_("NAME"), 0, N_("set font family name"), 0},
|
||||||
|
{"size", 's', N_("STR"), 0, N_("set font size"), 0},
|
||||||
|
{"desc", 'd', N_("NUM"), 0, N_("set font descent"), 0},
|
||||||
|
{"asce", 'c', N_("NUM"), 0, N_("set font ascent"), 0},
|
||||||
|
{"bold", 'b', 0, 0, N_("convert to bold font"), 0},
|
||||||
|
{"force-autohint", 'a', 0, 0, N_("force autohint"), 0},
|
||||||
|
{"no-hinting", 0x101, 0, 0, N_("disable hinting"), 0},
|
||||||
|
{"no-bitmap", 0x100, 0, 0, N_("ignore bitmap strikes when loading"), 0},
|
||||||
|
{"verbose", 'v', 0, 0, N_("print verbose messages."), 0},
|
||||||
|
{ 0, 0, 0, 0, 0, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct arguments
|
||||||
{
|
{
|
||||||
struct grub_font_info font_info;
|
struct grub_font_info font_info;
|
||||||
FT_Library ft_lib;
|
size_t nfiles;
|
||||||
int font_index = 0;
|
size_t files_max;
|
||||||
int font_size = 0;
|
char **files;
|
||||||
char *output_file = NULL;
|
char *output_file;
|
||||||
enum file_formats file_format = PF2;
|
int font_index;
|
||||||
|
int font_size;
|
||||||
|
enum file_formats file_format;
|
||||||
|
};
|
||||||
|
|
||||||
memset (&font_info, 0, sizeof (font_info));
|
static error_t
|
||||||
|
argp_parser (int key, char *arg, struct argp_state *state)
|
||||||
|
{
|
||||||
|
/* Get the input argument from argp_parse, which we
|
||||||
|
know is a pointer to our arguments structure. */
|
||||||
|
struct arguments *arguments = state->input;
|
||||||
|
|
||||||
set_program_name (argv[0]);
|
char *p;
|
||||||
|
|
||||||
grub_util_init_nls ();
|
switch (key)
|
||||||
|
|
||||||
/* Check for options. */
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
int c = getopt_long (argc, argv, "bao:n:i:s:d:r:hVv", options, 0);
|
|
||||||
|
|
||||||
if (c == -1)
|
|
||||||
break;
|
|
||||||
else
|
|
||||||
switch (c)
|
|
||||||
{
|
{
|
||||||
case 'b':
|
case 'b':
|
||||||
font_info.flags |= GRUB_FONT_FLAG_BOLD;
|
arguments->font_info.flags |= GRUB_FONT_FLAG_BOLD;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x100:
|
case 0x100:
|
||||||
font_info.flags |= GRUB_FONT_FLAG_NOBITMAP;
|
arguments->font_info.flags |= GRUB_FONT_FLAG_NOBITMAP;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x101:
|
case 0x101:
|
||||||
font_info.flags |= GRUB_FONT_FLAG_NOHINTING;
|
arguments->font_info.flags |= GRUB_FONT_FLAG_NOHINTING;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'a':
|
case 'a':
|
||||||
font_info.flags |= GRUB_FONT_FLAG_FORCEHINT;
|
arguments->font_info.flags |= GRUB_FONT_FLAG_FORCEHINT;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'o':
|
case 'o':
|
||||||
output_file = optarg;
|
arguments->output_file = xstrdup (arg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'n':
|
case 'n':
|
||||||
font_info.name = optarg;
|
arguments->font_info.name = xstrdup (arg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'i':
|
case 'i':
|
||||||
font_index = strtoul (optarg, NULL, 0);
|
arguments->font_index = strtoul (arg, NULL, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
font_size = strtoul (optarg, NULL, 0);
|
arguments->font_size = strtoul (arg, NULL, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'r':
|
case 'r':
|
||||||
{
|
{
|
||||||
char *p = optarg;
|
char *p = arg;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
@ -1066,15 +1031,16 @@ main (int argc, char *argv[])
|
||||||
if (*p != '-')
|
if (*p != '-')
|
||||||
grub_util_error (_("invalid font range"));
|
grub_util_error (_("invalid font range"));
|
||||||
b = strtoul (p + 1, &p, 0);
|
b = strtoul (p + 1, &p, 0);
|
||||||
if ((font_info.num_range & (GRUB_FONT_RANGE_BLOCK - 1)) == 0)
|
if ((arguments->font_info.num_range
|
||||||
font_info.ranges = xrealloc (font_info.ranges,
|
& (GRUB_FONT_RANGE_BLOCK - 1)) == 0)
|
||||||
(font_info.num_range +
|
arguments->font_info.ranges = xrealloc (arguments->font_info.ranges,
|
||||||
|
(arguments->font_info.num_range +
|
||||||
GRUB_FONT_RANGE_BLOCK) *
|
GRUB_FONT_RANGE_BLOCK) *
|
||||||
sizeof (grub_uint32_t) * 2);
|
sizeof (grub_uint32_t) * 2);
|
||||||
|
|
||||||
font_info.ranges[font_info.num_range * 2] = a;
|
arguments->font_info.ranges[arguments->font_info.num_range * 2] = a;
|
||||||
font_info.ranges[font_info.num_range * 2 + 1] = b;
|
arguments->font_info.ranges[arguments->font_info.num_range * 2 + 1] = b;
|
||||||
font_info.num_range++;
|
arguments->font_info.num_range++;
|
||||||
|
|
||||||
if (*p)
|
if (*p)
|
||||||
{
|
{
|
||||||
|
@ -1090,73 +1056,103 @@ main (int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
font_info.desc = strtoul (optarg, NULL, 0);
|
arguments->font_info.desc = strtoul (arg, NULL, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'e':
|
case 'e':
|
||||||
font_info.asce = strtoul (optarg, NULL, 0);
|
arguments->font_info.asce = strtoul (arg, NULL, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'h':
|
|
||||||
usage (0);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'V':
|
|
||||||
printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
font_verbosity++;
|
font_verbosity++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x102:
|
case 0x102:
|
||||||
file_format = ASCII_BITMAPS;
|
arguments->file_format = ASCII_BITMAPS;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x103:
|
case 0x103:
|
||||||
file_format = WIDTH_SPEC;
|
arguments->file_format = WIDTH_SPEC;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ARGP_KEY_ARG:
|
||||||
|
assert (arguments->nfiles < arguments->files_max);
|
||||||
|
arguments->files[arguments->nfiles++] = xstrdup(arg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
usage (1);
|
return ARGP_ERR_UNKNOWN;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct argp argp = {
|
||||||
|
options, argp_parser, N_("[OPTIONS] FONT_FILES"),
|
||||||
|
N_("Convert common font file formats into PF2"),
|
||||||
|
NULL, NULL, NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
FT_Library ft_lib;
|
||||||
|
struct arguments arguments;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
set_program_name (argv[0]);
|
||||||
|
|
||||||
|
grub_util_init_nls ();
|
||||||
|
|
||||||
|
memset (&arguments, 0, sizeof (struct arguments));
|
||||||
|
arguments.file_format = PF2;
|
||||||
|
arguments.files_max = argc + 1;
|
||||||
|
arguments.files = xmalloc ((arguments.files_max + 1)
|
||||||
|
* sizeof (arguments.files[0]));
|
||||||
|
memset (arguments.files, 0, (arguments.files_max + 1)
|
||||||
|
* sizeof (arguments.files[0]));
|
||||||
|
|
||||||
|
if (argp_parse (&argp, argc, argv, 0, 0, &arguments) != 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s", _("Error in parsing command line arguments\n"));
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_format == ASCII_BITMAPS && font_info.num_range > 0)
|
if (arguments.file_format == ASCII_BITMAPS
|
||||||
|
&& arguments.font_info.num_range > 0)
|
||||||
{
|
{
|
||||||
grub_util_error (_("Option --ascii-bitmaps doesn't accept ranges (use ASCII)."));
|
grub_util_error (_("Option --ascii-bitmaps doesn't accept ranges (use ASCII)."));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
else if (arguments.file_format == ASCII_BITMAPS)
|
||||||
else if (file_format == ASCII_BITMAPS)
|
|
||||||
{
|
{
|
||||||
font_info.ranges = xrealloc (font_info.ranges,
|
arguments.font_info.ranges = xrealloc (arguments.font_info.ranges,
|
||||||
GRUB_FONT_RANGE_BLOCK *
|
GRUB_FONT_RANGE_BLOCK *
|
||||||
sizeof (grub_uint32_t) * 2);
|
sizeof (grub_uint32_t) * 2);
|
||||||
|
|
||||||
font_info.ranges[0] = (grub_uint32_t) 0x00;
|
arguments.font_info.ranges[0] = (grub_uint32_t) 0x00;
|
||||||
font_info.ranges[1] = (grub_uint32_t) 0x7f;
|
arguments.font_info.ranges[1] = (grub_uint32_t) 0x7f;
|
||||||
font_info.num_range = 1;
|
arguments.font_info.num_range = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! output_file)
|
if (! arguments.output_file)
|
||||||
grub_util_error (_("no output file is specified"));
|
grub_util_error (_("no output file is specified"));
|
||||||
|
|
||||||
if (FT_Init_FreeType (&ft_lib))
|
if (FT_Init_FreeType (&ft_lib))
|
||||||
grub_util_error (_("FT_Init_FreeType fails"));
|
grub_util_error (_("FT_Init_FreeType fails"));
|
||||||
|
|
||||||
for (; optind < argc; optind++)
|
for (i = 0; i < arguments.nfiles; i++)
|
||||||
{
|
{
|
||||||
FT_Face ft_face;
|
FT_Face ft_face;
|
||||||
int size;
|
int size;
|
||||||
FT_Error err;
|
FT_Error err;
|
||||||
|
|
||||||
err = FT_New_Face (ft_lib, argv[optind], font_index, &ft_face);
|
err = FT_New_Face (ft_lib, arguments.files[i],
|
||||||
|
arguments.font_index, &ft_face);
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
grub_printf (_("can't open file %s, index %d: error %d"),
|
grub_printf (_("can't open file %s, index %d: error %d"),
|
||||||
argv[optind], font_index, err);
|
arguments.files[i],
|
||||||
|
arguments.font_index, err);
|
||||||
if (err > 0 && err < (signed) ARRAY_SIZE (ft_errmsgs))
|
if (err > 0 && err < (signed) ARRAY_SIZE (ft_errmsgs))
|
||||||
printf (": %s\n", ft_errmsgs[err]);
|
printf (": %s\n", ft_errmsgs[err]);
|
||||||
else
|
else
|
||||||
|
@ -1165,10 +1161,10 @@ main (int argc, char *argv[])
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((! font_info.name) && (ft_face->family_name))
|
if ((! arguments.font_info.name) && (ft_face->family_name))
|
||||||
font_info.name = xstrdup (ft_face->family_name);
|
arguments.font_info.name = xstrdup (ft_face->family_name);
|
||||||
|
|
||||||
size = font_size;
|
size = arguments.font_size;
|
||||||
if (! size)
|
if (! size)
|
||||||
{
|
{
|
||||||
if ((ft_face->face_flags & FT_FACE_FLAG_SCALABLE) ||
|
if ((ft_face->face_flags & FT_FACE_FLAG_SCALABLE) ||
|
||||||
|
@ -1178,12 +1174,13 @@ main (int argc, char *argv[])
|
||||||
size = ft_face->available_sizes[0].height;
|
size = ft_face->available_sizes[0].height;
|
||||||
}
|
}
|
||||||
|
|
||||||
font_info.style = ft_face->style_flags;
|
arguments.font_info.style = ft_face->style_flags;
|
||||||
font_info.size = size;
|
arguments.font_info.size = size;
|
||||||
|
|
||||||
if (FT_Set_Pixel_Sizes (ft_face, size, size))
|
if (FT_Set_Pixel_Sizes (ft_face, size, size))
|
||||||
grub_util_error (_("can't set %dx%d font size"), size, size);
|
grub_util_error (_("can't set %dx%d font size"),
|
||||||
add_font (&font_info, ft_face, file_format != PF2);
|
size, size);
|
||||||
|
add_font (&arguments.font_info, ft_face, arguments.file_format != PF2);
|
||||||
FT_Done_Face (ft_face);
|
FT_Done_Face (ft_face);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1196,46 +1193,52 @@ main (int argc, char *argv[])
|
||||||
|
|
||||||
memset (counter, 0, sizeof (counter));
|
memset (counter, 0, sizeof (counter));
|
||||||
|
|
||||||
for (cur = font_info.glyphs_unsorted; cur; cur = cur->next)
|
for (cur = arguments.font_info.glyphs_unsorted; cur; cur = cur->next)
|
||||||
counter[(cur->char_code & 0xffff) + 1]++;
|
counter[(cur->char_code & 0xffff) + 1]++;
|
||||||
for (i = 0; i < 0x10000; i++)
|
for (i = 0; i < 0x10000; i++)
|
||||||
counter[i+1] += counter[i];
|
counter[i+1] += counter[i];
|
||||||
tmp = xmalloc (font_info.num_glyphs
|
tmp = xmalloc (arguments.font_info.num_glyphs
|
||||||
* sizeof (tmp[0]));
|
* sizeof (tmp[0]));
|
||||||
for (cur = font_info.glyphs_unsorted; cur; cur = cur->next)
|
for (cur = arguments.font_info.glyphs_unsorted; cur; cur = cur->next)
|
||||||
tmp[counter[(cur->char_code & 0xffff)]++] = *cur;
|
tmp[counter[(cur->char_code & 0xffff)]++] = *cur;
|
||||||
|
|
||||||
memset (counter, 0, sizeof (counter));
|
memset (counter, 0, sizeof (counter));
|
||||||
|
|
||||||
for (cur = tmp; cur < tmp + font_info.num_glyphs; cur++)
|
for (cur = tmp; cur < tmp + arguments.font_info.num_glyphs; cur++)
|
||||||
counter[((cur->char_code & 0xffff0000) >> 16) + 1]++;
|
counter[((cur->char_code & 0xffff0000) >> 16) + 1]++;
|
||||||
for (i = 0; i < 0x10000; i++)
|
for (i = 0; i < 0x10000; i++)
|
||||||
counter[i+1] += counter[i];
|
counter[i+1] += counter[i];
|
||||||
font_info.glyphs_sorted = xmalloc (font_info.num_glyphs
|
arguments.font_info.glyphs_sorted = xmalloc (arguments.font_info.num_glyphs
|
||||||
* sizeof (font_info.glyphs_sorted[0]));
|
* sizeof (arguments.font_info.glyphs_sorted[0]));
|
||||||
for (cur = tmp; cur < tmp + font_info.num_glyphs; cur++)
|
for (cur = tmp; cur < tmp + arguments.font_info.num_glyphs; cur++)
|
||||||
font_info.glyphs_sorted[counter[(cur->char_code & 0xffff0000) >> 16]++]
|
arguments.font_info.glyphs_sorted[counter[(cur->char_code & 0xffff0000)
|
||||||
= *cur;
|
>> 16]++] = *cur;
|
||||||
free (tmp);
|
free (tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (file_format)
|
switch (arguments.file_format)
|
||||||
{
|
{
|
||||||
case PF2:
|
case PF2:
|
||||||
write_font_pf2 (&font_info, output_file);
|
write_font_pf2 (&arguments.font_info, arguments.output_file);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ASCII_BITMAPS:
|
case ASCII_BITMAPS:
|
||||||
write_font_ascii_bitmap (&font_info, output_file);
|
write_font_ascii_bitmap (&arguments.font_info, arguments.output_file);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WIDTH_SPEC:
|
case WIDTH_SPEC:
|
||||||
write_font_width_spec (&font_info, output_file);
|
write_font_width_spec (&arguments.font_info, arguments.output_file);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (font_verbosity > 1)
|
if (font_verbosity > 1)
|
||||||
print_glyphs (&font_info);
|
print_glyphs (&arguments.font_info);
|
||||||
|
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < arguments.nfiles; i++)
|
||||||
|
free (arguments.files[i]);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,23 +23,31 @@
|
||||||
#include <grub/term.h>
|
#include <grub/term.h>
|
||||||
#include <grub/keyboard_layouts.h>
|
#include <grub/keyboard_layouts.h>
|
||||||
|
|
||||||
|
#define _GNU_SOURCE 1
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <getopt.h>
|
#include <argp.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include "progname.h"
|
#include "progname.h"
|
||||||
|
|
||||||
#define CKBCOMP "ckbcomp"
|
struct arguments
|
||||||
|
{
|
||||||
|
char *input;
|
||||||
|
char *output;
|
||||||
|
int verbosity;
|
||||||
|
};
|
||||||
|
|
||||||
static struct option options[] = {
|
static struct argp_option options[] = {
|
||||||
{"output", required_argument, 0, 'o'},
|
{"input", 'i', N_("FILE"), 0,
|
||||||
{"help", no_argument, 0, 'h'},
|
N_("set input filename. Default is STDIN"), 0},
|
||||||
{"version", no_argument, 0, 'V'},
|
{"output", 'o', N_("FILE"), 0,
|
||||||
{"verbose", no_argument, 0, 'v'},
|
N_("set output filename. Default is STDOUT"), 0},
|
||||||
{0, 0, 0, 0}
|
{"verbose", 'v', 0, 0, N_("Print verbose messages."), 0},
|
||||||
|
{ 0, 0, 0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct console_grub_equivalence
|
struct console_grub_equivalence
|
||||||
|
@ -264,11 +272,6 @@ usage (int status)
|
||||||
else
|
else
|
||||||
printf (_("\
|
printf (_("\
|
||||||
Usage: %s [OPTIONS]\n\
|
Usage: %s [OPTIONS]\n\
|
||||||
-i, --input set input filename. Default is STDIN\n\
|
|
||||||
-o, --output set output filename. Default is STDOUT\n\
|
|
||||||
-h, --help display this message and exit.\n\
|
|
||||||
-V, --version print version information and exit.\n\
|
|
||||||
-v, --verbose print verbose messages.\n\
|
|
||||||
\n\
|
\n\
|
||||||
Report bugs to <%s>.\n"), program_name, PACKAGE_BUGREPORT);
|
Report bugs to <%s>.\n"), program_name, PACKAGE_BUGREPORT);
|
||||||
|
|
||||||
|
@ -414,8 +417,7 @@ write_keymaps (FILE *in, FILE *out)
|
||||||
|
|
||||||
if (ok == 0)
|
if (ok == 0)
|
||||||
{
|
{
|
||||||
fprintf (stderr, _("ERROR: no keycodes found. Check output of %s.\n"),
|
fprintf (stderr, "%s", _("ERROR: no keycodes found. Check the input.\n"));
|
||||||
CKBCOMP);
|
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,65 +426,68 @@ write_keymaps (FILE *in, FILE *out)
|
||||||
write_file (out, &layout);
|
write_file (out, &layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static error_t
|
||||||
main (int argc, char *argv[])
|
argp_parser (int key, char *arg, struct argp_state *state)
|
||||||
{
|
{
|
||||||
int verbosity;
|
/* Get the input argument from argp_parse, which we
|
||||||
char *infile_name = NULL;
|
know is a pointer to our arguments structure. */
|
||||||
char *outfile_name = NULL;
|
struct arguments *arguments = state->input;
|
||||||
FILE *in, *out;
|
|
||||||
|
|
||||||
set_program_name (argv[0]);
|
char *p;
|
||||||
|
|
||||||
verbosity = 0;
|
switch (key)
|
||||||
|
|
||||||
/* Check for options. */
|
|
||||||
while (1)
|
|
||||||
{
|
{
|
||||||
int c = getopt_long (argc, argv, "o:i:hVv", options, 0);
|
|
||||||
|
|
||||||
if (c == -1)
|
|
||||||
break;
|
|
||||||
else
|
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case 'h':
|
|
||||||
usage (0);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'i':
|
case 'i':
|
||||||
infile_name = optarg;
|
arguments->input = xstrdup (arg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'o':
|
case 'o':
|
||||||
outfile_name = optarg;
|
arguments->output = xstrdup (arg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'V':
|
|
||||||
printf ("%s (%s) %s\n", program_name, PACKAGE_NAME,
|
|
||||||
PACKAGE_VERSION);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
verbosity++;
|
arguments->verbosity++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
usage (1);
|
return ARGP_ERR_UNKNOWN;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (infile_name)
|
return 0;
|
||||||
in = fopen (infile_name, "r");
|
}
|
||||||
|
|
||||||
|
static struct argp argp = {
|
||||||
|
options, argp_parser, N_("[OPTIONS]"),
|
||||||
|
N_("Generate GRUB keyboard layout from Linux console one."),
|
||||||
|
NULL, NULL, NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
FILE *in, *out;
|
||||||
|
struct arguments arguments;
|
||||||
|
|
||||||
|
set_program_name (argv[0]);
|
||||||
|
|
||||||
|
/* Check for options. */
|
||||||
|
memset (&arguments, 0, sizeof (struct arguments));
|
||||||
|
if (argp_parse (&argp, argc, argv, 0, 0, &arguments) != 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s", _("Error in parsing command line arguments\n"));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arguments.input)
|
||||||
|
in = fopen (arguments.input, "r");
|
||||||
else
|
else
|
||||||
in = stdin;
|
in = stdin;
|
||||||
|
|
||||||
if (!in)
|
if (!in)
|
||||||
grub_util_error (_("Couldn't open input file: %s\n"), strerror (errno));
|
grub_util_error (_("Couldn't open input file: %s\n"), strerror (errno));
|
||||||
|
|
||||||
if (outfile_name)
|
if (arguments.output)
|
||||||
out = fopen (outfile_name, "wb");
|
out = fopen (arguments.output, "wb");
|
||||||
else
|
else
|
||||||
out = stdout;
|
out = stdout;
|
||||||
|
|
||||||
|
|
|
@ -29,38 +29,62 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <getopt.h>
|
|
||||||
|
#define _GNU_SOURCE 1
|
||||||
|
|
||||||
|
#include <argp.h>
|
||||||
|
|
||||||
#include "progname.h"
|
#include "progname.h"
|
||||||
|
|
||||||
static struct option options[] =
|
static struct argp_option options[] = {
|
||||||
{
|
{"iteration-count", 'c', N_("NUM"), 0, N_("Number of PBKDF2 iterations"), 0},
|
||||||
{"iteration_count", required_argument, 0, 'c'},
|
{"buflen", 'l', N_("NUM"), 0, N_("Length of generated hash"), 0},
|
||||||
{"buflen", required_argument, 0, 'l'},
|
{"salt", 's', N_("NUM"), 0, N_("Length of salt"), 0},
|
||||||
{"saltlen", required_argument, 0, 's'},
|
{ 0, 0, 0, 0, 0, 0 }
|
||||||
{"help", no_argument, 0, 'h'},
|
};
|
||||||
{"version", no_argument, 0, 'V'},
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
struct arguments
|
||||||
usage (int status)
|
|
||||||
{
|
{
|
||||||
if (status)
|
unsigned int count;
|
||||||
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
unsigned int buflen;
|
||||||
program_name);
|
unsigned int saltlen;
|
||||||
else
|
};
|
||||||
printf (_("\
|
|
||||||
Usage: %s [OPTIONS]\n\
|
|
||||||
\nOptions:\n\
|
|
||||||
-c number, --iteration-count=number Number of PBKDF2 iterations\n\
|
|
||||||
-l number, --buflen=number Length of generated hash\n\
|
|
||||||
-s number, --salt=number Length of salt\n\
|
|
||||||
\n\
|
|
||||||
Report bugs to <%s>.\n"), program_name, PACKAGE_BUGREPORT);
|
|
||||||
|
|
||||||
exit (status);
|
static error_t
|
||||||
|
argp_parser (int key, char *arg, struct argp_state *state)
|
||||||
|
{
|
||||||
|
/* Get the input argument from argp_parse, which we
|
||||||
|
know is a pointer to our arguments structure. */
|
||||||
|
struct arguments *arguments = state->input;
|
||||||
|
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case 'c':
|
||||||
|
arguments->count = strtoul (arg, NULL, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'l':
|
||||||
|
arguments->buflen = strtoul (arg, NULL, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 's':
|
||||||
|
arguments->saltlen = strtoul (arg, NULL, 0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return ARGP_ERR_UNKNOWN;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct argp argp = {
|
||||||
|
options, argp_parser, N_("[OPTIONS]"),
|
||||||
|
N_("Generate PBKDF2 password hash."),
|
||||||
|
NULL, NULL, NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
hexify (char *hex, grub_uint8_t *bin, grub_size_t n)
|
hexify (char *hex, grub_uint8_t *bin, grub_size_t n)
|
||||||
{
|
{
|
||||||
|
@ -85,7 +109,11 @@ hexify (char *hex, grub_uint8_t *bin, grub_size_t n)
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned int count = 10000, buflen = 64, saltlen = 64;
|
struct arguments arguments = {
|
||||||
|
.count = 10000,
|
||||||
|
.buflen = 64,
|
||||||
|
.saltlen = 64
|
||||||
|
};
|
||||||
char *bufhex, *salthex;
|
char *bufhex, *salthex;
|
||||||
gcry_err_code_t gcry_err;
|
gcry_err_code_t gcry_err;
|
||||||
grub_uint8_t *buf, *salt;
|
grub_uint8_t *buf, *salt;
|
||||||
|
@ -98,60 +126,30 @@ main (int argc, char *argv[])
|
||||||
grub_util_init_nls ();
|
grub_util_init_nls ();
|
||||||
|
|
||||||
/* Check for options. */
|
/* Check for options. */
|
||||||
while (1)
|
if (argp_parse (&argp, argc, argv, 0, 0, &arguments) != 0)
|
||||||
{
|
{
|
||||||
int c = getopt_long (argc, argv, "c:l:s:hvV", options, 0);
|
fprintf (stderr, "%s", _("Error in parsing command line arguments\n"));
|
||||||
|
exit(1);
|
||||||
if (c == -1)
|
|
||||||
break;
|
|
||||||
|
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case 'c':
|
|
||||||
count = strtoul (optarg, NULL, 0);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'l':
|
|
||||||
buflen = strtoul (optarg, NULL, 0);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 's':
|
|
||||||
saltlen = strtoul (optarg, NULL, 0);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'h':
|
|
||||||
usage (0);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
case 'V':
|
|
||||||
printf ("%s (%s) %s\n", program_name,
|
|
||||||
PACKAGE_NAME, PACKAGE_VERSION);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
default:
|
|
||||||
usage (1);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bufhex = malloc (buflen * 2 + 1);
|
bufhex = malloc (arguments.buflen * 2 + 1);
|
||||||
if (!bufhex)
|
if (!bufhex)
|
||||||
grub_util_error (_("out of memory"));
|
grub_util_error (_("out of memory"));
|
||||||
buf = malloc (buflen);
|
buf = malloc (arguments.buflen);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
{
|
{
|
||||||
free (bufhex);
|
free (bufhex);
|
||||||
grub_util_error (_("out of memory"));
|
grub_util_error (_("out of memory"));
|
||||||
}
|
}
|
||||||
|
|
||||||
salt = malloc (saltlen);
|
salt = malloc (arguments.saltlen);
|
||||||
if (!salt)
|
if (!salt)
|
||||||
{
|
{
|
||||||
free (bufhex);
|
free (bufhex);
|
||||||
free (buf);
|
free (buf);
|
||||||
grub_util_error (_("out of memory"));
|
grub_util_error (_("out of memory"));
|
||||||
}
|
}
|
||||||
salthex = malloc (saltlen * 2 + 1);
|
salthex = malloc (arguments.saltlen * 2 + 1);
|
||||||
if (!salthex)
|
if (!salthex)
|
||||||
{
|
{
|
||||||
free (salt);
|
free (salt);
|
||||||
|
@ -209,8 +207,8 @@ main (int argc, char *argv[])
|
||||||
fclose (f);
|
fclose (f);
|
||||||
grub_util_error (_("couldn't retrieve random data for salt"));
|
grub_util_error (_("couldn't retrieve random data for salt"));
|
||||||
}
|
}
|
||||||
rd = fread (salt, 1, saltlen, f);
|
rd = fread (salt, 1, arguments.saltlen, f);
|
||||||
if (rd != saltlen)
|
if (rd != arguments.saltlen)
|
||||||
{
|
{
|
||||||
fclose (f);
|
fclose (f);
|
||||||
memset (pass1, 0, sizeof (pass1));
|
memset (pass1, 0, sizeof (pass1));
|
||||||
|
@ -225,34 +223,34 @@ main (int argc, char *argv[])
|
||||||
|
|
||||||
gcry_err = grub_crypto_pbkdf2 (GRUB_MD_SHA512,
|
gcry_err = grub_crypto_pbkdf2 (GRUB_MD_SHA512,
|
||||||
(grub_uint8_t *) pass1, strlen (pass1),
|
(grub_uint8_t *) pass1, strlen (pass1),
|
||||||
salt, saltlen,
|
salt, arguments.saltlen,
|
||||||
count, buf, buflen);
|
arguments.count, buf, arguments.buflen);
|
||||||
memset (pass1, 0, sizeof (pass1));
|
memset (pass1, 0, sizeof (pass1));
|
||||||
|
|
||||||
if (gcry_err)
|
if (gcry_err)
|
||||||
{
|
{
|
||||||
memset (buf, 0, buflen);
|
memset (buf, 0, arguments.buflen);
|
||||||
memset (bufhex, 0, 2 * buflen);
|
memset (bufhex, 0, 2 * arguments.buflen);
|
||||||
free (buf);
|
free (buf);
|
||||||
free (bufhex);
|
free (bufhex);
|
||||||
memset (salt, 0, saltlen);
|
memset (salt, 0, arguments.saltlen);
|
||||||
memset (salthex, 0, 2 * saltlen);
|
memset (salthex, 0, 2 * arguments.saltlen);
|
||||||
free (salt);
|
free (salt);
|
||||||
free (salthex);
|
free (salthex);
|
||||||
grub_util_error (_("cryptographic error number %d"), gcry_err);
|
grub_util_error (_("cryptographic error number %d"), gcry_err);
|
||||||
}
|
}
|
||||||
|
|
||||||
hexify (bufhex, buf, buflen);
|
hexify (bufhex, buf, arguments.buflen);
|
||||||
hexify (salthex, salt, saltlen);
|
hexify (salthex, salt, arguments.saltlen);
|
||||||
|
|
||||||
printf (_("Your PBKDF2 is grub.pbkdf2.sha512.%d.%s.%s\n"),
|
printf (_("Your PBKDF2 is grub.pbkdf2.sha512.%d.%s.%s\n"),
|
||||||
count, salthex, bufhex);
|
arguments.count, salthex, bufhex);
|
||||||
memset (buf, 0, buflen);
|
memset (buf, 0, arguments.buflen);
|
||||||
memset (bufhex, 0, 2 * buflen);
|
memset (bufhex, 0, 2 * arguments.buflen);
|
||||||
free (buf);
|
free (buf);
|
||||||
free (bufhex);
|
free (bufhex);
|
||||||
memset (salt, 0, saltlen);
|
memset (salt, 0, arguments.saltlen);
|
||||||
memset (salthex, 0, 2 * saltlen);
|
memset (salthex, 0, 2 * arguments.saltlen);
|
||||||
free (salt);
|
free (salt);
|
||||||
free (salthex);
|
free (salthex);
|
||||||
|
|
||||||
|
|
|
@ -20,88 +20,83 @@
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include <grub/util/misc.h>
|
#include <grub/util/misc.h>
|
||||||
#include <grub/emu/misc.h>
|
#include <grub/emu/misc.h>
|
||||||
#include <grub/i18n.h>
|
#include <grub/i18n.h>
|
||||||
#include <getopt.h>
|
|
||||||
|
#define _GNU_SOURCE 1
|
||||||
|
#include <argp.h>
|
||||||
|
|
||||||
#include "progname.h"
|
#include "progname.h"
|
||||||
|
|
||||||
static struct option options[] =
|
struct arguments
|
||||||
{
|
|
||||||
{"help", no_argument, 0, 'h'},
|
|
||||||
{"version", no_argument, 0, 'V'},
|
|
||||||
{0, 0, 0, 0},
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
|
||||||
usage (int status)
|
|
||||||
{
|
{
|
||||||
if (status)
|
char *pathname;
|
||||||
fprintf (stderr, _("Try `%s --help' for more information.\n"), program_name);
|
};
|
||||||
else
|
|
||||||
printf (_("\
|
|
||||||
Usage: %s [OPTIONS] PATH\n\
|
|
||||||
\n\
|
|
||||||
Make a system path relative to its root.\n\
|
|
||||||
\n\
|
|
||||||
Options:\n\
|
|
||||||
-h, --help display this message and exit\n\
|
|
||||||
-V, --version print version information and exit\n\
|
|
||||||
\n\
|
|
||||||
Report bugs to <%s>.\n"), program_name, PACKAGE_BUGREPORT);
|
|
||||||
|
|
||||||
exit (status);
|
static struct argp_option options[] = {
|
||||||
|
{ 0, 0, 0, 0, 0, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
static error_t
|
||||||
|
argp_parser (int key, char *arg, struct argp_state *state)
|
||||||
|
{
|
||||||
|
/* Get the input argument from argp_parse, which we
|
||||||
|
know is a pointer to our arguments structure. */
|
||||||
|
struct arguments *arguments = state->input;
|
||||||
|
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case ARGP_KEY_ARG:
|
||||||
|
if (state->arg_num == 0)
|
||||||
|
arguments->pathname = xstrdup (arg);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Too many arguments. */
|
||||||
|
fprintf (stderr, _("Unknown extra argument `%s'.\n"), arg);
|
||||||
|
argp_usage (state);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ARGP_KEY_NO_ARGS:
|
||||||
|
fprintf (stderr, "%s", _("No path is specified.\n"));
|
||||||
|
argp_usage (state);
|
||||||
|
exit (1);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return ARGP_ERR_UNKNOWN;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct argp argp = {
|
||||||
|
options, argp_parser, N_("PATH"),
|
||||||
|
N_("Make a system path relative to its root."),
|
||||||
|
NULL, NULL, NULL
|
||||||
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *argument, *relpath;
|
char *relpath;
|
||||||
|
struct arguments arguments;
|
||||||
|
|
||||||
set_program_name (argv[0]);
|
set_program_name (argv[0]);
|
||||||
|
|
||||||
grub_util_init_nls ();
|
grub_util_init_nls ();
|
||||||
|
|
||||||
|
memset (&arguments, 0, sizeof (struct arguments));
|
||||||
|
|
||||||
/* Check for options. */
|
/* Check for options. */
|
||||||
while (1)
|
if (argp_parse (&argp, argc, argv, 0, 0, &arguments) != 0)
|
||||||
{
|
{
|
||||||
int c = getopt_long (argc, argv, "hV", options, 0);
|
fprintf (stderr, "%s", _("Error in parsing command line arguments\n"));
|
||||||
|
exit(1);
|
||||||
if (c == -1)
|
|
||||||
break;
|
|
||||||
else
|
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case 'h':
|
|
||||||
usage (0);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'V':
|
|
||||||
printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
default:
|
|
||||||
usage (1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optind >= argc)
|
relpath = grub_make_system_path_relative_to_its_root (arguments.pathname);
|
||||||
{
|
|
||||||
fprintf (stderr, "%s", _("No path is specified.\n"));
|
|
||||||
usage (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (optind + 1 != argc)
|
|
||||||
{
|
|
||||||
fprintf (stderr, _("Unknown extra argument `%s'.\n"), argv[optind + 1]);
|
|
||||||
usage (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
argument = argv[optind];
|
|
||||||
|
|
||||||
relpath = grub_make_system_path_relative_to_its_root (argument);
|
|
||||||
printf ("%s\n", relpath);
|
printf ("%s\n", relpath);
|
||||||
free (relpath);
|
free (relpath);
|
||||||
|
|
||||||
|
|
|
@ -43,9 +43,10 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#define _GNU_SOURCE 1
|
#define _GNU_SOURCE 1
|
||||||
#include <getopt.h>
|
#include <argp.h>
|
||||||
|
|
||||||
#include "progname.h"
|
#include "progname.h"
|
||||||
|
|
||||||
|
@ -663,153 +664,169 @@ probe (const char *path, char **device_names, char delim)
|
||||||
free (drives_names);
|
free (drives_names);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct option options[] =
|
static struct argp_option options[] = {
|
||||||
{
|
{"device", 'd', 0, 0,
|
||||||
{"device", no_argument, 0, 'd'},
|
N_("given argument is a system device, not a path"), 0},
|
||||||
{"device-map", required_argument, 0, 'm'},
|
{"device-map", 'm', N_("FILE"), 0,
|
||||||
{"target", required_argument, 0, 't'},
|
N_("use FILE as the device map [default=%s]"), 0},
|
||||||
{"help", no_argument, 0, 'h'},
|
{"target", 't', "(fs|fs_uuid|fs_label|drive|device|partmap|abstraction|cryptodisk_uuid|msdos_parttype)", 0,
|
||||||
{"version", no_argument, 0, 'V'},
|
N_("print filesystem module, GRUB drive, system device, partition map module, abstraction module or CRYPTO UUID [default=fs]"), 0},
|
||||||
{"verbose", no_argument, 0, 'v'},
|
{"verbose", 'v', 0, 0, N_("Print verbose messages."), 0},
|
||||||
{0, 0, 0, 0}
|
{ 0, 0, 0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
|
||||||
usage (int status)
|
static char *
|
||||||
|
help_filter (int key, const char *text, void *input __attribute__ ((unused)))
|
||||||
{
|
{
|
||||||
if (status)
|
switch (key)
|
||||||
fprintf (stderr,
|
{
|
||||||
_("Try `%s --help' for more information.\n"), program_name);
|
case 'm':
|
||||||
else
|
return xasprintf (text, DEFAULT_DEVICE_MAP);
|
||||||
printf (_("\
|
|
||||||
Usage: %s [OPTION]... [PATH|DEVICE]\n\
|
|
||||||
\n\
|
|
||||||
Probe device information for a given path (or device, if the -d option is given).\n\
|
|
||||||
\n\
|
|
||||||
-d, --device given argument is a system device, not a path\n\
|
|
||||||
-m, --device-map=FILE use FILE as the device map [default=%s]\n\
|
|
||||||
-t, --target=(fs|fs_uuid|fs_label|drive|device|partmap|abstraction|cryptodisk_uuid|msdos_parttype)\n\
|
|
||||||
print filesystem module, GRUB drive, system device, partition map module, abstraction module or CRYPTO UUID [default=fs]\n\
|
|
||||||
-h, --help display this message and exit\n\
|
|
||||||
-V, --version print version information and exit\n\
|
|
||||||
-v, --verbose print verbose messages\n\
|
|
||||||
\n\
|
|
||||||
Report bugs to <%s>.\n\
|
|
||||||
"), program_name,
|
|
||||||
DEFAULT_DEVICE_MAP, PACKAGE_BUGREPORT);
|
|
||||||
|
|
||||||
exit (status);
|
default:
|
||||||
|
return (char *) text;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
struct arguments
|
||||||
main (int argc, char *argv[])
|
|
||||||
{
|
{
|
||||||
char *dev_map = 0;
|
char **devices;
|
||||||
int zero_delim = 0;
|
size_t device_max;
|
||||||
char delim;
|
size_t ndevices;
|
||||||
|
char *dev_map;
|
||||||
|
int zero_delim;
|
||||||
|
};
|
||||||
|
|
||||||
set_program_name (argv[0]);
|
static error_t
|
||||||
|
argp_parser (int key, char *arg, struct argp_state *state)
|
||||||
|
{
|
||||||
|
/* Get the input argument from argp_parse, which we
|
||||||
|
know is a pointer to our arguments structure. */
|
||||||
|
struct arguments *arguments = state->input;
|
||||||
|
|
||||||
grub_util_init_nls ();
|
char *p;
|
||||||
|
|
||||||
/* Check for options. */
|
switch (key)
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
int c = getopt_long (argc, argv, "dm:t:hVv0", options, 0);
|
|
||||||
|
|
||||||
if (c == -1)
|
|
||||||
break;
|
|
||||||
else
|
|
||||||
switch (c)
|
|
||||||
{
|
{
|
||||||
case 'd':
|
case 'd':
|
||||||
argument_is_device = 1;
|
argument_is_device = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'm':
|
case 'm':
|
||||||
if (dev_map)
|
if (arguments->dev_map)
|
||||||
free (dev_map);
|
free (arguments->dev_map);
|
||||||
|
|
||||||
dev_map = xstrdup (optarg);
|
arguments->dev_map = xstrdup (arg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
if (!strcmp (optarg, "fs"))
|
if (!strcmp (arg, "fs"))
|
||||||
print = PRINT_FS;
|
print = PRINT_FS;
|
||||||
else if (!strcmp (optarg, "fs_uuid"))
|
else if (!strcmp (arg, "fs_uuid"))
|
||||||
print = PRINT_FS_UUID;
|
print = PRINT_FS_UUID;
|
||||||
else if (!strcmp (optarg, "fs_label"))
|
else if (!strcmp (arg, "fs_label"))
|
||||||
print = PRINT_FS_LABEL;
|
print = PRINT_FS_LABEL;
|
||||||
else if (!strcmp (optarg, "drive"))
|
else if (!strcmp (arg, "drive"))
|
||||||
print = PRINT_DRIVE;
|
print = PRINT_DRIVE;
|
||||||
else if (!strcmp (optarg, "device"))
|
else if (!strcmp (arg, "device"))
|
||||||
print = PRINT_DEVICE;
|
print = PRINT_DEVICE;
|
||||||
else if (!strcmp (optarg, "partmap"))
|
else if (!strcmp (arg, "partmap"))
|
||||||
print = PRINT_PARTMAP;
|
print = PRINT_PARTMAP;
|
||||||
else if (!strcmp (optarg, "abstraction"))
|
else if (!strcmp (arg, "abstraction"))
|
||||||
print = PRINT_ABSTRACTION;
|
print = PRINT_ABSTRACTION;
|
||||||
else if (!strcmp (optarg, "cryptodisk_uuid"))
|
else if (!strcmp (arg, "cryptodisk_uuid"))
|
||||||
print = PRINT_CRYPTODISK_UUID;
|
print = PRINT_CRYPTODISK_UUID;
|
||||||
else if (!strcmp (optarg, "msdos_parttype"))
|
else if (!strcmp (arg, "msdos_parttype"))
|
||||||
print = PRINT_MSDOS_PARTTYPE;
|
print = PRINT_MSDOS_PARTTYPE;
|
||||||
else if (!strcmp (optarg, "hints_string"))
|
else if (!strcmp (arg, "hints_string"))
|
||||||
print = PRINT_HINT_STR;
|
print = PRINT_HINT_STR;
|
||||||
else if (!strcmp (optarg, "bios_hints"))
|
else if (!strcmp (arg, "bios_hints"))
|
||||||
print = PRINT_BIOS_HINT;
|
print = PRINT_BIOS_HINT;
|
||||||
else if (!strcmp (optarg, "ieee1275_hints"))
|
else if (!strcmp (arg, "ieee1275_hints"))
|
||||||
print = PRINT_IEEE1275_HINT;
|
print = PRINT_IEEE1275_HINT;
|
||||||
else if (!strcmp (optarg, "baremetal_hints"))
|
else if (!strcmp (arg, "baremetal_hints"))
|
||||||
print = PRINT_BAREMETAL_HINT;
|
print = PRINT_BAREMETAL_HINT;
|
||||||
else if (!strcmp (optarg, "efi_hints"))
|
else if (!strcmp (arg, "efi_hints"))
|
||||||
print = PRINT_EFI_HINT;
|
print = PRINT_EFI_HINT;
|
||||||
else if (!strcmp (optarg, "arc_hints"))
|
else if (!strcmp (arg, "arc_hints"))
|
||||||
print = PRINT_ARC_HINT;
|
print = PRINT_ARC_HINT;
|
||||||
else if (!strcmp (optarg, "compatibility_hint"))
|
else if (!strcmp (arg, "compatibility_hint"))
|
||||||
print = PRINT_COMPATIBILITY_HINT;
|
print = PRINT_COMPATIBILITY_HINT;
|
||||||
else
|
else
|
||||||
usage (1);
|
argp_usage (state);
|
||||||
break;
|
|
||||||
|
|
||||||
case 'h':
|
|
||||||
usage (0);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '0':
|
case '0':
|
||||||
zero_delim = 1;
|
arguments->zero_delim = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'V':
|
|
||||||
printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
verbosity++;
|
verbosity++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
case ARGP_KEY_NO_ARGS:
|
||||||
usage (1);
|
fprintf (stderr, "%s", _("No path or device is specified.\n"));
|
||||||
|
argp_usage (state);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ARGP_KEY_ARG:
|
||||||
|
assert (arguments->ndevices < arguments->device_max);
|
||||||
|
arguments->devices[arguments->ndevices++] = xstrdup(arg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return ARGP_ERR_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct argp argp = {
|
||||||
|
options, argp_parser, N_("[OPTION]... [PATH|DEVICE]"),
|
||||||
|
N_("\
|
||||||
|
Probe device information for a given path (or device, if the -d option is given)."),
|
||||||
|
NULL, help_filter, NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char delim;
|
||||||
|
struct arguments arguments;
|
||||||
|
|
||||||
|
set_program_name (argv[0]);
|
||||||
|
|
||||||
|
grub_util_init_nls ();
|
||||||
|
|
||||||
|
memset (&arguments, 0, sizeof (struct arguments));
|
||||||
|
arguments.device_max = argc + 1;
|
||||||
|
arguments.devices = xmalloc ((arguments.device_max + 1)
|
||||||
|
* sizeof (arguments.devices[0]));
|
||||||
|
memset (arguments.devices, 0, (arguments.device_max + 1)
|
||||||
|
* sizeof (arguments.devices[0]));
|
||||||
|
|
||||||
|
/* Parse our arguments */
|
||||||
|
if (argp_parse (&argp, argc, argv, 0, 0, &arguments) != 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s", _("Error in parsing command line arguments\n"));
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbosity > 1)
|
if (verbosity > 1)
|
||||||
grub_env_set ("debug", "all");
|
grub_env_set ("debug", "all");
|
||||||
|
|
||||||
/* Obtain ARGUMENT. */
|
/* Obtain ARGUMENT. */
|
||||||
if (optind >= argc)
|
if (arguments.ndevices != 1 && !argument_is_device)
|
||||||
{
|
|
||||||
fprintf (stderr, "%s", _("No path or device is specified.\n"));
|
|
||||||
usage (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (optind + 1 != argc && !argument_is_device)
|
|
||||||
{
|
{
|
||||||
|
char *program = xstrdup(program_name);
|
||||||
fprintf (stderr, _("Unknown extra argument `%s'.\n"), argv[optind + 1]);
|
fprintf (stderr, _("Unknown extra argument `%s'.\n"), argv[optind + 1]);
|
||||||
usage (1);
|
argp_help (&argp, stderr, ARGP_HELP_STD_USAGE, program);
|
||||||
|
free (program);
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize the emulated biosdisk driver. */
|
/* Initialize the emulated biosdisk driver. */
|
||||||
grub_util_biosdisk_init (dev_map ? : DEFAULT_DEVICE_MAP);
|
grub_util_biosdisk_init (arguments.dev_map ? : DEFAULT_DEVICE_MAP);
|
||||||
|
|
||||||
/* Initialize all modules. */
|
/* Initialize all modules. */
|
||||||
grub_init_all ();
|
grub_init_all ();
|
||||||
|
@ -831,20 +848,21 @@ main (int argc, char *argv[])
|
||||||
else
|
else
|
||||||
delim = '\n';
|
delim = '\n';
|
||||||
|
|
||||||
if (zero_delim)
|
if (arguments.zero_delim)
|
||||||
delim = '\0';
|
delim = '\0';
|
||||||
|
|
||||||
/* Do it. */
|
/* Do it. */
|
||||||
if (argument_is_device)
|
if (argument_is_device)
|
||||||
probe (NULL, argv + optind, delim);
|
probe (NULL, arguments.devices, delim);
|
||||||
else
|
else
|
||||||
probe (argv[optind], NULL, delim);
|
probe (arguments.devices[0], NULL, delim);
|
||||||
|
|
||||||
if (!zero_delim && (print == PRINT_COMPATIBILITY_HINT
|
if (!arguments.zero_delim && (print == PRINT_COMPATIBILITY_HINT
|
||||||
|| print == PRINT_BIOS_HINT
|
|| print == PRINT_BIOS_HINT
|
||||||
|| print == PRINT_IEEE1275_HINT
|
|| print == PRINT_IEEE1275_HINT
|
||||||
|| print == PRINT_BAREMETAL_HINT
|
|| print == PRINT_BAREMETAL_HINT
|
||||||
|| print == PRINT_EFI_HINT || print == PRINT_ARC_HINT))
|
|| print == PRINT_EFI_HINT
|
||||||
|
|| print == PRINT_ARC_HINT))
|
||||||
putchar ('\n');
|
putchar ('\n');
|
||||||
|
|
||||||
/* Free resources. */
|
/* Free resources. */
|
||||||
|
@ -852,7 +870,14 @@ main (int argc, char *argv[])
|
||||||
grub_fini_all ();
|
grub_fini_all ();
|
||||||
grub_util_biosdisk_fini ();
|
grub_util_biosdisk_fini ();
|
||||||
|
|
||||||
free (dev_map);
|
{
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < arguments.ndevices; i++)
|
||||||
|
free (arguments.devices[i]);
|
||||||
|
}
|
||||||
|
free (arguments.devices);
|
||||||
|
|
||||||
|
free (arguments.dev_map);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,48 +34,65 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <getopt.h>
|
#include <argp.h>
|
||||||
|
|
||||||
#include "progname.h"
|
#include "progname.h"
|
||||||
|
|
||||||
static struct option options[] =
|
struct arguments
|
||||||
{
|
|
||||||
{"help", no_argument, 0, 'h'},
|
|
||||||
{"version", no_argument, 0, 'V'},
|
|
||||||
{"verbose", no_argument, 0, 'v'},
|
|
||||||
{0, 0, 0, 0}
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
|
||||||
usage (int status)
|
|
||||||
{
|
{
|
||||||
if (status)
|
int verbose;
|
||||||
fprintf (stderr,
|
char *filename;
|
||||||
_("Try ``%s --help'' for more information.\n"), program_name);
|
};
|
||||||
|
|
||||||
|
static struct argp_option options[] = {
|
||||||
|
{"verbose", 'v', 0, 0, N_("Print verbose messages."), 0},
|
||||||
|
{ 0, 0, 0, 0, 0, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
static error_t
|
||||||
|
argp_parser (int key, char *arg, struct argp_state *state)
|
||||||
|
{
|
||||||
|
/* Get the input argument from argp_parse, which we
|
||||||
|
know is a pointer to our arguments structure. */
|
||||||
|
struct arguments *arguments = state->input;
|
||||||
|
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case 'v':
|
||||||
|
arguments->verbose = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ARGP_KEY_ARG:
|
||||||
|
if (state->arg_num == 0)
|
||||||
|
arguments->filename = xstrdup (arg);
|
||||||
else
|
else
|
||||||
printf (_("\
|
{
|
||||||
Usage: %s [PATH]\n\
|
/* Too many arguments. */
|
||||||
\n\
|
fprintf (stderr, _("Unknown extra argument `%s'.\n"), arg);
|
||||||
Checks GRUB script configuration file for syntax errors.\n\
|
argp_usage (state);
|
||||||
\n\
|
}
|
||||||
-h, --help display this message and exit\n\
|
break;
|
||||||
-V, --version print version information and exit\n\
|
default:
|
||||||
-v, --verbose print the script as it is being processed\n\
|
return ARGP_ERR_UNKNOWN;
|
||||||
\n\
|
}
|
||||||
Report bugs to <%s>.\n\
|
return 0;
|
||||||
"), program_name,
|
|
||||||
PACKAGE_BUGREPORT);
|
|
||||||
exit (status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct argp argp = {
|
||||||
|
options, argp_parser, N_("[PATH]"),
|
||||||
|
N_("Checks GRUB script configuration file for syntax errors."),
|
||||||
|
NULL, NULL, NULL
|
||||||
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *argument;
|
|
||||||
char *input;
|
char *input;
|
||||||
int lineno = 0;
|
int lineno = 0;
|
||||||
FILE *file = 0;
|
FILE *file = 0;
|
||||||
int verbose = 0;
|
struct arguments arguments;
|
||||||
int found_input = 0;
|
int found_input = 0;
|
||||||
struct grub_script *script = NULL;
|
struct grub_script *script = NULL;
|
||||||
|
|
||||||
|
@ -98,7 +115,7 @@ main (int argc, char *argv[])
|
||||||
return grub_errno;
|
return grub_errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose)
|
if (arguments.verbose)
|
||||||
grub_printf("%s", cmdline);
|
grub_printf("%s", cmdline);
|
||||||
|
|
||||||
for (i = 0; cmdline[i] != '\0'; i++)
|
for (i = 0; cmdline[i] != '\0'; i++)
|
||||||
|
@ -122,52 +139,31 @@ main (int argc, char *argv[])
|
||||||
set_program_name (argv[0]);
|
set_program_name (argv[0]);
|
||||||
grub_util_init_nls ();
|
grub_util_init_nls ();
|
||||||
|
|
||||||
|
memset (&arguments, 0, sizeof (struct arguments));
|
||||||
|
|
||||||
/* Check for options. */
|
/* Check for options. */
|
||||||
while (1)
|
if (argp_parse (&argp, argc, argv, 0, 0, &arguments) != 0)
|
||||||
{
|
{
|
||||||
int c = getopt_long (argc, argv, "hvV", options, 0);
|
fprintf (stderr, "%s", _("Error in parsing command line arguments\n"));
|
||||||
|
exit(1);
|
||||||
if (c == -1)
|
|
||||||
break;
|
|
||||||
else
|
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case 'h':
|
|
||||||
usage (0);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'V':
|
|
||||||
printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
case 'v':
|
|
||||||
verbose = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
usage (1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Obtain ARGUMENT. */
|
/* Obtain ARGUMENT. */
|
||||||
if (optind >= argc)
|
if (!arguments.filename)
|
||||||
{
|
{
|
||||||
file = 0; /* read from stdin */
|
file = 0; /* read from stdin */
|
||||||
}
|
}
|
||||||
else if (optind + 1 != argc)
|
|
||||||
{
|
|
||||||
fprintf (stderr, _("Unknown extra argument `%s'.\n"), argv[optind + 1]);
|
|
||||||
usage (1);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
argument = argv[optind];
|
file = fopen (arguments.filename, "r");
|
||||||
file = fopen (argument, "r");
|
|
||||||
if (! file)
|
if (! file)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "%s: %s: %s\n", program_name, argument, strerror(errno));
|
char *program = xstrdup(program_name);
|
||||||
usage (1);
|
fprintf (stderr, "%s: %s: %s\n", program_name,
|
||||||
|
arguments.filename, strerror(errno));
|
||||||
|
argp_help (&argp, stderr, ARGP_HELP_STD_USAGE, program);
|
||||||
|
free(program);
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue