From 99922e4c2c5db0121bc0625ba4e804e63994865a Mon Sep 17 00:00:00 2001 From: turbocat Date: Fri, 15 Apr 2022 09:11:49 +0000 Subject: [PATCH] Update skipped files in previous commit git-svn-id: svn://kolibrios.org@9766 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/develop/ktcc/trunk/bin/lib/libc.def | 5 +- .../develop/ktcc/trunk/libc.obj/.clang-format | 6 + .../ktcc/trunk/libc.obj/include/assert.h | 8 +- .../trunk/libc.obj/include/clayer/boxlib.h | 236 ++-- .../trunk/libc.obj/include/clayer/buf2d.h | 112 +- .../trunk/libc.obj/include/clayer/dialog.h | 117 +- .../ktcc/trunk/libc.obj/include/clayer/gb.h | 26 +- .../ktcc/trunk/libc.obj/include/conio.h | 55 +- .../ktcc/trunk/libc.obj/include/ctype.h | 48 +- .../ktcc/trunk/libc.obj/include/errno.h | 178 +-- .../ktcc/trunk/libc.obj/include/float.h | 62 +- .../ktcc/trunk/libc.obj/include/limits.h | 65 +- .../ktcc/trunk/libc.obj/include/math.h | 207 +-- .../ktcc/trunk/libc.obj/include/setjmp.h | 6 +- .../ktcc/trunk/libc.obj/include/shell_api.h | 36 +- .../ktcc/trunk/libc.obj/include/stdarg.h | 69 +- .../ktcc/trunk/libc.obj/include/stdbool.h | 6 +- .../ktcc/trunk/libc.obj/include/stddef.h | 26 +- .../ktcc/trunk/libc.obj/include/stdint.h | 48 +- .../ktcc/trunk/libc.obj/include/stdio.h | 122 +- .../ktcc/trunk/libc.obj/include/stdlib.h | 112 +- .../ktcc/trunk/libc.obj/include/string.h | 163 +-- .../ktcc/trunk/libc.obj/include/sys/dir.h | 8 +- .../ktcc/trunk/libc.obj/include/sys/dirent.h | 33 +- .../ktcc/trunk/libc.obj/include/sys/ksys.h | 1242 ++++++++--------- .../ktcc/trunk/libc.obj/include/sys/socket.h | 92 +- .../ktcc/trunk/libc.obj/include/time.h | 26 +- .../trunk/libc.obj/loader/__lib__.asm.bak | 9 - .../ktcc/trunk/libc.obj/loader/__lib__.inc | 2 - .../ktcc/trunk/libc.obj/samples/assert_test.c | 11 +- .../ktcc/trunk/libc.obj/samples/basic_gui.c | 59 +- .../trunk/libc.obj/samples/clayer/boxlib.c | 122 +- .../trunk/libc.obj/samples/clayer/dialog.c | 34 +- .../trunk/libc.obj/samples/clayer/libimg.c | 85 +- .../trunk/libc.obj/samples/clayer/msgbox.c | 2 +- .../libc.obj/samples/clayer/rasterworks.c | 50 +- .../ktcc/trunk/libc.obj/samples/consoleio.c | 11 +- .../ktcc/trunk/libc.obj/samples/defgen.c | 28 +- .../ktcc/trunk/libc.obj/samples/dir_example.c | 41 +- .../ktcc/trunk/libc.obj/samples/file_io.c | 70 +- .../trunk/libc.obj/samples/http_tcp_demo.c | 30 +- .../ktcc/trunk/libc.obj/samples/libc_test.c | 28 +- .../ktcc/trunk/libc.obj/samples/math_test.c | 66 +- .../ktcc/trunk/libc.obj/samples/pipe.c | 27 +- .../ktcc/trunk/libc.obj/samples/sdltest.c | 94 +- .../ktcc/trunk/libc.obj/samples/shell_test.c | 9 +- .../ktcc/trunk/libc.obj/samples/stdio_test.c | 9 +- .../ktcc/trunk/libc.obj/samples/string_test.c | 13 +- .../ktcc/trunk/libc.obj/samples/thread_work.c | 53 +- .../trunk/libc.obj/samples/tmpdisk_work.c | 51 +- .../ktcc/trunk/libc.obj/samples/whois.c | 436 +++--- 51 files changed, 1967 insertions(+), 2487 deletions(-) create mode 100755 programs/develop/ktcc/trunk/libc.obj/.clang-format delete mode 100644 programs/develop/ktcc/trunk/libc.obj/loader/__lib__.asm.bak delete mode 100644 programs/develop/ktcc/trunk/libc.obj/loader/__lib__.inc diff --git a/programs/develop/ktcc/trunk/bin/lib/libc.def b/programs/develop/ktcc/trunk/bin/lib/libc.def index e7e026f5b8..a17f4ee2d7 100644 --- a/programs/develop/ktcc/trunk/bin/lib/libc.def +++ b/programs/develop/ktcc/trunk/bin/lib/libc.def @@ -66,11 +66,8 @@ qsort strtod __assert_fail ;____STRING____ -;memcpy memchr memcmp -!memmove -!memset strncat strchr strcat @@ -90,7 +87,7 @@ strspn strstr strtok strxfrm -_errno +__errno ;____SYS____ closedir opendir diff --git a/programs/develop/ktcc/trunk/libc.obj/.clang-format b/programs/develop/ktcc/trunk/libc.obj/.clang-format new file mode 100755 index 0000000000..4ad4b7bf38 --- /dev/null +++ b/programs/develop/ktcc/trunk/libc.obj/.clang-format @@ -0,0 +1,6 @@ +# Format Style Options - Created with Clang Power Tools +--- +BasedOnStyle: WebKit +AlignTrailingComments: true +AlignConsecutiveMacros: true +... diff --git a/programs/develop/ktcc/trunk/libc.obj/include/assert.h b/programs/develop/ktcc/trunk/libc.obj/include/assert.h index 4dd392ab0a..53ef06cb33 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/assert.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/assert.h @@ -4,6 +4,10 @@ #include #include -#define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__, __func__),0))) +#ifdef NDEBUG +#define assert(x) (void)0 +#else +#define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__, __func__), 0))) +#endif -#endif // _ASSERT_H_ \ No newline at end of file +#endif // _ASSERT_H_ diff --git a/programs/develop/ktcc/trunk/libc.obj/include/clayer/boxlib.h b/programs/develop/ktcc/trunk/libc.obj/include/clayer/boxlib.h index fba26347e2..545c9cd370 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/clayer/boxlib.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/clayer/boxlib.h @@ -3,49 +3,49 @@ #ifndef KOLIBRI_BOXLIB_H #define KOLIBRI_BOXLIB_H -#include -#include #include +#include +#include typedef unsigned color_t; int kolibri_boxlib_init(void); /* flags meaning */ -#define ed_figure_only 0b1000000000000000 // одни символы -#define ed_always_focus 0b100000000000000 // всегда с курсором (фокусом) -#define ed_focus 0b10 // фокус ввода приложения, мышится самостоятельно -#define ed_pass 0b1 // поле с паролем -#define ed_shift_on 0b1000 // если не установлен -значит впервые нажат shift,если был установлен, значит мы уже что - то делали удерживая //shift +#define ed_figure_only 0b1000000000000000 // одни символы +#define ed_always_focus 0b100000000000000 // всегда с курсором (фокусом) +#define ed_focus 0b10 // фокус ввода приложения, мышится самостоятельно +#define ed_pass 0b1 // поле с паролем +#define ed_shift_on 0b1000 // если не установлен -значит впервые нажат shift,если был установлен, значит мы уже что - то делали удерживая //shift #define ed_shift_on_off 0b1111111111110111 -#define ed_shift 0b100 //включается при нажатии на shift т.е. если нажимаю +#define ed_shift 0b100 //включается при нажатии на shift т.е. если нажимаю #define ed_shift_off 0b1111111111111011 -#define ed_shift_bac 0b10000 //бит для очистки выделеного shift т.е. при установке говорит что есть выделение -#define ed_shift_bac_cl 0b1111111111101111 //очистка при удалении выделения +#define ed_shift_bac 0b10000 //бит для очистки выделеного shift т.е. при установке говорит что есть выделение +#define ed_shift_bac_cl 0b1111111111101111 //очистка при удалении выделения #define ed_shift_cl 0b1111111111100011 #define ed_shift_mcl 0b1111111111111011 -#define ed_left_fl 0b100000 +#define ed_left_fl 0b100000 #define ed_right_fl 0b1111111111011111 -#define ed_offset_fl 0b1000000 +#define ed_offset_fl 0b1000000 #define ed_offset_cl 0b1111111110111111 -#define ed_insert 0b10000000 +#define ed_insert 0b10000000 #define ed_insert_cl 0b1111111101111111 -#define ed_mouse_on 0b100000000 -#define ed_mous_adn_b 0b100011000 -#define ed_mouse_off ~ed_mouse_on -#define ed_ctrl_on 0b1000000000 -#define ed_ctrl_off ~ed_ctrl_on -#define ed_alt_on 0b10000000000 -#define ed_alt_off ~ed_alt_on -#define ed_disabled 0b100000000000 +#define ed_mouse_on 0b100000000 +#define ed_mous_adn_b 0b100011000 +#define ed_mouse_off ~ed_mouse_on +#define ed_ctrl_on 0b1000000000 +#define ed_ctrl_off ~ed_ctrl_on +#define ed_alt_on 0b10000000000 +#define ed_alt_off ~ed_alt_on +#define ed_disabled 0b100000000000 // SCROLLBAR typedef struct { - uint16_t xsize; + uint16_t xsize; uint16_t xpos; uint16_t ysize; uint16_t ypos; uint32_t btn_height; - uint32_t type; // type 1 - stylish frame, type 2 - ?, type 0 - ? + uint32_t type; // type 1 - stylish frame, type 2 - ?, type 0 - ? uint32_t max_area; uint32_t cur_area; uint32_t position; @@ -65,9 +65,9 @@ typedef struct { uint32_t run_size; uint32_t position2; uint32_t work_size; - uint32_t all_redraw; // need to be set =1 before each redraw + uint32_t all_redraw; // need to be set =1 before each redraw uint32_t ar_offset; -} __attribute__ ((__packed__)) scrollbar; +} __attribute__((__packed__)) scrollbar; extern void __stdcall (*scrollbar_h_draw)(scrollbar*); extern void __stdcall (*scrollbar_h_mouse)(scrollbar*); @@ -82,58 +82,58 @@ typedef struct { unsigned int color; unsigned int border_color; unsigned int text_color; - char *text; + char* text; unsigned int flags; /* Users can use members above this */ unsigned int size_of_str; -}check_box; +} check_box; -extern void __stdcall (*check_box_draw2)(check_box *); -extern void __stdcall (*check_box_mouse2)(check_box *); -extern void __stdcall (*init_checkbox2)(check_box *); +extern void __stdcall (*check_box_draw2)(check_box*); +extern void __stdcall (*check_box_mouse2)(check_box*); +extern void __stdcall (*init_checkbox2)(check_box*); // DBUTTON typedef struct { - uint32_t type; - uint32_t x_w; - uint32_t y_h; - uint32_t mouse_pos; + uint32_t type; + uint32_t x_w; + uint32_t y_h; + uint32_t mouse_pos; uint32_t mouse_keys; uint32_t mouse_keys_old; - void* active_raw; //active bitmap - void* passive_raw; //passive bitmap - void* click_raw; //pressed bitmap + void* active_raw; //active bitmap + void* passive_raw; //passive bitmap + void* click_raw; //pressed bitmap uint32_t resolution_raw; // bpp, as esi fn65 - void* palette_raw; // palette, as edi fn65 + void* palette_raw; // palette, as edi fn65 uint32_t offset_raw; // width as ebp fn65 uint32_t select; // internal state: 0 - passive, 2 - pressed, 1 - clicked uint32_t click; // clicked - 1, zero it after tested } pict_button; -extern void __stdcall (*dynamic_button_draw)(pict_button *); -extern void __stdcall (*dynamic_button_mouse)(pict_button *); +extern void __stdcall (*dynamic_button_draw)(pict_button*); +extern void __stdcall (*dynamic_button_mouse)(pict_button*); // EDITBOX -#pragma pack(push,1) +#pragma pack(push, 1) typedef struct edit_box_t { unsigned int width; unsigned int left; unsigned int top; unsigned int color; - unsigned int shift_color; // selected text color + unsigned int shift_color; // selected text color unsigned int focus_border_color; unsigned int blur_border_color; unsigned int text_color; unsigned int max; - char *text; - void *mouse_variable; // must be pointer edit_box** to save focused editbox + char* text; + void* mouse_variable; // must be pointer edit_box** to save focused editbox unsigned int flags; - unsigned int size; // used symbols in buffer without trailing zero + unsigned int size; // used symbols in buffer without trailing zero unsigned int pos; // cursor position -/* The following struct members are not used by the users of API */ + /* The following struct members are not used by the users of API */ unsigned int offset; unsigned int cl_curs_x; unsigned int cl_curs_y; @@ -141,116 +141,116 @@ typedef struct edit_box_t { unsigned int shift_old; unsigned int height; unsigned int char_width; -}edit_box; +} edit_box; #pragma pack(pop) -extern void __stdcall (*edit_box_draw)(edit_box *); -extern void __stdcall (*edit_box_key)(edit_box *, unsigned int key_val); -extern void __stdcall (*edit_box_mouse)(edit_box *); -extern void __stdcall (*edit_box_set_text)(edit_box *, char *); +extern void __stdcall (*edit_box_draw)(edit_box*); +extern void __stdcall (*edit_box_key)(edit_box*, unsigned int key_val); +extern void __stdcall (*edit_box_mouse)(edit_box*); +extern void __stdcall (*edit_box_set_text)(edit_box*, char*); -extern void __stdcall (*edit_box_key_safe)(edit_box *e, ksys_oskey_t ch); +extern void __stdcall (*edit_box_key_safe)(edit_box* e, ksys_oskey_t ch); // FRAME typedef struct { - uint32_t type; - uint32_t x_w; - uint32_t y_h; - color_t ext_col; - color_t int_col; - uint32_t flags; - char *text_pointer; - uint32_t text_position; - uint32_t font_number; - uint32_t font_size_y; - color_t font_color; - color_t font_bg_color; -}frame; + uint32_t type; + uint32_t x_w; + uint32_t y_h; + color_t ext_col; + color_t int_col; + uint32_t flags; + char* text_pointer; + uint32_t text_position; + uint32_t font_number; + uint32_t font_size_y; + color_t font_color; + color_t font_bg_color; +} frame; -extern void __stdcall (*frame_draw)(frame *); +extern void __stdcall (*frame_draw)(frame*); // MENUBAR typedef struct { - uint32_t type; // 1 åñëè íåò ïîäìåíþ, ïðîñòî ïóíêò + uint32_t type; // 1 åñëè íåò ïîäìåíþ, ïðîñòî ïóíêò - uint32_t x_w; // âåðõíèé ïóíêò - uint32_t y_h; + uint32_t x_w; // âåðõíèé ïóíêò + uint32_t y_h; - char* text_pointer; - char* pos_pointer; - char* text_end; - uint32_t mouse_pos; - uint32_t mouse_keys; + char* text_pointer; + char* pos_pointer; + char* text_end; + uint32_t mouse_pos; + uint32_t mouse_keys; - uint32_t x_w1; // ïîäìåíþ - uint32_t y_h1; + uint32_t x_w1; // ïîäìåíþ + uint32_t y_h1; - color_t bckg_col; // ôîí âåðõíåãî ïóêòà - color_t frnt_col; // ôîí âûáðàííîãî âåðõíåãî ïóíêòà - color_t menu_col; // ôîí âûïàäàþùåé ÷àñòè (ïîäïóêòû) - uint32_t select; - uint32_t out_select; - char* buf_adress; - char* procinfo; - uint32_t click; - uint32_t cursor; - uint32_t cursor_old; - uint32_t interval; - uint32_t cursor_max; - uint32_t extended_key; - color_t menu_sel_col; // öâåò ôîíà âûáðàííîãî ïîäïóíêòà - color_t bckg_text_col; // öâåò øðèôòà íåâûáðàííîãî ïóíêòà - color_t frnt_text_col; // öâåò øðèôòà âûáðàííîãî ïóíêòà - uint32_t mouse_keys_old; - uint32_t font_height; - uint32_t cursor_out; - uint32_t get_mouse_flag; + color_t bckg_col; // ôîí âåðõíåãî ïóêòà + color_t frnt_col; // ôîí âûáðàííîãî âåðõíåãî ïóíêòà + color_t menu_col; // ôîí âûïàäàþùåé ÷àñòè (ïîäïóêòû) + uint32_t select; + uint32_t out_select; + char* buf_adress; + char* procinfo; + uint32_t click; + uint32_t cursor; + uint32_t cursor_old; + uint32_t interval; + uint32_t cursor_max; + uint32_t extended_key; + color_t menu_sel_col; // öâåò ôîíà âûáðàííîãî ïîäïóíêòà + color_t bckg_text_col; // öâåò øðèôòà íåâûáðàííîãî ïóíêòà + color_t frnt_text_col; // öâåò øðèôòà âûáðàííîãî ïóíêòà + uint32_t mouse_keys_old; + uint32_t font_height; + uint32_t cursor_out; + uint32_t get_mouse_flag; } menubar; -extern void __stdcall (*menu_bar_draw)(menubar *); -extern void __stdcall (*menu_bar_mouse)(menubar *); -extern void __stdcall (*menu_bar_activate)(menubar *); +extern void __stdcall (*menu_bar_draw)(menubar*); +extern void __stdcall (*menu_bar_mouse)(menubar*); +extern void __stdcall (*menu_bar_activate)(menubar*); // OPTIONBOX typedef struct option_box_t { - struct option_box_t **selected; + struct option_box_t** selected; uint16_t posx; uint16_t posy; uint32_t text_margin; // = 4 ðàññòîÿíèå îò ïðÿìîóãîëüíèêà ÷åê áîêñà äî íàäïèñè - uint32_t size; // 12 ðàçìåð êâàäðàòà ÷åê áîêñà + uint32_t size; // 12 ðàçìåð êâàäðàòà ÷åê áîêñà color_t color; color_t border_color; // individual border color_t text_color; - char *text; + char* text; uint32_t text_len; uint32_t flags; -} __attribute__ ((__packed__)) option_box; +} __attribute__((__packed__)) option_box; -extern void __stdcall (*option_box_draw)(option_box **); -extern void __stdcall (*option_box_mouse)(option_box **); +extern void __stdcall (*option_box_draw)(option_box**); +extern void __stdcall (*option_box_mouse)(option_box**); // PATHSHOW typedef struct { - uint32_t type; - uint32_t x_y; - uint16_t font_size_x; // 6 - for font 0, 8 - for font 1 - uint16_t area_size_x; - uint32_t font_number; // 0 - monospace, 1 - variable, as fn4 (2bit only 0-3) + uint32_t type; + uint32_t x_y; + uint16_t font_size_x; // 6 - for font 0, 8 - for font 1 + uint16_t area_size_x; + uint32_t font_number; // 0 - monospace, 1 - variable, as fn4 (2bit only 0-3) uint32_t background_flag; // as fn4, if 0, bk_color unneeded - color_t font_color; // as fn4 - color_t background_color; // as fn4 + color_t font_color; // as fn4 + color_t background_color; // as fn4 char* text_pointer; // 4096 ? char* work_area_pointer; // 4096 ? uint32_t temp_text_length; -} __attribute__ ((__packed__)) pathview; +} __attribute__((__packed__)) pathview; -extern void __stdcall (*path_show_prepare)(pathview *); -extern void __stdcall (*path_show_draw)(pathview *); +extern void __stdcall (*path_show_prepare)(pathview*); +extern void __stdcall (*path_show_draw)(pathview*); // PROGRESSBAR typedef struct { - unsigned int value; + unsigned int value; unsigned int left; unsigned int top; unsigned int width; @@ -263,7 +263,7 @@ typedef struct { unsigned int frame_color; } progressbar; -extern void __stdcall (*progressbar_draw)(progressbar *); -extern void __stdcall (*progressbar_progress)(progressbar *); +extern void __stdcall (*progressbar_draw)(progressbar*); +extern void __stdcall (*progressbar_progress)(progressbar*); #endif /* KOLIBRI_BOXLIB_H */ diff --git a/programs/develop/ktcc/trunk/libc.obj/include/clayer/buf2d.h b/programs/develop/ktcc/trunk/libc.obj/include/clayer/buf2d.h index 38f6f62929..330de798b6 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/clayer/buf2d.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/clayer/buf2d.h @@ -1,83 +1,83 @@ #ifndef KOLIBRI_BUF2D_H #define KOLIBRI_BUF2D_H +#include #include #include -#include typedef struct { - unsigned int *buf_pointer; - uint16_t left; - uint16_t top; - unsigned int width; - unsigned int height; - unsigned int bgcolor; - uint8_t color_bit; -} __attribute__ ((__packed__))buf2d_struct; + unsigned int* buf_pointer; + uint16_t left; + uint16_t top; + unsigned int width; + unsigned int height; + unsigned int bgcolor; + uint8_t color_bit; +} __attribute__((__packed__)) buf2d_struct; enum BUF2D_ALGORITM_FILTR { - SIERRA_LITE, - FLOYD_STEINBERG, - BURKERS, - HEAVYIRON_MOD, - ATKINSON + SIERRA_LITE, + FLOYD_STEINBERG, + BURKERS, + HEAVYIRON_MOD, + ATKINSON }; enum BUF2D_OPT_CROP { - BUF2D_OPT_CROP_TOP = 1, - BUF2D_OPT_CROP_LEFT = 2, - BUF2D_OPT_CROP_BOTTOM = 4, - BUF2D_OPT_CROP_RIGHT = 8 + BUF2D_OPT_CROP_TOP = 1, + BUF2D_OPT_CROP_LEFT = 2, + BUF2D_OPT_CROP_BOTTOM = 4, + BUF2D_OPT_CROP_RIGHT = 8 }; int kolibri_buf2d_init(void); -extern void __stdcall (*buf2d_create_asm)(buf2d_struct *); -extern void __stdcall (*buf2d_curve_bezier_asm)(buf2d_struct *, unsigned int, unsigned int, unsigned int, unsigned int); +extern void __stdcall (*buf2d_create_asm)(buf2d_struct*); +extern void __stdcall (*buf2d_curve_bezier_asm)(buf2d_struct*, unsigned int, unsigned int, unsigned int, unsigned int); buf2d_struct* buf2d_create(uint16_t tlx, uint16_t tly, unsigned int sizex, unsigned int sizey, unsigned int font_bgcolor, uint8_t color_bit) { - buf2d_struct *new_buf2d_struct = (buf2d_struct *)_ksys_alloc(sizeof(buf2d_struct)); - new_buf2d_struct -> left = tlx; - new_buf2d_struct -> top = tly; - new_buf2d_struct -> width = sizex; - new_buf2d_struct -> height = sizey; - new_buf2d_struct -> bgcolor = font_bgcolor; - new_buf2d_struct -> color_bit = color_bit; - buf2d_create_asm(new_buf2d_struct); + buf2d_struct* new_buf2d_struct = (buf2d_struct*)_ksys_alloc(sizeof(buf2d_struct)); + new_buf2d_struct->left = tlx; + new_buf2d_struct->top = tly; + new_buf2d_struct->width = sizex; + new_buf2d_struct->height = sizey; + new_buf2d_struct->bgcolor = font_bgcolor; + new_buf2d_struct->color_bit = color_bit; + buf2d_create_asm(new_buf2d_struct); return new_buf2d_struct; } -void buf2d_curve_bezier(buf2d_struct *buf, unsigned int p0_x, unsigned int p0_y, unsigned int p1_x, unsigned int p1_y, unsigned int p2_x, unsigned int p2_y, unsigned int color) +void buf2d_curve_bezier(buf2d_struct* buf, unsigned int p0_x, unsigned int p0_y, unsigned int p1_x, unsigned int p1_y, unsigned int p2_x, unsigned int p2_y, unsigned int color) { - buf2d_curve_bezier_asm(buf, (p0_x<<16)+p0_y, (p1_x<<16)+p1_y, (p2_x<<16)+p2_y, color); + buf2d_curve_bezier_asm(buf, (p0_x << 16) + p0_y, (p1_x << 16) + p1_y, (p2_x << 16) + p2_y, color); } -extern void __stdcall (*buf2d_draw)(buf2d_struct *); -extern void __stdcall (*buf2d_clear)(buf2d_struct *, unsigned int); -extern void __stdcall (*buf2d_delete)(buf2d_struct *); -extern void __stdcall (*buf2d_rotate)(buf2d_struct *, unsigned int); -extern void __stdcall (*buf2d_resize)(buf2d_struct *, unsigned int, unsigned int, unsigned int); -extern void __stdcall (*buf2d_line)(buf2d_struct *, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int); -extern void __stdcall (*buf2d_line_sm)(buf2d_struct *, unsigned int, unsigned int, unsigned int, unsigned int); -extern void __stdcall (*buf2d_rect_by_size)(buf2d_struct *, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int); -extern void __stdcall (*buf2d_filled_rect_by_size)(buf2d_struct *, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int); -extern void __stdcall (*buf2d_circle)(buf2d_struct *, unsigned int, unsigned int, unsigned int, unsigned int); -extern void __stdcall (*buf2d_img_hdiv2)(buf2d_struct *); -extern void __stdcall (*buf2d_img_wdiv2)(buf2d_struct *); -extern void __stdcall (*buf2d_conv_24_to_8)(buf2d_struct *, unsigned int); -extern void __stdcall (*buf2d_conv_24_to_32)(buf2d_struct *, unsigned int); -extern void __stdcall (*buf2d_bit_blt_transp)(buf2d_struct *, unsigned int, unsigned int, buf2d_struct *); -extern void __stdcall (*buf2d_bit_blt_alpha)(buf2d_struct *, unsigned int, unsigned int, buf2d_struct *); -extern void __stdcall (*buf2d_convert_text_matrix)(buf2d_struct *); -extern void __stdcall (*buf2d_draw_text)(buf2d_struct *, buf2d_struct *, const char *, unsigned int, unsigned int); -extern void __stdcall (*buf2d_crop_color)(buf2d_struct *, unsigned int, unsigned int); -extern void __stdcall (*buf2d_offset_h)(buf2d_struct *, unsigned int, unsigned int, unsigned int); -extern void __stdcall (*buf2d_flood_fill)(buf2d_struct *, unsigned int, unsigned int, unsigned int, unsigned int); -extern void __stdcall (*buf2d_set_pixel)(buf2d_struct *, unsigned int, unsigned int, unsigned int); -extern unsigned __stdcall (*buf2d_get_pixel)(buf2d_struct *, unsigned int, unsigned int); -extern void __stdcall (*buf2d_flip_h)(buf2d_struct *); -extern void __stdcall (*buf2d_flip_v)(buf2d_struct *); -extern void __stdcall (*buf2d_filter_dither)(buf2d_struct *, unsigned int); +extern void __stdcall (*buf2d_draw)(buf2d_struct*); +extern void __stdcall (*buf2d_clear)(buf2d_struct*, unsigned int); +extern void __stdcall (*buf2d_delete)(buf2d_struct*); +extern void __stdcall (*buf2d_rotate)(buf2d_struct*, unsigned int); +extern void __stdcall (*buf2d_resize)(buf2d_struct*, unsigned int, unsigned int, unsigned int); +extern void __stdcall (*buf2d_line)(buf2d_struct*, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int); +extern void __stdcall (*buf2d_line_sm)(buf2d_struct*, unsigned int, unsigned int, unsigned int, unsigned int); +extern void __stdcall (*buf2d_rect_by_size)(buf2d_struct*, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int); +extern void __stdcall (*buf2d_filled_rect_by_size)(buf2d_struct*, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int); +extern void __stdcall (*buf2d_circle)(buf2d_struct*, unsigned int, unsigned int, unsigned int, unsigned int); +extern void __stdcall (*buf2d_img_hdiv2)(buf2d_struct*); +extern void __stdcall (*buf2d_img_wdiv2)(buf2d_struct*); +extern void __stdcall (*buf2d_conv_24_to_8)(buf2d_struct*, unsigned int); +extern void __stdcall (*buf2d_conv_24_to_32)(buf2d_struct*, unsigned int); +extern void __stdcall (*buf2d_bit_blt_transp)(buf2d_struct*, unsigned int, unsigned int, buf2d_struct*); +extern void __stdcall (*buf2d_bit_blt_alpha)(buf2d_struct*, unsigned int, unsigned int, buf2d_struct*); +extern void __stdcall (*buf2d_convert_text_matrix)(buf2d_struct*); +extern void __stdcall (*buf2d_draw_text)(buf2d_struct*, buf2d_struct*, const char*, unsigned int, unsigned int); +extern void __stdcall (*buf2d_crop_color)(buf2d_struct*, unsigned int, unsigned int); +extern void __stdcall (*buf2d_offset_h)(buf2d_struct*, unsigned int, unsigned int, unsigned int); +extern void __stdcall (*buf2d_flood_fill)(buf2d_struct*, unsigned int, unsigned int, unsigned int, unsigned int); +extern void __stdcall (*buf2d_set_pixel)(buf2d_struct*, unsigned int, unsigned int, unsigned int); +extern unsigned __stdcall (*buf2d_get_pixel)(buf2d_struct*, unsigned int, unsigned int); +extern void __stdcall (*buf2d_flip_h)(buf2d_struct*); +extern void __stdcall (*buf2d_flip_v)(buf2d_struct*); +extern void __stdcall (*buf2d_filter_dither)(buf2d_struct*, unsigned int); #endif /* KOLIBRI_BUF2D_H */ diff --git a/programs/develop/ktcc/trunk/libc.obj/include/clayer/dialog.h b/programs/develop/ktcc/trunk/libc.obj/include/clayer/dialog.h index f43b25887c..fa768c6883 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/clayer/dialog.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/clayer/dialog.h @@ -4,14 +4,14 @@ #include #define NOT_SUCCESS 0 -#define SUCCESS 1 +#define SUCCESS 1 -char sz_com_area_name[] = "FFFFFFFF_open_dialog"; +char sz_com_area_name[] = "FFFFFFFF_open_dialog"; char sz_dir_default_path[] = "/sys"; -char sz_start_path[] = "/sys/File managers/opendial"; +char sz_start_path[] = "/sys/File managers/opendial"; -char cd_com_area_name[] = "FFFFFFFF_color_dialog"; -char cd_start_path[] = "/sys/colrdial"; +char cd_com_area_name[] = "FFFFFFFF_color_dialog"; +char cd_start_path[] = "/sys/colrdial"; enum open_dialog_mode { OPEN, @@ -20,9 +20,9 @@ enum open_dialog_mode { }; typedef struct { - unsigned int size; - unsigned char end; -}od_filter __attribute__ ((__packed__)); + unsigned int size; + unsigned char end; +} od_filter __attribute__((__packed__)); typedef struct { unsigned int mode; @@ -41,10 +41,9 @@ typedef struct { unsigned short x_start; unsigned short y_size; unsigned short y_start; -}open_dialog __attribute__ ((__packed__)); +} open_dialog __attribute__((__packed__)); - -typedef struct{ +typedef struct { unsigned int type; char* procinfo; char* com_area_name; @@ -58,70 +57,70 @@ typedef struct{ unsigned short y_start; unsigned int color_type; unsigned int color; -}color_dialog __attribute__ ((__packed__)); +} color_dialog __attribute__((__packed__)); -void fake_on_redraw(void) {} +void fake_on_redraw(void) { } open_dialog* kolibri_new_open_dialog(unsigned int mode, unsigned short tlx, unsigned short tly, unsigned short x_size, unsigned short y_size) { - open_dialog *new_opendialog = (open_dialog *)malloc(sizeof(open_dialog)); - od_filter *new_od_filter = (od_filter *)malloc(sizeof(od_filter)); - char *plugin_path = (char *)calloc(4096, sizeof(char)); - char *openfile_path = (char *)calloc(4096, sizeof(char)); - char *proc_info = (char *)calloc(1024, sizeof(char)); - char *filename_area = (char *)calloc(256, sizeof(char)); + open_dialog* new_opendialog = (open_dialog*)malloc(sizeof(open_dialog)); + od_filter* new_od_filter = (od_filter*)malloc(sizeof(od_filter)); + char* plugin_path = (char*)calloc(4096, sizeof(char)); + char* openfile_path = (char*)calloc(4096, sizeof(char)); + char* proc_info = (char*)calloc(1024, sizeof(char)); + char* filename_area = (char*)calloc(256, sizeof(char)); - new_od_filter -> size = 0; - new_od_filter -> end = 0; + new_od_filter->size = 0; + new_od_filter->end = 0; - new_opendialog -> mode = mode; - new_opendialog -> procinfo = proc_info; - new_opendialog -> com_area_name = sz_com_area_name; - new_opendialog -> com_area = 0; - new_opendialog -> opendir_path = plugin_path; - new_opendialog -> dir_default_path = sz_dir_default_path; - new_opendialog -> start_path = sz_start_path; - new_opendialog -> draw_window = &fake_on_redraw; - new_opendialog -> status = 0; - new_opendialog -> openfile_path = openfile_path; - new_opendialog -> filename_area = filename_area; - new_opendialog -> filter_area = new_od_filter; - new_opendialog -> x_size = x_size; - new_opendialog -> x_start = tlx; - new_opendialog -> y_size = y_size; - new_opendialog -> y_start = tly; - return new_opendialog; + new_opendialog->mode = mode; + new_opendialog->procinfo = proc_info; + new_opendialog->com_area_name = sz_com_area_name; + new_opendialog->com_area = 0; + new_opendialog->opendir_path = plugin_path; + new_opendialog->dir_default_path = sz_dir_default_path; + new_opendialog->start_path = sz_start_path; + new_opendialog->draw_window = &fake_on_redraw; + new_opendialog->status = 0; + new_opendialog->openfile_path = openfile_path; + new_opendialog->filename_area = filename_area; + new_opendialog->filter_area = new_od_filter; + new_opendialog->x_size = x_size; + new_opendialog->x_start = tlx; + new_opendialog->y_size = y_size; + new_opendialog->y_start = tly; + return new_opendialog; } -void cd_fake_on_redraw(void) {} +void cd_fake_on_redraw(void) { } color_dialog* kolibri_new_color_dialog(unsigned int type, unsigned short tlx, unsigned short tly, unsigned short x_size, unsigned short y_size) { - color_dialog *new_colordialog = (color_dialog *)malloc(sizeof(color_dialog)); - char *proc_info = (char *)calloc(1024, sizeof(char)); + color_dialog* new_colordialog = (color_dialog*)malloc(sizeof(color_dialog)); + char* proc_info = (char*)calloc(1024, sizeof(char)); - new_colordialog -> type = type; - new_colordialog -> procinfo = proc_info; - new_colordialog -> com_area_name = cd_com_area_name; - new_colordialog -> com_area = 0; - new_colordialog -> start_path = cd_start_path; - new_colordialog -> draw_window = &cd_fake_on_redraw; - new_colordialog -> status = 0; - new_colordialog -> x_size = x_size; - new_colordialog -> x_start = tlx; - new_colordialog -> y_size = y_size; - new_colordialog -> y_start = tly; - new_colordialog -> color_type = 0; - new_colordialog -> color = 0; - return new_colordialog; + new_colordialog->type = type; + new_colordialog->procinfo = proc_info; + new_colordialog->com_area_name = cd_com_area_name; + new_colordialog->com_area = 0; + new_colordialog->start_path = cd_start_path; + new_colordialog->draw_window = &cd_fake_on_redraw; + new_colordialog->status = 0; + new_colordialog->x_size = x_size; + new_colordialog->x_start = tlx; + new_colordialog->y_size = y_size; + new_colordialog->y_start = tly; + new_colordialog->color_type = 0; + new_colordialog->color = 0; + return new_colordialog; } void kolibri_dialog_init(); -extern void __stdcall (*OpenDialog_init)(open_dialog *); -extern void __stdcall (*OpenDialog_start)(open_dialog *); +extern void __stdcall (*OpenDialog_init)(open_dialog*); +extern void __stdcall (*OpenDialog_start)(open_dialog*); -extern void __stdcall (*ColorDialog_init)(color_dialog *); -extern void __stdcall (*ColorDialog_start)(color_dialog *); +extern void __stdcall (*ColorDialog_init)(color_dialog*); +extern void __stdcall (*ColorDialog_start)(color_dialog*); #endif diff --git a/programs/develop/ktcc/trunk/libc.obj/include/clayer/gb.h b/programs/develop/ktcc/trunk/libc.obj/include/clayer/gb.h index 564bbd7d6c..df0411e24d 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/clayer/gb.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/clayer/gb.h @@ -1,23 +1,23 @@ -#ifndef KOLIBRI_GB_H +#ifndef KOLIBRI_GB_H #define KOLIBRI_GB_H #pragma pack(push, 1) typedef struct { - int w; - int h; - char *bmp; - char *alpha; + int w; + int h; + char* bmp; + char* alpha; } GB_BMP; #pragma pack(pop) -void gb_pixel_set(GB_BMP *b, int x, int y, unsigned c); -int gb_pixel_get(GB_BMP *b, int x, int y, unsigned *c); -void gb_line(GB_BMP *b, int x1, int y1, int x2, int y2, unsigned c); -void gb_rect(GB_BMP *b, int x, int y, int w, int h, unsigned c); -void gb_bar(GB_BMP *b, int x, int y, int w, int h, unsigned c); -void gb_circle(GB_BMP *b, int x, int y, int r, unsigned c); -void gb_image_set(GB_BMP *b_dest, int x_d, int y_d, GB_BMP *b_src, int x_s, int y_s, int w, int h); -void gb_image_set_t(GB_BMP *b_dest, int x_d, int y_d, GB_BMP *b_src, int x_s, int y_s, int w, int h, unsigned c); +void gb_pixel_set(GB_BMP* b, int x, int y, unsigned c); +int gb_pixel_get(GB_BMP* b, int x, int y, unsigned* c); +void gb_line(GB_BMP* b, int x1, int y1, int x2, int y2, unsigned c); +void gb_rect(GB_BMP* b, int x, int y, int w, int h, unsigned c); +void gb_bar(GB_BMP* b, int x, int y, int w, int h, unsigned c); +void gb_circle(GB_BMP* b, int x, int y, int r, unsigned c); +void gb_image_set(GB_BMP* b_dest, int x_d, int y_d, GB_BMP* b_src, int x_s, int y_s, int w, int h); +void gb_image_set_t(GB_BMP* b_dest, int x_d, int y_d, GB_BMP* b_src, int x_s, int y_s, int w, int h, unsigned c); #endif // KOLIBRI_GB_H \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/include/conio.h b/programs/develop/ktcc/trunk/libc.obj/include/conio.h index 03fda9a338..73fa14b179 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/conio.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/conio.h @@ -1,7 +1,6 @@ /* - This is adapded thunk for console.obj sys library -.h is equal to svn:\programs\develop\libraries\console\console_en.txt +.h is equal to svn:\programs\develop\libraries\console\console_en.txt Adapted for tcc by Siemargl, 2016 @@ -15,19 +14,19 @@ Adapted for tcc by Siemargl, 2016 console.obj exports the following functions */ -typedef unsigned int dword; /* 32-bit unsigned integer */ +typedef unsigned int dword; /* 32-bit unsigned integer */ typedef unsigned short word; /* 16-bit unsigned integer */ #define CON_WINDOW_CLOSED 0x200 -#define CON_COLOR_BLUE 0x01 -#define CON_COLOR_GREEN 0x02 -#define CON_COLOR_RED 0x04 -#define CON_COLOR_BRIGHT 0x08 +#define CON_COLOR_BLUE 0x01 +#define CON_COLOR_GREEN 0x02 +#define CON_COLOR_RED 0x04 +#define CON_COLOR_BRIGHT 0x08 /* background color */ -#define CON_BGR_BLUE 0x10 -#define CON_BGR_GREEN 0x20 -#define CON_BGR_RED 0x40 +#define CON_BGR_BLUE 0x10 +#define CON_BGR_GREEN 0x20 +#define CON_BGR_RED 0x40 #define CON_BGR_BRIGHT 0x80 /* output controls */ @@ -35,25 +34,25 @@ typedef unsigned short word; /* 16-bit unsigned integer */ extern int _FUNC(con_init)(void); extern int _FUNC(con_init_opt)(dword wnd_width, dword wnd_height, dword scr_width, dword scr_height, const char* title); -extern void __stdcall _FUNC((*con_exit))(int bCloseWindow); -extern void __stdcall _FUNC((*con_set_title))(const char* title); -extern void __stdcall _FUNC((*con_write_asciiz))(const char* str); -extern void __stdcall _FUNC((*con_write_string))(const char* str, dword length); +extern void __stdcall _FUNC((*con_exit))(int bCloseWindow); +extern void __stdcall _FUNC((*con_set_title))(const char* title); +extern void __stdcall _FUNC((*con_write_asciiz))(const char* str); +extern void __stdcall _FUNC((*con_write_string))(const char* str, dword length); extern int __cdecl _FUNC((*con_printf))(const char* format, ...); -extern dword __stdcall _FUNC((*con_get_flags))(void); -extern dword __stdcall _FUNC((*con_set_flags))(dword new_flags); -extern int __stdcall _FUNC((*con_get_font_height))(void); -extern int __stdcall _FUNC((*con_get_cursor_height))(void); -extern int __stdcall _FUNC((*con_set_cursor_height))(int new_height); -extern int __stdcall _FUNC((*con_getch))(void); -extern word __stdcall _FUNC((*con_getch2))(void); -extern int __stdcall _FUNC((*con_kbhit))(void); -extern char* __stdcall _FUNC((*con_gets))(char* str, int n); -typedef int __stdcall _FUNC(* con_gets2_callback)(int keycode, char** pstr, int* pn, int* ppos); -extern char* __stdcall _FUNC((*con_gets2))(con_gets2_callback callback, char* str, int n); -extern void __stdcall _FUNC((*con_cls))(); -extern void __stdcall _FUNC((*con_get_cursor_pos))(int* px, int* py); -extern void __stdcall _FUNC((*con_set_cursor_pos))(int x, int y); +extern dword __stdcall _FUNC((*con_get_flags))(void); +extern dword __stdcall _FUNC((*con_set_flags))(dword new_flags); +extern int __stdcall _FUNC((*con_get_font_height))(void); +extern int __stdcall _FUNC((*con_get_cursor_height))(void); +extern int __stdcall _FUNC((*con_set_cursor_height))(int new_height); +extern int __stdcall _FUNC((*con_getch))(void); +extern word __stdcall _FUNC((*con_getch2))(void); +extern int __stdcall _FUNC((*con_kbhit))(void); +extern char* __stdcall _FUNC((*con_gets))(char* str, int n); +typedef int __stdcall _FUNC (*con_gets2_callback)(int keycode, char** pstr, int* pn, int* ppos); +extern char* __stdcall _FUNC((*con_gets2))(con_gets2_callback callback, char* str, int n); +extern void __stdcall _FUNC((*con_cls))(); +extern void __stdcall _FUNC((*con_get_cursor_pos))(int* px, int* py); +extern void __stdcall _FUNC((*con_set_cursor_pos))(int x, int y); extern int _FUNC(__con_is_load); #endif diff --git a/programs/develop/ktcc/trunk/libc.obj/include/ctype.h b/programs/develop/ktcc/trunk/libc.obj/include/ctype.h index bab080c8df..05b7f9a2fd 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/ctype.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/ctype.h @@ -8,37 +8,37 @@ #include -#define __ALNUM 1 -#define __ALPHA 2 -#define __CNTRL 4 -#define __DIGIT 8 -#define __GRAPH 16 -#define __LOWER 32 -#define __PRINT 64 -#define __PUNCT 128 -#define __BLANK 256 -#define __UPPER 512 +#define __ALNUM 1 +#define __ALPHA 2 +#define __CNTRL 4 +#define __DIGIT 8 +#define __GRAPH 16 +#define __LOWER 32 +#define __PRINT 64 +#define __PUNCT 128 +#define __BLANK 256 +#define __UPPER 512 #define __XDIGIT 1024 -#ifdef _BUILD_LIBC +#ifdef _BUILD_LIBC extern unsigned short __is[129]; #else -extern unsigned short *__is; +extern unsigned short* __is; #endif -#define isalnum(c)(__is[c+1] & __ALNUM ) /* 'a'-'z', 'A'-'Z', '0'-'9' */ -#define isalpha(c)(__is[c+1] & __ALPHA ) /* 'a'-'z', 'A'-'Z' */ -#define iscntrl(c)(__is[c+1] & __CNTRL ) /* 0-31, 127 */ -#define isdigit(c)(__is[c+1] & __DIGIT ) /* '0'-'9' */ -#define isgraph(c)(__is[c+1] & __GRAPH ) /* '!'-'~' */ -#define islower(c)(__is[c+1] & __LOWER ) /* 'a'-'z' */ -#define isprint(c)(__is[c+1] & __PRINT ) /* ' '-'~' */ -#define ispunct(c)(__is[c+1] & __PUNCT ) /* !alnum && !cntrl && !space */ -#define isspace(c)(__is[c+1] & __BLANK ) /* HT, LF, VT, FF, CR, ' ' */ -#define isupper(c)(__is[c+1] & __UPPER ) /* 'A'-'Z' */ -#define isxdigit(c)(__is[c+1] & __XDIGIT) /* '0'-'9', 'a'-'f', 'A'-'F' */ +#define isalnum(c) (__is[c + 1] & __ALNUM) /* 'a'-'z', 'A'-'Z', '0'-'9' */ +#define isalpha(c) (__is[c + 1] & __ALPHA) /* 'a'-'z', 'A'-'Z' */ +#define iscntrl(c) (__is[c + 1] & __CNTRL) /* 0-31, 127 */ +#define isdigit(c) (__is[c + 1] & __DIGIT) /* '0'-'9' */ +#define isgraph(c) (__is[c + 1] & __GRAPH) /* '!'-'~' */ +#define islower(c) (__is[c + 1] & __LOWER) /* 'a'-'z' */ +#define isprint(c) (__is[c + 1] & __PRINT) /* ' '-'~' */ +#define ispunct(c) (__is[c + 1] & __PUNCT) /* !alnum && !cntrl && !space */ +#define isspace(c) (__is[c + 1] & __BLANK) /* HT, LF, VT, FF, CR, ' ' */ +#define isupper(c) (__is[c + 1] & __UPPER) /* 'A'-'Z' */ +#define isxdigit(c) (__is[c + 1] & __XDIGIT) /* '0'-'9', 'a'-'f', 'A'-'F' */ -#define isascii(c) (!((c)&(~0x7f))) +#define isascii(c) (!((c) & (~0x7f))) #define toascii(c) ((c)&0x7f) extern int _FUNC(tolower)(int c); diff --git a/programs/develop/ktcc/trunk/libc.obj/include/errno.h b/programs/develop/ktcc/trunk/libc.obj/include/errno.h index a7a1fa8426..51f6e5c658 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/errno.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/errno.h @@ -3,148 +3,58 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - #ifdef _BUILD_LIBC -extern int _errno; -#define errno _errno +#define errno __errno +extern int __errno; #else -extern int* _errno; -#define errno *_errno +extern int* __errno; +#define errno *__errno #endif -#define EPERM 1 /* Operation not permitted */ -#define ENOENT 2 /* No such file or directory */ -#define ESRCH 3 /* No such process */ -#define EINTR 4 /* Interrupted system call */ -#define EIO 5 /* Input/output error */ -#define ENXIO 6 /* Device not configured */ -#define E2BIG 7 /* Argument list too long */ -#define ENOEXEC 8 /* Exec format error */ -#define EBADF 9 /* Bad file descriptor */ -#define ECHILD 10 /* No child processes */ -#define EDEADLK 11 /* Resource deadlock avoided */ -/* 11 was EAGAIN */ -#define ENOMEM 12 /* Cannot allocate memory */ -#define EACCES 13 /* Permission denied */ -#define EFAULT 14 /* Bad address */ -#define ENOTBLK 15 /* Block device required */ -#define EBUSY 16 /* Device / Resource busy */ -#define EEXIST 17 /* File exists */ -#define EXDEV 18 /* Cross-device link */ -#define ENODEV 19 /* Operation not supported by device */ -#define ENOTDIR 20 /* Not a directory */ -#define EISDIR 21 /* Is a directory */ -#define EINVAL 22 /* Invalid argument */ -#define ENFILE 23 /* Too many open files in system */ -#define EMFILE 24 /* Too many open files */ -#define ENOTTY 25 /* Inappropriate ioctl for device */ -#define ETXTBSY 26 /* Text file busy */ -#define EFBIG 27 /* File too large */ -#define ENOSPC 28 /* No space left on device */ -#define ESPIPE 29 /* Illegal seek */ -#define EROFS 30 /* Read-only file system */ -#define EMLINK 31 /* Too many links */ -#define EPIPE 32 /* Broken pipe */ +#define ENOTSUP 2 // Function is not supported +#define EUNKNFS 3 // Unknown file system +#define ENOTFOUND 5 // File not found +#define EEOF 6 // End of file +#define EFAULT 7 // Pointer lies outside of application memory +#define EDQUOT 8 // Disk is full +#define EFS 9 // File system error +#define EACCES 10 // Access denied +#define EDEV 11 // Device error +#define ENOMEMFS 12 // File system requires more memory -/* math software */ -#define EDOM 33 /* Numerical argument out of domain */ -#define ERANGE 34 /* Result too large */ +#define ENOMEM 30 // Not enough memory +#define ENOEXEC 31 // Is not executable +#define EPROCLIM 32 // Too many processes +#define EINVAL 33 // Invalid argument -/* non-blocking and interrupt i/o */ -#define EAGAIN 35 /* Resource temporarily unavailable */ -#define EWOULDBLOCK EAGAIN /* Operation would block */ -#define EINPROGRESS 36 /* Operation now in progress */ -#define EALREADY 37 /* Operation already in progress */ +#define EDOM 50 // Numerical argument out of domain +#define ERANGE 51 // Result too large +#define EILSEQ 52 // Illegal byte sequence -/* ipc/network software -- argument errors */ -#define ENOTSOCK 38 /* Socket operation on non-socket */ -#define EDESTADDRREQ 39 /* Destination address required */ -#define EMSGSIZE 40 /* Message too long */ -#define EPROTOTYPE 41 /* Protocol wrong type for socket */ -#define ENOPROTOOPT 42 /* Protocol not available */ -#define EPROTONOSUPPORT 43 /* Protocol not supported */ -#define ESOCKTNOSUPPORT 44 /* Socket type not supported */ -#define ENOTSUP 45 /* Operation not supported */ -#define EOPNOTSUPP ENOTSUP /* Operation not supported on socket */ -#define EPFNOSUPPORT 46 /* Protocol family not supported */ -#define EAFNOSUPPORT 47 /* Address family not supported by protocol family */ -#define EADDRINUSE 48 /* Address already in use */ -#define EADDRNOTAVAIL 49 /* Can't assign requested address */ +#define ENOBUFS 60 // Broken buffer +#define EINPROGRESS 61 // Operation now in progress +#define EOPNOTSUPP 62 // Operation not supported on transport endpoint +#define EWOULDBLOCK 63 // Operation would block +#define ENOTCONN 64 // Transport endpoint is not connected +#define EALREADY 65 // Operation already in progress +#define EMSGSIZE 66 // Message too long +#define EADDRINUSE 67 // Address already in use +#define ECONNREFUSED 68 // Connection refused +#define ECONNRESET 69 // Connection reset by peer +#define EISCONN 70 // Transport endpoint is already connected +#define ETIMEDOUT 71 // Connection timed out +#define ECONNABORTED 72 // Software caused connection abort -/* ipc/network software -- operational errors */ -#define ENETDOWN 50 /* Network is down */ -#define ENETUNREACH 51 /* Network is unreachable */ -#define ENETRESET 52 /* Network dropped connection on reset */ -#define ECONNABORTED 53 /* Software caused connection abort */ -#define ECONNRESET 54 /* Connection reset by peer */ -#define ENOBUFS 55 /* No buffer space available */ -#define EISCONN 56 /* Socket is already connected */ -#define ENOTCONN 57 /* Socket is not connected */ -#define ESHUTDOWN 58 /* Can't send after socket shutdown */ -#define ETOOMANYREFS 59 /* Too many references: can't splice */ -#define ETIMEDOUT 60 /* Operation timed out */ -#define ECONNREFUSED 61 /* Connection refused */ -#define ELOOP 62 /* Too many levels of symbolic links */ -#define ENAMETOOLONG 63 /* File name too long */ +/* +* UNIX-like errno +* Will be removed after changing STDIO. +*/ -/* should be rearranged */ -#define EHOSTDOWN 64 /* Host is down */ -#define EHOSTUNREACH 65 /* No route to host */ -#define ENOTEMPTY 66 /* Directory not empty */ - -/* quotas & mush */ -#define EPROCLIM 67 /* Too many processes */ -#define EUSERS 68 /* Too many users */ -#define EDQUOT 69 /* Disc quota exceeded */ - -/* Network File System */ -#define ESTALE 70 /* Stale NFS file handle */ -#define EREMOTE 71 /* Too many levels of remote in path */ -#define EBADRPC 72 /* RPC struct is bad */ -#define ERPCMISMATCH 73 /* RPC version wrong */ -#define EPROGUNAVAIL 74 /* RPC prog. not avail */ -#define EPROGMISMATCH 75 /* Program version wrong */ -#define EPROCUNAVAIL 76 /* Bad procedure for program */ -#define ENOLCK 77 /* No locks available */ -#define ENOSYS 78 /* Function not implemented */ -#define EFTYPE 79 /* Inappropriate file type or format */ -#define EAUTH 80 /* Authentication error */ -#define ENEEDAUTH 81 /* Need authenticator */ - -/* Intelligent device errors */ -#define EPWROFF 82 /* Device power is off */ -#define EDEVERR 83 /* Device error, e.g. paper out */ -#define EOVERFLOW 84 /* Value too large to be stored in data type */ - -/* Program loading errors */ -#define EBADEXEC 85 /* Bad executable */ -#define EBADARCH 86 /* Bad CPU type in executable */ -#define ESHLIBVERS 87 /* Shared library version mismatch */ -#define EBADMACHO 88 /* Malformed Macho file */ -#define ECANCELED 89 /* Operation canceled */ -#define EIDRM 90 /* Identifier removed */ -#define ENOMSG 91 /* No message of desired type */ -#define EILSEQ 92 /* Illegal byte sequence */ -#define ENOATTR 93 /* Attribute not found */ -#define EBADMSG 94 /* Bad message */ -#define EMULTIHOP 95 /* Reserved */ -#define ENODATA 96 /* No message available on STREAM */ -#define ENOLINK 97 /* Reserved */ -#define ENOSR 98 /* No STREAM resources */ -#define ENOSTR 99 /* Not a STREAM */ -#define EPROTO 100 /* Protocol error */ -#define ETIME 101 /* STREAM ioctl timeout */ -#define ENOPOLICY 103 /* No such policy registered */ -#define ENOTRECOVERABLE 104 /* State not recoverable */ -#define EOWNERDEAD 105 /* Previous owner died */ -#define EQFULL 106 /* Interface output queue is full */ -#define ELAST 106 /* Must be equal largest errno */ - -#ifdef __cplusplus -} -#endif +#define ENOTDIR 80 +#define EBADF 81 +#define EIO 82 +#define EISDIR 83 +#define ENOENT 84 +#define EOVERFLOW 85 #endif // _ERRNO_H_ diff --git a/programs/develop/ktcc/trunk/libc.obj/include/float.h b/programs/develop/ktcc/trunk/libc.obj/include/float.h index a2b4ed26a0..d30446fb23 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/float.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/float.h @@ -4,62 +4,62 @@ #define FLT_RADIX 2 /* IEEE float */ -#define FLT_MANT_DIG 24 -#define FLT_DIG 6 -#define FLT_ROUNDS 1 -#define FLT_EPSILON 1.19209290e-07F -#define FLT_MIN_EXP (-125) -#define FLT_MIN 1.17549435e-38F +#define FLT_MANT_DIG 24 +#define FLT_DIG 6 +#define FLT_ROUNDS 1 +#define FLT_EPSILON 1.19209290e-07F +#define FLT_MIN_EXP (-125) +#define FLT_MIN 1.17549435e-38F #define FLT_MIN_10_EXP (-37) -#define FLT_MAX_EXP 128 -#define FLT_MAX 3.40282347e+38F +#define FLT_MAX_EXP 128 +#define FLT_MAX 3.40282347e+38F #define FLT_MAX_10_EXP 38 /* IEEE double */ -#define DBL_MANT_DIG 53 -#define DBL_DIG 15 -#define DBL_EPSILON 2.2204460492503131e-16 -#define DBL_MIN_EXP (-1021) -#define DBL_MIN 2.2250738585072014e-308 +#define DBL_MANT_DIG 53 +#define DBL_DIG 15 +#define DBL_EPSILON 2.2204460492503131e-16 +#define DBL_MIN_EXP (-1021) +#define DBL_MIN 2.2250738585072014e-308 #define DBL_MIN_10_EXP (-307) -#define DBL_MAX_EXP 1024 -#define DBL_MAX 1.7976931348623157e+308 +#define DBL_MAX_EXP 1024 +#define DBL_MAX 1.7976931348623157e+308 #define DBL_MAX_10_EXP 308 /* horrible intel long double */ #if defined __i386__ || defined __x86_64__ -#define LDBL_MANT_DIG 64 -#define LDBL_DIG 18 -#define LDBL_EPSILON 1.08420217248550443401e-19L -#define LDBL_MIN_EXP (-16381) -#define LDBL_MIN 3.36210314311209350626e-4932L +#define LDBL_MANT_DIG 64 +#define LDBL_DIG 18 +#define LDBL_EPSILON 1.08420217248550443401e-19L +#define LDBL_MIN_EXP (-16381) +#define LDBL_MIN 3.36210314311209350626e-4932L #define LDBL_MIN_10_EXP (-4931) -#define LDBL_MAX_EXP 16384 -#define LDBL_MAX 1.18973149535723176502e+4932L +#define LDBL_MAX_EXP 16384 +#define LDBL_MAX 1.18973149535723176502e+4932L #define LDBL_MAX_10_EXP 4932 #else /* same as IEEE double */ -#define LDBL_MANT_DIG 53 -#define LDBL_DIG 15 -#define LDBL_EPSILON 2.2204460492503131e-16 -#define LDBL_MIN_EXP (-1021) -#define LDBL_MIN 2.2250738585072014e-308 +#define LDBL_MANT_DIG 53 +#define LDBL_DIG 15 +#define LDBL_EPSILON 2.2204460492503131e-16 +#define LDBL_MIN_EXP (-1021) +#define LDBL_MIN 2.2250738585072014e-308 #define LDBL_MIN_10_EXP (-307) -#define LDBL_MAX_EXP 1024 -#define LDBL_MAX 1.7976931348623157e+308 +#define LDBL_MAX_EXP 1024 +#define LDBL_MAX 1.7976931348623157e+308 #define LDBL_MAX_10_EXP 308 #endif #ifndef NAN -# define NAN (__nan__) +#define NAN (__nan__) #endif #ifndef INFINITY -# define INFINITY (__inf__) +#define INFINITY (__inf__) #endif #endif /* _FLOAT_H_ */ diff --git a/programs/develop/ktcc/trunk/libc.obj/include/limits.h b/programs/develop/ktcc/trunk/libc.obj/include/limits.h index 6f0103663f..8f1dbfa974 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/limits.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/limits.h @@ -1,44 +1,43 @@ #ifndef _LIMITS_H_ #define _LIMITS_H_ - -#define CHAR_BIT 8 -#define CHAR_MAX 127 -#define CHAR_MIN (-128) -#define INT_MAX 2147483647 -#define INT_MIN (-2147483647-1) -#define LONG_MAX 2147483647L -#define LONG_MIN (-2147483647L-1L) -#define MB_LEN_MAX 5 -#define SCHAR_MAX 127 -#define SCHAR_MIN (-128) -#define SHRT_MAX 32767 -#define SHRT_MIN (-32768) -#define UCHAR_MAX 255 -#define UINT_MAX 4294967295U -#define ULONG_MAX 4294967295UL -#define USHRT_MAX 65535 -#define WCHAR_MIN 0 -#define WCHAR_MAX 127 -#define WINT_MIN 0 -#define WINT_MAX 32767 -#define SSIZE_MAX 2147483647 - -#define LLONG_MIN (-9223372036854775807LL-1LL) -#define LLONG_MAX 9223372036854775807LL -#define ULLONG_MAX 18446744073709551615ULL + +#define CHAR_BIT 8 +#define CHAR_MAX 127 +#define CHAR_MIN (-128) +#define INT_MAX 2147483647 +#define INT_MIN (-2147483647 - 1) +#define LONG_MAX 2147483647L +#define LONG_MIN (-2147483647L - 1L) +#define MB_LEN_MAX 5 +#define SCHAR_MAX 127 +#define SCHAR_MIN (-128) +#define SHRT_MAX 32767 +#define SHRT_MIN (-32768) +#define UCHAR_MAX 255 +#define UINT_MAX 4294967295U +#define ULONG_MAX 4294967295UL +#define USHRT_MAX 65535 +#define WCHAR_MIN 0 +#define WCHAR_MAX 127 +#define WINT_MIN 0 +#define WINT_MAX 32767 +#define SSIZE_MAX 2147483647 + +#define LLONG_MIN (-9223372036854775807LL - 1LL) +#define LLONG_MAX 9223372036854775807LL +#define ULLONG_MAX 18446744073709551615ULL /* gnuc ones */ -#define LONG_LONG_MIN LLONG_MIN -#define LONG_LONG_MAX LLONG_MAX -#define ULONG_LONG_MAX ULLONG_MAX - +#define LONG_LONG_MIN LLONG_MIN +#define LONG_LONG_MAX LLONG_MAX +#define ULONG_LONG_MAX ULLONG_MAX #ifndef ARG_MAX -#define ARG_MAX 4096 +#define ARG_MAX 4096 #endif - + #ifndef PATH_MAX -#define PATH_MAX 4096 +#define PATH_MAX 4096 #endif #ifndef STDIO_MAX_MEM diff --git a/programs/develop/ktcc/trunk/libc.obj/include/math.h b/programs/develop/ktcc/trunk/libc.obj/include/math.h index b1749dc50b..b2373f5709 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/math.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/math.h @@ -6,166 +6,59 @@ #include -#ifdef __cplusplus -extern "C" { -#endif +extern double _FUNC(acos)(double _x); +extern double _FUNC(asin)(double _x); +extern double _FUNC(atan)(double _x); +extern double _FUNC(atan2)(double _y, double _x); +extern double _FUNC(ceil)(double _x); +extern double _FUNC(cos)(double _x); +extern double _FUNC(cosh)(double _x); +extern double _FUNC(exp)(double _x); +extern double _FUNC(fabs)(double _x); +extern double _FUNC(floor)(double _x); +extern double _FUNC(fmod)(double _x, double _y); +extern double _FUNC(frexp)(double _x, int* _pexp); +extern double _FUNC(ldexp)(double _x, int _exp); +extern double _FUNC(log)(double _y); +extern double _FUNC(log10)(double _x); +extern double _FUNC(modf)(double _x, double* _pint); +extern double _FUNC(pow)(double _x, double _y); +extern double _FUNC(sin)(double _x); +extern double _FUNC(sinh)(double _x); +extern double _FUNC(sqrt)(double _x); +extern double _FUNC(tan)(double _x); +extern double _FUNC(tanh)(double _x); +extern double _FUNC(acosh)(double); +extern double _FUNC(asinh)(double); +extern double _FUNC(atanh)(double); +extern double _FUNC(hypot)(double, double); +extern long double _FUNC(modfl)(long double _x, long double* _pint); +extern double _FUNC(pow10)(double _x); +extern double _FUNC(pow2)(double _x); -extern double _FUNC(acos)(double _x); -extern double _FUNC(asin)(double _x); -extern double _FUNC(atan)(double _x); -extern double _FUNC(atan2)(double _y, double _x); -extern double _FUNC(ceil)(double _x); -extern double _FUNC(cos)(double _x); -extern double _FUNC(cosh)(double _x); -extern double _FUNC(exp)(double _x); -extern double _FUNC(fabs)(double _x); -extern double _FUNC(floor)(double _x); -extern double _FUNC(fmod)(double _x, double _y); -extern double _FUNC(frexp)(double _x, int *_pexp); -extern double _FUNC(ldexp)(double _x, int _exp); -extern double _FUNC(log)(double _y); -extern double _FUNC(log10)(double _x); -extern double _FUNC(modf)(double _x, double *_pint); -extern double _FUNC(pow)(double _x, double _y); -extern double _FUNC(sin)(double _x); -extern double _FUNC(sinh)(double _x); -extern double _FUNC(sqrt)(double _x); -extern double _FUNC(tan)(double _x); -extern double _FUNC(tanh)(double _x); +#define M_E 2.7182818284590452354 +#define M_LOG2E 1.4426950408889634074 +#define M_LOG10E 0.43429448190325182765 +#define M_LN2 0.69314718055994530942 +#define M_LN10 2.30258509299404568402 +#define M_PI 3.14159265358979323846 +#define M_PI_2 1.57079632679489661923 +#define M_PI_4 0.78539816339744830962 +#define M_1_PI 0.31830988618379067154 +#define M_2_PI 0.63661977236758134308 +#define M_2_SQRTPI 1.12837916709551257390 +#define M_SQRT2 1.41421356237309504880 +#define M_SQRT1_2 0.70710678118654752440 +#define PI M_PI +#define PI2 M_PI_2 -#define M_E 2.7182818284590452354 -#define M_LOG2E 1.4426950408889634074 -#define M_LOG10E 0.43429448190325182765 -#define M_LN2 0.69314718055994530942 -#define M_LN10 2.30258509299404568402 -#define M_PI 3.14159265358979323846 -#define M_PI_2 1.57079632679489661923 -#define M_PI_4 0.78539816339744830962 -#define M_1_PI 0.31830988618379067154 -#define M_2_PI 0.63661977236758134308 -#define M_2_SQRTPI 1.12837916709551257390 -#define M_SQRT2 1.41421356237309504880 -#define M_SQRT1_2 0.70710678118654752440 -#define PI M_PI -#define PI2 M_PI_2 - -extern double _FUNC(acosh)(double); -extern double _FUNC(asinh)(double); -extern double _FUNC(atanh)(double); -extern double _FUNC(cbrt)(double); -extern double _FUNC(exp10)(double _x); -extern double _FUNC(exp2)(double _x); -extern double _FUNC(expm1)(double); -extern double _FUNC(hypot)(double, double); -extern double _FUNC(log1p)(double); -extern double _FUNC(log2)(double _x); -extern long double _FUNC(modfl)(long double _x, long double *_pint); -extern double _FUNC(pow10)(double _x); -extern double _FUNC(pow2)(double _x); -extern double _FUNC(powi)(double, int); -extern void _FUNC(sincos)(double, double *, double *); - -/* These are in libm.a (Cygnus). You must link -lm to get these */ -/* See libm/math.h for comments */ - -#ifndef __cplusplus struct exception { - int type; - const char *name; - double arg1; - double arg2; - double retval; - int err; + int type; + const char* name; + double arg1; + double arg2; + double retval; + int err; }; -#endif - -extern double _FUNC(erf)(double); -extern double _FUNC(erfc)(double); -extern double _FUNC(gamma)(double); -extern int _FUNC(isinf)(double); -extern int _FUNC(isnan)(double); -extern int _FUNC(finite)(double); -extern double _FUNC(j0)(double); -extern double _FUNC(j1)(double); -extern double _FUNC(jn)(int, double); -extern double _FUNC(lgamma)(double); -extern double _FUNC(nan)(const char*); -extern double _FUNC(y0)(double); -extern double _FUNC(y1)(double); -extern double _FUNC(yn)(int, double); -extern double _FUNC(logb)(double); -extern double _FUNC(nextafter)(double, double); -extern double _FUNC(remainder)(double, double); -extern double _FUNC(scalb)(double, double); -#ifndef __cplusplus -extern int _FUNC(matherr)(struct exception *); -#endif -extern double _FUNC(significand)(double); -extern double _FUNC(copysign)(double, double); -extern int _FUNC(ilogb)(double); -extern double _FUNC(rint)(double); -extern double _FUNC(scalbn)(double, int); -extern double _FUNC(drem)(double, double); -extern double _FUNC(gamma_r)(double, int *); -extern double _FUNC(lgamma_r)(double, int *); -extern float _FUNC(acosf)(float); -extern float _FUNC(asinf)(float); -extern float _FUNC(atanf)(float); -extern float _FUNC(atan2f)(float, float); -extern float _FUNC(cosf)(float); -extern float _FUNC(sinf)(float); -extern float _FUNC(tanf)(float); -extern float _FUNC(coshf)(float); -extern float _FUNC(sinhf)(float); -extern float _FUNC(tanhf)(float); -extern float _FUNC(expf)(float); -extern float _FUNC(frexpf)(float, int *); -extern float _FUNC(ldexpf)(float, int); -extern float _FUNC(logf)(float); -extern float _FUNC(log10f)(float); -extern float _FUNC(modff)(float, float *); -extern float _FUNC(powf)(float, float); -extern float _FUNC(sqrtf)(float); -extern float _FUNC(ceilf)(float); -extern float _FUNC(fabsf)(float); -extern float _FUNC(floorf)(float); -extern float _FUNC(fmodf)(float, float); -extern float _FUNC(erff)(float); -extern float _FUNC(erfcf)(float); -extern float _FUNC(gammaf)(float); -extern float _FUNC(hypotf)(float, float); -extern int _FUNC(isinff)(float); -extern int _FUNC(isnanf)(float); -extern int _FUNC(finitef)(float); -extern float _FUNC(j0f)(float); -extern float _FUNC(j1f)(float); -extern float _FUNC(jnf)(int, float); -extern float _FUNC(lgammaf)(float); -extern float _FUNC(nanf)(const char*); -extern float _FUNC(y0f)(float); -extern float _FUNC(y1f)(float); -extern float _FUNC(ynf)(int, float); -extern float _FUNC(acoshf)(float); -extern float _FUNC(asinhf)(float); -extern float _FUNC(atanhf)(float); -extern float _FUNC(cbrtf)(float); -extern float _FUNC(logbf)(float); -extern float _FUNC(nextafterf)(float, float); -extern float _FUNC(remainderf)(float, float); -extern float _FUNC(scalbf)(float, float); -extern float _FUNC(significandf)(float); -extern float _FUNC(copysignf)(float, float); -extern int _FUNC(ilogbf)(float); -extern float _FUNC(rintf)(float); -extern float _FUNC(scalbnf)(float, int); -extern float _FUNC(dremf)(float, float); -extern float _FUNC(expm1f)(float); -extern float _FUNC(log1pf)(float); -extern float _FUNC(gammaf_r)(float, int *); -extern float _FUNC(lgammaf_r)(float, int *); - -#ifdef __cplusplus -} -#endif #endif /* _MATH_H_ */ \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/include/setjmp.h b/programs/develop/ktcc/trunk/libc.obj/include/setjmp.h index aa1993680e..ed194407aa 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/setjmp.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/setjmp.h @@ -6,9 +6,9 @@ typedef unsigned long __jmp_buf[6]; typedef struct __jmp_buf_tag { - __jmp_buf __jb; - unsigned long __fl; - unsigned long __ss[128/sizeof(long)]; + __jmp_buf __jb; + unsigned long __fl; + unsigned long __ss[128 / sizeof(long)]; } jmp_buf[1]; extern int _FUNC(setjmp)(jmp_buf env); diff --git a/programs/develop/ktcc/trunk/libc.obj/include/shell_api.h b/programs/develop/ktcc/trunk/libc.obj/include/shell_api.h index 3a68b2d4b6..bd7c144e6f 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/shell_api.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/shell_api.h @@ -3,35 +3,37 @@ #include -#define SHELL_OK 0 -#define SHELL_EXIT 1 -#define SHELL_PUTC 2 -#define SHELL_PUTS 3 -#define SHELL_GETC 4 -#define SHELL_GETS 5 -#define SHELL_CLS 6 -#define SHELL_PID 7 -#define SHELL_PING 8 +#define SHELL_OK 0 +#define SHELL_EXIT 1 +#define SHELL_PUTC 2 +#define SHELL_PUTS 3 +#define SHELL_GETC 4 +#define SHELL_GETS 5 +#define SHELL_CLS 6 +#define SHELL_PID 7 +#define SHELL_PING 8 -#define SHELL_SHM_MAX 1024*16 +#define SHELL_SHM_MAX 1024 * 16 -extern char __shell_shm_name[32]; -extern char *__shell_shm; +extern char __shell_shm_name[32]; +extern char* __shell_shm; extern int __shell_is_init; extern void __shell_init(); -#define __SHELL_WAIT() while (*__shell_shm) _ksys_delay(5) +#define __SHELL_WAIT() \ + while (*__shell_shm) \ + _ksys_delay(5) -extern int shell_ping(); +extern int shell_ping(); extern unsigned shell_get_pid(); extern void shell_exit(); extern char shell_getc(); -extern void shell_gets(char *str, int n); +extern void shell_gets(char* str, int n); extern void shell_putc(char c); -extern void shell_puts(const char *str); -extern void shell_printf(const char *format,...); +extern void shell_puts(const char* str); +extern void shell_printf(const char* format, ...); extern void shell_cls(); #endif diff --git a/programs/develop/ktcc/trunk/libc.obj/include/stdarg.h b/programs/develop/ktcc/trunk/libc.obj/include/stdarg.h index bd0928d891..5f4537b881 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/stdarg.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/stdarg.h @@ -3,75 +3,14 @@ #include -#ifdef __x86_64__ -#ifndef _WIN64 - -//This should be in sync with the declaration on our lib/libtcc1.c -/* GCC compatible definition of va_list. */ -typedef struct { - unsigned int gp_offset; - unsigned int fp_offset; - union { - unsigned int overflow_offset; - char *overflow_arg_area; - }; - char *reg_save_area; -} __va_list_struct; - -typedef __va_list_struct va_list[1]; - -extern void _FUNC(__va_start)(__va_list_struct *ap, void *fp); -extern void* _FUNC(__va_arg)(__va_list_struct *ap, int arg_type, int size, int align); - -#define va_start(ap, last) __va_start(ap, __builtin_frame_address(0)) -#define va_arg(ap, type) \ - (*(type *)(__va_arg(ap, __builtin_va_arg_types(type), sizeof(type), __alignof__(type)))) -#define va_copy(dest, src) (*(dest) = *(src)) -#define va_end(ap) - -#else /* _WIN64 */ -typedef char *va_list; -#define va_start(ap,last) __builtin_va_start(ap,last) -#define va_arg(ap,type) (ap += 8, sizeof(type)<=8 ? *(type*)ap : **(type**)ap) -#define va_copy(dest, src) ((dest) = (src)) -#define va_end(ap) -#endif - -#elif __arm__ -typedef char *va_list; -#define _tcc_alignof(type) ((int)&((struct {char c;type x;} *)0)->x) -#define _tcc_align(addr,type) (((unsigned)addr + _tcc_alignof(type) - 1) \ - & ~(_tcc_alignof(type) - 1)) -#define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3) -#define va_arg(ap,type) (ap = (void *) ((_tcc_align(ap,type)+sizeof(type)+3) \ - &~3), *(type *)(ap - ((sizeof(type)+3)&~3))) +typedef char* va_list; +#define va_start(ap, last) ap = ((char*)&(last)) + ((sizeof(last) + 3) & ~3) +#define va_arg(ap, type) (ap += (sizeof(type) + 3) & ~3, *(type*)(ap - ((sizeof(type) + 3) & ~3))) #define va_copy(dest, src) (dest) = (src) #define va_end(ap) -#elif defined(__aarch64__) -typedef struct { - void *__stack; - void *__gr_top; - void *__vr_top; - int __gr_offs; - int __vr_offs; -} va_list; -#define va_start(ap, last) __va_start(ap, last) -#define va_arg(ap, type) __va_arg(ap, type) -#define va_end(ap) -#define va_copy(dest, src) ((dest) = (src)) - -#else /* __i386__ */ -typedef char *va_list; -/* only correct for i386 */ -#define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3) -#define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3))) -#define va_copy(dest, src) (dest) = (src) -#define va_end(ap) -#endif - /* fix a buggy dependency on GCC in libio.h */ typedef va_list __gnuc_va_list; #define _VA_LIST_DEFINED -#endif /* _STDARG_H */ +#endif /* _STDARG_H */ \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/include/stdbool.h b/programs/develop/ktcc/trunk/libc.obj/include/stdbool.h index 0af22124ae..d79a4d68d7 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/stdbool.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/stdbool.h @@ -3,9 +3,9 @@ /* ISOC99 boolean */ -#define bool _Bool -#define true 1 -#define false 0 +#define bool _Bool +#define true 1 +#define false 0 #define __bool_true_false_are_defined 1 #endif /* _STDBOOL_H */ diff --git a/programs/develop/ktcc/trunk/libc.obj/include/stddef.h b/programs/develop/ktcc/trunk/libc.obj/include/stddef.h index 574528f586..5e75c3c181 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/stddef.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/stddef.h @@ -8,38 +8,24 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t; typedef __PTRDIFF_TYPE__ intptr_t; typedef __SIZE_TYPE__ uintptr_t; -#ifndef __int8_t_defined -#define __int8_t_defined -typedef signed char int8_t; -typedef signed short int int16_t; -typedef signed int int32_t; -typedef signed long long int int64_t; -typedef unsigned char uint8_t; -typedef unsigned short int uint16_t; -typedef unsigned int uint32_t; -typedef unsigned long long int uint64_t; -typedef int64_t intmax_t; -typedef uint64_t uintmax_t; -#endif - #ifndef NULL - #define NULL ((void*)0) +#define NULL ((void*)0) #endif #ifdef _BUILD_LIBC - #define _FUNC(func) func +#define _FUNC(func) func #else - #define _FUNC(func) (*func) +#define _FUNC(func) (*func) #endif -#define offsetof(type, field) ((size_t)&((type *)0)->field) +#define offsetof(type, field) ((size_t) & ((type*)0)->field) #ifndef __stdcall - #define __stdcall __attribute__((stdcall)) +#define __stdcall __attribute__((stdcall)) #endif #ifndef __cdecl - #define __cdecl __attribute__((cdecl)) +#define __cdecl __attribute__((cdecl)) #endif #endif /* _STDDEF_H_ */ \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/include/stdint.h b/programs/develop/ktcc/trunk/libc.obj/include/stdint.h index 457027bf7d..b27cb18f47 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/stdint.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/stdint.h @@ -3,32 +3,36 @@ #include -#define INT8_MIN (-128) -#define INT8_MAX (127) -#define UINT8_MAX (255) +#define INT8_MIN (-128) +#define INT8_MAX (127) +#define UINT8_MAX (255) -#define INT16_MIN (-32768) -#define INT16_MAX (32767) -#define UINT16_MAX (65535) +#define INT16_MIN (-32768) +#define INT16_MAX (32767) +#define UINT16_MAX (65535) -#define INT32_MIN (-2147483647L-1) -#define INT32_MAX (2147483647L) -#define UINT32_MAX (4294967295UL) +#define INT32_MIN (-2147483647L - 1) +#define INT32_MAX (2147483647L) +#define UINT32_MAX (4294967295UL) -#if __have_long64 -#define INT64_MIN (-9223372036854775807L-1L) -#define INT64_MAX (9223372036854775807L) -#define UINT64_MAX (18446744073709551615U) -#elif __have_longlong64 -#define INT64_MIN (-9223372036854775807LL-1LL) -#define INT64_MAX (9223372036854775807LL) -#define UINT64_MAX (18446744073709551615ULL) -#else -#define INT64_MAX 0x7fffffffffffffffLL -#define INT64_MIN (-INT64_MAX - 1LL) -#define UINT64_MAX (__CONCAT(INT64_MAX, U) * 2ULL + 1ULL) +#define INT64_MAX 0x7fffffffffffffffLL +#define INT64_MIN (-INT64_MAX - 1LL) +#define UINT64_MAX (__CONCAT(INT64_MAX, U) * 2ULL + 1ULL) + +#ifndef __int8_t_defined +#define __int8_t_defined +typedef signed char int8_t; +typedef signed short int int16_t; +typedef signed int int32_t; +typedef signed long long int int64_t; +typedef unsigned char uint8_t; +typedef unsigned short int uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long int uint64_t; +typedef int64_t intmax_t; +typedef uint64_t uintmax_t; #endif -#define SIZE_MAX UINT32_MAX +#define SIZE_MAX UINT32_MAX #endif /* _STDINT_H_*/ diff --git a/programs/develop/ktcc/trunk/libc.obj/include/stdio.h b/programs/develop/ktcc/trunk/libc.obj/include/stdio.h index d0990e408e..0946351c36 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/stdio.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/stdio.h @@ -10,10 +10,10 @@ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// +// // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -35,29 +35,29 @@ #include #include -extern int _FUNC(puts)(const char *str); -extern int _FUNC(printf)(const char* format, ...); -extern int _FUNC(sprintf)(char* buffer, const char* format, ...); -extern int _FUNC(snprintf)(char* buffer, size_t count, const char* format, ...); -extern int _FUNC(vsnprintf)(char* buffer, size_t count, const char* format, va_list va); -extern int _FUNC(vsprintf)(char* buffer, const char* format, va_list va); -extern int _FUNC(vprintf)(const char* format, va_list va); +extern int _FUNC(puts)(const char* str); +extern int _FUNC(printf)(const char* format, ...); +extern int _FUNC(sprintf)(char* buffer, const char* format, ...); +extern int _FUNC(snprintf)(char* buffer, size_t count, const char* format, ...); +extern int _FUNC(vsnprintf)(char* buffer, size_t count, const char* format, va_list va); +extern int _FUNC(vsprintf)(char* buffer, const char* format, va_list va); +extern int _FUNC(vprintf)(const char* format, va_list va); extern void _FUNC(debug_printf)(const char* format, ...); typedef size_t fpos_t; -#define _FILEMODE_R 1 << 0 // Read -#define _FILEMODE_W 1 << 1 // Write -#define _FILEMODE_A 1 << 2 // Append -#define _FILEMODE_PLUS 1 << 3 // Plus +#define _FILEMODE_R 1 << 0 // Read +#define _FILEMODE_W 1 << 1 // Write +#define _FILEMODE_A 1 << 2 // Append +#define _FILEMODE_PLUS 1 << 3 // Plus typedef struct FILE_s { - char *name; + char* name; fpos_t position; int error; int eof; - int mode; // flags _FILEMODE_* + int mode; // flags _FILEMODE_* int __ungetc_emu_buff; // Uses __ungetc_emu (temporary solution!) } FILE; @@ -82,58 +82,58 @@ typedef struct FILE_s { #define TMP_MAX FOPEN_MAX #define stderr (FILE*)3 -#define stdin (FILE*)1 +#define stdin (FILE*)1 #define stdout (FILE*)2 -extern int _FUNC(fgetc)(FILE *); -extern char* _FUNC(fgets)(char *restrict, int, FILE *restrict); -extern int _FUNC(fprintf)(FILE *restrict, const char *restrict, ...); -extern int _FUNC(fputc)(int, FILE *); -extern int _FUNC(fputs)(const char *restrict, FILE *restrict); -extern size_t _FUNC(fread)(void *restrict, size_t size, size_t count, FILE *restrict); -extern int _FUNC(fscanf)(FILE *restrict, const char *restrict, ...); -extern size_t _FUNC(fwrite)(const void *restrict, size_t size, size_t count, FILE *restrict); -extern int _FUNC(getc)(FILE *); -#define getc() _FUNC(fgetc)(stdin) -extern int _FUNC(getchar)(void); -extern int _FUNC(printf)(const char *restrict, ...); -#define putc(ch) _FUNC(fputc)(ch, stdout) -extern int _FUNC(puts)(const char *); -extern int _FUNC(scanf)(const char *restrict, ...); -extern char* _FUNC(gets)(char *str); -extern int _FUNC(ungetc)(int, FILE *); -extern int _FUNC(vfprintf)(FILE *restrict, const char *restrict, va_list); -extern int _FUNC(vfscanf)(FILE *restrict, const char *restrict, va_list); -extern int _FUNC(vprintf)(const char *restrict, va_list); -extern int _FUNC(vscanf)(const char *restrict, va_list); -extern int _FUNC(sscanf)(const char*, const char *restrict, ...); -extern int _FUNC(vsscanf)(const char *, const char*, va_list); +extern int _FUNC(fgetc)(FILE*); +extern char* _FUNC(fgets)(char* restrict, int, FILE* restrict); +extern int _FUNC(fprintf)(FILE* restrict, const char* restrict, ...); +extern int _FUNC(fputc)(int, FILE*); +extern int _FUNC(fputs)(const char* restrict, FILE* restrict); +extern size_t _FUNC(fread)(void* restrict, size_t size, size_t count, FILE* restrict); +extern int _FUNC(fscanf)(FILE* restrict, const char* restrict, ...); +extern size_t _FUNC(fwrite)(const void* restrict, size_t size, size_t count, FILE* restrict); +extern int _FUNC(getc)(FILE*); +#define getc() _FUNC(fgetc)(stdin) +extern int _FUNC(getchar)(void); +extern int _FUNC(printf)(const char* restrict, ...); +#define putc(ch) _FUNC(fputc)(ch, stdout) +extern int _FUNC(puts)(const char*); +extern int _FUNC(scanf)(const char* restrict, ...); +extern char* _FUNC(gets)(char* str); +extern int _FUNC(ungetc)(int, FILE*); +extern int _FUNC(vfprintf)(FILE* restrict, const char* restrict, va_list); +extern int _FUNC(vfscanf)(FILE* restrict, const char* restrict, va_list); +extern int _FUNC(vprintf)(const char* restrict, va_list); +extern int _FUNC(vscanf)(const char* restrict, va_list); +extern int _FUNC(sscanf)(const char*, const char* restrict, ...); +extern int _FUNC(vsscanf)(const char*, const char*, va_list); -extern int _FUNC(remove)(const char *); -extern int _FUNC(rename)(const char *, const char *); -extern FILE* _FUNC(tmpfile)(void); -extern char* _FUNC(tmpnam)(char *); +extern int _FUNC(remove)(const char*); +extern int _FUNC(rename)(const char*, const char*); +extern FILE* _FUNC(tmpfile)(void); +extern char* _FUNC(tmpnam)(char*); -extern int _FUNC(fclose)(FILE *); -extern int _FUNC(fflush)(FILE *); -extern FILE* _FUNC(fopen)(const char *restrict, const char *restrict); -extern FILE* _FUNC(freopen)(const char *restrict, const char *restrict, FILE *restrict); -extern void _FUNC(setbuf)(FILE *restrict, char *restrict); -extern int _FUNC(setvbuf)(FILE *restrict, char *restrict, int, size_t); +extern int _FUNC(fclose)(FILE*); +extern int _FUNC(fflush)(FILE*); +extern FILE* _FUNC(fopen)(const char* restrict, const char* restrict); +extern FILE* _FUNC(freopen)(const char* restrict, const char* restrict, FILE* restrict); +extern void _FUNC(setbuf)(FILE* restrict, char* restrict); +extern int _FUNC(setvbuf)(FILE* restrict, char* restrict, int, size_t); -extern int _FUNC(fgetpos)(FILE *restrict, fpos_t *restrict); -extern int _FUNC(fseek)(FILE *, long, int); -extern int _FUNC(fsetpos)(FILE *, const fpos_t *); -extern long _FUNC(ftell)(FILE *); -extern void _FUNC(rewind)(FILE *); +extern int _FUNC(fgetpos)(FILE* restrict, fpos_t* restrict); +extern int _FUNC(fseek)(FILE*, long, int); +extern int _FUNC(fsetpos)(FILE*, const fpos_t*); +extern long _FUNC(ftell)(FILE*); +extern void _FUNC(rewind)(FILE*); -extern void _FUNC(clearerr)(FILE *); -extern int _FUNC(feof)(FILE *); -extern int _FUNC(ferror)(FILE *); -extern void _FUNC(perror)(const char *); +extern void _FUNC(clearerr)(FILE*); +extern int _FUNC(feof)(FILE*); +extern int _FUNC(ferror)(FILE*); +extern void _FUNC(perror)(const char*); -extern size_t _FUNC(fread)(void *restrict, size_t, size_t, FILE *restrict); +extern size_t _FUNC(fread)(void* restrict, size_t, size_t, FILE* restrict); -extern int _FUNC(getchar)(void); +extern int _FUNC(getchar)(void); -#endif // _STDIO_H_ +#endif // _STDIO_H_ diff --git a/programs/develop/ktcc/trunk/libc.obj/include/stdlib.h b/programs/develop/ktcc/trunk/libc.obj/include/stdlib.h index e39f5a9910..d124da013e 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/stdlib.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/stdlib.h @@ -3,69 +3,69 @@ #include -#define RAND_MAX 65535 +#define RAND_MAX 65535 #ifndef NULL -# define NULL ((void*)0) +#define NULL ((void*)0) #endif - -#define min(a, b) ((a)<(b) ? (a) : (b)) -#define max(a, b) ((a)>(b) ? (a) : (b)) -extern int _FUNC(atoi)(const char *s); -extern long _FUNC(atol)(const char *); -extern long long _FUNC(atoll)(const char *); +#define min(a, b) ((a) < (b) ? (a) : (b)) +#define max(a, b) ((a) > (b) ? (a) : (b)) + +typedef struct { + int quot; + int rem; +} div_t; + +typedef struct { + long quot; + long rem; +} ldiv_t; + +typedef struct { + long long quot; + long long rem; +} lldiv_t; + +static inline div_t div(int num, int den) +{ + return (div_t) { num / den, num % den }; +} + +static inline ldiv_t ldiv(long num, long den) +{ + return (ldiv_t) { num / den, num % den }; +} + +static inline lldiv_t lldiv(long long num, long long den) +{ + return (lldiv_t) { num / den, num % den }; +} + +extern void* _FUNC(malloc)(size_t size); +extern void* _FUNC(calloc)(size_t num, size_t size); +extern void* _FUNC(realloc)(void* ptr, size_t newsize); +extern void _FUNC(free)(void* ptr); + +extern long int _FUNC(strtol)(const char* str, char** endptr, int base); + +extern void _FUNC(exit)(int status); + +extern void _FUNC(srand)(unsigned s); +extern int _FUNC(rand)(void); + +extern void _FUNC(__assert_fail)(const char* expr, const char* file, int line, const char* func); +extern void _FUNC(qsort)(void* base0, size_t n, size_t size, int (*compar)(const void*, const void*)); + +extern double _FUNC(strtod)(const char* s, char** sret); +extern double _FUNC(atof)(const char* ascii); + +extern int _FUNC(atoi)(const char* s); +extern long _FUNC(atol)(const char*); +extern long long _FUNC(atoll)(const char*); extern void _FUNC(itoa)(int n, char* s); extern int _FUNC(abs)(int); extern long _FUNC(labs)(long); extern long long _FUNC(llabs)(long long); -typedef struct { - int quot; - int rem; -} div_t; - -typedef struct { - long quot; - long rem; -} ldiv_t; - -typedef struct { - long long quot; - long long rem; -} lldiv_t; - -static inline -div_t div(int num, int den) { - return (div_t){ num/den, num%den }; -} - -static inline -ldiv_t ldiv(long num, long den) { - return (ldiv_t){ num/den, num%den }; -} - -static inline -lldiv_t lldiv(long long num, long long den) { - return (lldiv_t){ num/den, num%den }; -} - -extern void* _FUNC(malloc)(size_t size); -extern void* _FUNC(calloc)(size_t num, size_t size); -extern void* _FUNC(realloc)(void *ptr, size_t newsize); -extern void _FUNC(free)(void *ptr); - -extern long int _FUNC(strtol)(const char* str, char** endptr, int base); - -extern void _FUNC(exit)(int status); - -extern void _FUNC(srand)(unsigned s); -extern int _FUNC(rand)(void); - -extern void _FUNC(__assert_fail)(const char *expr, const char *file, int line, const char *func); -extern void _FUNC(qsort)(void *base0, size_t n, size_t size, int (*compar)(const void *, const void *)); - -extern double _FUNC(strtod)(const char *s, char **sret); -extern double _FUNC(atof)(const char *ascii); - #endif diff --git a/programs/develop/ktcc/trunk/libc.obj/include/string.h b/programs/develop/ktcc/trunk/libc.obj/include/string.h index 003110f1af..cda6085e42 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/string.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/string.h @@ -1,34 +1,9 @@ -/* String handling - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - #ifndef _STRING_H_ #define _STRING_H_ #include -#ifdef __cplusplus -extern "C" { -#endif - -/* String function conventions */ - -/* - In any of the following functions taking a size_t n to specify the length of - an array or size of a memory region, n may be 0, but the pointer arguments to - the call shall still be valid unless otherwise stated. -*/ - -/* Copying functions */ - -extern void* _FUNC(memccpy)(void *restrict dest, const void *restrict src, int c, size_t n); - -/* Copy a number of n characters from the memory area pointed to by s2 to the - area pointed to by s1. If the two areas overlap, behaviour is undefined. - Returns the value of s1. -*/ +extern void* _FUNC(memccpy)(void* restrict dest, const void* restrict src, int c, size_t n); #ifdef __TINYC__ extern void* memcpy(void* s1, const void* s2, size_t n); @@ -40,142 +15,26 @@ extern void* _FUNC(memset)(void* s, int c, size_t n); extern void* _FUNC(memmove)(void* s1, const void* s2, size_t n); #endif -/* Copy the character array s2 (including terminating '\0' byte) into the - character array s1. - Returns the value of s1. -*/ -extern char* _FUNC(strcpy)(char* s1, const char* s2); - -/* Copy a maximum of n characters from the character array s2 into the character - array s1. If s2 is shorter than n characters, '\0' bytes will be appended to - the copy in s1 until n characters have been written. If s2 is longer than n - characters, NO terminating '\0' will be written to s1. If the arrays overlap, - behaviour is undefined. - Returns the value of s1. -*/ +extern char* _FUNC(strcpy)(char* s1, const char* s2); extern char* _FUNC(strncpy)(char* s1, const char* s2, size_t n); - -/* Concatenation functions */ - -/* Append the contents of the character array s2 (including terminating '\0') to - the character array s1 (first character of s2 overwriting the '\0' of s1). If - the arrays overlap, behaviour is undefined. - Returns the value of s1. -*/ extern char* _FUNC(strcat)(char* s1, const char* s2); - -/* Append a maximum of n characters from the character array s2 to the character - array s1 (first character of s2 overwriting the '\0' of s1). A terminating - '\0' is ALWAYS appended, even if the full n characters have already been - written. If the arrays overlap, behaviour is undefined. - Returns the value of s1. -*/ extern char* _FUNC(strncat)(char* s1, const char* s2, size_t n); - -/* Comparison functions */ - -/* Compare the first n characters of the memory areas pointed to by s1 and s2. - Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if - s1 > s2. -*/ -extern int _FUNC(memcmp)(const void * s1, const void* s2, size_t n); - -/* Compare the character arrays s1 and s2. - Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if - s1 > s2. -*/ -extern int _FUNC(strcmp)(const char * s1, const char* s2); - -/* Compare the character arrays s1 and s2, interpreted as specified by the - LC_COLLATE category of the current locale. - Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if - s1 > s2. - TODO: Currently a dummy wrapper for strcmp() as PDCLib does not yet support - locales. -*/ +extern int _FUNC(memcmp)(const void* s1, const void* s2, size_t n); +extern int _FUNC(strcmp)(const char* s1, const char* s2); extern int _FUNC(strcoll)(const char* s1, const char* s2); - -/* Compare no more than the first n characters of the character arrays s1 and - s2. - Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if - s1 > s2. -*/ extern int _FUNC(strncmp)(const char* s1, const char* s2, size_t n); - -/* Transform the character array s2 as appropriate for the LC_COLLATE setting of - the current locale. If length of resulting string is less than n, store it in - the character array pointed to by s1. Return the length of the resulting - string. -*/ extern size_t _FUNC(strxfrm)(char* s1, const char* s2, size_t n); - -/* Search functions */ - -/* Search the first n characters in the memory area pointed to by s for the - character c (interpreted as unsigned char). - Returns a pointer to the first instance found, or NULL. -*/ extern void* _FUNC(memchr)(const void* s, int c, size_t n); - -/* Search the character array s (including terminating '\0') for the character c - (interpreted as char). - Returns a pointer to the first instance found, or NULL. -*/ extern char* _FUNC(strchr)(const char* s, int c); - -/* Determine the length of the initial substring of character array s1 which - consists only of characters not from the character array s2. - Returns the length of that substring. -*/ extern size_t _FUNC(strcspn)(const char* s1, const char* s2); - -/* Search the character array s1 for any character from the character array s2. - Returns a pointer to the first occurrence, or NULL. -*/ extern char* _FUNC(strpbrk)(const char* s1, const char* s2); - -/* Search the character array s (including terminating '\0') for the character c - (interpreted as char). - Returns a pointer to the last instance found, or NULL. -*/ -extern char* _FUNC(strrchr)(const char * s, int c ); - -/* Determine the length of the initial substring of character array s1 which - consists only of characters from the character array s2. - Returns the length of that substring. -*/ -extern size_t _FUNC(strspn)(const char * s1, const char * s2); - -/* Search the character array s1 for the substring in character array s2. - Returns a pointer to that sbstring, or NULL. If s2 is of length zero, - returns s1. -*/ -extern char* _FUNC(strstr)(const char * s1, const char * s2); - -/* In a series of subsequent calls, parse a C string into tokens. - On the first call to strtok(), the first argument is a pointer to the to-be- - parsed C string. On subsequent calls, the first argument is NULL unless you - want to start parsing a new string. s2 holds an array of separator characters - which can differ from call to call. Leading separators are skipped, the first - trailing separator overwritten with '\0'. - Returns a pointer to the next token. - WARNING: This function uses static storage, and as such is not reentrant. -*/ +extern char* _FUNC(strrchr)(const char* s, int c); +extern size_t _FUNC(strspn)(const char* s1, const char* s2); +extern char* _FUNC(strstr)(const char* s1, const char* s2); extern char* _FUNC(strtok)(char* s1, const char* s2); - -/* Map an error number to a (locale-specific) error message string. Error - numbers are typically errno values, but any number is mapped to a message. - TODO: PDCLib does not yet support locales. -*/ -extern char* _FUNC(strerror)(int errnum); - -/* Returns the length of the string s (excluding terminating '\0').*/ -extern size_t _FUNC(strlen)(const char * s); - -/* The function reverses the sequence of characters in the string pointed to by str. */ -extern char* _FUNC(strrev)(char *str); - -/* The strdup function executes the function pointed to by the str argument. */ -extern char* _FUNC(strdup)(const char *str); +extern char* _FUNC(strerror)(int errnum); +extern size_t _FUNC(strlen)(const char* s); +extern char* _FUNC(strrev)(char* str); +extern char* _FUNC(strdup)(const char* str); #endif diff --git a/programs/develop/ktcc/trunk/libc.obj/include/sys/dir.h b/programs/develop/ktcc/trunk/libc.obj/include/sys/dir.h index 683f1f0bb2..97d2b03f87 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/sys/dir.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/sys/dir.h @@ -3,9 +3,9 @@ #include -extern char* _FUNC(getcwd)(char *buf, unsigned size); -extern void _FUNC(setcwd)(const char* cwd); -extern int _FUNC(rmdir)(const char* dir); -extern int _FUNC(mkdir)(const char* dir); +extern char* _FUNC(getcwd)(char* buf, unsigned size); +extern void _FUNC(setcwd)(const char* cwd); +extern int _FUNC(rmdir)(const char* dir); +extern int _FUNC(mkdir)(const char* dir); #endif \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/include/sys/dirent.h b/programs/develop/ktcc/trunk/libc.obj/include/sys/dirent.h index fddabd1efd..cecd558fe0 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/sys/dirent.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/sys/dirent.h @@ -3,32 +3,31 @@ #ifndef _DIRENT_H_ #define _DIRENT_H_ -#include #include +#include #define IS_FOLDER 16 -#define IS_FILE 0 +#define IS_FILE 0 typedef unsigned ino_t; -struct dirent{ - ino_t d_ino; //File serial number. - char d_name[PATH_MAX]; // Name of entry. - unsigned d_type; +struct dirent { + ino_t d_ino; //File serial number. + char d_name[PATH_MAX]; // Name of entry. + unsigned d_type; }; -typedef struct{ - struct dirent* objs; +typedef struct { + struct dirent* objs; ino_t pos; - ino_t num_objs; -}DIR; + ino_t num_objs; +} DIR; - -extern int _FUNC(closedir)(DIR *dir); -extern DIR* _FUNC(opendir)(const char *path); -extern struct dirent* _FUNC(readdir)(DIR *); -extern void _FUNC(rewinddir)(DIR *dir); -extern void _FUNC(seekdir)(DIR *dir, unsigned pos); -extern unsigned _FUNC(telldir)(DIR *dir); +extern int _FUNC(closedir)(DIR* dir); +extern DIR* _FUNC(opendir)(const char* path); +extern struct dirent* _FUNC(readdir)(DIR*); +extern void _FUNC(rewinddir)(DIR* dir); +extern void _FUNC(seekdir)(DIR* dir, unsigned pos); +extern unsigned _FUNC(telldir)(DIR* dir); #endif // _DIRENT_H_ diff --git a/programs/develop/ktcc/trunk/libc.obj/include/sys/ksys.h b/programs/develop/ktcc/trunk/libc.obj/include/sys/ksys.h index 1d5cbbc682..c378541cfe 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/sys/ksys.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/sys/ksys.h @@ -5,97 +5,103 @@ /* See sysfuncs.txt file for details. */ /* - * This file was created with you in mind. Lest you reinvent the wheel. - * If for some reason there is not enough wrapper add! I ask you to stick to the same style: snake_case. - * Structure names must start with "ksys_" and end with "_t". - * All wrappers must start with the "_ksys_" prefix. - * I consider it mandatory to place the wrappers in the correct order in the official documentation. + * This file was created with you in mind. Lest you reinvent the wheel. + * If for some reason there is not enough wrapper add! I ask you to stick to the same style: snake_case. + * Structure names must start with "ksys_" and end with "_t". + * All wrappers must start with the "_ksys_" prefix. + * I consider it mandatory to place the wrappers in the correct order in the official documentation. * Enjoy writing your code :) - * Warning! The end of the file is the old definitions of function/structure names. - * They are for compatibility... Better not to use them. + * Warning! The end of the file is the old definitions of function/structure names. + * They are for compatibility... Better not to use them. */ - + #ifndef _KSYS_H_ #define _KSYS_H_ #include +#include +#define KOSAPI static inline #define asm_inline __asm__ __volatile__ /*============== General structures ==============*/ -#pragma pack(push,1) +#pragma pack(push, 1) typedef struct { uint8_t blue; uint8_t green; uint8_t red; -}rgb_t; +} rgb_t; typedef union { uint32_t val; - struct{ + struct { uint8_t hour; uint8_t min; uint8_t sec; uint8_t _zero; }; -}ksys_time_t; +} ksys_time_t; typedef union { uint32_t val; - struct{ - uint8_t year; - uint8_t month; - uint8_t day; - uint8_t _zero; + struct { + uint8_t year; + uint8_t month; + uint8_t day; + uint8_t _zero; }; -}ksys_date_t; +} ksys_date_t; -typedef union{ +typedef union { uint32_t val; - struct{ - uint16_t x; - uint16_t y; + struct { + uint16_t x; + uint16_t y; }; -}ksys_pos_t; +} ksys_pos_t; -typedef union ksys_oskey_t{ +typedef union ksys_oskey_t { uint32_t val; - struct{ + struct { uint8_t state; uint8_t code; uint8_t ctrl_key; }; -}ksys_oskey_t; +} ksys_oskey_t; -typedef struct{ - void *data; +typedef struct { + void* data; size_t size; -}ksys_ufile_t; +} ksys_ufile_t; - -typedef struct{ - uint32_t p00; - union{ - uint64_t p04; +typedef struct { + uint32_t p00; + union { + uint64_t p04; struct { - uint32_t p04dw; - uint32_t p08dw; + uint32_t p04dw; + uint32_t p08dw; }; }; - uint32_t p12; + uint32_t p12; union { - uint32_t p16; - const char *new_name; - void *bdfe; - void *buf16; - const void *cbuf16; + uint32_t p16; + const char* new_name; + void* bdfe; + void* buf16; + const void* cbuf16; }; - char p20; - const char *p21; -}ksys70_t; + char p20; + const char* p21; +} ksys70_t; + +typedef struct { + uint32_t status; + uint32_t rw_bytes; +} ksys70_status_t; typedef struct { uint32_t attributes; @@ -106,38 +112,38 @@ typedef struct { ksys_date_t last_access_date; ksys_time_t last_modification_time; ksys_date_t last_modification_date; - unsigned long long size; + uint64_t size; char name[0]; -}ksys_bdfe_t; +} ksys_bdfe_t; typedef struct { - int cpu_usage; //+0 - int window_pos_info; //+4 - short int reserved1; //+8 - char name[12]; //+10 - int memstart; //+22 - int memused; //+26 - int pid; //+30 - int winx_start; //+34 - int winy_start; //+38 - int winx_size; //+42 - int winy_size; //+46 - short int slot_info; //+50 - short int reserved2; //+52 - int clientx; //+54 - int clienty; //+58 - int clientwidth; //+62 - int clientheight; //+66 - unsigned char window_state;//+70 - char reserved3[1024-71]; //+71 -}ksys_thread_t; + int cpu_usage; //+0 + int window_pos_info; //+4 + uint16_t reserved1; //+8 + char name[12]; //+10 + int memstart; //+22 + int memused; //+26 + int pid; //+30 + int winx_start; //+34 + int winy_start; //+38 + int winx_size; //+42 + int winy_size; //+46 + uint16_t slot_info; //+50 + uint16_t reserved2; //+52 + int clientx; //+54 + int clienty; //+58 + int clientwidth; //+62 + int clientheight; //+66 + uint8_t window_state; //+70 + uint8_t reserved3[1024 - 71]; //+71 +} ksys_thread_t; typedef unsigned int ksys_color_t; -typedef struct{ +typedef struct { ksys_color_t frame_area; ksys_color_t grab_bar; - ksys_color_t grab_bar_button; + ksys_color_t grab_bar_button; ksys_color_t grab_button_text; ksys_color_t grab_text; ksys_color_t work_area; @@ -145,58 +151,58 @@ typedef struct{ ksys_color_t work_button_text; ksys_color_t work_text; ksys_color_t work_graph; -}ksys_colors_table_t; +} ksys_colors_table_t; -typedef struct{ - unsigned pid; // PID of sending thread - unsigned datalen; // data bytes - char *data; // data begin -}ksys_ipc_msg; - -typedef struct{ - unsigned lock; // nonzero is locked - unsigned used; // used bytes in buffer - ksys_ipc_msg *data; // data begin -}ksys_ipc_buffer; +typedef struct { + unsigned pid; // PID of sending thread + unsigned datalen; // data bytes + char* data; // data begin +} ksys_ipc_msg; + +typedef struct { + unsigned lock; // nonzero is locked + unsigned used; // used bytes in buffer + ksys_ipc_msg* data; // data begin +} ksys_ipc_buffer; typedef struct { char* func_name; void* func_ptr; -}ksys_dll_t; +} ksys_dll_t; typedef unsigned ksys_drv_hand_t; -typedef struct{ +typedef struct { ksys_drv_hand_t handler; unsigned func_num; void* in_data_ptr; unsigned in_data_size; void* out_data_ptr; unsigned out_data_size; -}ksys_ioctl_t; +} ksys_ioctl_t; -typedef struct{ - char key[64]; +typedef struct { + char key[64]; char path[64]; -}ksys_dir_key_t; +} ksys_dir_key_t; #pragma pack(pop) typedef rgb_t ksys_bitmap_t; enum KSYS_FS_ERRORS { - KSYS_FS_ERR_SUCCESS = 0, // Success - KSYS_FS_ERR_1 = 1, // Base and/or partition of a hard disk is not defined (fn21.7 & fn21.8) - KSYS_FS_ERR_2 = 2, // Function is not supported for the given file system - KSYS_FS_ERR_3 = 3, // Unknown file system - KSYS_FS_ERR_4 = 4, // Reserved, is never returned in the current implementation - KSYS_FS_ERR_5 = 5, // File not found - KSYS_FS_ERR_EOF = 6, // End of file, EOF - KSYS_FS_ERR_7 = 7, // Pointer lies outside of application memory - KSYS_FS_ERR_8 = 8, // Disk is full - KSYS_FS_ERR_9 = 9, // FAT table is destroyed - KSYS_FS_ERR_10 = 10, // Access denied - KSYS_FS_ERR_11 = 11 // Device error + KSYS_FS_ERR_SUCCESS = 0, // Success + KSYS_FS_ERR_1 = 1, // Base and/or partition of a hard disk is not defined (fn21.7 & fn21.8) + KSYS_FS_ERR_2 = 2, // Function is not supported for the given file system + KSYS_FS_ERR_3 = 3, // Unknown file system + KSYS_FS_ERR_4 = 4, // Reserved, is never returned in the current implementation + KSYS_FS_ERR_5 = 5, // File not found + KSYS_FS_ERR_EOF = 6, // End of file, EOF + KSYS_FS_ERR_7 = 7, // Pointer lies outside of application memory + KSYS_FS_ERR_8 = 8, // Disk is full + KSYS_FS_ERR_9 = 9, // FAT table is destroyed + KSYS_FS_ERR_10 = 10, // Access denied + KSYS_FS_ERR_11 = 11 // Device error }; enum KSYS_EVENTS { @@ -212,865 +218,771 @@ enum KSYS_EVENTS { KSYS_EVENT_IRQBEGIN = 16 /* 16..31 IRQ0..IRQ15 interrupt =IRQBEGIN+IRQn */ }; -enum KSYS_FILE_ENCODING{ - KSYS_FILE_CP866 =1, +enum KSYS_FILE_ENCODING { + KSYS_FILE_CP866 = 1, KSYS_FILE_UTF16LE = 2, KSYS_FILE_UTF8 = 3 }; -static inline -int __strcmp(const char * s1, const char * s2 ) +KOSAPI int __strcmp(const char* s1, const char* s2) { - while ((*s1) && (*s1 == *s2)){ ++s1; ++s2; } - return(*(unsigned char*)s1 - *(unsigned char *)s2); + while ((*s1) && (*s1 == *s2)) { + ++s1; + ++s2; + } + return (*(unsigned char*)s1 - *(unsigned char*)s2); } /* ####################################################################### */ /* ############### С wrappers for system calls Kolibri OS ################ */ /* ####################################################################### */ - /*=============== Function -1 - terminate thread/process ===============*/ -static inline -void _ksys_exit(){ - asm_inline("int $0x40"::"a"(-1)); +KOSAPI void _ksys_exit(void) +{ + asm_inline("int $0x40" ::"a"(-1)); } /*============== Function 0 - define and draw the window. ==============*/ -static inline -void _ksys_create_window(uint32_t x, uint32_t y, uint32_t w, uint32_t h, const char *name, ksys_color_t workcolor, uint32_t style) { +KOSAPI void _ksys_create_window(uint32_t x, uint32_t y, uint32_t w, uint32_t h, const char* name, ksys_color_t workcolor, uint32_t style) +{ asm_inline( - "int $0x40" - ::"a"(0), - "b"((x << 16) | ((w-1) & 0xFFFF)), - "c"((y << 16) | ((h-1) & 0xFFFF)), + "int $0x40" ::"a"(0), + "b"((x << 16) | ((w - 1) & 0xFFFF)), + "c"((y << 16) | ((h - 1) & 0xFFFF)), "d"((style << 24) | (workcolor & 0xFFFFFF)), "D"(name), - "S"(0) - :"memory" - ); + "S"(0) + : "memory"); }; /*================ Function 1 - put pixel in the window. ===============*/ -static inline -void _ksys_draw_pixel(uint32_t x, uint32_t y, ksys_color_t color){ +KOSAPI void _ksys_draw_pixel(uint32_t x, uint32_t y, ksys_color_t color) +{ asm_inline( - "int $0x40" - ::"a"(1), "b"(x), "c"(y), "d"(color) - ); + "int $0x40" ::"a"(1), "b"(x), "c"(y), "d"(color)); } /*============ Function 2 - get the code of the pressed key. ===========*/ -static inline -ksys_oskey_t _ksys_get_key(void){ +KOSAPI ksys_oskey_t _ksys_get_key(void) +{ ksys_oskey_t val; asm_inline( "int $0x40" - :"=a"(val) - :"a"(2) - ); + : "=a"(val) + : "a"(2)); return val; } /*==================== Function 3 - get system time. ===================*/ -static inline -ksys_time_t _ksys_get_time(){ +KOSAPI ksys_time_t _ksys_get_time(void) +{ ksys_time_t c_time; asm_inline( "int $0x40" - :"=a"(c_time) - :"a"(3) - :"memory" - ); + : "=a"(c_time) + : "a"(3) + : "memory"); return c_time; } /*=================== Function 4 - draw text string. ===================*/ - -static inline -void _ksys_draw_text(const char *text, uint32_t x, uint32_t y, uint32_t len, ksys_color_t color) { - asm_inline( - "int $0x40" - ::"a"(4),"d"(text), +KOSAPI void _ksys_draw_text(const char* text, uint32_t x, uint32_t y, uint32_t len, ksys_color_t color) +{ + asm_inline( + "int $0x40" ::"a"(4), "d"(text), "b"((x << 16) | y), - "S"(len),"c"(color) - :"memory" - ); + "S"(len), "c"(color) + : "memory"); } /*========================= Function 5 - delay. ========================*/ -static inline -void _ksys_delay(uint32_t time){ +KOSAPI void _ksys_delay(uint32_t time) +{ asm_inline( - "int $0x40" - ::"a"(5), "b"(time) - :"memory" - ); + "int $0x40" ::"a"(5), "b"(time) + : "memory"); } /*=============== Function 7 - draw image in the window. ===============*/ -static inline -void _ksys_draw_bitmap(void *bitmap, int x, int y, int w, int h) +KOSAPI void _ksys_draw_bitmap(void* bitmap, int x, int y, int w, int h) { asm_inline( - "int $0x40" - ::"a"(7), "b"(bitmap), + "int $0x40" ::"a"(7), "b"(bitmap), "c"((w << 16) | h), "d"((x << 16) | y) - :"memory" - ); + : "memory"); } /*=============== Function 8 - define/delete the button. ===============*/ -static inline -void _ksys_define_button(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t id, ksys_color_t color) { - asm_inline( - "int $0x40" - ::"a"(8), - "b"((x<<16)+w), - "c"((y<<16)+h), +KOSAPI void _ksys_define_button(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t id, ksys_color_t color) +{ + asm_inline( + "int $0x40" ::"a"(8), + "b"((x << 16) + w), + "c"((y << 16) + h), "d"(id), - "S"(color) - ); + "S"(color)); }; -static inline -void _ksys_delete_button(uint32_t id){ +KOSAPI void _ksys_delete_button(uint32_t id) +{ asm_inline( - "int $0x40" - ::"a"(8),"d"(id & 0x00FFFFFF | 0x80000000) - ); -} + "int $0x40" ::"a"(8), "d"(id & 0x00FFFFFF | 0x80000000)); +} /*============ Function 9 - information on execution thread. ===========*/ -static inline -int _ksys_thread_info(ksys_thread_t* table, int slot){ +KOSAPI int _ksys_thread_info(ksys_thread_t* table, int slot) +{ int val; asm_inline( "int $0x40" - :"=a"(val) - :"a"(9), "b"(table), "c"(slot) - :"memory" - ); + : "=a"(val) + : "a"(9), "b"(table), "c"(slot) + : "memory"); return val; } /*==================== Function 10 - wait for event. ===================*/ -static inline -uint32_t _ksys_wait_event(void){ +KOSAPI uint32_t _ksys_wait_event(void) +{ uint32_t val; asm_inline( "int $0x40" - :"=a"(val) - :"a"(10) - ); + : "=a"(val) + : "a"(10)); return val; } /*=============== Function 11 - check for event, no wait. ==============*/ -static inline -uint32_t _ksys_check_event(void){ +KOSAPI uint32_t _ksys_check_event(void) +{ uint32_t val; asm_inline( "int $0x40" - :"=a"(val) - :"a"(11) - ); + : "=a"(val) + : "a"(11)); return val; } /*=============== Function 12 - begin/end window redraw. ===============*/ -static inline -void _ksys_start_draw(){ - asm_inline("int $0x40"::"a"(12),"b"(1)); +KOSAPI void _ksys_start_draw(void) +{ + asm_inline("int $0x40" ::"a"(12), "b"(1)); } -static inline -void _ksys_end_draw(){ - asm_inline("int $0x40" ::"a"(12),"b"(2)); +KOSAPI void _ksys_end_draw(void) +{ + asm_inline("int $0x40" ::"a"(12), "b"(2)); } /*============ Function 13 - draw a rectangle in the window. ===========*/ -static inline -void _ksys_draw_bar(uint32_t x, uint32_t y, uint32_t w, uint32_t h, ksys_color_t color){ +KOSAPI void _ksys_draw_bar(uint32_t x, uint32_t y, uint32_t w, uint32_t h, ksys_color_t color) +{ asm_inline( - "int $0x40" - ::"a"(13), "d"(color), + "int $0x40" ::"a"(13), "d"(color), "b"((x << 16) | w), - "c"((y << 16) | h) - ); + "c"((y << 16) | h)); } /*=================== Function 14 - get screen size. ===================*/ -static inline -ksys_pos_t _ksys_screen_size(){ - ksys_pos_t size; +KOSAPI ksys_pos_t _ksys_screen_size(void) +{ + ksys_pos_t size; ksys_pos_t size_tmp; asm_inline( "int $0x40" - :"=a"(size_tmp) - :"a"(14) - ); + : "=a"(size_tmp) + : "a"(14)); size.x = size_tmp.y; - size.y = size_tmp.x; + size.y = size_tmp.x; return size; } /*== Function 15, subfunction 1 - set a size of the background image. ==*/ -static inline -void _ksys_bg_set_size(uint32_t w, uint32_t h){ +KOSAPI void _ksys_bg_set_size(uint32_t w, uint32_t h) +{ asm_inline( - "int $0x40" - ::"a"(15), "b"(1), "c"(w), "d"(h) - ); + "int $0x40" ::"a"(15), "b"(1), "c"(w), "d"(h)); } /*=== Function 15, subfunction 2 - put pixel on the background image. ==*/ -static inline -void _ksys_bg_put_pixel(uint32_t x, uint32_t y, uint32_t w, ksys_color_t color){ +KOSAPI void _ksys_bg_put_pixel(uint32_t x, uint32_t y, uint32_t w, ksys_color_t color) +{ asm_inline( - "int $0x40" - ::"a"(15), "b"(2), "c"((x+y*w)*3), "d"(color) - ); + "int $0x40" ::"a"(15), "b"(2), "c"((x + y * w) * 3), "d"(color)); } /*=========== Function 15, subfunction 3 - redraw background. ==========*/ -static inline -void _ksys_bg_redraw(void){ +KOSAPI void _ksys_bg_redraw(void) +{ asm_inline( - "int $0x40" - ::"a"(15), "b"(3) - ); + "int $0x40" ::"a"(15), "b"(3)); } /*== Function 15, subfunction 4 - set drawing mode for the background. =*/ -enum KSYS_BG_MODES{ - KSYS_BG_MODE_PAVE=1, - KSYS_BG_MODE_STRETCH=2 +enum KSYS_BG_MODES { + KSYS_BG_MODE_PAVE = 1, + KSYS_BG_MODE_STRETCH = 2 }; -static inline -void _ksys_bg_set_mode(uint32_t mode){ +KOSAPI void _ksys_bg_set_mode(uint32_t mode) +{ asm_inline( - "int $0x40" - ::"a"(15), "b"(4), "c"(mode) - ); + "int $0x40" ::"a"(15), "b"(4), "c"(mode)); } /*===================== Function 15, subfunction 5 =====================*/ /*============ Put block of pixels on the background image. ============*/ -static inline -void _ksys_bg_put_bitmap(ksys_bitmap_t* bitmap, size_t bitmap_size, uint32_t x, uint32_t y, uint32_t w){ +KOSAPI void _ksys_bg_put_bitmap(ksys_bitmap_t* bitmap, size_t bitmap_size, uint32_t x, uint32_t y, uint32_t w) +{ asm_inline( - "int $0x40" - ::"a"(15), "b"(5), "c"(bitmap), "d"((x+y*w)*3), "S"(bitmap_size) - ); + "int $0x40" ::"a"(15), "b"(5), "c"(bitmap), "d"((x + y * w) * 3), "S"(bitmap_size)); } /*===================== Function 15, subfunction 6 =====================*/ /*======= Map background data to the address space of process. ==========*/ -static inline -ksys_bitmap_t* _ksys_bg_get_map() +KOSAPI ksys_bitmap_t* _ksys_bg_get_map(void) { - ksys_bitmap_t *bitmap; + ksys_bitmap_t* bitmap; asm_inline( "int $0x40" - :"=a"(bitmap) - :"a"(15), "b"(6) - ); + : "=a"(bitmap) + : "a"(15), "b"(6)); return bitmap; } /*===== Function 15, subfunction 7 - close mapped background data. =====*/ -static inline -int _ksys_bg_close_map(ksys_bitmap_t* bitmap) -{ +KOSAPI int _ksys_bg_close_map(ksys_bitmap_t* bitmap) +{ int status; // 1 - OK, 0 - ERROR asm_inline( "int $0x40" - :"=a"(status) - :"a"(15), "b"(7), "c"(bitmap) - ); + : "=a"(status) + : "a"(15), "b"(7), "c"(bitmap)); return status; } /*===================== Function 15, subfunction 9 =====================*/ /*============= Redraws a rectangular part of the background ===========*/ -static inline -void _ksys_bg_redraw_bar(ksys_pos_t angle1, ksys_pos_t angle2) +KOSAPI void _ksys_bg_redraw_bar(ksys_pos_t angle1, ksys_pos_t angle2) { asm_inline( - "int $0x40" - ::"a"(15), "b"(9), - "c"(angle1.x*(1<<16)+angle2.x), - "d"(angle1.y*(1<<16)+angle2.y) - ); + "int $0x40" ::"a"(15), "b"(9), + "c"(angle1.x * (1 << 16) + angle2.x), + "d"(angle1.y * (1 << 16) + angle2.y)); } /*=============== Function 16 - save ramdisk on a floppy. ==============*/ -static inline -int _ksys_save_ramdisk_fd(uint32_t floppy_id) +KOSAPI int _ksys_save_ramdisk_fd(uint32_t floppy_id) { int status; // 0 - OK, 1 - ERROR asm_inline( "int $0x40" - :"=a"(status) - :"a"(16), "b"(floppy_id) - ); - return status; + : "=a"(status) + : "a"(16), "b"(floppy_id)); + return status; } /*======= Function 17 - get the identifier of the pressed button. ======*/ -static inline -uint32_t _ksys_get_button() +KOSAPI uint32_t _ksys_get_button(void) { unsigned val; asm_inline( "int $0x40" - :"=a"(val) - :"a"(17) - ); - return val>>8; + : "=a"(val) + : "a"(17)); + return val >> 8; } /*===================== Function 18, subfunction 1 =====================*/ /*============= Make deactive the window of the given thread. ==========*/ -static inline -void _ksys_unfocus_window(int slot) +KOSAPI void _ksys_unfocus_window(int slot) { asm_inline( - "int $0x40" - ::"a"(18), "b"(1), "c"(slot) - ); + "int $0x40" ::"a"(18), "b"(1), "c"(slot)); } /*= Function 18, subfunction 2 - terminate process/thread by the slot. =*/ -static inline -void _ksys_kill_by_slot(int slot) +KOSAPI void _ksys_kill_by_slot(int slot) { asm_inline( - "int $0x40" - ::"a"(18), "b"(2), "c"(slot) - ); + "int $0x40" ::"a"(18), "b"(2), "c"(slot)); } /*===================== Function 18, subfunction 3 =====================*/ /*============= Make active the window of the given thread. ============*/ -static inline -void _ksys_focus_window(int slot){ +KOSAPI void _ksys_focus_window(int slot) +{ asm_inline( - "int $0x40" - ::"a"(18), "b"(3), "c"(slot) - ); + "int $0x40" ::"a"(18), "b"(3), "c"(slot)); } /*===================== Function 18, subfunction 4 =====================*/ /*=========== Get counter of idle time units per one second. ===========*/ -static inline -uint32_t _ksys_get_idle(void){ +KOSAPI uint32_t _ksys_get_idle(void) +{ uint32_t sec; asm_inline( "int $0x40" - :"=a"(sec) - :"a"(18), "b"(4) - ); + : "=a"(sec) + : "a"(18), "b"(4)); return sec; } /*========== Function 18, subfunction 5 - get CPU clock rate. ==========*/ /*================ modulo 2^32 clock ticks = 4GHz ======================*/ -static inline -uint32_t _ksys_get_cpu_clock(void){ +KOSAPI uint32_t _ksys_get_cpu_clock(void) +{ uint32_t clock; asm_inline( "int $0x40" - :"=a"(clock) - :"a"(18), "b"(5) - ); + : "=a"(clock) + : "a"(18), "b"(5)); return clock; } /* Function 18, subfunction 6 - save ramdisk to the file on hard drive. */ -static inline -uint32_t _ksys_save_ramdisk_hd(const char* ramdisk_path){ +KOSAPI uint32_t _ksys_save_ramdisk_hd(const char* ramdisk_path) +{ uint32_t fs_err; asm_inline( "int $0x40" - :"=a"(fs_err) - :"a"(18), "b"(6), "c"(ramdisk_path) - ); + : "=a"(fs_err) + : "a"(18), "b"(6), "c"(ramdisk_path)); return fs_err; } /* Function 18, subfunction 9 - system shutdown with the parameter. */ enum KSYS_SHD_PARAM { - KSYS_SHD_POWEROFF = 2, - KSYS_SHD_REBOOT = 3, + KSYS_SHD_POWEROFF = 2, + KSYS_SHD_REBOOT = 3, KSYS_SHD_RESTART_KRN = 4 }; -static inline -void _ksys_shutdown(uint32_t shd_param){ +KOSAPI void _ksys_shutdown(uint32_t shd_param) +{ asm_inline( - "int $0x40" - ::"a"(18), "b"(9), "c"(shd_param) - ); + "int $0x40" ::"a"(18), "b"(9), "c"(shd_param)); } /*========= Function 18, subfunction 16 - get size of free RAM. ========*/ -static inline -size_t _ksys_get_ram_size(void){ +KOSAPI size_t _ksys_get_ram_size(void) +{ size_t size; asm_inline( "int $0x40" - :"=a"(size) - :"a"(18), "b"(16) - ); + : "=a"(size) + : "a"(18), "b"(16)); return size; } /*======== Function 18, subfunction 17 - get full amount of RAM. =======*/ -static inline -size_t _ksys_get_full_ram(void){ +KOSAPI size_t _ksys_get_full_ram(void) +{ size_t size; asm_inline( "int $0x40" - :"=a"(size) - :"a"(18), "b"(17) - ); + : "=a"(size) + : "a"(18), "b"(17)); return size; } /*===================== Function 18, subfunction 18 ====================*/ /*============= Terminate process/thread by the identifier. ============*/ -static inline -void _ksys_kill_by_pid(uint32_t PID) +KOSAPI void _ksys_kill_by_pid(uint32_t PID) { asm_inline( - "int $0x40" - ::"a"(18), "b"(18), "c"(PID) - ); + "int $0x40" ::"a"(18), "b"(18), "c"(PID)); } /*===================== Function 18, subfunction 21 ====================*/ /*=====Get the slot number of the process / thread by identifier.. =====*/ -static inline -int _ksys_get_thread_slot(int PID){ +KOSAPI int _ksys_get_thread_slot(int PID) +{ int val; asm_inline( "int $0x40" - :"=a"(val) - :"a"(18), "b"(21), "c"(PID) - ); + : "=a"(val) + : "a"(18), "b"(21), "c"(PID)); return val; } /*============= Function 23 - wait for event with timeout. =============*/ -static inline -uint32_t _ksys_wait_event_timeout(uint32_t timeout){ +KOSAPI uint32_t _ksys_wait_event_timeout(uint32_t timeout) +{ unsigned val; asm_inline( "int $0x40" - :"=a"(val) - :"a"(23), "b"(timeout) - ); + : "=a"(val) + : "a"(23), "b"(timeout)); return val; } /*=== Function 26, subfunction 9 - get the value of the time counter. ==*/ -static inline -uint32_t _ksys_get_tick_count(){ +KOSAPI uint32_t _ksys_get_tick_count(void) +{ unsigned val; asm_inline( "int $0x40" - :"=a"(val) - :"a"(26),"b"(9) - ); + : "=a"(val) + : "a"(26), "b"(9)); return val; } /*===================== Function 26, subfunction 10 ====================*/ /*========== Get the value of the high precision time counter. =========*/ -static inline -uint64_t _ksys_get_ns_count(){ +KOSAPI uint64_t _ksys_get_ns_count(void) +{ uint64_t val; asm_inline( "int $0x40" - :"=A"(val) - :"a"(26), "b"(10) - ); + : "=A"(val) + : "a"(26), "b"(10)); return val; } /*=================== Function 29 - get system date. ===================*/ -static inline -ksys_date_t _ksys_get_date(){ +KOSAPI ksys_date_t _ksys_get_date(void) +{ ksys_date_t val; - asm_inline("int $0x40":"=a"(val):"a"(29)); + asm_inline("int $0x40" + : "=a"(val) + : "a"(29)); return val; } /*===========+ Function 30 - work with the current folder.==============*/ /*--------- Subfunction 1 - set current folder for the thread. ---------*/ -static inline -void _ksys_setcwd(char* dir){ +KOSAPI void _ksys_setcwd(char* dir) +{ asm_inline( - "int $0x40" - ::"a"(30), "b"(1), "c"(dir) - ); + "int $0x40" ::"a"(30), "b"(1), "c"(dir)); } - + /*--------- Subfunction 2 - get current folder for the thread. ---------*/ -static inline -int _ksys_getcwd(char* buf, int bufsize){ +KOSAPI int _ksys_getcwd(char* buf, int bufsize) +{ register int val; asm_inline( "int $0x40" - :"=a"(val):"a"(30), "b"(2), "c"(buf), "d"(bufsize) - ); + : "=a"(val) + : "a"(30), "b"(2), "c"(buf), "d"(bufsize)); return val; } /* ---- Subfunction 3 - install the add.system directory for the kernel ------*/ -static inline -int _ksys_set_kernel_dir(ksys_dir_key_t *table){ +KOSAPI int _ksys_set_kernel_dir(ksys_dir_key_t* table) +{ register int val; asm_inline( "int $0x40" - :"=a"(val) - :"a"(30), "b"(3), "c"(table) - :"memory" - ); + : "=a"(val) + : "a"(30), "b"(3), "c"(table) + : "memory"); return val; } /*=================== Function 37 - work with mouse. ===================*/ -enum KSYS_MOUSE_POS{ +enum KSYS_MOUSE_POS { KSYS_MOUSE_SCREEN_POS = 0, KSYS_MOUSE_WINDOW_POS = 1 }; -static inline -ksys_pos_t _ksys_get_mouse_pos(int origin){ +KOSAPI ksys_pos_t _ksys_get_mouse_pos(int origin) +{ ksys_pos_t pos; asm_inline( "int $0x40 \n\t" "rol $16, %%eax" - :"=a"(pos) - :"a"(37),"b"(origin) - ); + : "=a"(pos) + : "a"(37), "b"(origin)); return pos; } -static inline -uint32_t _ksys_get_mouse_buttons(void){ // subfunction 2 - states of the mouse buttons - uint32_t val; - asm_inline( - "int $0x40" - :"=a"(val) - :"a"(37),"b"(2) - ); - return val; -} - -static inline -uint32_t _ksys_get_mouse_eventstate(void){ // subfunction 3 - states and events of the mouse buttons - uint32_t val; - asm_inline( - "int $0x40" - :"=a"(val) - :"a"(37),"b"(3) - ); - return val; -} - -static inline -uint32_t _ksys_load_cursor(void *path, uint32_t flags) { // subfunction 4 - load cursor - uint32_t val; - asm_inline( - "int $0x40" - :"=a"(val) - :"a"(37), "b"(4), "c"(path), "d"(flags) - :"memory" - ); - return val; -} - -static inline -uint32_t _ksys_set_cursor(uint32_t cursor){ // subfunction 5 - set curso - uint32_t old; - asm_inline( - "int $0x40" - :"=a"(old) - :"a"(37), "b"(5), "c"(cursor) - ); - return old; -} - -static inline -int _ksys_delete_cursor(uint32_t cursor){ // subfunction 6 - delete curso - int ret; - asm_inline( - "int $0x40" - :"=a"(ret) - :"a"(37), "b"(6), "c"(cursor) - :"memory" - ); - return ret; -} - -static inline -uint32_t _ksys_get_mouse_wheels(void) // subfunction 7 - get scroll data +KOSAPI uint32_t _ksys_get_mouse_buttons(void) // subfunction 2 - states of the mouse buttons { uint32_t val; asm_inline( "int $0x40" - :"=a"(val) - :"a"(37),"b"(7) - ); + : "=a"(val) + : "a"(37), "b"(2)); + return val; +} + +KOSAPI uint32_t _ksys_get_mouse_eventstate(void) // subfunction 3 - states and events of the mouse buttons +{ + uint32_t val; + asm_inline( + "int $0x40" + : "=a"(val) + : "a"(37), "b"(3)); + return val; +} + +KOSAPI uint32_t _ksys_load_cursor(void* path, uint32_t flags) // subfunction 4 - load cursor +{ + uint32_t val; + asm_inline( + "int $0x40" + : "=a"(val) + : "a"(37), "b"(4), "c"(path), "d"(flags) + : "memory"); + return val; +} + +KOSAPI uint32_t _ksys_set_cursor(uint32_t cursor) // subfunction 5 - set cursor +{ + uint32_t old; + asm_inline( + "int $0x40" + : "=a"(old) + : "a"(37), "b"(5), "c"(cursor)); + return old; +} + +KOSAPI int _ksys_delete_cursor(uint32_t cursor) // subfunction 6 - delete cursor +{ + int ret; + asm_inline( + "int $0x40" + : "=a"(ret) + : "a"(37), "b"(6), "c"(cursor) + : "memory"); + return ret; +} + +KOSAPI uint32_t _ksys_get_mouse_wheels(void) // subfunction 7 - get scroll data +{ + uint32_t val; + asm_inline( + "int $0x40" + : "=a"(val) + : "a"(37), "b"(7)); return val; } /*=========== Function 40 - set the mask for expected events. ==========*/ -enum KSYS_EVENT_MASK{ +enum KSYS_EVENT_MASK { KSYS_EVM_REDRAW = 1, - KSYS_EVM_KEY = 2, + KSYS_EVM_KEY = 2, KSYS_EVM_BUTTON = 4, - KSYS_EVM_EXIT = 8, + KSYS_EVM_EXIT = 8, KSYS_EVM_BACKGROUND = 16, - KSYS_EVM_MOUSE = 32, - KSYS_EVM_IPC = 64, - KSYS_EVM_STACK = 128, - KSYS_EVM_DEBUG = 256, - KSYS_EVM_STACK2 = 512, - KSYS_EVM_MOUSE_FILTER = 0x80000000, + KSYS_EVM_MOUSE = 32, + KSYS_EVM_IPC = 64, + KSYS_EVM_STACK = 128, + KSYS_EVM_DEBUG = 256, + KSYS_EVM_STACK2 = 512, + KSYS_EVM_MOUSE_FILTER = 0x80000000, KSYS_EVM_CURSOR_FILTER = 0x40000000, }; -static inline -uint32_t _ksys_set_event_mask(uint32_t mask){ +KOSAPI uint32_t _ksys_set_event_mask(uint32_t mask) +{ unsigned val; asm_inline( "int $0x40" - :"=a"(val) - :"a"(40), "b"(mask) - ); + : "=a"(val) + : "a"(40), "b"(mask)); return val; } /*====================== Function 38 - draw line. ======================*/ -static inline -void _ksys_draw_line(int xs, int ys, int xe, int ye, ksys_color_t color) +KOSAPI void _ksys_draw_line(int xs, int ys, int xe, int ye, ksys_color_t color) { asm_inline( - "int $0x40" - ::"a"(38), "d"(color), + "int $0x40" ::"a"(38), "d"(color), "b"((xs << 16) | xe), - "c"((ys << 16) | ye) - ); + "c"((ys << 16) | ye)); } /*============= Function 47 - draw a number in the window. =============*/ -static inline -void _ksys_draw_number(int number, int x, int y, int len, ksys_color_t color){ +KOSAPI void _ksys_draw_number(int number, int x, int y, int len, ksys_color_t color) +{ unsigned fmt; fmt = len << 16 | 0x80000000; // no leading zeros + width asm_inline( - "int $0x40" - ::"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color) - ); + "int $0x40" ::"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color)); } -static inline -void _ksys_draw_number_bg(unsigned number, int x, int y, int len, ksys_color_t color, ksys_color_t bg){ +KOSAPI void _ksys_draw_number_bg(unsigned number, int x, int y, int len, ksys_color_t color, ksys_color_t bg) +{ unsigned fmt; fmt = len << 16 | 0x80000000; // no leading zeros + width asm_inline( - "int $0x40" - ::"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color), "D"(bg) - ); + "int $0x40" ::"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color), "D"(bg)); } /*====== Function 48, subfunction 3 - get standard window colors. ======*/ -static inline -void _ksys_get_system_colors(ksys_colors_table_t *color_table) +KOSAPI void _ksys_get_system_colors(ksys_colors_table_t* color_table) { asm_inline( - "int $0x40" - ::"a"(48),"b"(3),"c"(color_table),"d"(40) - ); + "int $0x40" ::"a"(48), "b"(3), "c"(color_table), "d"(40)); } /*============ Function 48, subfunction 4 - get skin height. ===========*/ -static inline -uint32_t _ksys_get_skin_height(){ +KOSAPI uint32_t _ksys_get_skin_height() +{ unsigned height; asm_inline( "int $0x40" - :"=a"(height) - :"a"(48),"b"(4) - ); + : "=a"(height) + : "a"(48), "b"(4)); return height; } /*==================== Function 51 - create thread. ====================*/ -static inline -int _ksys_create_thread(void* thread_entry, void* stack_top){ +KOSAPI int _ksys_create_thread(void* thread_entry, void* stack_top) +{ int val; asm_inline( "int $0x40" - :"=a"(val) - :"a"(51), "b"(1), "c"(thread_entry), "d"(stack_top) - :"memory" - ); + : "=a"(val) + : "a"(51), "b"(1), "c"(thread_entry), "d"(stack_top) + : "memory"); return val; } - /*==================== Function 54, subfunction 0 ======================*/ /*============== Get the number of slots in the clipboard. =============*/ -enum KSYS_CLIP_ENCODING{ +enum KSYS_CLIP_ENCODING { KSYS_CLIP_UTF8 = 0, KSYS_CLIP_CP866 = 1, KSYS_CLIP_CP1251 = 2 }; -enum KSYS_CLIP_TYPES{ +enum KSYS_CLIP_TYPES { KSYS_CLIP_TEXT = 0, KSYS_CLIP_IMAGE = 1, KSYS_CLIP_RAW = 2 }; -static inline -int _ksys_clip_num(){ +KOSAPI int _ksys_clip_num(void) +{ unsigned val; asm_inline( "int $0x40" - :"=a"(val) - :"a"(54), "b"(0) - ); + : "=a"(val) + : "a"(54), "b"(0)); return val; } - + /*==================== Function 54, subfunction 1 ======================*/ /*================= Read the data from the clipboard. ==================-*/ -static inline -char* _ksys_clip_get(int n) { // returned buffer must be freed by _ksys_free() +KOSAPI char* _ksys_clip_get(int n) // returned buffer must be freed by _ksys_free() +{ char* val; asm_inline( "int $0x40" - :"=a"(val) - :"a"(54), "b"(1), "c"(n) - ); + : "=a"(val) + : "a"(54), "b"(1), "c"(n)); return val; } - + /*==================== Function 54, subfunction 2 ======================*/ /*================= Write the data to the clipboard. ===================*/ -static inline -int _ksys_clip_set(int n, char *buffer){ +KOSAPI int _ksys_clip_set(int n, char* buffer) +{ unsigned val; asm_inline( "int $0x40" - :"=a"(val) - :"a"(54), "b"(2), "c"(n), "d"(buffer) - :"memory" - ); + : "=a"(val) + : "a"(54), "b"(2), "c"(n), "d"(buffer) + : "memory"); return val; } - + /*===================== Function 54, subfunction 3 =====================*/ /*================ Delete the last slot in the clipboard ===============*/ -static inline -int _ksys_clip_pop(){ - unsigned val; - asm_inline ( - "int $0x40" - :"=a"(val) - :"a"(54), "b"(3) - ); - return val; -} - -/*===================== Function 54, subfunction 4 =====================*/ -/*===================== Alarm reset the lock buffer ====================*/ - -static inline -int _ksys_clip_unlock(){ +KOSAPI int _ksys_clip_pop() +{ unsigned val; asm_inline( "int $0x40" - :"=a"(val) - :"a"(54), "b"(4) - ); + : "=a"(val) + : "a"(54), "b"(3)); + return val; +} + +/*===================== Function 54, subfunction 4 =====================*/ +/*===================== Alarm reset the lock buffer ====================*/ + +KOSAPI int _ksys_clip_unlock() +{ + unsigned val; + asm_inline( + "int $0x40" + : "=a"(val) + : "a"(54), "b"(4)); return val; } /*============== Function 63 - work with the debug board. ==============*/ -static inline -void _ksys_debug_putc(char c){ - asm_inline("int $0x40"::"a"(63), "b"(1), "c"(c)); +KOSAPI void _ksys_debug_putc(char c) +{ + asm_inline("int $0x40" ::"a"(63), "b"(1), "c"(c)); } - -static inline -void _ksys_debug_puts(const char* s){ - unsigned i=0; - while (*(s+i)){ - asm_inline ("int $0x40"::"a"(63), "b"(1), "c"(*(s+i))); + +KOSAPI void _ksys_debug_puts(const char* s) +{ + unsigned i = 0; + while (*(s + i)) { + asm_inline("int $0x40" ::"a"(63), "b"(1), "c"(*(s + i))); i++; } } @@ -1082,104 +994,93 @@ typedef enum KSYS_KEY_INPUT_MODE { KSYS_KEY_INPUT_MODE_SCANC = 1, } ksys_key_input_mode_t; -static inline -void _ksys_set_key_input_mode(ksys_key_input_mode_t mode){ +KOSAPI void _ksys_set_key_input_mode(ksys_key_input_mode_t mode) +{ asm_inline( - "int $0x40" - ::"a"(66),"b"(1),"c"(mode) - ); + "int $0x40" ::"a"(66), "b"(1), "c"(mode)); } /*========= Function 67 - change position/sizes of the window. =========*/ -static inline -void _ksys_change_window(int new_x, int new_y, int new_w, int new_h){ +KOSAPI void _ksys_change_window(int new_x, int new_y, int new_w, int new_h) +{ asm_inline( - "int $0x40" - ::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w),"S"(new_h) - ); + "int $0x40" ::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w), "S"(new_h)); } /*======== Function 68, subfunction 12 - allocate memory block. ========*/ -static inline -void* _ksys_alloc(size_t size){ - void *val; +KOSAPI void* _ksys_alloc(size_t size) +{ + void* val; asm_inline( "int $0x40" - :"=a"(val) - :"a"(68),"b"(12),"c"(size) - ); + : "=a"(val) + : "a"(68), "b"(12), "c"(size)); return val; } /*========== Function 68, subfunction 13 - free memory block. ==========*/ -static inline -int _ksys_free(void *mem){ +KOSAPI int _ksys_free(void* mem) +{ int val; asm_inline( "int $0x40" - :"=a"(val) - :"a"(68),"b"(13),"c"(mem) - ); + : "=a"(val) + : "a"(68), "b"(13), "c"(mem)); return val; } /*============= Function 68, subfunction 16 - load driver. =============*/ -static inline -ksys_drv_hand_t _ksys_load_driver(char *driver_name) +KOSAPI ksys_drv_hand_t _ksys_load_driver(char* driver_name) { ksys_drv_hand_t driver_h; asm_inline( "int $0x40" - :"=a"(driver_h) - :"a"(68), "b"(16), "c"(driver_name) - ); + : "=a"(driver_h) + : "a"(68), "b"(16), "c"(driver_name)); return driver_h; } /*============ Function 68, subfunction 17 - driver control. ===========*/ -static inline -unsigned _ksys_driver_control(ksys_ioctl_t *ioctl) +KOSAPI int _ksys_driver_control(ksys_ioctl_t* ioctl) { - unsigned status; + int status; asm_inline( "int $0x40" - :"=a"(status) - :"a"(68), "b"(17), "c"(ioctl) - :"memory" - ); + : "=a"(status) + : "a"(68), "b"(17), "c"(ioctl) + : "memory"); return status; } /*== Function 68, subfunction 18 - subfunction 19 - load DLL (MS COFF) ==*/ -static inline -ksys_dll_t* _ksys_dlopen(const char* path){ - ksys_dll_t *table; +KOSAPI ksys_dll_t* _ksys_dlopen(const char* path) +{ + ksys_dll_t* table; asm_inline( "int $0x40" - :"=a"(table) - :"a"(68),"b"(19), "c"(path) - :"memory" - ); + : "=a"(table) + : "a"(68), "b"(19), "c"(path) + : "memory"); return table; } /* It is not a system call, it serves as an auxiliary tool*/ -static inline -void* _ksys_dlsym(ksys_dll_t *table, const char* fun_name){ - unsigned i=0; - while (1){ - if (!(table+i)->func_name){ +KOSAPI void* _ksys_dlsym(ksys_dll_t* table, const char* fun_name) +{ + unsigned i = 0; + while (1) { + if (!(table + i)->func_name) { break; - }else{ - if (!__strcmp(fun_name, (table+i)->func_name)){ - return (table+i)->func_ptr; + } else { + if (!__strcmp(fun_name, (table + i)->func_name)) { + return (table + i)->func_ptr; } } i++; @@ -1189,35 +1090,32 @@ void* _ksys_dlsym(ksys_dll_t *table, const char* fun_name){ /* Function 68, subfunction 20 - reallocate memory block.*/ -static inline -void* _ksys_realloc(void *mem, size_t size){ - void *val; +KOSAPI void* _ksys_realloc(void* mem, size_t size) +{ + void* val; asm_inline( "int $0x40" - :"=a"(val) - :"a"(68),"b"(20),"c"(size),"d"(mem) - :"memory" - ); + : "=a"(val) + : "a"(68), "b"(20), "c"(size), "d"(mem) + : "memory"); return val; } /* Function 68, subfunction 21 - load driver by full name. */ -static inline -ksys_drv_hand_t _ksys_load_driver_opt(char *driver_path, char *cmd_line) +KOSAPI ksys_drv_hand_t _ksys_load_driver_opt(char* driver_path, char* cmd_line) { ksys_drv_hand_t driver_h; asm_inline( "int $0x40" - :"=a"(driver_h) - :"a"(68), "b"(21), "c"(driver_path), "d"(cmd_line) - ); + : "=a"(driver_h) + : "a"(68), "b"(21), "c"(driver_path), "d"(cmd_line)); return driver_h; } /*======== Function 68, subfunction 22 - open named memory area. =======*/ -enum KSYS_SHM_MODE{ +enum KSYS_SHM_MODE { KSYS_SHM_OPEN = 0x00, KSYS_SHM_OPEN_ALWAYS = 0x04, KSYS_SHM_CREATE = 0x08, @@ -1225,91 +1123,80 @@ enum KSYS_SHM_MODE{ KSYS_SHM_WRITE = 0x01, }; -static inline -int _ksys_shm_open(char *name, int mode, int size, char **new_shm) +KOSAPI int _ksys_shm_open(char* name, int mode, int size, char** new_shm) { int error; asm_inline( "int $0x40" - :"=a"(*new_shm), "=d"(error) - :"a"(68), "b"(22), "c"(name), "d"(size), "S"(mode) - ); + : "=a"(*new_shm), "=d"(error) + : "a"(68), "b"(22), "c"(name), "d"(size), "S"(mode)); return error; } /*======= Function 68, subfunction 23 - close named memory area. =======*/ -static inline -void _ksys_shm_close(char *shm_name) +KOSAPI void _ksys_shm_close(char* shm_name) { asm_inline( - "int $0x40": - :"a"(68), "b"(23), "c"(shm_name) - ); + "int $0x40" + : + : "a"(68), "b"(23), "c"(shm_name)); } /*====== Function 68, subfunction 26 - release memory pages ============*/ -static inline -int* _ksys_unmap(void *base, size_t offset, size_t size){ - int *val; +KOSAPI int* _ksys_unmap(void* base, size_t offset, size_t size) +{ + int* val; asm_inline( "int $0x40" - :"=a"(val) - :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size) - ); + : "=a"(val) + : "a"(68), "b"(26), "c"(base), "d"(offset), "S"(size)); return val; } /*========== Function 68, subfunction 27 - load file ===================*/ -static inline -ksys_ufile_t _ksys_load_file(const char *path) +KOSAPI ksys_ufile_t _ksys_load_file(const char* path) { ksys_ufile_t uf; asm_inline( "int $0x40" - :"=a"(uf.data), "=d"(uf.size) - :"a"(68), "b"(27),"c"(path) - :"memory" - ); + : "=a"(uf.data), "=d"(uf.size) + : "a"(68), "b"(27), "c"(path) + : "memory"); return uf; } /*==== Function 68, subfunction 28 - load file, specifying the encoding ===*/ -static inline -ksys_ufile_t _ksys_load_file_enc(const char *path, unsigned file_encoding) +KOSAPI ksys_ufile_t _ksys_load_file_enc(const char* path, unsigned file_encoding) { ksys_ufile_t uf; asm_inline( "int $0x40" - :"=a"(uf.data), "=d"(uf.size) - :"a"(68), "b"(28),"c"(path), "d"(file_encoding) - :"memory" - ); + : "=a"(uf.data), "=d"(uf.size) + : "a"(68), "b"(28), "c"(path), "d"(file_encoding) + : "memory"); return uf; } /*==== Function 70 - work with file system with long names support. ====*/ -static inline -int _ksys_work_files(const ksys70_t *k) +KOSAPI ksys70_status_t _ksys70(const ksys70_t* k) { - int status; + ksys70_status_t status; asm_inline( "int $0x40" - :"=a"(status) - :"a"(70), "b"(k) - :"memory" - ); + : "=a"(status.status), "=b"(status.rw_bytes) + : "a"(70), "b"(k) + : "memory"); return status; } /*====== Function 70, subfunction 0 - read file with long names support. ======*/ -static inline -int _ksys_file_read_file(const char *name, unsigned long long offset, unsigned size, void *buf, unsigned *bytes_read) +KOSAPI ksys70_status_t _ksys_file_read(const char* name, uint64_t offset, uint32_t size, void* buf) { ksys70_t k; k.p00 = 0; @@ -1318,35 +1205,27 @@ int _ksys_file_read_file(const char *name, unsigned long long offset, unsigned s k.buf16 = buf; k.p20 = 0; k.p21 = name; - int status; - asm_inline( - "int $0x40" - :"=a"(status), "=b"(*bytes_read) - :"a"(70), "b"(&k) - :"memory" - ); - return status; + return _ksys70(&k); } /*===================== Function 70, subfunction 2 =====================*/ /*============ Create/rewrite file with long names support. ============*/ -static inline -int _ksys_file_create(const char* name){ +KOSAPI int _ksys_file_create(const char* name) +{ ksys70_t k; - k.p00 = 2; + k.p00 = 2; k.p04dw = 0; k.p08dw = 0; - k.p12 = 0; - k.p21 = name; - return _ksys_work_files(&k); + k.p12 = 0; + k.p21 = name; + return _ksys70(&k).status; } /*===================== Function 70, subfunction 3 =====================*/ /*=========== Write to existing file with long names support. ==========*/ -static inline -int _ksys_file_write_file(const char *name, unsigned long long offset, unsigned size, const void *buf, unsigned *bytes_written) +KOSAPI ksys70_status_t _ksys_file_write(const char* name, uint64_t offset, uint32_t size, const void* buf) { ksys70_t k; k.p00 = 3; @@ -1355,129 +1234,130 @@ int _ksys_file_write_file(const char *name, unsigned long long offset, unsigned k.cbuf16 = buf; k.p20 = 0; k.p21 = name; - int status; - asm_inline( - "int $0x40" - :"=a"(status), "=b"(*bytes_written) - :"a"(70), "b"(&k) - :"memory" - ); - return status; + return _ksys70(&k); } /*========== Function 70, subfunction 5 - get information on file/folder. =====*/ -static inline -int _ksys_file_get_info(const char *name, ksys_bdfe_t *bdfe) +KOSAPI int _ksys_file_info(const char* name, ksys_bdfe_t* bdfe) { ksys70_t k; - k.p00 = 5; + k.p00 = 5; k.p04dw = 0; k.p08dw = 0; - k.p12 = 0; - k.bdfe = bdfe; - k.p20 = 0; - k.p21 = name; - return _ksys_work_files(&k); + k.p12 = 0; + k.bdfe = bdfe; + k.p20 = 0; + k.p21 = name; + return _ksys70(&k).status; } +#define _ksys_dir_info _ksys_file_info + /*=========== Function 70, subfunction 7 - start application. ===========*/ -static inline -int _ksys_exec(char *app_name, char *args) +KOSAPI int _ksys_exec(const char* app_name, char* args) { ksys70_t file_opt; file_opt.p00 = 7; file_opt.p04dw = 0; - file_opt.p08dw = (unsigned)args; + file_opt.p08dw = (uint32_t)args; file_opt.p12 = 0; file_opt.p16 = 0; file_opt.p20 = 0; file_opt.p21 = app_name; - return _ksys_work_files(&file_opt); + return _ksys70(&file_opt).status; } /*========== Function 70, subfunction 8 - delete file/folder. ==========*/ -static inline -int _ksys_file_delete(const char *name) +KOSAPI int _ksys_file_delete(const char* name) { ksys70_t k; k.p00 = 8; k.p20 = 0; k.p21 = name; - return _ksys_work_files(&k); + return _ksys70(&k).status; } /*============= Function 70, subfunction 9 - create folder. ============*/ -static inline -int _ksys_mkdir(const char *path) +KOSAPI int _ksys_mkdir(const char* path) { ksys70_t dir_opt; dir_opt.p00 = 9; dir_opt.p21 = path; - return _ksys_work_files(&dir_opt); + return _ksys70(&dir_opt).status; } /*============= Function 70, subfunction 10 - rename/move. =============*/ -static inline -int _ksys_file_rename(const char *name, const char *new_name) +KOSAPI int _ksys_file_rename(const char* name, const char* new_name) { ksys70_t k; k.p00 = 10; k.new_name = new_name; k.p20 = 0; k.p21 = name; - return _ksys_work_files(&k); + return _ksys70(&k).status; } +#define _ksys_dir_rename _ksys_file_rename + /*============= Function 77 - implements the POSIX subsystem. =============*/ -static inline -int _ksys_posix_read(int pipefd, void* buff, int n) +KOSAPI int _ksys_posix_read(int pipefd, void* buff, int n) { int count; asm_inline( "int $0x40" - :"=a"(count) - :"a"(77), "b"(10),"c"(pipefd), "d"(buff), "S"(n) - :"memory" - ); + : "=a"(count) + : "a"(77), "b"(10), "c"(pipefd), "d"(buff), "S"(n) + : "memory"); return count; } -static inline -int _ksys_posix_write(int pipefd, void* buff, int n) +KOSAPI int _ksys_posix_write(int pipefd, void* buff, int n) { int count; asm_inline( "int $0x40" - :"=a"(count) - :"a"(77), "b"(11),"c"(pipefd), "d"(buff), "S"(n) - :"memory" - ); + : "=a"(count) + : "a"(77), "b"(11), "c"(pipefd), "d"(buff), "S"(n) + : "memory"); return count; } -static inline -int _ksys_posix_pipe2(int pipefd[2], int flags) +KOSAPI int _ksys_posix_pipe2(int pipefd[2], int flags) { int err; asm_inline( "int $0x40" - :"=a"(err) - :"a"(77), "b"(13),"c"(pipefd), "d"(flags) - :"memory" - ); + : "=a"(err) + : "a"(77), "b"(13), "c"(pipefd), "d"(flags) + : "memory"); return err; } /* ######### Old names of functions and structures. Do not use again! ##########*/ -#define _ksys_get_event _ksys_wait_event +#define _ksys_get_event _ksys_wait_event +#define _ksys_file_get_info _ksys_file_info + +static inline int _ksys_file_read_file(const char* name, unsigned long long offset, unsigned size, void* buff, unsigned* bytes_read) +{ + ksys70_status_t res = _ksys_file_read(name, offset, size, buff); + *bytes_read = res.rw_bytes; + return res.status; +} + +static inline int _ksys_file_write_file(const char* name, unsigned long long offset, unsigned size, const void* buff, unsigned* bytes_write) +{ + ksys70_status_t res = _ksys_file_write(name, offset, size, buff); + *bytes_write = res.rw_bytes; + return res.status; +} #endif // _KSYS_H_ diff --git a/programs/develop/ktcc/trunk/libc.obj/include/sys/socket.h b/programs/develop/ktcc/trunk/libc.obj/include/sys/socket.h index 2d2d336f37..fc377468a6 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/sys/socket.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/sys/socket.h @@ -3,89 +3,89 @@ #ifndef _SOCKET_H_ #define _SOCKET_H_ +#include #include #include -#include // Socket Types #define SOCK_STREAM 1 -#define SOCK_DGRAM 2 -#define SOCK_RAW 3 - +#define SOCK_DGRAM 2 +#define SOCK_RAW 3 + // IP protocols -#define IPPROTO_IP 0 +#define IPPROTO_IP 0 #define IPPROTO_ICMP 1 -#define IPPROTO_TCP 6 -#define IPPROTO_UDP 17 -#define IPPROTO_RAW 255 - +#define IPPROTO_TCP 6 +#define IPPROTO_UDP 17 +#define IPPROTO_RAW 255 + // IP options #define IP_TTL 2 - + // Address families #define AF_UNSPEC 0 -#define AF_LOCAL 1 -#define AF_INET 2 // Default INET=IPv4 -#define AF_INET4 2 // IPv4 -#define AF_INET6 10 // IPv6 +#define AF_LOCAL 1 +#define AF_INET 2 // Default INET=IPv4 +#define AF_INET4 2 // IPv4 +#define AF_INET6 10 // IPv6 #define PF_UNSPEC AF_UNSPEC #define PF_LOCAL AF_LOCAL #define PF_INET4 AF_INET4 #define PF_INET6 AF_INET6 - + // internal definition #define AI_SUPPORTED 0x40F // for system function 76 -#define API_ETH (0<<16) -#define API_IPv4 (1<<16) -#define API_ICMP (2<<16) -#define API_UDP (3<<16) -#define API_TCP (4<<16) -#define API_ARP (5<<16) -#define API_PPPOE (6<<16) +#define API_ETH (0 << 16) +#define API_IPv4 (1 << 16) +#define API_ICMP (2 << 16) +#define API_UDP (3 << 16) +#define API_TCP (4 << 16) +#define API_ARP (5 << 16) +#define API_PPPOE (6 << 16) // Socket flags for user calls -#define MSG_NOFLAG 0 -#define MSG_PEEK 0x02 +#define MSG_NOFLAG 0 +#define MSG_PEEK 0x02 #define MSG_DONTWAIT 0x40 - + // Socket levels #define SOL_SOCKET 0xffff -//Socket options -#define SO_BINDTODEVICE (1<<9) -#define SO_NONBLOCK (1<<31) +// Socket options +#define SO_BINDTODEVICE (1 << 9) +#define SO_NONBLOCK (1 << 31) -#define PORT(X) (X<<8) +#define PORT(X) (X << 8) -#pragma pack(push,1) -struct sockaddr{ +#pragma pack(push, 1) +struct sockaddr { unsigned short sin_family; - unsigned short sin_port; + unsigned short sin_port; unsigned int sin_addr; unsigned long long sin_zero; -}; +}; -typedef struct{ - unsigned int level; - unsigned int optionname; - unsigned int optlenght; - unsigned char options; -}optstruct; +typedef struct { + unsigned int level; + unsigned int optionname; + unsigned int optlenght; + unsigned char options; +} optstruct; #pragma pack(pop) extern int _FUNC(socket)(int domain, int type, int protocol); extern int _FUNC(close)(int socket); -extern int _FUNC(bind)(int socket, const struct sockaddr *addres, int addres_len); +extern int _FUNC(bind)(int socket, const struct sockaddr* addres, int addres_len); extern int _FUNC(listen)(int socket, int backlog); extern int _FUNC(connect)(int socket, const struct sockaddr* address, int socket_len); -extern int _FUNC(accept)(int socket, const struct sockaddr *address, int address_len); -extern int _FUNC(send)(int socket, const void *message, size_t msg_len, int flag); -extern int _FUNC(recv)(int socket, void *buffer, size_t buff_len, int flag); -extern int _FUNC(setsockopt)(int socket,const optstruct* opt); +extern int _FUNC(accept)(int socket, const struct sockaddr* address, int address_len); +extern int _FUNC(send)(int socket, const void* message, size_t msg_len, int flag); +extern int _FUNC(recv)(int socket, void* buffer, size_t buff_len, int flag); +extern int _FUNC(setsockopt)(int socket, const optstruct* opt); extern int _FUNC(getsockopt)(int socket, optstruct* opt); -extern int _FUNC(socketpair)(int *socket1, int *socket2); +extern int _FUNC(socketpair)(int* socket1, int* socket2); -#endif //_SOCKET_H_ +#endif //_SOCKET_H_ \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/include/time.h b/programs/develop/ktcc/trunk/libc.obj/include/time.h index 6dc36eaa3d..70bfe70000 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/time.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/time.h @@ -5,27 +5,27 @@ typedef unsigned long int clock_t; typedef unsigned long int time_t; -#define clock() _ksys_get_clock() +#define clock() _ksys_get_clock() #define CLOCKS_PER_SEC 100 #pragma pack(push, 1) struct tm { - int tm_sec; /* seconds after the minute 0-61*/ - int tm_min; /* minutes after the hour 0-59 */ - int tm_hour; /* hours since midnight 0-23 */ - int tm_mday; /* day of the month 1-31 */ - int tm_mon; /* months since January 0-11 */ - int tm_year; /* years since 1900 */ - int tm_wday; /* days since Sunday 0-6 */ - int tm_yday; /* days since January 1 0-365 */ - int tm_isdst; /* Daylight Saving Time flag */ + int tm_sec; /* seconds after the minute 0-61*/ + int tm_min; /* minutes after the hour 0-59 */ + int tm_hour; /* hours since midnight 0-23 */ + int tm_mday; /* day of the month 1-31 */ + int tm_mon; /* months since January 0-11 */ + int tm_year; /* years since 1900 */ + int tm_wday; /* days since Sunday 0-6 */ + int tm_yday; /* days since January 1 0-365 */ + int tm_isdst; /* Daylight Saving Time flag */ }; #pragma pack(pop) -extern time_t _FUNC(mktime)(struct tm * timeptr); +extern time_t _FUNC(mktime)(struct tm* timeptr); extern time_t _FUNC(time)(time_t* timer); -extern struct tm * _FUNC(localtime)(const time_t * timer); +extern struct tm* _FUNC(localtime)(const time_t* timer); extern double _FUNC(difftime)(time_t end, time_t beginning); -extern char* _FUNC(asctime)(const struct tm *tm); +extern char* _FUNC(asctime)(const struct tm* tm); #endif \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/loader/__lib__.asm.bak b/programs/develop/ktcc/trunk/libc.obj/loader/__lib__.asm.bak deleted file mode 100644 index eac1985673..0000000000 --- a/programs/develop/ktcc/trunk/libc.obj/loader/__lib__.asm.bak +++ /dev/null @@ -1,9 +0,0 @@ -format ELF - -include '__lib__.inc' - -section '.text' - -public lib_name - -lib_name db 0x55, 0xAA, lib_name_str, 0 diff --git a/programs/develop/ktcc/trunk/libc.obj/loader/__lib__.inc b/programs/develop/ktcc/trunk/libc.obj/loader/__lib__.inc deleted file mode 100644 index 15d14f801d..0000000000 --- a/programs/develop/ktcc/trunk/libc.obj/loader/__lib__.inc +++ /dev/null @@ -1,2 +0,0 @@ -lib_name equ @libc.obj -lib_name_str equ '/sys/lib/libc.obj' diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/assert_test.c b/programs/develop/ktcc/trunk/libc.obj/samples/assert_test.c index 0e5711603f..99f47d7e9b 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/assert_test.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/assert_test.c @@ -1,9 +1,10 @@ #include #include -int a=431; -int b=532; +int a = 431; +int b = 532; -int main(){ - assert(a!=b); - assert(a==b); +int main() +{ + assert(a != b); + assert(a == b); } \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/basic_gui.c b/programs/develop/ktcc/trunk/libc.obj/samples/basic_gui.c index f4d930f67a..9f2af0ce47 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/basic_gui.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/basic_gui.c @@ -1,7 +1,7 @@ +#include #include #include #include -#include #include ksys_colors_table_t sys_color_table; @@ -10,8 +10,7 @@ char statusbar[255]; ksys_thread_t proc_info; char text_line[255]; -enum BUTTONS -{ +enum BUTTONS { BTN_QUIT = 1, BTN_POP = 10, BTN_UNLOCK = 11 @@ -23,40 +22,43 @@ enum BUTTONS void draw_window() { - int win_hight, win_width, i, pos_y = _ksys_get_skin_height() + 36; // 60 == 24+36 + int win_hight, win_width, i, pos_y = _ksys_get_skin_height() + 36; // 60 == 24+36 // start redraw _ksys_start_draw(); - // define&draw window + // define&draw window _ksys_create_window(10, 40, 600, 400, "My window", sys_color_table.work_area, 0x13); _ksys_thread_info(&proc_info, -1); + F - win_width = proc_info.winx_size; + win_width + = proc_info.winx_size; win_hight = proc_info.winy_size; - + _ksys_define_button(10, 30, 70, 20, BTN_POP, sys_color_table.work_button); - _ksys_draw_text("BUTTON1", 15, 34, 0, 0x90000000 | sys_color_table.work_button_text); //0x80000000 asciiz + _ksys_draw_text("BUTTON1", 15, 34, 0, 0x90000000 | sys_color_table.work_button_text); // 0x80000000 asciiz _ksys_define_button(100, 30, 80, 20, BTN_UNLOCK, sys_color_table.work_button); _ksys_draw_text("BUTTTON2", 110, 34, 0, 0x90000000 | sys_color_table.work_button_text); // display statusbar - _ksys_draw_bar(6, win_hight - 17, win_width - 11, 12, 0x80000000 | sys_color_table.work_area); //0x80000000 gradient + _ksys_draw_bar(6, win_hight - 17, win_width - 11, 12, 0x80000000 | sys_color_table.work_area); // 0x80000000 gradient _ksys_draw_text(statusbar, 10, win_hight - 15, 0, 0x80000000 | sys_color_table.work_text); // display strings - for (i = LINES; i > 0; i--){ - snprintf (text_line, sizeof text_line, "Line[%d]<>", i); + for (i = LINES; i > 0; i--) { + snprintf(text_line, sizeof text_line, "Line[%d]<>", i); text_line[(win_width - 10 - 5) / FONT_W + 1] = '\0'; // clip text size, seems to big lines crashing OS, and form len by window size _ksys_draw_text(text_line, 5, pos_y, 0, 0x90000000 | sys_color_table.work_text); pos_y += FONT_H; - if(pos_y + 29 > win_hight) break; // 12 font + 12 statusbar + 5 border + if (pos_y + 29 > win_hight) + break; // 12 font + 12 statusbar + 5 border } // end redraw _ksys_end_draw(); } - + int main() { int gui_event; @@ -67,30 +69,28 @@ int main() _ksys_get_system_colors(&sys_color_table); _ksys_set_event_mask(0xC0000027); // mouse events only when focused window and mouse inside - do{ - gui_event = _ksys_get_event(); - switch(gui_event) - { + do { + gui_event = _ksys_get_event(); + switch (gui_event) { case KSYS_EVENT_NONE: - break; + break; case KSYS_EVENT_REDRAW: draw_window(); - break; + break; case KSYS_EVENT_KEY: - break; + break; case KSYS_EVENT_BUTTON: pressed_button = _ksys_get_button(); - switch (pressed_button) - { - case BTN_POP: + switch (pressed_button) { + case BTN_POP: strcpy(statusbar, "POP pressed...."); draw_window(); break; - case BTN_UNLOCK: + case BTN_UNLOCK: strcpy(statusbar, "UNLOCK pressed...."); draw_window(); break; - case BTN_QUIT: + case BTN_QUIT: return 0; break; } @@ -99,17 +99,18 @@ int main() mouse_pos = _ksys_get_mouse_pos(KSYS_MOUSE_WINDOW_POS); // window relative mouse_button = _ksys_get_mouse_eventstate(); debug_printf("mouse ev (%d,%d)%x\n", mouse_pos.x, mouse_pos.y, mouse_button); - if (mouse_button & (1<<24)) // double click + if (mouse_button & (1 << 24)) // double click { int n = (mouse_pos.y - 60) / FONT_H; - if (n < 0 || n >= LINES) break; + if (n < 0 || n >= LINES) + break; debug_printf("click on str(%d), clip slot(%d)\n", n, LINES - n - 1); sprintf(statusbar, "click on str(%d), clip slot(%d)\n", n, LINES - n - 1); draw_window(); } break; } - } while(1) ; /* End of main activity loop */ + } while (1); /* End of main activity loop */ - return 0; + return 0; } diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/clayer/boxlib.c b/programs/develop/ktcc/trunk/libc.obj/samples/clayer/boxlib.c index be81481182..dfb7bdbc53 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/clayer/boxlib.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/clayer/boxlib.c @@ -1,11 +1,11 @@ // BOXLIB EXAMPLE (scrollbar, progressbar, editbox and checkbox) // Writed by maxcodehack and superturbocat2001 -#include -#include -#include #include #include +#include +#include +#include #define WIN_W 640 #define WIN_H 563 @@ -16,75 +16,77 @@ #define SCROLL_MAX_LEN 215 #define BLACK 0x000000 #define WHITE 0xFFFFFF -#define BLUE 0x0000FF -#define X_W(X, W) ((X<<16)+W) +#define BLUE 0x0000FF +#define X_W(X, W) ((X << 16) + W) #define Y_H X_W uint32_t wheels; char* title = "Boxlib example"; char ed_buff[ED_BUFF_LEN]; - -scrollbar scroll = {15, WIN_W - 26, WIN_H - 29, 0, 0, 2, 215, SCROLL_BUTTON_SIZE, 0,0x707070,0xD2CED0,0x555555}; -progressbar pg = {0, 10, 10, 270, 35, 1, 0, 200, 0xB4B4B4, 0x2728FF, 0xA9A9A9}; -edit_box ed={WIN_W-140,10,60,0xFFFFFF,0x6a9480,0,0x6a9480, BLACK | TEXT_SIZE, ED_BUFF_LEN, ed_buff,NULL,ed_focus}; -check_box output_off={X_W(10, 15), Y_H(120,15), 10, WHITE, BLUE, BLACK | TEXT_SIZE, "Disable duplicate output",0}; -void draw_window(){ - _ksys_start_draw(); - _ksys_create_window(215,100,WIN_W,WIN_H,title, 0x858585, 0x34); - edit_box_draw(&ed); - check_box_draw2(&output_off); - if(!output_off.flags){ - _ksys_draw_text(ed_buff, 10, 90, strlen(ed_buff), BLACK | TEXT_SIZE); - } - scrollbar_v_draw(&scroll); +scrollbar scroll = { 15, WIN_W - 26, WIN_H - 29, 0, 0, 2, 215, SCROLL_BUTTON_SIZE, 0, 0x707070, 0xD2CED0, 0x555555 }; +progressbar pg = { 0, 10, 10, 270, 35, 1, 0, 200, 0xB4B4B4, 0x2728FF, 0xA9A9A9 }; +edit_box ed = { WIN_W - 140, 10, 60, 0xFFFFFF, 0x6a9480, 0, 0x6a9480, BLACK | TEXT_SIZE, ED_BUFF_LEN, ed_buff, NULL, ed_focus }; +check_box output_off = { X_W(10, 15), Y_H(120, 15), 10, WHITE, BLUE, BLACK | TEXT_SIZE, "Disable duplicate output", 0 }; + +void draw_window() +{ + _ksys_start_draw(); + _ksys_create_window(215, 100, WIN_W, WIN_H, title, 0x858585, 0x34); + edit_box_draw(&ed); + check_box_draw2(&output_off); + if (!output_off.flags) { + _ksys_draw_text(ed_buff, 10, 90, strlen(ed_buff), BLACK | TEXT_SIZE); + } + scrollbar_v_draw(&scroll); progressbar_draw(&pg); - _ksys_end_draw(); + _ksys_end_draw(); } int main() { - init_checkbox2(&output_off); - _ksys_set_event_mask(KSYS_EVM_REDRAW + KSYS_EVM_KEY + KSYS_EVM_BUTTON + KSYS_EVM_MOUSE+ KSYS_EVM_MOUSE_FILTER); - while(1){ - switch(_ksys_get_event()){ - case KSYS_EVENT_BUTTON: - if (_ksys_get_button() == 1) return 0; - break; - - case KSYS_EVENT_KEY: - edit_box_key_safe(&ed, _ksys_get_key()); + init_checkbox2(&output_off); + _ksys_set_event_mask(KSYS_EVM_REDRAW + KSYS_EVM_KEY + KSYS_EVM_BUTTON + KSYS_EVM_MOUSE + KSYS_EVM_MOUSE_FILTER); + while (1) { + switch (_ksys_get_event()) { + case KSYS_EVENT_BUTTON: + if (_ksys_get_button() == 1) + return 0; + break; + + case KSYS_EVENT_KEY: + edit_box_key_safe(&ed, _ksys_get_key()); draw_window(); - break; - - case KSYS_EVENT_REDRAW: - draw_window(); - break; - - case KSYS_EVENT_MOUSE: - edit_box_mouse(&ed); - scrollbar_v_mouse(&scroll); - pg.value = scroll.position; - progressbar_draw(&pg); - check_box_mouse2(&output_off); - unsigned int scroll_strong = 10; + break; + + case KSYS_EVENT_REDRAW: + draw_window(); + break; + + case KSYS_EVENT_MOUSE: + edit_box_mouse(&ed); + scrollbar_v_mouse(&scroll); + pg.value = scroll.position; + progressbar_draw(&pg); + check_box_mouse2(&output_off); + unsigned int scroll_strong = 10; wheels = _ksys_get_mouse_wheels(); - if(wheels & 0xFFFF){ - if((short)wheels > 0){ - scroll.position += scroll_strong; - if(scroll.position>scroll.max_area-scroll.cur_area){ - scroll.position=scroll.max_area-scroll.cur_area; - } - }else if((short)wheels < 0 && scroll.position > 0){ - scroll.position -= scroll_strong; - if((int)scroll.position<0){ - scroll.position=0; - } - } - scrollbar_v_draw(&scroll); + if (wheels & 0xFFFF) { + if ((short)wheels > 0) { + scroll.position += scroll_strong; + if (scroll.position > scroll.max_area - scroll.cur_area) { + scroll.position = scroll.max_area - scroll.cur_area; + } + } else if ((short)wheels < 0 && scroll.position > 0) { + scroll.position -= scroll_strong; + if ((int)scroll.position < 0) { + scroll.position = 0; + } + } + scrollbar_v_draw(&scroll); } - break; - } - } - return 0; + break; + } + } + return 0; } diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/clayer/dialog.c b/programs/develop/ktcc/trunk/libc.obj/samples/clayer/dialog.c index 8051ef2bc4..37956bc7ae 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/clayer/dialog.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/clayer/dialog.c @@ -1,28 +1,28 @@ -#include #include #include +#include int main() { - open_dialog *dlg_open = kolibri_new_open_dialog(OPEN, 10, 10, 420, 320); // create opendialog struct - OpenDialog_init(dlg_open); // Initializing an open dialog box. - OpenDialog_start(dlg_open); // Show open dialog box - - color_dialog *color_select = kolibri_new_color_dialog(SELECT, 10, 10,420,320); // create colordialog struct - ColorDialog_init(color_select); // Initializing an color dialog box. - ColorDialog_start(color_select); // Show color dialog - - if(dlg_open->status == SUCCESS){ - printf("File selected '%s'\n",dlg_open->openfile_path); - }else{ + open_dialog* dlg_open = kolibri_new_open_dialog(OPEN, 10, 10, 420, 320); // create opendialog struct + OpenDialog_init(dlg_open); // Initializing an open dialog box. + OpenDialog_start(dlg_open); // Show open dialog box + + color_dialog* color_select = kolibri_new_color_dialog(SELECT, 10, 10, 420, 320); // create colordialog struct + ColorDialog_init(color_select); // Initializing an color dialog box. + ColorDialog_start(color_select); // Show color dialog + + if (dlg_open->status == SUCCESS) { + printf("File selected '%s'\n", dlg_open->openfile_path); + } else { puts("No file selected!"); } - - if(color_select->status == SUCCESS){ - printf("Color selected: #%06X\n",color_select->color); + + if (color_select->status == SUCCESS) { + printf("Color selected: #%06X\n", color_select->color); rgb_t color_rgb = (rgb_t)color_select->color; - printf("Red:%d Green:%d Blue:%d", color_rgb.red, color_rgb.green, color_rgb.blue); - }else{ + printf("Red:%d Green:%d Blue:%d", color_rgb.red, color_rgb.green, color_rgb.blue); + } else { puts("No color selected!"); } free(dlg_open); diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/clayer/libimg.c b/programs/develop/ktcc/trunk/libc.obj/samples/clayer/libimg.c index e30d85e69d..95b2f2a3e8 100755 --- a/programs/develop/ktcc/trunk/libc.obj/samples/clayer/libimg.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/clayer/libimg.c @@ -1,23 +1,24 @@ /* Written by turbocat2001 (Logaev Maxim) */ +#include +#include #include #include -#include -#include #include -#define NEW_IMG_H 128 +#define NEW_IMG_H 128 #define NEW_IMG_W 128 #define IMG_H 256 #define IMG_W 256 -Image *image_blend; // Create image struct +Image* image_blend; // Create image struct -ksys_colors_table_t sys_color_table; // Create system colors table +ksys_colors_table_t sys_color_table; // Create system colors table -void* load_img(char* fname, uint32_t* read_sz){ // Image file upload function - FILE *f = fopen(fname, "rb"); +void* load_img(char* fname, uint32_t* read_sz) +{ // Image file upload function + FILE* f = fopen(fname, "rb"); if (!f) { printf("Can't open file: %s\n", fname); return NULL; @@ -29,7 +30,7 @@ void* load_img(char* fname, uint32_t* read_sz){ // Image file upload function int filesize = ftell(f); rewind(f); void* fdata = malloc(filesize); - if(!fdata) { + if (!fdata) { printf("No memory for file %s\n", fname); return NULL; } @@ -42,55 +43,57 @@ void* load_img(char* fname, uint32_t* read_sz){ // Image file upload function return fdata; } -void draw_gui(){ +void draw_gui() +{ _ksys_start_draw(); - _ksys_create_window(10, 40, (IMG_W+NEW_IMG_W)+50, IMG_H+50, "Libimg", sys_color_table.work_area, 0x34); - img_draw(image_blend, 10, 10, IMG_W*2, IMG_H , 0, 0); // Draw blended image to window + _ksys_create_window(10, 40, (IMG_W + NEW_IMG_W) + 50, IMG_H + 50, "Libimg", sys_color_table.work_area, 0x34); + img_draw(image_blend, 10, 10, IMG_W * 2, IMG_H, 0, 0); // Draw blended image to window _ksys_end_draw(); } -int main(){ +int main() +{ _ksys_get_system_colors(&sys_color_table); // Get system colors theme _ksys_set_event_mask(0xC0000027); - - uint32_t img_size; - void *file_data = load_img("logo.png", &img_size); // Get RAW data and size - if(!file_data){ + + uint32_t img_size; + void* file_data = load_img("logo.png", &img_size); // Get RAW data and size + if (!file_data) { return 1; } Image* image = img_decode(file_data, img_size, 0); // Decode RAW data to Image data - - if (image->Type != IMAGE_BPP32) { + + if (image->Type != IMAGE_BPP32) { image = img_convert(image, NULL, IMAGE_BPP32, 0, 0); // Convert image to format BPP32 if (!image) { - printf("Сonvert error!: \n"); + printf("Сonvert error!: \n"); return 1; } } - - image_blend = img_create(IMG_W+NEW_IMG_W, IMG_H, IMAGE_BPP32); // Create an empty layer - img_fill_color(image_blend, IMG_W+NEW_IMG_W, IMG_H, sys_color_table.work_area); // Fill the layer with one color - img_blend(image_blend, image, 0, 0, 0, 0, IMG_W, IMG_H); // Blending images to display the alpha channel. + + image_blend = img_create(IMG_W + NEW_IMG_W, IMG_H, IMAGE_BPP32); // Create an empty layer + img_fill_color(image_blend, IMG_W + NEW_IMG_W, IMG_H, sys_color_table.work_area); // Fill the layer with one color + img_blend(image_blend, image, 0, 0, 0, 0, IMG_W, IMG_H); // Blending images to display the alpha channel. /* Reduce image size from 256x256 to 128x128 */ - image = img_scale(image, 0, 0, IMG_W, IMG_H, NULL, LIBIMG_SCALE_STRETCH , LIBIMG_INTER_BILINEAR, NEW_IMG_W, NEW_IMG_H); - img_blend(image_blend, image, 256, 0, 0, 0, NEW_IMG_W, NEW_IMG_H); - img_destroy(image); // Destroy image structure - free(file_data); // Free allocated file_data buffer - + image = img_scale(image, 0, 0, IMG_W, IMG_H, NULL, LIBIMG_SCALE_STRETCH, LIBIMG_INTER_BILINEAR, NEW_IMG_W, NEW_IMG_H); + img_blend(image_blend, image, 256, 0, 0, 0, NEW_IMG_W, NEW_IMG_H); + img_destroy(image); // Destroy image structure + free(file_data); // Free allocated file_data buffer + /* Main event loop */ - while (1) { - switch(_ksys_get_event()){ - case KSYS_EVENT_REDRAW: - draw_gui(); - break; - - case KSYS_EVENT_BUTTON: - if (_ksys_get_button()==1){ - return 0; - } - break; + while (1) { + switch (_ksys_get_event()) { + case KSYS_EVENT_REDRAW: + draw_gui(); + break; + + case KSYS_EVENT_BUTTON: + if (_ksys_get_button() == 1) { + return 0; + } + break; } - } - return 0; + } + return 0; } diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/clayer/msgbox.c b/programs/develop/ktcc/trunk/libc.obj/samples/clayer/msgbox.c index 7ccd9369eb..0c8890cf83 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/clayer/msgbox.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/clayer/msgbox.c @@ -2,7 +2,7 @@ int main() { - msgbox *msg1 = NULL; + msgbox* msg1 = NULL; msg1 = kolibri_new_msgbox("Title", "Text in window", 0, "Ok"); kolibri_start_msgbox(msg1, NULL); } diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/clayer/rasterworks.c b/programs/develop/ktcc/trunk/libc.obj/samples/clayer/rasterworks.c index 199114ed8e..c0fcf1d528 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/clayer/rasterworks.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/clayer/rasterworks.c @@ -1,8 +1,7 @@ -#include +#include #include #include #include -#include // Sizes int x_size = 768, y_size = 256; @@ -14,38 +13,39 @@ int main() { // Count length int ln_str = countUTF8Z(string, -1); - + // Create image buffer - void *buffi = malloc(x_size * y_size * 3 * sizeof(char) + 8); - + void* buffi = malloc(x_size * y_size * 3 * sizeof(char) + 8); + // Set sizes *((int*)buffi) = x_size; - *((int*)buffi+1) = y_size; - + *((int*)buffi + 1) = y_size; + // Fill color memset((char*)buffi + 8, 0xFF, x_size * y_size * 3); - + // Draw text on buffer - drawText(buffi, 5, 0, string, ln_str, 0xFF000000, 0x30C18); - drawText(buffi, 5, 32, string, ln_str, 0xFF000000, 0x1030C18); - drawText(buffi, 5, 64, string, ln_str, 0xFF000000, 0x2030C18); - drawText(buffi, 5, 96, string, ln_str, 0xFF000000, 0x4030C18); + drawText(buffi, 5, 0, string, ln_str, 0xFF000000, 0x30C18); + drawText(buffi, 5, 32, string, ln_str, 0xFF000000, 0x1030C18); + drawText(buffi, 5, 64, string, ln_str, 0xFF000000, 0x2030C18); + drawText(buffi, 5, 96, string, ln_str, 0xFF000000, 0x4030C18); drawText(buffi, 5, 128, string, ln_str, 0xFF000000, 0x8030C18); drawText(buffi, 5, 160, string, ln_str, 0xFF000000, 0x0F031428); - - while (1) { - switch (_ksys_get_event()){ - case KSYS_EVENT_REDRAW: - _ksys_start_draw(); - _ksys_create_window(50, 50, 800, 300, "Rasterworks Example", 0x999999, 0x34); - _ksys_draw_bitmap(buffi + 8, 10, 10, 768, 256); - _ksys_end_draw(); - break; - case KSYS_EVENT_BUTTON: - if(_ksys_get_button() == 1) exit(0); - break; - }; + while (1) { + switch (_ksys_get_event()) { + case KSYS_EVENT_REDRAW: + _ksys_start_draw(); + _ksys_create_window(50, 50, 800, 300, "Rasterworks Example", 0x999999, 0x34); + _ksys_draw_bitmap(buffi + 8, 10, 10, 768, 256); + _ksys_end_draw(); + break; + + case KSYS_EVENT_BUTTON: + if (_ksys_get_button() == 1) + exit(0); + break; + }; } return 0; } diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/consoleio.c b/programs/develop/ktcc/trunk/libc.obj/samples/consoleio.c index df6d5d7b59..5e7820ec63 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/consoleio.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/consoleio.c @@ -5,13 +5,14 @@ int main() { - if(con_init()) return 1; // init fail - (*con_set_title)("Console colors"); + if (con_init()) + return 1; // init fail + (*con_set_tsitle)("Console colors"); -// con_write_asciiz("\033[0;31;42m test \n"); // red on green bk + // con_write_asciiz("\033[0;31;42m test \n"); // red on green bk - for(int i = 30; i < 48; i++){ - (*con_printf)("\033[%dmColor 0x%02X: ", i, i); + for (int i = 30; i < 48; i++) { + (*con_printf)("\033[%dmColor 0x%02X: ", i, i); (*con_write_asciiz)("Text sample."); (*con_printf)(" printf %s test %d\n", "small", i); } diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/defgen.c b/programs/develop/ktcc/trunk/libc.obj/samples/defgen.c index 61a8ccaa7e..d7d3bccef2 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/defgen.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/defgen.c @@ -1,7 +1,7 @@ -#include "stddef.h" +#include +#include #include #include -#include #include #include @@ -12,38 +12,40 @@ enum ARGV_FILE { OUT = 2 }; -void show_help(void){ +void show_help(void) +{ puts("Usage: defgen [lib.obj] [lib.def]"); } -int main(int argc, char** argv){ +int main(int argc, char** argv) +{ - if(argc!=ARGC_VALID){ + if (argc != ARGC_VALID) { show_help(); return 0; } - ksys_dll_t *obj_dll = _ksys_dlopen(argv[IN]); + ksys_dll_t* obj_dll = _ksys_dlopen(argv[IN]); FILE* outfile = fopen(argv[OUT], "w"); - if(!obj_dll){ + if (!obj_dll) { printf("File '%s' not found!\n", argv[IN]); return 1; } - if(!outfile){ + if (!outfile) { printf("Unable to create file:'%s'!\n", argv[OUT]); return 2; } fprintf(outfile, "LIBRARY %s\n\n", basename(argv[IN])); fputs("EXPORTS\n", outfile); - - int i=0; - while(obj_dll[i].func_name){ - fprintf(outfile,"%s\n", obj_dll[i].func_name); + + int i = 0; + while (obj_dll[i].func_name) { + fprintf(outfile, "%s\n", obj_dll[i].func_name); i++; } - fclose(outfile); + fclose(outfile); return 0; } diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/dir_example.c b/programs/develop/ktcc/trunk/libc.obj/samples/dir_example.c index a4af2e98ca..3cbbd9aa48 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/dir_example.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/dir_example.c @@ -1,45 +1,44 @@ -#include -#include +#include #include #include -#include +#include +#include -const char *folder_type = "Folder"; -const char *file_type = "File"; +const char* folder_type = "Folder"; +const char* file_type = "File"; int main() { - char *path=getcwd(NULL, PATH_MAX); - printf("Current directory: %s\n", path); - if(mkdir("test")){ - puts("Test folder created!"); - } - else{ + char* path = getcwd(NULL, PATH_MAX); + printf("Current directory: %s\n", path); + if (mkdir("test")) { + puts("Test folder created!"); + } else { puts("Error creating folder!"); } - - DIR *mydir = opendir(path); - if(!mydir){ + + DIR* mydir = opendir(path); + if (!mydir) { puts("File system error."); return -1; } - struct dirent *file_info; - char *str_type=NULL; + struct dirent* file_info; + char* str_type = NULL; putc(' '); - while((file_info = readdir(mydir))!=NULL){ - if(file_info->d_type==IS_FOLDER){ + while ((file_info = readdir(mydir)) != NULL) { + if (file_info->d_type == IS_FOLDER) { (*con_set_flags)(CON_COLOR_GREEN); str_type = (char*)folder_type; - }else { + } else { (*con_set_flags)(7); str_type = (char*)file_type; } - printf("%3d %20s %s\n ", file_info->d_ino ,file_info->d_name, str_type); + printf("%3d %20s %s\n ", file_info->d_ino, file_info->d_name, str_type); }; setcwd("/sys/develop"); - path=getcwd(NULL, PATH_MAX); + path = getcwd(NULL, PATH_MAX); printf("Move to the directory: %s\n", path); free(path); } diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/file_io.c b/programs/develop/ktcc/trunk/libc.obj/samples/file_io.c index 0ef178eb70..deaac41020 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/file_io.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/file_io.c @@ -1,50 +1,50 @@ +#include #include #include #include -#include #define READ_MAX 255 static char test_str1[] = "123454567890abcdefghijklmnopqrstufvwxyz"; static char test_str2[READ_MAX]; -int main(int argc, char **argv) +int main(int argc, char** argv) { - int i=0; - FILE *f; + int i = 0; + FILE* f; - //write to file - debug_printf("Write file...\n"); - f=fopen("testfile.txt","w"); + // write to file + debug_printf("Write file...\n"); + f = fopen("testfile.txt", "w"); - while(test_str1[i]!='a'){ - fputc(test_str1[i],f); - i++; - } - fclose(f); + while (test_str1[i] != 'a') { + fputc(test_str1[i], f); + i++; + } + fclose(f); - //append to file - debug_printf("Apend file...\n"); - f=fopen("testfile.txt","a"); - fputs(test_str1+i,f); - char null_term = '\0'; - fwrite(&null_term, sizeof(char), 1, f); - printf("Error: %s\n",strerror(errno)); - fclose(f); + // append to file + debug_printf("Apend file...\n"); + f = fopen("testfile.txt", "a"); + fputs(test_str1 + i, f); + char null_term = '\0'; + fwrite(&null_term, sizeof(char), 1, f); + printf("Error: %s\n", strerror(errno)); + fclose(f); - //copy from testfile.txt to copyfile.txt - debug_printf("Read file...\n"); - f=fopen("testfile.txt","r"); - i=0; - while((test_str2[i]=fgetc(f))!=EOF && i -#include #include #include +#include -int main() { - char *host = "kolibrios.org"; +int main() +{ + char* host = "kolibrios.org"; int port = 80; printf("Connecting to %s on port %d\n", host, port); - struct addrinfo *addr_info; - char port_str[16]; sprintf(port_str, "%d", port); + struct addrinfo* addr_info; + char port_str[16]; + sprintf(port_str, "%d", port); struct addrinfo hints; memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_UNSPEC; // IPv4 or IPv6 doesnt matter + hints.ai_family = AF_UNSPEC; // IPv4 or IPv6 doesnt matter hints.ai_socktype = SOCK_STREAM; // TCP stream sockets if (getaddrinfo(host, port_str, 0, &addr_info) != 0) { printf("Host %s not found!\n", host); freeaddrinfo(addr_info); exit(-1); } - printf("IP address of %s is %s\n", host, inet_ntoa(addr_info->ai_addr->sin_addr)); - //printf("Host port = %d\n", addr_info->ai_addr->sin_port >> 8); + printf("IP address of %s is %s\n", host, inet_ntoa(addr_info->ai_addr->sin_addr)); + // printf("Host port = %d\n", addr_info->ai_addr->sin_port >> 8); char request[256]; sprintf(request, "GET /en/ HTTP/1.1\r\nHost: %s\r\n\r\n", host); @@ -29,22 +31,22 @@ int main() { puts("Connecting...\n"); if (connect(sock, addr_info->ai_addr, addr_info->ai_addrlen) != 0) { - printf("Connection failed, errno = %d\n", errno); - exit(errno); + printf("Connection failed, errno = %d\n", errno); + exit(errno); } puts("Connected successfully\n"); puts("Sending request...\n"); if (send(sock, request, strlen(request), MSG_NOFLAG) == -1) { - printf("Sending failed, errno = %d\n", errno); - exit(errno); + printf("Sending failed, errno = %d\n", errno); + exit(errno); } puts("Request sended successfully, waiting for response...\n"); char buf[512 + 1]; if (recv(sock, buf, 512, MSG_NOFLAG) == -1) { - printf("Receive failed, errno = %d\n", errno); - exit(errno); + printf("Receive failed, errno = %d\n", errno); + exit(errno); } printf("Response = %s\n", buf); diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/libc_test.c b/programs/develop/ktcc/trunk/libc.obj/samples/libc_test.c index f69b12a885..090305f19a 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/libc_test.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/libc_test.c @@ -1,15 +1,17 @@ -#include #include #include #include #include +#include #include -int comp(void *a, void *b) { +int comp(void* a, void* b) +{ return *(int*)a - *(int*)b; } -int main(){ +int main() +{ puts("Start testing."); assert(NULL == ((void*)0)); assert(RAND_MAX == 65535); @@ -45,11 +47,11 @@ int main(){ assert(output3.quot == 6); assert(output3.rem == 3); - char *st2 = malloc(sizeof(char)*2); + char* st2 = malloc(sizeof(char) * 2); assert(st2 != NULL); st2[0] = 'H'; st2[1] = 'i'; - st2 = realloc(st2, sizeof(char)*3); + st2 = realloc(st2, sizeof(char) * 3); st2[2] = '!'; assert(!strcmp(st2, "Hi!")); free(st2); @@ -61,8 +63,8 @@ int main(){ assert(!strcmp(st2, "Hi")); free(st2); - char *start = "100.00 Rub"; - char *end; + char* start = "100.00 Rub"; + char* end; assert(strtol(start, &end, 10) == 100L); assert(!strcmp(end, ".00 Rub")); @@ -70,17 +72,17 @@ int main(){ assert(strtod(start, &end) == 100.0); assert(!strcmp(end, " Rub")); - char *st3 = "21.3e3Hello World!"; + char* st3 = "21.3e3Hello World!"; assert(atof(st3) == 21300.0); - int nums[10] = {5, 3, 9, 1, 8, 4, 2, 0, 7, 6}; - qsort(nums, 10, sizeof(int), (int(*) (const void *, const void *))comp); - for (int i = 0; i < 10; i++) { + int nums[10] = { 5, 3, 9, 1, 8, 4, 2, 0, 7, 6 }; + qsort(nums, 10, sizeof(int), (int (*)(const void*, const void*))comp); + for (int i = 0; i < 10; i++) { assert(nums[i] == i); } - + time_t libc_time = time(NULL); - struct tm *libc_tm = localtime(&libc_time); + struct tm* libc_tm = localtime(&libc_time); printf(asctime(libc_tm)); puts("End testing."); diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/math_test.c b/programs/develop/ktcc/trunk/libc.obj/samples/math_test.c index 29bf738270..4dbdc9b893 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/math_test.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/math_test.c @@ -1,43 +1,41 @@ -#include #include +#include int main() -{ - int i; - for (i = 0; i < 20; i++) - { - printf("------------------------------------------------------\n"); -// printf ( "remainder of 5.3 / 2 is %f\n", remainder (5.3,2) ); - // printf ( "remainder of 18.5 / 4.2 is %f\n", remainder (18.5,4.2) ); -//remainder of 5.3 / 2 is -0.700000 -//remainder of 18.5 / 4.2 is 1.700000 +{ + int i; + for (i = 0; i < 20; i++) { + printf("------------------------------------------------------\n"); + // printf ( "remainder of 5.3 / 2 is %f\n", remainder (5.3,2) ); + // printf ( "remainder of 18.5 / 4.2 is %f\n", remainder (18.5,4.2) ); + // remainder of 5.3 / 2 is -0.700000 + // remainder of 18.5 / 4.2 is 1.700000 - printf ( "fmod of 5.3 / 2 is %f\n", fmod (5.3,2) ); - printf ( "fmod of 18.5 / 4.2 is %f\n", fmod (18.5,4.2) ); -// fmod of 5.3 / 2 is 1.300000 -// fmod of 18.5 / 4.2 is 1.700000 + printf("fmod of 5.3 / 2 is %f\n", fmod(5.3, 2)); + printf("fmod of 18.5 / 4.2 is %f\n", fmod(18.5, 4.2)); + // fmod of 5.3 / 2 is 1.300000 + // fmod of 18.5 / 4.2 is 1.700000 - double param, fractpart, intpart, result; - int n; + double param, fractpart, intpart, result; + int n; - param = 3.14159265; - fractpart = modf (param , &intpart); - printf ("%f = %f + %f \n", param, intpart, fractpart); -//3.141593 = 3.000000 + 0.141593 + param = 3.14159265; + fractpart = modf(param, &intpart); + printf("%f = %f + %f \n", param, intpart, fractpart); + // 3.141593 = 3.000000 + 0.141593 - param = 0.95; - n = 4; - result = ldexp (param , n); - printf ("%f * 2^%d = %f\n", param, n, result); -//0.950000 * 2^4 = 15.200000 + param = 0.95; + n = 4; + result = ldexp(param, n); + printf("%f * 2^%d = %f\n", param, n, result); + // 0.950000 * 2^4 = 15.200000 - param = 8.0; - result = frexp (param , &n); - printf ("%f = %f * 2^%d\n", param, result, n); -//8.000000 = 0.500000 * 2^4 - param = 50; - result = frexp (param , &n); - printf ("%f = %f * 2^%d\n", param, result, n); - - } + param = 8.0; + result = frexp(param, &n); + printf("%f = %f * 2^%d\n", param, result, n); + // 8.000000 = 0.500000 * 2^4 + param = 50; + result = frexp(param, &n); + printf("%f = %f * 2^%d\n", param, result, n); + } } diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/pipe.c b/programs/develop/ktcc/trunk/libc.obj/samples/pipe.c index 705ea2ce68..36da4e0971 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/pipe.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/pipe.c @@ -1,22 +1,23 @@ /* - * This is an example program for sending a message through a "pipe". + * This is an example program for sending a message through a "pipe". * Created by turbocat (Maxim Logaev) 2022. -*/ + */ -#include +#include #include #include -#include #include +#include #define TH_STACK_SIZE 1024 -#define MESSAGE_SIZE 12 +#define MESSAGE_SIZE 12 ksys_colors_table_t sys_colors; int pipefd[2]; -char *send_message = "HELLO PIPE!"; +char* send_message = "HELLO PIPE!"; -void tmain() { +void tmain() +{ char recv_message[MESSAGE_SIZE]; _ksys_posix_read(pipefd[0], recv_message, MESSAGE_SIZE); printf("RECV: %s\n", recv_message); @@ -25,14 +26,15 @@ void tmain() { exit(0); } -void create_thread(void){ - unsigned tid; // New thread ID - void *th_stack = malloc(TH_STACK_SIZE); // Allocate memory for thread stack +void create_thread(void) +{ + unsigned tid; // New thread ID + void* th_stack = malloc(TH_STACK_SIZE); // Allocate memory for thread stack if (!th_stack) { puts("Memory allocation error for thread!"); return; } - tid = _ksys_create_thread(tmain, th_stack+TH_STACK_SIZE); // Create new thread with entry "main" + tid = _ksys_create_thread(tmain, th_stack + TH_STACK_SIZE); // Create new thread with entry "main" if (tid == -1) { puts("Unable to create a new thread!"); return; @@ -40,7 +42,8 @@ void create_thread(void){ printf("New thread created (TID=%u)\n", tid); } -void main() { +void main() +{ if (_ksys_posix_pipe2(pipefd, 0)) { puts("Pipe creation error!"); return; diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/sdltest.c b/programs/develop/ktcc/trunk/libc.obj/samples/sdltest.c index c66e601a7c..2a8c1b746a 100755 --- a/programs/develop/ktcc/trunk/libc.obj/samples/sdltest.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/sdltest.c @@ -5,75 +5,69 @@ #define HEIGHT 480 #define BPP 4 #define DEPTH 32 - -void setpixel(SDL_Surface *screen, int x, int y, Uint8 r, Uint8 g, Uint8 b) + +void setpixel(SDL_Surface* screen, int x, int y, Uint8 r, Uint8 g, Uint8 b) { - Uint32 *pixmem32; - Uint32 colour; - - colour = SDL_MapRGB( screen->format, r, g, b ); - - pixmem32 = (Uint32*) screen->pixels + y + x; + Uint32* pixmem32; + Uint32 colour; + + colour = SDL_MapRGB(screen->format, r, g, b); + + pixmem32 = (Uint32*)screen->pixels + y + x; *pixmem32 = colour; } - - + void DrawScreen(SDL_Surface* screen, int h) { int x, y, ytimesw; - - if(SDL_MUSTLOCK(screen)) - { - if(SDL_LockSurface(screen) < 0) return; + + if (SDL_MUSTLOCK(screen)) { + if (SDL_LockSurface(screen) < 0) + return; } - - for(y = 0; y < screen->h; y++ ) - { - ytimesw = y*screen->pitch/BPP; - for( x = 0; x < screen->w; x++ ) - { - setpixel(screen, x, ytimesw, (x*x)/256+3*y+h, (y*y)/256+x+h, h); + + for (y = 0; y < screen->h; y++) { + ytimesw = y * screen->pitch / BPP; + for (x = 0; x < screen->w; x++) { + setpixel(screen, x, ytimesw, (x * x) / 256 + 3 * y + h, (y * y) / 256 + x + h, h); } } - if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen); - + if (SDL_MUSTLOCK(screen)) + SDL_UnlockSurface(screen); + SDL_Flip(screen); } - - + int main(int argc, char* argv[]) { - SDL_Surface *screen; + SDL_Surface* screen; SDL_Event event; - + int keypress = 0; - int h=0; - - if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1; - - if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_FULLSCREEN|SDL_HWSURFACE))) - { + int h = 0; + + if (SDL_Init(SDL_INIT_VIDEO) < 0) + return 1; + + if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_FULLSCREEN | SDL_HWSURFACE))) { SDL_Quit(); return 1; } - - while(!keypress) - { - DrawScreen(screen,h++); - while(SDL_PollEvent(&event)) - { - switch (event.type) - { - case SDL_QUIT: - keypress = 1; - break; - case SDL_KEYDOWN: - keypress = 1; - break; - } - } + + while (!keypress) { + DrawScreen(screen, h++); + while (SDL_PollEvent(&event)) { + switch (event.type) { + case SDL_QUIT: + keypress = 1; + break; + case SDL_KEYDOWN: + keypress = 1; + break; + } + } } - + SDL_Quit(); return 0; } diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/shell_test.c b/programs/develop/ktcc/trunk/libc.obj/samples/shell_test.c index c56a5869ba..84bc4caaca 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/shell_test.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/shell_test.c @@ -1,17 +1,18 @@ - #include "../include/shell_api.h" +#include "../include/shell_api.h" char string[256]; -int main(){ +int main() +{ shell_cls(); shell_printf("SHELL PID=%d\n\r", shell_get_pid()); - + shell_puts("This is a test console application for Shell\n\r"); shell_puts("Type a string (255 symbols max): "); shell_gets(string, 255); shell_printf("You typed: %s\n\r", string); - + shell_puts("Press any key: "); string[0] = shell_getc(); shell_printf("\n\rYou pressed: %c", string[0]); diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/stdio_test.c b/programs/develop/ktcc/trunk/libc.obj/samples/stdio_test.c index 1450232b76..b059f48ae9 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/stdio_test.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/stdio_test.c @@ -1,12 +1,13 @@ -#include -#include #include +#include +#include char* test_string1 = "Hello world!"; int a, b; -int main(int argc, char** argv){ - sscanf("43 53","%d %d",&a, &b); +int main(int argc, char** argv) +{ + sscanf("43 53", "%d %d", &a, &b); printf("(43 53) = (%d %d)\n", a, b); printf("Hello world! = %s\n", test_string1); printf("345.358980 = %f\n", 345.35898); diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/string_test.c b/programs/develop/ktcc/trunk/libc.obj/samples/string_test.c index c4b03cacfa..33cca8f18d 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/string_test.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/string_test.c @@ -1,17 +1,18 @@ +#include #include -#include #include #include -#include +#include -int main(int argc, char** argv){ - char hello1[]="Hello, KolibriOS!"; +int main(int argc, char** argv) +{ + char hello1[] = "Hello, KolibriOS!"; char hello2[20]; memcpy(hello1, hello2, strlen(hello1)); - if(!__strcmp(hello1, hello2)){ + if (!__strcmp(hello1, hello2)) { printf("memcpy: Successfully!\n"); return 0; - } else{ + } else { printf("memcpy: Failure\n"); return -1; } diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/thread_work.c b/programs/develop/ktcc/trunk/libc.obj/samples/thread_work.c index 12d962f355..48ce87d323 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/thread_work.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/thread_work.c @@ -1,18 +1,18 @@ /* - * An example of using threads to create a copy of a window. + * An example of using threads to create a copy of a window. * Built on top of the /programs/develop/examples/thread/trunk/thread.asm example. - * + * * Created by turbocat (Maxim Logaev) 2021. -*/ + */ -#include #include #include +#include #define TH_STACK_SIZE 1024 -enum BUTTONS{ - BTN_QUIT = 1, +enum BUTTONS { + BTN_QUIT = 1, BTN_CREATE_TH = 2, }; @@ -20,43 +20,46 @@ ksys_colors_table_t sys_colors; extern int main(); -void redraw_window(void){ - ksys_pos_t mouse_pos = _ksys_get_mouse_pos(KSYS_MOUSE_SCREEN_POS); +void redraw_window(void) +{ + ksys_pos_t mouse_pos = _ksys_get_mouse_pos(KSYS_MOUSE_SCREEN_POS); _ksys_start_draw(); _ksys_create_window(mouse_pos.x, mouse_pos.y, 140, 60, "Threads", sys_colors.work_area, 0x14); - _ksys_define_button(10, 30, 120, 20, BTN_CREATE_TH, sys_colors.work_button); + _ksys_define_button(10, 30, 120, 20, BTN_CREATE_TH, sys_colors.work_button); _ksys_draw_text("Create thread!", 15, 34, 0, 0x90000000 | sys_colors.work_button_text); _ksys_end_draw(); } -void create_thread(void){ - unsigned tid; // New thread ID - void *th_stack = malloc(TH_STACK_SIZE); // Allocate memory for thread stack - if(!th_stack){ - _ksys_debug_puts("Memory allocation error for thread!"); - return; +void create_thread(void) +{ + unsigned tid; // New thread ID + void* th_stack = malloc(TH_STACK_SIZE); // Allocate memory for thread stack + if (!th_stack) { + _ksys_debug_puts("Memory allocation error for thread!"); + return; } - tid = _ksys_create_thread(main, th_stack+TH_STACK_SIZE); // Create new thread with entry "main" - if(tid==-1){ + tid = _ksys_create_thread(main, th_stack + TH_STACK_SIZE); // Create new thread with entry "main" + if (tid == -1) { _ksys_debug_puts("Unable to create a new thread!"); return; } debug_printf("New thread created (TID=%u)\n", tid); } -int main(){ +int main() +{ _ksys_get_system_colors(&sys_colors); int gui_event; redraw_window(); - - while(1){ - gui_event = _ksys_get_event(); - switch(gui_event){ + + while (1) { + gui_event = _ksys_get_event(); + switch (gui_event) { case KSYS_EVENT_REDRAW: redraw_window(); break; case KSYS_EVENT_BUTTON: - switch (_ksys_get_button()){ + switch (_ksys_get_button()) { case BTN_CREATE_TH: create_thread(); break; @@ -64,6 +67,6 @@ int main(){ _ksys_exit(); } break; - } - } + } + } } diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/tmpdisk_work.c b/programs/develop/ktcc/trunk/libc.obj/samples/tmpdisk_work.c index f57fa909de..831df63d7b 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/tmpdisk_work.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/tmpdisk_work.c @@ -1,42 +1,43 @@ #include "stddef.h" -#include #include #include +#include #define DEV_ADD_DISK 1 -#define TMPDISK_SIZE 10 //Mb +#define TMPDISK_SIZE 10 // Mb #pragma pack(push, 1) -struct{ - unsigned disk_size; - unsigned char disk_id; -}tmpdisk_add; +struct { + unsigned disk_size; + unsigned char disk_id; +} tmpdisk_add; #pragma pack(pop) -char *tmpdisk_res_text[]={ - "TmpDisk operation completed successfully", - "Unknown IOCTL code, wrong input/output size...", - "DiskId must be from 0 to 9", - "DiskSize is too large", - "DiskSize is too small, might be too little free RAM", - "Memory allocation failed", - "Unknown error O_o", - 0}; +char* tmpdisk_res_text[] = { + "TmpDisk operation completed successfully", + "Unknown IOCTL code, wrong input/output size...", + "DiskId must be from 0 to 9", + "DiskSize is too large", + "DiskSize is too small, might be too little free RAM", + "Memory allocation failed", + "Unknown error O_o", + 0 +}; - -int main(){ +int main() +{ ksys_drv_hand_t tmpdisk_drv = _ksys_load_driver("tmpdisk"); - if(!tmpdisk_drv){ + if (!tmpdisk_drv) { puts("tmpdisk.sys driver not load!"); exit(0); - }else{ + } else { puts("tmpdisk.sys driver is load!"); } - - tmpdisk_add.disk_size = TMPDISK_SIZE*1024*1024/512; + + tmpdisk_add.disk_size = TMPDISK_SIZE * 1024 * 1024 / 512; tmpdisk_add.disk_id = 5; - + ksys_ioctl_t ioctl; ioctl.func_num = DEV_ADD_DISK; ioctl.handler = tmpdisk_drv; @@ -46,10 +47,10 @@ int main(){ ioctl.out_data_size = 0; printf("Create '/tmp%u/' disk a %u Mb size...\n", tmpdisk_add.disk_id, TMPDISK_SIZE); - unsigned status =_ksys_driver_control(&ioctl); - if(status<7){ + unsigned status = _ksys_driver_control(&ioctl); + if (status < 7) { puts(tmpdisk_res_text[status]); - }else{ + } else { puts(tmpdisk_res_text[6]); } exit(0); diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/whois.c b/programs/develop/ktcc/trunk/libc.obj/samples/whois.c index fcbb51b96e..88efc8f6f8 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/whois.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/whois.c @@ -4,19 +4,19 @@ The main code is taken from the site: https://www.binarytides.com/whois-client-code-in-c-with-linux-sockets/ */ -#include #include "sys/ksys.h" -#include -#include -#include -#include #include #include +#include +#include +#include +#include +#include -FILE *out=stdout; +FILE* out = stdout; #ifdef DEBUG -FILE *out=stderr; +FILE* out = stderr; #endif #define EXIT_SUCCESS 0 @@ -26,273 +26,273 @@ FILE *out=stderr; void show_help() { - puts("Usage: whois [-f ]\n"); - puts(" host Connect to server host"); - puts(" -f file Redirecting output to file\n"); - puts("Example: whois google.com -f my.txt"); + puts("Usage: whois [-f ]\n"); + puts(" host Connect to server host"); + puts(" -f file Redirecting output to file\n"); + puts("Example: whois google.com -f my.txt"); } -int get_whois_data(char * , char **); -int hostname_to_ip(char * , char *); -int whois_query(char * , char * , char **); -char *str_replace(char *search , char *replace , char *subject ); +int get_whois_data(char*, char**); +int hostname_to_ip(char*, char*); +int whois_query(char*, char*, char**); +char* str_replace(char* search, char* replace, char* subject); char* str_copy(char*); - -int main(int argc , char *argv[]) +int main(int argc, char* argv[]) { - char *domain , *data = NULL; - int f_flag=0; + char *domain, *data = NULL; + int f_flag = 0; - if(argc==2){ - domain=strdup(argv[1]); - } + if (argc == 2) { + domain = strdup(argv[1]); + } - else if(!strcmp(argv[2], "-f") && argc==4){ - domain=strdup(argv[1]); - if((out=fopen(argv[3],"w"))==NULL){ - printf("Error writing to file: '%s' !\n", argv[3]); - exit(0); - } - }else{ - show_help(); - exit(0); - } - if(out==stdout){ - con_init(); - (*con_set_title)("Whois"); - } - get_whois_data(domain , &data); - exit(0); + else if (!strcmp(argv[2], "-f") && argc == 4) { + domain = strdup(argv[1]); + if ((out = fopen(argv[3], "w")) == NULL) { + printf("Error writing to file: '%s' !\n", argv[3]); + exit(0); + } + } else { + show_help(); + exit(0); + } + if (out == stdout) { + con_init(); + (*con_set_title)("Whois"); + } + get_whois_data(domain, &data); + exit(0); } /* Get the whois data of a domain */ -int get_whois_data(char *domain , char **data) +int get_whois_data(char* domain, char** data) { - char ext[1024] , *pch , *response = NULL , *response_2 = NULL , *wch , *dt; + char ext[1024], *pch, *response = NULL, *response_2 = NULL, *wch, *dt; - //remove "http://" and "www." - domain = str_replace("http://" , "" , domain); - domain = str_replace("www." , "" , domain); + // remove "http://" and "www." + domain = str_replace("http://", "", domain); + domain = str_replace("www.", "", domain); - //get the extension , com , org , edu - dt = strdup(domain); + // get the extension , com , org , edu + dt = strdup(domain); - if(dt == NULL){ - fprintf(out, "strdup failed"); - } - pch = (char*)strtok(dt , "."); - while(pch != NULL){ - strcpy(ext , pch); - pch = strtok(NULL , "."); - } - // This will tell the whois server for the particular TLD like com , org - if( whois_query("whois.iana.org" , ext , &response) == EXIT_FAILURE){ - fprintf(out, "Whois query failed"); + if (dt == NULL) { + fprintf(out, "strdup failed"); + } + pch = (char*)strtok(dt, "."); + while (pch != NULL) { + strcpy(ext, pch); + pch = strtok(NULL, "."); + } + // This will tell the whois server for the particular TLD like com , org + if (whois_query("whois.iana.org", ext, &response) == EXIT_FAILURE) { + fprintf(out, "Whois query failed"); return 1; - } - fprintf(out, "\n\nResponse is:\n\n"); - fprintf(out, "%s", response); + } + fprintf(out, "\n\nResponse is:\n\n"); + fprintf(out, "%s", response); - // Now analysze the response - pch = strtok(response , "\n"); - while(pch != NULL){ - // Check if whois line - wch = strstr(pch , "whois."); - if(wch != NULL){ - break; - } - - // Next line please - pch = strtok(NULL , "\n"); - } - // Now we have the TLD whois server in wch , query again - //This will provide minimal whois information along with the parent whois server of the specific domain :) - wch = strdup(wch); - free(response); - //This should not be necessary , but segmentation fault without this , why ? - response = NULL; - if(wch != NULL){ - fprintf(out,"\nTLD Whois server is : %s" , wch); - if( whois_query(wch , domain , &response) == EXIT_FAILURE){ - fprintf(out, "Whois query failed\n"); - return EXIT_FAILURE; - } - }else{ - fprintf(out, "\nTLD whois server for %s not found\n" , ext); - return EXIT_SUCCESS; - } - - response_2 = strdup(response); - - // Again search for a whois server in this response. :) - pch = strtok(response , "\n"); - while(pch != NULL){ - // Check if whois line - wch = strstr(pch , "whois."); - if(wch != NULL){ - break; - } - //Next line please - pch = strtok(NULL , "\n"); - } - - /* - If a registrar whois server is found then query it - */ - if(wch){ - // Now we have the registrar whois server , this has the direct full information of the particular domain - // so lets query again - - fprintf(out, "\nRegistrar Whois server is : %s" , wch); - - if( whois_query(wch , domain , &response) == EXIT_FAILURE ){ - fprintf(out, "Whois query failed"); - }else{ - fprintf(out, "\n%s" , response); + // Now analysze the response + pch = strtok(response, "\n"); + while (pch != NULL) { + // Check if whois line + wch = strstr(pch, "whois."); + if (wch != NULL) { + break; } - } - /* - otherwise echo the output from the previous whois result - */ - else{ - fprintf(out, "%s" , response_2); - } - return 0; + + // Next line please + pch = strtok(NULL, "\n"); + } + // Now we have the TLD whois server in wch , query again + // This will provide minimal whois information along with the parent whois server of the specific domain :) + wch = strdup(wch); + free(response); + // This should not be necessary , but segmentation fault without this , why ? + response = NULL; + if (wch != NULL) { + fprintf(out, "\nTLD Whois server is : %s", wch); + if (whois_query(wch, domain, &response) == EXIT_FAILURE) { + fprintf(out, "Whois query failed\n"); + return EXIT_FAILURE; + } + } else { + fprintf(out, "\nTLD whois server for %s not found\n", ext); + return EXIT_SUCCESS; + } + + response_2 = strdup(response); + + // Again search for a whois server in this response. :) + pch = strtok(response, "\n"); + while (pch != NULL) { + // Check if whois line + wch = strstr(pch, "whois."); + if (wch != NULL) { + break; + } + // Next line please + pch = strtok(NULL, "\n"); + } + + /* + If a registrar whois server is found then query it +*/ + if (wch) { + // Now we have the registrar whois server , this has the direct full information of the particular domain + // so lets query again + + fprintf(out, "\nRegistrar Whois server is : %s", wch); + + if (whois_query(wch, domain, &response) == EXIT_FAILURE) { + fprintf(out, "Whois query failed"); + } else { + fprintf(out, "\n%s", response); + } + } + /* + otherwise echo the output from the previous whois result +*/ + else { + fprintf(out, "%s", response_2); + } + return 0; } /* Perform a whois query to a server and record the response */ -int whois_query(char *server , char *query , char **response) +int whois_query(char* server, char* query, char** response) { - char ip[32] , message[100] , buffer[1500]; - int sock , read_size , total_size = 0; - int WHOIS_PORT = 43; + char ip[32], message[100], buffer[1500]; + int sock, read_size, total_size = 0; + int WHOIS_PORT = 43; struct sockaddr dest; - - sock = socket(AF_INET4 , SOCK_STREAM , IPPROTO_TCP); - - //Prepare connection structures :) - memset(&dest , 0 , sizeof(dest) ); - dest.sin_family = AF_INET; + + sock = socket(AF_INET4, SOCK_STREAM, IPPROTO_TCP); + + // Prepare connection structures :) + memset(&dest, 0, sizeof(dest)); + dest.sin_family = AF_INET; server = str_copy(server); - + server[strcspn(server, "\r\n")] = '\0'; - fprintf(out, "\nResolving: %s ...\n" , server); - if(hostname_to_ip(server , ip) == EXIT_FAILURE ){ + fprintf(out, "\nResolving: %s ...\n", server); + if (hostname_to_ip(server, ip) == EXIT_FAILURE) { fprintf(out, "Failed\n"); return EXIT_FAILURE; - } - - fprintf(out, "Found ip: %s \n" , ip); + } + + fprintf(out, "Found ip: %s \n", ip); dest.sin_addr = inet_addr(ip); - dest.sin_port = PORT(WHOIS_PORT); + dest.sin_port = PORT(WHOIS_PORT); -; //Now connect to remote server - if(connect(sock , (const struct sockaddr*) &dest , sizeof(dest)) < 0){ - perror("connect failed"); - perror(strerror(errno)); + ; // Now connect to remote server + if (connect(sock, (const struct sockaddr*)&dest, sizeof(dest)) < 0) { + perror("connect failed"); + perror(strerror(errno)); return EXIT_FAILURE; - } + } - //Now send some data or message - fprintf(out, "\nQuerying for: %s ...\n" , query); - sprintf(message , "%s\r\n" , query); - if( send(sock , message , strlen(message) , 0) < 0){ - perror("send failed"); + // Now send some data or message + fprintf(out, "\nQuerying for: %s ...\n", query); + sprintf(message, "%s\r\n", query); + if (send(sock, message, strlen(message), 0) < 0) { + perror("send failed"); return EXIT_FAILURE; - } - - //Now receive the response - while((read_size = recv(sock, buffer, sizeof(buffer), 0))){ - *response = realloc(*response , read_size + total_size); - if(*response == NULL){ - fprintf(out, "realloc failed"); + } + + // Now receive the response + while ((read_size = recv(sock, buffer, sizeof(buffer), 0))) { + *response = realloc(*response, read_size + total_size); + if (*response == NULL) { + fprintf(out, "realloc failed"); return EXIT_FAILURE; - } - memcpy(*response + total_size , buffer , read_size); - total_size += read_size; - } - - fprintf(out, "Done\n"); - - *response = realloc(*response , total_size + 1); - *(*response + total_size) = '\0'; - close(sock); + } + memcpy(*response + total_size, buffer, read_size); + total_size += read_size; + } + + fprintf(out, "Done\n"); + + *response = realloc(*response, total_size + 1); + *(*response + total_size) = '\0'; + close(sock); return EXIT_SUCCESS; } /* Get the ip address of a given hostname */ -int hostname_to_ip(char *hostname , char *ip) +int hostname_to_ip(char* hostname, char* ip) { - struct addrinfo *addr_info; - char port_str[16]; sprintf(port_str, "%d", 80); + struct addrinfo* addr_info; + char port_str[16]; + sprintf(port_str, "%d", 80); struct addrinfo hints; memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_UNSPEC; // IPv4 or IPv6 doesnt matter + hints.ai_family = AF_UNSPEC; // IPv4 or IPv6 doesnt matter hints.ai_socktype = SOCK_STREAM; // TCP stream sockets if (getaddrinfo(hostname, port_str, 0, &addr_info) != 0) { freeaddrinfo(addr_info); - return EXIT_FAILURE; - }else{ - strcpy(ip, inet_ntoa(addr_info->ai_addr->sin_addr)); - return EXIT_SUCCESS; - } + return EXIT_FAILURE; + } else { + strcpy(ip, inet_ntoa(addr_info->ai_addr->sin_addr)); + return EXIT_SUCCESS; + } } /* Search and replace a string with another string , in a string */ -char *str_replace(char *search , char *replace , char *subject) +char* str_replace(char* search, char* replace, char* subject) { - char *p = NULL , *old = NULL , *new_subject = NULL ; - int c = 0 , search_size; - - search_size = strlen(search); - - //Count how many occurences - for(p = strstr(subject , search) ; p != NULL ; p = strstr(p + search_size , search)){ - c++; - } - //Final size - c = ( strlen(replace) - search_size )*c + strlen(subject); - - //New subject with new size - new_subject = malloc( c ); - - //Set it to blank - strcpy(new_subject , ""); - - //The start position - old = subject; - - for(p = strstr(subject , search) ; p != NULL ; p = strstr(p + search_size , search)){ - //move ahead and copy some text from original subject , from a certain position - strncpy(new_subject + strlen(new_subject) , old , p - old); - - //move ahead and copy the replacement text - strcpy(new_subject + strlen(new_subject) , replace); - - //The new start position after this search match - old = p + search_size; - } - - //Copy the part after the last search match - strcpy(new_subject + strlen(new_subject) , old); - - return new_subject; + char *p = NULL, *old = NULL, *new_subject = NULL; + int c = 0, search_size; + + search_size = strlen(search); + + // Count how many occurences + for (p = strstr(subject, search); p != NULL; p = strstr(p + search_size, search)) { + c++; + } + // Final size + c = (strlen(replace) - search_size) * c + strlen(subject); + + // New subject with new size + new_subject = malloc(c); + + // Set it to blank + strcpy(new_subject, ""); + + // The start position + old = subject; + + for (p = strstr(subject, search); p != NULL; p = strstr(p + search_size, search)) { + // move ahead and copy some text from original subject , from a certain position + strncpy(new_subject + strlen(new_subject), old, p - old); + + // move ahead and copy the replacement text + strcpy(new_subject + strlen(new_subject), replace); + + // The new start position after this search match + old = p + search_size; + } + + // Copy the part after the last search match + strcpy(new_subject + strlen(new_subject), old); + + return new_subject; } -char* str_copy(char *source) +char* str_copy(char* source) { - char *copy = malloc(strlen(source) + 1); - - if(copy){ + char* copy = malloc(strlen(source) + 1); + + if (copy) { strcpy(copy, source); } return copy; -} +}