Indentation fix, cleanup.
[AROS.git] / arch / all-pc / boot / grub2-aros / util / grub-mkrelpath.c
blob47a241a391b28644c05fed552d2571dbdb6e5eb7
1 /* grub-mkrelpath.c - make a system path relative to its root */
2 /*
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/>.
20 #include <config.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <grub/util/misc.h>
25 #include <grub/emu/misc.h>
26 #include <grub/i18n.h>
28 #define _GNU_SOURCE 1
29 #pragma GCC diagnostic ignored "-Wmissing-prototypes"
30 #pragma GCC diagnostic ignored "-Wmissing-declarations"
31 #include <argp.h>
32 #pragma GCC diagnostic error "-Wmissing-prototypes"
33 #pragma GCC diagnostic error "-Wmissing-declarations"
35 #include "progname.h"
37 struct arguments
39 char *pathname;
42 static struct argp_option options[] = {
43 { 0, 0, 0, 0, 0, 0 }
46 static error_t
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;
53 switch (key)
55 case ARGP_KEY_ARG:
56 if (state->arg_num == 0)
57 arguments->pathname = xstrdup (arg);
58 else
60 /* Too many arguments. */
61 fprintf (stderr, _("Unknown extra argument `%s'."), arg);
62 fprintf (stderr, "\n");
63 argp_usage (state);
65 break;
66 case ARGP_KEY_NO_ARGS:
67 fprintf (stderr, "%s", _("No path is specified.\n"));
68 argp_usage (state);
69 exit (1);
70 break;
71 default:
72 return ARGP_ERR_UNKNOWN;
74 return 0;
77 static struct argp argp = {
78 options, argp_parser, N_("PATH"),
79 N_("Transform a system filename into GRUB one."),
80 NULL, NULL, NULL
83 int
84 main (int argc, char *argv[])
86 char *relpath;
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"));
97 exit(1);
100 relpath = grub_make_system_path_relative_to_its_root (arguments.pathname);
101 printf ("%s\n", relpath);
102 free (relpath);
104 return 0;