Subversion Repositories HelenOS

Rev

Rev 4338 | Rev 4344 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4338 Rev 4341
Line 40... Line 40...
40
#include "scli.h"
40
#include "scli.h"
41
#include "input.h"
41
#include "input.h"
42
#include "errors.h"
42
#include "errors.h"
43
#include "exec.h"
43
#include "exec.h"
44
 
44
 
45
extern volatile unsigned int cli_interactive;
-
 
46
 
-
 
47
/* Not exposed in input.h */
-
 
48
static void cli_restricted(char *);
-
 
49
static void read_line(char *, int);
45
static void read_line(char *, int);
50
 
46
 
51
/* More than a macro than anything */
-
 
52
static void cli_restricted(char *cmd)
-
 
53
{
-
 
54
    printf("%s is not available in %s mode\n", cmd,
-
 
55
        cli_interactive ? "interactive" : "non-interactive");
-
 
56
 
-
 
57
    return;
-
 
58
}
-
 
59
 
-
 
60
/* Tokenizes input from console, sees if the first word is a built-in, if so
47
/* Tokenizes input from console, sees if the first word is a built-in, if so
61
 * invokes the built-in entry point (a[0]) passing all arguments in a[] to
48
 * invokes the built-in entry point (a[0]) passing all arguments in a[] to
62
 * the handler */
49
 * the handler */
63
int tok_input(cliuser_t *usr)
50
int tok_input(cliuser_t *usr)
64
{
51
{
Line 68... Line 55...
68
    char *tmp;
55
    char *tmp;
69
 
56
 
70
    if (NULL == usr->line)
57
    if (NULL == usr->line)
71
        return CL_EFAIL;
58
        return CL_EFAIL;
72
 
59
 
73
    tmp = cli_strdup(usr->line);
60
    tmp = strdup(usr->line);
74
 
61
 
75
    /* Break up what the user typed, space delimited */
-
 
76
 
-
 
77
    /* TODO: Protect things in quotes / ticks, expand wildcards */
-
 
78
    cmd[n] = cli_strtok(tmp, " ");
62
    cmd[n] = strtok(tmp, " ");
79
    while (cmd[n] && n < WORD_MAX) {
63
    while (cmd[n] && n < WORD_MAX) {
80
        cmd[++n] = cli_strtok(NULL, " ");
64
        cmd[++n] = strtok(NULL, " ");
81
    }
65
    }
82
 
66
 
83
    /* We have rubbish */
67
    /* We have rubbish */
84
    if (NULL == cmd[0]) {
68
    if (NULL == cmd[0]) {
85
        rc = CL_ENOENT;
69
        rc = CL_ENOENT;
86
        goto finit;
70
        goto finit;
87
    }
71
    }
88
 
72
 
89
    /* Its a builtin command */
73
    /* Its a builtin command ? */
90
    if ((i = (is_builtin(cmd[0]))) > -1) {
74
    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 */
-
 
102
        rc = run_builtin(i, cmd, usr);
75
        rc = run_builtin(i, cmd, usr);
103
        goto finit;
76
        goto finit;
104
    /* We repeat the same dance for modules */
77
    /* Its a module ? */
105
    } else if ((i = (is_module(cmd[0]))) > -1) {
78
    } 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
        }
-
 
112
        rc = run_module(i, cmd);
79
        rc = run_module(i, cmd);
113
        goto finit;
80
        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;
-
 
120
    }
81
    }
121
 
82
 
-
 
83
    /* See what try_exec thinks of it */
-
 
84
    rc = try_exec(cmd[0], cmd);
-
 
85
 
122
finit:
86
finit:
123
    if (NULL != usr->line) {
87
    if (NULL != usr->line) {
124
        free(usr->line);
88
        free(usr->line);
125
        usr->line = (char *) NULL;
89
        usr->line = (char *) NULL;
126
    }
90
    }
Line 172... Line 136...
172
    read_line(line, INPUT_MAX);
136
    read_line(line, INPUT_MAX);
173
    len = strlen(line);
137
    len = strlen(line);
174
    /* Make sure we don't have rubbish or a C/R happy user */
138
    /* Make sure we don't have rubbish or a C/R happy user */
175
    if (len == 0 || line[0] == '\n')
139
    if (len == 0 || line[0] == '\n')
176
        return;
140
        return;
177
    usr->line = cli_strdup(line);
141
    usr->line = strdup(line);
178
 
142
 
179
    return;
143
    return;
180
}
144
}
181
 
145