Subversion Repositories Kolibri OS

Rev

Rev 9354 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #include <_ansi.h>
  2. #include <stdio.h>
  3. #include <sys/unistd.h>
  4. #include "io.h"
  5. #include <string.h>
  6.  
  7. extern void load_libconsole();
  8. extern void  __stdcall con_init(unsigned w_w, unsigned w_h, unsigned s_w, unsigned s_h, const char* t);
  9. extern void  __stdcall con_exit(char bCloseWindow);
  10. extern void  __stdcall con_write_string(const char* string, unsigned length);
  11. extern char* __stdcall con_gets(char*, unsigned);
  12.  
  13. int __gui_mode;
  14.  
  15. static int console_read(const char *path, void *buff,
  16.            size_t offset, size_t count, size_t *done)
  17. {
  18.     char *p = buff;
  19.     /*int   cnt = 0;
  20.     short c;
  21.     char  ch;*/
  22.     con_gets(p, count+1);
  23.     *done = strlen(p);
  24.  
  25. //   __asm__ volatile("int3");
  26. /*
  27.     do
  28.     {
  29.         c = con_getch2();
  30.         printf("%d\n",(char)c);
  31.         ch = (char)c;
  32.         if(ch != 0)
  33.         {
  34.             p[cnt] = ch != 0x0D ? ch : 0x0A;
  35.             con_write_string(p+cnt, 1);
  36.             cnt++;
  37.         }
  38.     }while(ch != 0x0D);
  39.     *done = cnt;
  40. */
  41.     return 0;
  42. }
  43.  
  44. static int console_write(const char *path, const void *buff,
  45.                  size_t offset, size_t count, size_t *writes)
  46. {
  47.     con_write_string(buff, count);
  48.  
  49.     *writes = count;
  50.     return 0;
  51. };
  52.  
  53. void __init_conio()
  54. {
  55.     __io_handle *ioh;
  56.  
  57.     load_libconsole();
  58.     con_init(80, 25, 80, 500, "Console application");
  59.  
  60.     ioh = &__io_tab[STDIN_FILENO];
  61.     ioh->mode  = _READ|_ISTTY;
  62.     ioh->read  = &console_read;
  63.  
  64.     ioh = &__io_tab[STDOUT_FILENO];
  65.     ioh->mode  = _WRITE|_ISTTY;
  66.     ioh->write = &console_write;
  67. };
  68.  
  69. void __fini_conio()
  70. {
  71.     con_exit(0);
  72. }
  73.