reindent-20030715
[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
18 /* syndesc flags */
19 #define CMD_ALIAS       1       /* this is an alias */
20 #define CMD_ADMIN       2       /* admin. command, show only with -admin */
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 */
27 struct cmd_item {
28     struct cmd_item *next;
29     char *data;
30 };
31
32 struct 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 };
39
40 /* cmd_parmdesc flags */
41 #define CMD_REQUIRED        0
42 #define CMD_OPTIONAL        1
43 #define CMD_EXPANDS         2   /* if list, try to eat tokens through eoline, instead of just 1 */
44 #define CMD_HIDE            4   /* A hidden option */
45 #define CMD_PROCESSED       8
46
47 struct cmd_syndesc {
48     struct cmd_syndesc *next;   /* next one in system list */
49     struct cmd_syndesc *nextAlias;      /* next in alias chain */
50     struct cmd_syndesc *aliasOf;        /* back ptr for aliases */
51     char *name;                 /* subcommand name */
52     char *a0name;               /* command name from argv[0] */
53     char *help;                 /* help description */
54     int (*proc) (struct cmd_syndesc * ts, char *arock);
55     char *rock;
56     int nParms;                 /* number of parms */
57     afs_int32 flags;            /* random flags */
58     struct cmd_parmdesc parms[CMD_MAXPARMS];    /* parms themselves */
59 };
60
61 extern struct cmd_syndesc *cmd_CreateSyntax(char *namep,
62                                             int (*aprocp) (struct cmd_syndesc
63                                                            * ts, char *arock),
64                                             char *rockp, char *helpp);
65 extern int
66   cmd_SetBeforeProc(int (*aproc) (struct cmd_syndesc * ts, char *beforeRock),
67                     char *arock);
68 extern int
69   cmd_SetAfterProc(int (*aproc) (struct cmd_syndesc * ts, char *afterRock),
70                    char *arock);
71 extern int cmd_CreateAlias(struct cmd_syndesc *as, char *aname);
72 extern int cmd_Seek(struct cmd_syndesc *as, int apos);
73 extern int cmd_AddParm(struct cmd_syndesc *as, char *aname, int atype,
74                        afs_int32 aflags, char *ahelp);
75 extern int cmd_Dispatch(int argc, char **argv);
76 extern int cmd_FreeArgv(char **argv);
77 extern int cmd_ParseLine(char *aline, char **argv, afs_int32 * an,
78                          afs_int32 amaxn);
79 extern int cmd_IsAdministratorCommand(register struct cmd_syndesc *as);
80 extern void PrintSyntax(register struct cmd_syndesc *as);
81 extern void PrintFlagHelp(register struct cmd_syndesc *as);
82
83 #endif /* __CMD_INCL__ */