more, mostly whitespace, fixes from Thomas Klasusner

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@11176 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
2002-08-20 17:07:29 +00:00
parent 747a00df69
commit 879fc6b8bc
46 changed files with 402 additions and 401 deletions

View File

@@ -4,7 +4,7 @@
.Dt GETARG 3
.Os ROKEN
.Sh NAME
.Nm getarg ,
.Nm getarg ,
.Nm arg_printusage
.Nd collect command line options
.Sh SYNOPSIS
@@ -15,12 +15,12 @@
.Fn arg_printusage "struct getargs *args" "size_t num_args" "const char *progname" "const char *extra_string"
.Sh DESCRIPTION
.Fn getarg
collects any command line options given to a program in an easily used way.
.Fn arg_printusage
collects any command line options given to a program in an easily used way.
.Fn arg_printusage
pretty-prints the available options, with a short help text.
.Pp
.Fa args
is the option specification to use, and it's an array of
is the option specification to use, and it's an array of
.Fa struct getargs
elements.
.Fa num_args
@@ -43,7 +43,7 @@ and
.Fa num_args
as getarg;
.Fa progname
is the name of the program (to be used in the help text), and
is the name of the program (to be used in the help text), and
.Fa extra_string
is a string to print after the actual options to indicate more
arguments. The usefulness of this function is realised only be people
@@ -57,10 +57,10 @@ struct has the following elements.
struct getargs{
const char *long_name;
char short_name;
enum { arg_integer,
arg_string,
arg_flag,
arg_negative_flag,
enum { arg_integer,
arg_string,
arg_flag,
arg_negative_flag,
arg_strings,
arg_double,
arg_collect
@@ -72,14 +72,14 @@ struct getargs{
.Ed
.Pp
.Fa long_name
is the long name of the option, it can be
is the long name of the option, it can be
.Dv NULL ,
if you don't want a long name.
.Fa short_name
.Fa short_name
is the characted to use as short option, it can be zero. If the option
has a value the
.Fa value
field gets filled in with that value interpreted as specified by the
field gets filled in with that value interpreted as specified by the
.Fa type
field.
.Fa help
@@ -107,13 +107,13 @@ should point to a
the argument is a flag, and
.Fa value
should point to a
.Fa int .
.Fa int .
It gets filled in with either zero or one, depending on how the option
is given, the normal case beeing one. Note that if the option isn't
given, the value isn't altered, so it should be initialised to some
useful default.
.It Fa arg_negative_flag
this is the same as
this is the same as
.Fa arg_flag
but it reverses the meaning of the flag (a given short option clears
the flag), and the synopsis of a long option is negated.
@@ -121,7 +121,7 @@ the flag), and the synopsis of a long option is negated.
the argument can be given multiple times, and the values are collected
in an array;
.Fa value
should be a pointer to a
should be a pointer to a
.Fa struct getarg_strings
structure, which holds a length and a string pointer.
.It Fa arg_double
@@ -132,7 +132,7 @@ should point to a
.It Fa arg_collect
allows more fine-grained control of the option parsing process.
.Fa value
should be a pointer to a
should be a pointer to a
.Fa getarg_collect_info
structure:
.Bd -literal
@@ -151,7 +151,7 @@ typedef struct getarg_collect_info {
.Pp
With the
.Fa func
member set to a function to call, and
member set to a function to call, and
.Fa data
to some application specific data. The parameters to the collect function are:
.Bl -inset
@@ -169,27 +169,27 @@ application specific data
.Pp
You can modify
.Fa *optind ,
and
and
.Fa *optarg ,
but to do this correct you (more or less) have to know about the inner
workings of getarg.
.Pp
.Pp
You can skip parts of arguments by increasing
.Fa *optarg
(you could
implement the
implement the
.Fl z Ns Ar 3
set of flags from
.Nm gzip
with this), or whole argument strings by increasing
.Fa *optind
(let's say you want a flag
(let's say you want a flag
.Fl c Ar x y z
to specify a coordinate); if you also have to set
.Fa *optarg
to a sane value.
.Pp
The collect function should return one of
The collect function should return one of
.Dv ARG_ERR_NO_MATCH , ARG_ERR_BAD_ARG , ARG_ERR_NO_ARG
on error, zero otherwise.
.Pp
@@ -201,7 +201,7 @@ arguments, sans data, that where given to the collection function.
Don't use this more this unless you absolutely have to.
.El
.Pp
Option parsing is similar to what
Option parsing is similar to what
.Xr getopt
uses. Short options without arguments can be compressed
.Pf ( Fl xyz
@@ -217,18 +217,18 @@ or
Long option names are prefixed with -- (double dash), and the value
with a = (equal),
.Fl -foo= Ns Ar bar .
Long option flags can either be specified as they are
Long option flags can either be specified as they are
.Pf ( Fl -help ) ,
or with an (boolean parsable) option
.Pf ( Fl -help= Ns Ar yes ,
.Fl -help= Ns Ar true ,
or similar), or they can also be negated
or similar), or they can also be negated
.Pf ( Fl -no-help
is the same as
is the same as
.Fl -help= Ns no ) ,
and if you're really confused you can do it multiple times
.Pf ( Fl -no-no-help= Ns Ar false ,
or even
or even
.Fl -no-no-help= Ns Ar maybe ) .
.Sh EXAMPLE
.Bd -literal
@@ -243,13 +243,13 @@ int include_catalog = 1;
int help_flag;
struct getargs args[] = {
{ "source", 's', arg_string, &source,
{ "source", 's', arg_string, &source,
"source of shippment", "city" },
{ "destination", 'd', arg_string, &destination,
{ "destination", 'd', arg_string, &destination,
"destination of shippment", "city" },
{ "weight", 'w', arg_integer, &weight,
{ "weight", 'w', arg_integer, &weight,
"weight of shippment", "tons" },
{ "catalog", 'c', arg_negative_flag, &include_catalog,
{ "catalog", 'c', arg_negative_flag, &include_catalog,
"include product catalog" },
{ "help", 'h', arg_flag, &help_flag }
};
@@ -285,7 +285,7 @@ main(int argc, char **argv)
.Pp
The output help output from this program looks like this:
.Bd -literal
$ ship++ --help
$ ship++ --help
Usage: ship++ [--source=city] [-s city] [--destination=city] [-d city]
[--weight=tons] [-w tons] [--no-catalog] [-c] [--help] [-h] stuff...
-s city, --source=city source of shippment
@@ -297,7 +297,7 @@ Usage: ship++ [--source=city] [-s city] [--destination=city] [-d city]
It should be more flexible, so it would be possible to use other more
complicated option syntaxes, such as what
.Xr ps 1 ,
and
and
.Xr tar 1 ,
uses, or the AFS model where you can skip the flag names as long as
the options come in the correct order.