1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
27 * multi-pass commmand line option parse assist
29 * int fun(char** argv, int last)
31 * each fun() argument parses as much of argv as
32 * possible starting at (opt_info.index,opt_info.offset) using
35 * if last!=0 then fun is the last pass to view
36 * the current arg, otherwise fun sets opt_info.again=1
37 * and another pass will get a crack at it
39 * 0 fun() return causes immediate optjoin() 0 return
41 * optjoin() returns non-zero if more args remain
42 * to be parsed at opt_info.index
47 typedef int (*Optpass_f
)(char**, int);
50 optjoin(char** argv
, ...)
53 register Optpass_f fun
;
54 register Optpass_f rep
;
69 opt_info
.state
->join
= 0;
70 while (fun
= va_arg(ap
, Optpass_f
))
72 last_index
= opt_info
.index
;
73 last_offset
= opt_info
.offset
;
74 opt_info
.state
->join
++;
75 user
= (*fun
)(argv
, 0);
76 more
= argv
[opt_info
.index
] != 0;
81 opt_info
.state
->join
= 0;
86 if (*argv
[opt_info
.index
] != '+')
88 opt_info
.state
->join
= 0;
98 if (opt_info
.again
> 0 && (!err
|| err_index
< opt_info
.index
|| err_index
== opt_info
.index
&& err_offset
< opt_info
.offset
))
101 err_index
= opt_info
.index
;
102 err_offset
= opt_info
.offset
;
105 opt_info
.index
= opt_info
.state
->pindex
? opt_info
.state
->pindex
: 1;
106 opt_info
.offset
= opt_info
.state
->poffset
;
108 if (!rep
|| opt_info
.index
!= last_index
|| opt_info
.offset
!= last_offset
)
114 opt_info
.state
->join
= 0;