dd0ff4c02e0a51553e406d17f9fc2afa79d56ce7
[openafs.git] / src / cmd / cmd.p.h
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_ADMIN       2       /* admin. command, show only with -admin */
22 #define CMD_HIDDEN      4       /* A hidden command - similar to CMD_HIDE */
23
24 #define CMD_HELPPARM    (CMD_MAXPARMS-1)        /* last one is used by -help switch */
25 #define CMD_MAXPARMS    64      /* max number of parm types to a cmd line */
26
27 /* parse items are here */
28 struct cmd_item {
29     struct cmd_item *next;
30     char *data;
31 };
32
33 struct cmd_parmdesc {
34     char *name;                 /* switch name */
35     int type;                   /* flag, single or list */
36     struct cmd_item *items;     /* list of cmd items */
37     afs_int32 flags;            /* flags */
38     char *help;                 /* optional help descr */
39     struct cmd_item *aliases;   /* optional aliases */
40 };
41
42 /* cmd_parmdesc flags */
43 #define CMD_REQUIRED        0
44 #define CMD_OPTIONAL        1
45 #define CMD_EXPANDS         2   /* if list, try to eat tokens through eoline, instead of just 1 */
46 #define CMD_HIDE            4   /* A hidden option */
47 #define CMD_PROCESSED       8
48 #define CMD_NOABBRV        16   /* Abbreviation not supported */
49
50 struct cmd_syndesc {
51     struct cmd_syndesc *next;   /* next one in system list */
52     struct cmd_syndesc *nextAlias;      /* next in alias chain */
53     struct cmd_syndesc *aliasOf;        /* back ptr for aliases */
54     char *name;                 /* subcommand name */
55     char *a0name;               /* command name from argv[0] */
56     char *help;                 /* help description */
57     int (*proc) (struct cmd_syndesc * ts, void *arock);
58     void *rock;
59     int nParms;                 /* number of parms */
60     afs_int32 flags;            /* random flags */
61     struct cmd_parmdesc parms[CMD_MAXPARMS];    /* parms themselves */
62 };
63
64 extern struct cmd_syndesc *cmd_CreateSyntax(char *namep,
65                                             int (*aprocp) (struct cmd_syndesc
66                                                            * ts, void *arock),
67                                             void *rockp, char *helpp);
68 extern int
69   cmd_SetBeforeProc(int (*aproc) (struct cmd_syndesc * ts, void *beforeRock),
70                     void *arock);
71 extern int
72   cmd_SetAfterProc(int (*aproc) (struct cmd_syndesc * ts, void *afterRock),
73                    void *arock);
74 extern int cmd_CreateAlias(struct cmd_syndesc *as, char *aname);
75 extern int cmd_Seek(struct cmd_syndesc *as, int apos);
76 extern int cmd_AddParm(struct cmd_syndesc *as, char *aname, int atype,
77                        afs_int32 aflags, char *ahelp);
78 extern int cmd_AddParmAtOffset(struct cmd_syndesc *as, int ref, char *name,
79                                int atype, afs_int32 aflags, char *ahelp);
80 extern int cmd_AddParmAlias(struct cmd_syndesc *as, int pos, char *alias);
81 extern int cmd_Dispatch(int argc, char **argv);
82 extern int cmd_FreeArgv(char **argv);
83 extern int cmd_ParseLine(char *aline, char **argv, afs_int32 * an,
84                          afs_int32 amaxn);
85 extern int cmd_IsAdministratorCommand(struct cmd_syndesc *as);
86 extern void cmd_DisablePositionalCommands(void);
87 extern void cmd_DisableAbbreviations(void);
88 extern void PrintSyntax(struct cmd_syndesc *as);
89 extern void PrintFlagHelp(struct cmd_syndesc *as);
90
91 extern int cmd_Parse(int argc, char **argv, struct cmd_syndesc **outsyntax);
92 extern void cmd_FreeOptions(struct cmd_syndesc **ts);
93 extern int cmd_OptionAsInt(struct cmd_syndesc *syn, int pos, int *value);
94 extern int cmd_OptionAsUint(struct cmd_syndesc *, int, unsigned int *);
95 extern int cmd_OptionAsString(struct cmd_syndesc *syn, int pos, char **value);
96 extern int cmd_OptionAsList(struct cmd_syndesc *syn, int pos, struct cmd_item **);
97 extern int cmd_OptionAsFlag(struct cmd_syndesc *syn, int pos, int *value);
98 extern int cmd_OptionPresent(struct cmd_syndesc *syn, int pos);
99
100 /* Config files */
101
102 struct cmd_config_binding {
103     enum { cmd_config_string, cmd_config_list } type;
104     char *name;
105     struct cmd_config_binding *next;
106     union {
107         char *string;
108         struct cmd_config_binding *list;
109         void *generic;
110     } u;
111 };
112
113 /* Raw config file access */
114 typedef struct cmd_config_binding cmd_config_binding;
115 typedef struct cmd_config_binding cmd_config_section;
116
117 extern int cmd_RawConfigParseFileMulti(const char *, cmd_config_section **);
118 extern int cmd_RawConfigParseFile(const char *, cmd_config_section **);
119 extern int cmd_RawConfigFileFree(cmd_config_section *s);
120 extern const char* cmd_RawConfigGetString(const cmd_config_section *,
121                                           const char *, ...);
122 extern int cmd_RawConfigGetBool(const cmd_config_section *, int, ...);
123 extern int cmd_RawConfigGetInt(const cmd_config_section *, int, ...);
124 extern const cmd_config_binding *cmd_RawConfigGetList
125         (const cmd_config_section *, ...);
126
127 extern int cmd_OpenConfigFile(const char *file);
128 extern void cmd_SetCommandName(const char *command);
129 extern const cmd_config_section *cmd_RawFile(void);
130 extern const cmd_config_section *cmd_RawSection(void);
131
132 #endif /* __CMD_INCL__ */