forked from KolibriOS/kolibrios
Now for incorrect scripts (which doesnt start with #SHS) shell says that they are incorrect, not "File not found". Also, translated comments from russian to english in two files.
git-svn-id: svn://kolibrios.org@7792 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
#define SHELL_VERSION "0.7.8"
|
#define SHELL_VERSION "0.7.8a"
|
||||||
|
|
||||||
extern char PATH[256];
|
extern char PATH[256];
|
||||||
extern char PARAM[256];
|
extern char PARAM[256];
|
||||||
|
@@ -4,32 +4,30 @@
|
|||||||
int executable_run(char cmd[], char args[])
|
int executable_run(char cmd[], char args[])
|
||||||
{
|
{
|
||||||
|
|
||||||
char exec[FILENAME_MAX];
|
char exec[FILENAME_MAX];
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
if ( '/' == cmd[0]) // <EFBFBD> <20><><EFBFBD><EFBFBD> <20><>᮫<EFBFBD><E1AEAB><EFBFBD><EFBFBD><EFBFBD>
|
if ( '/' == cmd[0]) // if path is absolute
|
||||||
{
|
{
|
||||||
strcpy(exec, cmd);
|
strcpy(exec, cmd);
|
||||||
|
if (!file_check(exec) ) // check file existense
|
||||||
if ( !file_check(exec) ) // <20><EFBFBD><E0AEA2>塞 <20><><EFBFBD><EFBFBD><EFBFBD>⢮<EFBFBD><E2A2AE><EFBFBD><EFBFBD><EFBFBD> 䠩<><E4A0A9>
|
|
||||||
{
|
{
|
||||||
file_not_found(cmd);
|
file_not_found(cmd);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
strcpy(exec, cur_dir); // <EFBFBD><EFBFBD><EFBFBD>塞 䠩<> <20> ⥪<>饬 <20><>⠫<EFBFBD><E2A0AB><EFBFBD>
|
strcpy(exec, cur_dir); // check file in current directory
|
||||||
if (exec[strlen(exec)-1] != '/')
|
if (exec[strlen(exec)-1] != '/')
|
||||||
strcat(exec, "/"); // add slash
|
strcat(exec, "/"); // add slash
|
||||||
strcat(exec, cmd);
|
strcat(exec, cmd);
|
||||||
|
|
||||||
if ( !file_check(exec) ) // <EFBFBD><EFBFBD><EFBFBD>塞 <20><><EFBFBD><EFBFBD><EFBFBD>⢮<EFBFBD><E2A2AE><EFBFBD><EFBFBD><EFBFBD> 䠩<><E4A0A9>
|
if ( !file_check(exec) ) // check file existense
|
||||||
{
|
{
|
||||||
strcpy(exec, "/rd/1/"); // <EFBFBD><EFBFBD><EFBFBD>塞 䠩<> <20><> <20><><EFBFBD><EFBFBD>㠫쭮<E3A0AB> <20><>᪥
|
strcpy(exec, "/rd/1/"); // check file on virtual disk
|
||||||
strcat(exec, cmd);
|
strcat(exec, cmd);
|
||||||
if ( !file_check(exec) ) // <EFBFBD><EFBFBD><EFBFBD>塞 <20><><EFBFBD><EFBFBD><EFBFBD>⢮<EFBFBD><E2A2AE><EFBFBD><EFBFBD><EFBFBD> 䠩<><E4A0A9>
|
if ( !file_check(exec) ) // check file existense
|
||||||
{
|
{
|
||||||
file_not_found(cmd);
|
file_not_found(cmd);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -37,15 +35,12 @@ else
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if file exists:
|
||||||
|
|
||||||
if ( script_check(exec) )
|
// try to run as a program
|
||||||
return script_run(exec, args);
|
result = program_run(exec, args);
|
||||||
|
if (result > 0)
|
||||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ணࠬ<E0AEA3><E0A0AC> */
|
|
||||||
result = program_run(exec, args);
|
|
||||||
if (result > 0)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
if ( !program_console(result) )
|
if ( !program_console(result) )
|
||||||
{
|
{
|
||||||
LAST_PID = result;
|
LAST_PID = result;
|
||||||
@@ -57,11 +52,21 @@ if (result > 0)
|
|||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
file_not_found(cmd);
|
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 ("<EFBFBD>訡<EFBFBD><EFBFBD> <20> '%s' : <20><>ਯ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>稭<EFBFBD><E7A8AD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD>窨 #SHS\n\r", cmd);
|
||||||
|
#endif
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,17 +2,17 @@
|
|||||||
int program_run(char cmd[], char param[])
|
int program_run(char cmd[], char param[])
|
||||||
{
|
{
|
||||||
|
|
||||||
kol_struct70 k70;
|
kol_struct70 k70;
|
||||||
|
|
||||||
k70.p00 = 7;
|
k70.p00 = 7;
|
||||||
k70.p04 = 0;
|
k70.p04 = 0;
|
||||||
//k70.p08 = (unsigned) param;
|
//k70.p08 = (unsigned) param;
|
||||||
*((unsigned*)&k70 + 2) = (unsigned) param;
|
*((unsigned*)&k70 + 2) = (unsigned) param;
|
||||||
k70.p12 = 0;
|
k70.p12 = 0;
|
||||||
k70.p16 = 0;
|
k70.p16 = 0;
|
||||||
k70.p20 = 0;
|
k70.p20 = 0;
|
||||||
k70.p21 = cmd;
|
k70.p21 = cmd;
|
||||||
|
|
||||||
return kol_file_70(&k70);
|
return kol_file_70(&k70);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,22 +4,22 @@
|
|||||||
int script_check(char file[])
|
int script_check(char file[])
|
||||||
{
|
{
|
||||||
|
|
||||||
kol_struct70 k70;
|
kol_struct70 k70;
|
||||||
char buf[4];
|
char buf[4];
|
||||||
|
|
||||||
k70.p00 = 0;
|
k70.p00 = 0;
|
||||||
k70.p04 = 0;
|
k70.p04 = 0;
|
||||||
//k70.p08 = 0;
|
//k70.p08 = 0;
|
||||||
k70.p12 = 4; // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 4 <20><><EFBFBD><EFBFBD><EFBFBD>
|
k70.p12 = 4; // read 4 bytes
|
||||||
k70.p16 = (unsigned) buf;
|
k70.p16 = (unsigned) buf;
|
||||||
k70.p20 = 0;
|
k70.p20 = 0;
|
||||||
k70.p21 = file;
|
k70.p21 = file;
|
||||||
|
|
||||||
kol_file_70(&k70);
|
kol_file_70(&k70);
|
||||||
|
|
||||||
if ( !strcmp(buf, script_sign) )
|
if ( !strcmp(buf, script_sign) ) // if we found the script signature
|
||||||
return TRUE;
|
return TRUE;
|
||||||
else
|
else
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,55 +28,55 @@ else
|
|||||||
int script_run(char exec[], char args[])
|
int script_run(char exec[], char args[])
|
||||||
{
|
{
|
||||||
|
|
||||||
kol_struct70 k70;
|
kol_struct70 k70;
|
||||||
kol_struct_BDVK bdvk;
|
kol_struct_BDVK bdvk;
|
||||||
unsigned result, i;
|
unsigned result, i;
|
||||||
unsigned long long filesize, pos;
|
unsigned long long filesize, pos;
|
||||||
char *buf; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
char *buf; // buffer, where script is copied
|
||||||
|
|
||||||
k70.p00 = 5;
|
k70.p00 = 5;
|
||||||
k70.p04 = k70.p12 = 0;
|
k70.p04 = k70.p12 = 0;
|
||||||
//k70.p08 = 0;
|
//k70.p08 = 0;
|
||||||
k70.p16 = (unsigned) &bdvk;
|
k70.p16 = (unsigned) &bdvk;
|
||||||
k70.p20 = 0;
|
k70.p20 = 0;
|
||||||
k70.p21 = exec;
|
k70.p21 = exec;
|
||||||
|
|
||||||
result = kol_file_70(&k70); // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD>
|
result = kol_file_70(&k70); // get file info
|
||||||
if ( 0 != result )
|
if ( 0 != result )
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
filesize = bdvk.p32; // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
filesize = bdvk.p32; // get file size
|
||||||
|
|
||||||
buf = malloc(filesize+256); // may fail for over 4Gb file, but impossible case
|
buf = malloc(filesize+256); // may fail for over 4Gb file, but impossible case
|
||||||
if (NULL == buf)
|
if (NULL == buf)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
buf[filesize]=0;
|
buf[filesize]=0;
|
||||||
|
|
||||||
k70.p00 = 0;
|
k70.p00 = 0;
|
||||||
k70.p04 = 0;
|
k70.p04 = 0;
|
||||||
//k70.p08 = 0;
|
//k70.p08 = 0;
|
||||||
k70.p12 = filesize;
|
k70.p12 = filesize;
|
||||||
k70.p16 = (unsigned) buf;
|
k70.p16 = (unsigned) buf;
|
||||||
k70.p20 = 0;
|
k70.p20 = 0;
|
||||||
k70.p21 = exec;
|
k70.p21 = exec;
|
||||||
|
|
||||||
result = kol_file_70(&k70); // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD>
|
result = kol_file_70(&k70); // read file to the buffer
|
||||||
if ( 0 != result )
|
if ( 0 != result )
|
||||||
{
|
{
|
||||||
free(buf);
|
free(buf);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = 0;
|
pos = 0;
|
||||||
|
|
||||||
for (;;) // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
for (;;) // script processing
|
||||||
{
|
{
|
||||||
|
|
||||||
if (pos > filesize)
|
if (pos > filesize)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
for (i=0;;i++) // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
for (i=0;;i++) // reading a string
|
||||||
{
|
{
|
||||||
if ((0x0A == buf[pos])||(0x0D == buf[pos])||(0 == buf[pos]))
|
if ((0x0A == buf[pos])||(0x0D == buf[pos])||(0 == buf[pos]))
|
||||||
{
|
{
|
||||||
@@ -88,18 +88,18 @@ for (;;) //
|
|||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 0 == strlen(CMD) ) // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
if ( 0 == strlen(CMD) ) // empty string
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ('#' == CMD[0]) // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
if ('#' == CMD[0]) // comment
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
command_execute();
|
command_execute();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ===========================================================
|
/// ===========================================================
|
||||||
|
Reference in New Issue
Block a user