a2ca7586dc
git-svn-id: svn://kolibrios.org@2735 a494cfbc-eb01-0410-851d-a64ba20cac60
110 lines
1.8 KiB
C
110 lines
1.8 KiB
C
|
|
#include "system/kolibri.h"
|
|
#include "system/string.h"
|
|
|
|
#include "program_console.h"
|
|
|
|
char *buffer; // èñïîëüçóåòñÿ òîëüêî îäíà èìåíîâàííàÿ îáëàñòü, ïîýòîìó ìîæíî ñäåëàòü å¸ ãëîáàëüíîé ïåðåìåííîé
|
|
char name[32]; // èìÿ íóæíî êàê äëÿ ñîçäàíèÿ îáëàñòè, òàê è äëÿ óäàëåíèÿ, ïîýòîìó ìîæíî ñäåëàòü å¸ ãëîáàëüíîé ïåðåìåííîé
|
|
|
|
int sc_init() // èíèöèàëèçàöèÿ - ñîçäàíèå èìåíîâàííîé îáëàñòè
|
|
{
|
|
|
|
char *buf1k;
|
|
unsigned PID;
|
|
int result;
|
|
|
|
|
|
buf1k = malloc(1024);
|
|
if (NULL == buf1k)
|
|
return -1;
|
|
|
|
kol_process_info(-1, buf1k); // ïîëó÷àåì ÑÂÎÉ (-1) èäåíòèôèêàòîð ïðîöåññà
|
|
PID = *(buf1k+30);
|
|
free(buf1k);
|
|
|
|
itoa(PID, name); // ôîðìèðóåì èç íîìåðà ïðîöåññà ñòðîêó ñ çàãëàâíûìè íóëÿìè 42 -> 0042 (ò.å. äî 9999)
|
|
strcat(name, "-SHELL");
|
|
|
|
*buffer = NULL;
|
|
result = kol_buffer_open(name, SHM_OPEN_ALWAYS | SHM_WRITE, 1024*16, &buffer); // ñîçäà¸ì îáëàñòü (16 êèë)
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
|
|
void sc_puts(char *str)
|
|
{
|
|
*buffer = SC_PUTS;
|
|
strcpy(buffer+1, str);
|
|
while (*buffer) kol_sleep(5);
|
|
}
|
|
|
|
|
|
void sc_exit()
|
|
{
|
|
*buffer = SC_EXIT;
|
|
while (*buffer) kol_sleep(5);
|
|
kol_buffer_close(name);
|
|
}
|
|
|
|
|
|
void sc_gets(char *str)
|
|
{
|
|
*buffer = SC_GETS;
|
|
while (*buffer) kol_sleep(5);
|
|
strcpy(str, buffer+1);
|
|
}
|
|
|
|
|
|
char sc_getc()
|
|
{
|
|
*buffer = SC_GETC;
|
|
while (*buffer) kol_sleep(5);
|
|
return *(buffer+1);
|
|
}
|
|
|
|
|
|
void sc_putc(char c)
|
|
{
|
|
*buffer = SC_PUTC;
|
|
*(buffer+1) = c;
|
|
while (*buffer) kol_sleep(5);
|
|
}
|
|
|
|
|
|
|
|
void sc_cls()
|
|
{
|
|
*buffer = SC_CLS;
|
|
while (*buffer) kol_sleep(5);
|
|
}
|
|
|
|
|
|
|
|
|
|
void kol_main()
|
|
{
|
|
|
|
char string[256];
|
|
|
|
sc_init();
|
|
|
|
sc_cls();
|
|
sc_puts("This is a test console application for Shell\n\r");
|
|
sc_puts("Type a string (255 symbols max): ");
|
|
sc_gets(string);
|
|
sc_puts("You typed:\n\r");
|
|
sc_puts(string);
|
|
sc_puts("Press any key: ");
|
|
string[0] = sc_getc();
|
|
sc_puts("\n\rYou pressed: ");
|
|
sc_putc(string[0]);
|
|
|
|
sc_exit();
|
|
|
|
|
|
|
|
}
|