"Fossies" - the Fresh Open Source Software Archive 
Member "parsearg.h" (9 May 1995, 7188 Bytes) of package /linux/misc/old/cpost.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "parsearg.h" see the
Fossies "Dox" file reference documentation.
1 /*------------------------------------------------------------------*/
2 /* parsearg : parse parameters and options in an argv list */
3 /*------------------------------------------------------------------*/
4 /* 03-14-90 originally by Patrick J. Mueller */
5 /* 01-09-91 version 2.0 by Patrick J. Mueller */
6 /* 04-29-91 version 3.0 by Patrick J. Mueller */
7 /*------------------------------------------------------------------*/
8
9 /*------------------------------------------------------------------*/
10 /* description: */
11 /*------------------------------------------------------------------*/
12 /* parsearg() classifies argv-style parameters into three */
13 /* categories: */
14 /* */
15 /* - boolean switches */
16 /* - variable switches */
17 /* - parameters */
18 /* */
19 /* Switches are one character markers that are prefixed by the */
20 /* switch delimiter (usually - or /, but customizable via parameter */
21 /* to the function). A boolean switch has nothing following it: */
22 /* multiple boolean switches may be used in the command line */
23 /* concatenated together. A variable switch is followed */
24 /* immediately by it's value. A variable switch may be used as the */
25 /* last switch in a list of boolean switches (the remainder of the */
26 /* string is the value of that variable switch). A parameter is */
27 /* anything that is not a switch. */
28 /* */
29 /* parsearg() separates the switches from the parameters and resets */
30 /* the argv array and argc so that they point to parameters only. */
31 /* */
32 /* Information on which switches were used is returned in pointers. */
33 /* Each switch has a pointer associated with it. The pointer is to */
34 /* a variable that will be set to the contents of the item. For */
35 /* boolean switches, the pointer is a pointer to an int. The int */
36 /* will be set to 1 if the switch is used in the parameters, else */
37 /* it will be set to 0. For variable switches the pointer is a */
38 /* pointer to a pointer to a char. This points to a null */
39 /* terminated string which is the value of the switch or parameter. */
40 /* */
41 /* Switches (but not parameters) may also be specified in an */
42 /* environment variable. */
43 /* */
44 /* You may specify that switches should be handled in a case */
45 /* sensitive or case insensitive manner. */
46 /* */
47 /* The prototype for parsearg() is: */
48 /*------------------------------------------------------------------*/
49
50 void parsearg(
51 int *argc,
52 char **argv,
53 int case_sense,
54 char *env_var,
55 char *delimiters,
56 char *format_string,
57 ...
58 );
59
60 /*------------------------------------------------------------------*/
61 /* parameters: */
62 /*------------------------------------------------------------------*/
63 /* argc */
64 /* argv */
65 /* are variables in the same format as argc and argv. The */
66 /* original main() parameters should be passed here (pass the */
67 /* address to argc). Upon return from parsearg(), argc will */
68 /* contain the number of parameters passed in, and argv will */
69 /* point to an array of parameters, in the original argv */
70 /* format. */
71 /* */
72 /* case_sense */
73 /* set to 1 if you want switches handled in a case sensitive */
74 /* manner, set to 0 if you want switches handled in a case */
75 /* insensitive manner. */
76 /* */
77 /* env_var */
78 /* is the name of an environment variable. If the value of */
79 /* this pointer is not NULL and does not point to an empty */
80 /* string, this value will be considered the name of an */
81 /* environment variable. This environment variable will be */
82 /* retrieved and will be searched for additional switches */
83 /* BEFORE the argv values passed in so that the environment */
84 /* variable values can be overridden by commandline */
85 /* switches. */
86 /* */
87 /* delimiters */
88 /* is a string that contains a list of valid switch delimters */
89 /* ("-/" means to use - or / as a switch delimiter). */
90 /* */
91 /* format_string */
92 /* is a string of 'declarations' of switches to use. Each */
93 /* blank delimited item in the string corresponds to one */
94 /* switch. The first character of the item is the switch */
95 /* character. If anything follows the switch character, this */
96 /* item is a variable switch, else it is a boolean switch. */
97 /* The stuff following the switch character for a variable */
98 /* switch is ignored. */
99 /* */
100 /* ... */
101 /* everything following the format string are pointers to */
102 /* variables corresponding to switches. The 'declarations' */
103 /* in the format_string should line up 1-1 with the pointer */
104 /* variables, just as in printf(). */
105 /*------------------------------------------------------------------*/
106
107 /*------------------------------------------------------------------*/
108 /* additional notes: */
109 /*------------------------------------------------------------------*/
110 /* If multiple switches are in the argv array, the last one */
111 /* in the argv array will be the one used to set the variable. */
112 /*------------------------------------------------------------------*/
113