From dd92e74f770eaf2a021b00a728a560f5da7df011 Mon Sep 17 00:00:00 2001 From: "Magomed Kostoev (mkostoevr)" Date: Thu, 7 May 2020 09:30:37 +0000 Subject: [PATCH] Make it buildable by both TCC and GCC. Remove extra readme.txt (all info is in fat12.c) git-svn-id: svn://kolibrios.org@7882 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/fs/unimg/fat12.c | 98 ++++++++++++++++----------------- programs/fs/unimg/make_gcc.bat | 3 - programs/fs/unimg/make_tcc.bat | 2 - programs/fs/unimg/unimg | Bin 3594 -> 3601 bytes 4 files changed, 48 insertions(+), 55 deletions(-) diff --git a/programs/fs/unimg/fat12.c b/programs/fs/unimg/fat12.c index 62c16d7575..f9b5c78cb6 100644 --- a/programs/fs/unimg/fat12.c +++ b/programs/fs/unimg/fat12.c @@ -9,18 +9,26 @@ Usage: unimg path/to/img [output/folder] [-e] Author: Magomed Kostoev (Boppan, mkostoevr): FAT12 file system, driver. Contributor: Kiril Lipatov (Leency) */ +#ifdef __TINYC__ +# define TCC 1 +#else +# define GCC 1 +#endif + #include #include #include #include #include -#define TCC 0 -#define GCC 1 -#include "compiller.h" - -#ifdef GCC -#define con_init con_init +#if TCC +# include +# define printf con_printf +# define puts con_write_asciiz +#else +# define con_init_console_dll() 0 +# define con_set_title(s) +# define con_exit(close) #endif typedef struct { @@ -68,21 +76,13 @@ static int fat12__open(Fat12 *this, const char *img); static int fat12__error(Fat12 *this, const char *errorMessage); static void mkdir(const char *name) { - #ifdef TCC struct { int fn; int unused[4]; char b; const char *path __attribute__((packed)); } info; - #else - struct { - int fn; - int unused[4]; - char b; - const char *path; - } __attribute__((packed)) info; - #endif + memset(&info, 0, sizeof(info)); info.fn = 9; info.b = 0; @@ -376,14 +376,12 @@ static int fat12__error(Fat12 *this, const char *errorMessage) { static int handleError(const Fat12 *fat12) { printf("Error in Fat12: %s\n", fat12->errorMessage); + con_exit(0); return -1; } void writeFile(const char *fileName, int size, const uint8_t *data) { -// FILE *fp = NULL; -// if (!(fp = fopen(fileName, "wb"))) { perror(NULL); } -// fwrite(data, 1, size, fp); -// fclose(fp); +#if TCC struct Info { int number; int reserved0; @@ -391,15 +389,22 @@ void writeFile(const char *fileName, int size, const uint8_t *data) { int dataSize; const void *data; char zero; - const char *name; - } __attribute__((packed)) *info = calloc(sizeof(struct Info), 1); - - info->number = 2; // create/overwrite file - info->dataSize = size; - info->data = data; - info->zero = 0; - info->name = fileName; - asm volatile ("int $0x40" :: "a"(70), "b"(info)); + const char *name __attribute__((packed)); + } info; + + memset(&info, 0, sizeof(struct Info)); + info.number = 2; // create/overwrite file + info.dataSize = size; + info.data = data; + info.zero = 0; + info.name = fileName; + asm volatile ("int $0x40" :: "a"(70), "b"(&info)); +#else + FILE *fp = NULL; + if (!(fp = fopen(fileName, "wb"))) { perror(NULL); } + fwrite(data, 1, size, fp); + fclose(fp); +#endif } static int callback(const char *name, size_t size, const uint8_t *data, void *param) { @@ -422,14 +427,7 @@ static int callback(const char *name, size_t size, const uint8_t *data, void *pa } } printf("Extracting %s\n", outputPath->data); - #ifdef TCC - FILE *fp = NULL; - if (!(fp = fopen(outputPath->data, "wb"))) { perror(NULL); } - fwrite(data, 1, size, fp); - fclose(fp); - #else - writeFile(outputPath->data, size, data); - #endif + writeFile(outputPath->data, size, data); outputPath->data[outputPath->length] = '\0'; return 0; } @@ -440,45 +438,45 @@ int main(int argc, char* argv[]) { Fat12 fat12 = { 0 }; char *imageFile = NULL; String outputFolder = { 0 }; - int exit_code = 0; + int closeOnExit = 0; - char app_title[] = "UnImg - kolibri.img file unpacker"; - con_init(-1, -1, -1, 350, app_title); + if (con_init_console_dll()) { return -1; } + con_set_title("UnImg - kolibri.img file unpacker"); if (argc < 2) { puts(" Usage:"); puts(" unimg \"/path/to/kolibri.img\" \"/optional/extract/path\""); puts(" where optional key [-e] is exit on success"); - exit(exit_code); + con_exit(0); return -1; } else { - imageFile = argv[1]; - printf("File: %s\n", imageFile); + imageFile = argv[1]; + printf("File: %s\n", imageFile); } outputFolder.capacity = 4096; outputFolder.data = malloc(outputFolder.capacity); //! ACHTUNG: possible buffer overflow, is 4096 enough in KolibriOS? - if (argc >= 3 && argv[2][0] != '-') strcpy(outputFolder.data, argv[2]); + if (argc >= 3 && argv[2][0] != '-') { strcpy(outputFolder.data, argv[2]); } else { - strcpy(outputFolder.data, "/tmp0/1"); - strcat(outputFolder.data, strrchr(imageFile, '/')); + strcpy(outputFolder.data, "/tmp0/1"); + strcat(outputFolder.data, strrchr(imageFile, '/')); } outputFolder.length = strlen(outputFolder.data); // handle -e parameter - exit on success - if (argc >= 3 && !strcmp(argv[argc - 1], "-e")) { exit_code = 1; } + if (argc >= 3 && !strcmp(argv[argc - 1], "-e")) { closeOnExit = 1; } - if (!fat12__open(&fat12, imageFile)) { - return handleError(&fat12); + if (!fat12__open(&fat12, imageFile)) { + return handleError(&fat12); } - if (!fat12__forEachFile(&fat12, callback, &outputFolder)) { return handleError(&fat12); } puts("\nDONE!"); - exit(exit_code); + con_exit(closeOnExit); + return 0; } diff --git a/programs/fs/unimg/make_gcc.bat b/programs/fs/unimg/make_gcc.bat index d1465b157a..ff2ca5dec6 100644 --- a/programs/fs/unimg/make_gcc.bat +++ b/programs/fs/unimg/make_gcc.bat @@ -1,7 +1,4 @@ -@echo #define COMPILLER TCC > compiller.h - gcc -m32 -c -fomit-frame-pointer -IC:\Users\Boppan\Documents\KolibriOS\contrib/sdk/sources/newlib/libc/include fat12.c -o unimg.o -Wall -Wextra kos32-ld unimg.o -o unimg -static -S -nostdlib -T C:\Users\Boppan\Documents\KolibriOS\contrib/sdk/sources/newlib/app.lds --image-base 0 -L "C:\Program Files (x86)\kos32-msys-5.4.0\win32\lib" -lgcc -lapp -lc.dll kos32-objcopy unimg -O binary -@del compiller.h @pause \ No newline at end of file diff --git a/programs/fs/unimg/make_tcc.bat b/programs/fs/unimg/make_tcc.bat index 39f6e82015..c9befdb80b 100644 --- a/programs/fs/unimg/make_tcc.bat +++ b/programs/fs/unimg/make_tcc.bat @@ -1,4 +1,2 @@ -@echo #define COMPILLER TCC > compiller.h kos32-tcc fat12.c -lck -o unimg -@del compiller.h @pause \ No newline at end of file diff --git a/programs/fs/unimg/unimg b/programs/fs/unimg/unimg index 96b8a2ffd0fb484ed0236d904a6d9e1d516f73df..0a625baee91c8c31f3b03ca5ba4e1672906a5a2f 100644 GIT binary patch literal 3601 zcmV+s4({}A^-q^00001Mv*2LLXK;7ng=$wv^6SEyBn0bG(!D?V^IX1bO_j- zo+R5y)M7BgBFW*v;PB8>iz0N$k5p#6j&j0LqzD$(**Vz5LK(tELE*-RrV_+6?5t-gK<%{1e2vf81 zJ#`*VG2syVTLJ{}jpJ8}PIY_G)yNQDpCA0={x~wmE?r5cwr3mN+Pb8ng#7u9Kbx5V zkBpUzsyVa~$0+ET+%tkLQWr{k=2pzQslAjXOwRe68D6q~(Ag7L00To;?nsWNMm~*r zYBz(*StgQ$oThmpY8XuK@EnHzHCE+cSclIxfYtSdgYOf@inA~v`faUkR%9_u*nT7d ziYClH=NTX!2?6&`TY4i$bA~FA0pIVAnEWU6H_krTFs$|sZss`x6~gGFCqp#RT-9Jw zAxdwkG`43|aG{VMzf|qKn1mCxgYD)1hRm~jEfDwhe^2UtvxutP5L7$i5kbX? zjWUJtA}Dil0&a?xR=QwRnWefM$grnPDnkky-|z8c*jZByqs2Q*4?BzA7RAe?3>mi6 zqw8&j>wq1dn`G-WU@}#{pub(Wvrx+Mw7b{w}}G0o(V@-`RQLu zm%AB!4$d~AkE9i0*Q+_H>qP3O2Z$2&l&uSAGbPyZ)2Ou5>_iPvifj&F5T}esrY{pg z7EsGknQPeUOhsJwyHr9$qIw#?OiTxF;fx88JPr0dT5jaHUbu<$^kbjjFxE#jZ6-cEcsq$#?5PE&T#6$7!{+g8yC7piyN!a9_0% z)GO5vL@g@0+o4>;;^{xpDq{+WY;lPKS3*mp{@ zhd|awhjk%)QE2&HZ^SvlX2a2v9#Fnm&c}w;=XvNkDO_ps~;6`Pcv7viI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