]>
Commit | Line | Data |
---|---|---|
50ceeb7c FZ |
1 | /* grub-mkrelpath.c - make a system path relative to its root */ |
2 | /* | |
3 | * GRUB -- GRand Unified Bootloader | |
2f1a3acf | 4 | * Copyright (C) 2009,2010 Free Software Foundation, Inc. |
50ceeb7c FZ |
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 | ||
1d12cf29 YB |
20 | #include <config.h> |
21 | ||
f07ccea7 | 22 | #include <stdio.h> |
50ceeb7c | 23 | #include <grub/util/misc.h> |
81827e24 | 24 | #include <grub/emu/misc.h> |
8a4c07fd | 25 | #include <grub/i18n.h> |
50ceeb7c FZ |
26 | #include <getopt.h> |
27 | ||
8a4c07fd RM |
28 | #include "progname.h" |
29 | ||
50ceeb7c FZ |
30 | static struct option options[] = |
31 | { | |
32 | {"help", no_argument, 0, 'h'}, | |
33 | {"version", no_argument, 0, 'V'}, | |
574cce0c | 34 | {0, 0, 0, 0}, |
50ceeb7c FZ |
35 | }; |
36 | ||
37 | static void | |
38 | usage (int status) | |
39 | { | |
40 | if (status) | |
6e0632e2 | 41 | fprintf (stderr, _("Try `%s --help' for more information.\n"), program_name); |
50ceeb7c | 42 | else |
6e0632e2 | 43 | printf (_("\ |
8a4c07fd | 44 | Usage: %s [OPTIONS] PATH\n\ |
50ceeb7c | 45 | \n\ |
c0f48e65 | 46 | Make a system path relative to its root.\n\ |
50ceeb7c FZ |
47 | \n\ |
48 | Options:\n\ | |
49 | -h, --help display this message and exit\n\ | |
50 | -V, --version print version information and exit\n\ | |
51 | \n\ | |
6e0632e2 | 52 | Report bugs to <%s>.\n"), program_name, PACKAGE_BUGREPORT); |
50ceeb7c FZ |
53 | |
54 | exit (status); | |
55 | } | |
56 | ||
57 | int | |
58 | main (int argc, char *argv[]) | |
59 | { | |
60 | char *argument, *relpath; | |
61 | ||
8a4c07fd | 62 | set_program_name (argv[0]); |
2f1a3acf YB |
63 | |
64 | grub_util_init_nls (); | |
50ceeb7c FZ |
65 | |
66 | /* Check for options. */ | |
67 | while (1) | |
68 | { | |
69 | int c = getopt_long (argc, argv, "hV", options, 0); | |
70 | ||
71 | if (c == -1) | |
72 | break; | |
73 | else | |
74 | switch (c) | |
75 | { | |
76 | case 'h': | |
77 | usage (0); | |
78 | break; | |
79 | ||
80 | case 'V': | |
8a4c07fd | 81 | printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION); |
50ceeb7c FZ |
82 | return 0; |
83 | ||
84 | default: | |
85 | usage (1); | |
86 | break; | |
87 | } | |
88 | } | |
89 | ||
90 | if (optind >= argc) | |
91 | { | |
6e0632e2 | 92 | fprintf (stderr, _("No path is specified.\n")); |
50ceeb7c FZ |
93 | usage (1); |
94 | } | |
95 | ||
96 | if (optind + 1 != argc) | |
97 | { | |
6e0632e2 | 98 | fprintf (stderr, _("Unknown extra argument `%s'.\n"), argv[optind + 1]); |
50ceeb7c FZ |
99 | usage (1); |
100 | } | |
101 | ||
102 | argument = argv[optind]; | |
103 | ||
81827e24 | 104 | relpath = grub_make_system_path_relative_to_its_root (argument); |
50ceeb7c FZ |
105 | printf ("%s\n", relpath); |
106 | free (relpath); | |
107 | ||
108 | return 0; | |
109 | } |