2010-10-17 21:50:55 +02:00
|
|
|
|
|
|
|
|
|
/// ===========================================================
|
|
|
|
|
|
2013-10-19 09:13:02 +02:00
|
|
|
|
void command_history_add()
|
2010-10-17 21:50:55 +02:00
|
|
|
|
{
|
|
|
|
|
|
2013-10-19 09:13:02 +02:00
|
|
|
|
int i;
|
2010-10-17 21:50:55 +02:00
|
|
|
|
|
2013-10-19 09:13:02 +02:00
|
|
|
|
for (i = 0; i < CMD_HISTORY_NUM_REAL; i++)
|
|
|
|
|
if ( 0 == strcmp( CMD_HISTORY[i], CMD ) )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (i = CMD_HISTORY_NUM_REAL; i > 0 ; i--)
|
|
|
|
|
strcpy(CMD_HISTORY[i], CMD_HISTORY[i-1]);
|
|
|
|
|
|
|
|
|
|
strcpy(CMD_HISTORY[0], CMD);
|
|
|
|
|
|
|
|
|
|
if (CMD_HISTORY_NUM_REAL < CMD_HISTORY_NUM-1)
|
|
|
|
|
CMD_HISTORY_NUM_REAL++;
|
|
|
|
|
|
|
|
|
|
CMD_NUM = 0;
|
2010-10-17 21:50:55 +02:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-19 09:13:02 +02:00
|
|
|
|
|
|
|
|
|
|
2010-10-17 21:50:55 +02:00
|
|
|
|
/// ===========================================================
|
|
|
|
|
|
|
|
|
|
void command_get()
|
|
|
|
|
{
|
|
|
|
|
unsigned key;
|
|
|
|
|
|
2013-10-13 12:47:59 +02:00
|
|
|
|
unsigned i;
|
|
|
|
|
unsigned cmdLen = 0;
|
|
|
|
|
unsigned cmdPos = 0;
|
|
|
|
|
CMD[0] = '\0';
|
2010-10-17 21:50:55 +02:00
|
|
|
|
|
2014-01-23 08:41:40 +01:00
|
|
|
|
int clipNum; // number of clipboard slots
|
|
|
|
|
char* clipBuf; // clipboard buffer
|
|
|
|
|
char clipCopy[255+12];
|
|
|
|
|
|
2010-10-17 21:50:55 +02:00
|
|
|
|
for (;;)
|
|
|
|
|
{
|
|
|
|
|
key = getch();
|
|
|
|
|
if ( 0 != (key & 0xff) )
|
|
|
|
|
{
|
|
|
|
|
key &= 0xff;
|
|
|
|
|
switch (key)
|
|
|
|
|
{
|
|
|
|
|
case 27: // ESC
|
2013-10-13 12:47:59 +02:00
|
|
|
|
for (i = cmdPos; i < cmdLen; i++)
|
|
|
|
|
printf(" ");
|
|
|
|
|
for (i = cmdLen; i > 0; i--)
|
|
|
|
|
printf("%c %c", 8, 8);
|
|
|
|
|
cmdLen = 0;
|
|
|
|
|
cmdPos = 0;
|
|
|
|
|
CMD[0] = '\0';
|
2010-10-17 21:50:55 +02:00
|
|
|
|
break;
|
|
|
|
|
|
2013-10-13 12:47:59 +02:00
|
|
|
|
|
2010-10-17 21:50:55 +02:00
|
|
|
|
case 13: // ENTER
|
|
|
|
|
printf("\n\r");
|
2013-10-19 09:13:02 +02:00
|
|
|
|
command_history_add();
|
2010-10-17 21:50:55 +02:00
|
|
|
|
return;
|
|
|
|
|
|
2013-10-13 12:47:59 +02:00
|
|
|
|
|
2010-10-17 21:50:55 +02:00
|
|
|
|
case 8: // BACKSPACE
|
2013-10-13 12:47:59 +02:00
|
|
|
|
if (cmdPos > 0)
|
2010-10-17 21:50:55 +02:00
|
|
|
|
{
|
2013-10-13 12:47:59 +02:00
|
|
|
|
for (i = cmdPos-1; i < cmdLen; i++)
|
2013-11-28 20:08:52 +01:00
|
|
|
|
CMD[i] = CMD[i+1];
|
2013-10-13 12:47:59 +02:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < cmdLen-cmdPos; i++)
|
|
|
|
|
printf (" ");
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < cmdLen; i++)
|
|
|
|
|
printf ("%c %c", 8, 8);
|
|
|
|
|
|
|
|
|
|
printf("%s", CMD);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < cmdLen-cmdPos; i++)
|
|
|
|
|
printf("%c", 8);
|
|
|
|
|
|
|
|
|
|
cmdPos--;
|
|
|
|
|
cmdLen--;
|
2010-10-17 21:50:55 +02:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2013-10-13 12:47:59 +02:00
|
|
|
|
|
2010-10-17 21:50:55 +02:00
|
|
|
|
case 9: // TAB
|
|
|
|
|
break;
|
2014-01-23 08:41:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 22: // Ctrl+V
|
|
|
|
|
clipNum = kol_clip_num();
|
|
|
|
|
if (clipNum > 0)
|
|
|
|
|
{
|
|
|
|
|
clipBuf = kol_clip_get(clipNum-1);
|
|
|
|
|
// printf("Length: %d, Type: %d, Encoding: %d\n", (int) *clipBuf, (int)*(clipBuf+4), (int)*(clipBuf+8));
|
|
|
|
|
if ( (int) *clipBuf > 0 ) // is clipboard empty?
|
|
|
|
|
{
|
|
|
|
|
if ((int)*(clipBuf+4)==0) // text?
|
|
|
|
|
{
|
|
|
|
|
if ((int)*(clipBuf+8)==1) // 866 encoding?
|
2010-10-17 21:50:55 +02:00
|
|
|
|
|
2014-01-23 08:41:40 +01:00
|
|
|
|
for (i = cmdPos; i < cmdLen; i++)
|
|
|
|
|
printf(" ");
|
|
|
|
|
for (i = cmdLen; i > 0; i--)
|
|
|
|
|
printf("%c %c", 8, 8);
|
|
|
|
|
cmdLen = 0;
|
|
|
|
|
cmdPos = 0;
|
|
|
|
|
CMD[0] = '\0';
|
2013-10-13 12:47:59 +02:00
|
|
|
|
|
2014-01-23 08:41:40 +01:00
|
|
|
|
// strcpy_n
|
|
|
|
|
for (i = 0; i < 255; i++)
|
|
|
|
|
{
|
|
|
|
|
CMD[i]=*(clipBuf+12+i);
|
|
|
|
|
if (CMD[i]=='\0')
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmdPos = cmdLen = strlen(CMD);
|
|
|
|
|
/*
|
|
|
|
|
printf("Length: %d\n", cmdLen);
|
|
|
|
|
for (i = 0; i < cmdLen; i++)
|
|
|
|
|
printf("%d ", CMD[i]);
|
|
|
|
|
*/
|
|
|
|
|
printf("%s", CMD);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 3: // Ctrl+C
|
|
|
|
|
if ( cmdLen > 0 )
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
*clipCopy = 12 + cmdLen;
|
|
|
|
|
*(clipCopy+4)=0;
|
|
|
|
|
*(clipCopy+8)=1;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i <= cmdLen; i++)
|
|
|
|
|
*(clipCopy+12+i) = CMD[i];
|
|
|
|
|
|
|
|
|
|
kol_clip_set(12+cmdLen, clipCopy);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
2010-10-17 21:50:55 +02:00
|
|
|
|
default:
|
2013-10-13 12:47:59 +02:00
|
|
|
|
if (cmdLen < 255)
|
2010-10-17 21:50:55 +02:00
|
|
|
|
{
|
2013-02-17 16:22:51 +01:00
|
|
|
|
if ( kol_key_control() & 0x40 ) // <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CapsLock
|
2013-10-13 12:47:59 +02:00
|
|
|
|
if ( (kol_key_control() & 1) || (kol_key_control() & 2)) // <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
2011-09-12 18:54:25 +02:00
|
|
|
|
key = tolower(key);
|
|
|
|
|
else
|
|
|
|
|
key = toupper(key);
|
|
|
|
|
|
2014-01-23 08:41:40 +01:00
|
|
|
|
for (i = cmdLen+1; i > cmdPos; i--)
|
|
|
|
|
CMD[i] = CMD[i-1];
|
2013-10-13 12:47:59 +02:00
|
|
|
|
|
|
|
|
|
CMD[cmdPos] = key;
|
|
|
|
|
|
2014-01-23 08:41:40 +01:00
|
|
|
|
for (i = cmdPos; i > 0; i--)
|
|
|
|
|
printf("%c %c", 8, 8);
|
2013-10-13 12:47:59 +02:00
|
|
|
|
|
|
|
|
|
printf("%s", CMD);
|
|
|
|
|
|
2014-01-23 08:41:40 +01:00
|
|
|
|
for (i = 0; i < cmdLen-cmdPos; i++)
|
|
|
|
|
printf("%c", 8);
|
2013-10-13 12:47:59 +02:00
|
|
|
|
|
|
|
|
|
cmdPos++;
|
2014-01-23 08:41:40 +01:00
|
|
|
|
cmdLen++;
|
2010-10-17 21:50:55 +02:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2014-01-23 08:41:40 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2010-10-17 21:50:55 +02:00
|
|
|
|
{
|
2014-01-23 08:41:40 +01:00
|
|
|
|
key = (key>>8)&0xff;
|
|
|
|
|
switch (key)
|
|
|
|
|
{
|
2013-10-13 12:47:59 +02:00
|
|
|
|
case 83: // Del
|
|
|
|
|
if (cmdPos < cmdLen)
|
|
|
|
|
{
|
|
|
|
|
for (i = cmdPos; i < cmdLen; i++)
|
|
|
|
|
CMD[i] = CMD[i+1];
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < cmdLen-cmdPos; i++)
|
|
|
|
|
printf(" ");
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < cmdLen-cmdPos; i++)
|
|
|
|
|
printf("%c", 8);
|
|
|
|
|
|
|
|
|
|
for (i = cmdPos; i < cmdLen; i++)
|
|
|
|
|
printf("%c", CMD[i]);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < cmdLen-cmdPos; i++)
|
|
|
|
|
printf("%c", 8);
|
|
|
|
|
|
|
|
|
|
cmdLen--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 75: // Left
|
|
|
|
|
if (cmdPos > 0)
|
|
|
|
|
{
|
|
|
|
|
printf("%c", 8);
|
|
|
|
|
cmdPos--;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 77: // Right
|
|
|
|
|
if (cmdPos < cmdLen)
|
|
|
|
|
{
|
|
|
|
|
printf("%c", CMD[cmdPos]);
|
|
|
|
|
cmdPos++;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2010-10-17 21:50:55 +02:00
|
|
|
|
|
2013-02-16 12:25:37 +01:00
|
|
|
|
case 80: // Down
|
2013-10-19 09:13:02 +02:00
|
|
|
|
|
|
|
|
|
if (CMD_HISTORY_NUM_REAL > 0)
|
2010-10-17 21:50:55 +02:00
|
|
|
|
{
|
2013-10-13 12:47:59 +02:00
|
|
|
|
|
2013-10-19 09:13:02 +02:00
|
|
|
|
for (i = cmdPos; i < cmdLen; i++)
|
|
|
|
|
printf(" ");
|
2013-10-13 12:47:59 +02:00
|
|
|
|
|
2013-10-19 09:13:02 +02:00
|
|
|
|
for (i = cmdLen; i > 0; i--)
|
|
|
|
|
printf("%c %c", 8, 8);
|
2010-10-17 21:50:55 +02:00
|
|
|
|
|
2013-10-19 09:13:02 +02:00
|
|
|
|
if (CMD_NUM < CMD_HISTORY_NUM_REAL-1)
|
|
|
|
|
CMD_NUM++;
|
|
|
|
|
else
|
2010-10-17 21:50:55 +02:00
|
|
|
|
CMD_NUM = 0;
|
2013-10-13 12:47:59 +02:00
|
|
|
|
|
2013-11-28 20:08:52 +01:00
|
|
|
|
printf( "%s", CMD_HISTORY[CMD_NUM] );
|
2010-10-17 21:50:55 +02:00
|
|
|
|
strcpy(CMD, CMD_HISTORY[CMD_NUM]);
|
2013-10-19 09:13:02 +02:00
|
|
|
|
cmdLen = strlen(CMD);
|
|
|
|
|
cmdPos = strlen(CMD);
|
2013-10-13 12:47:59 +02:00
|
|
|
|
|
2010-10-17 21:50:55 +02:00
|
|
|
|
}
|
2013-10-19 09:13:02 +02:00
|
|
|
|
|
2010-10-17 21:50:55 +02:00
|
|
|
|
break;
|
|
|
|
|
|
2013-10-13 12:47:59 +02:00
|
|
|
|
|
2013-02-16 12:25:37 +01:00
|
|
|
|
case 72: // Up
|
2013-10-19 09:13:02 +02:00
|
|
|
|
if (CMD_HISTORY_NUM_REAL > 0)
|
2010-10-17 21:50:55 +02:00
|
|
|
|
{
|
2013-10-13 12:47:59 +02:00
|
|
|
|
|
2013-10-19 09:13:02 +02:00
|
|
|
|
for (i = cmdPos; i < cmdLen; i++)
|
|
|
|
|
printf(" ");
|
2013-10-13 12:47:59 +02:00
|
|
|
|
|
2013-10-19 09:13:02 +02:00
|
|
|
|
for (i = cmdLen; i > 0; i--)
|
|
|
|
|
printf("%c %c", 8, 8);
|
2010-10-17 21:50:55 +02:00
|
|
|
|
|
2013-10-19 09:13:02 +02:00
|
|
|
|
if (CMD_NUM > 0)
|
|
|
|
|
CMD_NUM--;
|
|
|
|
|
else
|
|
|
|
|
CMD_NUM = CMD_HISTORY_NUM_REAL-1;
|
2010-10-17 21:50:55 +02:00
|
|
|
|
|
2013-11-28 20:08:52 +01:00
|
|
|
|
printf( "%s", CMD_HISTORY[CMD_NUM] );
|
2010-10-17 21:50:55 +02:00
|
|
|
|
strcpy(CMD, CMD_HISTORY[CMD_NUM]);
|
2013-10-19 09:13:02 +02:00
|
|
|
|
cmdLen = strlen(CMD);
|
|
|
|
|
cmdPos = strlen(CMD);
|
|
|
|
|
|
2010-10-17 21:50:55 +02:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2013-10-13 12:47:59 +02:00
|
|
|
|
|
2010-10-17 21:50:55 +02:00
|
|
|
|
case 0: // console window closed
|
|
|
|
|
cmd_exit(NULL);
|
|
|
|
|
|
2013-10-13 12:47:59 +02:00
|
|
|
|
}
|
2010-10-17 21:50:55 +02:00
|
|
|
|
|
2013-10-13 12:47:59 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-10-17 21:50:55 +02:00
|
|
|
|
|
2013-10-13 12:47:59 +02:00
|
|
|
|
}
|
2010-10-17 21:50:55 +02:00
|
|
|
|
|
|
|
|
|
/// ===========================================================
|
|
|
|
|
|
|
|
|
|
int command_get_cmd(char cmd[])
|
|
|
|
|
{
|
2013-02-16 12:25:37 +01:00
|
|
|
|
unsigned i, len;
|
|
|
|
|
int quote = 0;
|
|
|
|
|
|
|
|
|
|
if (CMD[0]=='"')
|
|
|
|
|
quote = 1;
|
|
|
|
|
|
|
|
|
|
if (quote == 0)
|
|
|
|
|
{
|
|
|
|
|
for (i=0;;i++)
|
|
|
|
|
{
|
2010-10-17 21:50:55 +02:00
|
|
|
|
cmd[i] = CMD[i];
|
|
|
|
|
if (0 == cmd[i])
|
2014-12-01 12:38:20 +01:00
|
|
|
|
return i;
|
2010-10-17 21:50:55 +02:00
|
|
|
|
if ( iswhite(cmd[i]) )
|
|
|
|
|
{
|
2013-02-16 12:25:37 +01:00
|
|
|
|
cmd[i] = '\0';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return i+1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
len = 0;
|
|
|
|
|
for (i=1;;i++)
|
|
|
|
|
{
|
|
|
|
|
cmd[len] = CMD[i];
|
|
|
|
|
if (0 == cmd[len])
|
|
|
|
|
{
|
2014-12-01 12:38:20 +01:00
|
|
|
|
i--;
|
2010-10-17 21:50:55 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2013-02-16 12:25:37 +01:00
|
|
|
|
if ( cmd[len] == '"' )
|
|
|
|
|
{
|
|
|
|
|
cmd[len] = '\0';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
len++;
|
2010-10-17 21:50:55 +02:00
|
|
|
|
}
|
2013-02-16 12:25:37 +01:00
|
|
|
|
trim(cmd);
|
2014-12-01 12:38:20 +01:00
|
|
|
|
return i+1;
|
2013-02-16 12:25:37 +01:00
|
|
|
|
}
|
2010-10-17 21:50:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// ===========================================================
|
|
|
|
|
|
2013-02-17 16:22:51 +01:00
|
|
|
|
typedef int (*handler1_t)(char* arg);
|
2010-10-17 21:50:55 +02:00
|
|
|
|
|
|
|
|
|
/// ===========================================================
|
|
|
|
|
|
|
|
|
|
void command_execute()
|
|
|
|
|
{
|
|
|
|
|
char cmd[256];
|
|
|
|
|
char args[256];
|
|
|
|
|
unsigned arg;
|
|
|
|
|
int i;
|
2013-02-17 16:22:51 +01:00
|
|
|
|
int result;
|
2010-10-17 21:50:55 +02:00
|
|
|
|
|
|
|
|
|
trim(CMD);
|
|
|
|
|
arg = command_get_cmd(cmd);
|
|
|
|
|
|
|
|
|
|
if ( !strlen(cmd) )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
strcpy(args, CMD+arg);
|
|
|
|
|
trim(args);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_OF_CMD; i++)
|
|
|
|
|
{
|
|
|
|
|
if (!strcmp(cmd, COMMANDS[i].name))
|
|
|
|
|
{
|
2013-02-17 16:22:51 +01:00
|
|
|
|
result = ((handler1_t)COMMANDS[i].handler)(args);
|
|
|
|
|
if (result != TRUE)
|
|
|
|
|
{
|
|
|
|
|
#if LANG_ENG
|
|
|
|
|
printf(" Error!\n\r");
|
|
|
|
|
#elif LANG_RUS
|
|
|
|
|
printf(" <20>訡<EFBFBD><E8A8A1>!\n\r");
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2010-10-17 21:50:55 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( -1 != alias_search(CMD) )
|
|
|
|
|
{
|
|
|
|
|
strcpy(CMD, ALIASES+64*1024+256*alias_search(CMD));
|
|
|
|
|
command_execute();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
executable_run(cmd, args);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// ===========================================================
|
2013-02-17 16:22:51 +01:00
|
|
|
|
|