mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-18 19:10:06 +00:00
5a97622d5e
1997-02-22 00:17 Ulrich Drepper <drepper@cygnus.com> * catgets/gencat.c: Change to use argp. * db/makedb: Likewise. * locale/programs/localedef.c: Likewise. * locale/programs/locale.c: Little adjustment for better usage of argp. 1997-02-20 20:07 Greg McGary <gkm@eng.ascend.com> * Makeconfig: Add rules for libc with bounded pointers. * Makerules: Likewise. * config.make.in: Likewise. * configure.in: Likewise. 1997-02-21 10:41 Miles Bader <miles@gnu.ai.mit.edu> * argp.h (OPTION_NO_USAGE): New macro. * argp-help.c (usage_long_opt, usage_argful_short_opt, add_argless_short_opt): Implement OPTION_NO_USAGE. 1997-02-20 16:41 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> * malloc/obstack.h: Fix typo. 1997-02-20 15:56 Miles Bader <miles@gnu.ai.mit.edu> * argp-fmtstream.c (__argp_fmtstream_update): Account for case where NEXTLINE points one past the end of the active buffer. * argp-help.c <stddef.h>: New include. (__argp_failure): Only exit if STATE says it's ok. (print_header, hol_entry_help): Use UPARAMS fields rather than constants. (_help): Call fill_in_uparams if necessary. (struct hol_help_state): New type. (struct pentry_state): Add hhstate field. Remove prev_entry & sep_groups fields. (hol_entry_help): Add HHSTATE parameter. Remove prev_entry & sep_groups parameters. Suppress duplicate arguments if requested, and note the fact. (print_header, comma): Use PEST->hhstate fields. (hol_help): Add HHSTATE variable & pass to hol_entry_help. Remove LAST_ENTRY & SEP_GROUPS variables. If any suplicate arguments were suppressed, print explanatory note. (filter_doc): Replace PEST parameter with STATE. (struct uparams): New type. (uparams): New variable. (struct uparam_name): New type. (uparam_names): New variable. (fill_in_uparams): New function. (__argp_failure, __argp_error, __argp_state_help): Make STATE parameter const. * argp.h (argp_state_help, __argp_state_help, argp_usage, __argp_usage, argp_error, __argp_error, argp_failure, __argp_failure): Make STATE parameter const. (ARGP_KEY_HELP_DUP_ARGS_NOTE): New macro. * argp.h (argp_program_bug_address): Make const. 1997-02-20 19:20 Ulrich Drepper <drepper@cygnus.com> * sysdeps/unix/mman/syscalls.list: Explain msync interface. 1997-02-19 01:37 Erik Troan <ewt@redhat.com> * shadow/sgetspent_r.c: Accept empty third, fourth and fifth fields. 1997-02-20 14:44 Andreas Jaeger <aj@arthur.pfalz.de> * stdio-common/test-fseek.c: Remove temporary file, add copyright. 1997-02-20 17:51 Ulrich Drepper <drepper@cygnus.com> * sysdeps/generic/netinet/in.h: Protect contents using __BEGIN/END_DECLS. Reported by a sun <asun@zoology.washington.edu>. * inet/net/ethernet.h: Move to sysdeps/unix/sysv/linux/net. * inet/Makefile (headers): Remove net/ethernet.h. * sysdeps/unix/sysv/linux/Makefile: Install net/ethernet.h. * sysdeps/unix/sysv/linux/Dist: Distribute net/ethernet.h. 1997-02-20 15:23 Thorsten Kukuk <kukuk@weber.uni-paderborn.de> * nss/nsswitch.c (__nss_configure_lookup): Use correct test when searching in sorted array. 1997-02-20 01:24 Philip Blundell <pjb27@cam.ac.uk> * inet/getnameinfo.c: Change to use reentrant getXXbyYY functions and protect modification of global data. 1997-02-19 18:48 Miles Bader <miles@gnu.ai.mit.edu> * argp-parse.c (argp_default_parser): Set STATE->name for OPT_PROGNAME. (parser_init): Use the basename for PARSER->state.name. * argp-help.c (__argp_error, __argp_failure, __argp_state_help): Use PROGRAM_INVOCATION_SHORT_NAME instead of PROGRAM_INVOCATION_NAME. * argp-parse.c (parser_init): Set PARSER->state.flags. Make check whether PARSER has the prog name in argv[0] at the proper place. 1997-02-19 23:34 Ulrich Drepper <drepper@cygnus.com> * locale/programs/ld-time.c (time_finish): t_fmt_ampm is optional. Use default value instead of printing a warning. * nss/XXX-lookup.c: Add misssing explanation. 1997-02-19 19:14 Andreas Jaeger <aj@arthur.pfalz.de> * inet/in6_addr.c: Add missing braces. * inet/getnameinfo.c: Include <arpa/inet.h>. * sysdeps/posix/getaddrinfo.c: Include <arpa/inet.h>. 1997-02-19 11:46 Ulrich Drepper <drepper@cygnus.com> * string/strxfrm.c (STRCOLL): Correct handling of `position' levels with no non-IGNOREd element and handling of NUL byte. * string/strcoll.c (STRXFRM): Likewise. * locale/weight.h: Likewise. * shadow/sgetspent_r.c (LINE_PARSER): Add missing ')'.
210 lines
5.5 KiB
C
210 lines
5.5 KiB
C
/* Test program for argp argument parser
|
||
Copyright (C) 1997 Free Software Foundation, Inc.
|
||
This file is part of the GNU C Library.
|
||
Written by Miles Bader <miles@gnu.ai.mit.edu>.
|
||
|
||
The GNU C Library is free software; you can redistribute it and/or
|
||
modify it under the terms of the GNU Library General Public License as
|
||
published by the Free Software Foundation; either version 2 of the
|
||
License, or (at your option) any later version.
|
||
|
||
The GNU C Library 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
|
||
Library General Public License for more details.
|
||
|
||
You should have received a copy of the GNU Library General Public
|
||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||
Boston, MA 02111-1307, USA. */
|
||
|
||
#ifdef HAVE_CONFIG_H
|
||
#include <config.h>
|
||
#endif
|
||
|
||
#include <stdlib.h>
|
||
#include <time.h>
|
||
#include <string.h>
|
||
#include <argp.h>
|
||
|
||
const char *argp_program_version = "argp-test 1.0";
|
||
|
||
struct argp_option sub_options[] =
|
||
{
|
||
{"subopt1", 's', 0, 0, "Nested option 1"},
|
||
{"subopt2", 'S', 0, 0, "Nested option 2"},
|
||
|
||
{ 0, 0, 0, 0, "Some more nested options:", 10},
|
||
{"subopt3", 'p', 0, 0, "Nested option 3"},
|
||
|
||
{"subopt4", 'q', 0, 0, "Nested option 4", 1},
|
||
|
||
{0}
|
||
};
|
||
|
||
static const char sub_args_doc[] = "STRING...\n-";
|
||
static const char sub_doc[] = "\vThis is the doc string from the sub-arg-parser.";
|
||
|
||
static error_t
|
||
sub_parse_opt (int key, char *arg, struct argp_state *state)
|
||
{
|
||
switch (key)
|
||
{
|
||
case ARGP_KEY_NO_ARGS:
|
||
printf ("NO SUB ARGS\n");
|
||
break;
|
||
case ARGP_KEY_ARG:
|
||
printf ("SUB ARG: %s\n", arg);
|
||
break;
|
||
|
||
case 's' : case 'S': case 'p': case 'q':
|
||
printf ("SUB KEY %c\n", key);
|
||
break;
|
||
|
||
default:
|
||
return ARGP_ERR_UNKNOWN;
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
static char *
|
||
sub_help_filter (int key, const char *text, void *input)
|
||
{
|
||
if (key == ARGP_KEY_HELP_EXTRA)
|
||
return strdup ("This is some extra text from the sub parser (note that it \
|
||
is preceded by a blank line).");
|
||
else
|
||
return (char *)text;
|
||
}
|
||
|
||
static struct argp sub_argp = {
|
||
sub_options, sub_parse_opt, sub_args_doc, sub_doc, 0, sub_help_filter
|
||
};
|
||
|
||
/* Structure used to communicate with the parsing functions. */
|
||
struct params
|
||
{
|
||
unsigned foonly; /* Value parsed for foonly. */
|
||
unsigned foonly_default; /* Default value for it. */
|
||
};
|
||
|
||
#define OPT_PGRP 1
|
||
#define OPT_SESS 2
|
||
|
||
struct argp_option options[] =
|
||
{
|
||
{"pid", 'p', "PID", 0, "List the process PID"},
|
||
{"pgrp", OPT_PGRP,"PGRP",0, "List processes in the process group PGRP"},
|
||
{"no-parent", 'P', 0, 0, "Include processes without parents"},
|
||
{0, 'x', 0, OPTION_ALIAS},
|
||
{"all-fields",'Q', 0, 0, "Don't elide unusable fields (normally"
|
||
" if there's some reason ps can't"
|
||
" print a field for any process, it's"
|
||
" removed from the output entirely)" },
|
||
{"reverse", 'r', 0, 0, "Reverse the order of any sort"},
|
||
{"gratuitously-long-reverse-option", 0, 0, OPTION_ALIAS},
|
||
{"session", OPT_SESS,"SID", OPTION_ARG_OPTIONAL,
|
||
"Add the processes from the session"
|
||
" SID (which defaults to the sid of"
|
||
" the current process)" },
|
||
|
||
{0,0,0,0, "Here are some more options:"},
|
||
{"foonly", 'f', "ZOT", OPTION_ARG_OPTIONAL, "Glork a foonly"},
|
||
{"zaza", 'z', 0, 0, "Snit a zar"},
|
||
|
||
{0}
|
||
};
|
||
|
||
static const char args_doc[] = "STRING";
|
||
static const char doc[] = "Test program for argp."
|
||
"\vThis doc string comes after the options."
|
||
"\nHey! Some manual formatting!"
|
||
"\nThe current time is: %s";
|
||
|
||
static void
|
||
popt (int key, char *arg)
|
||
{
|
||
char buf[10];
|
||
if (isprint (key))
|
||
sprintf (buf, "%c", key);
|
||
else
|
||
sprintf (buf, "%d", key);
|
||
if (arg)
|
||
printf ("KEY %s: %s\n", buf, arg);
|
||
else
|
||
printf ("KEY %s\n", buf);
|
||
}
|
||
|
||
static error_t
|
||
parse_opt (int key, char *arg, struct argp_state *state)
|
||
{
|
||
struct params *params = state->input;
|
||
|
||
switch (key)
|
||
{
|
||
case ARGP_KEY_NO_ARGS:
|
||
printf ("NO ARGS\n");
|
||
break;
|
||
|
||
case ARGP_KEY_ARG:
|
||
if (state->arg_num > 0)
|
||
return ARGP_ERR_UNKNOWN; /* Leave it for the sub-arg parser. */
|
||
printf ("ARG: %s\n", arg);
|
||
break;
|
||
|
||
case 'f':
|
||
if (arg)
|
||
params->foonly = atoi (arg);
|
||
else
|
||
params->foonly = params->foonly_default;
|
||
popt (key, arg);
|
||
break;
|
||
|
||
case 'p': case 'P': case OPT_PGRP: case 'x': case 'Q':
|
||
case 'r': case OPT_SESS: case 'z':
|
||
popt (key, arg);
|
||
break;
|
||
|
||
default:
|
||
return ARGP_ERR_UNKNOWN;
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
static char *
|
||
help_filter (int key, const char *text, void *input)
|
||
{
|
||
char *new_text;
|
||
struct params *params = input;
|
||
|
||
if (key == ARGP_KEY_HELP_POST_DOC && text)
|
||
{
|
||
time_t now = time (0);
|
||
asprintf (&new_text, text, ctime (&now));
|
||
}
|
||
else if (key == 'f')
|
||
/* Show the default for the --foonly option. */
|
||
asprintf (&new_text, "%s (ZOT defaults to %x)",
|
||
text, params->foonly_default);
|
||
else
|
||
new_text = (char *)text;
|
||
|
||
return new_text;
|
||
}
|
||
|
||
static struct argp_child argp_children[] = { { &sub_argp }, { 0 } };
|
||
static struct argp argp = {
|
||
options, parse_opt, args_doc, doc, argp_children, help_filter
|
||
};
|
||
|
||
int
|
||
main (int argc, char **argv)
|
||
{
|
||
struct params params;
|
||
params.foonly = 0;
|
||
params.foonly_default = random ();
|
||
argp_parse (&argp, argc, argv, 0, 0, ¶ms);
|
||
printf ("After parsing: foonly = %x\n", params.foonly);
|
||
return 0;
|
||
}
|