Lines Matching defs:opts

27  * logadm/opts.c -- options handling routines
42 #include "opts.h"
46 static void opts_setcmdarg(struct opts *opts, const char *cmdarg);
49 struct opts {
126 struct opts *
127 opts_parse(struct opts *opts, char **argv, int flags)
132 if (opts == NULL) {
133 opts = MALLOC(sizeof (*opts));
134 opts->op_raw = opts->op_ints = NULL;
135 opts->op_cmdargs = fn_list_new(NULL);
138 /* no words to process, just return empty opts struct */
140 return (opts);
146 opts_setcmdarg(opts, ptr);
180 (void) opts_set(opts, info->oi_o, "");
190 opts_set(opts, info->oi_o, ptr);
195 return (opts);
199 * opts_free -- free a struct opts previously allocated by opts_parse()
202 opts_free(struct opts *opts)
204 if (opts) {
205 lut_free(opts->op_raw, NULL);
206 lut_free(opts->op_ints, NULL);
207 fn_list_free(opts->op_cmdargs);
208 FREE(opts);
216 opts_set(struct opts *opts, const char *o, const char *optarg)
222 opts->op_raw = lut_add(opts->op_raw, o, (void *)optarg);
226 opts->op_ints = lut_add(opts->op_ints, o, (void *)rval);
234 opts_setcmdarg(struct opts *opts, const char *cmdarg)
236 fn_list_adds(opts->op_cmdargs, cmdarg);
243 opts_count(struct opts *opts, const char *options)
251 if (lut_lookup(opts->op_raw, lhs))
261 opts_optarg(struct opts *opts, const char *o)
263 return ((char *)lut_lookup(opts->op_raw, o));
270 opts_optarg_int(struct opts *opts, const char *o)
274 ret = (off_t *)lut_lookup(opts->op_ints, o);
284 opts_cmdargs(struct opts *opts)
286 return (opts->op_cmdargs);
300 struct opts *
301 opts_merge(struct opts *back, struct opts *front)
303 struct opts *ret = MALLOC(sizeof (struct opts));
495 opts_print(struct opts *opts, FILE *stream, char *exclude)
504 lut_walk(opts->op_raw, printer, &pi);
506 fn_list_rewind(opts->op_cmdargs);
507 while ((fnp = fn_list_next(opts->op_cmdargs)) != NULL) {
526 * test main for opts module, usage: a.out options...
531 struct opts *opts;
542 err(0, "opts parsing failed");
544 opts = opts_parse(NULL, argv, OPTF_CLI);
547 opts_print(opts, stdout, NULL);