optparser.c

Sun, 21 May 2000 17:33:48 +0200

author
tuomov
date
Sun, 21 May 2000 17:33:48 +0200
changeset 12
5fd153b29d40
parent 9
55e7f2ff6021
child 19
3e498ec7abcd
permissions
-rw-r--r--

trunk: changeset 15
- Optparser generates --help from option descriptions in the
OptParserOpt structure

- Changed the options --license, --authors and --proginfo to single
--about

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 *
9
55e7f2ff6021 trunk: changeset 12
tuomov
parents: 5
diff changeset
4 * Copyright (c) Tuomo Valkonen 1999-2000.
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);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
149 }else if(*(p+1)=='-'){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
150 /* --foo */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
151 if(*(p+2)=='\0'){
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
152 /* -- arguments */
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
153 o_args_left=o_left;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
154 RET(OPT_ID_ARGUMENT);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
155 }
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
156 type=LONG;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
157 p2=p+2;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
158 }else{
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
159 /* -foo */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
160 if(*(p+1)=='\0'){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
161 /* - */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
162 o_args_left=1;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
163 RET(OPT_ID_ARGUMENT);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
164 }
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
165 if(*(p+2)!='\0' && o_mode==OPTP_MIDLONG)
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
166 type=MIDLONG;
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
167
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
168 p2=p+1;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
169 }
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 o=o_opts;
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 again:
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
174 for(; O_ID(o); o++){
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
175 if(type==LONG){
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
176 /* Do long option (--foo=bar) */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
177 if(o->longopt==NULL)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
178 continue;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
179 l=strlen(o->longopt);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
180 if(strncmp(p2, o->longopt, l)!=0)
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
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
183 if(p2[l]=='\0'){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
184 if(O_ARGS(o)==OPT_ARG)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
185 RET(E_OPT_MISSING_ARGUMENT);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
186 return O_ID(o);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
187 }else if(p2[l]=='='){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
188 if(!O_ARGS(o))
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
189 RET(E_OPT_UNEXPECTED_ARGUMENT);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
190 if(p2[l+1]=='\0')
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
191 RET(E_OPT_MISSING_ARGUMENT);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
192 o_tmp=p2+l+1;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
193 o_args_left=1;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
194 return O_ID(o);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
195 }
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
196 continue;
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
197 }else if(type==MIDLONG){
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
198 if(o->longopt==NULL)
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
199 continue;
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
200
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
201 if(strcmp(p2, o->longopt)!=0)
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
202 continue;
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
203 }else{ /* type==SHORT */
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
204 if(*p2!=(O_ID(o)&~OPT_ID_RESERVED_FLAG))
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
205 continue;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
206
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
207 if(*(p2+1)!='\0'){
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
208 if(o_mode==OPTP_CHAIN || o_mode==OPTP_NO_DASH){
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
209 /*valid_chain(p2+1, o_opts)*/
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
210 o_chain_ptr=p2+1;
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
211 p++;
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
212 }else if(o_mode==OPTP_IMMEDIATE){
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
213 if(!O_ARGS(o)){
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
214 if(*(p2+1)!='\0')
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
215 RET(E_OPT_UNEXPECTED_ARGUMENT);
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
216 }else{
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_MISSING_ARGUMENT);
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
219 o_tmp=p2+1;
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
220 o_args_left=1;
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
221 }
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
222 return O_ID(o);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
223 }else{
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
224 RET(E_OPT_SYNTAX_ERROR);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
225 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
226 }
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
227 }
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
228
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
229 do_arg:
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
230
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
231 if(!O_ARGS(o))
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
232 return O_ID(o);
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
233
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
234 if(!o_left || is_option(*o_current)){
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
235 if(O_ARGS(o)==OPT_OPT_ARG)
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
236 return O_ID(o);
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
237 RET(E_OPT_MISSING_ARGUMENT);
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
238 }
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
239
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
240 o_args_left=1;
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
241 return O_ID(o);
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
242 }
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
243
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
244 if(o!=&(common_opts[3])){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
245 o=common_opts;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
246 goto again;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
247 }
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
248
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
249 if(dash)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
250 RET(E_OPT_INVALID_OPTION);
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 RET(OPT_ID_ARGUMENT);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
253 #undef RET
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
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
256
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
257 int optparser_get_opt()
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
258 {
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
259 int oid=optparser_do_get_opt();
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
260
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
261 if(oid<=0 || (oid&OPT_ID_RESERVED_FLAG)==0)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
262 return oid;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
263
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
264 switch(oid){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
265 case OPT_ID_ABOUT:
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
266 if(o_cinfo->about!=NULL)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
267 printf("%s", o_cinfo->about);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
268 break;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
269
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
270 case OPT_ID_VERSION:
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
271 if(o_cinfo->version!=NULL)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
272 printf("%s\n", o_cinfo->version);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
273 break;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
274
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
275 case OPT_ID_HELP:
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
276 print_help(o_opts, o_mode==OPTP_MIDLONG, o_cinfo);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
277 break;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
278 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
279
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
280 exit(EXIT_SUCCESS);
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
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
284 /* */
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 const char* optparser_get_arg()
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 const char *p;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
290
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
291 if(o_tmp!=NULL){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
292 /* If o_args_left==0, then were returning an invalid option
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
293 * otherwise an immediate argument (e.g. -funsigned-char
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
294 * where '-f' is the option and 'unsigned-char' the argument)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
295 */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
296 if(o_args_left>0)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
297 o_args_left--;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
298 p=o_tmp;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
299 o_tmp=NULL;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
300 return p;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
301 }
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 if(o_args_left<1 || o_left<1)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
304 return NULL;
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 o_left--;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
307 o_args_left--;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
308 return *o_current++;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
309 }
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 static void warn_arg(const char *e)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
315 {
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
316 const char *p=optparser_get_arg();
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
317
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
318 if(p==NULL)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
319 warn("%s (null)", e);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
320 else
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
321 warn("%s \'%s\'", e, p);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
322 }
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 static void warn_opt(const char *e)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
326 {
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
327 if(o_tmp!=NULL && o_chain_ptr!=NULL)
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
328 warn("%s \'-%c\'", e, *o_tmp);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
329 else
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
330 warn_arg(e);
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
331 }
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 void optparser_print_error()
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 switch(o_error){
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
337 case E_OPT_INVALID_OPTION:
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
338 case E_OPT_INVALID_CHAIN_OPTION:
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
339 warn_opt(TR("Invalid option"));
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
340 break;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
341
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
342 case E_OPT_SYNTAX_ERROR:
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
343 warn_arg(TR("Syntax error while parsing"));
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
344 break;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
345
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
346 case E_OPT_MISSING_ARGUMENT:
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
347 warn_opt(TR("Missing argument to"));
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
348 break;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
349
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
350 case E_OPT_UNEXPECTED_ARGUMENT:
3
b1fbfab67908 trunk: changeset 6
tuomov
parents: 0
diff changeset
351 warn_opt(TR("No argument expected:"));
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
352 break;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
353
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
354 case OPT_ID_ARGUMENT:
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
355 warn(TR("Unexpected argument"));
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
356 break;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
357
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
358 default:
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
359 warn(TR("(unknown error)"));
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
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
362 o_tmp=NULL;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
363 o_error=0;
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
364 }
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
365
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 static uint opt_w(const OptParserOpt *opt, bool midlong)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
371 {
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
372 uint w=0;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
373
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
374 if((opt->optid&OPT_ID_NOSHORT_FLAG)==0){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
375 w+=2; /* "-o" */
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
376 if(opt->longopt!=NULL)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
377 w+=2; /* ", " */
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
378 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
379
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
380 if(opt->longopt!=NULL)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
381 w+=strlen(opt->longopt)+(midlong ? 1 : 2);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
382
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
383 if(O_ARGS(opt)){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
384 if(opt->argname==NULL)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
385 w+=4;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
386 else
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
387 w+=1+strlen(opt->argname); /* "=ARG" or " ARG" */
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
388
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
389 if(O_OPT_ARG(opt))
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
390 w+=2; /* [ARG] */
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
391 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
392
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
393 return w;
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
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
397 #define TERM_W 80
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
398 #define OFF1 2
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
399 #define OFF2 2
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
400 #define SPACER1 " "
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
401 #define SPACER2 " "
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
402
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
403 static void print_opt(const OptParserOpt *opt, bool midlong,
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
404 uint maxw, uint tw)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
405 {
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
406 FILE *f=stdout;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
407 const char *p, *p2, *p3;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
408 uint w=0;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
409
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
410 fprintf(f, SPACER1);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
411
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
412 /* short opt */
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
413
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
414 if((O_ID(opt)&OPT_ID_NOSHORT_FLAG)==0){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
415 fprintf(f, "-%c", O_ID(opt)&~OPT_ID_RESERVED_FLAG);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
416 w+=2;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
417
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
418 if(opt->longopt!=NULL){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
419 fprintf(f, ", ");
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
420 w+=2;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
421 }
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 /* long opt */
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
425
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
426 if(opt->longopt!=NULL){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
427 if(midlong){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
428 w++;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
429 fprintf(f, "-%s", opt->longopt);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
430 }else{
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
431 w+=2;
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 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
434 w+=strlen(opt->longopt);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
435 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
436
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
437 /* arg */
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
438
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
439 if(O_ARGS(opt)){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
440 w++;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
441 if(opt->longopt!=NULL && !midlong)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
442 putc('=', f);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
443 else
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
444 putc(' ', f);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
445
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
446 if(O_OPT_ARG(opt)){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
447 w+=2;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
448 putc('[', f);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
449 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
450
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
451 if(opt->argname!=NULL){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
452 fprintf(f, "%s", opt->argname);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
453 w+=strlen(opt->argname);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
454 }else{
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
455 w+=3;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
456 fprintf(f, "ARG");
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
457 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
458
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
459 if(O_OPT_ARG(opt))
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
460 putc(']', f);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
461 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
462
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
463 while(w++<maxw)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
464 putc(' ', f);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
465
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
466 /* descr */
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
467
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
468 p=p2=opt->descr;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
469
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
470 if(p==NULL){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
471 putc('\n', f);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
472 return;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
473 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
474
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
475 fprintf(f, SPACER2);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
476
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
477 maxw+=OFF1+OFF2;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
478 tw-=maxw;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
479
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
480 while(strlen(p)>tw){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
481 p3=p2=p+tw-2;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
482
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
483 while(*p2!=' ' && p2!=p)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
484 p2--;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
485
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
486 while(*p3!=' ' && *p3!='\0')
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
487 p3++;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
488
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
489 if((uint)(p3-p2)>tw){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
490 /* long word - just wrap */
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
491 p2=p+tw-2;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
492 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
493
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
494 writef(f, p, p2-p);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
495 if(*p2==' ')
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
496 putc('\n', f);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
497 else
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
498 fprintf(f, "\\\n");
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
499
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
500 p=p2+1;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
501
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
502 w=maxw;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
503 while(w--)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
504 putc(' ', f);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
505 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
506
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
507 fprintf(f, "%s\n", p);
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
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
511 static void print_opts(const OptParserOpt *opts, bool midlong,
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
512 const OptParserCommonInfo *cinfo)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
513 {
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
514 uint w, maxw=0;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
515 const OptParserOpt *o;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
516
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
517 o=opts;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
518 again:
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
519 for(; O_ID(o); o++){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
520 w=opt_w(o, midlong);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
521 if(w>maxw)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
522 maxw=w;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
523 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
524
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
525 if(o!=&(common_opts[3])){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
526 o=common_opts;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
527 goto again;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
528 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
529
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
530 o=opts;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
531 again2:
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
532 for(; O_ID(o); o++)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
533 print_opt(o, midlong, maxw, TERM_W);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
534
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
535 if(o!=&(common_opts[3])){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
536 printf("\n");
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
537 o=common_opts;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
538 goto again2;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
539 }
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 static void print_help(const OptParserOpt *opts, bool midlong,
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
544 const OptParserCommonInfo *cinfo)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
545 {
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
546 const char *tmp, *p=cinfo->usage_tmpl;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
547 size_t len;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
548 size_t start;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
549
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
550 while(1){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
551 tmp=strchr(p, '$');
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
552
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
553 if(tmp==NULL){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
554 writef(stdout, p, strlen(p));
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
555 return;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
556 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
557
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
558 if(tmp!=p)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
559 writef(stdout, p, tmp-p);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
560
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
561 p=tmp+1;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
562
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
563 if(*p=='p'){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
564 tmp=prog_execname();
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
565 writef(stdout, tmp, strlen(tmp));
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
566 }else if(*p=='o'){
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
567 print_opts(opts, midlong, cinfo);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
568 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
569 p++;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
570 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
571 }
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
572

mercurial