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