2
** petopt.h - Command line argument parser header file
4
** Copyright (c) 1999 Peter Eriksson <pen@lysator.liu.se>
6
** This program is free software; you can redistribute it and/or
7
** modify it as you wish - as long as you don't claim that you wrote
10
** This program is distributed in the hope that it will be useful,
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
/* Option types and flags */
19
#define POF_TYPEMASK 0x00FF
21
#define POF_NONE 0x0000
22
#define POF_INT 0x0001 /* Argument is an 'int' number */
23
#define POF_STR 0x0002 /* Argument is a 'char *' string */
24
#define POF_BOOL 0x0003 /* Argument is a 'int' boolean */
26
#define POF_OPT 0x0100 /* Argument is optional */
27
#define POF_DUP 0x0200 /* strdup() the assigned var (if string) */
30
#define POF_SYSLOG 0x1000 /* Send errors to syslog */
31
#define POF_NOERRPRINT 0x2000 /* Do not print errors to stderr */
32
#define POF_PRDEFAULT 0x4000 /* Print default values in usage text */
37
#define POE_OPTION -2 /* Invalid option */
38
#define POE_MULTI -3 /* Option is not unique */
39
#define POE_MISSING -4 /* Required argument to option is missing */
40
#define POE_INVALID -5 /* Invalid argument to option */
41
#define POE_INTERNAL -6 /* Internal error */
44
typedef struct petopt_option
46
int s; /* Short option character */
47
int f; /* Argument flags */
48
char *l; /* Long option name */
49
void *v; /* Variable pointer */
50
char *h; /* Help/usage string */
64
int (*parse)(struct petopt *pp, PETOPTS *pov, const char *arg);
65
int (*errpr)(struct petopt *pp, PETOPTS *pov, int err, FILE *fp);
72
petopt_setup(PETOPT **popp,
77
int (*parse)(PETOPT *pop, PETOPTS *pov, const char *arg),
78
int (*errpr)(PETOPT *pop, PETOPTS *pov, int err, FILE *fp));
82
petopt_parse(PETOPT *pop,
87
petopt_print_error(PETOPT *pop,
93
petopt_print_usage(PETOPT *pop,
97
petopt_cleanup(PETOPT *pop);