File: options.h

package info (click to toggle)
nn 6.5.1-4
  • links: PTS
  • area: main
  • in suites: slink
  • size: 2,472 kB
  • ctags: 4,518
  • sloc: ansic: 35,126; sh: 1,489; makefile: 214; awk: 138
file content (92 lines) | stat: -rw-r--r-- 2,403 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 *	(c) Copyright 1990, Kim Fabricius Storm.  All rights reserved.
 *
 *	Include file for generic option parsing
 */

/*
 * To use this routine, you must a table called an Option_Description.
 * Each element in this table describes one possible option:
 *	Its option letter
 *	Its argument type (if any)
 *	Whether an argument is mandatory or optional
 *	The address of the variable holding the option value
 *	The defualt value if argument is optional
 *
 * Example:
 *
 *	A program accepts the following options:
 *		-a	[no value]
 *		-b N	[a numeric value]
 *		-p [N]	[an optional numeric value]
 *		-t S	[a string value]
 *
 * The corresponding option description table would then look like:
 *
 *	#include <options.h>
 *	int a_flg = 1, b_value = 0, p_value = 0;
 *	char *t_string = "default";
 *
 *	Option_Description( options ) {
 *	    'a', Bool_Option(a_flg),
 *	    'b', Int_Option(b_value),
 *	    'p', Int_Option_Optional(p_value, -1),
 *	    't', String_Option(t_string),
 *	    '\0',
 *	 }
 * To parse the argument list - and the contents of the environment variable
 * XXINIT, all that has to be done is to issue the following call:
 *
 *	files = parse_options(argc, argv, "XXINIT", options, NULL);
 *
 * If no environment variable is associated with the program, use NULL as
 * the third parameter.
 *
 * Upon return, the elements argv[1] .. argv[files] will contain
 * the file names (and other 'non-options') that occur in the argument list.
 *
 * The last NULL argument may be replaced by your own 'usage routine'
 * which will be called in the following way:
 *
 *	usage(pname)
 *	char *pname; /+ argv[0] without path +/
 *
 *
 * char *program_name(argv)
 *
 * return a pointer to the last component of argv[0] (the program name with
 * with the path deleted).
 *

 */

#ifndef _NN_OPTIONS_H
#define _NN_OPTIONS_H 1

struct option_descr {
    char	option_letter;
    char	option_type;
    char **	option_address;
    char *	option_default;
} ;


#define	Option_Description(name) \
    struct option_descr name[] =

#define	Bool_Option(addr) \
    1, (char **)(&addr), (char *)0

#define	String_Option(addr) \
    2, &addr, (char *)0

#define String_Option_Optional(addr, default) \
    3, &addr, default

#define	Int_Option(addr) \
    4, (char **)(&addr), (char *)0

#define	Int_Option_Optional(addr, default) \
    5, (char **)(&addr), (char *)default

#endif /* _NN_OPTIONS_H */