2024-01-04 23:20:35 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) KolibriOS team 2004-2024. All rights reserved.
|
|
|
|
* Distributed under terms of the GNU General Public License
|
|
|
|
*/
|
|
|
|
|
2016-01-18 03:22:44 +01:00
|
|
|
#include <_ansi.h>
|
2021-06-07 18:51:13 +02:00
|
|
|
#include <stdio.h>
|
2016-01-18 03:22:44 +01:00
|
|
|
#include <sys/unistd.h>
|
|
|
|
#include "io.h"
|
2021-06-07 18:51:13 +02:00
|
|
|
#include <string.h>
|
2016-01-18 03:22:44 +01:00
|
|
|
|
2022-02-13 14:51:56 +01:00
|
|
|
extern void load_libconsole();
|
|
|
|
extern void __stdcall con_init(unsigned w_w, unsigned w_h, unsigned s_w, unsigned s_h, const char* t);
|
|
|
|
extern void __stdcall con_exit(char bCloseWindow);
|
|
|
|
extern void __stdcall con_write_string(const char* string, unsigned length);
|
|
|
|
extern char* __stdcall con_gets(char*, unsigned);
|
2021-12-02 20:24:53 +01:00
|
|
|
|
2016-01-18 03:22:44 +01:00
|
|
|
int __gui_mode;
|
|
|
|
|
2016-09-27 22:37:49 +02:00
|
|
|
static int console_read(const char *path, void *buff,
|
|
|
|
size_t offset, size_t count, size_t *done)
|
|
|
|
{
|
|
|
|
char *p = buff;
|
2021-06-07 18:51:13 +02:00
|
|
|
con_gets(p, count+1);
|
|
|
|
*done = strlen(p);
|
2016-09-27 22:37:49 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-18 03:22:44 +01:00
|
|
|
static int console_write(const char *path, const void *buff,
|
|
|
|
size_t offset, size_t count, size_t *writes)
|
|
|
|
{
|
|
|
|
con_write_string(buff, count);
|
|
|
|
|
|
|
|
*writes = count;
|
2016-09-27 22:37:49 +02:00
|
|
|
return 0;
|
2024-01-04 23:20:35 +01:00
|
|
|
}
|
2016-01-18 03:22:44 +01:00
|
|
|
|
2016-01-18 18:02:08 +01:00
|
|
|
void __init_conio()
|
2016-01-18 03:22:44 +01:00
|
|
|
{
|
|
|
|
__io_handle *ioh;
|
|
|
|
|
|
|
|
load_libconsole();
|
2016-01-18 18:02:08 +01:00
|
|
|
con_init(80, 25, 80, 500, "Console application");
|
2016-01-18 03:22:44 +01:00
|
|
|
|
2016-09-27 22:37:49 +02:00
|
|
|
ioh = &__io_tab[STDIN_FILENO];
|
|
|
|
ioh->mode = _READ|_ISTTY;
|
|
|
|
ioh->read = &console_read;
|
|
|
|
|
2016-01-18 03:22:44 +01:00
|
|
|
ioh = &__io_tab[STDOUT_FILENO];
|
|
|
|
ioh->mode = _WRITE|_ISTTY;
|
|
|
|
ioh->write = &console_write;
|
|
|
|
};
|
|
|
|
|
2016-01-18 18:02:08 +01:00
|
|
|
void __fini_conio()
|
2016-01-18 03:22:44 +01:00
|
|
|
{
|
|
|
|
con_exit(0);
|
|
|
|
}
|