Compare commits
5 Commits
shell-impr
...
8fb2204f8b
| Author | SHA1 | Date | |
|---|---|---|---|
| 8fb2204f8b | |||
|
|
c580d4ac5b | ||
|
|
17c33521c3 | ||
|
|
f6395c9501 | ||
|
|
000288ce8b |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -9,4 +9,3 @@ ehthumbs_vista.db
|
||||
._*
|
||||
programs/cmm/cmm.code-workspace
|
||||
programs/cmm/menu/.gitignore
|
||||
.vscode
|
||||
|
||||
@@ -122,7 +122,13 @@ struc fpcvt
|
||||
.sizeof:
|
||||
}
|
||||
|
||||
;-----------------------------------------------------------------------------
|
||||
; Command flags
|
||||
|
||||
CMD_WITHOUT_PARAM = 1b ; command may be called without parameters
|
||||
CMD_WITH_PARAM = 10b ; command may be called with parameters
|
||||
CMD_WITHOUT_LOADED_APP = 100b ; command may be called without loaded program
|
||||
CMD_WITH_LOADED_APP = 1000b ; command may be called with loaded program
|
||||
|
||||
;-----------------------------------------------------------------------------
|
||||
; Entry point
|
||||
@@ -449,63 +455,56 @@ z1:
|
||||
mov esi, commands
|
||||
call find_cmd
|
||||
mov eax, aUnknownCommand
|
||||
jc .x11
|
||||
|
||||
; check command requirements
|
||||
; flags field:
|
||||
; &1: command may be called without parameters
|
||||
; &2: command may be called with parameters
|
||||
; &4: command may be called without loaded program
|
||||
; &8: command may be called with loaded program
|
||||
jc .cmd_procg
|
||||
mov eax, [esi+8]
|
||||
mov ecx, [curarg]
|
||||
cmp byte [ecx], 0
|
||||
jz .noargs
|
||||
test byte [esi+16], 2
|
||||
jz .x11
|
||||
test byte [esi+16], CMD_WITH_PARAM
|
||||
jz .cmd_procg
|
||||
jmp @f
|
||||
|
||||
.noargs:
|
||||
test byte [esi+16], 1
|
||||
jz .x11
|
||||
test byte [esi+16], CMD_WITHOUT_PARAM
|
||||
jz .cmd_procg
|
||||
|
||||
@@:
|
||||
cmp [debuggee_pid], 0
|
||||
jz .nodebuggee
|
||||
mov eax, aAlreadyLoaded
|
||||
test byte [esi+16], 8
|
||||
jz .x11
|
||||
jmp .x9
|
||||
test byte [esi+16], CMD_WITH_LOADED_APP
|
||||
jz .cmd_procg
|
||||
jmp .run_cmd
|
||||
|
||||
.nodebuggee:
|
||||
mov eax, need_debuggee
|
||||
test byte [esi+16], 4
|
||||
jnz .x9
|
||||
mov eax, aNeedDebuggee
|
||||
test byte [esi+16], CMD_WITHOUT_LOADED_APP
|
||||
jnz .run_cmd
|
||||
|
||||
.x11:
|
||||
.cmd_procg:
|
||||
xchg esi, eax
|
||||
call put_message
|
||||
|
||||
; store cmdline for repeating
|
||||
.x10:
|
||||
.cmd_procg_no_put_msg:
|
||||
mov esi, cmdline
|
||||
mov ecx, [cmdline_len]
|
||||
|
||||
@@:
|
||||
cmp ecx, 0
|
||||
jle .we
|
||||
jle .wait_event
|
||||
mov al, [esi + ecx]
|
||||
mov [cmdline_prev + ecx], al
|
||||
dec ecx
|
||||
jmp @b
|
||||
|
||||
.we:
|
||||
.wait_event:
|
||||
mov [cmdline_len], 0
|
||||
jmp waitevent
|
||||
|
||||
.x9:
|
||||
.run_cmd:
|
||||
call dword [esi+4]
|
||||
jmp .x10
|
||||
jmp .cmd_procg_no_put_msg
|
||||
|
||||
;-----------------------------------------------------------------------------
|
||||
; Cmdline handling
|
||||
|
||||
@@ -1880,66 +1880,85 @@ help_groups:
|
||||
;-----------------------------------------------------------------------------
|
||||
; Commands format definitions
|
||||
|
||||
; TODO: make it with macros
|
||||
|
||||
; flags field:
|
||||
; &1: command may be called without parameters
|
||||
; &2: command may be called with parameters
|
||||
; &4: command may be called without loaded program
|
||||
; &8: command may be called with loaded program
|
||||
commands:
|
||||
dd _aH, OnHelp, HelpSyntax, HelpHelp
|
||||
db 0Fh
|
||||
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITHOUT_LOADED_APP or CMD_WITH_LOADED_APP
|
||||
|
||||
dd aHelp, OnHelp, HelpSyntax, HelpHelp
|
||||
db 0Fh
|
||||
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITHOUT_LOADED_APP or CMD_WITH_LOADED_APP
|
||||
|
||||
dd aQuit, OnQuit, QuitSyntax, QuitHelp
|
||||
db 0Dh
|
||||
db CMD_WITHOUT_PARAM or CMD_WITHOUT_LOADED_APP or CMD_WITH_LOADED_APP
|
||||
|
||||
dd aLoad, OnLoad, LoadSyntax, LoadHelp
|
||||
db 6
|
||||
db CMD_WITH_PARAM or CMD_WITHOUT_LOADED_APP
|
||||
|
||||
dd aReload, OnReload, ReloadSyntax, ReloadHelp
|
||||
db 0Dh
|
||||
db CMD_WITHOUT_PARAM or CMD_WITHOUT_LOADED_APP or CMD_WITH_LOADED_APP
|
||||
|
||||
dd aTerminate, OnTerminate, TerminateSyntax, TerminateHelp
|
||||
db 9
|
||||
db CMD_WITHOUT_PARAM or CMD_WITH_LOADED_APP
|
||||
|
||||
dd aDetach, OnDetach, DetachSyntax, DetachHelp
|
||||
db 9
|
||||
db CMD_WITHOUT_PARAM or CMD_WITH_LOADED_APP
|
||||
|
||||
dd aSuspend, OnSuspend, SuspendSyntax, SuspendHelp
|
||||
db 9
|
||||
db CMD_WITHOUT_PARAM or CMD_WITH_LOADED_APP
|
||||
|
||||
dd aResume, OnResume, ResumeSyntax, ResumeHelp
|
||||
db 0Bh
|
||||
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITH_LOADED_APP
|
||||
|
||||
dd aStep, OnStepMultiple, StepSyntax, StepHelp
|
||||
db 0Bh
|
||||
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITH_LOADED_APP
|
||||
|
||||
dd aProceed, OnProceedMultiple, ProceedSyntax, ProceedHelp
|
||||
db 0Bh
|
||||
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITH_LOADED_APP
|
||||
|
||||
dd aCalc, OnCalc, CalcSyntax, CalcHelp
|
||||
db 0Eh
|
||||
db CMD_WITH_PARAM or CMD_WITHOUT_LOADED_APP or CMD_WITH_LOADED_APP
|
||||
|
||||
dd aDump, OnDump, DumpSyntax, DumpHelp
|
||||
db 0Bh
|
||||
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITH_LOADED_APP
|
||||
|
||||
dd aUnassemble, OnUnassemble, UnassembleSyntax, UnassembleHelp
|
||||
db 0Bh
|
||||
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITH_LOADED_APP
|
||||
|
||||
dd aBp, OnBp, BpSyntax, BpHelp
|
||||
db 0Ah
|
||||
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
|
||||
|
||||
dd aBpm, OnBpmb, BpmSyntax, BpmHelp
|
||||
db 0Ah
|
||||
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
|
||||
|
||||
dd aBpmb, OnBpmb, BpmSyntax, BpmHelp
|
||||
db 0Ah
|
||||
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
|
||||
|
||||
dd aBpmw, OnBpmw, BpmSyntax, BpmHelp
|
||||
db 0Ah
|
||||
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
|
||||
|
||||
dd aBpmd, OnBpmd, BpmSyntax, BpmHelp
|
||||
db 0Ah
|
||||
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
|
||||
|
||||
dd aBl, OnBl, BlSyntax, BlHelp
|
||||
db 0Bh
|
||||
db CMD_WITHOUT_PARAM or CMD_WITH_PARAM or CMD_WITH_LOADED_APP
|
||||
|
||||
dd aBc, OnBc, BcSyntax, BcHelp
|
||||
db 0Ah
|
||||
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
|
||||
|
||||
dd aBd, OnBd, BdSyntax, BdHelp
|
||||
db 0Ah
|
||||
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
|
||||
|
||||
dd aBe, OnBe, BeSyntax, BeHelp
|
||||
db 0Ah
|
||||
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
|
||||
|
||||
dd aReg, OnReg, RSyntax, RHelp
|
||||
db 0Ah
|
||||
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
|
||||
|
||||
dd aUnpack, OnUnpack, UnpackSyntax, UnpackHelp
|
||||
db 9
|
||||
db CMD_WITHOUT_PARAM or CMD_WITH_LOADED_APP
|
||||
|
||||
dd aLoadSymbols, OnLoadSymbols, LoadSymbolsSyntax, LoadSymbolsHelp
|
||||
db 0Ah
|
||||
db CMD_WITH_PARAM or CMD_WITH_LOADED_APP
|
||||
|
||||
dd 0
|
||||
|
||||
;-----------------------------------------------------------------------------
|
||||
|
||||
@@ -84,6 +84,7 @@ commands: ; all commands must be in uppercase
|
||||
; dd 'APPE', login_first, login_first, login_first, cmd_APPE
|
||||
dd 'CDUP', login_first, login_first, login_first, cmdCDUP
|
||||
dd 'CWD', login_first, login_first, login_first, cmdCWD
|
||||
dd 'XCWD', login_first, login_first, login_first, cmdCWD
|
||||
dd 'DELE', login_first, login_first, login_first, cmdDELE
|
||||
; dd 'HELP', login_first, login_first, login_first, cmd_HELP
|
||||
dd 'LIST', login_first, login_first, login_first, cmdLIST
|
||||
@@ -96,6 +97,7 @@ commands: ; all commands must be in uppercase
|
||||
dd 'PASV', login_first, login_first, login_first, cmdPASV
|
||||
dd 'PORT', login_first, login_first, login_first, cmdPORT
|
||||
dd 'PWD', login_first, login_first, login_first, cmdPWD
|
||||
dd 'XPWD', login_first, login_first, login_first, cmdPWD
|
||||
dd 'QUIT', cmdQUIT, cmdQUIT, cmdQUIT, cmdQUIT
|
||||
; dd 'REIN', login_first, login_first, login_first, cmd_REIN
|
||||
; dd 'REST', login_first, login_first, login_first, cmd_REST
|
||||
@@ -342,7 +344,7 @@ align 4
|
||||
cmdABOR:
|
||||
|
||||
or [ebp + thread_data.permissions], ABORT
|
||||
sendFTP "250 Command succesul"
|
||||
sendFTP "250 Command successful"
|
||||
ret
|
||||
|
||||
;------------------------------------------------
|
||||
@@ -383,7 +385,7 @@ cmdCDUP:
|
||||
invoke con_write_asciiz, eax
|
||||
invoke con_write_asciiz, str_newline
|
||||
|
||||
sendFTP "250 Command succesul"
|
||||
sendFTP "250 Command successful"
|
||||
ret
|
||||
|
||||
;------------------------------------------------
|
||||
@@ -448,7 +450,7 @@ cmdCWD:
|
||||
invoke con_write_asciiz, eax
|
||||
invoke con_write_asciiz, str_newline
|
||||
|
||||
sendFTP "250 Command succesful"
|
||||
sendFTP "250 Command successful"
|
||||
ret
|
||||
|
||||
.err:
|
||||
@@ -510,7 +512,7 @@ cmdDELE:
|
||||
test eax, eax
|
||||
jnz .err
|
||||
|
||||
sendFTP "250 Command succesful"
|
||||
sendFTP "250 Command successful"
|
||||
ret
|
||||
.err:
|
||||
sendFTP "550 No such file"
|
||||
@@ -998,7 +1000,9 @@ cmdRETR:
|
||||
cmp eax, -1
|
||||
je .cannot_open ; FIXME: this is not the correct error
|
||||
|
||||
push eax
|
||||
invoke con_write_asciiz, str2
|
||||
pop eax
|
||||
|
||||
push eax ebx
|
||||
mov esi, eax
|
||||
|
||||
@@ -26,8 +26,8 @@ int cmd_kfetch(char param[]) {
|
||||
char str_resolution[24];
|
||||
ksys_pos_t resol = _ksys_screen_size();
|
||||
sprintf(str_resolution, "%u x %u", resol.x + 1, resol.y + 1);
|
||||
char str_cpu_info[50];
|
||||
get_cpu_brand_string(str_cpu_info);
|
||||
char str_cpu_info[16];
|
||||
get_str_cpu_info(str_cpu_info);
|
||||
char str_meminfo[24];
|
||||
get_str_meminfo(str_meminfo);
|
||||
|
||||
@@ -53,7 +53,7 @@ int cmd_kfetch(char param[]) {
|
||||
"\033[0;34;40m \033[0;31;40m \033[0;32;40mS\033[0;34;40m@\033[0;5;34;40mX\033[0;1;35;45m.\033[0;1;34;44m8\033[0;5;35;45m \033[0;5;34;44m \033[0;1;30;45m8\033[0;5;35;44m:\033[0;5;37;45m@\033[0;1;30;40m8\033[0;31;40m.\033[0;34;40m \033[0;31;40m \033[0;34;40m \033[0m\n\r"
|
||||
"\033[0;34;40m \033[0;31;40m \033[0;32;40m \033[0;31;40m.\033[0;32;40m;\033[0;34;40m;8\033[0;32;40m%%\033[0;5;34;40m8\033[0;34;40m8\033[0;1;30;44m8\033[0;1;30;40m8\033[0;34;40m;.\033[0;31;40m \033[0;34;40m \033[0;31;40m \033[0;34;40m \033[0m\n\r"
|
||||
"\033[0;34;40m \033[0;32;40m \033[0;31;40m \033[0;32;40m.\033[0;31;40m.\033[0;32;40m.\033[0;31;40m.\033[0;32;40m.\033[0;31;40m:. \033[0;32;40m. \033[0;34;40m \033[0;31;40m \033[0;34;40m \033[0m\n\r",
|
||||
|
||||
|
||||
"\033[0;36mOS\033[0m: KolibriOS ", str_os_rel_offset_dbgtag, "\033[0;36mKernel\033[0m: ", str_krn_abi_cmtid, "\033[0;36mUptime\033[0m: ", str_uptime, "\033[0;36mResolution\033[0m: ", str_resolution, "\033[0;36mCPU\033[0m: ", str_cpu_info, "\033[0;36mMemory\033[0m: ", str_meminfo
|
||||
);
|
||||
|
||||
|
||||
@@ -1,72 +1,65 @@
|
||||
#include "../system/kolibri.h"
|
||||
|
||||
void get_str_kernel_version(char *str, const char *fmt) {
|
||||
struct kernel_version kv;
|
||||
|
||||
kol_get_kernel_ver(&kv);
|
||||
char str_offset[8] = {'\0'};
|
||||
if (kv.offset)
|
||||
sprintf(str_offset, "+%u", kv.offset);
|
||||
char str_dbgtag[4] = {'\0'};
|
||||
if (kv.dbgtag)
|
||||
sprintf(str_dbgtag, "-%c", kv.dbgtag);
|
||||
char str_cmtid[16] = {'\0'};
|
||||
if (kv.cmtid)
|
||||
sprintf(str_cmtid, " (%08x)", kv.cmtid);
|
||||
|
||||
sprintf(str, fmt, kv.osrel[0], kv.osrel[1], kv.osrel[2], kv.osrel[3],
|
||||
str_offset, str_dbgtag, str_cmtid, kv.abimaj, kv.abimin);
|
||||
}
|
||||
|
||||
// Retrieves the CPU Brand String and writes it to the provided buffer.
|
||||
// out_buffer: A buffer of at least 49 bytes (48 for string + 1 for null)
|
||||
void get_cpu_brand_string(char *out_buffer) {
|
||||
if (!out_buffer) return;
|
||||
|
||||
uint32_t regs[4];
|
||||
|
||||
// 1. Check maximum extended function support
|
||||
__asm__ (
|
||||
"cpuid"
|
||||
: "=a" (regs[0]), "=b" (regs[1]), "=c" (regs[2]), "=d" (regs[3])
|
||||
: "a" (0x80000000)
|
||||
);
|
||||
|
||||
if (regs[0] < 0x80000004) {
|
||||
strcpy(out_buffer, "Brand String Not Supported");
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Extract brand string from leaves 0x80000002 to 0x80000004
|
||||
for (uint32_t leaf = 0x80000002; leaf <= 0x80000004; leaf++) {
|
||||
__asm__ (
|
||||
"cpuid"
|
||||
: "=a" (regs[0]), "=b" (regs[1]), "=c" (regs[2]), "=d" (regs[3])
|
||||
: "a" (leaf)
|
||||
);
|
||||
|
||||
// Copy the 16 bytes (4 registers * 4 bytes) from this leaf into the buffer
|
||||
memcpy(out_buffer + (leaf - 0x80000002) * 16, regs, 16);
|
||||
}
|
||||
|
||||
out_buffer[48] = '\0';
|
||||
}
|
||||
|
||||
int cmd_ver(char param[]) {
|
||||
if (!strcmp(param, "kernel")) {
|
||||
get_str_kernel_version(tmpstr, CMD_VER_FMT1);
|
||||
printf(tmpstr);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (!strcmp(param, "cpu")) {
|
||||
char str[49];
|
||||
get_cpu_brand_string(str);
|
||||
printf("%s\n\r", str);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
printf (" Shell v%s\n\r", SHELL_VERSION);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#include "../system/kolibri.h"
|
||||
|
||||
void get_str_kernel_version(char *str, const char *fmt) {
|
||||
struct kernel_version kv;
|
||||
|
||||
kol_get_kernel_ver(&kv);
|
||||
char str_offset[8] = {'\0'};
|
||||
if (kv.offset)
|
||||
sprintf(str_offset, "+%u", kv.offset);
|
||||
char str_dbgtag[4] = {'\0'};
|
||||
if (kv.dbgtag)
|
||||
sprintf(str_dbgtag, "-%c", kv.dbgtag);
|
||||
char str_cmtid[16] = {'\0'};
|
||||
if (kv.cmtid)
|
||||
sprintf(str_cmtid, " (%08x)", kv.cmtid);
|
||||
|
||||
sprintf(str, fmt, kv.osrel[0], kv.osrel[1], kv.osrel[2], kv.osrel[3],
|
||||
str_offset, str_dbgtag, str_cmtid, kv.abimaj, kv.abimin);
|
||||
}
|
||||
|
||||
void get_str_cpu_info(char *str) {
|
||||
unsigned a, b, c, d;
|
||||
|
||||
asm ("cpuid" :
|
||||
"=a" (a),
|
||||
"=b" (b),
|
||||
"=c" (c),
|
||||
"=d" (d):
|
||||
"a"(0));
|
||||
|
||||
str[0] = (b&0x000000ff) >> 0;
|
||||
str[1] = (b&0x0000ff00) >> 8;
|
||||
str[2] = (b&0x00ff0000) >> 16;
|
||||
str[3] = (b&0xff000000) >> 24;
|
||||
|
||||
str[4] = (d&0x000000ff) >> 0;
|
||||
str[5] = (d&0x0000ff00) >> 8;
|
||||
str[6] = (d&0x00ff0000) >> 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;
|
||||
str[12] = '\0';
|
||||
}
|
||||
|
||||
int cmd_ver(char param[]) {
|
||||
if (!strcmp(param, "kernel")) {
|
||||
get_str_kernel_version(tmpstr, CMD_VER_FMT1);
|
||||
printf(tmpstr);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (!strcmp(param, "cpu")) {
|
||||
char str[13];
|
||||
get_str_cpu_info(str);
|
||||
printf("%s\n\r", str);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
printf (" Shell v%s\n\r", SHELL_VERSION);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,170 +1,170 @@
|
||||
|
||||
#include "all.h"
|
||||
|
||||
int dir_check(char dir[])
|
||||
/// just checks, if dir[] is really a directory
|
||||
{
|
||||
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;
|
||||
|
||||
result = kol_file_70(&k70);
|
||||
|
||||
free((void*)k70.p16);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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';
|
||||
}
|
||||
|
||||
|
||||
int file_check(char file[])
|
||||
{
|
||||
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;
|
||||
|
||||
result = kol_file_70(&k70);
|
||||
|
||||
if (0 == result)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
void file_not_found(char file[]) {
|
||||
printf (FILE_NOT_FOUND_ERROR, file);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
// 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]);
|
||||
strcpy(title, "SHELL ");
|
||||
strcat(title, SHELL_VERSION);
|
||||
con_init_opt(-1, -1, -1, -1, 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();
|
||||
}
|
||||
|
||||
//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();
|
||||
}
|
||||
|
||||
#include "all.h"
|
||||
|
||||
int dir_check(char dir[])
|
||||
/// just checks, if dir[] is really a directory
|
||||
{
|
||||
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;
|
||||
|
||||
result = kol_file_70(&k70);
|
||||
|
||||
free((void*)k70.p16);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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';
|
||||
}
|
||||
|
||||
|
||||
int file_check(char file[])
|
||||
{
|
||||
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;
|
||||
|
||||
result = kol_file_70(&k70);
|
||||
|
||||
if (0 == result)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
void file_not_found(char file[]) {
|
||||
printf (FILE_NOT_FOUND_ERROR, file);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
// 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]);
|
||||
strcpy(title, "SHELL ");
|
||||
strcat(title, SHELL_VERSION);
|
||||
con_init_opt(-1, -1, -1, -1, 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();
|
||||
}
|
||||
|
||||
//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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user