Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / cmd / cmd.p.h
CommitLineData
805e021f
CE
1/*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
4 *
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
9
10#ifndef __CMD_INCL__
11#define __CMD_INCL__ 1
12
13/* parmdesc types */
14#define CMD_FLAG 1 /* no parms */
15#define CMD_SINGLE 2 /* one parm */
16#define CMD_LIST 3 /* two parms */
17#define CMD_SINGLE_OR_FLAG 4 /* one parm or flag */
18
19/* syndesc flags */
20#define CMD_ALIAS 1 /* this is an alias */
21#define CMD_HIDDEN 4 /* A hidden command - similar to CMD_HIDE */
22
23#define CMD_HELPPARM (CMD_MAXPARMS-1) /* last one is used by -help switch */
24#define CMD_MAXPARMS 64 /* max number of parm types to a cmd line */
25
26/* parse items are here */
27struct cmd_item {
28 struct cmd_item *next;
29 char *data;
30};
31
32struct cmd_parmdesc {
33 char *name; /* switch name */
34 int type; /* flag, single or list */
35 struct cmd_item *items; /* list of cmd items */
36 afs_int32 flags; /* flags */
37 char *help; /* optional help descr */
38 struct cmd_item *aliases; /* optional aliases */
39};
40
41/* cmd_parmdesc flags */
42#define CMD_REQUIRED 0
43#define CMD_OPTIONAL 1
44#define CMD_EXPANDS 2 /* if list, try to eat tokens through eoline, instead of just 1 */
45#define CMD_HIDE 4 /* A hidden option */
46#define CMD_PROCESSED 8
47#define CMD_NOABBRV 16 /* Abbreviation not supported */
48
49struct cmd_syndesc {
50 struct cmd_syndesc *next; /* next one in system list */
51 struct cmd_syndesc *nextAlias; /* next in alias chain */
52 struct cmd_syndesc *aliasOf; /* back ptr for aliases */
53 char *name; /* subcommand name */
54 char *a0name; /* command name from argv[0] */
55 char *help; /* help description */
56 int (*proc) (struct cmd_syndesc * ts, void *arock);
57 void *rock;
58 int nParms; /* number of parms */
59 afs_uint32 flags; /* random flags */
60 struct cmd_parmdesc parms[CMD_MAXPARMS]; /* parms themselves */
61};
62
63extern struct cmd_syndesc *cmd_CreateSyntax(char *namep,
64 int (*aprocp) (struct cmd_syndesc
65 * ts, void *arock),
66 void *rockp, afs_uint32 aflags, char *helpp);
67extern int
68 cmd_SetBeforeProc(int (*aproc) (struct cmd_syndesc * ts, void *beforeRock),
69 void *arock);
70extern int
71 cmd_SetAfterProc(int (*aproc) (struct cmd_syndesc * ts, void *afterRock),
72 void *arock);
73extern int cmd_CreateAlias(struct cmd_syndesc *as, char *aname);
74extern int cmd_Seek(struct cmd_syndesc *as, int apos);
75extern int cmd_AddParm(struct cmd_syndesc *as, char *aname, int atype,
76 afs_int32 aflags, char *ahelp);
77extern int cmd_AddParmAtOffset(struct cmd_syndesc *as, int ref, char *name,
78 int atype, afs_int32 aflags, char *ahelp);
79extern int cmd_AddParmAlias(struct cmd_syndesc *as, int pos, char *alias);
80extern int cmd_Dispatch(int argc, char **argv);
81extern int cmd_FreeArgv(char **argv);
82extern int cmd_ParseLine(char *aline, char **argv, afs_int32 * an,
83 afs_int32 amaxn);
84extern void cmd_DisablePositionalCommands(void);
85extern void cmd_DisableAbbreviations(void);
86extern void PrintSyntax(struct cmd_syndesc *as);
87extern void PrintFlagHelp(struct cmd_syndesc *as);
88
89extern int cmd_Parse(int argc, char **argv, struct cmd_syndesc **outsyntax);
90extern void cmd_FreeOptions(struct cmd_syndesc **ts);
91extern int cmd_OptionAsInt(struct cmd_syndesc *syn, int pos, int *value);
92extern int cmd_OptionAsUint(struct cmd_syndesc *, int, unsigned int *);
93extern int cmd_OptionAsString(struct cmd_syndesc *syn, int pos, char **value);
94extern int cmd_OptionAsList(struct cmd_syndesc *syn, int pos, struct cmd_item **);
95extern int cmd_OptionAsFlag(struct cmd_syndesc *syn, int pos, int *value);
96extern int cmd_OptionPresent(struct cmd_syndesc *syn, int pos);
97
98/* Config files */
99
100struct cmd_config_binding {
101 enum { cmd_config_string, cmd_config_list } type;
102 char *name;
103 struct cmd_config_binding *next;
104 union {
105 char *string;
106 struct cmd_config_binding *list;
107 void *generic;
108 } u;
109};
110
111/* Raw config file access */
112typedef struct cmd_config_binding cmd_config_binding;
113typedef struct cmd_config_binding cmd_config_section;
114
115extern int cmd_RawConfigParseFileMulti(const char *, cmd_config_section **);
116extern int cmd_RawConfigParseFile(const char *, cmd_config_section **);
117extern int cmd_RawConfigFileFree(cmd_config_section *s);
118extern const char* cmd_RawConfigGetString(const cmd_config_section *,
119 const char *, ...);
120extern int cmd_RawConfigGetBool(const cmd_config_section *, int, ...);
121extern int cmd_RawConfigGetInt(const cmd_config_section *, int, ...);
122extern const cmd_config_binding *cmd_RawConfigGetList
123 (const cmd_config_section *, ...);
124
125extern int cmd_OpenConfigFile(const char *file);
126extern void cmd_SetCommandName(const char *command);
127extern const cmd_config_section *cmd_RawFile(void);
128extern const cmd_config_section *cmd_RawSection(void);
129
130#endif /* __CMD_INCL__ */