optparser.c

Tue, 22 Jan 2002 01:20:58 +0100

author
tuomov
date
Tue, 22 Jan 2002 01:20:58 +0100
changeset 38
5e59489313a0
parent 36
63cd573ffbcf
child 53
f8f9366b359c
permissions
-rw-r--r--

trunk: changeset 41
END_CONFOPTS was missing

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

mercurial