1 /* grub-mkrelpath.c - make a system path relative to its root */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2009,2010 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
24 #include <grub/util/misc.h>
25 #include <grub/emu/misc.h>
26 #include <grub/i18n.h>
29 #pragma GCC diagnostic ignored "-Wmissing-prototypes"
30 #pragma GCC diagnostic ignored "-Wmissing-declarations"
32 #pragma GCC diagnostic error "-Wmissing-prototypes"
33 #pragma GCC diagnostic error "-Wmissing-declarations"
42 static struct argp_option options
[] = {
47 argp_parser (int key
, char *arg
, struct argp_state
*state
)
49 /* Get the input argument from argp_parse, which we
50 know is a pointer to our arguments structure. */
51 struct arguments
*arguments
= state
->input
;
56 if (state
->arg_num
== 0)
57 arguments
->pathname
= xstrdup (arg
);
60 /* Too many arguments. */
61 fprintf (stderr
, _("Unknown extra argument `%s'."), arg
);
62 fprintf (stderr
, "\n");
66 case ARGP_KEY_NO_ARGS
:
67 fprintf (stderr
, "%s", _("No path is specified.\n"));
72 return ARGP_ERR_UNKNOWN
;
77 static struct argp argp
= {
78 options
, argp_parser
, N_("PATH"),
79 N_("Transform a system filename into GRUB one."),
84 main (int argc
, char *argv
[])
87 struct arguments arguments
;
89 grub_util_host_init (&argc
, &argv
);
91 memset (&arguments
, 0, sizeof (struct arguments
));
93 /* Check for options. */
94 if (argp_parse (&argp
, argc
, argv
, 0, 0, &arguments
) != 0)
96 fprintf (stderr
, "%s", _("Error in parsing command line arguments\n"));
100 relpath
= grub_make_system_path_relative_to_its_root (arguments
.pathname
);
101 printf ("%s\n", relpath
);