Subversion Repositories HelenOS

Rev

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

Rev 3366 Rev 3372
Line 41... Line 41...
41
#include "errors.h"
41
#include "errors.h"
42
#include "exec.h"
42
#include "exec.h"
43
 
43
 
44
extern volatile unsigned int cli_interactive;
44
extern volatile unsigned int cli_interactive;
45
 
45
 
-
 
46
/* Not exposed in input.h */
-
 
47
static void cli_restricted(char *);
-
 
48
static void read_line(char *, int);
-
 
49
 
46
/* More than a macro than anything */
50
/* More than a macro than anything */
47
void cli_restricted(char *cmd)
51
static void cli_restricted(char *cmd)
48
{
52
{
49
    printf("%s is not available in %s mode\n", cmd,
53
    printf("%s is not available in %s mode\n", cmd,
50
        cli_interactive ? "interactive" : "non-interactive");
54
        cli_interactive ? "interactive" : "non-interactive");
51
 
55
 
52
    return;
56
    return;
Line 79... Line 83...
79
    if (NULL == cmd[0]) {
83
    if (NULL == cmd[0]) {
80
        rc = CL_ENOENT;
84
        rc = CL_ENOENT;
81
        goto finit;
85
        goto finit;
82
    }
86
    }
83
 
87
 
84
    /* Check what kind of command argv[0] might be, TODO: move this to
-
 
85
     * a function */
88
    /* Its a builtin command */
86
    if ((i = (is_builtin(cmd[0]))) > -1) {
89
    if ((i = (is_builtin(cmd[0]))) > -1) {
-
 
90
        /* Its not available in this mode, see what try_exec() thinks */
87
        if (builtin_is_restricted(i)) {
91
        if (builtin_is_restricted(i)) {
88
                rc = try_exec(cmd[0], cmd);
92
                rc = try_exec(cmd[0], cmd);
89
                if (rc)
93
                if (rc)
-
 
94
                    /* No external matching it could be found, tell the
-
 
95
                     * user that the command does exist, but is not
-
 
96
                     * available in this mode. */
90
                    cli_restricted(cmd[0]);
97
                    cli_restricted(cmd[0]);
91
                goto finit;
98
                goto finit;
92
        }
99
        }
-
 
100
        /* Its a builtin, its available, run it */
93
        rc = run_builtin(i, cmd, usr);
101
        rc = run_builtin(i, cmd, usr);
94
        goto finit;
102
        goto finit;
-
 
103
    /* We repeat the same dance for modules */
95
    } else if ((i = (is_module(cmd[0]))) > -1) {
104
    } else if ((i = (is_module(cmd[0]))) > -1) {
96
        if (module_is_restricted(i)) {
105
        if (module_is_restricted(i)) {
97
            rc = try_exec(cmd[0], cmd);
106
            rc = try_exec(cmd[0], cmd);
98
            if (rc)
107
            if (rc)
99
                cli_restricted(cmd[0]);
108
                cli_restricted(cmd[0]);
100
            goto finit;
109
            goto finit;
101
        }
110
        }
102
        rc = run_module(i, cmd);
111
        rc = run_module(i, cmd);
103
        goto finit;
112
        goto finit;
104
    } else {
113
    } else {
-
 
114
        /* Its not a module or builtin, restricted or otherwise.
-
 
115
         * See what try_exec() thinks of it and just pass its return
-
 
116
         * value back to the caller */
105
        rc = try_exec(cmd[0], cmd);
117
        rc = try_exec(cmd[0], cmd);
106
        goto finit;
118
        goto finit;
107
    }
119
    }
108
 
120
 
109
finit:
121
finit:
Line 116... Line 128...
116
 
128
 
117
    return rc;
129
    return rc;
118
}
130
}
119
 
131
 
120
/* Borrowed from Jiri Svoboda's 'cli' uspace app */
132
/* Borrowed from Jiri Svoboda's 'cli' uspace app */
121
void read_line(char *buffer, int n)
133
static void read_line(char *buffer, int n)
122
{
134
{
123
    char c;
135
    char c;
124
    int chars;
136
    int chars;
125
 
137
 
126
    chars = 0;
138
    chars = 0;
Line 142... Line 154...
142
    }
154
    }
143
    putchar('\n');
155
    putchar('\n');
144
    buffer[chars] = '\0';
156
    buffer[chars] = '\0';
145
}
157
}
146
 
158
 
-
 
159
/* TODO:
-
 
160
 * Implement something like editline() / readline(), if even
-
 
161
 * just for command history and making arrows work. */
147
void get_input(cliuser_t *usr)
162
void get_input(cliuser_t *usr)
148
{
163
{
149
    char line[INPUT_MAX];
164
    char line[INPUT_MAX];
150
    size_t len = 0;
165
    size_t len = 0;
151
 
166