optparser.c

Mon, 16 Feb 2004 00:44:56 +0100

author
tuomov
date
Mon, 16 Feb 2004 00:44:56 +0100
changeset 58
789df543d0c3
parent 53
f8f9366b359c
child 62
aae5facf9fc5
permissions
-rw-r--r--

trunk: changeset 1303
Moved header files to top level directory.

0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
1 /*
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
2 * libtu/optparser.c
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
3 *
36
63cd573ffbcf trunk: changeset 39
tuomov
parents: 19
diff changeset
4 * Copyright (c) Tuomo Valkonen 1999-2002.
53
f8f9366b359c trunk: changeset 57
tuomov
parents: 36
diff changeset
5 *
f8f9366b359c trunk: changeset 57
tuomov
parents: 36
diff changeset
6 * You may distribute and modify this library under the terms of either
f8f9366b359c trunk: changeset 57
tuomov
parents: 36
diff changeset
7 * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
8 */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
9
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
10 #include <string.h>
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
11 #include <stdlib.h>
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
12
5
f878a9ffa3e0 trunk: changeset 8
tuomov
parents: 3
diff changeset
13 #include <libtu/util.h>
f878a9ffa3e0 trunk: changeset 8
tuomov
parents: 3
diff changeset
14 #include <libtu/misc.h>
f878a9ffa3e0 trunk: changeset 8
tuomov
parents: 3
diff changeset
15 #include <libtu/optparser.h>
f878a9ffa3e0 trunk: changeset 8
tuomov
parents: 3
diff changeset
16 #include <libtu/output.h>
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
17
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
18
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
19 #define O_ARGS(o) (o->flags&OPT_OPT_ARG)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
20 #define O_ARG(o) (o->flasg&OPT_ARG)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
21 #define O_OPT_ARG(o) (O_ARGS(o)==OPT_OPT_ARG)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
22 #define O_ID(o) (o->optid)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
23
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
24 #define OPT_ID_HELP OPT_ID_RESERVED('h')
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
25 #define OPT_ID_VERSION OPT_ID_RESERVED('V')
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
26 #define OPT_ID_ABOUT OPT_ID_RESERVED('a'|OPT_ID_NOSHORT_FLAG)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
27
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
28
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
29 static OptParserOpt common_opts[]={
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
30 {OPT_ID_HELP, "help", 0, NULL, DUMMY_TR("Show this help")},
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
31 {OPT_ID_VERSION, "version", 0, NULL, DUMMY_TR("Show program version")},
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
32 {OPT_ID_ABOUT, "about", 0, NULL, DUMMY_TR("Show about text")},
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
33 {0, NULL, 0, NULL, NULL}
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
34 };
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
35
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
36
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
37 static OptParserCommonInfo dummy_cinfo[]={
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
38 NULL, /* version */
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
39 "Usage: $p\n", /* usage_tmpl */
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
40 NULL /* about */
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
41 };
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
42
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
43
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
44 static const OptParserOpt *o_opts=NULL;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
45 static char *const *o_current=NULL;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
46 static int o_left=0;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
47 static const char* o_chain_ptr=NULL;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
48 static int o_args_left=0;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
49 static const char*o_tmp=NULL;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
50 static int o_error=0;
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
51 static int o_mode=OPTP_CHAIN;
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
52 static const OptParserCommonInfo *o_cinfo=NULL;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
53
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
54
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
55 /* */
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
56
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
57
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
58 static void print_help(const OptParserOpt *opts, bool midlong,
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
59 const OptParserCommonInfo *cinfo);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
60
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
61
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
62 /* */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
63
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
64
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
65 void optparser_init(int argc, char *const argv[], int mode,
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
66 const OptParserOpt *opts, const OptParserCommonInfo *cinfo)
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
67 {
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
68 o_mode=mode;
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
69 o_opts=(opts==NULL ? common_opts : opts);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
70 o_current=argv+1;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
71 o_left=argc-1;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
72 o_chain_ptr=NULL;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
73 o_args_left=0;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
74 o_tmp=NULL;
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
75 o_cinfo=(cinfo==NULL ? dummy_cinfo : cinfo);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
76 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
77
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
78
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
79 /* */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
80
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
81
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
82 static const OptParserOpt *find_chain_opt(char p, const OptParserOpt *o)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
83 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
84 for(;O_ID(o);o++){
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
85 if((O_ID(o)&~OPT_ID_RESERVED_FLAG)==p)
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
86 return o;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
87 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
88 return NULL;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
89 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
90
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
91
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
92 static bool is_option(const char *p)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
93 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
94 if(p==NULL)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
95 return FALSE;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
96 if(*p++!='-')
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
97 return FALSE;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
98 if(*p++!='-')
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
99 return FALSE;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
100 if(*p=='\0')
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
101 return FALSE;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
102 return TRUE;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
103 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
104
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
105
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
106 /* */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
107
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
108 enum{
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
109 SHORT, MIDLONG, LONG
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
110 };
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
111
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
112
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
113 static int optparser_do_get_opt()
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
114 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
115 #define RET(X) return o_tmp=p, o_error=X
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
116 const char *p, *p2=NULL;
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
117 bool dash=TRUE;
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
118 int type=SHORT;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
119 const OptParserOpt *o;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
120 int l;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
121
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
122 while(o_args_left)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
123 optparser_get_arg();
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
124
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
125 o_tmp=NULL;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
126
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
127 /* Are we doing a chain (i.e. opt. of style 'tar xzf')? */
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
128 if(o_chain_ptr!=NULL){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
129 p=o_chain_ptr++;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
130 if(!*o_chain_ptr)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
131 o_chain_ptr=NULL;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
132
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
133 o=find_chain_opt(*p, o_opts);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
134
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
135 if(o==NULL)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
136 RET(E_OPT_INVALID_CHAIN_OPTION);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
137
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
138 goto do_arg;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
139 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
140
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
141 if(o_left<1)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
142 return OPT_ID_END;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
143
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
144 o_left--;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
145 p=*o_current++;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
146
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
147 if(*p!='-'){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
148 dash=FALSE;
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
149 if(o_mode!=OPTP_NO_DASH)
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
150 RET(OPT_ID_ARGUMENT);
19
3e498ec7abcd trunk: changeset 22
tuomov
parents: 12
diff changeset
151 p2=p;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
152 }else if(*(p+1)=='-'){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
153 /* --foo */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
154 if(*(p+2)=='\0'){
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
155 /* -- arguments */
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
156 o_args_left=o_left;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
157 RET(OPT_ID_ARGUMENT);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
158 }
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
159 type=LONG;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
160 p2=p+2;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
161 }else{
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
162 /* -foo */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
163 if(*(p+1)=='\0'){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
164 /* - */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
165 o_args_left=1;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
166 RET(OPT_ID_ARGUMENT);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
167 }
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
168 if(*(p+2)!='\0' && o_mode==OPTP_MIDLONG)
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
169 type=MIDLONG;
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
170
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
171 p2=p+1;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
172 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
173
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
174 o=o_opts;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
175
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
176 again:
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
177 for(; O_ID(o); o++){
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
178 if(type==LONG){
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
179 /* Do long option (--foo=bar) */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
180 if(o->longopt==NULL)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
181 continue;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
182 l=strlen(o->longopt);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
183 if(strncmp(p2, o->longopt, l)!=0)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
184 continue;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
185
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
186 if(p2[l]=='\0'){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
187 if(O_ARGS(o)==OPT_ARG)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
188 RET(E_OPT_MISSING_ARGUMENT);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
189 return O_ID(o);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
190 }else if(p2[l]=='='){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
191 if(!O_ARGS(o))
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
192 RET(E_OPT_UNEXPECTED_ARGUMENT);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
193 if(p2[l+1]=='\0')
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
194 RET(E_OPT_MISSING_ARGUMENT);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
195 o_tmp=p2+l+1;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
196 o_args_left=1;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
197 return O_ID(o);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
198 }
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
199 continue;
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
200 }else if(type==MIDLONG){
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
201 if(o->longopt==NULL)
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
202 continue;
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
203
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
204 if(strcmp(p2, o->longopt)!=0)
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
205 continue;
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
206 }else{ /* type==SHORT */
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
207 if(*p2!=(O_ID(o)&~OPT_ID_RESERVED_FLAG))
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
208 continue;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
209
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
210 if(*(p2+1)!='\0'){
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
211 if(o_mode==OPTP_CHAIN || o_mode==OPTP_NO_DASH){
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
212 /*valid_chain(p2+1, o_opts)*/
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
213 o_chain_ptr=p2+1;
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
214 p++;
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
215 }else if(o_mode==OPTP_IMMEDIATE){
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
216 if(!O_ARGS(o)){
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
217 if(*(p2+1)!='\0')
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
218 RET(E_OPT_UNEXPECTED_ARGUMENT);
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
219 }else{
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
220 if(*(p2+1)=='\0')
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
221 RET(E_OPT_MISSING_ARGUMENT);
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
222 o_tmp=p2+1;
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
223 o_args_left=1;
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
224 }
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
225 return O_ID(o);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
226 }else{
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
227 RET(E_OPT_SYNTAX_ERROR);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
228 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
229 }
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
230 }
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
231
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
232 do_arg:
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
233
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
234 if(!O_ARGS(o))
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
235 return O_ID(o);
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
236
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
237 if(!o_left || is_option(*o_current)){
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
238 if(O_ARGS(o)==OPT_OPT_ARG)
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
239 return O_ID(o);
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
240 RET(E_OPT_MISSING_ARGUMENT);
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
241 }
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
242
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
243 o_args_left=1;
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
244 return O_ID(o);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
245 }
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
246
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
247 if(o!=&(common_opts[3])){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
248 o=common_opts;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
249 goto again;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
250 }
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
251
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
252 if(dash)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
253 RET(E_OPT_INVALID_OPTION);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
254
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
255 RET(OPT_ID_ARGUMENT);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
256 #undef RET
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
257 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
258
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
259
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
260 int optparser_get_opt()
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
261 {
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
262 int oid=optparser_do_get_opt();
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
263
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
264 if(oid<=0 || (oid&OPT_ID_RESERVED_FLAG)==0)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
265 return oid;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
266
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
267 switch(oid){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
268 case OPT_ID_ABOUT:
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
269 if(o_cinfo->about!=NULL)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
270 printf("%s", o_cinfo->about);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
271 break;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
272
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
273 case OPT_ID_VERSION:
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
274 if(o_cinfo->version!=NULL)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
275 printf("%s\n", o_cinfo->version);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
276 break;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
277
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
278 case OPT_ID_HELP:
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
279 print_help(o_opts, o_mode==OPTP_MIDLONG, o_cinfo);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
280 break;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
281 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
282
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
283 exit(EXIT_SUCCESS);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
284 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
285
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
286
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
287 /* */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
288
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
289
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
290 const char* optparser_get_arg()
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
291 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
292 const char *p;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
293
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
294 if(o_tmp!=NULL){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
295 /* If o_args_left==0, then were returning an invalid option
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
296 * otherwise an immediate argument (e.g. -funsigned-char
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
297 * where '-f' is the option and 'unsigned-char' the argument)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
298 */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
299 if(o_args_left>0)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
300 o_args_left--;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
301 p=o_tmp;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
302 o_tmp=NULL;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
303 return p;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
304 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
305
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
306 if(o_args_left<1 || o_left<1)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
307 return NULL;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
308
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
309 o_left--;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
310 o_args_left--;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
311 return *o_current++;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
312 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
313
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
314
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
315 /* */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
316
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
317 static void warn_arg(const char *e)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
318 {
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
319 const char *p=optparser_get_arg();
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
320
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
321 if(p==NULL)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
322 warn("%s (null)", e);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
323 else
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
324 warn("%s \'%s\'", e, p);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
325 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
326
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
327
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
328 static void warn_opt(const char *e)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
329 {
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
330 if(o_tmp!=NULL && o_chain_ptr!=NULL)
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
331 warn("%s \'-%c\'", e, *o_tmp);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
332 else
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
333 warn_arg(e);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
334 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
335
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
336
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
337 void optparser_print_error()
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
338 {
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
339 switch(o_error){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
340 case E_OPT_INVALID_OPTION:
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
341 case E_OPT_INVALID_CHAIN_OPTION:
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
342 warn_opt(TR("Invalid option"));
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
343 break;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
344
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
345 case E_OPT_SYNTAX_ERROR:
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
346 warn_arg(TR("Syntax error while parsing"));
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
347 break;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
348
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
349 case E_OPT_MISSING_ARGUMENT:
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
350 warn_opt(TR("Missing argument to"));
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
351 break;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
352
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
353 case E_OPT_UNEXPECTED_ARGUMENT:
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
354 warn_opt(TR("No argument expected:"));
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
355 break;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
356
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
357 case OPT_ID_ARGUMENT:
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
358 warn(TR("Unexpected argument"));
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
359 break;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
360
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
361 default:
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
362 warn(TR("(unknown error)"));
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
363 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
364
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
365 o_tmp=NULL;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
366 o_error=0;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
367 }
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
368
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
369
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
370 /* */
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
371
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
372
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
373 static uint opt_w(const OptParserOpt *opt, bool midlong)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
374 {
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
375 uint w=0;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
376
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
377 if((opt->optid&OPT_ID_NOSHORT_FLAG)==0){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
378 w+=2; /* "-o" */
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
379 if(opt->longopt!=NULL)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
380 w+=2; /* ", " */
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
381 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
382
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
383 if(opt->longopt!=NULL)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
384 w+=strlen(opt->longopt)+(midlong ? 1 : 2);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
385
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
386 if(O_ARGS(opt)){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
387 if(opt->argname==NULL)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
388 w+=4;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
389 else
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
390 w+=1+strlen(opt->argname); /* "=ARG" or " ARG" */
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
391
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
392 if(O_OPT_ARG(opt))
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
393 w+=2; /* [ARG] */
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
394 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
395
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
396 return w;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
397 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
398
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
399
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
400 #define TERM_W 80
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
401 #define OFF1 2
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
402 #define OFF2 2
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
403 #define SPACER1 " "
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
404 #define SPACER2 " "
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
405
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
406 static void print_opt(const OptParserOpt *opt, bool midlong,
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
407 uint maxw, uint tw)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
408 {
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
409 FILE *f=stdout;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
410 const char *p, *p2, *p3;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
411 uint w=0;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
412
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
413 fprintf(f, SPACER1);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
414
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
415 /* short opt */
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
416
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
417 if((O_ID(opt)&OPT_ID_NOSHORT_FLAG)==0){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
418 fprintf(f, "-%c", O_ID(opt)&~OPT_ID_RESERVED_FLAG);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
419 w+=2;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
420
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
421 if(opt->longopt!=NULL){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
422 fprintf(f, ", ");
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
423 w+=2;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
424 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
425 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
426
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
427 /* long opt */
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
428
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
429 if(opt->longopt!=NULL){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
430 if(midlong){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
431 w++;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
432 fprintf(f, "-%s", opt->longopt);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
433 }else{
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
434 w+=2;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
435 fprintf(f, "--%s", opt->longopt);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
436 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
437 w+=strlen(opt->longopt);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
438 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
439
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
440 /* arg */
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
441
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
442 if(O_ARGS(opt)){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
443 w++;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
444 if(opt->longopt!=NULL && !midlong)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
445 putc('=', f);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
446 else
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
447 putc(' ', f);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
448
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
449 if(O_OPT_ARG(opt)){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
450 w+=2;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
451 putc('[', f);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
452 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
453
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
454 if(opt->argname!=NULL){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
455 fprintf(f, "%s", opt->argname);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
456 w+=strlen(opt->argname);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
457 }else{
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
458 w+=3;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
459 fprintf(f, "ARG");
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
460 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
461
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
462 if(O_OPT_ARG(opt))
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
463 putc(']', f);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
464 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
465
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
466 while(w++<maxw)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
467 putc(' ', f);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
468
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
469 /* descr */
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
470
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
471 p=p2=opt->descr;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
472
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
473 if(p==NULL){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
474 putc('\n', f);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
475 return;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
476 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
477
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
478 fprintf(f, SPACER2);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
479
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
480 maxw+=OFF1+OFF2;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
481 tw-=maxw;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
482
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
483 while(strlen(p)>tw){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
484 p3=p2=p+tw-2;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
485
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
486 while(*p2!=' ' && p2!=p)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
487 p2--;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
488
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
489 while(*p3!=' ' && *p3!='\0')
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
490 p3++;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
491
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
492 if((uint)(p3-p2)>tw){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
493 /* long word - just wrap */
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
494 p2=p+tw-2;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
495 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
496
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
497 writef(f, p, p2-p);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
498 if(*p2==' ')
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
499 putc('\n', f);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
500 else
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
501 fprintf(f, "\\\n");
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
502
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
503 p=p2+1;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
504
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
505 w=maxw;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
506 while(w--)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
507 putc(' ', f);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
508 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
509
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
510 fprintf(f, "%s\n", p);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
511 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
512
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
513
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
514 static void print_opts(const OptParserOpt *opts, bool midlong,
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
515 const OptParserCommonInfo *cinfo)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
516 {
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
517 uint w, maxw=0;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
518 const OptParserOpt *o;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
519
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
520 o=opts;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
521 again:
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
522 for(; O_ID(o); o++){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
523 w=opt_w(o, midlong);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
524 if(w>maxw)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
525 maxw=w;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
526 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
527
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
528 if(o!=&(common_opts[3])){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
529 o=common_opts;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
530 goto again;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
531 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
532
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
533 o=opts;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
534 again2:
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
535 for(; O_ID(o); o++)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
536 print_opt(o, midlong, maxw, TERM_W);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
537
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
538 if(o!=&(common_opts[3])){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
539 printf("\n");
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
540 o=common_opts;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
541 goto again2;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
542 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
543 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
544
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
545
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
546 static void print_help(const OptParserOpt *opts, bool midlong,
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
547 const OptParserCommonInfo *cinfo)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
548 {
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
549 const char *tmp, *p=cinfo->usage_tmpl;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
550 size_t len;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
551 size_t start;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
552
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
553 while(1){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
554 tmp=strchr(p, '$');
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
555
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
556 if(tmp==NULL){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
557 writef(stdout, p, strlen(p));
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
558 return;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
559 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
560
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
561 if(tmp!=p)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
562 writef(stdout, p, tmp-p);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
563
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
564 p=tmp+1;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
565
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
566 if(*p=='p'){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
567 tmp=prog_execname();
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
568 writef(stdout, tmp, strlen(tmp));
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
569 }else if(*p=='o'){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
570 print_opts(opts, midlong, cinfo);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
571 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
572 p++;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
573 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
574 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
575

mercurial