]> git.proxmox.com Git - grub2.git/blob - util/grub-mkrelpath.c
merge with mainline
[grub2.git] / util / grub-mkrelpath.c
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.
5 *
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.
10 *
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.
15 *
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/>.
18 */
19
20 #include <stdio.h>
21 #include <grub/util/misc.h>
22 #include <grub/emu/misc.h>
23 #include <grub/i18n.h>
24 #include <getopt.h>
25
26 #include "progname.h"
27
28 static struct option options[] =
29 {
30 {"help", no_argument, 0, 'h'},
31 {"version", no_argument, 0, 'V'},
32 {0, 0, 0, 0},
33 };
34
35 static void
36 usage (int status)
37 {
38 if (status)
39 fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
40 else
41 printf ("\
42 Usage: %s [OPTIONS] PATH\n\
43 \n\
44 Make a system path relative to it's root.\n\
45 \n\
46 Options:\n\
47 -h, --help display this message and exit\n\
48 -V, --version print version information and exit\n\
49 \n\
50 Report bugs to <%s>.\n", program_name, PACKAGE_BUGREPORT);
51
52 exit (status);
53 }
54
55 int
56 main (int argc, char *argv[])
57 {
58 char *argument, *relpath;
59
60 set_program_name (argv[0]);
61
62 grub_util_init_nls ();
63
64 /* Check for options. */
65 while (1)
66 {
67 int c = getopt_long (argc, argv, "hV", options, 0);
68
69 if (c == -1)
70 break;
71 else
72 switch (c)
73 {
74 case 'h':
75 usage (0);
76 break;
77
78 case 'V':
79 printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
80 return 0;
81
82 default:
83 usage (1);
84 break;
85 }
86 }
87
88 if (optind >= argc)
89 {
90 fprintf (stderr, "No path is specified.\n");
91 usage (1);
92 }
93
94 if (optind + 1 != argc)
95 {
96 fprintf (stderr, "Unknown extra argument `%s'.\n", argv[optind + 1]);
97 usage (1);
98 }
99
100 argument = argv[optind];
101
102 relpath = grub_make_system_path_relative_to_its_root (argument);
103 printf ("%s\n", relpath);
104 free (relpath);
105
106 return 0;
107 }