Annotation of libaitcli/inc/aitcli.h, revision 1.1.1.1.2.1
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.1! misho 6: * $Id: aitcli.h,v 1.1.1.1 2010/04/16 13:20:29 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: * @out = Output handle
57: * @csPrompt = Prompt text
58: * return: -1 error, 0 = exit w/^+D, 1 done.
59: */
60: int cliExec(cliCommands_t *cmdList, FILE *out, const char *csPrompt);
61:
62:
63: /*
64: * cli_PrintHelp() Helper print for missing command arguments
65: * @out = Output stream
66: * @cmds = Commands list
67: * @idx = Selected command ID
68: * return: -1 error, !=-1 ok
69: * return: none
70: */
71: inline int cli_PrintHelp(FILE *out, void *cmds, int idx);
72:
73: /*
74: * cli_Cmd_Unsupported() Builtin helper function for unsupported commands
75: * @cmds = Commands list
76: * @idx = Selected command ID
77: * @out = Output handle
78: * @args = Parsed arguments array
79: * return: -1 error, 0 = ok, 1 exit from Cli!
80: */
81: int cli_Cmd_Unsupported(void *cmds, int idx, FILE *out, char ** __restrict args);
82: /*
83: * cli_Cmd_Help() Builtin helper function for Help screen
84: * @cmds = Commands list
85: * @idx = Selected command ID
86: * @out = Output handle
87: * @args = Parsed arguments array
88: * return: -1 error, 0 = ok
89: */
90: int cli_Cmd_Help(void *cmds, int idx, FILE *out, char ** __restrict args);
91: /*
92: * cli_Cmd_Exit() Builtin helper function for Exit from Cli
93: * @cmds = Commands list
94: * @idx = Selected command ID
95: * @out = Output handle
96: * @args = Parsed arguments array
97: * return: 1 exit from Cli!
98: */
99: int cli_Cmd_Exit(void *cmds, int idx, FILE *out, char ** __restrict args);
100:
101:
102: /*
103: * cli_Register_Commands - Declare helper function for register and export Commands variable
104: */
105: #define CLI_REGISTER_COMMANDS(CMDS) \
106: extern cliCommands_t CMDS[];
107: /*
108: * cli_Make_Comp_Commands - Declare helper function for Commands completion arguments
109: */
110: #define CLI_MAKE_COMP_COMMANDS(FUNC, CMDS) \
111: char *FUNC(const char *text, int state) \
112: { \
113: register int i; \
114: int len = strlen(text); \
115: for (i = state; CMDS[i].cmd_name; i++) { \
116: if (strncmp(CMDS[i].cmd_name, "---", 3) && \
117: !strncmp(CMDS[i].cmd_name, text, len)) \
118: return strdup(CMDS[i].cmd_name); \
119: } \
120: return NULL; \
121: }
122:
123: /*
124: * cli_Make_Comp_Args - Declare helper function for Arguments completion
125: */
126: #define CLI_MAKE_COMP_ARGS(FUNC, ARGS) \
127: char *FUNC(const char *text __attribute__((unused)), int state) \
128: { \
129: while (ARGS[state]) \
130: return strdup(ARGS[state]); \
131: return NULL; \
132: }
133:
134: /*
135: * cli_Comp_Filename() Builtin helper function for filename completion arguments
136: * @text = Text line
137: * @state = Position state
138: * return: NULL not found filename, != NULL filename
139: */
140: char *cli_Comp_Filename(const char *text, int state);
141:
142:
143: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>