00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <stdio.h>
00035 #include <stdlib.h>
00036 #include <str.h>
00037 #include "errors.h"
00038 #include "cmds.h"
00039 #include "builtin_aliases.h"
00040
00041 extern volatile unsigned int cli_interactive;
00042
00043 int is_builtin(const char *command)
00044 {
00045 builtin_t *cmd;
00046 unsigned int i = 0;
00047
00048 if (NULL == command)
00049 return -2;
00050
00051 for (cmd = builtins; cmd->name != NULL; cmd++, i++) {
00052 if (!str_cmp(cmd->name, command))
00053 return i;
00054 }
00055
00056 return -1;
00057 }
00058
00059 int is_builtin_alias(const char *command)
00060 {
00061 unsigned int i = 0;
00062
00063 if (NULL == command)
00064 return -1;
00065
00066 for(i=0; builtin_aliases[i] != NULL; i+=2) {
00067 if (!str_cmp(builtin_aliases[i], command))
00068 return 1;
00069 }
00070
00071 return 0;
00072 }
00073
00074 char *alias_for_builtin(const char *command)
00075 {
00076 unsigned int i = 0;
00077
00078 if (NULL == command)
00079 return (char *)NULL;
00080
00081 for(i=0; builtin_aliases[i] != NULL; i++) {
00082 if (!str_cmp(builtin_aliases[i], command))
00083 return (char *)builtin_aliases[++i];
00084 i++;
00085 }
00086
00087 return (char *)NULL;
00088 }
00089
00090 int help_builtin(int builtin, unsigned int extended)
00091 {
00092 builtin_t *cmd = builtins;
00093
00094 cmd += builtin;
00095
00096 if (NULL != cmd->help) {
00097 cmd->help(extended);
00098 return CL_EOK;
00099 } else
00100 return CL_ENOENT;
00101 }
00102
00103 int run_builtin(int builtin, char *argv[], cliuser_t *usr)
00104 {
00105 builtin_t *cmd = builtins;
00106
00107 cmd += builtin;
00108
00109 if (NULL != cmd->entry)
00110 return((int)cmd->entry(argv, usr));
00111
00112 return CL_ENOENT;
00113 }