mirror of
https://github.com/troglobit/editline.git
synced 2025-05-06 04:21:24 +08:00
examples/fileman.c: Further code cleanup and simplification
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
parent
a237e39181
commit
8f5a5da754
@ -26,8 +26,6 @@ void initialize_readline();
|
|||||||
int execute_line(char *line);
|
int execute_line(char *line);
|
||||||
int valid_argument(char *caller, char *arg);
|
int valid_argument(char *caller, char *arg);
|
||||||
|
|
||||||
typedef int rl_icpfunc_t(char *);
|
|
||||||
|
|
||||||
/* The names of functions that actually do the manipulation. */
|
/* The names of functions that actually do the manipulation. */
|
||||||
int com_list(char *);
|
int com_list(char *);
|
||||||
int com_view(char *);
|
int com_view(char *);
|
||||||
@ -40,39 +38,36 @@ int com_help(char *);
|
|||||||
int com_cd(char *);
|
int com_cd(char *);
|
||||||
int com_quit(char *);
|
int com_quit(char *);
|
||||||
|
|
||||||
/* A structure which contains information on the commands this program
|
struct cmd {
|
||||||
can understand. */
|
char *name; /* User printable name of the function. */
|
||||||
|
int (*func)(char *); /* Function to call to do the job. */
|
||||||
|
char *doc; /* Documentation for this function. */
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct {
|
struct cmd commands[] = {
|
||||||
char *name; /* User printable name of the function. */
|
{ "cd", com_cd, "Change to directory DIR"},
|
||||||
rl_icpfunc_t *func; /* Function to call to do the job. */
|
{ "delete", com_delete, "Delete FILE"},
|
||||||
char *doc; /* Documentation for this function. */
|
{ "help", com_help, "Display this text"},
|
||||||
} COMMAND;
|
{ "?", com_help, "Synonym for `help'"},
|
||||||
|
{ "list", com_list, "List files in DIR"},
|
||||||
COMMAND commands[] = {
|
{ "ls", com_list, "Synonym for `list'"},
|
||||||
{"cd", com_cd, "Change to directory DIR"},
|
{ "pwd", com_pwd, "Print the current working directory"},
|
||||||
{"delete", com_delete, "Delete FILE"},
|
{ "quit", com_quit, "Quit using Fileman"},
|
||||||
{"help", com_help, "Display this text"},
|
{ "rename", com_rename, "Rename FILE to NEWNAME"},
|
||||||
{"?", com_help, "Synonym for `help'"},
|
{ "stat", com_stat, "Print out statistics on FILE"},
|
||||||
{"list", com_list, "List files in DIR"},
|
{ "view", com_view, "View the contents of FILE"},
|
||||||
{"ls", com_list, "Synonym for `list'"},
|
{ "history", com_history, "List editline history"},
|
||||||
{"pwd", com_pwd, "Print the current working directory"},
|
{ NULL, NULL, NULL },
|
||||||
{"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"},
|
|
||||||
{"history", com_history, "List editline history"},
|
|
||||||
{(char *)NULL, (rl_icpfunc_t *) NULL, (char *)NULL}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Forward declarations. */
|
/* Forward declarations. */
|
||||||
char *stripwhite();
|
char *stripwhite();
|
||||||
COMMAND *find_command();
|
struct cmd *find_command();
|
||||||
|
|
||||||
/* When non-zero, this means the user is done using this program. */
|
/* When non-zero, this means the user is done using this program. */
|
||||||
int done;
|
int done;
|
||||||
|
|
||||||
int main(int argc __attribute__ ((__unused__)), char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *line, *s;
|
char *line, *s;
|
||||||
|
|
||||||
@ -119,7 +114,7 @@ int main(int argc __attribute__ ((__unused__)), char **argv)
|
|||||||
int execute_line(char *line)
|
int execute_line(char *line)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
COMMAND *command;
|
struct cmd *command;
|
||||||
char *word;
|
char *word;
|
||||||
|
|
||||||
/* Isolate the command word. */
|
/* Isolate the command word. */
|
||||||
@ -153,7 +148,7 @@ int execute_line(char *line)
|
|||||||
|
|
||||||
/* Look up NAME as the name of a command, and return a pointer to that
|
/* Look up NAME as the name of a command, and return a pointer to that
|
||||||
command. Return a NULL pointer if NAME isn't a command name. */
|
command. Return a NULL pointer if NAME isn't a command name. */
|
||||||
COMMAND *find_command(char *name)
|
struct cmd *find_command(char *name)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -288,7 +283,7 @@ int com_view(char *arg)
|
|||||||
return system(syscom);
|
return system(syscom);
|
||||||
}
|
}
|
||||||
|
|
||||||
int com_history(char *arg __attribute__ ((__unused__)))
|
int com_history(char *arg)
|
||||||
{
|
{
|
||||||
const char *he;
|
const char *he;
|
||||||
|
|
||||||
@ -301,7 +296,7 @@ int com_history(char *arg __attribute__ ((__unused__)))
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int com_rename(char *arg __attribute__ ((__unused__)))
|
int com_rename(char *arg)
|
||||||
{
|
{
|
||||||
too_dangerous("rename");
|
too_dangerous("rename");
|
||||||
return 1;
|
return 1;
|
||||||
@ -332,7 +327,7 @@ int com_stat(char *arg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int com_delete(char *arg __attribute__ ((__unused__)))
|
int com_delete(char *arg)
|
||||||
{
|
{
|
||||||
too_dangerous("delete");
|
too_dangerous("delete");
|
||||||
return 1;
|
return 1;
|
||||||
@ -387,7 +382,7 @@ int com_cd(char *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Print out the current working directory. */
|
/* Print out the current working directory. */
|
||||||
int com_pwd(char *ignore __attribute__ ((__unused__)))
|
int com_pwd(char *ignore)
|
||||||
{
|
{
|
||||||
char dir[1024], *s;
|
char dir[1024], *s;
|
||||||
|
|
||||||
@ -403,7 +398,7 @@ int com_pwd(char *ignore __attribute__ ((__unused__)))
|
|||||||
|
|
||||||
/* The user wishes to quit using this program. Just set DONE
|
/* The user wishes to quit using this program. Just set DONE
|
||||||
non-zero. */
|
non-zero. */
|
||||||
int com_quit(char *arg __attribute__ ((__unused__)))
|
int com_quit(char *arg)
|
||||||
{
|
{
|
||||||
done = 1;
|
done = 1;
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user