6 * Id: 9d4a7c1c6ae364a6134dc5ff01f58f08b52f1a16
7 * Time-stamp: "2008-07-30 16:56:32 bkorb"
9 * This is a special option processing routine that will save the
10 * argument to an option in a FIFO queue.
12 * This file is part of AutoOpts, a companion to AutoGen.
13 * AutoOpts is free software.
14 * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved
16 * AutoOpts is available under any one of two licenses. The license
17 * in use must be one of these two and the choice is under the control
18 * of the user of the license.
20 * The GNU Lesser General Public License, version 3 or later
21 * See the files "COPYING.lgplv3" and "COPYING.gplv3"
23 * The Modified Berkeley Software Distribution License
24 * See the file "COPYING.mbsd"
26 * These files have the following md5sums:
28 * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
29 * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
30 * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
34 # include REGEX_HEADER
37 /*=export_func optionUnstackArg
40 * what: Remove option args from a stack
41 * arg: + tOptions* + pOpts + program options descriptor +
42 * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
45 * Invoked for options that are equivalenced to stacked options.
56 if ((pOptDesc
->fOptState
& OPTST_RESET
) != 0)
58 pAL
= (tArgList
*)pOptDesc
->optCookie
;
61 * IF we don't have any stacked options,
62 * THEN indicate that we don't have any of these options
65 pOptDesc
->fOptState
&= OPTST_PERSISTENT_MASK
;
66 if ( (pOptDesc
->fOptState
& OPTST_INITENABLED
) == 0)
67 pOptDesc
->fOptState
|= OPTST_DISABLED
;
76 if (regcomp( &re
, pOptDesc
->optArg
.argString
, REG_NOSUB
) != 0)
80 * search the list for the entry(s) to remove. Entries that
81 * are removed are *not* copied into the result. The source
82 * index is incremented every time. The destination only when
83 * we are keeping a define.
85 for (i
= 0, dIdx
= 0, ct
= pAL
->useCt
; --ct
>= 0; i
++) {
86 tCC
* pzSrc
= pAL
->apzArgs
[ i
];
87 char* pzEq
= strchr( pzSrc
, '=' );
92 res
= regexec( &re
, pzSrc
, (size_t)0, NULL
, 0 );
96 * Remove this entry by reducing the in-use count
97 * and *not* putting the string pointer back into
110 * IF we have dropped an entry
111 * THEN we have to move the current one.
114 pAL
->apzArgs
[ dIdx
] = pzSrc
;
121 #else /* not WITH_LIBREGEX */
126 * search the list for the entry(s) to remove. Entries that
127 * are removed are *not* copied into the result. The source
128 * index is incremented every time. The destination only when
129 * we are keeping a define.
131 for (i
= 0, dIdx
= 0, ct
= pAL
->useCt
; --ct
>= 0; i
++) {
132 tCC
* pzSrc
= pAL
->apzArgs
[ i
];
133 char* pzEq
= strchr( pzSrc
, '=' );
138 if (strcmp( pzSrc
, pOptDesc
->optArg
.argString
) == 0) {
140 * Remove this entry by reducing the in-use count
141 * and *not* putting the string pointer back into
151 * IF we have dropped an entry
152 * THEN we have to move the current one.
155 pAL
->apzArgs
[ dIdx
] = pzSrc
;
160 #endif /* WITH_LIBREGEX */
162 * IF we have unstacked everything,
163 * THEN indicate that we don't have any of these options
165 if (pAL
->useCt
== 0) {
166 pOptDesc
->fOptState
&= OPTST_PERSISTENT_MASK
;
167 if ( (pOptDesc
->fOptState
& OPTST_INITENABLED
) == 0)
168 pOptDesc
->fOptState
|= OPTST_DISABLED
;
169 AGFREE( (void*)pAL
);
170 pOptDesc
->optCookie
= NULL
;
176 * Put an entry into an argument list. The first argument points to
177 * a pointer to the argument list structure. It gets passed around
178 * as an opaque address.
181 addArgListEntry( void** ppAL
, void* entry
)
183 tArgList
* pAL
= *(void**)ppAL
;
186 * IF we have never allocated one of these,
187 * THEN allocate one now
190 pAL
= (tArgList
*)AGALOC( sizeof( *pAL
), "new option arg stack" );
194 pAL
->allocCt
= MIN_ARG_ALLOC_CT
;
199 * ELSE if we are out of room
200 * THEN make it bigger
202 else if (pAL
->useCt
>= pAL
->allocCt
) {
203 size_t sz
= sizeof( *pAL
);
204 pAL
->allocCt
+= INCR_ARG_ALLOC_CT
;
207 * The base structure contains space for MIN_ARG_ALLOC_CT
208 * pointers. We subtract it off to find our augment size.
210 sz
+= sizeof(char*) * (pAL
->allocCt
- MIN_ARG_ALLOC_CT
);
211 pAL
= (tArgList
*)AGREALOC( (void*)pAL
, sz
, "expanded opt arg stack" );
218 * Insert the new argument into the list
220 pAL
->apzArgs
[ (pAL
->useCt
)++ ] = entry
;
224 /*=export_func optionStackArg
227 * what: put option args on a stack
228 * arg: + tOptions* + pOpts + program options descriptor +
229 * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
232 * Keep an entry-ordered list of option arguments.
241 if ((pOD
->fOptState
& OPTST_RESET
) != 0) {
242 tArgList
* pAL
= (void*)pOD
->optCookie
;
249 AGFREE(pAL
->apzArgs
[ix
]);
253 if (pOD
->optArg
.argString
== NULL
)
256 AGDUPSTR(pz
, pOD
->optArg
.argString
, "stack arg");
257 addArgListEntry( &(pOD
->optCookie
), (void*)pz
);
263 * c-file-style: "stroustrup"
264 * indent-tabs-mode: nil
266 * end of autoopts/stack.c */