.\" -*-nroff-*-
-.TH mdwopt 3 "6 July 1999" "Straylight/Edgeware" "mLib utilities library"
+.\"
+.\" Manual for option parsing
+.\"
+.\" (c) 1999, 2001, 2005, 2007, 2009, 2023, 2024 Straylight/Edgeware
+.\"
+.
+.\"----- Licensing notice ---------------------------------------------------
+.\"
+.\" This file is part of the mLib utilities library.
+.\"
+.\" mLib 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.
+.\"
+.\" mLib 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 mLib. If not, write to the Free Software
+.\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+.\" USA.
+.
+.\"--------------------------------------------------------------------------
+.so ../defs.man \" @@@PRE@@@
+.
+.\"--------------------------------------------------------------------------
+.TH mdwopt 3mLib "6 July 1999" "Straylight/Edgeware" "mLib utilities library"
+.\" @mdwopt
+.
+.\"--------------------------------------------------------------------------
.SH "NAME"
mdwopt \- command-line option parser
-.\" @mdwopt
+.
+.\"--------------------------------------------------------------------------
.SH "SYNOPSIS"
+.
.nf
.B "#include <mLib/mdwopt.h>"
.PP
.BI " const char * "shortopt ,
.BI " const struct option *" longopt ", int *" longind );
.fi
+.
+.\"--------------------------------------------------------------------------
.SH "OVERVIEW"
+.
The
.B mdwopt
function is a command line options parser which is (mostly) compatible
functions, although provides more features than either. It's not the
most featureful options parser around, but it's good enough for my
purposes at the moment.
+.
+.\"--------------------------------------------------------------------------
.SH "OPTION SYNTAX"
+.
A command line consists of a number of
.I words
(which may contain spaces, according to various shell quoting
.IR long .
Traditional Unix (and POSIX) only uses short options. The long options
are a GNU convention.
+.
.SS "Short option syntax"
Short options are the sort which Unix has known for ages: an option is a
single letter, preceded by a
.RB ` \- '
to introduce the option. (Some programs use upper-case option letters
to indicate this instead.)
+.
.SS "Long option syntax"
Long options, as popularized by the GNU utilities, are given long-ish
memorable names, preceded by a double-dash
character, and negated by a
.RB ` + '
character.
+.
.SS "Numerical options"
Finally, some (older) programs accept arguments of the form
.RB ` \- \c
.IR number ',
to set some numerical parameter, typically a line count of some kind.
+.
+.\"--------------------------------------------------------------------------
.SH "PARSING OPTIONS WITH \fBmdwopt\fP"
+.
An application parses its options by calling
.B mdwopt
repeatedly. Each time it is called,
will usually be exactly the arguments passed to the program's
.B main
function.
+.
.SS "Short option parsing"
Short options are described by a string,
.IR shortopt ,
returned ORed with
.B OPTF_NEGATED
(bit 8 set).
+.
.SS "Long option parsing"
Long options are described in a table. Each entry in the
table is of type
Arguments from long options are stored in the
.B arg
member of the data block.
+.
.SS "Other optional features"
The
.I flags
.RB ` \- '.
The return value is
.RB ` # ' " | OPTF_NEGATED" .
+.
.SS "Compatibility features"
The macros
.BR getopt ,
to read by people used to the traditional
.B getopt
function.
+.
+.\"--------------------------------------------------------------------------
.SH "SEE ALSO"
+.
.BR getopt (3),
.BR mLib (3).
+.
+.\"--------------------------------------------------------------------------
.SH "AUTHOR"
+.
Mark Wooding, <mdw@distorted.org.uk>
+.
+.\"----- That's all, folks --------------------------------------------------