forked from KolibriOS/kolibrios
kolibri-libc:
- Added full import console.obj - Added dir.h - Fixed dirent bug - Added dirent example - Fixed localtime bug. git-svn-id: svn://kolibrios.org@8744 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
@@ -1,56 +1,62 @@
|
||||
#include <sys/ksys.h>
|
||||
#include "conio.h"
|
||||
#include <conio.h>
|
||||
#include "stdio.h"
|
||||
|
||||
static char* __con_caption = "Console application";
|
||||
static char* __con_dllname = "/sys/lib/console.obj";
|
||||
|
||||
int __con_is_load = 0;
|
||||
|
||||
void stdcall (*__con_init_hidden)(int wnd_width, int wnd_height,int scr_width, int scr_height, const char* title);
|
||||
void stdcall (*__con_write_asciiz)(const char* str);
|
||||
void stdcall (*__con_write_string)(const char* str, unsigned length);
|
||||
int stdcall (*__con_getch)(void);
|
||||
short stdcall (*__con_getch2)(void);
|
||||
int stdcall (*__con_kbhit)(void);
|
||||
char* stdcall (*__con_gets)(char* str, int n);
|
||||
char* stdcall (*__con_gets2)(__con_gets2_callback callback, char* str, int n);
|
||||
void stdcall (*__con_exit)(int status);
|
||||
void stdcall (*__con_set_title)(const char* title);
|
||||
void stdcall (*__con_init_hidden)(int wnd_width, unsigned wnd_height, int scr_width, int scr_height, const char* title);
|
||||
void stdcall (*con_exit)(int);
|
||||
void stdcall (*con_set_title)(const char* title);
|
||||
void stdcall (*con_write_asciiz)(const char* str);
|
||||
void stdcall (*con_write_string)(const char* str, dword length);
|
||||
int cdecl (*con_printf)(const char* format, ...);
|
||||
dword stdcall (*con_get_flags)(void);
|
||||
dword stdcall (*con_set_flags)(dword new_flags);
|
||||
int stdcall (*con_get_font_height)(void);
|
||||
int stdcall (*con_get_cursor_height)(void);
|
||||
int stdcall (*con_set_cursor_height)(int new_height);
|
||||
int stdcall (*con_getch)(void);
|
||||
word stdcall (*con_getch2)(void);
|
||||
int stdcall (*con_kbhit)(void);
|
||||
char* stdcall (*con_gets)(char* str, int n);
|
||||
char* stdcall (*con_gets2)(con_gets2_callback callback, char* str, int n);
|
||||
void stdcall (*con_cls)();
|
||||
void stdcall (*con_get_cursor_pos)(int* px, int* py);
|
||||
void stdcall (*con_set_cursor_pos)(int x, int y);
|
||||
|
||||
static void __con_panic(char* func_name)
|
||||
{
|
||||
_ksys_debug_puts("libc.obj: ");
|
||||
_ksys_debug_puts(func_name);
|
||||
_ksys_debug_puts(" = NULL\n");
|
||||
debug_printf("In console.obj %s=NULL!\n", func_name);
|
||||
_ksys_exit();
|
||||
}
|
||||
|
||||
static void __con_lib_link(ksys_coff_etable_t *exp)
|
||||
{
|
||||
__con_init_hidden = _ksys_get_coff_func(exp, "con_init", __con_panic);
|
||||
__con_write_asciiz = _ksys_get_coff_func(exp, "con_write_asciiz", __con_panic);
|
||||
__con_write_string = _ksys_get_coff_func(exp, "con_write_string", __con_panic);
|
||||
__con_getch = _ksys_get_coff_func(exp, "con_getch", __con_panic);
|
||||
__con_getch2 = _ksys_get_coff_func(exp, "con_getch2", __con_panic);
|
||||
__con_kbhit = _ksys_get_coff_func(exp, "con_kbhit", __con_panic);
|
||||
__con_gets = _ksys_get_coff_func(exp, "con_gets", __con_panic);
|
||||
__con_gets2 = _ksys_get_coff_func(exp, "con_gets2", __con_panic);
|
||||
__con_exit = _ksys_get_coff_func(exp, "con_exit", __con_panic);
|
||||
__con_set_title = _ksys_get_coff_func(exp, "con_set_title", __con_panic);
|
||||
__con_init_hidden = _ksys_get_coff_func(exp, "con_init", __con_panic);
|
||||
con_exit = _ksys_get_coff_func(exp, "con_exit", __con_panic);
|
||||
con_set_title = _ksys_get_coff_func(exp, "con_set_title", __con_panic);
|
||||
con_write_asciiz = _ksys_get_coff_func(exp, "con_write_asciiz", __con_panic);
|
||||
con_write_string = _ksys_get_coff_func(exp, "con_write_string", __con_panic);
|
||||
con_printf = _ksys_get_coff_func(exp, "con_printf", __con_panic);
|
||||
con_get_flags = _ksys_get_coff_func(exp, "con_get_flags", __con_panic);
|
||||
con_set_flags = _ksys_get_coff_func(exp, "con_set_flags", __con_panic);
|
||||
con_get_font_height = _ksys_get_coff_func(exp, "con_get_font_height", __con_panic);
|
||||
con_get_cursor_height = _ksys_get_coff_func(exp, "con_get_cursor_height", __con_panic);
|
||||
con_set_cursor_height = _ksys_get_coff_func(exp, "con_set_cursor_height", __con_panic);
|
||||
con_getch = _ksys_get_coff_func(exp, "con_getch", __con_panic);
|
||||
con_getch2 = _ksys_get_coff_func(exp, "con_getch2", __con_panic);
|
||||
con_kbhit = _ksys_get_coff_func(exp, "con_kbhit", __con_panic);
|
||||
con_gets = _ksys_get_coff_func(exp, "con_gets", __con_panic);
|
||||
con_gets2 = _ksys_get_coff_func(exp, "con_gets2", __con_panic);
|
||||
con_cls = _ksys_get_coff_func(exp, "con_cls", __con_panic);
|
||||
con_get_cursor_pos = _ksys_get_coff_func(exp, "con_get_cursor_pos", __con_panic);
|
||||
con_set_cursor_pos = _ksys_get_coff_func(exp, "con_set_cursor_pos", __con_panic);
|
||||
}
|
||||
|
||||
|
||||
int __con_init(void)
|
||||
{
|
||||
return __con_init_opt(-1, -1, -1, -1, __con_caption);
|
||||
}
|
||||
|
||||
void con_set_title(const char* title){
|
||||
__con_init();
|
||||
__con_set_title(title);
|
||||
}
|
||||
|
||||
int __con_init_opt(int wnd_width, int wnd_height,int scr_width, int scr_height, const char* title)
|
||||
int con_init_opt(dword wnd_width, dword wnd_height, dword scr_width, dword scr_height, const char* title)
|
||||
{
|
||||
if(!__con_is_load){
|
||||
ksys_coff_etable_t *__con_lib;
|
||||
@@ -66,3 +72,10 @@ int __con_init_opt(int wnd_width, int wnd_height,int scr_width, int scr_height,
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int con_init(void)
|
||||
{
|
||||
return con_init_opt(-1, -1, -1, -1, __con_caption);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
|
||||
This is adapded thunk for console.obj sys library
|
||||
Only for internal use in stdio.h
|
||||
|
||||
Adapted for tcc by Siemargl, 2016
|
||||
|
||||
*/
|
||||
#ifndef _CONIO_H_
|
||||
#define _CONIO_H_
|
||||
|
||||
#define cdecl __attribute__ ((cdecl))
|
||||
#define stdcall __attribute__ ((stdcall))
|
||||
|
||||
void stdcall (*__con_write_asciiz)(const char* str);
|
||||
/* Display ASCIIZ-string to the console at the current position, shifting
|
||||
the current position. */
|
||||
|
||||
void stdcall (*__con_write_string)(const char* str, unsigned length);
|
||||
/* Similar to __con_write_asciiz, but length of the string must be given as a
|
||||
separate parameter */
|
||||
|
||||
int stdcall (*__con_getch)(void);
|
||||
/* Get one character from the keyboard.
|
||||
|
||||
For normal characters function returns ASCII-code. For extended
|
||||
characters (eg, Fx, and arrows), first function call returns 0
|
||||
and second call returns the extended code (similar to the DOS-function
|
||||
input). Starting from version 7, after closing the console window,
|
||||
this function returns 0. */
|
||||
|
||||
short stdcall (*__con_getch2)(void);
|
||||
/* Reads a character from the keyboard. Low byte contains the ASCII-code
|
||||
(0 for extended characters), high byte - advanced code (like in BIOS
|
||||
input functions). Starting from version 7, after closing the console
|
||||
window, this function returns 0. */
|
||||
|
||||
int stdcall (*__con_kbhit)(void);
|
||||
/* Returns 1 if a key was pressed, 0 otherwise. To read pressed keys use
|
||||
__con_getch and __con_getch2. Starting from version 6, after closing
|
||||
the console window, this function returns 1. */
|
||||
|
||||
char* stdcall (*__con_gets)(char* str, int n);
|
||||
/* Reads a string from the keyboard. Reading is interrupted when got
|
||||
"new line" character, or after reading the (n-1) characters (depending on
|
||||
what comes first). In the first case the newline is also recorded in the
|
||||
str. The acquired line is complemented by a null character.
|
||||
Starting from version 6, the function returns a pointer to the entered
|
||||
line if reading was successful, and NULL if the console window was closed. */
|
||||
|
||||
typedef int (stdcall * __con_gets2_callback)(int keycode, char** pstr, int* pn,
|
||||
int* ppos);
|
||||
|
||||
char* stdcall (*__con_gets2)(__con_gets2_callback callback, char* str, int n);
|
||||
/* Con_gets completely analogous, except that when the user
|
||||
press unrecognized key, it calls the specified callback-procedure
|
||||
(which may, for example, handle up / down for history and tab to enter
|
||||
autocompletion). You should pass to the procedure: key code and three pointers
|
||||
- to the string, to the maximum length and to the current position.
|
||||
function may change the contents of string and may change the string
|
||||
itself (for example, to reallocate memory for increase the limit),
|
||||
maximum length, and position of the line - pointers are passed for it.
|
||||
Return value: 0 = line wasn't changed 1 = line changed, you should
|
||||
remove old string and display new, 2 = line changed, it is necessary
|
||||
to display it; 3 = immediately exit the function.
|
||||
Starting from version 6, the function returns a pointer to the entered
|
||||
line with the successful reading, and NULL if the console window was closed. */
|
||||
|
||||
int __con_is_load;
|
||||
unsigned *__con_dll_ver;
|
||||
|
||||
int __con_init(void);
|
||||
int __con_init_opt(int wnd_width, int wnd_height, int scr_width, int scr_height, const char* title);
|
||||
void stdcall (*__con_exit)(int status);
|
||||
|
||||
#endif
|
||||
@@ -13,8 +13,8 @@ size_t fread(void *restrict ptr, size_t size, size_t nmemb, FILE *restrict strea
|
||||
}
|
||||
|
||||
if(stream==stdin){
|
||||
__con_init();
|
||||
__con_gets((char*)ptr, bytes_count+1);
|
||||
con_init();
|
||||
con_gets((char*)ptr, bytes_count+1);
|
||||
return nmemb;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include <sys/ksys.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
size_t fwrite(const void *restrict ptr, size_t size, size_t nmemb, FILE *restrict stream) {
|
||||
unsigned bytes_written = 0;
|
||||
unsigned bytes_count = size * nmemb;
|
||||
@@ -14,8 +13,8 @@ size_t fwrite(const void *restrict ptr, size_t size, size_t nmemb, FILE *restric
|
||||
}
|
||||
|
||||
if(stream==stdout){
|
||||
__con_init();
|
||||
__con_write_string((char*)ptr, bytes_count);
|
||||
con_init();
|
||||
con_write_string((char*)ptr, bytes_count);
|
||||
return nmemb;
|
||||
}
|
||||
else if(stream==stderr){
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include "conio.h"
|
||||
#include <conio.h>
|
||||
|
||||
int getchar(void) {
|
||||
__con_init();
|
||||
con_init();
|
||||
char c = 0;
|
||||
__con_gets(&c, 2);
|
||||
con_gets(&c, 2);
|
||||
if (c == 0) {
|
||||
c = EOF;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
|
||||
char *gets(char* str)
|
||||
{
|
||||
__con_init();
|
||||
if(__con_gets(str, STDIO_MAX_MEM)==NULL){
|
||||
con_init();
|
||||
if(con_gets(str, STDIO_MAX_MEM)==NULL){
|
||||
errno = EIO;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
int puts(const char *str)
|
||||
{
|
||||
__con_init();
|
||||
__con_write_asciiz(str);
|
||||
__con_write_asciiz("\n");
|
||||
con_init();
|
||||
con_write_asciiz(str);
|
||||
con_write_asciiz("\n");
|
||||
return strlen(str);
|
||||
}
|
||||
@@ -18,9 +18,9 @@ int vprintf ( const char * format, va_list arg )
|
||||
errno = ENOMEM;
|
||||
return errno;
|
||||
}
|
||||
__con_init();
|
||||
con_init();
|
||||
len = vsnprintf(s, STDIO_MAX_MEM, format, arg);
|
||||
__con_write_string(s, len);
|
||||
con_write_string(s, len);
|
||||
free(s);
|
||||
return(len);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user