Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3808 → Rev 3809

/trunk/uspace/app/bdsh/input.c
72,9 → 72,6
 
tmp = cli_strdup(usr->line);
 
/* Break up what the user typed, space delimited */
 
/* TODO: Protect things in quotes / ticks, expand wildcards */
cmd[n] = cli_strtok(tmp, " ");
while (cmd[n] && n < WORD_MAX) {
cmd[++n] = cli_strtok(NULL, " ");
86,39 → 83,19
goto finit;
}
 
/* Its a builtin command */
/* Its a builtin command ? */
if ((i = (is_builtin(cmd[0]))) > -1) {
/* Its not available in this mode, see what try_exec() thinks */
if (builtin_is_restricted(i)) {
rc = try_exec(cmd[0], cmd);
if (rc)
/* No external matching it could be found, tell the
* user that the command does exist, but is not
* available in this mode. */
cli_restricted(cmd[0]);
goto finit;
}
/* Its a builtin, its available, run it */
rc = run_builtin(i, cmd, usr);
goto finit;
/* We repeat the same dance for modules */
/* Its a module ? */
} else if ((i = (is_module(cmd[0]))) > -1) {
if (module_is_restricted(i)) {
rc = try_exec(cmd[0], cmd);
if (rc)
cli_restricted(cmd[0]);
goto finit;
}
rc = run_module(i, cmd);
goto finit;
} else {
/* Its not a module or builtin, restricted or otherwise.
* See what try_exec() thinks of it and just pass its return
* value back to the caller */
rc = try_exec(cmd[0], cmd);
goto finit;
}
 
/* See what try_exec thinks of it */
rc = try_exec(cmd[0], cmd);
 
finit:
if (NULL != usr->line) {
free(usr->line);
/trunk/uspace/app/bdsh/cmds/mod_cmds.c
53,26 → 53,6
 
extern volatile unsigned int cli_interactive;
 
int module_is_restricted(int pos)
{
/* Restriction Levels:
* -1 -> Available only in interactive mode
* 0 -> Available in any mode
* 1 -> Available only in non-interactive mode */
 
module_t *mod = modules;
mod += pos;
/* We're interactive, and the module is OK to run */
if (cli_interactive && mod->restricted <= 0)
return 0;
/* We're not interactive, and the module is OK to run */
if (!cli_interactive && mod->restricted >= 0)
return 0;
 
/* Anything else is just a big fat no :) */
return 1;
}
 
/* Checks if an entry function matching command exists in modules[], if so
* its position in the array is returned */
int is_module(const char *command)
/trunk/uspace/app/bdsh/cmds/modules/cp/cp_def.h
3,6 → 3,5
"Copy files and directories",
&cmd_cp,
&help_cmd_cp,
0
},
 
/trunk/uspace/app/bdsh/cmds/modules/quit/quit.c
34,7 → 34,7
#include "quit.h"
#include "cmds.h"
 
static char *cmdname = "quit";
static char *cmdname = "exit";
 
extern volatile unsigned int cli_quit;
extern const char *progname;
/trunk/uspace/app/bdsh/cmds/modules/quit/quit_def.h
1,14 → 1,6
{
"quit",
"Exit the console",
&cmd_quit,
&help_cmd_quit,
-1
},
{
"exit",
NULL,
"Exit the shell",
&cmd_quit,
&help_cmd_quit,
-1
},
/trunk/uspace/app/bdsh/cmds/modules/touch/touch_def.h
3,6 → 3,5
"Create files or update access times",
&cmd_touch,
&help_cmd_touch,
0
},
 
/trunk/uspace/app/bdsh/cmds/modules/mkdir/mkdir_def.h
3,14 → 3,6
"Create new directories",
&cmd_mkdir,
&help_cmd_mkdir,
0
},
 
{
"md",
NULL,
&cmd_mkdir,
&help_cmd_mkdir,
0
},
 
/trunk/uspace/app/bdsh/cmds/modules/cat/cat_def.h
3,6 → 3,5
"Show the contents of a file",
&cmd_cat,
&help_cmd_cat,
0
},
 
