2009-11-08 00:49:15 +00:00
|
|
|
/* grub-mkrelpath.c - make a system path relative to its root */
|
|
|
|
/*
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
2010-01-01 20:32:30 +00:00
|
|
|
* Copyright (C) 2009,2010 Free Software Foundation, Inc.
|
2009-11-08 00:49:15 +00:00
|
|
|
*
|
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GRUB is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-09-24 07:19:57 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2010-04-27 15:25:12 +00:00
|
|
|
#include <stdio.h>
|
2009-11-08 00:49:15 +00:00
|
|
|
#include <grub/util/misc.h>
|
2010-05-04 03:39:03 +00:00
|
|
|
#include <grub/emu/misc.h>
|
2009-11-25 23:10:02 +00:00
|
|
|
#include <grub/i18n.h>
|
2009-11-08 00:49:15 +00:00
|
|
|
#include <getopt.h>
|
|
|
|
|
2009-11-25 23:10:02 +00:00
|
|
|
#include "progname.h"
|
|
|
|
|
2009-11-08 00:49:15 +00:00
|
|
|
static struct option options[] =
|
|
|
|
{
|
|
|
|
{"help", no_argument, 0, 'h'},
|
|
|
|
{"version", no_argument, 0, 'V'},
|
2009-12-14 10:06:24 +00:00
|
|
|
{0, 0, 0, 0},
|
2009-11-08 00:49:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage (int status)
|
|
|
|
{
|
|
|
|
if (status)
|
2011-11-11 20:44:56 +00:00
|
|
|
fprintf (stderr, _("Try `%s --help' for more information.\n"), program_name);
|
2009-11-08 00:49:15 +00:00
|
|
|
else
|
2011-11-11 20:44:56 +00:00
|
|
|
printf (_("\
|
2009-11-25 23:10:02 +00:00
|
|
|
Usage: %s [OPTIONS] PATH\n\
|
2009-11-08 00:49:15 +00:00
|
|
|
\n\
|
2010-05-20 22:27:15 +00:00
|
|
|
Make a system path relative to its root.\n\
|
2009-11-08 00:49:15 +00:00
|
|
|
\n\
|
|
|
|
Options:\n\
|
|
|
|
-h, --help display this message and exit\n\
|
|
|
|
-V, --version print version information and exit\n\
|
|
|
|
\n\
|
2011-11-11 20:44:56 +00:00
|
|
|
Report bugs to <%s>.\n"), program_name, PACKAGE_BUGREPORT);
|
2009-11-08 00:49:15 +00:00
|
|
|
|
|
|
|
exit (status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
char *argument, *relpath;
|
|
|
|
|
2009-11-25 23:10:02 +00:00
|
|
|
set_program_name (argv[0]);
|
2010-01-01 20:32:30 +00:00
|
|
|
|
|
|
|
grub_util_init_nls ();
|
2009-11-08 00:49:15 +00:00
|
|
|
|
|
|
|
/* Check for options. */
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int c = getopt_long (argc, argv, "hV", options, 0);
|
|
|
|
|
|
|
|
if (c == -1)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case 'h':
|
|
|
|
usage (0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'V':
|
2009-11-25 23:10:02 +00:00
|
|
|
printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
|
2009-11-08 00:49:15 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
usage (1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (optind >= argc)
|
|
|
|
{
|
2012-02-03 10:07:18 +00:00
|
|
|
fprintf (stderr, "%s", _("No path is specified.\n"));
|
2009-11-08 00:49:15 +00:00
|
|
|
usage (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (optind + 1 != argc)
|
|
|
|
{
|
2011-11-11 20:44:56 +00:00
|
|
|
fprintf (stderr, _("Unknown extra argument `%s'.\n"), argv[optind + 1]);
|
2009-11-08 00:49:15 +00:00
|
|
|
usage (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
argument = argv[optind];
|
|
|
|
|
2010-05-04 03:39:03 +00:00
|
|
|
relpath = grub_make_system_path_relative_to_its_root (argument);
|
2009-11-08 00:49:15 +00:00
|
|
|
printf ("%s\n", relpath);
|
|
|
|
free (relpath);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|