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 
00025 #define RESULT_SUCCESS     0
00026 #define RESULT_SHOWUSAGE   1
00027 #define RESULT_FAILURE     2
00028 
00029 #define AST_MAX_CMD_LEN    16
00030 
00031 #define AST_MAX_ARGS 64
00032 
00033 //! A command line entry */
00034 struct ast_cli_entry {
00035    /*! Null terminated list of the words of the command */
00036    char *cmda[AST_MAX_CMD_LEN];
00037    /*! Handler for the command (fd for output, # of arguments, argument list).  Returns RESULT_SHOWUSAGE for improper arguments */
00038    int (*handler)(int fd, int argc, char *argv[]);
00039    /*! Summary of the command (< 60 characters) */
00040    char *summary;
00041    /*! Detailed usage information */
00042    char *usage;
00043    /*! Generate a list of possible completions for a given word */
00044    char *(*generator)(char *line, char *word, int pos, int state);
00045    /*! For linking */
00046    struct ast_cli_entry *next;
00047    /*! For keeping track of usage */
00048    int inuse;
00049 };
00050 
00051 //! Interprets a command
00052 /*! Interpret a command s, sending output to fd
00053  * Returns 0 on succes, -1 on failure 
00054  */
00055 extern int ast_cli_command(int fd, char *s);
00056 
00057 //! Registers a command
00058 /*! 
00059  * \param fd File descriptor that I/O is done to
00060  * \param s string given at prompt
00061  * Register your own command
00062  * Returns 0 on success, -1 on failure
00063  */
00064 extern int ast_cli_register(struct ast_cli_entry *e);
00065 
00066 //! Unregisters a command
00067 /*!
00068  * \param e which cli entry to unregister
00069  * Unregister your own command.  You must pass a completed ast_cli_entry structur
00070  * Returns 0 on success, -1 on failure
00071  */
00072 extern int ast_cli_unregister(struct ast_cli_entry *e);
00073 
00074 //! Readline madness
00075 /* Useful for readline, that's about it
00076  * Returns 0 on success, -1 on failure
00077  */
00078 extern char *ast_cli_generator(char *, char *, int);
00079 
00080 extern int ast_cli_generatornummatches(char *, char *);
00081 extern char **ast_cli_completion_matches(char *, char *);
00082 
00083 #if defined(__cplusplus) || defined(c_plusplus)
00084 }
00085 #endif
00086 
00087 #endif

Generated on Fri Oct 31 07:05:05 2003 for Asterisk by doxygen 1.3.4