/branches/dynload/uspace/app/bdsh/input.c |
---|
34,6 → 34,10 |
#include <string.h> |
#include <io/stream.h> |
#include <console.h> |
#include <kbd/kbd.h> |
#include <kbd/keycode.h> |
#include <errno.h> |
#include <bool.h> |
#include "config.h" |
#include "util.h" |
57,7 → 61,7 |
if (NULL == usr->line) |
return CL_EFAIL; |
tmp = strdup(usr->line); |
tmp = str_dup(usr->line); |
cmd[n] = strtok(tmp, " "); |
while (cmd[n] && n < WORD_MAX) { |
96,30 → 100,44 |
static void read_line(char *buffer, int n) |
{ |
char c; |
int chars; |
kbd_event_t ev; |
size_t offs, otmp; |
wchar_t dec; |
chars = 0; |
while (chars < n - 1) { |
c = getchar(); |
if (c < 0) |
offs = 0; |
while (true) { |
fflush(stdout); |
if (kbd_get_event(&ev) < 0) |
return; |
if (c == '\n') |
if (ev.type == KE_RELEASE) |
continue; |
if (ev.key == KC_ENTER || ev.key == KC_NENTER) |
break; |
if (c == '\b') { |
if (chars > 0) { |
if (ev.key == KC_BACKSPACE) { |
if (offs > 0) { |
/* |
* Back up until we reach valid start of |
* character. |
*/ |
while (offs > 0) { |
--offs; otmp = offs; |
dec = str_decode(buffer, &otmp, n); |
if (dec != U_SPECIAL) |
break; |
} |
putchar('\b'); |
--chars; |
} |
continue; |
} |
if (c >= ' ') { |
putchar(c); |
buffer[chars++] = c; |
if (ev.c >= ' ') { |
//putchar(ev.c); |
if (chr_encode(ev.c, buffer, &offs, n - 1) == EOK) |
console_putchar(ev.c); |
} |
} |
putchar('\n'); |
buffer[chars] = '\0'; |
buffer[offs] = '\0'; |
} |
/* TODO: |
128,7 → 146,6 |
void get_input(cliuser_t *usr) |
{ |
char line[INPUT_MAX]; |
size_t len = 0; |
console_set_style(STYLE_EMPHASIS); |
printf("%s", usr->prompt); |
135,11 → 152,10 |
console_set_style(STYLE_NORMAL); |
read_line(line, INPUT_MAX); |
len = strlen(line); |
/* Make sure we don't have rubbish or a C/R happy user */ |
if (len == 0 || line[0] == '\n') |
if (str_cmp(line, "") == 0 || str_cmp(line, "\n") == 0) |
return; |
usr->line = strdup(line); |
usr->line = str_dup(line); |
return; |
} |
/branches/dynload/uspace/app/bdsh/cmds/mod_cmds.c |
---|
64,7 → 64,7 |
return -2; |
for (mod = modules; mod->name != NULL; mod++, i++) { |
if (!strcmp(mod->name, command)) |
if (!str_cmp(mod->name, command)) |
return i; |
} |
81,7 → 81,7 |
return -1; |
for(i=0; mod_aliases[i] != NULL; i+=2) { |
if (!strcmp(mod_aliases[i], command)) |
if (!str_cmp(mod_aliases[i], command)) |
return 1; |
} |
97,7 → 97,7 |
return (char *)NULL; |
for(i=0; mod_aliases[i] != NULL; i++) { |
if (!strcmp(mod_aliases[i], command)) |
if (!str_cmp(mod_aliases[i], command)) |
return (char *)mod_aliases[++i]; |
i++; |
} |
/branches/dynload/uspace/app/bdsh/cmds/modules/touch/touch.c |
---|
80,7 → 80,7 |
} |
for (i = 1; i < argc; i ++) { |
buff = strdup(argv[i]); |
buff = str_dup(argv[i]); |
dirp = opendir(buff); |
if (dirp) { |
cli_error(CL_ENOTSUP, "%s is a directory", buff); |
/branches/dynload/uspace/app/bdsh/cmds/modules/mkdir/mkdir.c |
---|
93,7 → 93,7 |
/* Its a good idea to allocate path, plus we (may) need a copy of |
* path to tokenize if parents are specified */ |
if (NULL == (tmp = strdup(path))) { |
if (NULL == (tmp = str_dup(path))) { |
cli_error(CL_ENOMEM, "%s: path too big?", cmdname); |
return 1; |
} |
149,7 → 149,7 |
while (dirs[i] != NULL) { |
/* Sometimes make or scripts conjoin odd paths. Account for something |
* like this: ../../foo/bar/../foo/foofoo/./bar */ |
if (!strcmp(dirs[i], "..") || !strcmp(dirs[i], ".")) { |
if (!str_cmp(dirs[i], "..") || !str_cmp(dirs[i], ".")) { |
if (0 != (chdir(dirs[i]))) { |
cli_error(CL_EFAIL, "%s: impossible path: %s", |
cmdname, path); |
/branches/dynload/uspace/app/bdsh/cmds/modules/help/help.c |
---|
107,7 → 107,7 |
} |
if (argc == 3) { |
if (!strcmp("extended", argv[2])) |
if (!str_cmp("extended", argv[2])) |
level = HELP_LONG; |
else |
level = HELP_SHORT; |
/branches/dynload/uspace/app/bdsh/cmds/modules/ls/ls.c |
---|
182,7 → 182,7 |
if (argc == 1) |
getcwd(buff, PATH_MAX); |
else |
strncpy(buff, argv[1], PATH_MAX); |
str_cpy(buff, PATH_MAX, argv[1]); |
scope = ls_scope(buff); |
/branches/dynload/uspace/app/bdsh/cmds/modules/rm/rm.c |
---|
216,7 → 216,7 |
i = optind; |
while (NULL != argv[i]) { |
len = strlen(argv[i]) + 2; |
len = str_size(argv[i]) + 2; |
buff = (char *) realloc(buff, len); |
if (buff == NULL) { |
printf("rm: out of memory\n"); |
/branches/dynload/uspace/app/bdsh/cmds/builtin_cmds.c |
---|
49,7 → 49,7 |
return -2; |
for (cmd = builtins; cmd->name != NULL; cmd++, i++) { |
if (!strcmp(cmd->name, command)) |
if (!str_cmp(cmd->name, command)) |
return i; |
} |
64,7 → 64,7 |
return -1; |
for(i=0; builtin_aliases[i] != NULL; i+=2) { |
if (!strcmp(builtin_aliases[i], command)) |
if (!str_cmp(builtin_aliases[i], command)) |
return 1; |
} |
79,7 → 79,7 |
return (char *)NULL; |
for(i=0; builtin_aliases[i] != NULL; i++) { |
if (!strcmp(builtin_aliases[i], command)) |
if (!str_cmp(builtin_aliases[i], command)) |
return (char *)builtin_aliases[++i]; |
i++; |
} |
/branches/dynload/uspace/app/bdsh/exec.c |
---|
71,7 → 71,7 |
char *path_tok; |
char *path[PATH_MAX]; |
int n = 0, i = 0; |
size_t x = strlen(cmd) + 2; |
size_t x = str_size(cmd) + 2; |
found = (char *)malloc(PATH_MAX); |
80,12 → 80,12 |
return (char *) cmd; |
} |
path_tok = strdup(PATH); |
path_tok = str_dup(PATH); |
/* Extract the PATH env to a path[] array */ |
path[n] = strtok(path_tok, PATH_DELIM); |
while (NULL != path[n]) { |
if ((strlen(path[n]) + x ) > PATH_MAX) { |
if ((str_size(path[n]) + x ) > PATH_MAX) { |
cli_error(CL_ENOTSUP, |
"Segment %d of path is too large, search ends at segment %d", |
n, n-1); |
114,7 → 114,7 |
task_id_t tid; |
char *tmp; |
tmp = strdup(find_command(cmd)); |
tmp = str_dup(find_command(cmd)); |
free(found); |
tid = task_spawn((const char *)tmp, argv); |