/trunk/uspace/app/bdsh/cmds/modules/help/help.c
133,13 → 133,11
 
/* First, show a list of built in commands that are available in this mode */
for (cmd = builtins; cmd->name != NULL; cmd++, i++) {
if (!builtin_is_restricted(i)) {
if (is_builtin_alias(cmd->name))
printf(" %-16s\tAlias for `%s'\n", cmd->name,
alias_for_builtin(cmd->name));
else
printf(" %-16s\t%s\n", cmd->name, cmd->desc);
}
}
 
i = 0;
146,13 → 144,11
 
/* Now, show a list of module commands that are available in this mode */
for (mod = modules; mod->name != NULL; mod++, i++) {
if (!module_is_restricted(i)) {
if (is_module_alias(mod->name))
printf(" %-16s\tAlias for `%s'\n", mod->name,
alias_for_module(mod->name));
else
printf(" %-16s\t%s\n", mod->name, mod->desc);
}
}
 
printf("\n Try %s %s for more information on how `%s' works.\n\n",
/trunk/uspace/app/bdsh/cmds/modules/help/help_def.h
3,5 → 3,4
"Show help for commands",
&cmd_help,
&help_cmd_help,
0
},
/trunk/uspace/app/bdsh/cmds/modules/sleep/sleep_def.h
3,6 → 3,5
"Pause for given time interval (in seconds)",
&cmd_sleep,
&help_cmd_sleep,
0
},
 
/trunk/uspace/app/bdsh/cmds/modules/pwd/pwd_def.h
3,5 → 3,4
"Prints the current working directory",
&cmd_pwd,
&help_cmd_pwd,
-1
},
/trunk/uspace/app/bdsh/cmds/modules/module_aliases.h
12,10 → 12,6
* the entry point being reached. */
 
char *mod_aliases[] = {
"exit", "quit",
"md", "mkdir",
"del", "rm",
"dir", "ls",
NULL, NULL
};
 
/trunk/uspace/app/bdsh/cmds/modules/ls/ls_def.h
3,14 → 3,4
"List files and directories",
&cmd_ls,
&help_cmd_ls,
0
},
 
{
"dir",
NULL,
&cmd_ls,
&help_cmd_ls,
0
},
 
/trunk/uspace/app/bdsh/cmds/modules/rm/rm_def.h
3,14 → 3,5
"Remove files and directories",
&cmd_rm,
&help_cmd_rm,
0
},
 
{
"del",
NULL,
&cmd_rm,
&help_cmd_rm,
0
},
 
/trunk/uspace/app/bdsh/cmds/builtins/cd/cd_def.h
3,12 → 3,4
"Change the current working directory",
&cmd_cd,
&help_cmd_cd,
-1
},
{
"chdir",
NULL,
&cmd_cd,
&help_cmd_cd,
-1
},
/trunk/uspace/app/bdsh/cmds/builtins/builtin_aliases.h
4,7 → 4,6
/* See modules/module_aliases.h for an explanation of this file */
 
char *builtin_aliases[] = {
"chdir", "cd",
NULL, NULL
};
 
/trunk/uspace/app/bdsh/cmds/cmds.h
36,7 → 36,6
char *desc; /* Description of the command */
mod_entry_t entry; /* Command (exec) entry function */
mod_help_t help; /* Command (help) entry function */
int restricted; /* Restricts to interactive/non-interactive only */
} module_t;
 
/* Builtin structure, same as modules except different types of entry points */
/trunk/uspace/app/bdsh/cmds/builtin_cmds.c
40,19 → 40,6
 
extern volatile unsigned int cli_interactive;
 
int builtin_is_restricted(int pos)
{
builtin_t *cmd = builtins;
cmd += pos;
 
if (cli_interactive && cmd->restricted <= 0)
return 0;
if (!cli_interactive && cmd->restricted >= 0)
return 0;
 
return 1;
}
 
int is_builtin(const char *command)
{
builtin_t *cmd;