1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright (c) 2001 by Sun Microsystems, Inc. 24 * All rights reserved. 25 * 26 * logadm/opts.h -- public definitions for opts module 27 */ 28 29 #ifndef _LOGADM_OPTS_H 30 #define _LOGADM_OPTS_H 31 32 #pragma ident "%Z%%M% %I% %E% SMI" 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 /* various types of options we allow */ 39 enum opttype { 40 OPTTYPE_BOOLEAN, /* simple boolean flag */ 41 OPTTYPE_INT, /* simple number */ 42 OPTTYPE_STRING /* string (like a pathname) */ 43 }; 44 45 struct opts; 46 47 /* info that drives option parsing (table of these is passed to opts_init()) */ 48 struct optinfo { 49 char *oi_o; /* the option */ 50 enum opttype oi_t; /* the type of this option */ 51 /* parser, if set, is called to parse optarg */ 52 int (*oi_parser)(const char *o, const char *optarg); 53 int oi_flags; 54 }; 55 56 /* flags for struct optinfo */ 57 #define OPTF_CLI 1 58 #define OPTF_CONF 2 59 60 void opts_init(struct optinfo *table, int numentries); 61 struct opts *opts_parse(char **args, int flags); 62 void opts_free(struct opts *opts); 63 void opts_set(struct opts *opts, const char *o, const char *optarg); 64 int opts_count(struct opts *opts, const char *options); 65 const char *opts_optarg(struct opts *opts, const char *o); 66 int opts_optarg_int(struct opts *opts, const char *o); 67 struct fn_list *opts_cmdargs(struct opts *opts); 68 struct opts *opts_merge(struct opts *back, struct opts *front); 69 70 #define OPTP_NOW (-1) 71 #define OPTP_NEVER (-2) 72 73 int opts_parse_ctime(const char *o, const char *optarg); 74 int opts_parse_bytes(const char *o, const char *optarg); 75 int opts_parse_atopi(const char *o, const char *optarg); 76 int opts_parse_seconds(const char *o, const char *optarg); 77 78 void opts_print(struct opts *opts, FILE *stream, char *exclude); 79 void opts_printword(const char *word, FILE *stream); 80 81 #ifdef __cplusplus 82 } 83 #endif 84 85 #endif /* _LOGADM_OPTS_H */ 86