2008-12-14 14:55:46 +03:00
|
|
|
|
|
|
|
|
|
#include "all.h"
|
|
|
|
|
|
|
|
|
|
/// ===========================================================
|
|
|
|
|
|
|
|
|
|
int dir_check(char dir[])
|
2017-02-06 15:35:58 +03:00
|
|
|
|
/// just checks, if dir[] is really a directory
|
2008-12-14 14:55:46 +03:00
|
|
|
|
{
|
|
|
|
|
kol_struct70 k70;
|
|
|
|
|
int result;
|
|
|
|
|
|
|
|
|
|
k70.p00 = 1;
|
|
|
|
|
k70.p04 = 0;
|
2017-02-06 15:35:58 +03:00
|
|
|
|
//k70.p08 = 0;
|
|
|
|
|
k70.p12 = 2; // enough to read . & ..
|
|
|
|
|
k70.p16 = (unsigned)malloc(32+k70.p12*560);
|
2008-12-14 14:55:46 +03:00
|
|
|
|
k70.p20 = 0;
|
|
|
|
|
k70.p21 = dir;
|
|
|
|
|
|
|
|
|
|
result = kol_file_70(&k70);
|
|
|
|
|
|
2013-02-16 15:25:37 +04:00
|
|
|
|
free((void*)k70.p16);
|
2008-12-14 14:55:46 +03:00
|
|
|
|
|
2017-02-06 15:35:58 +03:00
|
|
|
|
if ( (0 == result)||(6 == result) ) // 6 is possible ???
|
2008-12-14 14:55:46 +03:00
|
|
|
|
return TRUE;
|
|
|
|
|
else
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// ===========================================================
|
|
|
|
|
|
|
|
|
|
void dir_truncate(char dir[])
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
i = strlen(dir)-1;
|
|
|
|
|
for (;;i--)
|
|
|
|
|
if ('/' == dir[i])
|
|
|
|
|
{
|
|
|
|
|
dir[i+1] = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-17 00:50:49 +03:00
|
|
|
|
/// ===========================================================
|
|
|
|
|
|
|
|
|
|
void get_file_dir_loc(char *filepath, char *dir_path)
|
|
|
|
|
{
|
|
|
|
|
char *res = strrchr(filepath, '/');
|
|
|
|
|
if (res == 0)
|
|
|
|
|
{
|
|
|
|
|
dir_path = '\0';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
size_t pos = res - filepath;
|
|
|
|
|
strncpy(dir_path, filepath, pos);
|
|
|
|
|
dir_path[pos] = '\0';
|
|
|
|
|
}
|
2008-12-14 14:55:46 +03:00
|
|
|
|
|
|
|
|
|
/// ===========================================================
|
|
|
|
|
|
|
|
|
|
int file_check(char file[])
|
|
|
|
|
{
|
|
|
|
|
kol_struct70 k70;
|
|
|
|
|
int result;
|
|
|
|
|
|
|
|
|
|
k70.p00 = 0;
|
|
|
|
|
k70.p04 = 0;
|
2017-02-06 15:35:58 +03:00
|
|
|
|
//k70.p08 = 0;
|
2008-12-14 14:55:46 +03:00
|
|
|
|
k70.p12 = 0;
|
|
|
|
|
k70.p16 = 0;
|
|
|
|
|
k70.p20 = 0;
|
|
|
|
|
k70.p21 = file;
|
|
|
|
|
|
|
|
|
|
result = kol_file_70(&k70);
|
|
|
|
|
|
|
|
|
|
if (0 == result)
|
|
|
|
|
return TRUE;
|
|
|
|
|
else
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// ===========================================================
|
|
|
|
|
|
2012-04-16 14:40:07 +04:00
|
|
|
|
void file_not_found(char file[])
|
|
|
|
|
{
|
|
|
|
|
#if LANG_ENG
|
|
|
|
|
printf (" File '%s' not found.\n\r", file);
|
|
|
|
|
#elif LANG_RUS
|
|
|
|
|
printf (" <20><><EFBFBD><EFBFBD> '%s' <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.\n\r", file);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// ===========================================================
|
|
|
|
|
|
2008-12-14 14:55:46 +03:00
|
|
|
|
int iswhite(char c)
|
|
|
|
|
{
|
|
|
|
|
return ((' ' == c) || ('\t' == c) || (13 == c) || (10 == c));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// ===========================================================
|
|
|
|
|
|
|
|
|
|
void trim(char string[])
|
|
|
|
|
{
|
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
|
|
for (i=0; ;i++)
|
|
|
|
|
if ( !iswhite(string[i]) )
|
|
|
|
|
break;
|
|
|
|
|
j = 0;
|
|
|
|
|
for (;;i++, j++)
|
|
|
|
|
{
|
|
|
|
|
string[j] = string[i];
|
|
|
|
|
if ('\0' == string[i] )
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i=0; ;i++)
|
|
|
|
|
if ('\0' == string[i])
|
|
|
|
|
break;
|
|
|
|
|
i--;
|
|
|
|
|
for (;i>0;--i)
|
|
|
|
|
if ( iswhite(string[i]) )
|
|
|
|
|
string[i] = '\0';
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// ===========================================================
|
|
|
|
|
|
|
|
|
|
void kol_main()
|
|
|
|
|
{
|
|
|
|
|
|
2010-10-07 17:43:56 +04:00
|
|
|
|
NUM_OF_CMD = sizeof(COMMANDS)/sizeof(COMMANDS[0]);
|
|
|
|
|
|
2008-12-14 14:55:46 +03:00
|
|
|
|
strcpy(title, "SHELL ");
|
|
|
|
|
strcat(title, SHELL_VERSION);
|
|
|
|
|
CONSOLE_INIT(title);
|
|
|
|
|
|
2017-01-07 00:23:13 +03:00
|
|
|
|
if (sizeof (kol_struct70) != 25)
|
|
|
|
|
{
|
|
|
|
|
printf("Invalid struct align kol_struct70, need to fix compile options\n\r");
|
|
|
|
|
kol_exit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-02-10 20:36:03 +03:00
|
|
|
|
//strcpy(cur_dir, PATH);
|
|
|
|
|
//dir_truncate(cur_dir);
|
|
|
|
|
getcwd(cur_dir, sizeof cur_dir);
|
|
|
|
|
//printf("curdir %s\n", cur_dir);
|
2008-12-14 14:55:46 +03:00
|
|
|
|
|
|
|
|
|
con_set_cursor_height(con_get_font_height()-1);
|
|
|
|
|
|
2010-10-07 17:43:56 +04:00
|
|
|
|
ALIASES = malloc(128*1024);
|
|
|
|
|
|
2017-02-10 20:36:03 +03:00
|
|
|
|
if (!PARAM || PARAM[0] == 0)
|
2013-10-27 03:26:02 +04:00
|
|
|
|
{
|
2017-02-10 20:36:03 +03:00
|
|
|
|
strcpy(CMD, PATH);
|
|
|
|
|
dir_truncate(CMD);
|
2013-10-26 22:53:48 +04:00
|
|
|
|
strcat(CMD, ".shell");
|
|
|
|
|
if ( !file_check(CMD) )
|
|
|
|
|
strcpy(CMD, "/sys/settings/.shell");
|
2013-10-27 03:26:02 +04:00
|
|
|
|
}
|
2013-10-09 01:38:43 +04:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (PARAM[0] == '/')
|
|
|
|
|
{
|
|
|
|
|
strcpy(cur_dir, PARAM);
|
2013-10-27 03:26:02 +04:00
|
|
|
|
*(strrchr(cur_dir, '/')+1)=0;
|
2013-10-09 01:38:43 +04:00
|
|
|
|
}
|
2008-12-14 14:55:46 +03:00
|
|
|
|
strcpy(CMD, PARAM);
|
2013-10-09 01:38:43 +04:00
|
|
|
|
}
|
2008-12-14 14:55:46 +03:00
|
|
|
|
|
|
|
|
|
command_execute();
|
|
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
|
{
|
2020-04-17 00:50:49 +03:00
|
|
|
|
//printf("\033[32;1m");
|
2008-12-14 14:55:46 +03:00
|
|
|
|
printf ("# ");
|
2020-04-17 00:50:49 +03:00
|
|
|
|
//printf("\033[0m");
|
2008-12-14 14:55:46 +03:00
|
|
|
|
command_get();
|
|
|
|
|
command_execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_exit(0);
|
|
|
|
|
kol_exit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// ===========================================================
|