Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

cli.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- A telephony toolkit for Linux.
00003  *
00004  * Standard Command Line Interface
00005  * 
00006  * Copyright (C) 1999, Mark Spencer
00007  *
00008  * Mark Spencer <markster@linux-support.net>
00009  *
00010  * This program is free software, distributed under the terms of
00011  * the GNU General Public License
00012  */
00013 
00014 #ifndef _ASTERISK_CLI_H
00015 #define _ASTERISK_CLI_H
00016 
00017 #if defined(__cplusplus) || defined(c_plusplus)
00018 extern "C" {
00019 #endif
00020 
00021 #include <stdarg.h>
00022 
00023 extern void ast_cli(int fd, char *fmt, ...)
00024    __attribute__ ((format (printf, 2, 3)));
00025 
00026 #define RESULT_SUCCESS     0
00027 #define RESULT_SHOWUSAGE   1
00028 #define RESULT_FAILURE     2
00029 
00030 #define AST_MAX_CMD_LEN    16
00031 
00032 #define AST_MAX_ARGS 64
00033 
00034 #define AST_CLI_COMPLETE_EOF  "_EOF_"
00035 
00036 //! A command line entry */
00037 struct ast_cli_entry {
00038    /*! Null terminated list of the words of the command */
00039    char *cmda[AST_MAX_CMD_LEN];
00040    /*! Handler for the command (fd for output, # of arguments, argument list).  Returns RESULT_SHOWUSAGE for improper arguments */
00041    int (*handler)(int fd, int argc, char *argv[]);
00042    /*! Summary of the command (< 60 characters) */
00043    char *summary;
00044    /*! Detailed usage information */
00045    char *usage;
00046    /*! Generate a list of possible completions for a given word */
00047    char *(*generator)(char *line, char *word, int pos, int state);
00048    /*! For linking */
00049    struct ast_cli_entry *next;
00050    /*! For keeping track of usage */
00051    int inuse;
00052 };
00053 
00054 //! Interprets a command
00055 /*! Interpret a command s, sending output to fd
00056  * Returns 0 on succes, -1 on failure 
00057  */
00058 extern int ast_cli_command(int fd, char *s);
00059 
00060 //! Registers a command
00061 /*! 
00062  * \param fd File descriptor that I/O is done to
00063  * \param s string given at prompt
00064  * Register your own command
00065  * Returns 0 on success, -1 on failure
00066  */
00067 extern int ast_cli_register(struct ast_cli_entry *e);
00068 
00069 //! Unregisters a command
00070 /*!
00071  * \param e which cli entry to unregister
00072  * Unregister your own command.  You must pass a completed ast_cli_entry structur
00073  * Returns 0 on success, -1 on failure
00074  */
00075 extern int ast_cli_unregister(struct ast_cli_entry *e);
00076 
00077 //! Readline madness
00078 /* Useful for readline, that's about it
00079  * Returns 0 on success, -1 on failure
00080  */
00081 extern char *ast_cli_generator(char *, char *, int);
00082 
00083 extern int ast_cli_generatornummatches(char *, char *);
00084 extern char **ast_cli_completion_matches(char *, char *);
00085 
00086 #if defined(__cplusplus) || defined(c_plusplus)
00087 }
00088 #endif
00089 
00090 #endif

Generated on Sun Apr 18 23:33:50 2004 for Asterisk by doxygen 1.3.6-20040222