Subversion Repositories Kolibri OS

Rev

Rev 9716 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright (C) KolibriOS team 2004-2024. All rights reserved.
  3.  * Distributed under terms of the GNU General Public License
  4. */
  5.  
  6. #include <_ansi.h>
  7. #include <stdio.h>
  8. #include <sys/unistd.h>
  9. #include "io.h"
  10. #include <string.h>
  11.  
  12. extern void load_libconsole();
  13. extern void  __stdcall con_init(unsigned w_w, unsigned w_h, unsigned s_w, unsigned s_h, const char* t);
  14. extern void  __stdcall con_exit(char bCloseWindow);
  15. extern void  __stdcall con_write_string(const char* string, unsigned length);
  16. extern char* __stdcall con_gets(char*, unsigned);
  17.  
  18. int __gui_mode;
  19.  
  20. static int console_read(const char *path, void *buff,
  21.            size_t offset, size_t count, size_t *done)
  22. {
  23.     char *p = buff;
  24.     con_gets(p, count+1);
  25.     *done = strlen(p);
  26.     return 0;
  27. }
  28.  
  29. static int console_write(const char *path, const void *buff,
  30.                  size_t offset, size_t count, size_t *writes)
  31. {
  32.     con_write_string(buff, count);
  33.  
  34.     *writes = count;
  35.     return 0;
  36. }
  37.  
  38. void __init_conio()
  39. {
  40.     __io_handle *ioh;
  41.  
  42.     load_libconsole();
  43.     con_init(80, 25, 80, 500, "Console application");
  44.  
  45.     ioh = &__io_tab[STDIN_FILENO];
  46.     ioh->mode  = _READ|_ISTTY;
  47.     ioh->read  = &console_read;
  48.  
  49.     ioh = &__io_tab[STDOUT_FILENO];
  50.     ioh->mode  = _WRITE|_ISTTY;
  51.     ioh->write = &console_write;
  52. };
  53.  
  54. void __fini_conio()
  55. {
  56.     con_exit(0);
  57. }
  58.