2012-03-23 19:53:16 +01:00
|
|
|
|
|
|
|
|
|
#include "../program_console.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int program_console(int pid)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
char name[32];
|
|
|
|
|
char *buffer;
|
2021-03-03 22:14:44 +01:00
|
|
|
|
char *buf1k;
|
2012-03-23 19:53:16 +01:00
|
|
|
|
int result;
|
|
|
|
|
int i;
|
|
|
|
|
char command;
|
|
|
|
|
int size;
|
|
|
|
|
int is_end;
|
|
|
|
|
|
2012-06-04 14:54:51 +02:00
|
|
|
|
itoa(pid, name);
|
2012-03-23 19:53:16 +01:00
|
|
|
|
strcat(name, "-SHELL");
|
|
|
|
|
|
|
|
|
|
buffer = NULL;
|
2021-03-03 22:14:44 +01:00
|
|
|
|
buf1k = NULL;
|
2012-03-23 19:53:16 +01:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < 30; i++)
|
|
|
|
|
{
|
|
|
|
|
result = kol_buffer_open(name, SHM_OPEN | SHM_WRITE, 0, &buffer);
|
|
|
|
|
if (buffer != NULL)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
kol_sleep(2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (buffer == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
else
|
|
|
|
|
size = result;
|
|
|
|
|
|
|
|
|
|
is_end = 0;
|
|
|
|
|
for (;;)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
command = *(buffer);
|
|
|
|
|
|
|
|
|
|
switch (command)
|
|
|
|
|
{
|
|
|
|
|
case SC_EXIT:
|
|
|
|
|
*buffer = SC_OK;
|
|
|
|
|
is_end = 1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SC_OK:
|
|
|
|
|
kol_sleep(5);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SC_CLS:
|
|
|
|
|
con_cls();
|
|
|
|
|
*buffer = SC_OK;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SC_PUTC:
|
|
|
|
|
printf("%c", *(buffer+1));
|
|
|
|
|
*buffer = SC_OK;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SC_PUTS:
|
|
|
|
|
printf("%s", buffer+1 );
|
|
|
|
|
*buffer = SC_OK;
|
2021-03-03 22:14:44 +01:00
|
|
|
|
break;
|
|
|
|
|
|
2012-03-23 19:53:16 +01:00
|
|
|
|
case SC_GETC:
|
|
|
|
|
*(buffer+1) = (char) getch() ;
|
|
|
|
|
*buffer = SC_OK;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SC_GETS:
|
|
|
|
|
gets(buffer+1, size-2);
|
|
|
|
|
*buffer = SC_OK;
|
|
|
|
|
break;
|
2021-03-03 22:14:44 +01:00
|
|
|
|
|
2021-03-04 09:50:03 +01:00
|
|
|
|
case SC_PID:
|
2021-03-03 22:14:44 +01:00
|
|
|
|
buf1k=malloc(1024);
|
|
|
|
|
kol_process_info(-1, buf1k);
|
2021-03-04 09:50:03 +01:00
|
|
|
|
memcpy(buffer+1, buf1k+30, sizeof(unsigned));
|
2021-03-03 22:14:44 +01:00
|
|
|
|
*buffer = SC_OK;
|
|
|
|
|
free(buf1k);
|
|
|
|
|
break;
|
|
|
|
|
|
2021-03-04 09:50:03 +01:00
|
|
|
|
case SC_PING:
|
|
|
|
|
*buffer = SC_OK;
|
|
|
|
|
break;
|
|
|
|
|
|
2012-03-23 19:53:16 +01:00
|
|
|
|
default:
|
|
|
|
|
#if LANG_ENG
|
|
|
|
|
printf (" Error in console application.\n\r");
|
|
|
|
|
#elif LANG_RUS
|
2013-02-16 12:25:37 +01:00
|
|
|
|
printf (" <20>訡<EFBFBD><E8A8A1> <20> <20><><EFBFBD>᮫쭮<E1AEAB> <20>ਫ<EFBFBD><E0A8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.\n\r");
|
2012-03-23 19:53:16 +01:00
|
|
|
|
#endif
|
|
|
|
|
return 0;
|
|
|
|
|
};
|
|
|
|
|
if (is_end)
|
|
|
|
|
{
|
|
|
|
|
printf("\n\r");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 9;
|
2012-06-04 14:54:51 +02:00
|
|
|
|
}
|
2013-02-17 16:22:51 +01:00
|
|
|
|
|