From 0428045f250b163741caffc77b2380d396dba99f Mon Sep 17 00:00:00 2001 From: turbocat Date: Sat, 1 Jan 2022 16:37:00 +0000 Subject: [PATCH] libc.obj: Updated samples. git-svn-id: svn://kolibrios.org@9553 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../ktcc/trunk/libc.obj/samples/Makefile | 55 +++++++++---------- .../ktcc/trunk/libc.obj/samples/build_all.sh | 38 ++++++------- .../trunk/libc.obj/samples/clayer/boxlib.c | 6 +- .../trunk/libc.obj/samples/clayer/dialog.c | 1 - .../trunk/libc.obj/samples/clayer/libimg.c | 11 +--- .../ktcc/trunk/libc.obj/samples/defgen.c | 49 +++++++++++++++++ .../trunk/libc.obj/samples/http_tcp_demo.c | 4 -- .../ktcc/trunk/libc.obj/samples/string_test.c | 2 +- .../ktcc/trunk/libc.obj/samples/whois.c | 5 +- 9 files changed, 102 insertions(+), 69 deletions(-) create mode 100644 programs/develop/ktcc/trunk/libc.obj/samples/defgen.c diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/Makefile b/programs/develop/ktcc/trunk/libc.obj/samples/Makefile index 3bbd6bf93b..e480e37589 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/Makefile +++ b/programs/develop/ktcc/trunk/libc.obj/samples/Makefile @@ -1,41 +1,40 @@ -KTCC=kos32-tcc +KTCC=../../bin/kos32-tcc FASM= fasm KPACK = kpack + CFLAGS = -I../include -I../../../../../../contrib/sdk/sources/SDL-1.2.2_newlib/include -LDFLAGS = -nostdlib -L../../bin/lib ../../bin/lib/crt0.o - -BIN= stdio_test.kex \ -basic_gui.kex \ -http_tcp_demo.kex \ -math_test.kex \ -string_test.kex \ -whois.kex \ -file_io.kex \ -tmpdisk_work.kex \ -consoleio.kex \ -assert_test.kex \ -fasm/sprintf_test.kex \ -clayer/rasterworks.kex \ -clayer/libimg.kex \ -clayer/dialog.kex \ -clayer/msgbox.kex \ -clayer/boxlib.kex \ -thread_work.kex \ -sdltest.kex \ -shell_test.kex \ -libc_test.kex - -LIBS= -lSDL -lshell -ltcc -lsound -ldialog -lrasterworks -limg -lbox -lmsgbox -lnetwork -lc.obj +LIBS = -lbox_lib -lshell -lSDL -lsound -lnetwork -lrasterworks -limg -ldialog -lmsgbox +BIN = stdio_test.kex \ + basic_gui.kex \ + http_tcp_demo.kex \ + math_test.kex \ + string_test.kex \ + whois.kex \ + file_io.kex \ + tmpdisk_work.kex \ + consoleio.kex \ + assert_test.kex \ + clayer/rasterworks.kex \ + clayer/libimg.kex \ + clayer/dialog.kex \ + clayer/msgbox.kex \ + clayer/boxlib.kex \ + thread_work.kex \ + sdltest.kex \ + shell_test.kex \ + libc_test.kex \ + defgen.kex + all: $(BIN) %.kex : %.c $(KTCC) $(CFLAGS) $(LDFLAGS) $< -o $@ $(LIBS) $(KPACK) --nologo $@ - -%.kex : %.asm + +-%.kex : %.asm $(FASM) $< $@ $(KPACK) --nologo $@ - + clean: rm *.kex clayer/*.kex diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/build_all.sh b/programs/develop/ktcc/trunk/libc.obj/samples/build_all.sh index 7d6cfeda49..cddad56b51 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/build_all.sh +++ b/programs/develop/ktcc/trunk/libc.obj/samples/build_all.sh @@ -1,24 +1,24 @@ #SHS mkdir /tmp0/1/tcc_samples -../tcc file_io.c -o /tmp0/1/tcc_samples/file_io -lc.obj -../tcc whois.c -o /tmp0/1/tcc_samples/whois -ltcc -lnetwork -lc.obj -../tcc stdio_test.c -o /tmp0/1/tcc_samples/stdio_test -lc.obj -../tcc basic_gui.c -o /tmp0/1/tcc_samples/basic_gui -ltcc -lc.obj -../tcc consoleio.c -o /tmp0/1/tcc_samples/consoleio -lc.obj -../tcc dir_example.c -o /tmp0/1/tcc_samples/ls_dir -lc.obj -../tcc http_tcp_demo.c -o /tmp0/1/tcc_samples/http_tcp_demo -ltcc -lnetwork -lc.obj -../tcc math_test.c -o /tmp0/1/tcc_samples/math_test -ltcc -lc.obj -../tcc string_test.c -o /tmp0/1/tcc_samples/string_test -ltcc -lc.obj -../tcc tmpdisk_work.c -o /tmp0/1/tcc_samples/tmpdisk_work -ltcc -lc.obj -../tcc clayer/boxlib.c -o /tmp0/1/tcc_samples/boxlib -ltcc -lbox -lc.obj -../tcc clayer/dialog.c -o /tmp0/1/tcc_samples/dialog -ltcc -ldialog -lc.obj +../tcc file_io.c -o /tmp0/1/tcc_samples/file_io +../tcc whois.c -o /tmp0/1/tcc_samples/whois -lnetwork +../tcc stdio_test.c -o /tmp0/1/tcc_samples/stdio_test +../tcc basic_gui.c -o /tmp0/1/tcc_samples/basic_gui +../tcc consoleio.c -o /tmp0/1/tcc_samples/consoleio +../tcc dir_example.c -o /tmp0/1/tcc_samples/ls_dir +../tcc http_tcp_demo.c -o /tmp0/1/tcc_samples/http_tcp_demo -lnetwork +../tcc math_test.c -o /tmp0/1/tcc_samples/math_test +../tcc string_test.c -o /tmp0/1/tcc_samples/string_test +../tcc tmpdisk_work.c -o /tmp0/1/tcc_samples/tmpdisk_work +../tcc clayer/boxlib.c -o /tmp0/1/tcc_samples/boxlib -lbox_lib +../tcc clayer/dialog.c -o /tmp0/1/tcc_samples/dialog -ldialog cp clayer/logo.png /tmp0/1/tcc_samples/logo.png -../tcc clayer/libimg.c -o /tmp0/1/tcc_samples/libimg -ltcc -limg -lc.obj -../tcc clayer/msgbox.c -o /tmp0/1/tcc_samples/msgbox -ltcc -lmsgbox -lc.obj -../tcc clayer/rasterworks.c -o /tmp0/1/tcc_samples/rasterworks -ltcc -lrasterworks -lc.obj -../tcc thread_work.c -o /tmp0/1/tcc_samples/thread_work -ltcc -lc.obj -../tcc -I../include/SDL sdltest.c -o /tmp0/1/tcc_samples/sdltest -lSDL -lsound -ltcc -lc.obj -../tcc shell_test.c -o /tmp0/1/tcc_samples/shell_test -lshell -ltcc -lc.obj -../tcc libc_test.c -o /tmp0/1/tcc_samples/libc_test -ltcc -lc.obj +../tcc clayer/libimg.c -o /tmp0/1/tcc_samples/libimg -limg +../tcc clayer/msgbox.c -o /tmp0/1/tcc_samples/msgbox -lmsgbox +../tcc clayer/rasterworks.c -o /tmp0/1/tcc_samples/rasterworks -lrasterworks +../tcc thread_work.c -o /tmp0/1/tcc_samples/thread_work -ltcc -lc +../tcc -I../include/SDL sdltest.c -o /tmp0/1/tcc_samples/sdltest -lSDL -lsound +../tcc shell_test.c -o /tmp0/1/tcc_samples/shell_test -lshell +../tcc libc_test.c -o /tmp0/1/tcc_samples/libc_test "/sys/File managers/Eolite" /tmp0/1/tcc_samples exit diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/clayer/boxlib.c b/programs/develop/ktcc/trunk/libc.obj/samples/clayer/boxlib.c index 6298a96308..be81481182 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/clayer/boxlib.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/clayer/boxlib.c @@ -42,10 +42,8 @@ void draw_window(){ _ksys_end_draw(); } - int main() { - kolibri_boxlib_init(); 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){ @@ -55,7 +53,7 @@ int main() break; case KSYS_EVENT_KEY: - edit_box_key(&ed, _ksys_get_key().val); + edit_box_key_safe(&ed, _ksys_get_key()); draw_window(); break; @@ -89,4 +87,4 @@ int main() } } return 0; -} \ No newline at end of file +} diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/clayer/dialog.c b/programs/develop/ktcc/trunk/libc.obj/samples/clayer/dialog.c index 9d84bc9f67..8051ef2bc4 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/clayer/dialog.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/clayer/dialog.c @@ -4,7 +4,6 @@ int main() { - kolibri_dialog_init(); // dialog init 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 diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/clayer/libimg.c b/programs/develop/ktcc/trunk/libc.obj/samples/clayer/libimg.c index 3d09442167..e30d85e69d 100755 --- a/programs/develop/ktcc/trunk/libc.obj/samples/clayer/libimg.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/clayer/libimg.c @@ -44,18 +44,13 @@ void* load_img(char* fname, uint32_t* read_sz){ // Image file upload function 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(){ - if (kolibri_libimg_init() == -1){ - printf("Error loading lib_img.obj\n"); - exit(0); - } - - _ksys_get_system_colors(&sys_color_table); // Get system colors theme + _ksys_get_system_colors(&sys_color_table); // Get system colors theme _ksys_set_event_mask(0xC0000027); uint32_t img_size; diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/defgen.c b/programs/develop/ktcc/trunk/libc.obj/samples/defgen.c new file mode 100644 index 0000000000..61a8ccaa7e --- /dev/null +++ b/programs/develop/ktcc/trunk/libc.obj/samples/defgen.c @@ -0,0 +1,49 @@ +#include "stddef.h" +#include +#include +#include +#include +#include + +#define ARGC_VALID 3 + +enum ARGV_FILE { + IN = 1, + OUT = 2 +}; + +void show_help(void){ + puts("Usage: defgen [lib.obj] [lib.def]"); +} + +int main(int argc, char** argv){ + + if(argc!=ARGC_VALID){ + show_help(); + return 0; + } + + ksys_dll_t *obj_dll = _ksys_dlopen(argv[IN]); + FILE* outfile = fopen(argv[OUT], "w"); + + if(!obj_dll){ + printf("File '%s' not found!\n", argv[IN]); + return 1; + } + + 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); + i++; + } + fclose(outfile); + return 0; +} diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/http_tcp_demo.c b/programs/develop/ktcc/trunk/libc.obj/samples/http_tcp_demo.c index 0b79b38006..5423a69818 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/http_tcp_demo.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/http_tcp_demo.c @@ -3,11 +3,7 @@ #include #include -int errno; - int main() { - networklib_init(); - char *host = "kolibrios.org"; int port = 80; printf("Connecting to %s on port %d\n", host, port); diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/string_test.c b/programs/develop/ktcc/trunk/libc.obj/samples/string_test.c index 5bf99c36f2..c4b03cacfa 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/string_test.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/string_test.c @@ -8,7 +8,7 @@ int main(int argc, char** argv){ char hello1[]="Hello, KolibriOS!"; char hello2[20]; memcpy(hello1, hello2, strlen(hello1)); - if(!_ksys_strcmp(hello1, hello2)){ + if(!__strcmp(hello1, hello2)){ printf("memcpy: Successfully!\n"); return 0; } else{ diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/whois.c b/programs/develop/ktcc/trunk/libc.obj/samples/whois.c index 5d29a63fdb..fcbb51b96e 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/whois.c +++ b/programs/develop/ktcc/trunk/libc.obj/samples/whois.c @@ -5,8 +5,6 @@ https://www.binarytides.com/whois-client-code-in-c-with-linux-sockets/ */ #include -int errno; - #include "sys/ksys.h" #include #include @@ -42,8 +40,7 @@ char* str_copy(char*); int main(int argc , char *argv[]) -{ - networklib_init(); +{ char *domain , *data = NULL; int f_flag=0;