mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
Remove the now obsolete argparse code.
* tests/gpgscm/main.c: Switch to the new option parser. * common/argparse.c, common/argparse.h: Remove. * common/init.c (_init_common_subsystems): Do not call obsolete func. * common/Makefile.am (common_sources): Remove those files. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
ba463128ce
commit
cdbe10b762
@ -48,7 +48,6 @@ common_sources = \
|
||||
mapstrings.c stringhelp.c stringhelp.h \
|
||||
strlist.c strlist.h \
|
||||
utf8conv.c utf8conv.h \
|
||||
argparse.c argparse.h \
|
||||
logging.h \
|
||||
dotlock.c dotlock.h \
|
||||
mischelp.c mischelp.h \
|
||||
|
1663
common/argparse.c
1663
common/argparse.c
File diff suppressed because it is too large
Load Diff
@ -1,207 +0,0 @@
|
||||
/* argparse.h - Argument parser for option handling.
|
||||
* Copyright (C) 1997-2001, 2006-2008, 2013-2017 Werner Koch
|
||||
* Copyright (C) 1998-2001, 2006-2008, 2012 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2015-2017 g10 Code GmbH
|
||||
*
|
||||
* This file is part of GnuPG.
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This file 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 Lesser General Public License
|
||||
* along with this program; if not, see <https://www.gnu.org/licenses/>.
|
||||
* SPDX-License-Identifier: LGPL-2.1+
|
||||
*/
|
||||
|
||||
#ifndef GNUPG_COMMON_ARGPARSE_H
|
||||
#define GNUPG_COMMON_ARGPARSE_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int *argc; /* Pointer to ARGC (value subject to change). */
|
||||
char ***argv; /* Pointer to ARGV (value subject to change). */
|
||||
unsigned int flags; /* Global flags. May be set prior to calling the
|
||||
parser. The parser may change the value. */
|
||||
int err; /* Print error description for last option.
|
||||
Either 0, ARGPARSE_PRINT_WARNING or
|
||||
ARGPARSE_PRINT_ERROR. */
|
||||
|
||||
int r_opt; /* Returns option code. */
|
||||
int r_type; /* Returns type of option value. */
|
||||
union {
|
||||
int ret_int;
|
||||
long ret_long;
|
||||
unsigned long ret_ulong;
|
||||
char *ret_str;
|
||||
} r; /* Return values */
|
||||
|
||||
struct {
|
||||
int idx;
|
||||
int inarg;
|
||||
int stopped;
|
||||
const char *last;
|
||||
void *aliases;
|
||||
const void *cur_alias;
|
||||
void *iio_list;
|
||||
} internal; /* Private - do not change. */
|
||||
} ARGPARSE_ARGS;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int short_opt;
|
||||
const char *long_opt;
|
||||
unsigned int flags;
|
||||
const char *description; /* Optional option description. */
|
||||
} ARGPARSE_OPTS;
|
||||
|
||||
/* Short options. */
|
||||
#define ARGPARSE_SHORTOPT_HELP 32768
|
||||
#define ARGPARSE_SHORTOPT_VERSION 32769
|
||||
#define ARGPARSE_SHORTOPT_WARRANTY 32770
|
||||
#define ARGPARSE_SHORTOPT_DUMP_OPTIONS 32771
|
||||
|
||||
|
||||
/* Global flags (ARGPARSE_ARGS). */
|
||||
#define ARGPARSE_FLAG_KEEP 1 /* Do not remove options form argv. */
|
||||
#define ARGPARSE_FLAG_ALL 2 /* Do not stop at last option but return
|
||||
remaining args with R_OPT set to -1. */
|
||||
#define ARGPARSE_FLAG_MIXED 4 /* Assume options and args are mixed. */
|
||||
#define ARGPARSE_FLAG_NOSTOP 8 /* Do not stop processing at "--". */
|
||||
#define ARGPARSE_FLAG_ARG0 16 /* Do not skip the first arg. */
|
||||
#define ARGPARSE_FLAG_ONEDASH 32 /* Allow long options with one dash. */
|
||||
#define ARGPARSE_FLAG_NOVERSION 64 /* No output for "--version". */
|
||||
|
||||
#define ARGPARSE_FLAG_STOP_SEEN 256 /* Set to true if a "--" has been seen. */
|
||||
|
||||
/* Flags for each option (ARGPARSE_OPTS). The type code may be
|
||||
ORed with the OPT flags. */
|
||||
#define ARGPARSE_TYPE_NONE 0 /* Does not take an argument. */
|
||||
#define ARGPARSE_TYPE_INT 1 /* Takes an int argument. */
|
||||
#define ARGPARSE_TYPE_STRING 2 /* Takes a string argument. */
|
||||
#define ARGPARSE_TYPE_LONG 3 /* Takes a long argument. */
|
||||
#define ARGPARSE_TYPE_ULONG 4 /* Takes an unsigned long argument. */
|
||||
#define ARGPARSE_OPT_OPTIONAL (1<<3) /* Argument is optional. */
|
||||
#define ARGPARSE_OPT_PREFIX (1<<4) /* Allow 0x etc. prefixed values. */
|
||||
#define ARGPARSE_OPT_IGNORE (1<<6) /* Ignore command or option. */
|
||||
#define ARGPARSE_OPT_COMMAND (1<<7) /* The argument is a command. */
|
||||
|
||||
#define ARGPARSE_TYPE_MASK 7 /* Mask for the type values (internal). */
|
||||
|
||||
/* A set of macros to make option definitions easier to read. */
|
||||
#define ARGPARSE_x(s,l,t,f,d) \
|
||||
{ (s), (l), ARGPARSE_TYPE_ ## t | (f), (d) }
|
||||
|
||||
#define ARGPARSE_s(s,l,t,d) \
|
||||
{ (s), (l), ARGPARSE_TYPE_ ## t, (d) }
|
||||
#define ARGPARSE_s_n(s,l,d) \
|
||||
{ (s), (l), ARGPARSE_TYPE_NONE, (d) }
|
||||
#define ARGPARSE_s_i(s,l,d) \
|
||||
{ (s), (l), ARGPARSE_TYPE_INT, (d) }
|
||||
#define ARGPARSE_s_s(s,l,d) \
|
||||
{ (s), (l), ARGPARSE_TYPE_STRING, (d) }
|
||||
#define ARGPARSE_s_l(s,l,d) \
|
||||
{ (s), (l), ARGPARSE_TYPE_LONG, (d) }
|
||||
#define ARGPARSE_s_u(s,l,d) \
|
||||
{ (s), (l), ARGPARSE_TYPE_ULONG, (d) }
|
||||
|
||||
#define ARGPARSE_o(s,l,t,d) \
|
||||
{ (s), (l), (ARGPARSE_TYPE_ ## t | ARGPARSE_OPT_OPTIONAL), (d) }
|
||||
#define ARGPARSE_o_n(s,l,d) \
|
||||
{ (s), (l), (ARGPARSE_TYPE_NONE | ARGPARSE_OPT_OPTIONAL), (d) }
|
||||
#define ARGPARSE_o_i(s,l,d) \
|
||||
{ (s), (l), (ARGPARSE_TYPE_INT | ARGPARSE_OPT_OPTIONAL), (d) }
|
||||
#define ARGPARSE_o_s(s,l,d) \
|
||||
{ (s), (l), (ARGPARSE_TYPE_STRING | ARGPARSE_OPT_OPTIONAL), (d) }
|
||||
#define ARGPARSE_o_l(s,l,d) \
|
||||
{ (s), (l), (ARGPARSE_TYPE_LONG | ARGPARSE_OPT_OPTIONAL), (d) }
|
||||
#define ARGPARSE_o_u(s,l,d) \
|
||||
{ (s), (l), (ARGPARSE_TYPE_ULONG | ARGPARSE_OPT_OPTIONAL), (d) }
|
||||
|
||||
#define ARGPARSE_p(s,l,t,d) \
|
||||
{ (s), (l), (ARGPARSE_TYPE_ ## t | ARGPARSE_OPT_PREFIX), (d) }
|
||||
#define ARGPARSE_p_n(s,l,d) \
|
||||
{ (s), (l), (ARGPARSE_TYPE_NONE | ARGPARSE_OPT_PREFIX), (d) }
|
||||
#define ARGPARSE_p_i(s,l,d) \
|
||||
{ (s), (l), (ARGPARSE_TYPE_INT | ARGPARSE_OPT_PREFIX), (d) }
|
||||
#define ARGPARSE_p_s(s,l,d) \
|
||||
{ (s), (l), (ARGPARSE_TYPE_STRING | ARGPARSE_OPT_PREFIX), (d) }
|
||||
#define ARGPARSE_p_l(s,l,d) \
|
||||
{ (s), (l), (ARGPARSE_TYPE_LONG | ARGPARSE_OPT_PREFIX), (d) }
|
||||
#define ARGPARSE_p_u(s,l,d) \
|
||||
{ (s), (l), (ARGPARSE_TYPE_ULONG | ARGPARSE_OPT_PREFIX), (d) }
|
||||
|
||||
#define ARGPARSE_op(s,l,t,d) \
|
||||
{ (s), (l), (ARGPARSE_TYPE_ ## t \
|
||||
| ARGPARSE_OPT_OPTIONAL | ARGPARSE_OPT_PREFIX), (d) }
|
||||
#define ARGPARSE_op_n(s,l,d) \
|
||||
{ (s), (l), (ARGPARSE_TYPE_NONE \
|
||||
| ARGPARSE_OPT_OPTIONAL | ARGPARSE_OPT_PREFIX), (d) }
|
||||
#define ARGPARSE_op_i(s,l,d) \
|
||||
{ (s), (l), (ARGPARSE_TYPE_INT \
|
||||
| ARGPARSE_OPT_OPTIONAL | ARGPARSE_OPT_PREFIX), (d) }
|
||||
#define ARGPARSE_op_s(s,l,d) \
|
||||
{ (s), (l), (ARGPARSE_TYPE_STRING \
|
||||
| ARGPARSE_OPT_OPTIONAL | ARGPARSE_OPT_PREFIX), (d) }
|
||||
#define ARGPARSE_op_l(s,l,d) \
|
||||
{ (s), (l), (ARGPARSE_TYPE_LONG \
|
||||
| ARGPARSE_OPT_OPTIONAL | ARGPARSE_OPT_PREFIX), (d) }
|
||||
#define ARGPARSE_op_u(s,l,d) \
|
||||
{ (s), (l), (ARGPARSE_TYPE_ULONG \
|
||||
| ARGPARSE_OPT_OPTIONAL | ARGPARSE_OPT_PREFIX), (d) }
|
||||
|
||||
#define ARGPARSE_c(s,l,d) \
|
||||
{ (s), (l), (ARGPARSE_TYPE_NONE | ARGPARSE_OPT_COMMAND), (d) }
|
||||
|
||||
#define ARGPARSE_ignore(s,l) \
|
||||
{ (s), (l), (ARGPARSE_OPT_IGNORE), "@" }
|
||||
|
||||
#define ARGPARSE_group(s,d) \
|
||||
{ (s), NULL, 0, (d) }
|
||||
|
||||
/* Placeholder options for help, version, warranty and dump-options. See arg_parse(). */
|
||||
#define ARGPARSE_end() \
|
||||
{ 0, NULL, 0, NULL }, \
|
||||
{ 0, NULL, 0, NULL }, \
|
||||
{ 0, NULL, 0, NULL }, \
|
||||
{ 0, NULL, 0, NULL }, \
|
||||
{ 0, NULL, 0, NULL }
|
||||
|
||||
|
||||
/* Other constants. */
|
||||
#define ARGPARSE_PRINT_WARNING 1
|
||||
#define ARGPARSE_PRINT_ERROR 2
|
||||
|
||||
|
||||
/* Error values. */
|
||||
#define ARGPARSE_IS_ARG (-1)
|
||||
#define ARGPARSE_INVALID_OPTION (-2)
|
||||
#define ARGPARSE_MISSING_ARG (-3)
|
||||
#define ARGPARSE_KEYWORD_TOO_LONG (-4)
|
||||
#define ARGPARSE_READ_ERROR (-5)
|
||||
#define ARGPARSE_UNEXPECTED_ARG (-6)
|
||||
#define ARGPARSE_INVALID_COMMAND (-7)
|
||||
#define ARGPARSE_AMBIGUOUS_OPTION (-8)
|
||||
#define ARGPARSE_AMBIGUOUS_COMMAND (-9)
|
||||
#define ARGPARSE_INVALID_ALIAS (-10)
|
||||
#define ARGPARSE_OUT_OF_CORE (-11)
|
||||
#define ARGPARSE_INVALID_ARG (-12)
|
||||
|
||||
|
||||
int arg_parse (ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts);
|
||||
int optfile_parse (FILE *fp, const char *filename, unsigned *lineno,
|
||||
ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts);
|
||||
void usage (int level);
|
||||
const char *strusage (int level);
|
||||
void set_strusage (const char *(*f)( int ));
|
||||
void argparse_register_outfnc (int (*fnc)(int, const char *));
|
||||
|
||||
#endif /*GNUPG_COMMON_ARGPARSE_H*/
|
@ -210,7 +210,6 @@ _init_common_subsystems (gpg_err_source_t errsource, int *argcp, char ***argvp)
|
||||
}
|
||||
|
||||
/* --version et al shall use estream as well. */
|
||||
argparse_register_outfnc (writestring_via_estream); /* legacy. */
|
||||
gpgrt_set_usage_outfnc (writestring_via_estream);
|
||||
|
||||
/* Register our string mapper with gpgrt. */
|
||||
|
@ -25,7 +25,6 @@ common/helpfile.c
|
||||
common/gettime.c
|
||||
common/ksba-io-support.c
|
||||
|
||||
common/argparse.c
|
||||
common/utf8conv.c
|
||||
common/dotlock.c
|
||||
common/init.c
|
||||
|
@ -16,12 +16,10 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <https://www.gnu.org/licenses/>.
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
/* We don't want to have the macros from gpgrt here until we have
|
||||
* completely replaced this module by the one from gpgrt. */
|
||||
#undef GPGRT_ENABLE_ARGPARSE_MACROS
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
@ -45,13 +43,11 @@
|
||||
#include "scheme-private.h"
|
||||
#include "ffi.h"
|
||||
#include "../common/i18n.h"
|
||||
#include "../../common/argparse.h"
|
||||
#include "../../common/init.h"
|
||||
#include "../../common/logging.h"
|
||||
#include "../../common/strlist.h"
|
||||
#include "../../common/sysutils.h"
|
||||
#include "../../common/util.h"
|
||||
#include "../common/argparse.h" /* temporary hack. */
|
||||
|
||||
/* The TinyScheme banner. Unfortunately, it isn't in the header
|
||||
file. */
|
||||
@ -69,7 +65,7 @@ enum cmd_and_opt_values
|
||||
};
|
||||
|
||||
/* The list of commands and options. */
|
||||
static ARGPARSE_OPTS opts[] =
|
||||
static gpgrt_opt_t opts[] =
|
||||
{
|
||||
ARGPARSE_s_n (oVerbose, "verbose", N_("verbose")),
|
||||
ARGPARSE_end (),
|
||||
@ -80,11 +76,9 @@ size_t scmpath_len = 0;
|
||||
|
||||
/* Command line parsing. */
|
||||
static void
|
||||
parse_arguments (ARGPARSE_ARGS *pargs, ARGPARSE_OPTS *popts)
|
||||
parse_arguments (gpgrt_argparse_t *pargs, gpgrt_opt_t *popts)
|
||||
{
|
||||
int no_more_options = 0;
|
||||
|
||||
while (!no_more_options && optfile_parse (NULL, NULL, NULL, pargs, popts))
|
||||
while (gpgrt_argparse (NULL, pargs, popts))
|
||||
{
|
||||
switch (pargs->r_opt)
|
||||
{
|
||||
@ -93,7 +87,7 @@ parse_arguments (ARGPARSE_ARGS *pargs, ARGPARSE_OPTS *popts)
|
||||
break;
|
||||
|
||||
default:
|
||||
pargs->err = 2;
|
||||
pargs->err = ARGPARSE_PRINT_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -107,9 +101,11 @@ my_strusage( int level )
|
||||
|
||||
switch (level)
|
||||
{
|
||||
case 9: p = "GPL-3.0-or-later"; break;
|
||||
case 11: p = "gpgscm (@GNUPG@)";
|
||||
break;
|
||||
case 13: p = VERSION; break;
|
||||
case 14: p = GNUPG_DEF_COPYRIGHT_LINE; break;
|
||||
case 17: p = PRINTABLE_OS_NAME; break;
|
||||
case 19: p = _("Please report bugs to <@EMAIL@>.\n"); break;
|
||||
|
||||
@ -256,7 +252,7 @@ main (int argc, char **argv)
|
||||
int retcode;
|
||||
gpg_error_t err;
|
||||
char *argv0;
|
||||
ARGPARSE_ARGS pargs;
|
||||
gpgrt_argparse_t pargs;
|
||||
scheme *sc;
|
||||
char *p;
|
||||
#if _WIN32
|
||||
@ -283,7 +279,7 @@ main (int argc, char **argv)
|
||||
if (*p == pathsep)
|
||||
*p = 0, scmpath_len++;
|
||||
|
||||
set_strusage (my_strusage);
|
||||
gpgrt_set_strusage (my_strusage);
|
||||
log_set_prefix ("gpgscm", GPGRT_LOG_WITH_PREFIX);
|
||||
|
||||
/* Make sure that our subsystems are ready. */
|
||||
@ -301,6 +297,7 @@ main (int argc, char **argv)
|
||||
pargs.argv = &argv;
|
||||
pargs.flags = 0;
|
||||
parse_arguments (&pargs, opts);
|
||||
gpgrt_argparse (NULL, &pargs, NULL);
|
||||
|
||||
if (log_get_errorcount (0))
|
||||
exit (2);
|
||||
|
Loading…
x
Reference in New Issue
Block a user