From 2c99a3d8d74f58e4cc7974c4092c82cd6095ff48 Mon Sep 17 00:00:00 2001 From: dacctal Date: Thu, 2 Jul 2026 05:11:34 +0000 Subject: asan-free checkpoint! --- include/cla_parse.h | 26 ------ include/parse_args.h | 26 ++++++ src/cla_parse.c | 229 --------------------------------------------------- src/parse_args.c | 183 ++++++++++++++++++++++++++++++++++++++++ src/pkg_create.c | 6 +- 5 files changed, 214 insertions(+), 256 deletions(-) delete mode 100644 include/cla_parse.h create mode 100644 include/parse_args.h delete mode 100644 src/cla_parse.c create mode 100644 src/parse_args.c diff --git a/include/cla_parse.h b/include/cla_parse.h deleted file mode 100644 index eca1395..0000000 --- a/include/cla_parse.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - - pkgit - package it! - - Copyright (C) 2026 dacctal - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -*/ - -#ifndef PKGIT_CLA_PARSE_H -#define PKGIT_CLA_PARSE_H - -void cla_parse(int argc, char **argv); - -#endif \ No newline at end of file diff --git a/include/parse_args.h b/include/parse_args.h new file mode 100644 index 0000000..d68c37f --- /dev/null +++ b/include/parse_args.h @@ -0,0 +1,26 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + +#ifndef PKGIT_CLA_PARSE_H +#define PKGIT_CLA_PARSE_H + +void parse_args(int argc, char **argv); + +#endif \ No newline at end of file diff --git a/src/cla_parse.c b/src/cla_parse.c deleted file mode 100644 index 4d824f4..0000000 --- a/src/cla_parse.c +++ /dev/null @@ -1,229 +0,0 @@ -/* - - pkgit - package it! - - Copyright (C) 2026 dacctal - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -*/ - -#include -#include - -#include "cla_parse.h" - -#include "globs.h" -#include "log.h" -#include "str.h" -// #include "declare.h" -// #include "deps_resolve.h" -#include "help.h" -// #include "name_from_url.h" -// #include "pkg_build.h" -#include "pkg.h" -// #include "pkg_search.h" -// #include "pkg_install.h" -// #include "pkg_list.h" -// #include "pkg_remove.h" -// #include "pkgit_globals.h" -// #include "repo_add.h" -// #include "update.h" - -#define COMMAND(large, small) \ - (!strcmp(argv[i], large) || !strcmp(argv[i], small)) - -#define NOT_ENOUGH_ARGS(arg, next) \ - log_error("Not enough arguments! Try: pkgit %s [%s]", (arg), (next)) - -void cmd_add(char **argv, int i) { - if (argv[i + 1]) { - printf("add repo %s\n", argv[i + 1]); - // repo_add(argv[i + 1], name_from_url(argv[i + 1])); - } else { - NOT_ENOUGH_ARGS(argv[i], "url"); - } -} - -void cmd_build(int argc, char **argv, int i) { - if (argv[i + 1]) { - for (int j = i + 1; j < argc; j++) { - if (argv[j][0] == '-') - continue; - printf("build pkg %s\n", argv[j]); - // str_slc arg = mstrslc(argv[j]); - // package_t pkg = pkg_create(arg); - // pkg_build(pkg); - } - } else { - printf("build pkg .\n"); - // str_slc arg = mstrslc("."); - // package_t pkg = pkg_create(arg); - // pkg_build(pkg); - } -} - -void cmd_install(int argc, char **argv, int i) { - if (argv[i + 1]) { - for (int j = i + 1; j < argc; j++) { - if (argv[j][0] == '-') - continue; - printf("install pkg %s\n", argv[j]); - // str_slc arg = mstrslc(argv[j]); - // package_t pkg = pkg_create(arg); - // pkg_install(pkg); - } - } else { - NOT_ENOUGH_ARGS(argv[i], "url/pkg"); - } -} - -void cmd_remove(int argc, char **argv, int i) { - if (argv[i + 1]) { - for (int j = i + 1; j < argc; j++) { - if (argv[j][0] == '-') - continue; - printf("remove pkg %s\n", argv[j]); - // str_slc arg = mstrslc(argv[j]); - // package_t pkg = pkg_create(arg); - // pkg_remove(pkg); - } - } else { - NOT_ENOUGH_ARGS(argv[i], "url/pkg"); - } -} - -void flags_mod(char **argv, int i) { - for (size_t j = 1; j < strlen(argv[i]); j++) { - switch (argv[i][j]) { - case 'q': - flags.verbose = false; - break; - case 'f': - flags.force = true; - break; - default: - break; - } - } -} - -void flags_cmd(int argc, char **argv, int i) { - for (size_t j = 1; j < strlen(argv[i]); j++) { - switch (argv[i][j]) { - case 'a': - cmd_add(argv, i); - break; - case 'b': - cmd_build(argc, argv, i); - break; - case 'c': /*deps_resolve();*/ - printf("deps_resolve\n"); - break; - case 'd': /*declare();*/ - printf("declare\n"); - break; - case 'i': - cmd_install(argc, argv, i); - break; - case 'r': - cmd_remove(argc, argv, i); - break; - case 'u': /*update();*/ - printf("update\n"); - break; - case 'l': /*pkgs_list();*/ - printf("list\n"); - break; - case 's': /*search(argv[i + 1]);*/ - printf("search\n"); - break; - case 'v': - printf("%s\n", VERSION); - break; - case 'h': - help(); - break; - default: - break; - } - } -} - -void flags_parse(int argc, char **argv) { - for (int i = 1; i < argc; i++) { - if (argv[i][0] != '-') - continue; - if (argv[i][1] == '-') { - if (COMMAND("--quiet", "-q")) - flags.verbose = false; - if (COMMAND("--force", "-f")) { - flags.force = true; - }; - } else { - flags_mod(argv, i); - flags_cmd(argc, argv, i); - } - } -} - -void cmds_parse(int argc, char **argv) { - for (int i = 1; i < argc; i++) { - if (COMMAND("--add", "a")) { - cmd_add(argv, i); - } - if (COMMAND("--build", "b")) { - cmd_build(argc, argv, i); - } - if (COMMAND("--install", "i")) { - cmd_install(argc, argv, i); - } - if (COMMAND("--remove", "r")) { - cmd_remove(argc, argv, i); - } - if (COMMAND("--update", "u")) { - panic("not implemented"); - // update(); - } - if (COMMAND("--declare", "d")) { - // declare(); - } - if (COMMAND("--list", "l")) { - // pkgs_list(); - } - if (COMMAND("--search", "s")) { - // search(argv[i + 1]); - } - if (COMMAND("--version", "v")) { - printf(VERSION "\n"); - } - if (COMMAND("--help", "h")) { - help(); - } - if (COMMAND("--check", "c")) { - // deps_resolve - } - } -} - -void cla_parse(int argc, char **argv) { - // default - flags.force = false; - flags.verbose = true; - if (argc == 1) { - help(); - return; - } - flags_parse(argc, argv); - cmds_parse(argc, argv); -} diff --git a/src/parse_args.c b/src/parse_args.c new file mode 100644 index 0000000..1746ccc --- /dev/null +++ b/src/parse_args.c @@ -0,0 +1,183 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + +#include +#include + +#include "parse_args.h" + +#include "globs.h" +#include "log.h" +#include "str.h" +// #include "declare.h" +// #include "easter_egg.h" +#include "help.h" +// #include "name_from_url.h" +// #include "pkg_build.h" +#include "pkg.h" +// #include "pkg_search.h" +// #include "pkg_install.h" +// #include "pkg_list.h" +// #include "pkg_remove.h" +// #include "pkgit_globals.h" +// #include "repo_add.h" +// #include "update.h" + +#define COMMAND(large, small) \ + (!strcmp(argv[i], large) || !strcmp(argv[i], small)) + +#define NOT_ENOUGH_ARGS(arg, next) \ + log_error("Not enough arguments! Try: pkgit %s [%s]", (arg), (next)) + +void cmd_add(char **argv, int i) { + if (argv[i + 1]) { + printf("add repo %s\n", argv[i + 1]); + // repo_add(argv[i + 1], name_from_url(argv[i + 1])); + } else { + NOT_ENOUGH_ARGS(argv[i], "url"); + } +} + +void cmd_build(int argc, char **argv, int i) { + if (argv[i + 1]) { + for (int j = i + 1; j < argc; j++) { + if (argv[j][0] == '-') + continue; + printf("build pkg %s\n", argv[j]); + // str_slc arg = mstrslc(argv[j]); + // package_t pkg = pkg_create(arg); + // pkg_build(pkg); + } + } else { + printf("build pkg .\n"); + // str_slc arg = mstrslc("."); + // package_t pkg = pkg_create(arg); + // pkg_build(pkg); + } +} + +void cmd_install(int argc, char **argv, int i) { + if (argv[i + 1]) { + for (int j = i + 1; j < argc; j++) { + if (argv[j][0] == '-') + continue; + printf("install pkg %s\n", argv[j]); + // str_slc arg = mstrslc(argv[j]); + // package_t pkg = pkg_create(arg); + // pkg_install(pkg); + } + } else { + NOT_ENOUGH_ARGS(argv[i], "url/pkg"); + } +} + +void cmd_remove(int argc, char **argv, int i) { + if (argv[i + 1]) { + for (int j = i + 1; j < argc; j++) { + if (argv[j][0] == '-') + continue; + printf("remove pkg %s\n", argv[j]); + // str_slc arg = mstrslc(argv[j]); + // package_t pkg = pkg_create(arg); + // pkg_remove(pkg); + } + } else { + NOT_ENOUGH_ARGS(argv[i], "url/pkg"); + } +} + +void flags_mod(char **argv, int i) { + for (size_t j = 1; j < strlen(argv[i]); j++) { + switch (argv[i][j]) { + case 'q': + flags.verbose = false; + break; + case 'f': + flags.force = true; + break; + default: + break; + } + } +} + +void flags_cmd(int argc, char **argv, int i) { + for (size_t j = 1; j < strlen(argv[i]); j++) { + switch (argv[i][j]) { + case 'a': cmd_add(argv, i); break; + case 'b': cmd_build(argc, argv, i); break; + case 'c': panic("not implemented"); printf("easter_egg\n"); break; + case 'd': panic("not implemented"); printf("declare\n"); break; + case 'i': cmd_install(argc, argv, i); break; + case 'r': cmd_remove(argc, argv, i); break; + case 'u': panic("not implemented"); printf("update\n"); break; + case 'l': panic("not implemented"); printf("list\n"); break; + case 's': panic("not implemented"); printf("search\n"); break; + case 'v': printf("%s\n", VERSION); break; + case 'h': help(); break; + default: break; + } + } +} + +void parse_flags(int argc, char **argv) { + for (int i = 1; i < argc; i++) { + if (argv[i][0] != '-') continue; + if (argv[i][1] == '-') { + if (COMMAND("--quiet", "-q")) flags.verbose = false; + if (COMMAND("--force", "-f")) flags.force = true; + } else { + flags_mod(argv, i); + flags_cmd(argc, argv, i); + } + } +} + +void parse_cmds(int argc, char **argv) { + for (int i = 1; i < argc; i++) { + if (COMMAND("--add", "a")) { cmd_add(argv, i); } + if (COMMAND("--build", "b")) { cmd_build(argc, argv, i); } + if (COMMAND("--install", "i")) { cmd_install(argc, argv, i); } + if (COMMAND("--remove", "r")) { cmd_remove(argc, argv, i); } + if (COMMAND("--update", "u")) { panic("not implemented"); } + if (COMMAND("--declare", "d")) { panic("not implemented"); } + if (COMMAND("--list", "l")) { panic("not implemented"); } + if (COMMAND("--search", "s")) { panic("not implemented"); } + if (COMMAND("--version", "v")) { printf(VERSION "\n"); } + if (COMMAND("--help", "h")) { help(); } + if (COMMAND("--check", "c")) { panic("not implemented"); } + } +} + +void parse_args(int argc, char **argv) { + // default + flags.force = false; + flags.verbose = true; + if (argc == 1) { + help(); + return; + } + parse_flags(argc, argv); + parse_cmds(argc, argv); +} + +void str_parse_args(str *args[]) { + if (!args[0]) { help(); return; } +} diff --git a/src/pkg_create.c b/src/pkg_create.c index 9517868..ebf0745 100644 --- a/src/pkg_create.c +++ b/src/pkg_create.c @@ -45,10 +45,12 @@ static str get_pkgsrc(package_t pkg) { } package_t pkg_create(str_slc arg) { + str ver_buf = mstr("HEAD"); package_t pkg = { - .version = mstr("HEAD"), + .version = ver_buf, .is_local = false, }; + str_free(&ver_buf); char cwd[MAX_PATH_LEN]; getcwd(cwd, MAX_PATH_LEN); @@ -95,5 +97,7 @@ package_t pkg_create(str_slc arg) { exit(EXIT_FAILURE); } pkg.src = get_pkgsrc(pkg); + str_free(&cwd_str); + str_free(&dest_dir); return pkg; } -- cgit v1.2.3