From 3256dedea859f778603f0ea20bd43e6f723ad838 Mon Sep 17 00:00:00 2001 From: Nasarus Date: Sun, 17 Oct 2010 19:50:55 +0000 Subject: [PATCH] Shell 0.4.4 (All) git-svn-id: svn://kolibrios.org@1665 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/system/shell/bin/.shell | 5 + programs/system/shell/bin/shell.kex | Bin 0 -> 4713 bytes programs/system/shell/clean.bat | 2 + programs/system/shell/cmd/cmd_about.c | 17 + programs/system/shell/cmd/cmd_alias.c | 19 + programs/system/shell/cmd/cmd_ccpuid.c | 33 ++ programs/system/shell/cmd/cmd_cd.c | 47 ++ programs/system/shell/cmd/cmd_clear.c | 6 + programs/system/shell/cmd/cmd_date.c | 23 + programs/system/shell/cmd/cmd_echo.c | 6 + programs/system/shell/cmd/cmd_exit.c | 8 + programs/system/shell/cmd/cmd_free.c | 14 + programs/system/shell/cmd/cmd_help.c | 32 ++ programs/system/shell/cmd/cmd_kill.c | 43 ++ programs/system/shell/cmd/cmd_ls.c | 47 ++ programs/system/shell/cmd/cmd_mkdir.c | 44 ++ programs/system/shell/cmd/cmd_more.c | 87 ++++ programs/system/shell/cmd/cmd_ps.c | 32 ++ programs/system/shell/cmd/cmd_pwd.c | 6 + programs/system/shell/cmd/cmd_reboot.c | 6 + programs/system/shell/cmd/cmd_rm.c | 50 +++ programs/system/shell/cmd/cmd_rmdir.c | 46 ++ programs/system/shell/cmd/cmd_sleep.c | 12 + programs/system/shell/cmd/cmd_touch.c | 54 +++ programs/system/shell/cmd/cmd_ver.c | 6 + programs/system/shell/modules/module_alias.c | 126 ++++++ .../system/shell/modules/module_command.c | 203 +++++++++ .../system/shell/modules/module_executable.c | 60 +++ .../system/shell/modules/module_program.c | 16 + programs/system/shell/modules/module_script.c | 102 +++++ programs/system/shell/start.asm | 41 ++ programs/system/shell/system/boolean.h | 3 + programs/system/shell/system/console.c | 88 ++++ programs/system/shell/system/kolibri.c | 412 ++++++++++++++++++ programs/system/shell/system/kolibri.h | 90 ++++ programs/system/shell/system/stdlib.c | 33 ++ programs/system/shell/system/stdlib.h | 14 + programs/system/shell/system/string.c | 124 ++++++ programs/system/shell/system/string.h | 15 + 39 files changed, 1972 insertions(+) create mode 100644 programs/system/shell/bin/.shell create mode 100644 programs/system/shell/bin/shell.kex create mode 100644 programs/system/shell/clean.bat create mode 100644 programs/system/shell/cmd/cmd_about.c create mode 100644 programs/system/shell/cmd/cmd_alias.c create mode 100644 programs/system/shell/cmd/cmd_ccpuid.c create mode 100644 programs/system/shell/cmd/cmd_cd.c create mode 100644 programs/system/shell/cmd/cmd_clear.c create mode 100644 programs/system/shell/cmd/cmd_date.c create mode 100644 programs/system/shell/cmd/cmd_echo.c create mode 100644 programs/system/shell/cmd/cmd_exit.c create mode 100644 programs/system/shell/cmd/cmd_free.c create mode 100644 programs/system/shell/cmd/cmd_help.c create mode 100644 programs/system/shell/cmd/cmd_kill.c create mode 100644 programs/system/shell/cmd/cmd_ls.c create mode 100644 programs/system/shell/cmd/cmd_mkdir.c create mode 100644 programs/system/shell/cmd/cmd_more.c create mode 100644 programs/system/shell/cmd/cmd_ps.c create mode 100644 programs/system/shell/cmd/cmd_pwd.c create mode 100644 programs/system/shell/cmd/cmd_reboot.c create mode 100644 programs/system/shell/cmd/cmd_rm.c create mode 100644 programs/system/shell/cmd/cmd_rmdir.c create mode 100644 programs/system/shell/cmd/cmd_sleep.c create mode 100644 programs/system/shell/cmd/cmd_touch.c create mode 100644 programs/system/shell/cmd/cmd_ver.c create mode 100644 programs/system/shell/modules/module_alias.c create mode 100644 programs/system/shell/modules/module_command.c create mode 100644 programs/system/shell/modules/module_executable.c create mode 100644 programs/system/shell/modules/module_program.c create mode 100644 programs/system/shell/modules/module_script.c create mode 100644 programs/system/shell/start.asm create mode 100644 programs/system/shell/system/boolean.h create mode 100644 programs/system/shell/system/console.c create mode 100644 programs/system/shell/system/kolibri.c create mode 100644 programs/system/shell/system/kolibri.h create mode 100644 programs/system/shell/system/stdlib.c create mode 100644 programs/system/shell/system/stdlib.h create mode 100644 programs/system/shell/system/string.c create mode 100644 programs/system/shell/system/string.h diff --git a/programs/system/shell/bin/.shell b/programs/system/shell/bin/.shell new file mode 100644 index 0000000000..c65fcb04e5 --- /dev/null +++ b/programs/system/shell/bin/.shell @@ -0,0 +1,5 @@ +#SHS + +about +echo Type 'help' for help +echo diff --git a/programs/system/shell/bin/shell.kex b/programs/system/shell/bin/shell.kex new file mode 100644 index 0000000000000000000000000000000000000000..07b30a48e9f565925a68b45fc7449058369573de GIT binary patch literal 4713 zcmV-v5|-^tP(w@1Hvj;E00001Mv*2LLXK;4&&M{gp_WjK+AFYWlP7+=hq{_28ii1Y z{=n}^Q(@xmLVoX?H}cm^7NwS1diSf*WyEY7!&{IF89Q?LKsw@7S=REGGe~@YT&e*& z$nE}K;F6)V^#?kEO10BEW{z-?0xEB2fT~49x5BaiwxC0MfxJ*(lA4C0g}9@V{Sj0C z&~xOdEa;gc{R?YiU@;icF-2^$qZ-VEq_)ok5WZ#`0#z=p&{jU(xppJ{CHEAsyUl?P z?*^?I4-r?GpLF^ZO5>GRSdYPpn1h2m#1RiTK+Kz((1b~gxTr*5s`wlj@uAkE+uinD zwDq%)U3D(iH{{JGT%QG|XO4pi#^R9a?F0cZw}{NC!iyR?cid0sFW?$C>T7cdyBPB+i}$i<18>mJv)#@>2{WG8Fu{ZB5{41ao@LHG3N})0p%y49M=2$*xeJ#crJ7e5^r=-f z4IVeuFa*|#>efj{t$N)Cj2V`mS}qLFv<2~b+MJto_D0%epy|XVcaN+gMz9SeS z+;;OJabtY5&9z(w7jemOe)B5!MR!th!l83tk!4~N15QEN{{uUYe05Jdb;@nAj=MHm zOcZ~*0d_zA~1tfZ2(#CwZ|$~6jC*`D86IX$wZT3saVDS_h&W;{TM zNG#C0K)OSBvgs|>Ymkl8AfDI%UECPJ8r_!jSb*^R06JV( zC~YowMk!JyL!Y-yRNw=_z|9#?R?J~@CT9g=n}WFpLHRjw`I-sxGwDw+u+KG~*<;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000) >> 16; +str[7] = (d&0xff000000) >> 24; + +str[8] = (c&0x000000ff) >> 0; +str[9] = (c&0x0000ff00) >> 8; +str[10] = (c&0x00ff0000) >> 16; +str[11] = (c&0xff000000) >> 24; + +printf("%s\n\r", str); +return TRUE; +} diff --git a/programs/system/shell/cmd/cmd_cd.c b/programs/system/shell/cmd/cmd_cd.c new file mode 100644 index 0000000000..8a2322f384 --- /dev/null +++ b/programs/system/shell/cmd/cmd_cd.c @@ -0,0 +1,47 @@ + +int cmd_cd(char dir[]) +{ + +char temp[256]; +unsigned result; + +if (NULL == dir) + { + printf(" cd directory\n\r"); + return FALSE; + } + +if ( 0 == strcmp(dir, ".") ) + return FALSE; + +if ( ( 0 == strcmp(dir, "..") ) && ( 0 != strcmp(cur_dir, "/")) ) + { + cur_dir[strlen(cur_dir)-1]='\0'; + dir_truncate(cur_dir); + return FALSE; + } + +if ( '/' == dir[0]) + { + if ( dir_check(dir) ) + { + strcpy(cur_dir, dir); + return TRUE; + } + return FALSE; + } +else + { + strcpy(temp, cur_dir); + strcat(temp, dir); + + if ( dir_check(temp) ) + { + strcpy(cur_dir, temp); + return TRUE; + } + + return FALSE; + } + +} diff --git a/programs/system/shell/cmd/cmd_clear.c b/programs/system/shell/cmd/cmd_clear.c new file mode 100644 index 0000000000..70913d9851 --- /dev/null +++ b/programs/system/shell/cmd/cmd_clear.c @@ -0,0 +1,6 @@ + +int cmd_clear(char param[]) +{ +con_cls(); +return TRUE; +} diff --git a/programs/system/shell/cmd/cmd_date.c b/programs/system/shell/cmd/cmd_date.c new file mode 100644 index 0000000000..5015ce1a3b --- /dev/null +++ b/programs/system/shell/cmd/cmd_date.c @@ -0,0 +1,23 @@ + + +int cmd_date(char param[]) +{ +unsigned date; +unsigned time; + +date = kol_system_date_get(); +printf(" date [dd.mm.yy]: %x%x.%x%x.%x%x", + (date&0xf00000)>>20, (date&0xf0000)>>16, // day + (date&0xf000)>>12, (date&0xf00)>>8, //month + (date&0xf0)>>4, (date&0xf) ); // year + + +time = kol_system_time_get(); + +printf("\n\r time [hh:mm:ss]: %x%x:%x%x:%x%x\n\r", + (time&0xf0)>>4, (time&0xf), // hours + (time&0xf000)>>12, (time&0xf00)>>8, // minutes + (time&0xf00000)>>20, (time&0xf0000)>>16 ); // seconds + +return TRUE; +} diff --git a/programs/system/shell/cmd/cmd_echo.c b/programs/system/shell/cmd/cmd_echo.c new file mode 100644 index 0000000000..c81d496911 --- /dev/null +++ b/programs/system/shell/cmd/cmd_echo.c @@ -0,0 +1,6 @@ + +int cmd_echo(char text[]) +{ +printf("%s\n\r", text); +return TRUE; +} diff --git a/programs/system/shell/cmd/cmd_exit.c b/programs/system/shell/cmd/cmd_exit.c new file mode 100644 index 0000000000..4c75d6feb2 --- /dev/null +++ b/programs/system/shell/cmd/cmd_exit.c @@ -0,0 +1,8 @@ + +int cmd_exit(char param[]) +{ +free(ALIASES); +_exit(1); +kol_exit(); +return TRUE; +} diff --git a/programs/system/shell/cmd/cmd_free.c b/programs/system/shell/cmd/cmd_free.c new file mode 100644 index 0000000000..4c1d97e8a4 --- /dev/null +++ b/programs/system/shell/cmd/cmd_free.c @@ -0,0 +1,14 @@ + +int cmd_free(char param[]) +{ +unsigned total, free, used; + +total = kol_system_mem(); +free = kol_system_memfree(); +used = total - free; + +printf (" total [kB / MB / %%]: %-7d / %-5d / 100\n\r free [kB / MB / %%]: %-7d / %-5d / %d\n\r used [kB / MB / %%]: %-7d / %-5d / %d\n\r", + total, total/1024, free, free/1024, (free*100)/total, used, total/1024-free/1024, 100-(free*100)/total ); + +return TRUE; +} diff --git a/programs/system/shell/cmd/cmd_help.c b/programs/system/shell/cmd/cmd_help.c new file mode 100644 index 0000000000..02fb18c67d --- /dev/null +++ b/programs/system/shell/cmd/cmd_help.c @@ -0,0 +1,32 @@ + +int cmd_help(char cmd[]) +{ + +int i; + +char available[]={" %d commands available:\n\r"}; + +if ( !strlen(cmd) ) + { + printf (available, NUM_OF_CMD); + for (i = 0; i < NUM_OF_CMD; i++) + printf(" %s\n\r", COMMANDS[i].name); + return TRUE; + } +else + { + for (i=0; i'9')) + return 0; + else + n = 10 * n + s[i] - '0'; + +return n; +} + + + +int cmd_kill(char process[]) +{ + +unsigned proc; +int result; + +if (NULL == process) + { + printf(" kill PID\n\r"); + return FALSE; + } +else + { + proc = _atoi(process); + if ( 0 != proc ) + { + result = kol_process_kill_pid(proc); + if (result < 0) + return FALSE; + else + return TRUE; + } + } + +} diff --git a/programs/system/shell/cmd/cmd_ls.c b/programs/system/shell/cmd/cmd_ls.c new file mode 100644 index 0000000000..d9a3bad68f --- /dev/null +++ b/programs/system/shell/cmd/cmd_ls.c @@ -0,0 +1,47 @@ + +int cmd_ls(char dir[]) +{ + +kol_struct70 k70; +unsigned *n; +unsigned num_of_file; +unsigned *t; +unsigned type_of_file; +int i; + +k70.p00 = 1; +k70.p04 = 0; +k70.p08 = 0; +k70.p12 = 2*1024*1024; // 2 MB +k70.p16 = malloc(2*1024*1024); +k70.p20 = 0; + +/// !!! +// Если ls запускается без параметров, просматриваем текущий каталог +if ( !strlen(dir) ) + k70.p21 = cur_dir; +else + k70.p21 = dir; + +if ( !kol_file_70(&k70) ) // проверяем существование каталога + { + free(k70.p16); + return FALSE; + } + +n = k70.p16+8; +num_of_file = *n; // число файлов в каталоге + +for (i = 0; i < num_of_file; i++) + { + printf (" %s", k70.p16+32+40+(264+40)*i); + t = k70.p16+32+(264+40)*i; + type_of_file = *t; + if ( (0x10 == (type_of_file&0x10)) || (8 == (type_of_file&8)) ) + printf ("/"); + printf ("\n\r"); + } + +free(k70.p16); +return TRUE; +} diff --git a/programs/system/shell/cmd/cmd_mkdir.c b/programs/system/shell/cmd/cmd_mkdir.c new file mode 100644 index 0000000000..b2d2533eee --- /dev/null +++ b/programs/system/shell/cmd/cmd_mkdir.c @@ -0,0 +1,44 @@ + +int cmd_mkdir(char dir[]) +{ + +char temp[256]; +kol_struct70 k70; +unsigned result; + +if (NULL == dir) + { + printf(" mkdir directory\n\r"); + return FALSE; + } + + +if ( 0 == strcmp(dir, ".") || ( 0 == strcmp(dir, "..") ) || ( 0 == strcmp(cur_dir, "/")) ) + { + return FALSE; + } + +k70.p00 = 9; +k70.p04 = 0; +k70.p08 = 0; +k70.p12 = 0; +k70.p16 = 0; +k70.p20 = 0; + +if ( '/' == dir[0]) + k70.p21 = dir; +else + { + strcpy(temp, cur_dir); + strcat(temp, dir); + k70.p21 = temp; + } + +result = kol_file_70(&k70); + +if (0 == result) + return TRUE; +else + return FALSE; + +} diff --git a/programs/system/shell/cmd/cmd_more.c b/programs/system/shell/cmd/cmd_more.c new file mode 100644 index 0000000000..8fdee45820 --- /dev/null +++ b/programs/system/shell/cmd/cmd_more.c @@ -0,0 +1,87 @@ + +int cmd_more(char file[]) +{ + +kol_struct70 k70; +kol_struct_BDVK bdvk; +unsigned result, filesize, pos, i; +char buf[81]; //буфер +char temp[256]; +unsigned flags; + +if (NULL == file) + { + printf (" less filename\n\r"); + return FALSE; + } + +if ( '/' == file[0]) + { + strcpy(temp, file); + + if ( !file_check(temp) ) + { + return FALSE; + } + } +else + { + strcpy(temp, cur_dir); + strcat(temp, file); + + if ( !file_check(temp) ) + { + return FALSE; + } + } + +k70.p00 = 5; +k70.p04 = k70.p08 = k70.p12 = 0; +k70.p16 = &bdvk; +k70.p20 = 0; +k70.p21 = temp; + +result = kol_file_70(&k70); // получаем информацию о файле +if ( 0 != result ) + return FALSE; + +filesize = bdvk.p32[0]; // получаем размер файла + +buf[80]=0; +flags = con_get_flags(); + +for (pos=0;pos 255) + return FALSE; + +if ( !alias_split (alias, buf1, buf2)) + return FALSE; + +strcpy (ALIASES+256*ALIAS_NUM, buf1); +strcpy (ALIASES+256*ALIAS_NUM+64*1024, buf2); +ALIAS_NUM++; + +return TRUE; +} + +/// =========================================================== + +void alias_list() +{ + +unsigned i; + +if ( 0 == ALIAS_NUM) + return; + +for (i = 0; i < ALIAS_NUM; i++) + printf (" %s=%s\n\r",ALIASES+256*i, ALIASES+256*i+64*1024); +} + +/// =========================================================== + +int alias_split (char alias[], char s1[], char s2[]) +{ + +unsigned i, j; + +if (NULL == strchr(alias, '=')) + return FALSE; + +for (i=0, j = 0;; i++) + { + if ('=' == alias[i]) + { + s1[i]='\0'; + break; + } + s1[i]=alias[i]; + } + +j = 0; + +for (;; i++, j++) + { + s2[j]=alias[i]; + if ('\0' == alias[i]) + break; + } + +trim(s1); + +for (i=0;;i++) + { + s2[i] = s2[i+1]; + if ('\0' == s2[i] ) + break; + } + +trim(s2); + +return TRUE; + +} + +/// =========================================================== diff --git a/programs/system/shell/modules/module_command.c b/programs/system/shell/modules/module_command.c new file mode 100644 index 0000000000..42aff58895 --- /dev/null +++ b/programs/system/shell/modules/module_command.c @@ -0,0 +1,203 @@ + +/// =========================================================== + +void command_clear() +{ +for (;CMD_POS;CMD_POS--) + printf("%c %c", 8, 8); +CMD[0]='\0'; +} + +/// =========================================================== + +void command_history_add(char command[]) +{ + +if ( (0 != strcmp( CMD_HISTORY[0], CMD)) && + (0 != strcmp( CMD_HISTORY[1], CMD)) && + (0 != strcmp( CMD_HISTORY[2], CMD)) && + (0 != strcmp( CMD_HISTORY[3], CMD)) && + (0 != strcmp( CMD_HISTORY[4], CMD)) ) + + { + strcpy(CMD_HISTORY[4], CMD_HISTORY[3]); + strcpy(CMD_HISTORY[3], CMD_HISTORY[2]); + strcpy(CMD_HISTORY[2], CMD_HISTORY[1]); + strcpy(CMD_HISTORY[1], CMD_HISTORY[0]); + + strcpy(CMD_HISTORY[0], CMD); + } + +} + +/// =========================================================== + +void command_get() +{ +unsigned key; +//unsigned pos = 0; +int hist; + +CMD_POS = 0; +CMD_NUM = 0; + +for (;;) + { + key = getch(); + if ( 0 != (key & 0xff) ) + { + key &= 0xff; + switch (key) + { + case 27: // ESC + command_clear(); + break; + + case 13: // ENTER + CMD[CMD_POS] = '\0'; + printf("\n\r"); + + command_history_add(CMD); + return; + + case 8: // BACKSPACE + if (CMD_POS > 0) + { + printf ("%c %c", 8, 8); + CMD_POS--; + } + break; + + case 9: // TAB + break; + + default: + if (CMD_POS < 255) + { + CMD[CMD_POS] = key; + CMD_POS++; + printf("%c", key); + } + break; + }; + } + else // обработка расширенных клавиш + { + key = (key>>8)&0xff; +// printf ("%d\n\r", key); + + switch (key) + { + + case 72: // UP + for (hist = 0; hist < CMD_HISTORY_NUM; hist++) + { + command_clear(); + + if (CMD_NUM < CMD_HISTORY_NUM-1) + CMD_NUM++; + else + CMD_NUM = 0; + + printf( CMD_HISTORY[CMD_NUM] ); + strcpy(CMD, CMD_HISTORY[CMD_NUM]); + if ((CMD_POS = strlen(CMD)) != 0) + break; + } + + break; + + case 80: // DOWN + for (hist = 0; hist < CMD_HISTORY_NUM; hist++) + { + command_clear(); + + if (CMD_NUM > 0) + CMD_NUM--; + else + CMD_NUM = CMD_HISTORY_NUM-1; + + printf( CMD_HISTORY[CMD_NUM] ); + strcpy(CMD, CMD_HISTORY[CMD_NUM]); + if ((CMD_POS = strlen(CMD)) != 0) + break; + } + break; + + case 0: // console window closed + cmd_exit(NULL); + + }; + } + + } +} + + + +/// =========================================================== + +int command_get_cmd(char cmd[]) +{ +unsigned i; +for (i=0;;i++) + { + cmd[i] = CMD[i]; + if (0 == cmd[i]) + { + i = -2; + break; + } + if ( iswhite(cmd[i]) ) + { + cmd[i] = '\0'; + break; + } + } +return i+1; +} + +/// =========================================================== + +typedef void (*handler1_t)(char* arg); + +/// =========================================================== + +void command_execute() +{ +char cmd[256]; +char args[256]; +unsigned arg; +int i; + +trim(CMD); +arg = command_get_cmd(cmd); + +if ( !strlen(cmd) ) + return; + +strcpy(args, CMD+arg); +trim(args); + +for (i = 0; i < NUM_OF_CMD; i++) + { + if (!strcmp(cmd, COMMANDS[i].name)) + { + ((handler1_t)COMMANDS[i].handler)(args); + return; + } + } + + +if ( -1 != alias_search(CMD) ) + { + strcpy(CMD, ALIASES+64*1024+256*alias_search(CMD)); + command_execute(); + return; + } + +executable_run(cmd, args); + +} + +/// =========================================================== diff --git a/programs/system/shell/modules/module_executable.c b/programs/system/shell/modules/module_executable.c new file mode 100644 index 0000000000..78a9e80164 --- /dev/null +++ b/programs/system/shell/modules/module_executable.c @@ -0,0 +1,60 @@ + +/// =========================================================== + +int executable_run(char cmd[], char args[]) +{ + +char exec[256]; +char error_starting[]={" No such command '%s'.\n\r"}; +int result; + +if ( '/' == cmd[0]) // если путь абсолбтный + { + strcpy(exec, cmd); + + if ( !file_check(exec) ) // проверяем существование файла + { + printf(error_starting, cmd); + return FALSE; + } + } + +else + { + strcpy(exec, cur_dir); // проверяем файл в текущем каталоге + strcat(exec, cmd); + + if ( !file_check(exec) ) // проверяем существование файла + { + strcpy(exec, "/rd/1/"); // проверяем файл на виртуальном диске + strcat(exec, cmd); + if ( !file_check(exec) ) // проверяем существование файла + { + printf(error_starting, cmd); + return FALSE; + } + } + } + + +if ( script_check(exec) ) + { + return script_run(exec, args); + } + +/* запуск программы */ +result = program_run(exec, args); +if (result > 0) + { + printf (" '%s' started. PID = %d\n\r", cmd, result); + return TRUE; + } +else + { + printf(error_starting, cmd); + return FALSE; + } + +} + +/// =========================================================== diff --git a/programs/system/shell/modules/module_program.c b/programs/system/shell/modules/module_program.c new file mode 100644 index 0000000000..6bbbe2685a --- /dev/null +++ b/programs/system/shell/modules/module_program.c @@ -0,0 +1,16 @@ + +int program_run(char cmd[], char param[]) +{ + +kol_struct70 k70; + +k70.p00 = 7; +k70.p04 = 0; +k70.p08 = param; +k70.p12 = 0; +k70.p16 = 0; +k70.p20 = 0; +k70.p21 = cmd; + +return kol_file_70(&k70); +} diff --git a/programs/system/shell/modules/module_script.c b/programs/system/shell/modules/module_script.c new file mode 100644 index 0000000000..4abc0ee726 --- /dev/null +++ b/programs/system/shell/modules/module_script.c @@ -0,0 +1,102 @@ + +/// =========================================================== + +int script_check(char file[]) +{ + +kol_struct70 k70; +char buf[4]; + +k70.p00 = 0; +k70.p04 = 0; +k70.p08 = 0; +k70.p12 = 4; // читать 4 байта +k70.p16 = buf; +k70.p20 = 0; +k70.p21 = file; + +kol_file_70(&k70); + +if ( !strcmp(buf, script_sign) ) + return TRUE; +else + return FALSE; +} + +/// =========================================================== + +int script_run(char exec[], char args[]) +{ + +kol_struct70 k70; +kol_struct_BDVK bdvk; +unsigned result, filesize, pos, i; +char *buf; //буфер, куда копируется скрипт + +k70.p00 = 5; +k70.p04 = k70.p08 = k70.p12 = 0; +k70.p16 = &bdvk; +k70.p20 = 0; +k70.p21 = exec; + +result = kol_file_70(&k70); // получаем информацию о файле +if ( 0 != result ) + return FALSE; + +filesize = bdvk.p32[0]; // получаем размер файла + +buf = malloc(filesize+256); +if (NULL == buf) + return FALSE; + +buf[filesize]=0; + +k70.p00 = 0; +k70.p04 = k70.p08 = 0; +k70.p12 = filesize; +k70.p16 = buf; +k70.p20 = 0; +k70.p21 = exec; + +result = kol_file_70(&k70); // считываем файл в буфер +if ( 0 != result ) + { + free(buf); + return FALSE; + } + +pos = 0; + +for (;;) // обработка скрипта + { + + if (pos > filesize) + break; + + for (i=0;;i++) // считывание строки + { + if ((0x0A == buf[pos])||(0x0D == buf[pos])||(0 == buf[pos])) + { + pos++; + CMD[i] = '\0'; + break; + } + CMD[i] = buf[pos]; + pos++; + } + + if ( 0 == strlen(CMD) ) // пустая строка + continue; + + if ('#' == CMD[0]) // комментарий + continue; + + command_execute(); + + } + +free(buf); +return TRUE; +} + +/// =========================================================== diff --git a/programs/system/shell/start.asm b/programs/system/shell/start.asm new file mode 100644 index 0000000000..d8f0f13995 --- /dev/null +++ b/programs/system/shell/start.asm @@ -0,0 +1,41 @@ + +format MS COFF + +public Start +public _PATH +public _PARAM + +extrn Memory +extrn hEnd + +extrn _kol_main + +section ".text" code + db "MENUET01" + dd 1, Start, hEnd, Memory, hStack, _PARAM, _PATH + +Start: + +; инициализация кучи +mov eax, 68 +mov ebx, 11 +int 0x40 + +; вызов главной процедуры +mov eax, _kol_main +call eax + +; завершение работы программы +mov eax, -1 +int 0x40 + +section ".bss" + +_PARAM: +rb 256 + +_PATH: +rb 256 + +rb 8*1024 +hStack: diff --git a/programs/system/shell/system/boolean.h b/programs/system/shell/system/boolean.h new file mode 100644 index 0000000000..072ddad2f3 --- /dev/null +++ b/programs/system/shell/system/boolean.h @@ -0,0 +1,3 @@ + +#define FALSE 0 +#define TRUE 1 diff --git a/programs/system/shell/system/console.c b/programs/system/shell/system/console.c new file mode 100644 index 0000000000..7883274c65 --- /dev/null +++ b/programs/system/shell/system/console.c @@ -0,0 +1,88 @@ + +///=========================== + +#define CON_COLOR_BLUE 1 +#define CON_COLOR_GREEN 2 +#define CON_COLOR_RED 4 +#define CON_COLOR_BRIGHT 8 +/* цвет фона */ +#define CON_BGR_BLUE 0x10 +#define CON_BGR_GREEN 0x20 +#define CON_BGR_RED 0x40 +#define CON_BGR_BRIGHT 0x80 + +///=========================== + +void (* _stdcall con_init)(unsigned w_w, unsigned w_h, unsigned s_w, unsigned s_h, const char* t); +void (* _cdecl printf)(const char* format,...); +void (* _stdcall _exit)(char bCloseWindow); +void (* __stdcall gets)(char* str, int n); + int (* __stdcall getch)(void); + int (* __stdcall con_get_font_height)(void); + int (* __stdcall con_set_cursor_height)(int new_height); +unsigned (*__stdcall con_get_flags)(void); +unsigned (*__stdcall con_set_flags)(unsigned new_flags); +void (*__stdcall con_cls)(void); + +///=========================== + +void CONSOLE_INIT(char title[]) +{ +kol_struct_import *imp; + +imp = kol_cofflib_load("/sys/lib/console.obj"); +if (imp == NULL) + kol_exit(); + +con_init = ( _stdcall void (*)(unsigned, unsigned, unsigned, unsigned, const char*)) + kol_cofflib_procload (imp, "con_init"); +if (con_init == NULL) + kol_exit(); + +printf = ( _cdecl void (*)(const char*,...)) + kol_cofflib_procload (imp, "con_printf"); +if (printf == NULL) + kol_exit(); + +_exit = ( _stdcall void (*)(char)) + kol_cofflib_procload (imp, "con_exit"); +if (_exit == NULL) + kol_exit(); + +gets = ( _stdcall void (*)(char*, int)) + kol_cofflib_procload (imp, "con_gets"); +if (gets == NULL) + kol_exit(); + +getch = ( _stdcall int (*)(void)) + kol_cofflib_procload (imp, "con_getch2"); +if (getch == NULL) + kol_exit(); + +con_get_font_height = ( _stdcall int (*)(void)) + kol_cofflib_procload (imp, "con_get_font_height"); +if (con_get_font_height == NULL) + kol_exit(); + +con_set_cursor_height = ( _stdcall int (*)(int)) + kol_cofflib_procload (imp, "con_set_cursor_height"); +if (con_set_cursor_height == NULL) + kol_exit(); + +con_get_flags = ( _stdcall unsigned (*)(void)) + kol_cofflib_procload (imp, "con_get_flags"); +if (con_get_flags == NULL) + kol_exit(); + +con_set_flags = ( _stdcall unsigned (*)(unsigned)) + kol_cofflib_procload (imp, "con_set_flags"); +if (con_set_flags == NULL) + kol_exit(); + +con_cls = ( _stdcall void (*)(void)) + kol_cofflib_procload (imp, "con_cls"); +if (con_cls == NULL) + kol_exit(); + +con_init(-1, -1, -1, -1, title); +} diff --git a/programs/system/shell/system/kolibri.c b/programs/system/shell/system/kolibri.c new file mode 100644 index 0000000000..c5a8deb4ca --- /dev/null +++ b/programs/system/shell/system/kolibri.c @@ -0,0 +1,412 @@ + +#include "kolibri.h" +#include "string.h" + + +extern char KOL_PATH[256]; +extern char KOL_PARAM[256]; +extern char KOL_DIR[256]; + + +void kol_exit() +{ +asm ("int $0x40"::"a"(-1)); +} + + +void kol_sleep(unsigned d) +{ +asm ("int $0x40"::"a"(5), "b"(d)); +} + + +void kol_wnd_define(unsigned x, unsigned y, unsigned w, unsigned h, unsigned c) +{ +asm ("nop"::"a"(0), "b"(x*65536+w), "c"(y*65536+h), "d"(c)); +asm ("movl $0xffffff, %esi \n int $0x40"); +} + + +void kol_wnd_move(unsigned x, unsigned y) +{ +asm ("nop"::"a"(67), "b"(x), "c"(y)); +asm ("movl $-1, %edx \n movl $-1, %esi \n int $0x40"); +} + + +void kol_event_mask(unsigned e) +{ +asm ("int $0x40"::"a"(40), "b"(e)); +} + + +unsigned kol_event_wait() +{ +asm ("int $0x40"::"a"(10)); +} + + +unsigned kol_event_wait_time(unsigned time) +{ +asm ("int $0x40"::"a"(23), "b"(time)); +} + + +unsigned kol_event_check() +{ +asm ("int $0x40"::"a"(11)); +} + + +void kol_paint_start() +{ +asm ("int $0x40"::"a"(12), "b"(1)); +} + + +void kol_paint_end() +{ +asm ("int $0x40"::"a"(12), "b"(2)); +} + + +void kol_paint_pixel(unsigned x, unsigned y, unsigned c) +{ +asm ("int $0x40"::"a"(1), "b"(x), "c"(y), "d"(c)); +} + + +void kol_paint_bar(unsigned x, unsigned y, unsigned w, unsigned h, unsigned c) +{ +asm ("int $0x40"::"a"(13), "b"(x*65536+w), "c"(y*65536+h), "d"(c)); +} + + +void kol_paint_line(unsigned x1, unsigned y1, unsigned x2, unsigned y2, unsigned c) +{ +asm ("int $0x40"::"a"(38), "b"(x1*65536+x2), "c"(y1*65536+y2), "d"(c)); +} + + +void kol_paint_string(unsigned x, unsigned y, char *s, unsigned c) +{ +asm ("int $0x40"::"a"(4), "b"(x*65536+y), "c"(c), "d"(s)); +} + + +void kol_paint_image(unsigned x, unsigned y, unsigned w, unsigned h, char *d) +{ +asm ("int $0x40"::"a"(7), "c"(w*65536+h), "d"(x*65536+y), "b"(d)); +} + + +void kol_paint_image_pal(unsigned x, unsigned y, unsigned w, unsigned h, char *d, unsigned *palette) +{ +asm ("nop"::"c"(w*65536+h), "d"(x*65536+y), "b"(d)); +asm ("nop"::"a"(palette)); +asm ("movl %eax, %edi"); +asm ("xor %eax, %eax"); +asm ("movl %eax, %ebp"); +asm ("pushl $8"); +asm ("popl %esi"); +asm ("int $0x40"::"a"(65)); +} + + +unsigned kol_key_get() +{ +asm ("int $0x40"::"a"(2)); +} + + +unsigned kol_key_control() +{ +asm ("int $0x40"::"a"(66), "b"(3)); +} + + +void kol_key_lang_set(unsigned lang) +{ +asm ("int $0x40"::"a"(21), "b"(2), "c"(9), "d"(lang)); +} + + +unsigned kol_key_lang_get() +{ +asm ("int $0x40"::"a"(26), "b"(2), "c"(9)); +} + + +void kol_key_mode_set(unsigned mode) +{ +asm ("int $0x40"::"a"(66), "b"(1), "c"(mode)); +} + + +unsigned kol_key_mode_get() +{ +asm ("int $0x40"::"a"(66), "b"(2)); +} + + +unsigned kol_btn_get() +{ +asm ("int $0x40"::"a"(17)); +} + + +void kol_btn_define(unsigned x, unsigned y, unsigned w, unsigned h, unsigned d, unsigned c) +{ +asm ("nop"::"b"(x*65536+w), "c"(y*65536+h), "d"(d)); +asm ("nop"::"a"(c)); +asm ("movl %eax, %esi"); +asm ("int $0x40"::"a"(8)); +} + + +void kol_btn_type(unsigned t) +{ +asm ("int $0x40"::"a"(48), "b"(1), "c"(t)); +} + + +void kol_wnd_caption(char *s) +{ +asm ("int $0x40"::"a"(71), "b"(1), "c"(s)); +} + + +unsigned kol_mouse_pos() +{ +asm ("int $0x40"::"a"(37), "b"(0)); +} + + +unsigned kol_mouse_posw() +{ +asm ("int $0x40"::"a"(37), "b"(1)); +} + + +unsigned kol_mouse_btn() +{ +asm ("int $0x40"::"a"(37), "b"(2)); +} + + +void kol_board_putc(char c) +{ +asm ("int $0x40"::"a"(63), "b"(1), "c"(c)); +} + + +void kol_board_puts(char *s) +{ +unsigned i; +i = 0; +while (*(s+i)) + { + asm ("int $0x40"::"a"(63), "b"(1), "c"(*(s+i))); + i++; + } +} + + +void kol_board_puti(int n) +{ +char c; +int i = 0; +do + { + c = n % 10 + '0'; + asm ("int $0x40"::"a"(63), "b"(1), "c"(c)); + i++; + } + while ((n /= 10) > 0); +} + + +int kol_file_70(kol_struct70 *k) +{ +asm ("int $0x40"::"a"(70), "b"(k)); +} + + +kol_struct_import* kol_cofflib_load(char *name) +{ +asm ("int $0x40"::"a"(68), "b"(19), "c"(name)); +} + + +void* kol_cofflib_procload (kol_struct_import *imp, char *name) +{ +int i; +for (i=0;;i++) + if ( NULL == ((imp+i) -> name)) + break; + else + if ( 0 == strcmp(name, (imp+i)->name) ) + return (imp+i)->data; +return NULL; +} + + +unsigned kol_cofflib_procnum (kol_struct_import *imp) +{ +unsigned i, n; + +for (i=n=0;;i++) + if ( NULL == ((imp+i) -> name)) + break; + else + n++; + +return n; +} + + +void kol_cofflib_procname (kol_struct_import *imp, char *name, unsigned n) +{ +unsigned i; +*name = 0; + +for (i=0;;i++) + if ( NULL == ((imp+i) -> name)) + break; + else + if ( i == n ) + { + strcpy(name, ((imp+i)->name)); + break; + } + +} + + +unsigned kol_system_cpufreq() +{ +asm ("int $0x40"::"a"(18), "b"(5)); +} + + +unsigned kol_system_mem() +{ +asm ("int $0x40"::"a"(18), "b"(17)); +} + + +unsigned kol_system_memfree() +{ +asm ("int $0x40"::"a"(18), "b"(16)); +} + + +unsigned kol_system_time_get() +{ +asm ("int $0x40"::"a"(3)); +} + + +unsigned kol_system_date_get() +{ +asm ("int $0x40"::"a"(29)); +} + + +unsigned kol_system_end(unsigned param) +{ +asm ("int $0x40"::"a"(18), "b"(9), "c"(param)); +} + + +void kol_path_file2dir(char *dir, char *fname) +{ +unsigned i; +strcpy (dir, fname); +for ( i = strlen(dir);; --i) + if ( '/' == dir[i]) + { + dir[i] = '\0'; + return; + } +} + + +void kol_path_full(char *full, char *fname) +{ +char temp[256]; + +switch (*fname) +{ + +case '/': + strncpy(temp, fname+1, 2); + temp[2]=0; + if ( (!strcmp("rd", temp)) || (!strcmp("hd", temp)) || (!strcmp("cd", temp)) ) + strcpy (full, fname); + break; + +case '.': + break; + +default: + break; + +}; + +} + + + +void kol_screen_wait_rr() +{ +asm ("int $0x40"::"a"(18), "b"(14)); +} + + + +void kol_screen_get_size(unsigned *w, unsigned *h) +{ +unsigned size; +asm ("int $0x40":"=a"(size):"a"(14)); +*w = size / 65536; +*h = size % 65536; +} + + + +unsigned kol_skin_height() +{ +asm ("int $0x40"::"a"(48), "b"(4)); +} + + +unsigned kol_thread_start(unsigned start, unsigned stack) +{ +asm ("int $0x40"::"a"(51), "b"(1), "c"(start), "d"(stack)); +} + + +unsigned kol_time_tick() +{ +asm ("int $0x40"::"a"(26), "b"(9)); +} + + +unsigned kol_sound_speaker(char data[]) +{ +asm ("movl %0, %%esi"::"a"(data)); +asm ("int $0x40"::"a"(55), "b"(55)); +} + + +unsigned kol_process_info(unsigned slot, char buf1k[]) +{ +asm ("int $0x40"::"a"(9), "b"(buf1k), "c"(slot)); +} + + +int kol_process_kill_pid(unsigned process) +{ +asm ("int $0x40"::"a"(18), "b"(18), "c"(process)); +} diff --git a/programs/system/shell/system/kolibri.h b/programs/system/shell/system/kolibri.h new file mode 100644 index 0000000000..53575d1a72 --- /dev/null +++ b/programs/system/shell/system/kolibri.h @@ -0,0 +1,90 @@ + +#define NULL ((void*)0) + +typedef struct +{ +unsigned p00 __attribute__((packed)); +unsigned p04 __attribute__((packed)); +unsigned p08 __attribute__((packed)); +unsigned p12 __attribute__((packed)); +unsigned p16 __attribute__((packed)); +char p20 __attribute__((packed)); +char *p21 __attribute__((packed)); +} kol_struct70 __attribute__((packed)); + + +typedef struct +{ +unsigned p00 __attribute__((packed)); +char p04 __attribute__((packed)); +char p05[3] __attribute__((packed)); +unsigned p08 __attribute__((packed)); +unsigned p12 __attribute__((packed)); +unsigned p16 __attribute__((packed)); +unsigned p20 __attribute__((packed)); +unsigned p24 __attribute__((packed)); +unsigned p28 __attribute__((packed)); +unsigned p32[2] __attribute__((packed)); +unsigned p40 __attribute__((packed)); +} kol_struct_BDVK __attribute__((packed)); + +typedef struct +{ +char *name __attribute__((packed)); +void *data __attribute__((packed)); +} kol_struct_import __attribute__((packed)); + + +void kol_exit(); +void kol_sleep(unsigned d); +void kol_wnd_define(unsigned x, unsigned y, unsigned w, unsigned h, unsigned c); +void kol_wnd_move(unsigned x, unsigned y); +void kol_wnd_caption(char *s); +void kol_event_mask(unsigned e); +unsigned kol_event_wait(); +unsigned kol_event_wait_time(unsigned time); +unsigned kol_event_check(); +void kol_paint_start(); +void kol_paint_end(); +void kol_paint_pixel(unsigned x, unsigned y, unsigned c); +void kol_paint_bar(unsigned x, unsigned y, unsigned w, unsigned h, unsigned c); +void kol_paint_line(unsigned x1, unsigned y1, unsigned x2, unsigned y2, unsigned c); +void kol_paint_string(unsigned x, unsigned y, char *s, unsigned c); +void kol_paint_image(unsigned x, unsigned y, unsigned w, unsigned h, char *d); +void kol_paint_image_pal(unsigned x, unsigned y, unsigned w, unsigned h, char *d, unsigned *palette); +unsigned kol_key_get(); +unsigned kol_key_control(); +void kol_key_lang_set(unsigned lang); +unsigned kol_key_lang_get(); +void kol_key_mode_set(unsigned mode); +unsigned kol_key_mode_get(); +void kol_btn_define(unsigned x, unsigned y, unsigned w, unsigned h, unsigned d, unsigned c); +unsigned kol_btn_get(); +void kol_btn_type(unsigned t); +unsigned kol_mouse_pos(); +unsigned kol_mouse_posw(); +unsigned kol_mouse_btn(); +void kol_board_putc(char c); +void kol_board_puts(char *s); +void kol_board_puti(int n); +int kol_file_70(kol_struct70 *k); +kol_struct_import* kol_cofflib_load(char *name); +void* kol_cofflib_procload (kol_struct_import *imp, char *name); +unsigned kol_cofflib_procnum (kol_struct_import *imp); +void kol_cofflib_procname (kol_struct_import *imp, char *name, unsigned n); +unsigned kol_system_end(unsigned param); +unsigned kol_system_cpufreq(); +unsigned kol_system_mem(); +unsigned kol_system_memfree(); +unsigned kol_system_time_get(); +unsigned kol_system_date_get(); +void kol_path_file2dir(char *dir, char *fname); +void kol_path_full(char *full, char *fname); +void kol_screen_wait_rr(); +void kol_screen_get_size(unsigned *w, unsigned *h); +unsigned kol_skin_height(); +unsigned kol_thread_start(unsigned start, unsigned stack); +unsigned kol_time_tick(); +unsigned kol_sound_speaker(char data[]); +unsigned kol_process_info(unsigned slot, char buf1k[]); +int kol_process_kill_pid(unsigned process); diff --git a/programs/system/shell/system/stdlib.c b/programs/system/shell/system/stdlib.c new file mode 100644 index 0000000000..f52c263273 --- /dev/null +++ b/programs/system/shell/system/stdlib.c @@ -0,0 +1,33 @@ + +unsigned int seed_o = 0x45168297; + + +void srand (unsigned seed) +{ +seed_o = seed; +} + + +int rand (void) +{ +seed_o = seed_o * 0x15a4e35 + 1; +return(seed_o >> 16); +} + + +void* malloc(unsigned s) +{ +asm ("int $0x40"::"a"(68), "b"(12), "c"(s) ); +} + + +void free(void *p) +{ +asm ("int $0x40"::"a"(68), "b"(13), "c"(p) ); +} + + +void* realloc(void *p, unsigned s) +{ +asm ("int $0x40"::"a"(68), "b"(12), "c"(p), "d"(s) ); +} diff --git a/programs/system/shell/system/stdlib.h b/programs/system/shell/system/stdlib.h new file mode 100644 index 0000000000..e984555604 --- /dev/null +++ b/programs/system/shell/system/stdlib.h @@ -0,0 +1,14 @@ + +#define RAND_MAX 0x7FFFU + +#define isspace(c) ((c)==' ') +#define abs(i) (((i)<0)?(-(i)):(i)) + +#define random(num) ((rand()*(num))/((RAND_MAX+1))) + +void* malloc(unsigned size); +void free(void *pointer); +void* realloc(void* pointer, unsigned size); + +void srand (unsigned seed); +int rand (void); diff --git a/programs/system/shell/system/string.c b/programs/system/shell/system/string.c new file mode 100644 index 0000000000..145b47686c --- /dev/null +++ b/programs/system/shell/system/string.c @@ -0,0 +1,124 @@ + +#include "string.h" + +void* memset(void *mem, int c, unsigned size) +{ +unsigned i; + +for ( i = 0; i < size; i++ ) + *((char *)mem+i) = (char) c; + +return NULL; +} + + +void* memcpy(void *dst, const void *src, unsigned size) +{ + +unsigned i; + +for ( i = 0; i < size; i++) + *(char *)(dst+i) = *(char *)(src+i); + +return NULL; +} + + +int memcmp(const void* buf1, const void* buf2, int count) +{ +int i; +for (i=0;i*(unsigned char*)buf2) + return 1; + } +return 0; +} + +void strcat(char strDest[], char strSource[]) +{ + +int i, j; + +i = j = 0; +while (strDest[i] != '\0') + i++; + +while ((strDest[i++] = strSource[j++]) != '\0') + ; +} + + +int strcmp(const char* string1, const char* string2) +{ + +while (1) +{ +if (*string1<*string2) + return -1; +if (*string1>*string2) + return 1; + +if (*string1=='\0') + return 0; + +string1++; +string2++; +} + +} + + +void strcpy(char strDest[], const char strSource[]) +{ +unsigned i; + +i = 0; +while ((strDest[i] = strSource[i]) != '\0') + i++; + +} + + +char* strncpy(char *strDest, const char *strSource, unsigned n) +{ +unsigned i; + +if (! n ) + return strDest; + +i = 0; +while ((strDest[i] = strSource[i]) != '\0') + if ( (n-1) == i ) + break; + else + i++; + +return strDest; +} + + +int strlen(const char* string) +{ +int i; + +i=0; +while (*string++) i++; +return i; +} + + + +char* strchr(const char* string, int c) +{ + while (*string) + { + if (*string==c) + return (char*)string; + string++; + } + return (char*)0; +} + diff --git a/programs/system/shell/system/string.h b/programs/system/shell/system/string.h new file mode 100644 index 0000000000..1ce28e29e9 --- /dev/null +++ b/programs/system/shell/system/string.h @@ -0,0 +1,15 @@ + +#ifndef NULL +#define NULL ((void*)0) +#endif + +void* memset(void *mem, int c, unsigned size); +void* memcpy(void *dst, const void *src, unsigned size); +int memcmp(const void* buf1, const void* buf2, int count); + +void strcat(char strDest[], char strSource[]); +int strcmp(const char* string1, const char* string2); +void strcpy(char strDest[], const char strSource[]); +char* strncpy(char *strDest, const char *strSource, unsigned n); +int strlen(const char* string); +char *strchr(const char* string, int c);