From 78378a42a7746e51e7a7e4160b4560b506287b5e Mon Sep 17 00:00:00 2001 From: Ayabusa Date: Sun, 7 Jun 2026 21:40:54 +0200 Subject: [PATCH] good enough arg parser --- Makefile | 2 +- src/cli.c | 23 +++++++++++++++++++++++ src/cli.h | 3 +++ src/cli.o | Bin 5312 -> 0 bytes src/main.c | 6 ++++-- 5 files changed, 31 insertions(+), 3 deletions(-) delete mode 100644 src/cli.o diff --git a/Makefile b/Makefile index 262a9eb..9faa0d0 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CFLAGS = -Wall -Wextra -g LIBS = -lcurl SRC = src/main.c src/cpu.c src/downloader.c src/cli.c -OBJ = build/main.o build/cpu.o build/downloader.o src/cli.o +OBJ = build/main.o build/cpu.o build/downloader.o build/cli.o RES = build/Thoryum all: setup $(OBJ) build diff --git a/src/cli.c b/src/cli.c index 083bf2c..5643c76 100644 --- a/src/cli.c +++ b/src/cli.c @@ -5,8 +5,19 @@ #include "cli.h" extern char *optarg; // What the hell is that glibc ??? +extern int optind, opterr, optopt; + +void check_help(int argc, char **argv) { + for (int i = 1; i < argc; i++) + if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { + print_help(); + exit(EXIT_SUCCESS); + } +} struct ctx *init_ctx(int argc, char **argv) { + check_help(argc, argv); + struct ctx *ctx = calloc(1, sizeof(struct ctx)); int opt; @@ -39,6 +50,18 @@ void *free_ctx(struct ctx *ctx) { return NULL; } +void print_ctx(struct ctx *ctx) { + printf( + "Thoryum context:\n" + "Mode = %s\n" + "Install location = '%s'\n" + "Silent = %s\n", + ctx->mode ? "UPDATE" : "NORMAL", + ctx->install_loc, + ctx->silent ? "YES" : "NOPE" + ); +} + void print_help() { printf( "Usage: thoryum [options]\n" diff --git a/src/cli.h b/src/cli.h index 9647c10..8a36ff2 100644 --- a/src/cli.h +++ b/src/cli.h @@ -12,6 +12,9 @@ struct ctx { int silent; }; +struct ctx *init_ctx(int argc, char **argv); +void *free_ctx(struct ctx *ctx); +void print_ctx(struct ctx *ctx); void print_help(); #endif diff --git a/src/cli.o b/src/cli.o deleted file mode 100644 index 48003b7777b9555d0cbfecaf0564d75a669010d6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5312 zcmbVQU2Ggz6}~g$wKqHdOWZn5Q^+-HaZ-6^U7eKWEOJ^|zKTJz*LKBQn?m+vNy_er$KVD2Iz|KbvI#8vE?O*OqVm zbNS^D`HdGpT)vV2{deOa{{VHCZ!F!p`R+Sio!3eQ`bR0fx$zETYpK@|^E_+DNhfdd z^|+k{ag=UURuvMY+>3Y+rI{CoyeY!ANM-=4^SoX6GQqDUUK=pJ6(`_Ea5N0SRV|6H zr6O@Fl`DnM`3mPwbA~$(dI1J$B?+Po>>v!Hyd_ec5mB4gdJ$FQ^yq%AE6ldH^ugYck zakLdAts*Qg6;>E_Oms>EbJ8Sa=w243cq}1m9IU$#HXgFHk9L4Tp0Z2si?yy zW+I7T8^Kk~{ig7*s!dE~SlDN=6Qo%XHE6?Ul%F8uX*15lx}0ZCfP6c?3O;Maw7@^^ z^b>FfwY5dRhVxRkXYy>0%7GuZUfLJu>9Ha$oCK##m1<}csP6z8zAF{@+~w;kg15yQoO&_>8aryu{ z8YwZe3|ya8n{i82RYj_Hmqr50iC23~JSe?^j`=o5$yzFo^OU zrxE4V*<;lp^1~cXP%08rMBi~!Qr9uO~}uO0LKSO7Mi8e z@$Z`FMh4eG0Wg%EMj?(57OD9llq9isQ3#S{-)xe)bK@>TF+?s z1%<{xR2y=v~wO<9mpN`k2p0kOBI9(RJ}<#XqXyv|d-kbH$(3aGL)a4X1qi zl7@d@@x6JD^ZbFrDL&2rM+&Dr*VoIH+=Lz}1S^Ut}J0YiY{dBrX^!tqb^Buo*;KG3dy#SF0sr8`RKPL5UYN1e)$*a90X4fp|1T zcvJFz+-eE9$6fdVC0w}L;Hv<>5)==YtP9@@@cS_9D8Hh)xs`Y=dQoZNpR(s*hkHx; zMs60>K>vVL=}KzsAdE0S7rRI?cw7F?fS=F`$NL#=@ywC%qZJAB6LGr75kq>Z=6Q~xt%=V=qxSoSy=^xMBOz6e0? zDL=S>ct#YT_V3Gp={^BsgXk1Ue$yAjg6|pQa08xx_Cx9tJ*w&Jx?cl%zxlsETo{r) z&L2}kpa1iK=|0i&go?k7Ob_Y0A;|j0FRP3HBV~*6@vBLXkM}S7q)PJDtiKm|Ii2o%FP*qEF zM)sT(RZsgz@VhWTpSpcnDPn%~l5YQd5cWI2JL>%CT=4wxn~m%#|NF(pc+V=ulWM{E n{nao35YuZ1+TTV2&~(vtTYdlbf~24QVfDfE=dNWj(Cz;R%KUl- diff --git a/src/main.c b/src/main.c index 62bafe9..42bf73c 100644 --- a/src/main.c +++ b/src/main.c @@ -34,7 +34,7 @@ void patch_desktop_file(char *install_loc) { wait(NULL); } -int main() { +int main(int argc, char **argv) { printf("Hello this is Thoryum ;)\n"); enum CPU_opti opti = CPU_fetch_opti(); char opti_name[5] = {0}; @@ -47,5 +47,7 @@ int main() { */ //printf("Latest version url : '%s,'\n",DL_get_latest_version_url("AVX.zip")); //patch_desktop_file("."); - print_help(); + struct ctx *ctx = init_ctx(argc, argv); + print_ctx(ctx); + ctx = free_ctx(ctx); } -- 2.43.0