diff --git a/programs/system/shell/globals.h b/programs/system/shell/globals.h index 87e99d3adf..6960f44ba0 100644 --- a/programs/system/shell/globals.h +++ b/programs/system/shell/globals.h @@ -1,5 +1,5 @@ -#define SHELL_VERSION "0.7.8" +#define SHELL_VERSION "0.7.8a" extern char PATH[256]; extern char PARAM[256]; diff --git a/programs/system/shell/modules/module_executable.c b/programs/system/shell/modules/module_executable.c index ce823ba0f1..11838e07c6 100644 --- a/programs/system/shell/modules/module_executable.c +++ b/programs/system/shell/modules/module_executable.c @@ -4,63 +4,68 @@ int executable_run(char cmd[], char args[]) { -char exec[FILENAME_MAX]; -int result; + char exec[FILENAME_MAX]; + int result; -if ( '/' == cmd[0]) // если путь абсолютный + if ( '/' == cmd[0]) // if path is absolute { - strcpy(exec, cmd); - - if ( !file_check(exec) ) // проверяем существование файла + strcpy(exec, cmd); + if (!file_check(exec) ) // check file existense { - file_not_found(cmd); - return FALSE; + file_not_found(cmd); + return FALSE; } } - -else + else { - strcpy(exec, cur_dir); // проверяем файл в текущем каталоге - if (exec[strlen(exec)-1] != '/') - strcat(exec, "/"); // add slash - strcat(exec, cmd); - - if ( !file_check(exec) ) // проверяем существование файла - { - strcpy(exec, "/rd/1/"); // проверяем файл на виртуальном диске + strcpy(exec, cur_dir); // check file in current directory + if (exec[strlen(exec)-1] != '/') + strcat(exec, "/"); // add slash strcat(exec, cmd); - if ( !file_check(exec) ) // проверяем существование файла - { + + if ( !file_check(exec) ) // check file existense + { + strcpy(exec, "/rd/1/"); // check file on virtual disk + strcat(exec, cmd); + if ( !file_check(exec) ) // check file existense + { file_not_found(cmd); return FALSE; - } + } } } + // if file exists: -if ( script_check(exec) ) - return script_run(exec, args); - -/* запуск программы */ -result = program_run(exec, args); -if (result > 0) + // try to run as a program + result = program_run(exec, args); + if (result > 0) { - - if ( !program_console(result) ) + if ( !program_console(result) ) { - LAST_PID = result; - #if LANG_ENG - printf (" '%s' started. PID = %d\n\r", cmd, result); - #elif LANG_RUS - printf (" '%s' запущен. PID = %d\n\r", cmd, result); - #endif + LAST_PID = result; + #if LANG_ENG + printf (" '%s' started. PID = %d\n\r", cmd, result); + #elif LANG_RUS + printf (" '%s' запущен. PID = %d\n\r", cmd, result); + #endif } - return TRUE; + return TRUE; } -else + else { - file_not_found(cmd); - return FALSE; + if ( script_check(exec) ) // if file is a valid script + { + return script_run(exec, args); + } else + { + #if LANG_ENG + printf ("Error in '%s' : script must start with #SHS line\n\r", cmd); + #elif LANG_RUS + printf ("Ошибка в '%s' : скрипт должен начинаться со строчки #SHS\n\r", cmd); + #endif + return FALSE; + } } } diff --git a/programs/system/shell/modules/module_program.c b/programs/system/shell/modules/module_program.c index 666ecb48ee..93c9d0d4e9 100644 --- a/programs/system/shell/modules/module_program.c +++ b/programs/system/shell/modules/module_program.c @@ -2,17 +2,17 @@ int program_run(char cmd[], char param[]) { -kol_struct70 k70; + kol_struct70 k70; -k70.p00 = 7; -k70.p04 = 0; -//k70.p08 = (unsigned) param; -*((unsigned*)&k70 + 2) = (unsigned) param; -k70.p12 = 0; -k70.p16 = 0; -k70.p20 = 0; -k70.p21 = cmd; + k70.p00 = 7; + k70.p04 = 0; + //k70.p08 = (unsigned) param; + *((unsigned*)&k70 + 2) = (unsigned) param; + k70.p12 = 0; + k70.p16 = 0; + k70.p20 = 0; + k70.p21 = cmd; -return kol_file_70(&k70); + return kol_file_70(&k70); } diff --git a/programs/system/shell/modules/module_script.c b/programs/system/shell/modules/module_script.c index 0594ff8ccc..0b7297e7e9 100644 --- a/programs/system/shell/modules/module_script.c +++ b/programs/system/shell/modules/module_script.c @@ -4,23 +4,23 @@ int script_check(char file[]) { -kol_struct70 k70; -char buf[4]; + kol_struct70 k70; + char buf[4]; -k70.p00 = 0; -k70.p04 = 0; -//k70.p08 = 0; -k70.p12 = 4; // ўшЄрЄ№ 4 срщЄр -k70.p16 = (unsigned) buf; -k70.p20 = 0; -k70.p21 = file; + k70.p00 = 0; + k70.p04 = 0; + //k70.p08 = 0; + k70.p12 = 4; // read 4 bytes + k70.p16 = (unsigned) buf; + k70.p20 = 0; + k70.p21 = file; -kol_file_70(&k70); + kol_file_70(&k70); -if ( !strcmp(buf, script_sign) ) - return TRUE; -else - return FALSE; + if ( !strcmp(buf, script_sign) ) // if we found the script signature + return TRUE; + else + return FALSE; } /// =========================================================== @@ -28,78 +28,78 @@ else int script_run(char exec[], char args[]) { -kol_struct70 k70; -kol_struct_BDVK bdvk; -unsigned result, i; -unsigned long long filesize, pos; -char *buf; //сєЇхЁ, ъєфр ъюяшЁєхЄё  ёъЁшяЄ + kol_struct70 k70; + kol_struct_BDVK bdvk; + unsigned result, i; + unsigned long long filesize, pos; + char *buf; // buffer, where script is copied -k70.p00 = 5; -k70.p04 = k70.p12 = 0; -//k70.p08 = 0; -k70.p16 = (unsigned) &bdvk; -k70.p20 = 0; -k70.p21 = exec; + k70.p00 = 5; + k70.p04 = k70.p12 = 0; + //k70.p08 = 0; + k70.p16 = (unsigned) &bdvk; + k70.p20 = 0; + k70.p21 = exec; -result = kol_file_70(&k70); // яюыєўрхь шэЇюЁьрЎш■ ю Їрщых -if ( 0 != result ) - return FALSE; + result = kol_file_70(&k70); // get file info + if ( 0 != result ) + return FALSE; -filesize = bdvk.p32; // яюыєўрхь ЁрчьхЁ Їрщыр + filesize = bdvk.p32; // get file size -buf = malloc(filesize+256); // may fail for over 4Gb file, but impossible case -if (NULL == buf) - return FALSE; + buf = malloc(filesize+256); // may fail for over 4Gb file, but impossible case + if (NULL == buf) + return FALSE; -buf[filesize]=0; + buf[filesize]=0; -k70.p00 = 0; -k70.p04 = 0; -//k70.p08 = 0; -k70.p12 = filesize; -k70.p16 = (unsigned) buf; -k70.p20 = 0; -k70.p21 = exec; + k70.p00 = 0; + k70.p04 = 0; + //k70.p08 = 0; + k70.p12 = filesize; + k70.p16 = (unsigned) 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++) // ёўшЄ√трэшх ёЄЁюъш + result = kol_file_70(&k70); // read file to the buffer + if ( 0 != result ) { - if ((0x0A == buf[pos])||(0x0D == buf[pos])||(0 == buf[pos])) - { - pos++; - CMD[i] = '\0'; - break; - } - CMD[i] = buf[pos]; - pos++; + free(buf); + return FALSE; } - if ( 0 == strlen(CMD) ) // яєёЄр  ёЄЁюър - continue; + pos = 0; - if ('#' == CMD[0]) // ъюььхэЄрЁшщ - continue; + for (;;) // script processing + { - command_execute(); + if (pos > filesize) + break; - } + for (i=0;;i++) // reading a string + { + if ((0x0A == buf[pos])||(0x0D == buf[pos])||(0 == buf[pos])) + { + pos++; + CMD[i] = '\0'; + break; + } + CMD[i] = buf[pos]; + pos++; + } -free(buf); -return TRUE; + if ( 0 == strlen(CMD) ) // empty string + continue; + + if ('#' == CMD[0]) // comment + continue; + + command_execute(); + + } + + free(buf); + return TRUE; } /// ===========================================================