/programs/develop/ktcc/trunk/libc.obj/samples/assert_test.c |
---|
3,7 → 3,8 |
int a=431; |
int b=532; |
int main(){ |
int main() |
{ |
assert(a!=b); |
assert(a==b); |
} |
/programs/develop/ktcc/trunk/libc.obj/samples/basic_gui.c |
---|
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 |
ksys_thread_t proc_info; |
char text_line[255]; |
enum BUTTONS |
{ |
enum BUTTONS { |
BTN_QUIT = 1, |
BTN_POP = 10, |
BTN_UNLOCK = 11 |
30,8 → 29,10 |
// 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); |
51,7 → 52,8 |
_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(); |
69,8 → 71,7 |
do{ |
gui_event = _ksys_get_event(); |
switch(gui_event) |
{ |
switch (gui_event) { |
case KSYS_EVENT_NONE: |
break; |
case KSYS_EVENT_REDRAW: |
80,8 → 81,7 |
break; |
case KSYS_EVENT_BUTTON: |
pressed_button = _ksys_get_button(); |
switch (pressed_button) |
{ |
switch (pressed_button) { |
case BTN_POP: |
strcpy(statusbar, "POP pressed...."); |
draw_window(); |
102,7 → 102,8 |
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(); |
/programs/develop/ktcc/trunk/libc.obj/samples/clayer/boxlib.c |
---|
1,11 → 1,11 |
// BOXLIB EXAMPLE (scrollbar, progressbar, editbox and checkbox) |
// Writed by maxcodehack and superturbocat2001 |
#include <sys/ksys.h> |
#include <clayer/boxlib.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <string.h> |
#include <clayer/boxlib.h> |
#include <stdio.h> |
#include <sys/ksys.h> |
#define WIN_W 640 |
#define WIN_H 563 |
29,7 → 29,8 |
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(){ |
void draw_window() |
{ |
_ksys_start_draw(); |
_ksys_create_window(215,100,WIN_W,WIN_H,title, 0x858585, 0x34); |
edit_box_draw(&ed); |
49,7 → 50,8 |
while(1){ |
switch(_ksys_get_event()){ |
case KSYS_EVENT_BUTTON: |
if (_ksys_get_button() == 1) return 0; |
if (_ksys_get_button() == 1) |
return 0; |
break; |
case KSYS_EVENT_KEY: |
/programs/develop/ktcc/trunk/libc.obj/samples/clayer/dialog.c |
---|
1,6 → 1,6 |
#include <sys/ksys.h> |
#include <clayer/dialog.h> |
#include <stdio.h> |
#include <sys/ksys.h> |
int main() |
{ |
/programs/develop/ktcc/trunk/libc.obj/samples/clayer/libimg.c |
---|
1,9 → 1,9 |
/* 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 |
16,7 → 16,8 |
ksys_colors_table_t sys_color_table; // Create system colors table |
void* load_img(char* fname, uint32_t* read_sz){ // Image file upload function |
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); |
42,7 → 43,8 |
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 |
49,7 → 51,8 |
_ksys_end_draw(); |
} |
int main(){ |
int main() |
{ |
_ksys_get_system_colors(&sys_color_table); // Get system colors theme |
_ksys_set_event_mask(0xC0000027); |
/programs/develop/ktcc/trunk/libc.obj/samples/clayer/rasterworks.c |
---|
1,8 → 1,7 |
#include <clayer/rasterworks.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <sys/ksys.h> |
#include <clayer/rasterworks.h> |
// Sizes |
int x_size = 768, y_size = 256; |
43,7 → 42,8 |
break; |
case KSYS_EVENT_BUTTON: |
if(_ksys_get_button() == 1) exit(0); |
if (_ksys_get_button() == 1) |
exit(0); |
break; |
}; |
} |
/programs/develop/ktcc/trunk/libc.obj/samples/consoleio.c |
---|
5,8 → 5,9 |
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 |
/programs/develop/ktcc/trunk/libc.obj/samples/defgen.c |
---|
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,11 → 12,13 |
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){ |
show_help(); |
/programs/develop/ktcc/trunk/libc.obj/samples/dir_example.c |
---|
1,8 → 1,8 |
#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"; |
13,8 → 13,7 |
printf("Current directory: %s\n", path); |
if(mkdir("test")){ |
puts("Test folder created!"); |
} |
else{ |
} else { |
puts("Error creating folder!"); |
} |
/programs/develop/ktcc/trunk/libc.obj/samples/file_io.c |
---|
1,7 → 1,7 |
#include <errno.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <string.h> |
#include <errno.h> |
#define READ_MAX 255 |
/programs/develop/ktcc/trunk/libc.obj/samples/http_tcp_demo.c |
---|
1,14 → 1,16 |
#include <clayer/network.h> |
#include <string.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <string.h> |
int main() { |
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); |
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 |
/programs/develop/ktcc/trunk/libc.obj/samples/libc_test.c |
---|
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); |
/programs/develop/ktcc/trunk/libc.obj/samples/math_test.c |
---|
1,11 → 1,10 |
#include <math.h> |
#include <stdio.h> |
#include <math.h> |
int main() |
{ |
int i; |
for (i = 0; i < 20; 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) ); |
38,6 → 37,5 |
param = 50; |
result = frexp (param , &n); |
printf ("%f = %f * 2^%d\n", param, result, n); |
} |
} |
/programs/develop/ktcc/trunk/libc.obj/samples/pipe.c |
---|
3,11 → 3,11 |
* 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 |
16,7 → 16,8 |
int pipefd[2]; |
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,7 → 26,8 |
exit(0); |
} |
void create_thread(void){ |
void create_thread(void) |
{ |
unsigned tid; // New thread ID |
void *th_stack = malloc(TH_STACK_SIZE); // Allocate memory for thread stack |
if (!th_stack) { |
40,7 → 42,8 |
printf("New thread created (TID=%u)\n", tid); |
} |
void main() { |
void main() |
{ |
if (_ksys_posix_pipe2(pipefd, 0)) { |
puts("Pipe creation error!"); |
return; |
/programs/develop/ktcc/trunk/libc.obj/samples/sdltest.c |
---|
17,30 → 17,27 |
*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++ ) |
{ |
for (y = 0; y < screen->h; y++) { |
ytimesw = y*screen->pitch/BPP; |
for( x = 0; x < screen->w; x++ ) |
{ |
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; |
49,21 → 46,18 |
int keypress = 0; |
int h=0; |
if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1; |
if (SDL_Init(SDL_INIT_VIDEO) < 0) |
return 1; |
if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_FULLSCREEN|SDL_HWSURFACE))) |
{ |
if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_FULLSCREEN | SDL_HWSURFACE))) { |
SDL_Quit(); |
return 1; |
} |
while(!keypress) |
{ |
while (!keypress) { |
DrawScreen(screen,h++); |
while(SDL_PollEvent(&event)) |
{ |
switch (event.type) |
{ |
while (SDL_PollEvent(&event)) { |
switch (event.type) { |
case SDL_QUIT: |
keypress = 1; |
break; |
/programs/develop/ktcc/trunk/libc.obj/samples/shell_test.c |
---|
2,7 → 2,8 |
char string[256]; |
int main(){ |
int main() |
{ |
shell_cls(); |
shell_printf("SHELL PID=%d\n\r", shell_get_pid()); |
/programs/develop/ktcc/trunk/libc.obj/samples/stdio_test.c |
---|
1,11 → 1,12 |
#include <limits.h> |
#include <stdio.h> |
#include <sys/ksys.h> |
#include <stdio.h> |
#include <limits.h> |
char* test_string1 = "Hello world!"; |
int a, b; |
int main(int argc, char** argv){ |
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); |
/programs/develop/ktcc/trunk/libc.obj/samples/string_test.c |
---|
1,10 → 1,11 |
#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){ |
int main(int argc, char** argv) |
{ |
char hello1[]="Hello, KolibriOS!"; |
char hello2[20]; |
memcpy(hello1, hello2, strlen(hello1)); |
/programs/develop/ktcc/trunk/libc.obj/samples/thread_work.c |
---|
5,9 → 5,9 |
* 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 |
20,7 → 20,8 |
extern int main(); |
void redraw_window(void){ |
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); |
29,7 → 30,8 |
_ksys_end_draw(); |
} |
void create_thread(void){ |
void create_thread(void) |
{ |
unsigned tid; // New thread ID |
void *th_stack = malloc(TH_STACK_SIZE); // Allocate memory for thread stack |
if(!th_stack){ |
44,7 → 46,8 |
debug_printf("New thread created (TID=%u)\n", tid); |
} |
int main(){ |
int main() |
{ |
_ksys_get_system_colors(&sys_colors); |
int gui_event; |
redraw_window(); |
/programs/develop/ktcc/trunk/libc.obj/samples/tmpdisk_work.c |
---|
1,7 → 1,7 |
#include "stddef.h" |
#include <sys/ksys.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <sys/ksys.h> |
#define DEV_ADD_DISK 1 |
22,10 → 22,11 |
"DiskSize is too small, might be too little free RAM", |
"Memory allocation failed", |
"Unknown error O_o", |
0}; |
0 |
}; |
int main(){ |
int main() |
{ |
ksys_drv_hand_t tmpdisk_drv = _ksys_load_driver("tmpdisk"); |
if(!tmpdisk_drv){ |
puts("tmpdisk.sys driver not load!"); |
/programs/develop/ktcc/trunk/libc.obj/samples/whois.c |
---|
4,14 → 4,14 |
https://www.binarytides.com/whois-client-code-in-c-with-linux-sockets/ |
*/ |
#include "sys/ksys.h" |
#include <clayer/network.h> |
#include <conio.h> |
#include <errno.h> |
#include "sys/ksys.h" |
#include <stdio.h> |
#include <stdlib.h> |
#include <string.h> |
#include <stdlib.h> |
#include <sys/socket.h> |
#include <clayer/network.h> |
#include <conio.h> |
FILE *out=stdout; |
38,7 → 38,6 |
char *str_replace(char *search , char *replace , char *subject ); |
char* str_copy(char*); |
int main(int argc , char *argv[]) |
{ |
char *domain , *data = NULL; |
231,7 → 230,8 |
int hostname_to_ip(char *hostname , char *ip) |
{ |
struct addrinfo *addr_info; |
char port_str[16]; sprintf(port_str, "%d", 80); |
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 |