Annotation of libaitcli/inc/aitcli.h, revision 1.1.1.1.2.2
1.1 misho 1: /*************************************************************************
2: * (C) 2010 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
3: * by Michael Pounov <misho@openbsd-bg.org>
4: *
5: * $Author: misho $
1.1.1.1.2.2! misho 6: * $Id: aitcli.h,v 1.1.1.1.2.1 2010/04/18 20:42:23 misho Exp $
1.1 misho 7: *
8: *************************************************************************/
9: #ifndef __AITCLI_H
10: #define __AITCLI_H
11:
12:
13: struct tagCLICmd {
14: const char *cmd_name;
15: int (*cmd_func)(void *, int, FILE *, char **);
16: const char *cmd_doc;
17: const char *cmd_help;
18: char *(*cmd_comp)(const char *, int);
19: };
20:
21: typedef struct tagCLICmd cliCommands_t;
22: typedef char *cli_CompEntry_t(const char *, int);
23: typedef char **cli_Completion_t(const char *, int, int);
24:
25:
26: // cli_GetErrno() Get error code of last operation
27: inline int cli_GetErrno();
28: // cli_GetError() Get error text of last operation
29: inline const char *cli_GetError();
30:
31: /*
32: * cli_Printf() Printf CLI features
33: * @out = Output stream
34: * @csFormat = Printf format string
35: * return: none
36: */
37: inline int cli_Printf(FILE *out, const char *csFormat, ...);
38:
39: /*
1.1.1.1.2.1 misho 40: * cliTTY() Initialize I/O TTY CLI features
41: * @inp = input handle
42: * @out = output handle
43: * return: none
44: */
45: inline void cliTTY(FILE *inp, FILE *out);
46: /*
1.1 misho 47: * cliComp() Initialize completion CLI features
48: * @cmdComplete = Completion function
49: * @cmdEntry = Compentry function
50: * return: none
51: */
52: inline void cliComp(cli_Completion_t *cmdComplete, cli_CompEntry_t *cmdEntry);
53: /*
54: * cliExec() Execute CLI main loop
55: * @cmdList = Commands list
56: * @csPrompt = Prompt text
57: * return: -1 error, 0 = exit w/^+D, 1 done.
58: */
1.1.1.1.2.2! misho 59: int cliExec(cliCommands_t *cmdList, const char *csPrompt);
1.1 misho 60:
61:
62: /*
63: * cli_PrintHelp() Helper print for missing command arguments
64: * @out = Output stream
65: * @cmds = Commands list
66: * @idx = Selected command ID
67: * return: -1 error, !=-1 ok
68: * return: none
69: */
70: inline int cli_PrintHelp(FILE *out, void *cmds, int idx);
71:
72: /*
73: * cli_Cmd_Unsupported() Builtin helper function for unsupported commands
74: * @cmds = Commands list
75: * @idx = Selected command ID
76: * @out = Output handle
77: * @args = Parsed arguments array
78: * return: -1 error, 0 = ok, 1 exit from Cli!
79: */
80: int cli_Cmd_Unsupported(void *cmds, int idx, FILE *out, char ** __restrict args);
81: /*
82: * cli_Cmd_Help() Builtin helper function for Help screen
83: * @cmds = Commands list
84: * @idx = Selected command ID
85: * @out = Output handle
86: * @args = Parsed arguments array
87: * return: -1 error, 0 = ok
88: */
89: int cli_Cmd_Help(void *cmds, int idx, FILE *out, char ** __restrict args);
90: /*
91: * cli_Cmd_Exit() Builtin helper function for Exit from Cli
92: * @cmds = Commands list
93: * @idx = Selected command ID
94: * @out = Output handle
95: * @args = Parsed arguments array
96: * return: 1 exit from Cli!
97: */
98: int cli_Cmd_Exit(void *cmds, int idx, FILE *out, char ** __restrict args);
99:
100:
101: /*
102: * cli_Register_Commands - Declare helper function for register and export Commands variable
103: */
104: #define CLI_REGISTER_COMMANDS(CMDS) \
105: extern cliCommands_t CMDS[];
106: /*
107: * cli_Make_Comp_Commands - Declare helper function for Commands completion arguments
108: */
109: #define CLI_MAKE_COMP_COMMANDS(FUNC, CMDS) \
110: char *FUNC(const char *text, int state) \
111: { \
112: register int i; \
113: int len = strlen(text); \
114: for (i = state; CMDS[i].cmd_name; i++) { \
115: if (strncmp(CMDS[i].cmd_name, "---", 3) && \
116: !strncmp(CMDS[i].cmd_name, text, len)) \
117: return strdup(CMDS[i].cmd_name); \
118: } \
119: return NULL; \
120: }
121:
122: /*
123: * cli_Make_Comp_Args - Declare helper function for Arguments completion
124: */
125: #define CLI_MAKE_COMP_ARGS(FUNC, ARGS) \
126: char *FUNC(const char *text __attribute__((unused)), int state) \
127: { \
128: while (ARGS[state]) \
129: return strdup(ARGS[state]); \
130: return NULL; \
131: }
132:
133: /*
134: * cli_Comp_Filename() Builtin helper function for filename completion arguments
135: * @text = Text line
136: * @state = Position state
137: * return: NULL not found filename, != NULL filename
138: */
139: char *cli_Comp_Filename(const char *text, int state);
140:
141:
142: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>