forked from KolibriOS/kolibrios
2a7660964a
git-svn-id: svn://kolibrios.org@3268 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); // ä®à¬¨à㥬 ¨§ ®¬¥à ¯à®æ¥áá áâபã
|
|
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();
|
|
|
|
|
|
|
|
}
|