Merge mainline into newreloc
This commit is contained in:
commit
f0847685dd
26 changed files with 4939 additions and 29 deletions
52
ChangeLog
52
ChangeLog
|
@ -1,3 +1,55 @@
|
||||||
|
2010-04-03 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
|
MIPS multiboot2 support.
|
||||||
|
|
||||||
|
* conf/mips.rmk (pkglib_MODULES): Add multiboot2.mod.
|
||||||
|
(multiboot2_mod_SOURCES): New variable.
|
||||||
|
(multiboot2_mod_CFLAGS): Likewise.
|
||||||
|
(multiboot2_mod_LDFLAGS): Likewise.
|
||||||
|
(multiboot2_mod_ASFLAGS): Likewise.
|
||||||
|
* include/grub/i386/multiboot.h (MULTIBOOT_INITIAL_STATE): New
|
||||||
|
definition.
|
||||||
|
(MULTIBOOT_ENTRY_REGISTER): Likewise.
|
||||||
|
(MULTIBOOT_MBI_REGISTER): Likewise.
|
||||||
|
(MULTIBOOT_ARCHITECTURE_CURRENT): Likewise.
|
||||||
|
(MULTIBOOT_ELF32_MACHINE): Likewise.
|
||||||
|
(MULTIBOOT_ELF64_MACHINE): Likewise.
|
||||||
|
* include/grub/mips/multiboot.h: New file.
|
||||||
|
* include/grub/video.h (grub_video_driver_id): New type
|
||||||
|
GRUB_VIDEO_DRIVER_SM712.
|
||||||
|
(grub_video_get_info_and_fini): Export.
|
||||||
|
(grub_video_get_palette): Likewise.
|
||||||
|
(grub_video_get_driver_id): Likewise.
|
||||||
|
* include/multiboot2.h: Resynced with spec.
|
||||||
|
* loader/i386/multiboot.c: Moved from here ...
|
||||||
|
* loader/multiboot.c: ... here. All users updated.
|
||||||
|
(grub_multiboot_boot): Use platform-specific macros.
|
||||||
|
* loader/i386/multiboot_elfxx.c: Moved from here ...
|
||||||
|
* loader/multiboot_elfxx.c: ... here. All users updated.
|
||||||
|
(E_MACHINE): Use MULTIBOOT_ELF32_MACHINE and MULTIBOOT_ELF64_MACHINE.
|
||||||
|
* loader/i386/multiboot_mbi2.c (grub_multiboot_load): Check arcitecture.
|
||||||
|
* video/sm712.c (grub_video_sm712_adapter): Add missing id field.
|
||||||
|
|
||||||
|
2010-04-02 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
|
Import gnulib argp module.
|
||||||
|
|
||||||
|
* gnulib/argp-ba.c: New file.
|
||||||
|
* gnulib/argp-eexst.c: Likewise.
|
||||||
|
* gnulib/argp-fmtstream.c: Likewise.
|
||||||
|
* gnulib/argp-fmtstream.h: Likewise.
|
||||||
|
* gnulib/argp-fs-xinl.c: Likewise.
|
||||||
|
* gnulib/argp-help.c: Likewise.
|
||||||
|
* gnulib/argp-namefrob.h: Likewise.
|
||||||
|
* gnulib/argp-parse.c: Likewise.
|
||||||
|
* gnulib/argp-pin.c: Likewise.
|
||||||
|
* gnulib/argp-pv.c: Likewise.
|
||||||
|
* gnulib/argp-pvh.c: Likewise.
|
||||||
|
* gnulib/argp-version-etc.c: Likewise.
|
||||||
|
* gnulib/argp-version-etc.h: Likewise.
|
||||||
|
* gnulib/argp-xinl.c: Likewise.
|
||||||
|
* gnulib/argp.h: Likewise.
|
||||||
|
|
||||||
2010-03-31 Vladimir Serbinenko <phcoder@gmail.com>
|
2010-03-31 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
* kern/device.c (grub_device_iterate): Clear errors after failed
|
* kern/device.c (grub_device_iterate): Clear errors after failed
|
||||||
|
|
|
@ -61,15 +61,13 @@ setpci_mod_CFLAGS = $(COMMON_CFLAGS)
|
||||||
setpci_mod_LDFLAGS = $(COMMON_LDFLAGS)
|
setpci_mod_LDFLAGS = $(COMMON_LDFLAGS)
|
||||||
|
|
||||||
pkglib_MODULES += multiboot.mod
|
pkglib_MODULES += multiboot.mod
|
||||||
multiboot_mod_SOURCES = loader/i386/multiboot.c \
|
multiboot_mod_SOURCES = loader/multiboot.c loader/i386/multiboot_mbi.c
|
||||||
loader/i386/multiboot_mbi.c
|
|
||||||
multiboot_mod_CFLAGS = $(COMMON_CFLAGS)
|
multiboot_mod_CFLAGS = $(COMMON_CFLAGS)
|
||||||
multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
|
multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
|
||||||
multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS)
|
multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS)
|
||||||
|
|
||||||
pkglib_MODULES += multiboot2.mod
|
pkglib_MODULES += multiboot2.mod
|
||||||
multiboot2_mod_SOURCES = loader/i386/multiboot.c \
|
multiboot2_mod_SOURCES = loader/multiboot.c loader/multiboot_mbi2.c
|
||||||
loader/i386/multiboot_mbi2.c
|
|
||||||
multiboot2_mod_CFLAGS = $(COMMON_CFLAGS) -DGRUB_USE_MULTIBOOT2
|
multiboot2_mod_CFLAGS = $(COMMON_CFLAGS) -DGRUB_USE_MULTIBOOT2
|
||||||
multiboot2_mod_LDFLAGS = $(COMMON_LDFLAGS)
|
multiboot2_mod_LDFLAGS = $(COMMON_LDFLAGS)
|
||||||
multiboot2_mod_ASFLAGS = $(COMMON_ASFLAGS)
|
multiboot2_mod_ASFLAGS = $(COMMON_ASFLAGS)
|
||||||
|
|
|
@ -30,4 +30,11 @@ relocator_mod_CFLAGS = $(COMMON_CFLAGS)
|
||||||
relocator_mod_ASFLAGS = $(COMMON_ASFLAGS)
|
relocator_mod_ASFLAGS = $(COMMON_ASFLAGS)
|
||||||
relocator_mod_LDFLAGS = $(COMMON_LDFLAGS)
|
relocator_mod_LDFLAGS = $(COMMON_LDFLAGS)
|
||||||
|
|
||||||
|
pkglib_MODULES += multiboot2.mod
|
||||||
|
multiboot2_mod_SOURCES = loader/multiboot.c \
|
||||||
|
loader/multiboot_mbi2.c
|
||||||
|
multiboot2_mod_CFLAGS = $(COMMON_CFLAGS) -DGRUB_USE_MULTIBOOT2
|
||||||
|
multiboot2_mod_LDFLAGS = $(COMMON_LDFLAGS)
|
||||||
|
multiboot2_mod_ASFLAGS = $(COMMON_ASFLAGS)
|
||||||
|
|
||||||
include $(srcdir)/conf/common.mk
|
include $(srcdir)/conf/common.mk
|
||||||
|
|
34
gnulib/argp-ba.c
Normal file
34
gnulib/argp-ba.c
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/* Default definition for ARGP_PROGRAM_BUG_ADDRESS.
|
||||||
|
Copyright (C) 1996, 1997, 1999, 2009, 2010 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Written by Miles Bader <miles@gnu.ai.mit.edu>.
|
||||||
|
|
||||||
|
This program 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.
|
||||||
|
|
||||||
|
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
/* If set by the user program, it should point to string that is the
|
||||||
|
bug-reporting address for the program. It will be printed by argp_help if
|
||||||
|
the ARGP_HELP_BUG_ADDR flag is set (as it is by various standard help
|
||||||
|
messages), embedded in a sentence that says something like `Report bugs to
|
||||||
|
ADDR.'. */
|
||||||
|
const char *argp_program_bug_address
|
||||||
|
/* This variable should be zero-initialized. On most systems, putting it into
|
||||||
|
BSS is sufficient. Not so on MacOS X 10.3 and 10.4, see
|
||||||
|
<http://lists.gnu.org/archive/html/bug-gnulib/2009-01/msg00329.html>
|
||||||
|
<http://lists.gnu.org/archive/html/bug-gnulib/2009-08/msg00096.html>. */
|
||||||
|
#if defined __ELF__
|
||||||
|
/* On ELF systems, variables in BSS behave well. */
|
||||||
|
#else
|
||||||
|
= (const char *) 0
|
||||||
|
#endif
|
||||||
|
;
|
30
gnulib/argp-eexst.c
Normal file
30
gnulib/argp-eexst.c
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/* Default definition for ARGP_ERR_EXIT_STATUS
|
||||||
|
Copyright (C) 1997, 2009, 2010 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Written by Miles Bader <miles@gnu.ai.mit.edu>.
|
||||||
|
|
||||||
|
This program 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.
|
||||||
|
|
||||||
|
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <sysexits.h>
|
||||||
|
|
||||||
|
#include "argp.h"
|
||||||
|
|
||||||
|
/* The exit status that argp will use when exiting due to a parsing error.
|
||||||
|
If not defined or set by the user program, this defaults to EX_USAGE from
|
||||||
|
<sysexits.h>. */
|
||||||
|
error_t argp_err_exit_status = EX_USAGE;
|
435
gnulib/argp-fmtstream.c
Normal file
435
gnulib/argp-fmtstream.c
Normal file
|
@ -0,0 +1,435 @@
|
||||||
|
/* Word-wrapping and line-truncating streams
|
||||||
|
Copyright (C) 1997-1999, 2001-2003, 2005, 2009-2010 Free Software
|
||||||
|
Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Written by Miles Bader <miles@gnu.ai.mit.edu>.
|
||||||
|
|
||||||
|
This program 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.
|
||||||
|
|
||||||
|
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
/* This package emulates glibc `line_wrap_stream' semantics for systems that
|
||||||
|
don't have that. */
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#include "argp-fmtstream.h"
|
||||||
|
#include "argp-namefrob.h"
|
||||||
|
|
||||||
|
#ifndef ARGP_FMTSTREAM_USE_LINEWRAP
|
||||||
|
|
||||||
|
#ifndef isblank
|
||||||
|
#define isblank(ch) ((ch)==' ' || (ch)=='\t')
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined _LIBC && defined USE_IN_LIBIO
|
||||||
|
# include <wchar.h>
|
||||||
|
# include <libio/libioP.h>
|
||||||
|
# define __vsnprintf(s, l, f, a) _IO_vsnprintf (s, l, f, a)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define INIT_BUF_SIZE 200
|
||||||
|
#define PRINTF_SIZE_GUESS 150
|
||||||
|
|
||||||
|
/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines
|
||||||
|
written on it with LMARGIN spaces and limits them to RMARGIN columns
|
||||||
|
total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by
|
||||||
|
replacing the whitespace before them with a newline and WMARGIN spaces.
|
||||||
|
Otherwise, chars beyond RMARGIN are simply dropped until a newline.
|
||||||
|
Returns NULL if there was an error. */
|
||||||
|
argp_fmtstream_t
|
||||||
|
__argp_make_fmtstream (FILE *stream,
|
||||||
|
size_t lmargin, size_t rmargin, ssize_t wmargin)
|
||||||
|
{
|
||||||
|
argp_fmtstream_t fs;
|
||||||
|
|
||||||
|
fs = (struct argp_fmtstream *) malloc (sizeof (struct argp_fmtstream));
|
||||||
|
if (fs != NULL)
|
||||||
|
{
|
||||||
|
fs->stream = stream;
|
||||||
|
|
||||||
|
fs->lmargin = lmargin;
|
||||||
|
fs->rmargin = rmargin;
|
||||||
|
fs->wmargin = wmargin;
|
||||||
|
fs->point_col = 0;
|
||||||
|
fs->point_offs = 0;
|
||||||
|
|
||||||
|
fs->buf = (char *) malloc (INIT_BUF_SIZE);
|
||||||
|
if (! fs->buf)
|
||||||
|
{
|
||||||
|
free (fs);
|
||||||
|
fs = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fs->p = fs->buf;
|
||||||
|
fs->end = fs->buf + INIT_BUF_SIZE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fs;
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
|
/* Not exported. */
|
||||||
|
#ifdef weak_alias
|
||||||
|
weak_alias (__argp_make_fmtstream, argp_make_fmtstream)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Flush FS to its stream, and free it (but don't close the stream). */
|
||||||
|
void
|
||||||
|
__argp_fmtstream_free (argp_fmtstream_t fs)
|
||||||
|
{
|
||||||
|
__argp_fmtstream_update (fs);
|
||||||
|
if (fs->p > fs->buf)
|
||||||
|
{
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
__fxprintf (fs->stream, "%.*s", (int) (fs->p - fs->buf), fs->buf);
|
||||||
|
#else
|
||||||
|
fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
free (fs->buf);
|
||||||
|
free (fs);
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
|
/* Not exported. */
|
||||||
|
#ifdef weak_alias
|
||||||
|
weak_alias (__argp_fmtstream_free, argp_fmtstream_free)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Process FS's buffer so that line wrapping is done from POINT_OFFS to the
|
||||||
|
end of its buffer. This code is mostly from glibc stdio/linewrap.c. */
|
||||||
|
void
|
||||||
|
__argp_fmtstream_update (argp_fmtstream_t fs)
|
||||||
|
{
|
||||||
|
char *buf, *nl;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
/* Scan the buffer for newlines. */
|
||||||
|
buf = fs->buf + fs->point_offs;
|
||||||
|
while (buf < fs->p)
|
||||||
|
{
|
||||||
|
size_t r;
|
||||||
|
|
||||||
|
if (fs->point_col == 0 && fs->lmargin != 0)
|
||||||
|
{
|
||||||
|
/* We are starting a new line. Print spaces to the left margin. */
|
||||||
|
const size_t pad = fs->lmargin;
|
||||||
|
if (fs->p + pad < fs->end)
|
||||||
|
{
|
||||||
|
/* We can fit in them in the buffer by moving the
|
||||||
|
buffer text up and filling in the beginning. */
|
||||||
|
memmove (buf + pad, buf, fs->p - buf);
|
||||||
|
fs->p += pad; /* Compensate for bigger buffer. */
|
||||||
|
memset (buf, ' ', pad); /* Fill in the spaces. */
|
||||||
|
buf += pad; /* Don't bother searching them. */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* No buffer space for spaces. Must flush. */
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < pad; i++)
|
||||||
|
{
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
if (_IO_fwide (fs->stream, 0) > 0)
|
||||||
|
putwc_unlocked (L' ', fs->stream);
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
putc_unlocked (' ', fs->stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fs->point_col = pad;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = fs->p - buf;
|
||||||
|
nl = memchr (buf, '\n', len);
|
||||||
|
|
||||||
|
if (fs->point_col < 0)
|
||||||
|
fs->point_col = 0;
|
||||||
|
|
||||||
|
if (!nl)
|
||||||
|
{
|
||||||
|
/* The buffer ends in a partial line. */
|
||||||
|
|
||||||
|
if (fs->point_col + len < fs->rmargin)
|
||||||
|
{
|
||||||
|
/* The remaining buffer text is a partial line and fits
|
||||||
|
within the maximum line width. Advance point for the
|
||||||
|
characters to be written and stop scanning. */
|
||||||
|
fs->point_col += len;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
/* Set the end-of-line pointer for the code below to
|
||||||
|
the end of the buffer. */
|
||||||
|
nl = fs->p;
|
||||||
|
}
|
||||||
|
else if (fs->point_col + (nl - buf) < (ssize_t) fs->rmargin)
|
||||||
|
{
|
||||||
|
/* The buffer contains a full line that fits within the maximum
|
||||||
|
line width. Reset point and scan the next line. */
|
||||||
|
fs->point_col = 0;
|
||||||
|
buf = nl + 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This line is too long. */
|
||||||
|
r = fs->rmargin - 1;
|
||||||
|
|
||||||
|
if (fs->wmargin < 0)
|
||||||
|
{
|
||||||
|
/* Truncate the line by overwriting the excess with the
|
||||||
|
newline and anything after it in the buffer. */
|
||||||
|
if (nl < fs->p)
|
||||||
|
{
|
||||||
|
memmove (buf + (r - fs->point_col), nl, fs->p - nl);
|
||||||
|
fs->p -= buf + (r - fs->point_col) - nl;
|
||||||
|
/* Reset point for the next line and start scanning it. */
|
||||||
|
fs->point_col = 0;
|
||||||
|
buf += r + 1; /* Skip full line plus \n. */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* The buffer ends with a partial line that is beyond the
|
||||||
|
maximum line width. Advance point for the characters
|
||||||
|
written, and discard those past the max from the buffer. */
|
||||||
|
fs->point_col += len;
|
||||||
|
fs->p -= fs->point_col - r;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Do word wrap. Go to the column just past the maximum line
|
||||||
|
width and scan back for the beginning of the word there.
|
||||||
|
Then insert a line break. */
|
||||||
|
|
||||||
|
char *p, *nextline;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
p = buf + (r + 1 - fs->point_col);
|
||||||
|
while (p >= buf && !isblank ((unsigned char) *p))
|
||||||
|
--p;
|
||||||
|
nextline = p + 1; /* This will begin the next line. */
|
||||||
|
|
||||||
|
if (nextline > buf)
|
||||||
|
{
|
||||||
|
/* Swallow separating blanks. */
|
||||||
|
if (p >= buf)
|
||||||
|
do
|
||||||
|
--p;
|
||||||
|
while (p >= buf && isblank ((unsigned char) *p));
|
||||||
|
nl = p + 1; /* The newline will replace the first blank. */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* A single word that is greater than the maximum line width.
|
||||||
|
Oh well. Put it on an overlong line by itself. */
|
||||||
|
p = buf + (r + 1 - fs->point_col);
|
||||||
|
/* Find the end of the long word. */
|
||||||
|
if (p < nl)
|
||||||
|
do
|
||||||
|
++p;
|
||||||
|
while (p < nl && !isblank ((unsigned char) *p));
|
||||||
|
if (p == nl)
|
||||||
|
{
|
||||||
|
/* It already ends a line. No fussing required. */
|
||||||
|
fs->point_col = 0;
|
||||||
|
buf = nl + 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
/* We will move the newline to replace the first blank. */
|
||||||
|
nl = p;
|
||||||
|
/* Swallow separating blanks. */
|
||||||
|
do
|
||||||
|
++p;
|
||||||
|
while (isblank ((unsigned char) *p));
|
||||||
|
/* The next line will start here. */
|
||||||
|
nextline = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Note: There are a bunch of tests below for
|
||||||
|
NEXTLINE == BUF + LEN + 1; this case is where NL happens to fall
|
||||||
|
at the end of the buffer, and NEXTLINE is in fact empty (and so
|
||||||
|
we need not be careful to maintain its contents). */
|
||||||
|
|
||||||
|
if ((nextline == buf + len + 1
|
||||||
|
? fs->end - nl < fs->wmargin + 1
|
||||||
|
: nextline - (nl + 1) < fs->wmargin)
|
||||||
|
&& fs->p > nextline)
|
||||||
|
{
|
||||||
|
/* The margin needs more blanks than we removed. */
|
||||||
|
if (fs->end - fs->p > fs->wmargin + 1)
|
||||||
|
/* Make some space for them. */
|
||||||
|
{
|
||||||
|
size_t mv = fs->p - nextline;
|
||||||
|
memmove (nl + 1 + fs->wmargin, nextline, mv);
|
||||||
|
nextline = nl + 1 + fs->wmargin;
|
||||||
|
len = nextline + mv - buf;
|
||||||
|
*nl++ = '\n';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
/* Output the first line so we can use the space. */
|
||||||
|
{
|
||||||
|
#ifdef _LIBC
|
||||||
|
__fxprintf (fs->stream, "%.*s\n",
|
||||||
|
(int) (nl - fs->buf), fs->buf);
|
||||||
|
#else
|
||||||
|
if (nl > fs->buf)
|
||||||
|
fwrite_unlocked (fs->buf, 1, nl - fs->buf, fs->stream);
|
||||||
|
putc_unlocked ('\n', fs->stream);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
len += buf - fs->buf;
|
||||||
|
nl = buf = fs->buf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
/* We can fit the newline and blanks in before
|
||||||
|
the next word. */
|
||||||
|
*nl++ = '\n';
|
||||||
|
|
||||||
|
if (nextline - nl >= fs->wmargin
|
||||||
|
|| (nextline == buf + len + 1 && fs->end - nextline >= fs->wmargin))
|
||||||
|
/* Add blanks up to the wrap margin column. */
|
||||||
|
for (i = 0; i < fs->wmargin; ++i)
|
||||||
|
*nl++ = ' ';
|
||||||
|
else
|
||||||
|
for (i = 0; i < fs->wmargin; ++i)
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
if (_IO_fwide (fs->stream, 0) > 0)
|
||||||
|
putwc_unlocked (L' ', fs->stream);
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
putc_unlocked (' ', fs->stream);
|
||||||
|
|
||||||
|
/* Copy the tail of the original buffer into the current buffer
|
||||||
|
position. */
|
||||||
|
if (nl < nextline)
|
||||||
|
memmove (nl, nextline, buf + len - nextline);
|
||||||
|
len -= nextline - buf;
|
||||||
|
|
||||||
|
/* Continue the scan on the remaining lines in the buffer. */
|
||||||
|
buf = nl;
|
||||||
|
|
||||||
|
/* Restore bufp to include all the remaining text. */
|
||||||
|
fs->p = nl + len;
|
||||||
|
|
||||||
|
/* Reset the counter of what has been output this line. If wmargin
|
||||||
|
is 0, we want to avoid the lmargin getting added, so we set
|
||||||
|
point_col to a magic value of -1 in that case. */
|
||||||
|
fs->point_col = fs->wmargin ? fs->wmargin : -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remember that we've scanned as far as the end of the buffer. */
|
||||||
|
fs->point_offs = fs->p - fs->buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Ensure that FS has space for AMOUNT more bytes in its buffer, either by
|
||||||
|
growing the buffer, or by flushing it. True is returned iff we succeed. */
|
||||||
|
int
|
||||||
|
__argp_fmtstream_ensure (struct argp_fmtstream *fs, size_t amount)
|
||||||
|
{
|
||||||
|
if ((size_t) (fs->end - fs->p) < amount)
|
||||||
|
{
|
||||||
|
ssize_t wrote;
|
||||||
|
|
||||||
|
/* Flush FS's buffer. */
|
||||||
|
__argp_fmtstream_update (fs);
|
||||||
|
|
||||||
|
#ifdef _LIBC
|
||||||
|
__fxprintf (fs->stream, "%.*s", (int) (fs->p - fs->buf), fs->buf);
|
||||||
|
wrote = fs->p - fs->buf;
|
||||||
|
#else
|
||||||
|
wrote = fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream);
|
||||||
|
#endif
|
||||||
|
if (wrote == fs->p - fs->buf)
|
||||||
|
{
|
||||||
|
fs->p = fs->buf;
|
||||||
|
fs->point_offs = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fs->p -= wrote;
|
||||||
|
fs->point_offs -= wrote;
|
||||||
|
memmove (fs->buf, fs->buf + wrote, fs->p - fs->buf);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((size_t) (fs->end - fs->buf) < amount)
|
||||||
|
/* Gotta grow the buffer. */
|
||||||
|
{
|
||||||
|
size_t old_size = fs->end - fs->buf;
|
||||||
|
size_t new_size = old_size + amount;
|
||||||
|
char *new_buf;
|
||||||
|
|
||||||
|
if (new_size < old_size || ! (new_buf = realloc (fs->buf, new_size)))
|
||||||
|
{
|
||||||
|
__set_errno (ENOMEM);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
fs->buf = new_buf;
|
||||||
|
fs->end = new_buf + new_size;
|
||||||
|
fs->p = fs->buf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t
|
||||||
|
__argp_fmtstream_printf (struct argp_fmtstream *fs, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
int out;
|
||||||
|
size_t avail;
|
||||||
|
size_t size_guess = PRINTF_SIZE_GUESS; /* How much space to reserve. */
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
|
||||||
|
if (! __argp_fmtstream_ensure (fs, size_guess))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
va_start (args, fmt);
|
||||||
|
avail = fs->end - fs->p;
|
||||||
|
out = __vsnprintf (fs->p, avail, fmt, args);
|
||||||
|
va_end (args);
|
||||||
|
if ((size_t) out >= avail)
|
||||||
|
size_guess = out + 1;
|
||||||
|
}
|
||||||
|
while ((size_t) out >= avail);
|
||||||
|
|
||||||
|
fs->p += out;
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
|
/* Not exported. */
|
||||||
|
#ifdef weak_alias
|
||||||
|
weak_alias (__argp_fmtstream_printf, argp_fmtstream_printf)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* !ARGP_FMTSTREAM_USE_LINEWRAP */
|
354
gnulib/argp-fmtstream.h
Normal file
354
gnulib/argp-fmtstream.h
Normal file
|
@ -0,0 +1,354 @@
|
||||||
|
/* Word-wrapping and line-truncating streams.
|
||||||
|
Copyright (C) 1997, 2006-2010 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Written by Miles Bader <miles@gnu.ai.mit.edu>.
|
||||||
|
|
||||||
|
This program 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.
|
||||||
|
|
||||||
|
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
/* This package emulates glibc `line_wrap_stream' semantics for systems that
|
||||||
|
don't have that. If the system does have it, it is just a wrapper for
|
||||||
|
that. This header file is only used internally while compiling argp, and
|
||||||
|
shouldn't be installed. */
|
||||||
|
|
||||||
|
#ifndef _ARGP_FMTSTREAM_H
|
||||||
|
#define _ARGP_FMTSTREAM_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#ifndef __attribute__
|
||||||
|
/* The __attribute__ feature is available in gcc versions 2.5 and later.
|
||||||
|
The __-protected variants of the attributes 'format' and 'printf' are
|
||||||
|
accepted by gcc versions 2.6.4 (effectively 2.7) and later.
|
||||||
|
We enable __attribute__ only if these are supported too, because
|
||||||
|
gnulib and libintl do '#define printf __printf__' when they override
|
||||||
|
the 'printf' function. */
|
||||||
|
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
|
||||||
|
# define __attribute__(Spec) /* empty */
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (_LIBC - 0 && !defined (USE_IN_LIBIO)) \
|
||||||
|
|| (defined (__GNU_LIBRARY__) && defined (HAVE_LINEWRAP_H))
|
||||||
|
/* line_wrap_stream is available, so use that. */
|
||||||
|
#define ARGP_FMTSTREAM_USE_LINEWRAP
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef ARGP_FMTSTREAM_USE_LINEWRAP
|
||||||
|
/* Just be a simple wrapper for line_wrap_stream; the semantics are
|
||||||
|
*slightly* different, as line_wrap_stream doesn't actually make a new
|
||||||
|
object, it just modifies the given stream (reversibly) to do
|
||||||
|
line-wrapping. Since we control who uses this code, it doesn't matter. */
|
||||||
|
|
||||||
|
#include <linewrap.h>
|
||||||
|
|
||||||
|
typedef FILE *argp_fmtstream_t;
|
||||||
|
|
||||||
|
#define argp_make_fmtstream line_wrap_stream
|
||||||
|
#define __argp_make_fmtstream line_wrap_stream
|
||||||
|
#define argp_fmtstream_free line_unwrap_stream
|
||||||
|
#define __argp_fmtstream_free line_unwrap_stream
|
||||||
|
|
||||||
|
#define __argp_fmtstream_putc(fs,ch) putc(ch,fs)
|
||||||
|
#define argp_fmtstream_putc(fs,ch) putc(ch,fs)
|
||||||
|
#define __argp_fmtstream_puts(fs,str) fputs(str,fs)
|
||||||
|
#define argp_fmtstream_puts(fs,str) fputs(str,fs)
|
||||||
|
#define __argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs)
|
||||||
|
#define argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs)
|
||||||
|
#define __argp_fmtstream_printf fprintf
|
||||||
|
#define argp_fmtstream_printf fprintf
|
||||||
|
|
||||||
|
#define __argp_fmtstream_lmargin line_wrap_lmargin
|
||||||
|
#define argp_fmtstream_lmargin line_wrap_lmargin
|
||||||
|
#define __argp_fmtstream_set_lmargin line_wrap_set_lmargin
|
||||||
|
#define argp_fmtstream_set_lmargin line_wrap_set_lmargin
|
||||||
|
#define __argp_fmtstream_rmargin line_wrap_rmargin
|
||||||
|
#define argp_fmtstream_rmargin line_wrap_rmargin
|
||||||
|
#define __argp_fmtstream_set_rmargin line_wrap_set_rmargin
|
||||||
|
#define argp_fmtstream_set_rmargin line_wrap_set_rmargin
|
||||||
|
#define __argp_fmtstream_wmargin line_wrap_wmargin
|
||||||
|
#define argp_fmtstream_wmargin line_wrap_wmargin
|
||||||
|
#define __argp_fmtstream_set_wmargin line_wrap_set_wmargin
|
||||||
|
#define argp_fmtstream_set_wmargin line_wrap_set_wmargin
|
||||||
|
#define __argp_fmtstream_point line_wrap_point
|
||||||
|
#define argp_fmtstream_point line_wrap_point
|
||||||
|
|
||||||
|
#else /* !ARGP_FMTSTREAM_USE_LINEWRAP */
|
||||||
|
/* Guess we have to define our own version. */
|
||||||
|
|
||||||
|
struct argp_fmtstream
|
||||||
|
{
|
||||||
|
FILE *stream; /* The stream we're outputting to. */
|
||||||
|
|
||||||
|
size_t lmargin, rmargin; /* Left and right margins. */
|
||||||
|
ssize_t wmargin; /* Margin to wrap to, or -1 to truncate. */
|
||||||
|
|
||||||
|
/* Point in buffer to which we've processed for wrapping, but not output. */
|
||||||
|
size_t point_offs;
|
||||||
|
/* Output column at POINT_OFFS, or -1 meaning 0 but don't add lmargin. */
|
||||||
|
ssize_t point_col;
|
||||||
|
|
||||||
|
char *buf; /* Output buffer. */
|
||||||
|
char *p; /* Current end of text in BUF. */
|
||||||
|
char *end; /* Absolute end of BUF. */
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct argp_fmtstream *argp_fmtstream_t;
|
||||||
|
|
||||||
|
/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines
|
||||||
|
written on it with LMARGIN spaces and limits them to RMARGIN columns
|
||||||
|
total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by
|
||||||
|
replacing the whitespace before them with a newline and WMARGIN spaces.
|
||||||
|
Otherwise, chars beyond RMARGIN are simply dropped until a newline.
|
||||||
|
Returns NULL if there was an error. */
|
||||||
|
extern argp_fmtstream_t __argp_make_fmtstream (FILE *__stream,
|
||||||
|
size_t __lmargin,
|
||||||
|
size_t __rmargin,
|
||||||
|
ssize_t __wmargin);
|
||||||
|
extern argp_fmtstream_t argp_make_fmtstream (FILE *__stream,
|
||||||
|
size_t __lmargin,
|
||||||
|
size_t __rmargin,
|
||||||
|
ssize_t __wmargin);
|
||||||
|
|
||||||
|
/* Flush __FS to its stream, and free it (but don't close the stream). */
|
||||||
|
extern void __argp_fmtstream_free (argp_fmtstream_t __fs);
|
||||||
|
extern void argp_fmtstream_free (argp_fmtstream_t __fs);
|
||||||
|
|
||||||
|
extern ssize_t __argp_fmtstream_printf (argp_fmtstream_t __fs,
|
||||||
|
const char *__fmt, ...)
|
||||||
|
__attribute__ ((__format__ (printf, 2, 3)));
|
||||||
|
extern ssize_t argp_fmtstream_printf (argp_fmtstream_t __fs,
|
||||||
|
const char *__fmt, ...)
|
||||||
|
__attribute__ ((__format__ (printf, 2, 3)));
|
||||||
|
|
||||||
|
#if _LIBC || !defined __OPTIMIZE__
|
||||||
|
extern int __argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch);
|
||||||
|
extern int argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch);
|
||||||
|
|
||||||
|
extern int __argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str);
|
||||||
|
extern int argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str);
|
||||||
|
|
||||||
|
extern size_t __argp_fmtstream_write (argp_fmtstream_t __fs,
|
||||||
|
const char *__str, size_t __len);
|
||||||
|
extern size_t argp_fmtstream_write (argp_fmtstream_t __fs,
|
||||||
|
const char *__str, size_t __len);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Access macros for various bits of state. */
|
||||||
|
#define argp_fmtstream_lmargin(__fs) ((__fs)->lmargin)
|
||||||
|
#define argp_fmtstream_rmargin(__fs) ((__fs)->rmargin)
|
||||||
|
#define argp_fmtstream_wmargin(__fs) ((__fs)->wmargin)
|
||||||
|
#define __argp_fmtstream_lmargin argp_fmtstream_lmargin
|
||||||
|
#define __argp_fmtstream_rmargin argp_fmtstream_rmargin
|
||||||
|
#define __argp_fmtstream_wmargin argp_fmtstream_wmargin
|
||||||
|
|
||||||
|
#if _LIBC || !defined __OPTIMIZE__
|
||||||
|
/* Set __FS's left margin to LMARGIN and return the old value. */
|
||||||
|
extern size_t argp_fmtstream_set_lmargin (argp_fmtstream_t __fs,
|
||||||
|
size_t __lmargin);
|
||||||
|
extern size_t __argp_fmtstream_set_lmargin (argp_fmtstream_t __fs,
|
||||||
|
size_t __lmargin);
|
||||||
|
|
||||||
|
/* Set __FS's right margin to __RMARGIN and return the old value. */
|
||||||
|
extern size_t argp_fmtstream_set_rmargin (argp_fmtstream_t __fs,
|
||||||
|
size_t __rmargin);
|
||||||
|
extern size_t __argp_fmtstream_set_rmargin (argp_fmtstream_t __fs,
|
||||||
|
size_t __rmargin);
|
||||||
|
|
||||||
|
/* Set __FS's wrap margin to __WMARGIN and return the old value. */
|
||||||
|
extern size_t argp_fmtstream_set_wmargin (argp_fmtstream_t __fs,
|
||||||
|
size_t __wmargin);
|
||||||
|
extern size_t __argp_fmtstream_set_wmargin (argp_fmtstream_t __fs,
|
||||||
|
size_t __wmargin);
|
||||||
|
|
||||||
|
/* Return the column number of the current output point in __FS. */
|
||||||
|
extern size_t argp_fmtstream_point (argp_fmtstream_t __fs);
|
||||||
|
extern size_t __argp_fmtstream_point (argp_fmtstream_t __fs);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Internal routines. */
|
||||||
|
extern void _argp_fmtstream_update (argp_fmtstream_t __fs);
|
||||||
|
extern void __argp_fmtstream_update (argp_fmtstream_t __fs);
|
||||||
|
extern int _argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount);
|
||||||
|
extern int __argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount);
|
||||||
|
|
||||||
|
#ifdef __OPTIMIZE__
|
||||||
|
/* Inline versions of above routines. */
|
||||||
|
|
||||||
|
#if !_LIBC
|
||||||
|
#define __argp_fmtstream_putc argp_fmtstream_putc
|
||||||
|
#define __argp_fmtstream_puts argp_fmtstream_puts
|
||||||
|
#define __argp_fmtstream_write argp_fmtstream_write
|
||||||
|
#define __argp_fmtstream_set_lmargin argp_fmtstream_set_lmargin
|
||||||
|
#define __argp_fmtstream_set_rmargin argp_fmtstream_set_rmargin
|
||||||
|
#define __argp_fmtstream_set_wmargin argp_fmtstream_set_wmargin
|
||||||
|
#define __argp_fmtstream_point argp_fmtstream_point
|
||||||
|
#define __argp_fmtstream_update _argp_fmtstream_update
|
||||||
|
#define __argp_fmtstream_ensure _argp_fmtstream_ensure
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef ARGP_FS_EI
|
||||||
|
# ifdef __GNUC__
|
||||||
|
/* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
|
||||||
|
inline semantics, unless -fgnu89-inline is used. It defines a macro
|
||||||
|
__GNUC_STDC_INLINE__ to indicate this situation or a macro
|
||||||
|
__GNUC_GNU_INLINE__ to indicate the opposite situation.
|
||||||
|
|
||||||
|
GCC 4.2 with -std=c99 or -std=gnu99 implements the GNU C inline
|
||||||
|
semantics but warns, unless -fgnu89-inline is used:
|
||||||
|
warning: C99 inline functions are not supported; using GNU89
|
||||||
|
warning: to disable this warning use -fgnu89-inline or the gnu_inline function attribute
|
||||||
|
It defines a macro __GNUC_GNU_INLINE__ to indicate this situation.
|
||||||
|
|
||||||
|
Whereas Apple GCC 4.0.1 build 5479 without -std=c99 or -std=gnu99
|
||||||
|
implements the GNU C inline semantics and defines the macro
|
||||||
|
__GNUC_GNU_INLINE__, but it does not warn and does not support
|
||||||
|
__attribute__ ((__gnu_inline__)).
|
||||||
|
|
||||||
|
All in all, these are the possible combinations. For every compiler,
|
||||||
|
we need to choose ARGP_FS_EI so that the corresponding table cell
|
||||||
|
contains an "ok".
|
||||||
|
|
||||||
|
\ ARGP_FS_EI inline extern extern
|
||||||
|
\ inline inline
|
||||||
|
CC \ __attribute__
|
||||||
|
((gnu_inline))
|
||||||
|
|
||||||
|
gcc 4.3.0 error ok ok
|
||||||
|
gcc 4.3.0 -std=gnu99 -fgnu89-inline error ok ok
|
||||||
|
gcc 4.3.0 -std=gnu99 ok error ok
|
||||||
|
|
||||||
|
gcc 4.2.2 error ok ok
|
||||||
|
gcc 4.2.2 -std=gnu99 -fgnu89-inline error ok ok
|
||||||
|
gcc 4.2.2 -std=gnu99 error warning ok
|
||||||
|
|
||||||
|
gcc 4.1.2 error ok warning
|
||||||
|
gcc 4.1.2 -std=gnu99 error ok warning
|
||||||
|
|
||||||
|
Apple gcc 4.0.1 error ok warning
|
||||||
|
Apple gcc 4.0.1 -std=gnu99 ok error warning
|
||||||
|
*/
|
||||||
|
# if defined __GNUC_STDC_INLINE__
|
||||||
|
# define ARGP_FS_EI inline
|
||||||
|
# elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)
|
||||||
|
# define ARGP_FS_EI extern inline __attribute__ ((__gnu_inline__))
|
||||||
|
# else
|
||||||
|
# define ARGP_FS_EI extern inline
|
||||||
|
# endif
|
||||||
|
# else
|
||||||
|
/* With other compilers, assume the ISO C99 meaning of 'inline', if
|
||||||
|
the compiler supports 'inline' at all. */
|
||||||
|
# define ARGP_FS_EI inline
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ARGP_FS_EI size_t
|
||||||
|
__argp_fmtstream_write (argp_fmtstream_t __fs,
|
||||||
|
const char *__str, size_t __len)
|
||||||
|
{
|
||||||
|
if (__fs->p + __len <= __fs->end || __argp_fmtstream_ensure (__fs, __len))
|
||||||
|
{
|
||||||
|
memcpy (__fs->p, __str, __len);
|
||||||
|
__fs->p += __len;
|
||||||
|
return __len;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ARGP_FS_EI int
|
||||||
|
__argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str)
|
||||||
|
{
|
||||||
|
size_t __len = strlen (__str);
|
||||||
|
if (__len)
|
||||||
|
{
|
||||||
|
size_t __wrote = __argp_fmtstream_write (__fs, __str, __len);
|
||||||
|
return __wrote == __len ? 0 : -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ARGP_FS_EI int
|
||||||
|
__argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch)
|
||||||
|
{
|
||||||
|
if (__fs->p < __fs->end || __argp_fmtstream_ensure (__fs, 1))
|
||||||
|
return *__fs->p++ = __ch;
|
||||||
|
else
|
||||||
|
return EOF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set __FS's left margin to __LMARGIN and return the old value. */
|
||||||
|
ARGP_FS_EI size_t
|
||||||
|
__argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, size_t __lmargin)
|
||||||
|
{
|
||||||
|
size_t __old;
|
||||||
|
if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
|
||||||
|
__argp_fmtstream_update (__fs);
|
||||||
|
__old = __fs->lmargin;
|
||||||
|
__fs->lmargin = __lmargin;
|
||||||
|
return __old;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set __FS's right margin to __RMARGIN and return the old value. */
|
||||||
|
ARGP_FS_EI size_t
|
||||||
|
__argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, size_t __rmargin)
|
||||||
|
{
|
||||||
|
size_t __old;
|
||||||
|
if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
|
||||||
|
__argp_fmtstream_update (__fs);
|
||||||
|
__old = __fs->rmargin;
|
||||||
|
__fs->rmargin = __rmargin;
|
||||||
|
return __old;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set FS's wrap margin to __WMARGIN and return the old value. */
|
||||||
|
ARGP_FS_EI size_t
|
||||||
|
__argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, size_t __wmargin)
|
||||||
|
{
|
||||||
|
size_t __old;
|
||||||
|
if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
|
||||||
|
__argp_fmtstream_update (__fs);
|
||||||
|
__old = __fs->wmargin;
|
||||||
|
__fs->wmargin = __wmargin;
|
||||||
|
return __old;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return the column number of the current output point in __FS. */
|
||||||
|
ARGP_FS_EI size_t
|
||||||
|
__argp_fmtstream_point (argp_fmtstream_t __fs)
|
||||||
|
{
|
||||||
|
if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
|
||||||
|
__argp_fmtstream_update (__fs);
|
||||||
|
return __fs->point_col >= 0 ? __fs->point_col : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !_LIBC
|
||||||
|
#undef __argp_fmtstream_putc
|
||||||
|
#undef __argp_fmtstream_puts
|
||||||
|
#undef __argp_fmtstream_write
|
||||||
|
#undef __argp_fmtstream_set_lmargin
|
||||||
|
#undef __argp_fmtstream_set_rmargin
|
||||||
|
#undef __argp_fmtstream_set_wmargin
|
||||||
|
#undef __argp_fmtstream_point
|
||||||
|
#undef __argp_fmtstream_update
|
||||||
|
#undef __argp_fmtstream_ensure
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __OPTIMIZE__ */
|
||||||
|
|
||||||
|
#endif /* ARGP_FMTSTREAM_USE_LINEWRAP */
|
||||||
|
|
||||||
|
#endif /* argp-fmtstream.h */
|
42
gnulib/argp-fs-xinl.c
Normal file
42
gnulib/argp-fs-xinl.c
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
/* Real definitions for extern inline functions in argp-fmtstream.h
|
||||||
|
Copyright (C) 1997, 2003, 2004, 2009, 2010 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Written by Miles Bader <miles@gnu.ai.mit.edu>.
|
||||||
|
|
||||||
|
This program 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.
|
||||||
|
|
||||||
|
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define ARGP_FS_EI
|
||||||
|
#undef __OPTIMIZE__
|
||||||
|
#define __OPTIMIZE__ 1
|
||||||
|
#include "argp-fmtstream.h"
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/* Not exported. */
|
||||||
|
/* Add weak aliases. */
|
||||||
|
#if _LIBC - 0 && !defined (ARGP_FMTSTREAM_USE_LINEWRAP) && defined (weak_alias)
|
||||||
|
|
||||||
|
weak_alias (__argp_fmtstream_putc, argp_fmtstream_putc)
|
||||||
|
weak_alias (__argp_fmtstream_puts, argp_fmtstream_puts)
|
||||||
|
weak_alias (__argp_fmtstream_write, argp_fmtstream_write)
|
||||||
|
weak_alias (__argp_fmtstream_set_lmargin, argp_fmtstream_set_lmargin)
|
||||||
|
weak_alias (__argp_fmtstream_set_rmargin, argp_fmtstream_set_rmargin)
|
||||||
|
weak_alias (__argp_fmtstream_set_wmargin, argp_fmtstream_set_wmargin)
|
||||||
|
weak_alias (__argp_fmtstream_point, argp_fmtstream_point)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#endif
|
1951
gnulib/argp-help.c
Normal file
1951
gnulib/argp-help.c
Normal file
File diff suppressed because it is too large
Load diff
157
gnulib/argp-namefrob.h
Normal file
157
gnulib/argp-namefrob.h
Normal file
|
@ -0,0 +1,157 @@
|
||||||
|
/* Name frobnication for compiling argp outside of glibc
|
||||||
|
Copyright (C) 1997, 2003, 2007, 2009, 2010 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Written by Miles Bader <miles@gnu.ai.mit.edu>.
|
||||||
|
|
||||||
|
This program 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.
|
||||||
|
|
||||||
|
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
#if !_LIBC
|
||||||
|
/* This code is written for inclusion in gnu-libc, and uses names in the
|
||||||
|
namespace reserved for libc. If we're not compiling in libc, define those
|
||||||
|
names to be the normal ones instead. */
|
||||||
|
|
||||||
|
/* argp-parse functions */
|
||||||
|
#undef __argp_parse
|
||||||
|
#define __argp_parse argp_parse
|
||||||
|
#undef __option_is_end
|
||||||
|
#define __option_is_end _option_is_end
|
||||||
|
#undef __option_is_short
|
||||||
|
#define __option_is_short _option_is_short
|
||||||
|
#undef __argp_input
|
||||||
|
#define __argp_input _argp_input
|
||||||
|
|
||||||
|
/* argp-help functions */
|
||||||
|
#undef __argp_help
|
||||||
|
#define __argp_help argp_help
|
||||||
|
#undef __argp_error
|
||||||
|
#define __argp_error argp_error
|
||||||
|
#undef __argp_failure
|
||||||
|
#define __argp_failure argp_failure
|
||||||
|
#undef __argp_state_help
|
||||||
|
#define __argp_state_help argp_state_help
|
||||||
|
#undef __argp_usage
|
||||||
|
#define __argp_usage argp_usage
|
||||||
|
|
||||||
|
/* argp-fmtstream functions */
|
||||||
|
#undef __argp_make_fmtstream
|
||||||
|
#define __argp_make_fmtstream argp_make_fmtstream
|
||||||
|
#undef __argp_fmtstream_free
|
||||||
|
#define __argp_fmtstream_free argp_fmtstream_free
|
||||||
|
#undef __argp_fmtstream_putc
|
||||||
|
#define __argp_fmtstream_putc argp_fmtstream_putc
|
||||||
|
#undef __argp_fmtstream_puts
|
||||||
|
#define __argp_fmtstream_puts argp_fmtstream_puts
|
||||||
|
#undef __argp_fmtstream_write
|
||||||
|
#define __argp_fmtstream_write argp_fmtstream_write
|
||||||
|
#undef __argp_fmtstream_printf
|
||||||
|
#define __argp_fmtstream_printf argp_fmtstream_printf
|
||||||
|
#undef __argp_fmtstream_set_lmargin
|
||||||
|
#define __argp_fmtstream_set_lmargin argp_fmtstream_set_lmargin
|
||||||
|
#undef __argp_fmtstream_set_rmargin
|
||||||
|
#define __argp_fmtstream_set_rmargin argp_fmtstream_set_rmargin
|
||||||
|
#undef __argp_fmtstream_set_wmargin
|
||||||
|
#define __argp_fmtstream_set_wmargin argp_fmtstream_set_wmargin
|
||||||
|
#undef __argp_fmtstream_point
|
||||||
|
#define __argp_fmtstream_point argp_fmtstream_point
|
||||||
|
#undef __argp_fmtstream_update
|
||||||
|
#define __argp_fmtstream_update _argp_fmtstream_update
|
||||||
|
#undef __argp_fmtstream_ensure
|
||||||
|
#define __argp_fmtstream_ensure _argp_fmtstream_ensure
|
||||||
|
#undef __argp_fmtstream_lmargin
|
||||||
|
#define __argp_fmtstream_lmargin argp_fmtstream_lmargin
|
||||||
|
#undef __argp_fmtstream_rmargin
|
||||||
|
#define __argp_fmtstream_rmargin argp_fmtstream_rmargin
|
||||||
|
#undef __argp_fmtstream_wmargin
|
||||||
|
#define __argp_fmtstream_wmargin argp_fmtstream_wmargin
|
||||||
|
|
||||||
|
/* normal libc functions we call */
|
||||||
|
#undef __flockfile
|
||||||
|
#define __flockfile flockfile
|
||||||
|
#undef __funlockfile
|
||||||
|
#define __funlockfile funlockfile
|
||||||
|
#undef __mempcpy
|
||||||
|
#define __mempcpy mempcpy
|
||||||
|
#undef __sleep
|
||||||
|
#define __sleep sleep
|
||||||
|
#undef __strcasecmp
|
||||||
|
#define __strcasecmp strcasecmp
|
||||||
|
#undef __strchrnul
|
||||||
|
#define __strchrnul strchrnul
|
||||||
|
#undef __strerror_r
|
||||||
|
#define __strerror_r strerror_r
|
||||||
|
#undef __strndup
|
||||||
|
#define __strndup strndup
|
||||||
|
#undef __vsnprintf
|
||||||
|
#define __vsnprintf vsnprintf
|
||||||
|
|
||||||
|
#if defined(HAVE_DECL_CLEARERR_UNLOCKED) && !HAVE_DECL_CLEARERR_UNLOCKED
|
||||||
|
# define clearerr_unlocked(x) clearerr (x)
|
||||||
|
#endif
|
||||||
|
#if defined(HAVE_DECL_FEOF_UNLOCKED) && !HAVE_DECL_FEOF_UNLOCKED
|
||||||
|
# define feof_unlocked(x) feof (x)
|
||||||
|
# endif
|
||||||
|
#if defined(HAVE_DECL_FERROR_UNLOCKED) && !HAVE_DECL_FERROR_UNLOCKED
|
||||||
|
# define ferror_unlocked(x) ferror (x)
|
||||||
|
# endif
|
||||||
|
#if defined(HAVE_DECL_FFLUSH_UNLOCKED) && !HAVE_DECL_FFLUSH_UNLOCKED
|
||||||
|
# define fflush_unlocked(x) fflush (x)
|
||||||
|
# endif
|
||||||
|
#if defined(HAVE_DECL_FGETS_UNLOCKED) && !HAVE_DECL_FGETS_UNLOCKED
|
||||||
|
# define fgets_unlocked(x,y,z) fgets (x,y,z)
|
||||||
|
# endif
|
||||||
|
#if defined(HAVE_DECL_FPUTC_UNLOCKED) && !HAVE_DECL_FPUTC_UNLOCKED
|
||||||
|
# define fputc_unlocked(x,y) fputc (x,y)
|
||||||
|
# endif
|
||||||
|
#if defined(HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED
|
||||||
|
# define fputs_unlocked(x,y) fputs (x,y)
|
||||||
|
# endif
|
||||||
|
#if defined(HAVE_DECL_FREAD_UNLOCKED) && !HAVE_DECL_FREAD_UNLOCKED
|
||||||
|
# define fread_unlocked(w,x,y,z) fread (w,x,y,z)
|
||||||
|
# endif
|
||||||
|
#if defined(HAVE_DECL_FWRITE_UNLOCKED) && !HAVE_DECL_FWRITE_UNLOCKED
|
||||||
|
# define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z)
|
||||||
|
# endif
|
||||||
|
#if defined(HAVE_DECL_GETC_UNLOCKED) && !HAVE_DECL_GETC_UNLOCKED
|
||||||
|
# define getc_unlocked(x) getc (x)
|
||||||
|
# endif
|
||||||
|
#if defined(HAVE_DECL_GETCHAR_UNLOCKED) && !HAVE_DECL_GETCHAR_UNLOCKED
|
||||||
|
# define getchar_unlocked() getchar ()
|
||||||
|
# endif
|
||||||
|
#if defined(HAVE_DECL_PUTC_UNLOCKED) && !HAVE_DECL_PUTC_UNLOCKED
|
||||||
|
# define putc_unlocked(x,y) putc (x,y)
|
||||||
|
# endif
|
||||||
|
#if defined(HAVE_DECL_PUTCHAR_UNLOCKED) && !HAVE_DECL_PUTCHAR_UNLOCKED
|
||||||
|
# define putchar_unlocked(x) putchar (x)
|
||||||
|
# endif
|
||||||
|
|
||||||
|
#endif /* !_LIBC */
|
||||||
|
|
||||||
|
#ifndef __set_errno
|
||||||
|
#define __set_errno(e) (errno = (e))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined GNULIB_ARGP_DISABLE_DIRNAME
|
||||||
|
# define __argp_base_name(arg) arg
|
||||||
|
#elif defined GNULIB_ARGP_EXTERN_BASENAME
|
||||||
|
extern char *__argp_base_name (const char *arg);
|
||||||
|
#else
|
||||||
|
# include "dirname.h"
|
||||||
|
# define __argp_base_name last_component
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
|
||||||
|
# define __argp_short_program_name() (program_invocation_short_name)
|
||||||
|
#else
|
||||||
|
extern char *__argp_short_program_name (void);
|
||||||
|
#endif
|
952
gnulib/argp-parse.c
Normal file
952
gnulib/argp-parse.c
Normal file
|
@ -0,0 +1,952 @@
|
||||||
|
/* Hierarchial argument parsing, layered over getopt
|
||||||
|
Copyright (C) 1995-2000, 2002-2004, 2009-2010 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Written by Miles Bader <miles@gnu.ai.mit.edu>.
|
||||||
|
|
||||||
|
This program 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.
|
||||||
|
|
||||||
|
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <alloca.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <getopt_int.h>
|
||||||
|
|
||||||
|
#ifdef _LIBC
|
||||||
|
# include <libintl.h>
|
||||||
|
# undef dgettext
|
||||||
|
# define dgettext(domain, msgid) \
|
||||||
|
INTUSE(__dcgettext) (domain, msgid, LC_MESSAGES)
|
||||||
|
#else
|
||||||
|
# include "gettext.h"
|
||||||
|
#endif
|
||||||
|
#define N_(msgid) msgid
|
||||||
|
|
||||||
|
#include "argp.h"
|
||||||
|
#include "argp-namefrob.h"
|
||||||
|
|
||||||
|
#define alignof(type) offsetof (struct { char c; type x; }, x)
|
||||||
|
#define alignto(n, d) ((((n) + (d) - 1) / (d)) * (d))
|
||||||
|
|
||||||
|
/* Getopt return values. */
|
||||||
|
#define KEY_END (-1) /* The end of the options. */
|
||||||
|
#define KEY_ARG 1 /* A non-option argument. */
|
||||||
|
#define KEY_ERR '?' /* An error parsing the options. */
|
||||||
|
|
||||||
|
/* The meta-argument used to prevent any further arguments being interpreted
|
||||||
|
as options. */
|
||||||
|
#define QUOTE "--"
|
||||||
|
|
||||||
|
/* The number of bits we steal in a long-option value for our own use. */
|
||||||
|
#define GROUP_BITS CHAR_BIT
|
||||||
|
|
||||||
|
/* The number of bits available for the user value. */
|
||||||
|
#define USER_BITS ((sizeof ((struct option *)0)->val * CHAR_BIT) - GROUP_BITS)
|
||||||
|
#define USER_MASK ((1 << USER_BITS) - 1)
|
||||||
|
|
||||||
|
/* EZ alias for ARGP_ERR_UNKNOWN. */
|
||||||
|
#define EBADKEY ARGP_ERR_UNKNOWN
|
||||||
|
|
||||||
|
/* Default options. */
|
||||||
|
|
||||||
|
/* When argp is given the --HANG switch, _ARGP_HANG is set and argp will sleep
|
||||||
|
for one second intervals, decrementing _ARGP_HANG until it's zero. Thus
|
||||||
|
you can force the program to continue by attaching a debugger and setting
|
||||||
|
it to 0 yourself. */
|
||||||
|
static volatile int _argp_hang;
|
||||||
|
|
||||||
|
#define OPT_PROGNAME -2
|
||||||
|
#define OPT_USAGE -3
|
||||||
|
#define OPT_HANG -4
|
||||||
|
|
||||||
|
static const struct argp_option argp_default_options[] =
|
||||||
|
{
|
||||||
|
{"help", '?', 0, 0, N_("give this help list"), -1},
|
||||||
|
{"usage", OPT_USAGE, 0, 0, N_("give a short usage message"), 0},
|
||||||
|
{"program-name",OPT_PROGNAME,N_("NAME"), OPTION_HIDDEN, N_("set the program name"), 0},
|
||||||
|
{"HANG", OPT_HANG, N_("SECS"), OPTION_ARG_OPTIONAL | OPTION_HIDDEN,
|
||||||
|
N_("hang for SECS seconds (default 3600)"), 0},
|
||||||
|
{NULL, 0, 0, 0, NULL, 0}
|
||||||
|
};
|
||||||
|
|
||||||
|
static error_t
|
||||||
|
argp_default_parser (int key, char *arg, struct argp_state *state)
|
||||||
|
{
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case '?':
|
||||||
|
__argp_state_help (state, state->out_stream, ARGP_HELP_STD_HELP);
|
||||||
|
break;
|
||||||
|
case OPT_USAGE:
|
||||||
|
__argp_state_help (state, state->out_stream,
|
||||||
|
ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OPT_PROGNAME: /* Set the program name. */
|
||||||
|
#if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_NAME
|
||||||
|
program_invocation_name = arg;
|
||||||
|
#endif
|
||||||
|
/* [Note that some systems only have PROGRAM_INVOCATION_SHORT_NAME (aka
|
||||||
|
__PROGNAME), in which case, PROGRAM_INVOCATION_NAME is just defined
|
||||||
|
to be that, so we have to be a bit careful here.] */
|
||||||
|
|
||||||
|
/* Update what we use for messages. */
|
||||||
|
state->name = __argp_base_name (arg);
|
||||||
|
|
||||||
|
#if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
|
||||||
|
program_invocation_short_name = state->name;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if ((state->flags & (ARGP_PARSE_ARGV0 | ARGP_NO_ERRS))
|
||||||
|
== ARGP_PARSE_ARGV0)
|
||||||
|
/* Update what getopt uses too. */
|
||||||
|
state->argv[0] = arg;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OPT_HANG:
|
||||||
|
_argp_hang = atoi (arg ? arg : "3600");
|
||||||
|
while (_argp_hang-- > 0)
|
||||||
|
__sleep (1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return EBADKEY;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct argp argp_default_argp =
|
||||||
|
{argp_default_options, &argp_default_parser, NULL, NULL, NULL, NULL, "libc"};
|
||||||
|
|
||||||
|
|
||||||
|
static const struct argp_option argp_version_options[] =
|
||||||
|
{
|
||||||
|
{"version", 'V', 0, 0, N_("print program version"), -1},
|
||||||
|
{NULL, 0, 0, 0, NULL, 0}
|
||||||
|
};
|
||||||
|
|
||||||
|
static error_t
|
||||||
|
argp_version_parser (int key, char *arg, struct argp_state *state)
|
||||||
|
{
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case 'V':
|
||||||
|
if (argp_program_version_hook)
|
||||||
|
(*argp_program_version_hook) (state->out_stream, state);
|
||||||
|
else if (argp_program_version)
|
||||||
|
fprintf (state->out_stream, "%s\n", argp_program_version);
|
||||||
|
else
|
||||||
|
__argp_error (state, dgettext (state->root_argp->argp_domain,
|
||||||
|
"(PROGRAM ERROR) No version known!?"));
|
||||||
|
if (! (state->flags & ARGP_NO_EXIT))
|
||||||
|
exit (0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return EBADKEY;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct argp argp_version_argp =
|
||||||
|
{argp_version_options, &argp_version_parser, NULL, NULL, NULL, NULL, "libc"};
|
||||||
|
|
||||||
|
/* Returns the offset into the getopt long options array LONG_OPTIONS of a
|
||||||
|
long option with called NAME, or -1 if none is found. Passing NULL as
|
||||||
|
NAME will return the number of options. */
|
||||||
|
static int
|
||||||
|
find_long_option (struct option *long_options, const char *name)
|
||||||
|
{
|
||||||
|
struct option *l = long_options;
|
||||||
|
while (l->name != NULL)
|
||||||
|
if (name != NULL && strcmp (l->name, name) == 0)
|
||||||
|
return l - long_options;
|
||||||
|
else
|
||||||
|
l++;
|
||||||
|
if (name == NULL)
|
||||||
|
return l - long_options;
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* The state of a `group' during parsing. Each group corresponds to a
|
||||||
|
particular argp structure from the tree of such descending from the top
|
||||||
|
level argp passed to argp_parse. */
|
||||||
|
struct group
|
||||||
|
{
|
||||||
|
/* This group's parsing function. */
|
||||||
|
argp_parser_t parser;
|
||||||
|
|
||||||
|
/* Which argp this group is from. */
|
||||||
|
const struct argp *argp;
|
||||||
|
|
||||||
|
/* Points to the point in SHORT_OPTS corresponding to the end of the short
|
||||||
|
options for this group. We use it to determine from which group a
|
||||||
|
particular short options is from. */
|
||||||
|
char *short_end;
|
||||||
|
|
||||||
|
/* The number of non-option args sucessfully handled by this parser. */
|
||||||
|
unsigned args_processed;
|
||||||
|
|
||||||
|
/* This group's parser's parent's group. */
|
||||||
|
struct group *parent;
|
||||||
|
unsigned parent_index; /* And the our position in the parent. */
|
||||||
|
|
||||||
|
/* These fields are swapped into and out of the state structure when
|
||||||
|
calling this group's parser. */
|
||||||
|
void *input, **child_inputs;
|
||||||
|
void *hook;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Call GROUP's parser with KEY and ARG, swapping any group-specific info
|
||||||
|
from STATE before calling, and back into state afterwards. If GROUP has
|
||||||
|
no parser, EBADKEY is returned. */
|
||||||
|
static error_t
|
||||||
|
group_parse (struct group *group, struct argp_state *state, int key, char *arg)
|
||||||
|
{
|
||||||
|
if (group->parser)
|
||||||
|
{
|
||||||
|
error_t err;
|
||||||
|
state->hook = group->hook;
|
||||||
|
state->input = group->input;
|
||||||
|
state->child_inputs = group->child_inputs;
|
||||||
|
state->arg_num = group->args_processed;
|
||||||
|
err = (*group->parser)(key, arg, state);
|
||||||
|
group->hook = state->hook;
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return EBADKEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct parser
|
||||||
|
{
|
||||||
|
const struct argp *argp;
|
||||||
|
|
||||||
|
/* SHORT_OPTS is the getopt short options string for the union of all the
|
||||||
|
groups of options. */
|
||||||
|
char *short_opts;
|
||||||
|
/* LONG_OPTS is the array of getop long option structures for the union of
|
||||||
|
all the groups of options. */
|
||||||
|
struct option *long_opts;
|
||||||
|
/* OPT_DATA is the getopt data used for the re-entrant getopt. */
|
||||||
|
struct _getopt_data opt_data;
|
||||||
|
|
||||||
|
/* States of the various parsing groups. */
|
||||||
|
struct group *groups;
|
||||||
|
/* The end of the GROUPS array. */
|
||||||
|
struct group *egroup;
|
||||||
|
/* An vector containing storage for the CHILD_INPUTS field in all groups. */
|
||||||
|
void **child_inputs;
|
||||||
|
|
||||||
|
/* True if we think using getopt is still useful; if false, then
|
||||||
|
remaining arguments are just passed verbatim with ARGP_KEY_ARG. This is
|
||||||
|
cleared whenever getopt returns KEY_END, but may be set again if the user
|
||||||
|
moves the next argument pointer backwards. */
|
||||||
|
int try_getopt;
|
||||||
|
|
||||||
|
/* State block supplied to parsing routines. */
|
||||||
|
struct argp_state state;
|
||||||
|
|
||||||
|
/* Memory used by this parser. */
|
||||||
|
void *storage;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* The next usable entries in the various parser tables being filled in by
|
||||||
|
convert_options. */
|
||||||
|
struct parser_convert_state
|
||||||
|
{
|
||||||
|
struct parser *parser;
|
||||||
|
char *short_end;
|
||||||
|
struct option *long_end;
|
||||||
|
void **child_inputs_end;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Converts all options in ARGP (which is put in GROUP) and ancestors
|
||||||
|
into getopt options stored in SHORT_OPTS and LONG_OPTS; SHORT_END and
|
||||||
|
CVT->LONG_END are the points at which new options are added. Returns the
|
||||||
|
next unused group entry. CVT holds state used during the conversion. */
|
||||||
|
static struct group *
|
||||||
|
convert_options (const struct argp *argp,
|
||||||
|
struct group *parent, unsigned parent_index,
|
||||||
|
struct group *group, struct parser_convert_state *cvt)
|
||||||
|
{
|
||||||
|
/* REAL is the most recent non-alias value of OPT. */
|
||||||
|
const struct argp_option *real = argp->options;
|
||||||
|
const struct argp_child *children = argp->children;
|
||||||
|
|
||||||
|
if (real || argp->parser)
|
||||||
|
{
|
||||||
|
const struct argp_option *opt;
|
||||||
|
|
||||||
|
if (real)
|
||||||
|
for (opt = real; !__option_is_end (opt); opt++)
|
||||||
|
{
|
||||||
|
if (! (opt->flags & OPTION_ALIAS))
|
||||||
|
/* OPT isn't an alias, so we can use values from it. */
|
||||||
|
real = opt;
|
||||||
|
|
||||||
|
if (! (real->flags & OPTION_DOC))
|
||||||
|
/* A real option (not just documentation). */
|
||||||
|
{
|
||||||
|
if (__option_is_short (opt))
|
||||||
|
/* OPT can be used as a short option. */
|
||||||
|
{
|
||||||
|
*cvt->short_end++ = opt->key;
|
||||||
|
if (real->arg)
|
||||||
|
{
|
||||||
|
*cvt->short_end++ = ':';
|
||||||
|
if (real->flags & OPTION_ARG_OPTIONAL)
|
||||||
|
*cvt->short_end++ = ':';
|
||||||
|
}
|
||||||
|
*cvt->short_end = '\0'; /* keep 0 terminated */
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opt->name
|
||||||
|
&& find_long_option (cvt->parser->long_opts, opt->name) < 0)
|
||||||
|
/* OPT can be used as a long option. */
|
||||||
|
{
|
||||||
|
cvt->long_end->name = opt->name;
|
||||||
|
cvt->long_end->has_arg =
|
||||||
|
(real->arg
|
||||||
|
? (real->flags & OPTION_ARG_OPTIONAL
|
||||||
|
? optional_argument
|
||||||
|
: required_argument)
|
||||||
|
: no_argument);
|
||||||
|
cvt->long_end->flag = 0;
|
||||||
|
/* we add a disambiguating code to all the user's
|
||||||
|
values (which is removed before we actually call
|
||||||
|
the function to parse the value); this means that
|
||||||
|
the user loses use of the high 8 bits in all his
|
||||||
|
values (the sign of the lower bits is preserved
|
||||||
|
however)... */
|
||||||
|
cvt->long_end->val =
|
||||||
|
((opt->key ? opt->key : real->key) & USER_MASK)
|
||||||
|
+ (((group - cvt->parser->groups) + 1) << USER_BITS);
|
||||||
|
|
||||||
|
/* Keep the LONG_OPTS list terminated. */
|
||||||
|
(++cvt->long_end)->name = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
group->parser = argp->parser;
|
||||||
|
group->argp = argp;
|
||||||
|
group->short_end = cvt->short_end;
|
||||||
|
group->args_processed = 0;
|
||||||
|
group->parent = parent;
|
||||||
|
group->parent_index = parent_index;
|
||||||
|
group->input = 0;
|
||||||
|
group->hook = 0;
|
||||||
|
group->child_inputs = 0;
|
||||||
|
|
||||||
|
if (children)
|
||||||
|
/* Assign GROUP's CHILD_INPUTS field some space from
|
||||||
|
CVT->child_inputs_end.*/
|
||||||
|
{
|
||||||
|
unsigned num_children = 0;
|
||||||
|
while (children[num_children].argp)
|
||||||
|
num_children++;
|
||||||
|
group->child_inputs = cvt->child_inputs_end;
|
||||||
|
cvt->child_inputs_end += num_children;
|
||||||
|
}
|
||||||
|
|
||||||
|
parent = group++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
parent = 0;
|
||||||
|
|
||||||
|
if (children)
|
||||||
|
{
|
||||||
|
unsigned index = 0;
|
||||||
|
while (children->argp)
|
||||||
|
group =
|
||||||
|
convert_options (children++->argp, parent, index++, group, cvt);
|
||||||
|
}
|
||||||
|
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Find the merged set of getopt options, with keys appropiately prefixed. */
|
||||||
|
static void
|
||||||
|
parser_convert (struct parser *parser, const struct argp *argp, int flags)
|
||||||
|
{
|
||||||
|
struct parser_convert_state cvt;
|
||||||
|
|
||||||
|
cvt.parser = parser;
|
||||||
|
cvt.short_end = parser->short_opts;
|
||||||
|
cvt.long_end = parser->long_opts;
|
||||||
|
cvt.child_inputs_end = parser->child_inputs;
|
||||||
|
|
||||||
|
if (flags & ARGP_IN_ORDER)
|
||||||
|
*cvt.short_end++ = '-';
|
||||||
|
else if (flags & ARGP_NO_ARGS)
|
||||||
|
*cvt.short_end++ = '+';
|
||||||
|
*cvt.short_end = '\0';
|
||||||
|
|
||||||
|
cvt.long_end->name = NULL;
|
||||||
|
|
||||||
|
parser->argp = argp;
|
||||||
|
|
||||||
|
if (argp)
|
||||||
|
parser->egroup = convert_options (argp, 0, 0, parser->groups, &cvt);
|
||||||
|
else
|
||||||
|
parser->egroup = parser->groups; /* No parsers at all! */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Lengths of various parser fields which we will allocated. */
|
||||||
|
struct parser_sizes
|
||||||
|
{
|
||||||
|
size_t short_len; /* Getopt short options string. */
|
||||||
|
size_t long_len; /* Getopt long options vector. */
|
||||||
|
size_t num_groups; /* Group structures we allocate. */
|
||||||
|
size_t num_child_inputs; /* Child input slots. */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* For ARGP, increments the NUM_GROUPS field in SZS by the total number of
|
||||||
|
argp structures descended from it, and the SHORT_LEN & LONG_LEN fields by
|
||||||
|
the maximum lengths of the resulting merged getopt short options string and
|
||||||
|
long-options array, respectively. */
|
||||||
|
static void
|
||||||
|
calc_sizes (const struct argp *argp, struct parser_sizes *szs)
|
||||||
|
{
|
||||||
|
const struct argp_child *child = argp->children;
|
||||||
|
const struct argp_option *opt = argp->options;
|
||||||
|
|
||||||
|
if (opt || argp->parser)
|
||||||
|
{
|
||||||
|
szs->num_groups++;
|
||||||
|
if (opt)
|
||||||
|
{
|
||||||
|
int num_opts = 0;
|
||||||
|
while (!__option_is_end (opt++))
|
||||||
|
num_opts++;
|
||||||
|
szs->short_len += num_opts * 3; /* opt + up to 2 `:'s */
|
||||||
|
szs->long_len += num_opts;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (child)
|
||||||
|
while (child->argp)
|
||||||
|
{
|
||||||
|
calc_sizes ((child++)->argp, szs);
|
||||||
|
szs->num_child_inputs++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initializes PARSER to parse ARGP in a manner described by FLAGS. */
|
||||||
|
static error_t
|
||||||
|
parser_init (struct parser *parser, const struct argp *argp,
|
||||||
|
int argc, char **argv, int flags, void *input)
|
||||||
|
{
|
||||||
|
error_t err = 0;
|
||||||
|
struct group *group;
|
||||||
|
struct parser_sizes szs;
|
||||||
|
struct _getopt_data opt_data = _GETOPT_DATA_INITIALIZER;
|
||||||
|
char *storage;
|
||||||
|
size_t glen, gsum;
|
||||||
|
size_t clen, csum;
|
||||||
|
size_t llen, lsum;
|
||||||
|
size_t slen, ssum;
|
||||||
|
|
||||||
|
szs.short_len = (flags & ARGP_NO_ARGS) ? 0 : 1;
|
||||||
|
szs.long_len = 0;
|
||||||
|
szs.num_groups = 0;
|
||||||
|
szs.num_child_inputs = 0;
|
||||||
|
|
||||||
|
if (argp)
|
||||||
|
calc_sizes (argp, &szs);
|
||||||
|
|
||||||
|
/* Lengths of the various bits of storage used by PARSER. */
|
||||||
|
glen = (szs.num_groups + 1) * sizeof (struct group);
|
||||||
|
clen = szs.num_child_inputs * sizeof (void *);
|
||||||
|
llen = (szs.long_len + 1) * sizeof (struct option);
|
||||||
|
slen = szs.short_len + 1;
|
||||||
|
|
||||||
|
/* Sums of previous lengths, properly aligned. There's no need to
|
||||||
|
align gsum, since struct group is aligned at least as strictly as
|
||||||
|
void * (since it contains a void * member). And there's no need
|
||||||
|
to align lsum, since struct option is aligned at least as
|
||||||
|
strictly as char. */
|
||||||
|
gsum = glen;
|
||||||
|
csum = alignto (gsum + clen, alignof (struct option));
|
||||||
|
lsum = csum + llen;
|
||||||
|
ssum = lsum + slen;
|
||||||
|
|
||||||
|
parser->storage = malloc (ssum);
|
||||||
|
if (! parser->storage)
|
||||||
|
return ENOMEM;
|
||||||
|
|
||||||
|
storage = parser->storage;
|
||||||
|
parser->groups = parser->storage;
|
||||||
|
parser->child_inputs = (void **) (storage + gsum);
|
||||||
|
parser->long_opts = (struct option *) (storage + csum);
|
||||||
|
parser->short_opts = storage + lsum;
|
||||||
|
parser->opt_data = opt_data;
|
||||||
|
|
||||||
|
memset (parser->child_inputs, 0, clen);
|
||||||
|
parser_convert (parser, argp, flags);
|
||||||
|
|
||||||
|
memset (&parser->state, 0, sizeof (struct argp_state));
|
||||||
|
parser->state.root_argp = parser->argp;
|
||||||
|
parser->state.argc = argc;
|
||||||
|
parser->state.argv = argv;
|
||||||
|
parser->state.flags = flags;
|
||||||
|
parser->state.err_stream = stderr;
|
||||||
|
parser->state.out_stream = stdout;
|
||||||
|
parser->state.next = 0; /* Tell getopt to initialize. */
|
||||||
|
parser->state.pstate = parser;
|
||||||
|
|
||||||
|
parser->try_getopt = 1;
|
||||||
|
|
||||||
|
/* Call each parser for the first time, giving it a chance to propagate
|
||||||
|
values to child parsers. */
|
||||||
|
if (parser->groups < parser->egroup)
|
||||||
|
parser->groups->input = input;
|
||||||
|
for (group = parser->groups;
|
||||||
|
group < parser->egroup && (!err || err == EBADKEY);
|
||||||
|
group++)
|
||||||
|
{
|
||||||
|
if (group->parent)
|
||||||
|
/* If a child parser, get the initial input value from the parent. */
|
||||||
|
group->input = group->parent->child_inputs[group->parent_index];
|
||||||
|
|
||||||
|
if (!group->parser
|
||||||
|
&& group->argp->children && group->argp->children->argp)
|
||||||
|
/* For the special case where no parsing function is supplied for an
|
||||||
|
argp, propagate its input to its first child, if any (this just
|
||||||
|
makes very simple wrapper argps more convenient). */
|
||||||
|
group->child_inputs[0] = group->input;
|
||||||
|
|
||||||
|
err = group_parse (group, &parser->state, ARGP_KEY_INIT, 0);
|
||||||
|
}
|
||||||
|
if (err == EBADKEY)
|
||||||
|
err = 0; /* Some parser didn't understand. */
|
||||||
|
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
|
||||||
|
if (parser->state.flags & ARGP_NO_ERRS)
|
||||||
|
{
|
||||||
|
parser->opt_data.opterr = 0;
|
||||||
|
if (parser->state.flags & ARGP_PARSE_ARGV0)
|
||||||
|
/* getopt always skips ARGV[0], so we have to fake it out. As long
|
||||||
|
as OPTERR is 0, then it shouldn't actually try to access it. */
|
||||||
|
parser->state.argv--, parser->state.argc++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
parser->opt_data.opterr = 1; /* Print error messages. */
|
||||||
|
|
||||||
|
if (parser->state.argv == argv && argv[0])
|
||||||
|
/* There's an argv[0]; use it for messages. */
|
||||||
|
parser->state.name = __argp_base_name (argv[0]);
|
||||||
|
else
|
||||||
|
parser->state.name = __argp_short_program_name ();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Free any storage consumed by PARSER (but not PARSER itself). */
|
||||||
|
static error_t
|
||||||
|
parser_finalize (struct parser *parser,
|
||||||
|
error_t err, int arg_ebadkey, int *end_index)
|
||||||
|
{
|
||||||
|
struct group *group;
|
||||||
|
|
||||||
|
if (err == EBADKEY && arg_ebadkey)
|
||||||
|
/* Suppress errors generated by unparsed arguments. */
|
||||||
|
err = 0;
|
||||||
|
|
||||||
|
if (! err)
|
||||||
|
{
|
||||||
|
if (parser->state.next == parser->state.argc)
|
||||||
|
/* We successfully parsed all arguments! Call all the parsers again,
|
||||||
|
just a few more times... */
|
||||||
|
{
|
||||||
|
for (group = parser->groups;
|
||||||
|
group < parser->egroup && (!err || err==EBADKEY);
|
||||||
|
group++)
|
||||||
|
if (group->args_processed == 0)
|
||||||
|
err = group_parse (group, &parser->state, ARGP_KEY_NO_ARGS, 0);
|
||||||
|
for (group = parser->egroup - 1;
|
||||||
|
group >= parser->groups && (!err || err==EBADKEY);
|
||||||
|
group--)
|
||||||
|
err = group_parse (group, &parser->state, ARGP_KEY_END, 0);
|
||||||
|
|
||||||
|
if (err == EBADKEY)
|
||||||
|
err = 0; /* Some parser didn't understand. */
|
||||||
|
|
||||||
|
/* Tell the user that all arguments are parsed. */
|
||||||
|
if (end_index)
|
||||||
|
*end_index = parser->state.next;
|
||||||
|
}
|
||||||
|
else if (end_index)
|
||||||
|
/* Return any remaining arguments to the user. */
|
||||||
|
*end_index = parser->state.next;
|
||||||
|
else
|
||||||
|
/* No way to return the remaining arguments, they must be bogus. */
|
||||||
|
{
|
||||||
|
if (!(parser->state.flags & ARGP_NO_ERRS)
|
||||||
|
&& parser->state.err_stream)
|
||||||
|
fprintf (parser->state.err_stream,
|
||||||
|
dgettext (parser->argp->argp_domain,
|
||||||
|
"%s: Too many arguments\n"),
|
||||||
|
parser->state.name);
|
||||||
|
err = EBADKEY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Okay, we're all done, with either an error or success; call the parsers
|
||||||
|
to indicate which one. */
|
||||||
|
|
||||||
|
if (err)
|
||||||
|
{
|
||||||
|
/* Maybe print an error message. */
|
||||||
|
if (err == EBADKEY)
|
||||||
|
/* An appropriate message describing what the error was should have
|
||||||
|
been printed earlier. */
|
||||||
|
__argp_state_help (&parser->state, parser->state.err_stream,
|
||||||
|
ARGP_HELP_STD_ERR);
|
||||||
|
|
||||||
|
/* Since we didn't exit, give each parser an error indication. */
|
||||||
|
for (group = parser->groups; group < parser->egroup; group++)
|
||||||
|
group_parse (group, &parser->state, ARGP_KEY_ERROR, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
/* Notify parsers of success, and propagate back values from parsers. */
|
||||||
|
{
|
||||||
|
/* We pass over the groups in reverse order so that child groups are
|
||||||
|
given a chance to do there processing before passing back a value to
|
||||||
|
the parent. */
|
||||||
|
for (group = parser->egroup - 1
|
||||||
|
; group >= parser->groups && (!err || err == EBADKEY)
|
||||||
|
; group--)
|
||||||
|
err = group_parse (group, &parser->state, ARGP_KEY_SUCCESS, 0);
|
||||||
|
if (err == EBADKEY)
|
||||||
|
err = 0; /* Some parser didn't understand. */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Call parsers once more, to do any final cleanup. Errors are ignored. */
|
||||||
|
for (group = parser->egroup - 1; group >= parser->groups; group--)
|
||||||
|
group_parse (group, &parser->state, ARGP_KEY_FINI, 0);
|
||||||
|
|
||||||
|
if (err == EBADKEY)
|
||||||
|
err = EINVAL;
|
||||||
|
|
||||||
|
free (parser->storage);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Call the user parsers to parse the non-option argument VAL, at the current
|
||||||
|
position, returning any error. The state NEXT pointer is assumed to have
|
||||||
|
been adjusted (by getopt) to point after this argument; this function will
|
||||||
|
adjust it correctly to reflect however many args actually end up being
|
||||||
|
consumed. */
|
||||||
|
static error_t
|
||||||
|
parser_parse_arg (struct parser *parser, char *val)
|
||||||
|
{
|
||||||
|
/* Save the starting value of NEXT, first adjusting it so that the arg
|
||||||
|
we're parsing is again the front of the arg vector. */
|
||||||
|
int index = --parser->state.next;
|
||||||
|
error_t err = EBADKEY;
|
||||||
|
struct group *group;
|
||||||
|
int key = 0; /* Which of ARGP_KEY_ARG[S] we used. */
|
||||||
|
|
||||||
|
/* Try to parse the argument in each parser. */
|
||||||
|
for (group = parser->groups
|
||||||
|
; group < parser->egroup && err == EBADKEY
|
||||||
|
; group++)
|
||||||
|
{
|
||||||
|
parser->state.next++; /* For ARGP_KEY_ARG, consume the arg. */
|
||||||
|
key = ARGP_KEY_ARG;
|
||||||
|
err = group_parse (group, &parser->state, key, val);
|
||||||
|
|
||||||
|
if (err == EBADKEY)
|
||||||
|
/* This parser doesn't like ARGP_KEY_ARG; try ARGP_KEY_ARGS instead. */
|
||||||
|
{
|
||||||
|
parser->state.next--; /* For ARGP_KEY_ARGS, put back the arg. */
|
||||||
|
key = ARGP_KEY_ARGS;
|
||||||
|
err = group_parse (group, &parser->state, key, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! err)
|
||||||
|
{
|
||||||
|
if (key == ARGP_KEY_ARGS)
|
||||||
|
/* The default for ARGP_KEY_ARGS is to assume that if NEXT isn't
|
||||||
|
changed by the user, *all* arguments should be considered
|
||||||
|
consumed. */
|
||||||
|
parser->state.next = parser->state.argc;
|
||||||
|
|
||||||
|
if (parser->state.next > index)
|
||||||
|
/* Remember that we successfully processed a non-option
|
||||||
|
argument -- but only if the user hasn't gotten tricky and set
|
||||||
|
the clock back. */
|
||||||
|
(--group)->args_processed += (parser->state.next - index);
|
||||||
|
else
|
||||||
|
/* The user wants to reparse some args, give getopt another try. */
|
||||||
|
parser->try_getopt = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Call the user parsers to parse the option OPT, with argument VAL, at the
|
||||||
|
current position, returning any error. */
|
||||||
|
static error_t
|
||||||
|
parser_parse_opt (struct parser *parser, int opt, char *val)
|
||||||
|
{
|
||||||
|
/* The group key encoded in the high bits; 0 for short opts or
|
||||||
|
group_number + 1 for long opts. */
|
||||||
|
int group_key = opt >> USER_BITS;
|
||||||
|
error_t err = EBADKEY;
|
||||||
|
|
||||||
|
if (group_key == 0)
|
||||||
|
/* A short option. By comparing OPT's position in SHORT_OPTS to the
|
||||||
|
various starting positions in each group's SHORT_END field, we can
|
||||||
|
determine which group OPT came from. */
|
||||||
|
{
|
||||||
|
struct group *group;
|
||||||
|
char *short_index = strchr (parser->short_opts, opt);
|
||||||
|
|
||||||
|
if (short_index)
|
||||||
|
for (group = parser->groups; group < parser->egroup; group++)
|
||||||
|
if (group->short_end > short_index)
|
||||||
|
{
|
||||||
|
err = group_parse (group, &parser->state, opt,
|
||||||
|
parser->opt_data.optarg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
/* A long option. We use shifts instead of masking for extracting
|
||||||
|
the user value in order to preserve the sign. */
|
||||||
|
err =
|
||||||
|
group_parse (&parser->groups[group_key - 1], &parser->state,
|
||||||
|
(opt << GROUP_BITS) >> GROUP_BITS,
|
||||||
|
parser->opt_data.optarg);
|
||||||
|
|
||||||
|
if (err == EBADKEY)
|
||||||
|
/* At least currently, an option not recognized is an error in the
|
||||||
|
parser, because we pre-compute which parser is supposed to deal
|
||||||
|
with each option. */
|
||||||
|
{
|
||||||
|
static const char bad_key_err[] =
|
||||||
|
N_("(PROGRAM ERROR) Option should have been recognized!?");
|
||||||
|
if (group_key == 0)
|
||||||
|
__argp_error (&parser->state, "-%c: %s", opt,
|
||||||
|
dgettext (parser->argp->argp_domain, bad_key_err));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
struct option *long_opt = parser->long_opts;
|
||||||
|
while (long_opt->val != opt && long_opt->name)
|
||||||
|
long_opt++;
|
||||||
|
__argp_error (&parser->state, "--%s: %s",
|
||||||
|
long_opt->name ? long_opt->name : "???",
|
||||||
|
dgettext (parser->argp->argp_domain, bad_key_err));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Parse the next argument in PARSER (as indicated by PARSER->state.next).
|
||||||
|
Any error from the parsers is returned, and *ARGP_EBADKEY indicates
|
||||||
|
whether a value of EBADKEY is due to an unrecognized argument (which is
|
||||||
|
generally not fatal). */
|
||||||
|
static error_t
|
||||||
|
parser_parse_next (struct parser *parser, int *arg_ebadkey)
|
||||||
|
{
|
||||||
|
int opt;
|
||||||
|
error_t err = 0;
|
||||||
|
|
||||||
|
if (parser->state.quoted && parser->state.next < parser->state.quoted)
|
||||||
|
/* The next argument pointer has been moved to before the quoted
|
||||||
|
region, so pretend we never saw the quoting `--', and give getopt
|
||||||
|
another chance. If the user hasn't removed it, getopt will just
|
||||||
|
process it again. */
|
||||||
|
parser->state.quoted = 0;
|
||||||
|
|
||||||
|
if (parser->try_getopt && !parser->state.quoted)
|
||||||
|
/* Give getopt a chance to parse this. */
|
||||||
|
{
|
||||||
|
/* Put it back in OPTIND for getopt. */
|
||||||
|
parser->opt_data.optind = parser->state.next;
|
||||||
|
/* Distinguish KEY_ERR from a real option. */
|
||||||
|
parser->opt_data.optopt = KEY_END;
|
||||||
|
if (parser->state.flags & ARGP_LONG_ONLY)
|
||||||
|
opt = _getopt_long_only_r (parser->state.argc, parser->state.argv,
|
||||||
|
parser->short_opts, parser->long_opts, 0,
|
||||||
|
&parser->opt_data);
|
||||||
|
else
|
||||||
|
opt = _getopt_long_r (parser->state.argc, parser->state.argv,
|
||||||
|
parser->short_opts, parser->long_opts, 0,
|
||||||
|
&parser->opt_data);
|
||||||
|
/* And see what getopt did. */
|
||||||
|
parser->state.next = parser->opt_data.optind;
|
||||||
|
|
||||||
|
if (opt == KEY_END)
|
||||||
|
/* Getopt says there are no more options, so stop using
|
||||||
|
getopt; we'll continue if necessary on our own. */
|
||||||
|
{
|
||||||
|
parser->try_getopt = 0;
|
||||||
|
if (parser->state.next > 1
|
||||||
|
&& strcmp (parser->state.argv[parser->state.next - 1], QUOTE)
|
||||||
|
== 0)
|
||||||
|
/* Not only is this the end of the options, but it's a
|
||||||
|
`quoted' region, which may have args that *look* like
|
||||||
|
options, so we definitely shouldn't try to use getopt past
|
||||||
|
here, whatever happens. */
|
||||||
|
parser->state.quoted = parser->state.next;
|
||||||
|
}
|
||||||
|
else if (opt == KEY_ERR && parser->opt_data.optopt != KEY_END)
|
||||||
|
/* KEY_ERR can have the same value as a valid user short
|
||||||
|
option, but in the case of a real error, getopt sets OPTOPT
|
||||||
|
to the offending character, which can never be KEY_END. */
|
||||||
|
{
|
||||||
|
*arg_ebadkey = 0;
|
||||||
|
return EBADKEY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
opt = KEY_END;
|
||||||
|
|
||||||
|
if (opt == KEY_END)
|
||||||
|
{
|
||||||
|
/* We're past what getopt considers the options. */
|
||||||
|
if (parser->state.next >= parser->state.argc
|
||||||
|
|| (parser->state.flags & ARGP_NO_ARGS))
|
||||||
|
/* Indicate that we're done. */
|
||||||
|
{
|
||||||
|
*arg_ebadkey = 1;
|
||||||
|
return EBADKEY;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
/* A non-option arg; simulate what getopt might have done. */
|
||||||
|
{
|
||||||
|
opt = KEY_ARG;
|
||||||
|
parser->opt_data.optarg = parser->state.argv[parser->state.next++];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opt == KEY_ARG)
|
||||||
|
/* A non-option argument; try each parser in turn. */
|
||||||
|
err = parser_parse_arg (parser, parser->opt_data.optarg);
|
||||||
|
else
|
||||||
|
err = parser_parse_opt (parser, opt, parser->opt_data.optarg);
|
||||||
|
|
||||||
|
if (err == EBADKEY)
|
||||||
|
*arg_ebadkey = (opt == KEY_END || opt == KEY_ARG);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Parse the options strings in ARGC & ARGV according to the argp in ARGP.
|
||||||
|
FLAGS is one of the ARGP_ flags above. If END_INDEX is non-NULL, the
|
||||||
|
index in ARGV of the first unparsed option is returned in it. If an
|
||||||
|
unknown option is present, EINVAL is returned; if some parser routine
|
||||||
|
returned a non-zero value, it is returned; otherwise 0 is returned. */
|
||||||
|
error_t
|
||||||
|
__argp_parse (const struct argp *argp, int argc, char **argv, unsigned flags,
|
||||||
|
int *end_index, void *input)
|
||||||
|
{
|
||||||
|
error_t err;
|
||||||
|
struct parser parser;
|
||||||
|
|
||||||
|
/* If true, then err == EBADKEY is a result of a non-option argument failing
|
||||||
|
to be parsed (which in some cases isn't actually an error). */
|
||||||
|
int arg_ebadkey = 0;
|
||||||
|
|
||||||
|
#ifndef _LIBC
|
||||||
|
if (!(flags & ARGP_PARSE_ARGV0))
|
||||||
|
{
|
||||||
|
#ifdef HAVE_DECL_PROGRAM_INVOCATION_NAME
|
||||||
|
if (!program_invocation_name)
|
||||||
|
program_invocation_name = argv[0];
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
|
||||||
|
if (!program_invocation_short_name)
|
||||||
|
program_invocation_short_name = __argp_base_name (argv[0]);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (! (flags & ARGP_NO_HELP))
|
||||||
|
/* Add our own options. */
|
||||||
|
{
|
||||||
|
struct argp_child *child = alloca (4 * sizeof (struct argp_child));
|
||||||
|
struct argp *top_argp = alloca (sizeof (struct argp));
|
||||||
|
|
||||||
|
/* TOP_ARGP has no options, it just serves to group the user & default
|
||||||
|
argps. */
|
||||||
|
memset (top_argp, 0, sizeof (*top_argp));
|
||||||
|
top_argp->children = child;
|
||||||
|
|
||||||
|
memset (child, 0, 4 * sizeof (struct argp_child));
|
||||||
|
|
||||||
|
if (argp)
|
||||||
|
(child++)->argp = argp;
|
||||||
|
(child++)->argp = &argp_default_argp;
|
||||||
|
if (argp_program_version || argp_program_version_hook)
|
||||||
|
(child++)->argp = &argp_version_argp;
|
||||||
|
child->argp = 0;
|
||||||
|
|
||||||
|
argp = top_argp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Construct a parser for these arguments. */
|
||||||
|
err = parser_init (&parser, argp, argc, argv, flags, input);
|
||||||
|
|
||||||
|
if (! err)
|
||||||
|
/* Parse! */
|
||||||
|
{
|
||||||
|
while (! err)
|
||||||
|
err = parser_parse_next (&parser, &arg_ebadkey);
|
||||||
|
err = parser_finalize (&parser, err, arg_ebadkey, end_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
#ifdef weak_alias
|
||||||
|
weak_alias (__argp_parse, argp_parse)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Return the input field for ARGP in the parser corresponding to STATE; used
|
||||||
|
by the help routines. */
|
||||||
|
void *
|
||||||
|
__argp_input (const struct argp *argp, const struct argp_state *state)
|
||||||
|
{
|
||||||
|
if (state)
|
||||||
|
{
|
||||||
|
struct group *group;
|
||||||
|
struct parser *parser = state->pstate;
|
||||||
|
|
||||||
|
for (group = parser->groups; group < parser->egroup; group++)
|
||||||
|
if (group->argp == argp)
|
||||||
|
return group->input;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#ifdef weak_alias
|
||||||
|
weak_alias (__argp_input, _argp_input)
|
||||||
|
#endif
|
27
gnulib/argp-pin.c
Normal file
27
gnulib/argp-pin.c
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/* Full and short program names for argp module
|
||||||
|
Copyright (C) 2005, 2009, 2010 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This program 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.
|
||||||
|
|
||||||
|
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME
|
||||||
|
char *program_invocation_short_name = 0;
|
||||||
|
#endif
|
||||||
|
#ifndef HAVE_PROGRAM_INVOCATION_NAME
|
||||||
|
char *program_invocation_name = 0;
|
||||||
|
#endif
|
||||||
|
|
34
gnulib/argp-pv.c
Normal file
34
gnulib/argp-pv.c
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/* Default definition for ARGP_PROGRAM_VERSION.
|
||||||
|
Copyright (C) 1996, 1997, 1999, 2006, 2009, 2010 Free Software Foundation,
|
||||||
|
Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Written by Miles Bader <miles@gnu.ai.mit.edu>.
|
||||||
|
|
||||||
|
This program 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.
|
||||||
|
|
||||||
|
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
/* If set by the user program to a non-zero value, then a default option
|
||||||
|
--version is added (unless the ARGP_NO_HELP flag is used), which will
|
||||||
|
print this string followed by a newline and exit (unless the
|
||||||
|
ARGP_NO_EXIT flag is used). Overridden by ARGP_PROGRAM_VERSION_HOOK. */
|
||||||
|
const char *argp_program_version
|
||||||
|
/* This variable should be zero-initialized. On most systems, putting it into
|
||||||
|
BSS is sufficient. Not so on MacOS X 10.3 and 10.4, see
|
||||||
|
<http://lists.gnu.org/archive/html/bug-gnulib/2009-01/msg00329.html>
|
||||||
|
<http://lists.gnu.org/archive/html/bug-gnulib/2009-08/msg00096.html>. */
|
||||||
|
#if defined __ELF__
|
||||||
|
/* On ELF systems, variables in BSS behave well. */
|
||||||
|
#else
|
||||||
|
= (const char *) 0
|
||||||
|
#endif
|
||||||
|
;
|
31
gnulib/argp-pvh.c
Normal file
31
gnulib/argp-pvh.c
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/* Default definition for ARGP_PROGRAM_VERSION_HOOK.
|
||||||
|
Copyright (C) 1996, 1997, 1999, 2004, 2009, 2010 Free Software Foundation,
|
||||||
|
Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Written by Miles Bader <miles@gnu.ai.mit.edu>.
|
||||||
|
|
||||||
|
This program 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.
|
||||||
|
|
||||||
|
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "argp.h"
|
||||||
|
|
||||||
|
/* If set by the user program to a non-zero value, then a default option
|
||||||
|
--version is added (unless the ARGP_NO_HELP flag is used), which calls
|
||||||
|
this function with a stream to print the version to and a pointer to the
|
||||||
|
current parsing state, and then exits (unless the ARGP_NO_EXIT flag is
|
||||||
|
used). This variable takes precedent over ARGP_PROGRAM_VERSION. */
|
||||||
|
void (*argp_program_version_hook) (FILE *stream, struct argp_state *state) = NULL;
|
38
gnulib/argp-version-etc.c
Normal file
38
gnulib/argp-version-etc.c
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/* Version hook for Argp.
|
||||||
|
Copyright (C) 2009, 2010 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This program 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.
|
||||||
|
|
||||||
|
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
#include <version-etc.h>
|
||||||
|
#include <argp.h>
|
||||||
|
#include <argp-version-etc.h>
|
||||||
|
|
||||||
|
static const char *program_canonical_name;
|
||||||
|
static const char * const *program_authors;
|
||||||
|
|
||||||
|
static void
|
||||||
|
version_etc_hook (FILE *stream, struct argp_state *state)
|
||||||
|
{
|
||||||
|
version_etc_ar (stream, program_canonical_name, PACKAGE_NAME, VERSION,
|
||||||
|
program_authors);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
argp_version_setup (const char *name, const char * const *authors)
|
||||||
|
{
|
||||||
|
argp_program_version_hook = version_etc_hook;
|
||||||
|
program_canonical_name = name;
|
||||||
|
program_authors = authors;
|
||||||
|
}
|
40
gnulib/argp-version-etc.h
Normal file
40
gnulib/argp-version-etc.h
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/* Version hook for Argp.
|
||||||
|
Copyright (C) 2009, 2010 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This program 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.
|
||||||
|
|
||||||
|
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
#ifndef _ARGP_VERSION_ETC_H
|
||||||
|
#define _ARGP_VERSION_ETC_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Setup standard display of the version information for the `--version'
|
||||||
|
option. NAME is the canonical program name, and AUTHORS is a NULL-
|
||||||
|
terminated array of author names. At least one author name must be
|
||||||
|
given.
|
||||||
|
|
||||||
|
If NAME is NULL, the package name (as given by the PACKAGE macro)
|
||||||
|
is asumed to be the name of the program.
|
||||||
|
|
||||||
|
This function is intended to be called before argp_parse().
|
||||||
|
*/
|
||||||
|
extern void argp_version_setup (const char *name, const char * const *authors);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _ARGP_VERSION_ETC_H */
|
42
gnulib/argp-xinl.c
Normal file
42
gnulib/argp-xinl.c
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
/* Real definitions for extern inline functions in argp.h
|
||||||
|
Copyright (C) 1997, 1998, 2004, 2009, 2010 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Written by Miles Bader <miles@gnu.ai.mit.edu>.
|
||||||
|
|
||||||
|
This program 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.
|
||||||
|
|
||||||
|
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined _LIBC || defined HAVE_FEATURES_H
|
||||||
|
# include <features.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __USE_EXTERN_INLINES
|
||||||
|
# define __USE_EXTERN_INLINES 1
|
||||||
|
#endif
|
||||||
|
#define ARGP_EI
|
||||||
|
#undef __OPTIMIZE__
|
||||||
|
#define __OPTIMIZE__ 1
|
||||||
|
#include "argp.h"
|
||||||
|
|
||||||
|
/* Add weak aliases. */
|
||||||
|
#if _LIBC - 0 && defined (weak_alias)
|
||||||
|
|
||||||
|
weak_alias (__argp_usage, argp_usage)
|
||||||
|
weak_alias (__option_is_short, _option_is_short)
|
||||||
|
weak_alias (__option_is_end, _option_is_end)
|
||||||
|
|
||||||
|
#endif
|
645
gnulib/argp.h
Normal file
645
gnulib/argp.h
Normal file
|
@ -0,0 +1,645 @@
|
||||||
|
/* Hierarchial argument parsing, layered over getopt.
|
||||||
|
Copyright (C) 1995-1999, 2003-2010 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Written by Miles Bader <miles@gnu.ai.mit.edu>.
|
||||||
|
|
||||||
|
This program 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.
|
||||||
|
|
||||||
|
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
#ifndef _ARGP_H
|
||||||
|
#define _ARGP_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
#define __need_error_t
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#ifndef __THROW
|
||||||
|
# define __THROW
|
||||||
|
#endif
|
||||||
|
#ifndef __NTH
|
||||||
|
# define __NTH(fct) fct __THROW
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __attribute__
|
||||||
|
/* The __attribute__ feature is available in gcc versions 2.5 and later.
|
||||||
|
The __-protected variants of the attributes 'format' and 'printf' are
|
||||||
|
accepted by gcc versions 2.6.4 (effectively 2.7) and later.
|
||||||
|
We enable __attribute__ only if these are supported too, because
|
||||||
|
gnulib and libintl do '#define printf __printf__' when they override
|
||||||
|
the 'printf' function. */
|
||||||
|
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
|
||||||
|
# define __attribute__(Spec) /* empty */
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* GCC 2.95 and later have "__restrict"; C99 compilers have
|
||||||
|
"restrict", and "configure" may have defined "restrict".
|
||||||
|
Other compilers use __restrict, __restrict__, and _Restrict, and
|
||||||
|
'configure' might #define 'restrict' to those words. */
|
||||||
|
#ifndef __restrict
|
||||||
|
# if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__))
|
||||||
|
# if 199901L <= __STDC_VERSION__
|
||||||
|
# define __restrict restrict
|
||||||
|
# else
|
||||||
|
# define __restrict
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __error_t_defined
|
||||||
|
typedef int error_t;
|
||||||
|
# define __error_t_defined
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* A description of a particular option. A pointer to an array of
|
||||||
|
these is passed in the OPTIONS field of an argp structure. Each option
|
||||||
|
entry can correspond to one long option and/or one short option; more
|
||||||
|
names for the same option can be added by following an entry in an option
|
||||||
|
array with options having the OPTION_ALIAS flag set. */
|
||||||
|
struct argp_option
|
||||||
|
{
|
||||||
|
/* The long option name. For more than one name for the same option, you
|
||||||
|
can use following options with the OPTION_ALIAS flag set. */
|
||||||
|
const char *name;
|
||||||
|
|
||||||
|
/* What key is returned for this option. If > 0 and printable, then it's
|
||||||
|
also accepted as a short option. */
|
||||||
|
int key;
|
||||||
|
|
||||||
|
/* If non-NULL, this is the name of the argument associated with this
|
||||||
|
option, which is required unless the OPTION_ARG_OPTIONAL flag is set. */
|
||||||
|
const char *arg;
|
||||||
|
|
||||||
|
/* OPTION_ flags. */
|
||||||
|
int flags;
|
||||||
|
|
||||||
|
/* The doc string for this option. If both NAME and KEY are 0, This string
|
||||||
|
will be printed outdented from the normal option column, making it
|
||||||
|
useful as a group header (it will be the first thing printed in its
|
||||||
|
group); in this usage, it's conventional to end the string with a `:'.
|
||||||
|
|
||||||
|
Write the initial value as N_("TEXT") if you want xgettext to collect
|
||||||
|
it into a POT file. */
|
||||||
|
const char *doc;
|
||||||
|
|
||||||
|
/* The group this option is in. In a long help message, options are sorted
|
||||||
|
alphabetically within each group, and the groups presented in the order
|
||||||
|
0, 1, 2, ..., n, -m, ..., -2, -1. Every entry in an options array with
|
||||||
|
if this field 0 will inherit the group number of the previous entry, or
|
||||||
|
zero if it's the first one, unless its a group header (NAME and KEY both
|
||||||
|
0), in which case, the previous entry + 1 is the default. Automagic
|
||||||
|
options such as --help are put into group -1. */
|
||||||
|
int group;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* The argument associated with this option is optional. */
|
||||||
|
#define OPTION_ARG_OPTIONAL 0x1
|
||||||
|
|
||||||
|
/* This option isn't displayed in any help messages. */
|
||||||
|
#define OPTION_HIDDEN 0x2
|
||||||
|
|
||||||
|
/* This option is an alias for the closest previous non-alias option. This
|
||||||
|
means that it will be displayed in the same help entry, and will inherit
|
||||||
|
fields other than NAME and KEY from the aliased option. */
|
||||||
|
#define OPTION_ALIAS 0x4
|
||||||
|
|
||||||
|
/* This option isn't actually an option (and so should be ignored by the
|
||||||
|
actual option parser), but rather an arbitrary piece of documentation that
|
||||||
|
should be displayed in much the same manner as the options. If this flag
|
||||||
|
is set, then the option NAME field is displayed unmodified (e.g., no `--'
|
||||||
|
prefix is added) at the left-margin (where a *short* option would normally
|
||||||
|
be displayed), and the documentation string in the normal place. The NAME
|
||||||
|
field will be translated using gettext, unless OPTION_NO_TRANS is set (see
|
||||||
|
below). For purposes of sorting, any leading whitespace and punctuation is
|
||||||
|
ignored, except that if the first non-whitespace character is not `-', this
|
||||||
|
entry is displayed after all options (and OPTION_DOC entries with a leading
|
||||||
|
`-') in the same group. */
|
||||||
|
#define OPTION_DOC 0x8
|
||||||
|
|
||||||
|
/* This option shouldn't be included in `long' usage messages (but is still
|
||||||
|
included in help messages). This is mainly intended for options that are
|
||||||
|
completely documented in an argp's ARGS_DOC field, in which case including
|
||||||
|
the option in the generic usage list would be redundant. For instance,
|
||||||
|
if ARGS_DOC is "FOO BAR\n-x BLAH", and the `-x' option's purpose is to
|
||||||
|
distinguish these two cases, -x should probably be marked
|
||||||
|
OPTION_NO_USAGE. */
|
||||||
|
#define OPTION_NO_USAGE 0x10
|
||||||
|
|
||||||
|
/* Valid only in conjunction with OPTION_DOC. This option disables translation
|
||||||
|
of option name. */
|
||||||
|
#define OPTION_NO_TRANS 0x20
|
||||||
|
|
||||||
|
|
||||||
|
struct argp; /* fwd declare this type */
|
||||||
|
struct argp_state; /* " */
|
||||||
|
struct argp_child; /* " */
|
||||||
|
|
||||||
|
/* The type of a pointer to an argp parsing function. */
|
||||||
|
typedef error_t (*argp_parser_t) (int key, char *arg,
|
||||||
|
struct argp_state *state);
|
||||||
|
|
||||||
|
/* What to return for unrecognized keys. For special ARGP_KEY_ keys, such
|
||||||
|
returns will simply be ignored. For user keys, this error will be turned
|
||||||
|
into EINVAL (if the call to argp_parse is such that errors are propagated
|
||||||
|
back to the user instead of exiting); returning EINVAL itself would result
|
||||||
|
in an immediate stop to parsing in *all* cases. */
|
||||||
|
#define ARGP_ERR_UNKNOWN E2BIG /* Hurd should never need E2BIG. XXX */
|
||||||
|
|
||||||
|
/* Special values for the KEY argument to an argument parsing function.
|
||||||
|
ARGP_ERR_UNKNOWN should be returned if they aren't understood.
|
||||||
|
|
||||||
|
The sequence of keys to a parsing function is either (where each
|
||||||
|
uppercased word should be prefixed by `ARGP_KEY_' and opt is a user key):
|
||||||
|
|
||||||
|
INIT opt... NO_ARGS END SUCCESS -- No non-option arguments at all
|
||||||
|
or INIT (opt | ARG)... END SUCCESS -- All non-option args parsed
|
||||||
|
or INIT (opt | ARG)... SUCCESS -- Some non-option arg unrecognized
|
||||||
|
|
||||||
|
The third case is where every parser returned ARGP_KEY_UNKNOWN for an
|
||||||
|
argument, in which case parsing stops at that argument (returning the
|
||||||
|
unparsed arguments to the caller of argp_parse if requested, or stopping
|
||||||
|
with an error message if not).
|
||||||
|
|
||||||
|
If an error occurs (either detected by argp, or because the parsing
|
||||||
|
function returned an error value), then the parser is called with
|
||||||
|
ARGP_KEY_ERROR, and no further calls are made. */
|
||||||
|
|
||||||
|
/* This is not an option at all, but rather a command line argument. If a
|
||||||
|
parser receiving this key returns success, the fact is recorded, and the
|
||||||
|
ARGP_KEY_NO_ARGS case won't be used. HOWEVER, if while processing the
|
||||||
|
argument, a parser function decrements the NEXT field of the state it's
|
||||||
|
passed, the option won't be considered processed; this is to allow you to
|
||||||
|
actually modify the argument (perhaps into an option), and have it
|
||||||
|
processed again. */
|
||||||
|
#define ARGP_KEY_ARG 0
|
||||||
|
/* There are remaining arguments not parsed by any parser, which may be found
|
||||||
|
starting at (STATE->argv + STATE->next). If success is returned, but
|
||||||
|
STATE->next left untouched, it's assumed that all arguments were consume,
|
||||||
|
otherwise, the parser should adjust STATE->next to reflect any arguments
|
||||||
|
consumed. */
|
||||||
|
#define ARGP_KEY_ARGS 0x1000006
|
||||||
|
/* There are no more command line arguments at all. */
|
||||||
|
#define ARGP_KEY_END 0x1000001
|
||||||
|
/* Because it's common to want to do some special processing if there aren't
|
||||||
|
any non-option args, user parsers are called with this key if they didn't
|
||||||
|
successfully process any non-option arguments. Called just before
|
||||||
|
ARGP_KEY_END (where more general validity checks on previously parsed
|
||||||
|
arguments can take place). */
|
||||||
|
#define ARGP_KEY_NO_ARGS 0x1000002
|
||||||
|
/* Passed in before any parsing is done. Afterwards, the values of each
|
||||||
|
element of the CHILD_INPUT field, if any, in the state structure is
|
||||||
|
copied to each child's state to be the initial value of the INPUT field. */
|
||||||
|
#define ARGP_KEY_INIT 0x1000003
|
||||||
|
/* Use after all other keys, including SUCCESS & END. */
|
||||||
|
#define ARGP_KEY_FINI 0x1000007
|
||||||
|
/* Passed in when parsing has successfully been completed (even if there are
|
||||||
|
still arguments remaining). */
|
||||||
|
#define ARGP_KEY_SUCCESS 0x1000004
|
||||||
|
/* Passed in if an error occurs. */
|
||||||
|
#define ARGP_KEY_ERROR 0x1000005
|
||||||
|
|
||||||
|
/* An argp structure contains a set of options declarations, a function to
|
||||||
|
deal with parsing one, documentation string, a possible vector of child
|
||||||
|
argp's, and perhaps a function to filter help output. When actually
|
||||||
|
parsing options, getopt is called with the union of all the argp
|
||||||
|
structures chained together through their CHILD pointers, with conflicts
|
||||||
|
being resolved in favor of the first occurrence in the chain. */
|
||||||
|
struct argp
|
||||||
|
{
|
||||||
|
/* An array of argp_option structures, terminated by an entry with both
|
||||||
|
NAME and KEY having a value of 0. */
|
||||||
|
const struct argp_option *options;
|
||||||
|
|
||||||
|
/* What to do with an option from this structure. KEY is the key
|
||||||
|
associated with the option, and ARG is any associated argument (NULL if
|
||||||
|
none was supplied). If KEY isn't understood, ARGP_ERR_UNKNOWN should be
|
||||||
|
returned. If a non-zero, non-ARGP_ERR_UNKNOWN value is returned, then
|
||||||
|
parsing is stopped immediately, and that value is returned from
|
||||||
|
argp_parse(). For special (non-user-supplied) values of KEY, see the
|
||||||
|
ARGP_KEY_ definitions below. */
|
||||||
|
argp_parser_t parser;
|
||||||
|
|
||||||
|
/* A string describing what other arguments are wanted by this program. It
|
||||||
|
is only used by argp_usage to print the `Usage:' message. If it
|
||||||
|
contains newlines, the strings separated by them are considered
|
||||||
|
alternative usage patterns, and printed on separate lines (lines after
|
||||||
|
the first are prefix by ` or: ' instead of `Usage:'). */
|
||||||
|
const char *args_doc;
|
||||||
|
|
||||||
|
/* If non-NULL, a string containing extra text to be printed before and
|
||||||
|
after the options in a long help message (separated by a vertical tab
|
||||||
|
`\v' character).
|
||||||
|
Write the initial value as N_("BEFORE-TEXT") "\v" N_("AFTER-TEXT") if
|
||||||
|
you want xgettext to collect the two pieces of text into a POT file. */
|
||||||
|
const char *doc;
|
||||||
|
|
||||||
|
/* A vector of argp_children structures, terminated by a member with a 0
|
||||||
|
argp field, pointing to child argps should be parsed with this one. Any
|
||||||
|
conflicts are resolved in favor of this argp, or early argps in the
|
||||||
|
CHILDREN list. This field is useful if you use libraries that supply
|
||||||
|
their own argp structure, which you want to use in conjunction with your
|
||||||
|
own. */
|
||||||
|
const struct argp_child *children;
|
||||||
|
|
||||||
|
/* If non-zero, this should be a function to filter the output of help
|
||||||
|
messages. KEY is either a key from an option, in which case TEXT is
|
||||||
|
that option's help text, or a special key from the ARGP_KEY_HELP_
|
||||||
|
defines, below, describing which other help text TEXT is. The function
|
||||||
|
should return either TEXT, if it should be used as-is, a replacement
|
||||||
|
string, which should be malloced, and will be freed by argp, or NULL,
|
||||||
|
meaning `print nothing'. The value for TEXT is *after* any translation
|
||||||
|
has been done, so if any of the replacement text also needs translation,
|
||||||
|
that should be done by the filter function. INPUT is either the input
|
||||||
|
supplied to argp_parse, or NULL, if argp_help was called directly. */
|
||||||
|
char *(*help_filter) (int __key, const char *__text, void *__input);
|
||||||
|
|
||||||
|
/* If non-zero the strings used in the argp library are translated using
|
||||||
|
the domain described by this string. Otherwise the currently installed
|
||||||
|
default domain is used. */
|
||||||
|
const char *argp_domain;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Possible KEY arguments to a help filter function. */
|
||||||
|
#define ARGP_KEY_HELP_PRE_DOC 0x2000001 /* Help text preceeding options. */
|
||||||
|
#define ARGP_KEY_HELP_POST_DOC 0x2000002 /* Help text following options. */
|
||||||
|
#define ARGP_KEY_HELP_HEADER 0x2000003 /* Option header string. */
|
||||||
|
#define ARGP_KEY_HELP_EXTRA 0x2000004 /* After all other documentation;
|
||||||
|
TEXT is NULL for this key. */
|
||||||
|
/* Explanatory note emitted when duplicate option arguments have been
|
||||||
|
suppressed. */
|
||||||
|
#define ARGP_KEY_HELP_DUP_ARGS_NOTE 0x2000005
|
||||||
|
#define ARGP_KEY_HELP_ARGS_DOC 0x2000006 /* Argument doc string. */
|
||||||
|
|
||||||
|
/* When an argp has a non-zero CHILDREN field, it should point to a vector of
|
||||||
|
argp_child structures, each of which describes a subsidiary argp. */
|
||||||
|
struct argp_child
|
||||||
|
{
|
||||||
|
/* The child parser. */
|
||||||
|
const struct argp *argp;
|
||||||
|
|
||||||
|
/* Flags for this child. */
|
||||||
|
int flags;
|
||||||
|
|
||||||
|
/* If non-zero, an optional header to be printed in help output before the
|
||||||
|
child options. As a side-effect, a non-zero value forces the child
|
||||||
|
options to be grouped together; to achieve this effect without actually
|
||||||
|
printing a header string, use a value of "". */
|
||||||
|
const char *header;
|
||||||
|
|
||||||
|
/* Where to group the child options relative to the other (`consolidated')
|
||||||
|
options in the parent argp; the values are the same as the GROUP field
|
||||||
|
in argp_option structs, but all child-groupings follow parent options at
|
||||||
|
a particular group level. If both this field and HEADER are zero, then
|
||||||
|
they aren't grouped at all, but rather merged with the parent options
|
||||||
|
(merging the child's grouping levels with the parents). */
|
||||||
|
int group;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Parsing state. This is provided to parsing functions called by argp,
|
||||||
|
which may examine and, as noted, modify fields. */
|
||||||
|
struct argp_state
|
||||||
|
{
|
||||||
|
/* The top level ARGP being parsed. */
|
||||||
|
const struct argp *root_argp;
|
||||||
|
|
||||||
|
/* The argument vector being parsed. May be modified. */
|
||||||
|
int argc;
|
||||||
|
char **argv;
|
||||||
|
|
||||||
|
/* The index in ARGV of the next arg that to be parsed. May be modified. */
|
||||||
|
int next;
|
||||||
|
|
||||||
|
/* The flags supplied to argp_parse. May be modified. */
|
||||||
|
unsigned flags;
|
||||||
|
|
||||||
|
/* While calling a parsing function with a key of ARGP_KEY_ARG, this is the
|
||||||
|
number of the current arg, starting at zero, and incremented after each
|
||||||
|
such call returns. At all other times, this is the number of such
|
||||||
|
arguments that have been processed. */
|
||||||
|
unsigned arg_num;
|
||||||
|
|
||||||
|
/* If non-zero, the index in ARGV of the first argument following a special
|
||||||
|
`--' argument (which prevents anything following being interpreted as an
|
||||||
|
option). Only set once argument parsing has proceeded past this point. */
|
||||||
|
int quoted;
|
||||||
|
|
||||||
|
/* An arbitrary pointer passed in from the user. */
|
||||||
|
void *input;
|
||||||
|
/* Values to pass to child parsers. This vector will be the same length as
|
||||||
|
the number of children for the current parser. */
|
||||||
|
void **child_inputs;
|
||||||
|
|
||||||
|
/* For the parser's use. Initialized to 0. */
|
||||||
|
void *hook;
|
||||||
|
|
||||||
|
/* The name used when printing messages. This is initialized to ARGV[0],
|
||||||
|
or PROGRAM_INVOCATION_NAME if that is unavailable. */
|
||||||
|
char *name;
|
||||||
|
|
||||||
|
/* Streams used when argp prints something. */
|
||||||
|
FILE *err_stream; /* For errors; initialized to stderr. */
|
||||||
|
FILE *out_stream; /* For information; initialized to stdout. */
|
||||||
|
|
||||||
|
void *pstate; /* Private, for use by argp. */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Flags for argp_parse (note that the defaults are those that are
|
||||||
|
convenient for program command line parsing): */
|
||||||
|
|
||||||
|
/* Don't ignore the first element of ARGV. Normally (and always unless
|
||||||
|
ARGP_NO_ERRS is set) the first element of the argument vector is
|
||||||
|
skipped for option parsing purposes, as it corresponds to the program name
|
||||||
|
in a command line. */
|
||||||
|
#define ARGP_PARSE_ARGV0 0x01
|
||||||
|
|
||||||
|
/* Don't print error messages for unknown options to stderr; unless this flag
|
||||||
|
is set, ARGP_PARSE_ARGV0 is ignored, as ARGV[0] is used as the program
|
||||||
|
name in the error messages. This flag implies ARGP_NO_EXIT (on the
|
||||||
|
assumption that silent exiting upon errors is bad behaviour). */
|
||||||
|
#define ARGP_NO_ERRS 0x02
|
||||||
|
|
||||||
|
/* Don't parse any non-option args. Normally non-option args are parsed by
|
||||||
|
calling the parse functions with a key of ARGP_KEY_ARG, and the actual arg
|
||||||
|
as the value. Since it's impossible to know which parse function wants to
|
||||||
|
handle it, each one is called in turn, until one returns 0 or an error
|
||||||
|
other than ARGP_ERR_UNKNOWN; if an argument is handled by no one, the
|
||||||
|
argp_parse returns prematurely (but with a return value of 0). If all
|
||||||
|
args have been parsed without error, all parsing functions are called one
|
||||||
|
last time with a key of ARGP_KEY_END. This flag needn't normally be set,
|
||||||
|
as the normal behavior is to stop parsing as soon as some argument can't
|
||||||
|
be handled. */
|
||||||
|
#define ARGP_NO_ARGS 0x04
|
||||||
|
|
||||||
|
/* Parse options and arguments in the same order they occur on the command
|
||||||
|
line -- normally they're rearranged so that all options come first. */
|
||||||
|
#define ARGP_IN_ORDER 0x08
|
||||||
|
|
||||||
|
/* Don't provide the standard long option --help, which causes usage and
|
||||||
|
option help information to be output to stdout, and exit (0) called. */
|
||||||
|
#define ARGP_NO_HELP 0x10
|
||||||
|
|
||||||
|
/* Don't exit on errors (they may still result in error messages). */
|
||||||
|
#define ARGP_NO_EXIT 0x20
|
||||||
|
|
||||||
|
/* Use the gnu getopt `long-only' rules for parsing arguments. */
|
||||||
|
#define ARGP_LONG_ONLY 0x40
|
||||||
|
|
||||||
|
/* Turns off any message-printing/exiting options. */
|
||||||
|
#define ARGP_SILENT (ARGP_NO_EXIT | ARGP_NO_ERRS | ARGP_NO_HELP)
|
||||||
|
|
||||||
|
/* Parse the options strings in ARGC & ARGV according to the options in ARGP.
|
||||||
|
FLAGS is one of the ARGP_ flags above. If ARG_INDEX is non-NULL, the
|
||||||
|
index in ARGV of the first unparsed option is returned in it. If an
|
||||||
|
unknown option is present, ARGP_ERR_UNKNOWN is returned; if some parser
|
||||||
|
routine returned a non-zero value, it is returned; otherwise 0 is
|
||||||
|
returned. This function may also call exit unless the ARGP_NO_HELP flag
|
||||||
|
is set. INPUT is a pointer to a value to be passed in to the parser. */
|
||||||
|
extern error_t argp_parse (const struct argp *__restrict __argp,
|
||||||
|
int /*argc*/, char **__restrict /*argv*/,
|
||||||
|
unsigned __flags, int *__restrict __arg_index,
|
||||||
|
void *__restrict __input);
|
||||||
|
extern error_t __argp_parse (const struct argp *__restrict __argp,
|
||||||
|
int /*argc*/, char **__restrict /*argv*/,
|
||||||
|
unsigned __flags, int *__restrict __arg_index,
|
||||||
|
void *__restrict __input);
|
||||||
|
|
||||||
|
/* Global variables. */
|
||||||
|
|
||||||
|
/* GNULIB makes sure both program_invocation_name and
|
||||||
|
program_invocation_short_name are available */
|
||||||
|
#ifdef GNULIB_PROGRAM_INVOCATION_NAME
|
||||||
|
extern char *program_invocation_name;
|
||||||
|
# undef HAVE_DECL_PROGRAM_INVOCATION_NAME
|
||||||
|
# define HAVE_DECL_PROGRAM_INVOCATION_NAME 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef GNULIB_PROGRAM_INVOCATION_SHORT_NAME
|
||||||
|
extern char *program_invocation_short_name;
|
||||||
|
# undef HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
|
||||||
|
# define HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* If defined or set by the user program to a non-zero value, then a default
|
||||||
|
option --version is added (unless the ARGP_NO_HELP flag is used), which
|
||||||
|
will print this string followed by a newline and exit (unless the
|
||||||
|
ARGP_NO_EXIT flag is used). Overridden by ARGP_PROGRAM_VERSION_HOOK. */
|
||||||
|
extern const char *argp_program_version;
|
||||||
|
|
||||||
|
/* If defined or set by the user program to a non-zero value, then a default
|
||||||
|
option --version is added (unless the ARGP_NO_HELP flag is used), which
|
||||||
|
calls this function with a stream to print the version to and a pointer to
|
||||||
|
the current parsing state, and then exits (unless the ARGP_NO_EXIT flag is
|
||||||
|
used). This variable takes precedent over ARGP_PROGRAM_VERSION. */
|
||||||
|
extern void (*argp_program_version_hook) (FILE *__restrict __stream,
|
||||||
|
struct argp_state *__restrict
|
||||||
|
__state);
|
||||||
|
|
||||||
|
/* If defined or set by the user program, it should point to string that is
|
||||||
|
the bug-reporting address for the program. It will be printed by
|
||||||
|
argp_help if the ARGP_HELP_BUG_ADDR flag is set (as it is by various
|
||||||
|
standard help messages), embedded in a sentence that says something like
|
||||||
|
`Report bugs to ADDR.'. */
|
||||||
|
extern const char *argp_program_bug_address;
|
||||||
|
|
||||||
|
/* The exit status that argp will use when exiting due to a parsing error.
|
||||||
|
If not defined or set by the user program, this defaults to EX_USAGE from
|
||||||
|
<sysexits.h>. */
|
||||||
|
extern error_t argp_err_exit_status;
|
||||||
|
|
||||||
|
/* Flags for argp_help. */
|
||||||
|
#define ARGP_HELP_USAGE 0x01 /* a Usage: message. */
|
||||||
|
#define ARGP_HELP_SHORT_USAGE 0x02 /* " but don't actually print options. */
|
||||||
|
#define ARGP_HELP_SEE 0x04 /* a `Try ... for more help' message. */
|
||||||
|
#define ARGP_HELP_LONG 0x08 /* a long help message. */
|
||||||
|
#define ARGP_HELP_PRE_DOC 0x10 /* doc string preceding long help. */
|
||||||
|
#define ARGP_HELP_POST_DOC 0x20 /* doc string following long help. */
|
||||||
|
#define ARGP_HELP_DOC (ARGP_HELP_PRE_DOC | ARGP_HELP_POST_DOC)
|
||||||
|
#define ARGP_HELP_BUG_ADDR 0x40 /* bug report address */
|
||||||
|
#define ARGP_HELP_LONG_ONLY 0x80 /* modify output appropriately to
|
||||||
|
reflect ARGP_LONG_ONLY mode. */
|
||||||
|
|
||||||
|
/* These ARGP_HELP flags are only understood by argp_state_help. */
|
||||||
|
#define ARGP_HELP_EXIT_ERR 0x100 /* Call exit(1) instead of returning. */
|
||||||
|
#define ARGP_HELP_EXIT_OK 0x200 /* Call exit(0) instead of returning. */
|
||||||
|
|
||||||
|
/* The standard thing to do after a program command line parsing error, if an
|
||||||
|
error message has already been printed. */
|
||||||
|
#define ARGP_HELP_STD_ERR \
|
||||||
|
(ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR)
|
||||||
|
/* The standard thing to do after a program command line parsing error, if no
|
||||||
|
more specific error message has been printed. */
|
||||||
|
#define ARGP_HELP_STD_USAGE \
|
||||||
|
(ARGP_HELP_SHORT_USAGE | ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR)
|
||||||
|
/* The standard thing to do in response to a --help option. */
|
||||||
|
#define ARGP_HELP_STD_HELP \
|
||||||
|
(ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG | ARGP_HELP_EXIT_OK \
|
||||||
|
| ARGP_HELP_DOC | ARGP_HELP_BUG_ADDR)
|
||||||
|
|
||||||
|
/* Output a usage message for ARGP to STREAM. FLAGS are from the set
|
||||||
|
ARGP_HELP_*. */
|
||||||
|
extern void argp_help (const struct argp *__restrict __argp,
|
||||||
|
FILE *__restrict __stream,
|
||||||
|
unsigned __flags, char *__restrict __name);
|
||||||
|
extern void __argp_help (const struct argp *__restrict __argp,
|
||||||
|
FILE *__restrict __stream, unsigned __flags,
|
||||||
|
char *__name);
|
||||||
|
|
||||||
|
/* The following routines are intended to be called from within an argp
|
||||||
|
parsing routine (thus taking an argp_state structure as the first
|
||||||
|
argument). They may or may not print an error message and exit, depending
|
||||||
|
on the flags in STATE -- in any case, the caller should be prepared for
|
||||||
|
them *not* to exit, and should return an appropiate error after calling
|
||||||
|
them. [argp_usage & argp_error should probably be called argp_state_...,
|
||||||
|
but they're used often enough that they should be short] */
|
||||||
|
|
||||||
|
/* Output, if appropriate, a usage message for STATE to STREAM. FLAGS are
|
||||||
|
from the set ARGP_HELP_*. */
|
||||||
|
extern void argp_state_help (const struct argp_state *__restrict __state,
|
||||||
|
FILE *__restrict __stream,
|
||||||
|
unsigned int __flags);
|
||||||
|
extern void __argp_state_help (const struct argp_state *__restrict __state,
|
||||||
|
FILE *__restrict __stream,
|
||||||
|
unsigned int __flags);
|
||||||
|
|
||||||
|
#if _LIBC || !defined __USE_EXTERN_INLINES
|
||||||
|
/* Possibly output the standard usage message for ARGP to stderr and exit. */
|
||||||
|
extern void argp_usage (const struct argp_state *__state);
|
||||||
|
extern void __argp_usage (const struct argp_state *__state);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* If appropriate, print the printf string FMT and following args, preceded
|
||||||
|
by the program name and `:', to stderr, and followed by a `Try ... --help'
|
||||||
|
message, then exit (1). */
|
||||||
|
extern void argp_error (const struct argp_state *__restrict __state,
|
||||||
|
const char *__restrict __fmt, ...)
|
||||||
|
__attribute__ ((__format__ (__printf__, 2, 3)));
|
||||||
|
extern void __argp_error (const struct argp_state *__restrict __state,
|
||||||
|
const char *__restrict __fmt, ...)
|
||||||
|
__attribute__ ((__format__ (__printf__, 2, 3)));
|
||||||
|
|
||||||
|
/* Similar to the standard gnu error-reporting function error(), but will
|
||||||
|
respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print
|
||||||
|
to STATE->err_stream. This is useful for argument parsing code that is
|
||||||
|
shared between program startup (when exiting is desired) and runtime
|
||||||
|
option parsing (when typically an error code is returned instead). The
|
||||||
|
difference between this function and argp_error is that the latter is for
|
||||||
|
*parsing errors*, and the former is for other problems that occur during
|
||||||
|
parsing but don't reflect a (syntactic) problem with the input. */
|
||||||
|
extern void argp_failure (const struct argp_state *__restrict __state,
|
||||||
|
int __status, int __errnum,
|
||||||
|
const char *__restrict __fmt, ...)
|
||||||
|
__attribute__ ((__format__ (__printf__, 4, 5)));
|
||||||
|
extern void __argp_failure (const struct argp_state *__restrict __state,
|
||||||
|
int __status, int __errnum,
|
||||||
|
const char *__restrict __fmt, ...)
|
||||||
|
__attribute__ ((__format__ (__printf__, 4, 5)));
|
||||||
|
|
||||||
|
#if _LIBC || !defined __USE_EXTERN_INLINES
|
||||||
|
/* Returns true if the option OPT is a valid short option. */
|
||||||
|
extern int _option_is_short (const struct argp_option *__opt) __THROW;
|
||||||
|
extern int __option_is_short (const struct argp_option *__opt) __THROW;
|
||||||
|
|
||||||
|
/* Returns true if the option OPT is in fact the last (unused) entry in an
|
||||||
|
options array. */
|
||||||
|
extern int _option_is_end (const struct argp_option *__opt) __THROW;
|
||||||
|
extern int __option_is_end (const struct argp_option *__opt) __THROW;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Return the input field for ARGP in the parser corresponding to STATE; used
|
||||||
|
by the help routines. */
|
||||||
|
extern void *_argp_input (const struct argp *__restrict __argp,
|
||||||
|
const struct argp_state *__restrict __state)
|
||||||
|
__THROW;
|
||||||
|
extern void *__argp_input (const struct argp *__restrict __argp,
|
||||||
|
const struct argp_state *__restrict __state)
|
||||||
|
__THROW;
|
||||||
|
|
||||||
|
#ifdef __USE_EXTERN_INLINES
|
||||||
|
|
||||||
|
# if !_LIBC
|
||||||
|
# define __argp_usage argp_usage
|
||||||
|
# define __argp_state_help argp_state_help
|
||||||
|
# define __option_is_short _option_is_short
|
||||||
|
# define __option_is_end _option_is_end
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# ifndef ARGP_EI
|
||||||
|
# ifdef __GNUC__
|
||||||
|
/* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
|
||||||
|
inline semantics, unless -fgnu89-inline is used. It defines a macro
|
||||||
|
__GNUC_STDC_INLINE__ to indicate this situation or a macro
|
||||||
|
__GNUC_GNU_INLINE__ to indicate the opposite situation.
|
||||||
|
GCC 4.2 with -std=c99 or -std=gnu99 implements the GNU C inline
|
||||||
|
semantics but warns, unless -fgnu89-inline is used:
|
||||||
|
warning: C99 inline functions are not supported; using GNU89
|
||||||
|
warning: to disable this warning use -fgnu89-inline or the gnu_inline function attribute
|
||||||
|
It defines a macro __GNUC_GNU_INLINE__ to indicate this situation. */
|
||||||
|
# if defined __GNUC_STDC_INLINE__
|
||||||
|
# define ARGP_EI __inline__
|
||||||
|
# elif defined __GNUC_GNU_INLINE__
|
||||||
|
# define ARGP_EI extern __inline__ __attribute__ ((__gnu_inline__))
|
||||||
|
# else
|
||||||
|
# define ARGP_EI extern __inline__
|
||||||
|
# endif
|
||||||
|
# else
|
||||||
|
/* With other compilers, assume the ISO C99 meaning of 'inline', if
|
||||||
|
the compiler supports 'inline' at all. */
|
||||||
|
# define ARGP_EI inline
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
|
||||||
|
ARGP_EI void
|
||||||
|
__argp_usage (const struct argp_state *__state)
|
||||||
|
{
|
||||||
|
__argp_state_help (__state, stderr, ARGP_HELP_STD_USAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
ARGP_EI int
|
||||||
|
__NTH (__option_is_short (const struct argp_option *__opt))
|
||||||
|
{
|
||||||
|
if (__opt->flags & OPTION_DOC)
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int __key = __opt->key;
|
||||||
|
return __key > 0 && __key <= UCHAR_MAX && isprint (__key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ARGP_EI int
|
||||||
|
__NTH (__option_is_end (const struct argp_option *__opt))
|
||||||
|
{
|
||||||
|
return !__opt->key && !__opt->name && !__opt->doc && !__opt->group;
|
||||||
|
}
|
||||||
|
|
||||||
|
# if !_LIBC
|
||||||
|
# undef __argp_usage
|
||||||
|
# undef __argp_state_help
|
||||||
|
# undef __option_is_short
|
||||||
|
# undef __option_is_end
|
||||||
|
# endif
|
||||||
|
#endif /* Use extern inlines. */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* argp.h */
|
31
include/grub/mips/multiboot.h
Normal file
31
include/grub/mips/multiboot.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* GRUB -- GRand Unified Bootloader
|
||||||
|
* Copyright (C) 2002,2003,2004,2007,2008,2009 Free Software Foundation, Inc.
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GRUB_MULTIBOOT_CPU_HEADER
|
||||||
|
#define GRUB_MULTIBOOT_CPU_HEADER 1
|
||||||
|
|
||||||
|
#define MULTIBOOT_INITIAL_STATE { .gpr[4] = MULTIBOOT_BOOTLOADER_MAGIC, \
|
||||||
|
.jumpreg = 1 }
|
||||||
|
#define MULTIBOOT_ENTRY_REGISTER gpr[1]
|
||||||
|
#define MULTIBOOT_MBI_REGISTER gpr[5]
|
||||||
|
#define MULTIBOOT_ARCHITECTURE_CURRENT MULTIBOOT_ARCHITECTURE_MIPS32
|
||||||
|
|
||||||
|
#define MULTIBOOT_ELF32_MACHINE EM_MIPS
|
||||||
|
#define MULTIBOOT_ELF64_MACHINE EM_MIPS
|
||||||
|
|
||||||
|
#endif /* ! GRUB_MULTIBOOT_CPU_HEADER */
|
|
@ -180,7 +180,8 @@ typedef enum grub_video_driver_id
|
||||||
GRUB_VIDEO_DRIVER_NONE,
|
GRUB_VIDEO_DRIVER_NONE,
|
||||||
GRUB_VIDEO_DRIVER_VBE,
|
GRUB_VIDEO_DRIVER_VBE,
|
||||||
GRUB_VIDEO_DRIVER_EFI_UGA,
|
GRUB_VIDEO_DRIVER_EFI_UGA,
|
||||||
GRUB_VIDEO_DRIVER_EFI_GOP
|
GRUB_VIDEO_DRIVER_EFI_GOP,
|
||||||
|
GRUB_VIDEO_DRIVER_SM712
|
||||||
} grub_video_driver_id_t;
|
} grub_video_driver_id_t;
|
||||||
|
|
||||||
struct grub_video_adapter
|
struct grub_video_adapter
|
||||||
|
@ -272,7 +273,7 @@ grub_err_t EXPORT_FUNC (grub_video_get_info) (struct grub_video_mode_info *mode_
|
||||||
sure that framebuffer address doesn't change. To ensure this abstraction
|
sure that framebuffer address doesn't change. To ensure this abstraction
|
||||||
grub_video_get_info_and_fini is the only function supplying framebuffer
|
grub_video_get_info_and_fini is the only function supplying framebuffer
|
||||||
address. */
|
address. */
|
||||||
grub_err_t grub_video_get_info_and_fini (struct grub_video_mode_info *mode_info,
|
grub_err_t EXPORT_FUNC (grub_video_get_info_and_fini) (struct grub_video_mode_info *mode_info,
|
||||||
void **framebuffer);
|
void **framebuffer);
|
||||||
|
|
||||||
enum grub_video_blit_format grub_video_get_blit_format (struct grub_video_mode_info *mode_info);
|
enum grub_video_blit_format grub_video_get_blit_format (struct grub_video_mode_info *mode_info);
|
||||||
|
@ -280,8 +281,9 @@ enum grub_video_blit_format grub_video_get_blit_format (struct grub_video_mode_i
|
||||||
grub_err_t grub_video_set_palette (unsigned int start, unsigned int count,
|
grub_err_t grub_video_set_palette (unsigned int start, unsigned int count,
|
||||||
struct grub_video_palette_data *palette_data);
|
struct grub_video_palette_data *palette_data);
|
||||||
|
|
||||||
grub_err_t grub_video_get_palette (unsigned int start, unsigned int count,
|
grub_err_t EXPORT_FUNC (grub_video_get_palette) (unsigned int start,
|
||||||
struct grub_video_palette_data *palette_data);
|
unsigned int count,
|
||||||
|
struct grub_video_palette_data *palette_data);
|
||||||
|
|
||||||
grub_err_t EXPORT_FUNC (grub_video_set_viewport) (unsigned int x,
|
grub_err_t EXPORT_FUNC (grub_video_set_viewport) (unsigned int x,
|
||||||
unsigned int y,
|
unsigned int y,
|
||||||
|
@ -356,7 +358,6 @@ grub_video_check_mode_flag (unsigned int flags, unsigned int mask,
|
||||||
return (flag & mask) ? !! (flags & flag) : def;
|
return (flag & mask) ? !! (flags & flag) : def;
|
||||||
}
|
}
|
||||||
|
|
||||||
grub_video_driver_id_t
|
grub_video_driver_id_t EXPORT_FUNC (grub_video_get_driver_id) (void);
|
||||||
grub_video_get_driver_id (void);
|
|
||||||
|
|
||||||
#endif /* ! GRUB_VIDEO_HEADER */
|
#endif /* ! GRUB_VIDEO_HEADER */
|
||||||
|
|
|
@ -61,7 +61,8 @@
|
||||||
#define MULTIBOOT_HEADER_TAG_FRAMEBUFFER 5
|
#define MULTIBOOT_HEADER_TAG_FRAMEBUFFER 5
|
||||||
#define MULTIBOOT_HEADER_TAG_MODULE_ALIGN 6
|
#define MULTIBOOT_HEADER_TAG_MODULE_ALIGN 6
|
||||||
|
|
||||||
#define GRUB_MULTIBOOT_ARCHITECTURE_I386 0
|
#define MULTIBOOT_ARCHITECTURE_I386 0
|
||||||
|
#define MULTIBOOT_ARCHITECTURE_MIPS32 4
|
||||||
#define MULTIBOOT_HEADER_TAG_OPTIONAL 1
|
#define MULTIBOOT_HEADER_TAG_OPTIONAL 1
|
||||||
|
|
||||||
#define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1
|
#define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1
|
||||||
|
|
|
@ -258,9 +258,9 @@ malloc_in_range (struct grub_relocator *rel,
|
||||||
for (cur = extra_blocks; cur; cur = cur->next)
|
for (cur = extra_blocks; cur; cur = cur->next)
|
||||||
maxevents += 2;
|
maxevents += 2;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
maxevents += grub_relocator_firmware_get_max_events ();
|
maxevents += grub_relocator_firmware_get_max_events ();
|
||||||
|
#endif
|
||||||
|
|
||||||
events = grub_malloc (maxevents * sizeof (events[0]));
|
events = grub_malloc (maxevents * sizeof (events[0]));
|
||||||
eventt = grub_malloc (maxevents * sizeof (events[0]));
|
eventt = grub_malloc (maxevents * sizeof (events[0]));
|
||||||
|
@ -372,7 +372,9 @@ malloc_in_range (struct grub_relocator *rel,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if GRUB_RELOCATOR_HAVE_FIRMWARE_REQUESTS
|
||||||
N += grub_relocator_firmware_fill_events (events + N);
|
N += grub_relocator_firmware_fill_events (events + N);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Put ending events after starting events. */
|
/* Put ending events after starting events. */
|
||||||
{
|
{
|
||||||
|
@ -492,7 +494,10 @@ malloc_in_range (struct grub_relocator *rel,
|
||||||
|
|
||||||
found:
|
found:
|
||||||
{
|
{
|
||||||
int inreg = 0, regbeg = 0, fwin = 0, fwb = 0, ncol = 0;
|
int inreg = 0, regbeg = 0, ncol = 0;
|
||||||
|
#if GRUB_RELOCATOR_HAVE_FIRMWARE_REQUESTS
|
||||||
|
int fwin = 0, fwb = 0;
|
||||||
|
#endif
|
||||||
int last_start = 0;
|
int last_start = 0;
|
||||||
for (j = 0; j < N; j++)
|
for (j = 0; j < N; j++)
|
||||||
{
|
{
|
||||||
|
@ -621,7 +626,10 @@ malloc_in_range (struct grub_relocator *rel,
|
||||||
|
|
||||||
{
|
{
|
||||||
int last_start = 0;
|
int last_start = 0;
|
||||||
int inreg = 0, regbeg = 0, fwin = 0, fwb = 0, ncol = 0;
|
int inreg = 0, regbeg = 0, ncol = 0;
|
||||||
|
#if GRUB_RELOCATOR_HAVE_FIRMWARE_REQUESTS
|
||||||
|
int fwin = 0, fwb = 0;
|
||||||
|
#endif
|
||||||
int cural = 0;
|
int cural = 0;
|
||||||
for (j = 0; j < N; j++)
|
for (j = 0; j < N; j++)
|
||||||
{
|
{
|
||||||
|
@ -1008,10 +1016,12 @@ grub_relocator_unload (struct grub_relocator *rel)
|
||||||
grub_free (h + 1);
|
grub_free (h + 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#if GRUB_RELOCATOR_HAVE_FIRMWARE_REQUESTS
|
||||||
case CHUNK_TYPE_FIRMWARE:
|
case CHUNK_TYPE_FIRMWARE:
|
||||||
grub_relocator_firmware_free_region (chunk->subchunks[i].start,
|
grub_relocator_firmware_free_region (chunk->subchunks[i].start,
|
||||||
chunk->subchunks[i].size);
|
chunk->subchunks[i].size);
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
next = chunk->next;
|
next = chunk->next;
|
||||||
grub_free (chunk->subchunks);
|
grub_free (chunk->subchunks);
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include <grub/command.h>
|
#include <grub/command.h>
|
||||||
#include <grub/machine/loader.h>
|
#include <grub/machine/loader.h>
|
||||||
#include <grub/multiboot.h>
|
#include <grub/multiboot.h>
|
||||||
|
#include <grub/cpu/multiboot.h>
|
||||||
#include <grub/machine/memory.h>
|
#include <grub/machine/memory.h>
|
||||||
#include <grub/elf.h>
|
#include <grub/elf.h>
|
||||||
#include <grub/aout.h>
|
#include <grub/aout.h>
|
||||||
|
@ -41,7 +42,7 @@
|
||||||
#include <grub/misc.h>
|
#include <grub/misc.h>
|
||||||
#include <grub/gzio.h>
|
#include <grub/gzio.h>
|
||||||
#include <grub/env.h>
|
#include <grub/env.h>
|
||||||
#include <grub/i386/relocator.h>
|
#include <grub/cpu/relocator.h>
|
||||||
#include <grub/video.h>
|
#include <grub/video.h>
|
||||||
#include <grub/memory.h>
|
#include <grub/memory.h>
|
||||||
#include <grub/i18n.h>
|
#include <grub/i18n.h>
|
||||||
|
@ -116,18 +117,12 @@ static grub_err_t
|
||||||
grub_multiboot_boot (void)
|
grub_multiboot_boot (void)
|
||||||
{
|
{
|
||||||
grub_err_t err;
|
grub_err_t err;
|
||||||
struct grub_relocator32_state state =
|
struct grub_relocator32_state state = MULTIBOOT_INITIAL_STATE;
|
||||||
{
|
|
||||||
.eax = MULTIBOOT_BOOTLOADER_MAGIC,
|
state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip;
|
||||||
.ecx = 0,
|
|
||||||
.edx = 0,
|
err = grub_multiboot_make_mbi (&state.MULTIBOOT_MBI_REGISTER);
|
||||||
.eip = grub_multiboot_payload_eip,
|
|
||||||
/* Set esp to some random location in low memory to avoid breaking
|
|
||||||
non-compliant kernels. */
|
|
||||||
.esp = 0x7ff00
|
|
||||||
};
|
|
||||||
|
|
||||||
err = grub_multiboot_make_mbi (&state.ebx);
|
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
|
@ -18,13 +18,13 @@
|
||||||
|
|
||||||
#if defined(MULTIBOOT_LOAD_ELF32)
|
#if defined(MULTIBOOT_LOAD_ELF32)
|
||||||
# define XX 32
|
# define XX 32
|
||||||
# define E_MACHINE EM_386
|
# define E_MACHINE MULTIBOOT_ELF32_MACHINE
|
||||||
# define ELFCLASSXX ELFCLASS32
|
# define ELFCLASSXX ELFCLASS32
|
||||||
# define Elf_Ehdr Elf32_Ehdr
|
# define Elf_Ehdr Elf32_Ehdr
|
||||||
# define Elf_Phdr Elf32_Phdr
|
# define Elf_Phdr Elf32_Phdr
|
||||||
#elif defined(MULTIBOOT_LOAD_ELF64)
|
#elif defined(MULTIBOOT_LOAD_ELF64)
|
||||||
# define XX 64
|
# define XX 64
|
||||||
# define E_MACHINE EM_X86_64
|
# define E_MACHINE MULTIBOOT_ELF64_MACHINE
|
||||||
# define ELFCLASSXX ELFCLASS64
|
# define ELFCLASSXX ELFCLASS64
|
||||||
# define Elf_Ehdr Elf64_Ehdr
|
# define Elf_Ehdr Elf64_Ehdr
|
||||||
# define Elf_Phdr Elf64_Phdr
|
# define Elf_Phdr Elf64_Phdr
|
|
@ -22,6 +22,7 @@
|
||||||
#include <grub/machine/biosnum.h>
|
#include <grub/machine/biosnum.h>
|
||||||
#endif
|
#endif
|
||||||
#include <grub/multiboot.h>
|
#include <grub/multiboot.h>
|
||||||
|
#include <grub/cpu/multiboot.h>
|
||||||
#include <grub/cpu/relocator.h>
|
#include <grub/cpu/relocator.h>
|
||||||
#include <grub/disk.h>
|
#include <grub/disk.h>
|
||||||
#include <grub/device.h>
|
#include <grub/device.h>
|
||||||
|
@ -89,7 +90,8 @@ grub_multiboot_load (grub_file_t file)
|
||||||
{
|
{
|
||||||
if (header->magic == MULTIBOOT_HEADER_MAGIC
|
if (header->magic == MULTIBOOT_HEADER_MAGIC
|
||||||
&& !(header->magic + header->architecture
|
&& !(header->magic + header->architecture
|
||||||
+ header->header_length + header->checksum))
|
+ header->header_length + header->checksum)
|
||||||
|
&& header->architecture == MULTIBOOT_ARCHITECTURE_CURRENT)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,6 +191,7 @@ grub_video_sm712_get_info_and_fini (struct grub_video_mode_info *mode_info,
|
||||||
static struct grub_video_adapter grub_video_sm712_adapter =
|
static struct grub_video_adapter grub_video_sm712_adapter =
|
||||||
{
|
{
|
||||||
.name = "SM712 Video Driver",
|
.name = "SM712 Video Driver",
|
||||||
|
.id = GRUB_VIDEO_DRIVER_SM712,
|
||||||
|
|
||||||
.init = grub_video_sm712_video_init,
|
.init = grub_video_sm712_video_init,
|
||||||
.fini = grub_video_sm712_video_fini,
|
.fini = grub_video_sm712_video_fini,
|
||||||
|
|
Loading…
Reference in a new issue