SHELL 0.8.2
- big refactoring, now uses libc.obj - added kfetch command git-svn-id: svn://kolibrios.org@8827 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
@@ -1,188 +1,170 @@
|
||||
|
||||
#include "all.h"
|
||||
|
||||
/// ===========================================================
|
||||
|
||||
int dir_check(char dir[])
|
||||
/// just checks, if dir[] is really a directory
|
||||
{
|
||||
kol_struct70 k70;
|
||||
int result;
|
||||
kol_struct70 k70;
|
||||
int result;
|
||||
|
||||
k70.p00 = 1;
|
||||
k70.p04 = 0;
|
||||
//k70.p08 = 0;
|
||||
k70.p12 = 2; // enough to read . & ..
|
||||
k70.p16 = (unsigned)malloc(32+k70.p12*560);
|
||||
k70.p20 = 0;
|
||||
k70.p21 = dir;
|
||||
k70.p00 = 1;
|
||||
k70.p04 = 0;
|
||||
//k70.p08 = 0;
|
||||
k70.p12 = 2; // enough to read . & ..
|
||||
k70.p16 = (unsigned)malloc(32+k70.p12*560);
|
||||
k70.p20 = 0;
|
||||
k70.p21 = dir;
|
||||
|
||||
result = kol_file_70(&k70);
|
||||
result = kol_file_70(&k70);
|
||||
|
||||
free((void*)k70.p16);
|
||||
free((void*)k70.p16);
|
||||
|
||||
if ( (0 == result)||(6 == result) ) // 6 is possible ???
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
if ( (0 == result)||(6 == result) ) // 6 is possible ???
|
||||
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;
|
||||
}
|
||||
int i;
|
||||
i = strlen(dir)-1;
|
||||
for (;;i--)
|
||||
if ('/' == dir[i])
|
||||
{
|
||||
dir[i+1] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/// ===========================================================
|
||||
|
||||
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';
|
||||
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';
|
||||
}
|
||||
|
||||
/// ===========================================================
|
||||
|
||||
int file_check(char file[])
|
||||
{
|
||||
kol_struct70 k70;
|
||||
int result;
|
||||
kol_struct70 k70;
|
||||
int result;
|
||||
|
||||
k70.p00 = 0;
|
||||
k70.p04 = 0;
|
||||
//k70.p08 = 0;
|
||||
k70.p12 = 0;
|
||||
k70.p16 = 0;
|
||||
k70.p20 = 0;
|
||||
k70.p21 = file;
|
||||
k70.p00 = 0;
|
||||
k70.p04 = 0;
|
||||
//k70.p08 = 0;
|
||||
k70.p12 = 0;
|
||||
k70.p16 = 0;
|
||||
k70.p20 = 0;
|
||||
k70.p21 = file;
|
||||
|
||||
result = kol_file_70(&k70);
|
||||
result = kol_file_70(&k70);
|
||||
|
||||
if (0 == result)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
if (0 == result)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/// ===========================================================
|
||||
|
||||
void file_not_found(char file[])
|
||||
{
|
||||
#if LANG_ENG
|
||||
printf (" File '%s' not found.\n\r", file);
|
||||
#elif LANG_RUS
|
||||
printf (" ” ©« '%s' ¥ ©¤¥.\n\r", file);
|
||||
#endif
|
||||
void file_not_found(char file[]) {
|
||||
printf (FILE_NOT_FOUND_ERROR, file);
|
||||
}
|
||||
|
||||
/// ===========================================================
|
||||
|
||||
int iswhite(char c)
|
||||
{
|
||||
return ((' ' == c) || ('\t' == c) || (13 == c) || (10 == c));
|
||||
}
|
||||
|
||||
/// ===========================================================
|
||||
int iswhite(char c) {return ((' ' == c) || ('\t' == c) || (13 == c) || (10 == c)); }
|
||||
|
||||
void trim(char string[])
|
||||
{
|
||||
int i, j;
|
||||
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 ( !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;
|
||||
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()
|
||||
// entry point
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i; for (i = 1; i < argc; i++) {
|
||||
strcat(cmdline, argv[i]);
|
||||
if (i != argc - 1) {
|
||||
strcat(cmdline, " ");
|
||||
}
|
||||
}
|
||||
|
||||
NUM_OF_CMD = sizeof(COMMANDS)/sizeof(COMMANDS[0]);
|
||||
NUM_OF_CMD = sizeof(COMMANDS)/sizeof(COMMANDS[0]);
|
||||
strcpy(title, "SHELL ");
|
||||
strcat(title, SHELL_VERSION);
|
||||
con_init_opt(-1, -1, -1, -1, title);
|
||||
|
||||
strcpy(title, "SHELL ");
|
||||
strcat(title, SHELL_VERSION);
|
||||
CONSOLE_INIT(title);
|
||||
//printf("argc = %d\ncmdline = '%s'\n", argc, cmdline);
|
||||
|
||||
if (sizeof (kol_struct70) != 25)
|
||||
{
|
||||
printf("Invalid struct align kol_struct70, need to fix compile options\n\r");
|
||||
kol_exit();
|
||||
if (sizeof (kol_struct70) != 25) {
|
||||
printf("Invalid struct align kol_struct70, need to fix compile options\n\r");
|
||||
kol_exit();
|
||||
}
|
||||
|
||||
//strcpy(cur_dir, PATH);
|
||||
//dir_truncate(cur_dir);
|
||||
getcwd(cur_dir, sizeof cur_dir);
|
||||
//printf("curdir %s\n", cur_dir);
|
||||
|
||||
con_set_cursor_height(con_get_font_height()-1);
|
||||
|
||||
ALIASES = malloc(128*1024);
|
||||
|
||||
if (!cmdline || cmdline[0] == 0) {
|
||||
strcpy(CMD, argv[0]);
|
||||
dir_truncate(CMD);
|
||||
strcat(CMD, ".shell");
|
||||
if ( !file_check(CMD) )
|
||||
strcpy(CMD, "/sys/settings/.shell");
|
||||
}
|
||||
else {
|
||||
if (cmdline[0] == '/')
|
||||
{
|
||||
strcpy(cur_dir, cmdline);
|
||||
*(strrchr(cur_dir, '/')+1)=0;
|
||||
}
|
||||
strcpy(CMD, cmdline);
|
||||
}
|
||||
|
||||
command_execute();
|
||||
|
||||
for (;;) {
|
||||
//printf("\033[32;1m");
|
||||
printf ("# ");
|
||||
//printf("\033[0m");
|
||||
command_get();
|
||||
command_execute();
|
||||
}
|
||||
|
||||
con_exit(0);
|
||||
kol_exit();
|
||||
}
|
||||
|
||||
|
||||
//strcpy(cur_dir, PATH);
|
||||
//dir_truncate(cur_dir);
|
||||
getcwd(cur_dir, sizeof cur_dir);
|
||||
//printf("curdir %s\n", cur_dir);
|
||||
|
||||
con_set_cursor_height(con_get_font_height()-1);
|
||||
|
||||
ALIASES = malloc(128*1024);
|
||||
|
||||
if (!PARAM || PARAM[0] == 0)
|
||||
{
|
||||
strcpy(CMD, PATH);
|
||||
dir_truncate(CMD);
|
||||
strcat(CMD, ".shell");
|
||||
if ( !file_check(CMD) )
|
||||
strcpy(CMD, "/sys/settings/.shell");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (PARAM[0] == '/')
|
||||
{
|
||||
strcpy(cur_dir, PARAM);
|
||||
*(strrchr(cur_dir, '/')+1)=0;
|
||||
}
|
||||
strcpy(CMD, PARAM);
|
||||
}
|
||||
|
||||
command_execute();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
//printf("\033[32;1m");
|
||||
printf ("# ");
|
||||
//printf("\033[0m");
|
||||
command_get();
|
||||
command_execute();
|
||||
}
|
||||
|
||||
_exit(0);
|
||||
kol_exit();
|
||||
}
|
||||
|
||||
/// ===========================================================
|
||||
|
||||
Reference in New Issue
Block a user