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>
|
2012-02-03 20:45:43 +00:00
|
|
|
#include <string.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>
|
2012-02-03 20:45:43 +00:00
|
|
|
|
|
|
|
#define _GNU_SOURCE 1
|
|
|
|
#include <argp.h>
|
2009-11-08 00:49:15 +00:00
|
|
|
|
2009-11-25 23:10:02 +00:00
|
|
|
#include "progname.h"
|
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
struct arguments
|
|
|
|
{
|
|
|
|
char *pathname;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct argp_option options[] = {
|
|
|
|
{ 0, 0, 0, 0, 0, 0 }
|
|
|
|
};
|
2009-11-08 00:49:15 +00:00
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
static error_t
|
|
|
|
argp_parser (int key, char *arg, struct argp_state *state)
|
2009-11-08 00:49:15 +00:00
|
|
|
{
|
2012-02-03 20:45:43 +00:00
|
|
|
/* Get the input argument from argp_parse, which we
|
|
|
|
know is a pointer to our arguments structure. */
|
|
|
|
struct arguments *arguments = state->input;
|
|
|
|
|
|
|
|
switch (key)
|
|
|
|
{
|
|
|
|
case ARGP_KEY_ARG:
|
|
|
|
if (state->arg_num == 0)
|
|
|
|
arguments->pathname = xstrdup (arg);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Too many arguments. */
|
|
|
|
fprintf (stderr, _("Unknown extra argument `%s'.\n"), arg);
|
|
|
|
argp_usage (state);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ARGP_KEY_NO_ARGS:
|
|
|
|
fprintf (stderr, "%s", _("No path is specified.\n"));
|
|
|
|
argp_usage (state);
|
|
|
|
exit (1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return ARGP_ERR_UNKNOWN;
|
|
|
|
}
|
|
|
|
return 0;
|
2009-11-08 00:49:15 +00:00
|
|
|
}
|
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
static struct argp argp = {
|
|
|
|
options, argp_parser, N_("PATH"),
|
2012-02-23 21:27:25 +00:00
|
|
|
N_("Transform a system filename into GRUB one."),
|
2012-02-03 20:45:43 +00:00
|
|
|
NULL, NULL, NULL
|
|
|
|
};
|
|
|
|
|
2009-11-08 00:49:15 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2012-02-03 20:45:43 +00:00
|
|
|
char *relpath;
|
|
|
|
struct arguments arguments;
|
2009-11-08 00:49:15 +00:00
|
|
|
|
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
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
memset (&arguments, 0, sizeof (struct arguments));
|
2009-11-08 00:49:15 +00:00
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
/* Check for options. */
|
|
|
|
if (argp_parse (&argp, argc, argv, 0, 0, &arguments) != 0)
|
2009-11-08 00:49:15 +00:00
|
|
|
{
|
2012-02-03 20:45:43 +00:00
|
|
|
fprintf (stderr, "%s", _("Error in parsing command line arguments\n"));
|
|
|
|
exit(1);
|
2009-11-08 00:49:15 +00:00
|
|
|
}
|
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
relpath = grub_make_system_path_relative_to_its_root (arguments.pathname);
|
2009-11-08 00:49:15 +00:00
|
|
|
printf ("%s\n", relpath);
|
|
|
|
free (relpath);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|