Version 0.1.1 from FTP
[asterisk/asterisk.git] / include / asterisk / cli.h
1 /*
2  * Asterisk -- A telephony toolkit for Linux.
3  *
4  * Standard Command Line Interface
5  * 
6  * Copyright (C) 1999, Mark Spencer
7  *
8  * Mark Spencer <markster@linux-support.net>
9  *
10  * This program is free software, distributed under the terms of
11  * the GNU General Public License
12  */
13
14 #ifndef _ASTERISK_CLI_H
15 #define _ASTERISK_CLI_H
16
17 #if defined(__cplusplus) || defined(c_plusplus)
18 extern "C" {
19 #endif
20
21 #include <stdarg.h>
22
23 extern void ast_cli(int fd, char *fmt, ...);
24
25 #define RESULT_SUCCESS          0
26 #define RESULT_SHOWUSAGE        1
27 #define RESULT_FAILURE          2
28
29 #define AST_MAX_CMD_LEN         16
30
31 /* A command line entry */
32 #define AST_MAX_ARGS 64
33
34 struct ast_cli_entry {
35         /* Null terminated list of the words of the command */
36         char *cmda[AST_MAX_CMD_LEN];
37         /* Handler for the command (fd for output, # of arguments, argument list). 
38             Returns RESULT_SHOWUSAGE for improper arguments */
39         int (*handler)(int fd, int argc, char *argv[]);
40         /* Summary of the command (< 60 characters) */
41         char *summary;
42         /* Detailed usage information */
43         char *usage;
44         /* Generate a list of possible completions for a given word */
45         char *(*generator)(char *line, char *word, int pos, int state);
46         /* For linking */
47         struct ast_cli_entry *next;
48 };
49
50 /* Interpret a command s, sending output to fd */
51 extern int ast_cli_command(int fd, char *s);
52
53 /* Register your own command */
54 extern int ast_cli_register(struct ast_cli_entry *e);
55
56 /* Unregister your own command */
57 extern int ast_cli_unregister(struct ast_cli_entry *e);
58
59 /* Useful for readline, that's about it */
60 extern char *ast_cli_generator(char *, char *, int);
61
62 #if defined(__cplusplus) || defined(c_plusplus)
63 }
64 #endif
65
66 #endif