/branches/dd/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/dd/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/dd/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/dd/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/dd/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/dd/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/dd/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/dd/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/dd/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); |
/branches/dd/uspace/app/tester/tester.c |
---|
47,6 → 47,7 |
test_t tests[] = { |
#include "thread/thread1.def" |
#include "print/print1.def" |
#include "print/print4.def" |
#include "fault/fault1.def" |
#include "fault/fault2.def" |
#include "ipc/register.def" |
/branches/dd/uspace/app/tester/devmap/devmap1.c |
---|
140,7 → 140,7 |
req = async_send_2(phone, DEVMAP_DRIVER_REGISTER, 0, 0, &answer); |
retval = ipc_data_write_start(phone, (char *)name, strlen(name) + 1); |
retval = ipc_data_write_start(phone, (char *)name, str_size(name) + 1); |
if (retval != EOK) { |
async_wait_for(req, NULL); |
173,7 → 173,7 |
req = async_send_2(driver_phone, DEVMAP_DEVICE_GET_HANDLE, 0, 0, |
&answer); |
retval = ipc_data_write_start(driver_phone, name, strlen(name) + 1); |
retval = ipc_data_write_start(driver_phone, name, str_size(name) + 1); |
if (retval != EOK) { |
printf("Failed to send device name '%s'.\n", name); |
215,7 → 215,7 |
req = async_send_2(driver_phone, DEVMAP_DEVICE_REGISTER, 0, 0, &answer); |
retval = ipc_data_write_start(driver_phone, (char *)name, |
strlen(name) + 1); |
str_size(name) + 1); |
if (retval != EOK) { |
printf("Failed to send device name '%s'.\n", name); |
/branches/dd/uspace/app/tester/print/print4.c |
---|
0,0 → 1,92 |
/* |
* Copyright (c) 2009 Martin Decky |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#include <stdio.h> |
#include <unistd.h> |
#include "../tester.h" |
#define PRIx8 "x" |
char *test_print4(bool quiet) |
{ |
if (!quiet) { |
printf("ASCII printable characters (32 - 127) using printf(\"%%c\") and printf(\"%%lc\"):\n"); |
uint8_t group; |
for (group = 1; group < 4; group++) { |
printf("%#" PRIx8 ": ", group << 5); |
uint8_t index; |
for (index = 0; index < 32; index++) |
printf("%c", (char) ((group << 5) + index)); |
printf(" "); |
for (index = 0; index < 32; index++) |
printf("%lc", (wchar_t) ((group << 5) + index)); |
printf("\n"); |
} |
printf("\nExtended ASCII characters (128 - 255) using printf(\"%%lc\"):\n"); |
for (group = 4; group < 8; group++) { |
printf("%#" PRIx8 ": ", group << 5); |
uint8_t index; |
for (index = 0; index < 32; index++) |
printf("%lc", (wchar_t) ((group << 5) + index)); |
printf("\n"); |
} |
printf("\nUTF-8 strings using printf(\"%%s\"):\n"); |
printf("English: %s\n", "Quick brown fox jumps over the lazy dog"); |
printf("Czech: %s\n", "Příliš žluťoučký kůň úpěl ďábelské ódy"); |
printf("Greek: %s\n", "á½® ξεῖν’, ἀγγÎλλειν Λακεδαιμονίοις ὅτι τῇδε"); |
printf("Hebrew: %s\n", "משוואת ברנולי היא משוואה בהידרודינמיקה"); |
printf("Arabic: %s\n", "التوزيع الجغرافي للحمل العنقودي"); |
printf("Russian: %s\n", "Леннон познакомился с художницей-авангардисткой"); |
printf("Armenian: %s\n", "ÕÕ¯Õ½Õ¥Ö Õ°Ö€Õ¡Õ¿Õ¡Ö€Õ¡Õ¯Õ¾Õ¥Õ¬ ÔµÖ€Õ¸Ö‚Õ½Õ¡Õ²Õ¥Õ´Õ« Õ°Õ¡ÕµÕ¯Õ¡Õ¯Õ¡Õ¶"); |
printf("\nUTF-32 strings using printf(\"%%ls\"):\n"); |
printf("English: %ls\n", L"Quick brown fox jumps over the lazy dog"); |
printf("Czech: %ls\n", L"Příliš žluťoučký kůň úpěl ďábelské ódy"); |
printf("Greek: %ls\n", L"á½® ξεῖν’, ἀγγÎλλειν Λακεδαιμονίοις ὅτι τῇδε"); |
printf("Hebrew: %ls\n", L"משוואת ברנולי היא משוואה בהידרודינמיקה"); |
printf("Arabic: %ls\n", L"التوزيع الجغرافي للحمل العنقودي"); |
printf("Russian: %ls\n", L"Леннон познакомился с художницей-авангардисткой"); |
printf("Armenian: %ls\n", L"ÕÕ¯Õ½Õ¥Ö Õ°Ö€Õ¡Õ¿Õ¡Ö€Õ¡Õ¯Õ¾Õ¥Õ¬ ÔµÖ€Õ¸Ö‚Õ½Õ¡Õ²Õ¥Õ´Õ« Õ°Õ¡ÕµÕ¯Õ¡Õ¯Õ¡Õ¶"); |
printf("Test: [%d] '%lc'\n", L'\x0161', L'\x0161'); |
} |
printf("[Press a key]\n"); |
getchar(); |
return NULL; |
} |
Property changes: |
Added: svn:mergeinfo |
/branches/dd/uspace/app/tester/print/print4.def |
---|
0,0 → 1,6 |
{ |
"print4", |
"Unicode test", |
&test_print4, |
true |
}, |
Property changes: |
Added: svn:mergeinfo |
/branches/dd/uspace/app/tester/tester.h |
---|
60,6 → 60,7 |
extern char * test_thread1(bool quiet); |
extern char * test_print1(bool quiet); |
extern char * test_print4(bool quiet); |
extern char * test_fault1(bool quiet); |
extern char * test_fault2(bool quiet); |
extern char * test_register(bool quiet); |
/branches/dd/uspace/app/tester/Makefile |
---|
45,6 → 45,7 |
SOURCES = tester.c \ |
thread/thread1.c \ |
print/print1.c \ |
print/print4.c \ |
fault/fault1.c \ |
fault/fault2.c \ |
ipc/register.c \ |
/branches/dd/uspace/app/tetris/scores.c |
---|
55,6 → 55,9 |
#include <stdio.h> |
/* #include <stdlib.h> */ |
#include <string.h> |
#include <kbd/kbd.h> |
#include <kbd/keycode.h> |
#include <stdlib.h> |
/* #include <time.h> */ |
/* #include <term.h> */ |
/* #include <unistd.h> */ |
114,7 → 117,8 |
*/ |
static void copyhiscore(int dest, int src) |
{ |
strcpy(scores[dest].hs_name, scores[src].hs_name); |
str_cpy(scores[dest].hs_name, STR_BOUNDS(MAXLOGNAME) + 1, |
scores[src].hs_name); |
scores[dest].hs_score = scores[src].hs_score; |
scores[dest].hs_level = scores[src].hs_level; |
} |
122,32 → 126,58 |
void insertscore(int score, int level) |
{ |
int i,j; |
int key; |
size_t off; |
kbd_event_t ev; |
clear_screen(); |
moveto(10 , 10); |
puts("Insert your name: "); |
strncpy(scores[NUMSPOTS - 1].hs_name, "Player", MAXLOGNAME); |
i = 6; |
str_cpy(scores[NUMSPOTS - 1].hs_name, STR_BOUNDS(MAXLOGNAME) + 1, |
"Player"); |
i = 6; off = 6; |
moveto(10 , 28); |
printf("%s%.*s",scores[NUMSPOTS - 1].hs_name,MAXLOGNAME-i,"........................................"); |
key = getchar(); |
while(key != '\n') { |
if (key == '\b') { |
if (i > 0) |
scores[NUMSPOTS - 1].hs_name[--i] = '\0'; |
} else { |
if (i < (MAXLOGNAME - 1)) |
scores[NUMSPOTS - 1].hs_name[i++] = key; |
scores[NUMSPOTS - 1].hs_name[i] = '\0'; |
while (1) { |
fflush(stdout); |
if (kbd_get_event(&ev) != EOK) |
exit(1); |
if (ev.type == KE_RELEASE) |
continue; |
if (ev.key == KC_ENTER || ev.key == KC_NENTER) |
break; |
if (ev.key == KC_BACKSPACE) { |
if (i > 0) { |
wchar_t uc; |
--i; |
while (off > 0) { |
--off; |
size_t otmp = off; |
uc = str_decode(scores[NUMSPOTS - 1].hs_name, |
&otmp, STR_BOUNDS(MAXLOGNAME) + 1); |
if (uc != U_SPECIAL) |
break; |
} |
scores[NUMSPOTS - 1].hs_name[off] = '\0'; |
} |
} else if (ev.c != '\0') { |
if (i < (MAXLOGNAME - 1)) { |
if (chr_encode(ev.c, scores[NUMSPOTS - 1].hs_name, |
&off, STR_BOUNDS(MAXLOGNAME) + 1) == EOK) { |
++i; |
} |
scores[NUMSPOTS - 1].hs_name[off] = '\0'; |
} |
} |
moveto(10 , 28); |
printf("%s%.*s",scores[NUMSPOTS - 1].hs_name,MAXLOGNAME-i,"........................................"); |
key = getchar(); |
} |
scores[NUMSPOTS - 1].hs_score = score; |
167,7 → 197,7 |
{ |
int i; |
for(i = 0; i < NUMSPOTS; i++) { |
strncpy(scores[i].hs_name, "HelenOS Team", MAXLOGNAME); |
str_cpy(scores[i].hs_name, STR_BOUNDS(MAXLOGNAME) + 1, "HelenOS Team"); |
scores[i].hs_score = (NUMSPOTS - i) * 200; |
scores[i].hs_level = (i + 1 > MAXLEVEL?MAXLEVEL:i + 1); |
} |
261,7 → 291,7 |
/* change = 0; */ |
/* me = thisuser(); */ |
/* for (i = 0, sp = &scores[0]; i < nscores; i++, sp++) { */ |
/* if (sp->hs_level != level || strcmp(sp->hs_name, me) != 0) */ |
/* if (sp->hs_level != level || str_cmp(sp->hs_name, me) != 0) */ |
/* continue; */ |
/* if (score > sp->hs_score) { */ |
/* (void)printf("%s bettered %s %d score of %d!\n", */ |
389,7 → 419,7 |
/* * This is O(n^2), but do you think we care? */ |
/* *\/ */ |
/* for (j = 0, pu = count; j < numnames; j++, pu++) */ |
/* if (strcmp(sp->hs_name, pu->name) == 0) */ |
/* if (str_cmp(sp->hs_name, pu->name) == 0) */ |
/* break; */ |
/* if (j == numnames) { */ |
/* /\* */ |
526,7 → 556,7 |
/* if (me != NULL && */ |
/* sp->hs_level == level && */ |
/* sp->hs_score == score && */ |
/* strcmp(sp->hs_name, me) == 0) { */ |
/* str_cmp(sp->hs_name, me) == 0) { */ |
/* putpad(SOstr); */ |
/* highlight = 1; */ |
/* } */ |
/branches/dd/uspace/app/tetris/screen.c |
---|
280,7 → 280,7 |
scr_msg(char *s, int set) |
{ |
int l = strlen(s); |
int l = str_size(s); |
moveto(Rows - 2, ((Cols - l) >> 1) - 1); |
if (set) |
/branches/dd/uspace/app/tetris/scores.h |
---|
45,9 → 45,11 |
* Tetris scores. |
*/ |
#include <sys/time.h> |
#include <string.h> |
#define MAXLOGNAME 16 |
struct highscore { |
char hs_name[MAXLOGNAME + 1]; /* login name */ |
char hs_name[STR_BOUNDS(MAXLOGNAME) + 1]; /* login name */ |
int hs_score; /* raw score */ |
int hs_level; /* play level */ |
// time_t hs_time; /* time at game end */ |
/branches/dd/uspace/app/tetris/tetris.c |
---|
277,7 → 277,7 |
/* classic = 1; */ |
/* break; */ |
/* case 'k': */ |
/* if (strlen(keys = optarg) != 6) */ |
/* if (str_size(keys = optarg) != 6) */ |
/* usage(); */ |
/* break; */ |
/* case 'l': */ |
311,7 → 311,7 |
errx(1, "duplicate command keys specified."); |
} |
if (keys[i] == ' ') |
strncpy(key_write[i], "<space>", sizeof key_write[i]); |
str_cpy(key_write[i], sizeof key_write[i], "<space>"); |
else { |
key_write[i][0] = keys[i]; |
key_write[i][1] = '\0'; |
/branches/dd/uspace/app/klog/klog.c |
---|
47,21 → 47,21 |
#define NAME "klog" |
#define KLOG_SIZE PAGE_SIZE |
/* Pointer to klog area */ |
static char *klog; |
static wchar_t *klog; |
static count_t klog_length; |
static void interrupt_received(ipc_callid_t callid, ipc_call_t *call) |
{ |
async_serialize_start(); |
size_t klog_start = (size_t) IPC_GET_ARG1(*call); |
size_t klog_len = (size_t) IPC_GET_ARG2(*call); |
size_t klog_stored = (size_t) IPC_GET_ARG3(*call); |
size_t i; |
count_t klog_start = (count_t) IPC_GET_ARG1(*call); |
count_t klog_len = (count_t) IPC_GET_ARG2(*call); |
count_t klog_stored = (count_t) IPC_GET_ARG3(*call); |
count_t i; |
for (i = klog_len - klog_stored; i < klog_len; i++) |
putchar(klog[(klog_start + i) % KLOG_SIZE]); |
putchar(klog[(klog_start + i) % klog_length]); |
async_serialize_end(); |
} |
70,14 → 70,18 |
{ |
console_wait(); |
klog = (char *) as_get_mappable_page(KLOG_SIZE); |
count_t klog_pages = sysinfo_value("klog.pages"); |
size_t klog_size = klog_pages * PAGE_SIZE; |
klog_length = klog_size / sizeof(wchar_t); |
klog = (wchar_t *) as_get_mappable_page(klog_pages); |
if (klog == NULL) { |
printf(NAME ": Error allocating memory area\n"); |
return -1; |
} |
int res = ipc_share_in_start_1_0(PHONE_NS, (void *) klog, KLOG_SIZE, |
SERVICE_MEM_KLOG); |
int res = ipc_share_in_start_1_0(PHONE_NS, (void *) klog, |
klog_size, SERVICE_MEM_KLOG); |
if (res != EOK) { |
printf(NAME ": Error initializing memory area\n"); |
return -1; |
91,7 → 95,7 |
async_set_interrupt_received(interrupt_received); |
klog_update(); |
async_manager(); |
return 0; |
} |