Changeset d752cf4 in mainline


Ignore:
Timestamp:
2009-01-22T07:13:13Z (15 years ago)
Author:
Tim Post <echo@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
491af07
Parents:
48c3d50
Message:

Eliminate 'restrict' from command structure, get rid of needless aliases.
Order of search is builtin → module → external, there is no need to
restrict commands to (non)interative shells only any longer.

Location:
uspace/app/bdsh
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/builtin_cmds.c

    r48c3d50 rd752cf4  
    4040
    4141extern volatile unsigned int cli_interactive;
    42 
    43 int builtin_is_restricted(int pos)
    44 {
    45         builtin_t *cmd = builtins;
    46         cmd += pos;
    47 
    48         if (cli_interactive && cmd->restricted <= 0)
    49                 return 0;
    50         if (!cli_interactive && cmd->restricted >= 0)
    51                 return 0;
    52 
    53         return 1;
    54 }
    5542
    5643int is_builtin(const char *command)
  • uspace/app/bdsh/cmds/builtins/builtin_aliases.h

    r48c3d50 rd752cf4  
    55
    66char *builtin_aliases[] = {
    7         "chdir", "cd",
    87        NULL, NULL
    98};
  • uspace/app/bdsh/cmds/builtins/cd/cd_def.h

    r48c3d50 rd752cf4  
    44        &cmd_cd,
    55        &help_cmd_cd,
    6         -1
    76},
    8 {
    9         "chdir",
    10         NULL,
    11         &cmd_cd,
    12         &help_cmd_cd,
    13         -1
    14 },
  • uspace/app/bdsh/cmds/cmds.h

    r48c3d50 rd752cf4  
    3737        mod_entry_t entry;  /* Command (exec) entry function */
    3838        mod_help_t help;    /* Command (help) entry function */
    39         int restricted;     /* Restricts to interactive/non-interactive only */
    4039} module_t;
    4140
  • uspace/app/bdsh/cmds/mod_cmds.c

    r48c3d50 rd752cf4  
    5353
    5454extern volatile unsigned int cli_interactive;
    55 
    56 int module_is_restricted(int pos)
    57 {
    58         /* Restriction Levels:
    59          * -1 -> Available only in interactive mode
    60          *  0 -> Available in any mode
    61          *  1 -> Available only in non-interactive mode */
    62 
    63         module_t *mod = modules;
    64         mod += pos;
    65         /* We're interactive, and the module is OK to run */
    66         if (cli_interactive && mod->restricted <= 0)
    67                 return 0;
    68         /* We're not interactive, and the module is OK to run */
    69         if (!cli_interactive && mod->restricted >= 0)
    70                 return 0;
    71 
    72         /* Anything else is just a big fat no :) */
    73         return 1;
    74 }
    7555
    7656/* Checks if an entry function matching command exists in modules[], if so
  • uspace/app/bdsh/cmds/modules/cat/cat_def.h

    r48c3d50 rd752cf4  
    44        &cmd_cat,
    55        &help_cmd_cat,
    6         0
    76},
    87
  • uspace/app/bdsh/cmds/modules/cp/cp_def.h

    r48c3d50 rd752cf4  
    44        &cmd_cp,
    55        &help_cmd_cp,
    6         0
    76},
    87
  • uspace/app/bdsh/cmds/modules/help/help.c

    r48c3d50 rd752cf4  
    134134        /* First, show a list of built in commands that are available in this mode */
    135135        for (cmd = builtins; cmd->name != NULL; cmd++, i++) {
    136                 if (!builtin_is_restricted(i)) {
    137136                        if (is_builtin_alias(cmd->name))
    138137                                printf("   %-16s\tAlias for `%s'\n", cmd->name,
     
    140139                        else
    141140                                printf("   %-16s\t%s\n", cmd->name, cmd->desc);
    142                 }
    143141        }
    144142
     
    147145        /* Now, show a list of module commands that are available in this mode */
    148146        for (mod = modules; mod->name != NULL; mod++, i++) {
    149                 if (!module_is_restricted(i)) {
    150147                        if (is_module_alias(mod->name))
    151148                                printf("   %-16s\tAlias for `%s'\n", mod->name,
     
    153150                        else
    154151                                printf("   %-16s\t%s\n", mod->name, mod->desc);
    155                 }
    156152        }
    157153
  • uspace/app/bdsh/cmds/modules/help/help_def.h

    r48c3d50 rd752cf4  
    44        &cmd_help,
    55        &help_cmd_help,
    6         0
    76},
  • uspace/app/bdsh/cmds/modules/ls/ls_def.h

    r48c3d50 rd752cf4  
    44        &cmd_ls,
    55        &help_cmd_ls,
    6         0
    76},
    8 
    9 {
    10         "dir",
    11         NULL,
    12         &cmd_ls,
    13         &help_cmd_ls,
    14         0
    15 },
    16 
  • uspace/app/bdsh/cmds/modules/mkdir/mkdir_def.h

    r48c3d50 rd752cf4  
    44        &cmd_mkdir,
    55        &help_cmd_mkdir,
    6         0
    76},
    87
    9 {
    10         "md",
    11         NULL,
    12         &cmd_mkdir,
    13         &help_cmd_mkdir,
    14         0
    15 },
    168
  • uspace/app/bdsh/cmds/modules/module_aliases.h

    r48c3d50 rd752cf4  
    1313
    1414char *mod_aliases[] = {
    15         "exit", "quit",
    16         "md", "mkdir",
    17         "del", "rm",
    18         "dir", "ls",
    1915        NULL, NULL
    2016};
  • uspace/app/bdsh/cmds/modules/pwd/pwd_def.h

    r48c3d50 rd752cf4  
    44        &cmd_pwd,
    55        &help_cmd_pwd,
    6         -1
    76},
  • uspace/app/bdsh/cmds/modules/quit/quit.c

    r48c3d50 rd752cf4  
    3535#include "cmds.h"
    3636
    37 static char *cmdname = "quit";
     37static char *cmdname = "exit";
    3838
    3939extern volatile unsigned int cli_quit;
  • uspace/app/bdsh/cmds/modules/quit/quit_def.h

    r48c3d50 rd752cf4  
    11{
    2         "quit",
    3         "Exit the console",
     2        "exit",
     3        "Exit the shell",
    44        &cmd_quit,
    55        &help_cmd_quit,
    6         -1
    76},
    8 {
    9         "exit",
    10         NULL,
    11         &cmd_quit,
    12         &help_cmd_quit,
    13         -1
    14 },
  • uspace/app/bdsh/cmds/modules/rm/rm_def.h

    r48c3d50 rd752cf4  
    44        &cmd_rm,
    55        &help_cmd_rm,
    6         0
    76},
    87
    9 {
    10         "del",
    11         NULL,
    12         &cmd_rm,
    13         &help_cmd_rm,
    14         0
    15 },
    16 
  • uspace/app/bdsh/cmds/modules/sleep/sleep_def.h

    r48c3d50 rd752cf4  
    44        &cmd_sleep,
    55        &help_cmd_sleep,
    6         0
    76},
    87
  • uspace/app/bdsh/cmds/modules/touch/touch_def.h

    r48c3d50 rd752cf4  
    44        &cmd_touch,
    55        &help_cmd_touch,
    6         0
    76},
    87
  • uspace/app/bdsh/input.c

    r48c3d50 rd752cf4  
    7373        tmp = cli_strdup(usr->line);
    7474
    75         /* Break up what the user typed, space delimited */
    76 
    77         /* TODO: Protect things in quotes / ticks, expand wildcards */
    7875        cmd[n] = cli_strtok(tmp, " ");
    7976        while (cmd[n] && n < WORD_MAX) {
     
    8784        }
    8885
    89         /* Its a builtin command */
     86        /* Its a builtin command ? */
    9087        if ((i = (is_builtin(cmd[0]))) > -1) {
    91                 /* Its not available in this mode, see what try_exec() thinks */
    92                 if (builtin_is_restricted(i)) {
    93                                 rc = try_exec(cmd[0], cmd);
    94                                 if (rc)
    95                                         /* No external matching it could be found, tell the
    96                                          * user that the command does exist, but is not
    97                                          * available in this mode. */
    98                                         cli_restricted(cmd[0]);
    99                                 goto finit;
    100                 }
    101                 /* Its a builtin, its available, run it */
    10288                rc = run_builtin(i, cmd, usr);
    10389                goto finit;
    104         /* We repeat the same dance for modules */
     90        /* Its a module ? */
    10591        } else if ((i = (is_module(cmd[0]))) > -1) {
    106                 if (module_is_restricted(i)) {
    107                         rc = try_exec(cmd[0], cmd);
    108                         if (rc)
    109                                 cli_restricted(cmd[0]);
    110                         goto finit;
    111                 }
    11292                rc = run_module(i, cmd);
    11393                goto finit;
    114         } else {
    115                 /* Its not a module or builtin, restricted or otherwise.
    116                  * See what try_exec() thinks of it and just pass its return
    117                  * value back to the caller */
    118                 rc = try_exec(cmd[0], cmd);
    119                 goto finit;
    12094        }
     95
     96        /* See what try_exec thinks of it */
     97        rc = try_exec(cmd[0], cmd);
    12198
    12299finit:
Note: See TracChangeset for help on using the changeset viewer.