Update skipped files in previous commit

git-svn-id: svn://kolibrios.org@9766 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
turbocat 2022-04-15 09:11:49 +00:00
parent cde4fa851d
commit 99922e4c2c
51 changed files with 1967 additions and 2487 deletions

View File

@ -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

View File

@ -0,0 +1,6 @@
# Format Style Options - Created with Clang Power Tools
---
BasedOnStyle: WebKit
AlignTrailingComments: true
AlignConsecutiveMacros: true
...

View File

@ -4,6 +4,10 @@
#include <stddef.h>
#include <stdlib.h>
#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_
#endif // _ASSERT_H_

View File

@ -3,49 +3,49 @@
#ifndef KOLIBRI_BOXLIB_H
#define KOLIBRI_BOXLIB_H
#include <sys/ksys.h>
#include <stdint.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/ksys.h>
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 */

View File

@ -1,83 +1,83 @@
#ifndef KOLIBRI_BUF2D_H
#define KOLIBRI_BUF2D_H
#include <stddef.h>
#include <stdint.h>
#include <sys/ksys.h>
#include <stddef.h>
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 */

View File

@ -4,14 +4,14 @@
#include <stdlib.h>
#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

View File

@ -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

View File

@ -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

View File

@ -8,37 +8,37 @@
#include <stddef.h>
#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);

View File

@ -3,148 +3,58 @@
#include <stddef.h>
#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_

View File

@ -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_ */

View File

@ -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

View File

@ -6,166 +6,59 @@
#include <stddef.h>
#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_ */

View File

@ -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);

View File

@ -3,35 +3,37 @@
#include <sys/ksys.h>
#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

View File

@ -3,75 +3,14 @@
#include <stddef.h>
#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 */

View File

@ -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 */

View File

@ -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_ */

View File

@ -3,32 +3,36 @@
#include <stddef.h>
#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_*/

View File

@ -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 <stdarg.h>
#include <stddef.h>
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_

View File

@ -3,69 +3,69 @@
#include <stddef.h>
#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

View File

@ -1,34 +1,9 @@
/* String handling <string.h>
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 <stddef.h>
#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

View File

@ -3,9 +3,9 @@
#include <stddef.h>
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

View File

@ -3,32 +3,31 @@
#ifndef _DIRENT_H_
#define _DIRENT_H_
#include <stddef.h>
#include <limits.h>
#include <stddef.h>
#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_

File diff suppressed because it is too large Load Diff

View File

@ -3,89 +3,89 @@
#ifndef _SOCKET_H_
#define _SOCKET_H_
#include <errno.h>
#include <stddef.h>
#include <sys/ksys.h>
#include <errno.h>
// 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_

View File

@ -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

View File

@ -1,9 +0,0 @@
format ELF
include '__lib__.inc'
section '.text'
public lib_name
lib_name db 0x55, 0xAA, lib_name_str, 0

View File

@ -1,2 +0,0 @@
lib_name equ @libc.obj
lib_name_str equ '/sys/lib/libc.obj'

View File

@ -1,9 +1,10 @@
#include <assert.h>
#include <stdio.h>
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);
}

View File

@ -1,7 +1,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <sys/ksys.h>
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]<<Just a text>>", i);
for (i = LINES; i > 0; i--) {
snprintf(text_line, sizeof text_line, "Line[%d]<<Just a text>>", 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;
}

View File

@ -1,11 +1,11 @@
// BOXLIB EXAMPLE (scrollbar, progressbar, editbox and checkbox)
// Writed by maxcodehack and superturbocat2001
#include <sys/ksys.h>
#include <stdlib.h>
#include <string.h>
#include <clayer/boxlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ksys.h>
#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;
}

View File

@ -1,28 +1,28 @@
#include <sys/ksys.h>
#include <clayer/dialog.h>
#include <stdio.h>
#include <sys/ksys.h>
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);

View File

@ -1,23 +1,24 @@
/* Written by turbocat2001 (Logaev Maxim) */
#include <clayer/libimg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <clayer/libimg.h>
#include <sys/ksys.h>
#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;
}

View File

@ -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);
}

View File

@ -1,8 +1,7 @@
#include <stdlib.h>
#include <clayer/rasterworks.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ksys.h>
#include <clayer/rasterworks.h>
// 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;
}

View File

@ -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);
}

View File

@ -1,7 +1,7 @@
#include "stddef.h"
#include <libgen.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <libgen.h>
#include <string.h>
#include <sys/ksys.h>
@ -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;
}

View File

@ -1,45 +1,44 @@
#include <sys/dirent.h>
#include <sys/dir.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <sys/dir.h>
#include <sys/dirent.h>
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);
}

View File

@ -1,50 +1,50 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#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<READ_MAX){
fputc(test_str2[i], stdout);
i++;
}
printf("\n%s\n", test_str1);
if(!strcmp(test_str2, test_str1)){
puts("TEST: OK!");
}else{
puts("TEST: FAIL!");
}
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 < READ_MAX) {
fputc(test_str2[i], stdout);
i++;
}
printf("\n%s\n", test_str1);
if (!strcmp(test_str2, test_str1)) {
puts("TEST: OK!");
} else {
puts("TEST: FAIL!");
}
fclose(f);
}

View File

@ -1,25 +1,27 @@
#include <clayer/network.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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);

View File

@ -1,15 +1,17 @@
#include <sys/ksys.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ksys.h>
#include <time.h>
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.");

View File

@ -1,43 +1,41 @@
#include <stdio.h>
#include <math.h>
#include <stdio.h>
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);
}
}

View File

@ -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 <sys/ksys.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <sys/ksys.h>
#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;

View File

@ -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;
}

View File

@ -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]);

View File

@ -1,12 +1,13 @@
#include <sys/ksys.h>
#include <stdio.h>
#include <limits.h>
#include <stdio.h>
#include <sys/ksys.h>
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);

View File

@ -1,17 +1,18 @@
#include <ctype.h>
#include <errno.h>
#include <sys/ksys.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <sys/ksys.h>
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;
}

View File

@ -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 <sys/ksys.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ksys.h>
#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;
}
}
}
}
}

View File

@ -1,42 +1,43 @@
#include "stddef.h"
#include <sys/ksys.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ksys.h>
#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);

View File

@ -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 <errno.h>
#include "sys/ksys.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <clayer/network.h>
#include <conio.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
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 <host> [-f <file>]\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 <host> [-f <file>]\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;
}
}