使用GNU ReadLine Library实现命令解析器
时间:2010-05-31 来源:creatory
使用GNU ReadLine Library实现命令解析器(历史记录,Tab自动补全等)
#include <stdio.h>
#include <sys/types.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/errno.h> #include <readline/readline.h>
#include <readline/history.h> extern char *getwd ();
extern char *xmalloc (); /* The names of functions that actually do the manipulation. */
int com_list (char*);
int com_view (char*);
int com_rename (char*);
int com_stat (char*);
int com_pwd (char*);
int com_delete (char*);
int com_help (char*);
int com_cd (char*);
int com_quit (char*); /* A structure which contains information on the commands this program
can understand. */ typedef struct {
char *name; /* User printable name of the function. */
Function *func; /* Function to call to do the job. */
char *doc; /* Documentation for this function. */
} COMMAND; COMMAND commands[] = {
{ "cd", com_cd, "Change to directory DIR" },
{ "delete", com_delete, "Delete FILE" },
{ "help", com_help, "Display this text" },
{ "?", com_help, "Synonym for `help'" },
{ "list", com_list, "List files in DIR" },
{ "ls", com_list, "Synonym for `list'" },
{ "pwd", com_pwd, "Print the current working directory" },
{ "quit", com_quit, "Quit using Fileman" },
{ "rename", com_rename, "Rename FILE to NEWNAME" },
{ "stat", com_stat, "Print out statistics on FILE" },
{ "view", com_view, "View the contents of FILE" },
{ (char *)NULL, (Function *)NULL, (char *)
#include <sys/types.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/errno.h> #include <readline/readline.h>
#include <readline/history.h> extern char *getwd ();
extern char *xmalloc (); /* The names of functions that actually do the manipulation. */
int com_list (char*);
int com_view (char*);
int com_rename (char*);
int com_stat (char*);
int com_pwd (char*);
int com_delete (char*);
int com_help (char*);
int com_cd (char*);
int com_quit (char*); /* A structure which contains information on the commands this program
can understand. */ typedef struct {
char *name; /* User printable name of the function. */
Function *func; /* Function to call to do the job. */
char *doc; /* Documentation for this function. */
} COMMAND; COMMAND commands[] = {
{ "cd", com_cd, "Change to directory DIR" },
{ "delete", com_delete, "Delete FILE" },
{ "help", com_help, "Display this text" },
{ "?", com_help, "Synonym for `help'" },
{ "list", com_list, "List files in DIR" },
{ "ls", com_list, "Synonym for `list'" },
{ "pwd", com_pwd, "Print the current working directory" },
{ "quit", com_quit, "Quit using Fileman" },
{ "rename", com_rename, "Rename FILE to NEWNAME" },
{ "stat", com_stat, "Print out statistics on FILE" },
{ "view", com_view, "View the contents of FILE" },
{ (char *)NULL, (Function *)NULL, (char *)
相关阅读 更多 +