aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.clang-format36
-rw-r--r--.clangd9
-rw-r--r--.gitignore3
-rw-r--r--include/globs.h20
-rw-r--r--include/pkg.h33
-rw-r--r--include/pkg/create.h25
-rw-r--r--include/str.h16
-rw-r--r--refactor.patch1060
-rw-r--r--src/cla_parse.c76
-rw-r--r--src/globs.c1
-rw-r--r--src/help.c9
-rw-r--r--src/lua_globs.c4
-rw-r--r--src/main.c4
-rw-r--r--src/pkg/.clangd4
-rw-r--r--src/pkg_create.c (renamed from src/pkg/create.c)5
-rw-r--r--src/pkg_free.c9
-rw-r--r--src/str.c25
17 files changed, 162 insertions, 1177 deletions
diff --git a/.clang-format b/.clang-format
index a729ffe..fc0a6f3 100644
--- a/.clang-format
+++ b/.clang-format
@@ -1,7 +1,7 @@
---
Language: Cpp
-AlignAfterOpenBracket: true
AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
Enabled: false
@@ -68,19 +68,17 @@ AlignConsecutiveTableGenDefinitionColons:
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments:
- AlignPPAndNotPP: true
Kind: Always
OverEmptyLines: 0
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowBreakBeforeNoexceptSpecifier: Never
-AllowBreakBeforeQtProperty: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseExpressionOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortCompoundRequirementOnASingleLine: true
AllowShortEnumsOnASingleLine: true
-AllowShortFunctionsOnASingleLine: All
+AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
@@ -116,19 +114,9 @@ BraceWrapping:
BreakAdjacentStringLiterals: true
BreakAfterAttributes: Leave
BreakAfterJavaFieldAnnotations: false
-BreakAfterOpenBracketBracedList: false
-BreakAfterOpenBracketFunction: false
-BreakAfterOpenBracketIf: false
-BreakAfterOpenBracketLoop: false
-BreakAfterOpenBracketSwitch: false
BreakAfterReturnType: None
BreakArrays: true
BreakBeforeBinaryOperators: None
-BreakBeforeCloseBracketBracedList: false
-BreakBeforeCloseBracketFunction: false
-BreakBeforeCloseBracketIf: false
-BreakBeforeCloseBracketLoop: false
-BreakBeforeCloseBracketSwitch: false
BreakBeforeConceptDeclarations: Always
BreakBeforeBraces: Attach
BreakBeforeInlineASMColon: OnlyMultiline
@@ -145,7 +133,7 @@ CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
-Cpp11BracedListStyle: AlignFirstComment
+Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
@@ -190,16 +178,10 @@ InsertNewlineAtEOF: false
InsertTrailingCommas: None
IntegerLiteralSeparator:
Binary: 0
- BinaryMinDigitsInsert: 0
- BinaryMaxDigitsRemove: 0
- Decimal: 0
- DecimalMinDigitsInsert: 0
- DecimalMaxDigitsRemove: 0
- Hex: 0
- HexMinDigitsInsert: 0
- HexMaxDigitsRemove: 0
BinaryMinDigits: 0
+ Decimal: 0
DecimalMinDigits: 0
+ Hex: 0
HexMinDigits: 0
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
@@ -215,11 +197,6 @@ MacroBlockEnd: ''
MainIncludeChar: Quote
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
-NumericLiteralCase:
- ExponentLetter: Leave
- HexDigit: Leave
- Prefix: Leave
- Suffix: Leave
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
@@ -256,7 +233,6 @@ SkipMacroDefinitionBody: false
SortIncludes:
Enabled: true
IgnoreCase: false
- IgnoreExtension: false
SortJavaStaticImport: Before
SortUsingDeclarations: LexicographicNumeric
SpaceAfterCStyleCast: false
@@ -285,7 +261,7 @@ SpaceBeforeParensOptions:
BeforeNonEmptyParentheses: false
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
-SpaceInEmptyBraces: Never
+SpaceInEmptyBlock: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInContainerLiterals: true
diff --git a/.clangd b/.clangd
index 5022e8f..496ad97 100644
--- a/.clangd
+++ b/.clangd
@@ -1,4 +1,9 @@
+If:
+ PathMatch: .*\.h
CompileFlags:
- Add: [-I/usr/include/luajit-2.1, -I../include]
+ Add: [-std=c99,-xc-header,-Wall,-Werror,-pedantic,-Wvla,-Iinclude,-I../include,-I../../include/]
---
-UseTab: Always
+If:
+ PathMatch: .*\.c
+CompileFlags:
+ Add: [-std=c99,-xc-header,-Wall,-Werror,-pedantic,-Wvla,-Iinclude,-I../include,-I../../include/]
diff --git a/.gitignore b/.gitignore
index 46d5825..f3ab545 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
pkgit
obj/
patches/
+*.patch
+demo
+demo*
diff --git a/include/globs.h b/include/globs.h
index 4611216..bec1dc9 100644
--- a/include/globs.h
+++ b/include/globs.h
@@ -1,28 +1,28 @@
/*
-
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 <https://www.gnu.org/licenses/>.
-
*/
#ifndef PKGIT_GLOBALS_H
#define PKGIT_GLOBALS_H
+#include <stdlib.h>
+
#include "str.h"
-#include <stdint.h>
#define VERSION "1.4.0_INDEV"
#define RED "\x1b[0;31m"
@@ -58,6 +58,8 @@
#define ITALIC "\x1b[3m"
#define COLOR_RESET "\x1b[0m"
+#define LENGTH(lst) (sizeof(lst) / sizeof(*(lst)))
+
#define eprintf(...) fprintf(stderr, __VA_ARGS__);
#define check_alloc(ptr) \
@@ -66,7 +68,6 @@
panic("allocation of `%s` failed", #ptr); \
} while (0)
-#include <stdlib.h>
#define panic(...) \
do { \
eprintf(BOLD RED "panic:" COLOR_RESET " line %d, func \"%s\" in file " \
@@ -105,11 +106,6 @@
#define MAX_PATH_LEN 1024
typedef struct {
- str name, url, version, target, src;
- bool is_local;
-} package_t;
-
-typedef struct {
bool verbose, force;
} cli_flags_t;
diff --git a/include/pkg.h b/include/pkg.h
new file mode 100644
index 0000000..9cb3944
--- /dev/null
+++ b/include/pkg.h
@@ -0,0 +1,33 @@
+/*
+ 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 <https://www.gnu.org/licenses/>.
+*/
+
+#ifndef PKGIT_PKG_H
+#define PKGIT_PKG_H
+
+#include "str.h"
+
+typedef struct {
+ str name, url, version, target, src;
+ bool is_local;
+} package_t;
+
+package_t pkg_create(str_slc arg);
+void pkg_free(package_t *pkg);
+
+#endif
diff --git a/include/pkg/create.h b/include/pkg/create.h
deleted file mode 100644
index 95e12c6..0000000
--- a/include/pkg/create.h
+++ /dev/null
@@ -1,25 +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 <https://www.gnu.org/licenses/>.
-
-*/
-
-#ifndef PKGIT_PKG_CREATE_H
-#define PKGIT_PKG_CREATE_H
-#include "globs.h"
-package_t pkg_create(str_slc arg);
-#endif
diff --git a/include/str.h b/include/str.h
index f5c79dd..8623312 100644
--- a/include/str.h
+++ b/include/str.h
@@ -116,36 +116,42 @@ void str_free(str *s);
/**
* Copies the entirety of src into dest, resizing it if necessary, while
* overwriting all existing data.
+ * dest will be initialized if necessary.
*/
void str_copy_into(str *dest, const str *src);
/**
* Copies a source C string at src into an already initialized
* str, resizing the buffer if necessary, overwriting all existing data.
+ * dest will be initialized if necessary.
*/
void str_copy_cstr_into(str *dest, const char *src);
/**
* Copies a source string slice at src into an already initialized
* str, resizing the buffer if necessary, overwriting all existing data.
+ * dest will be initialized if necessary.
*/
void str_copy_str_slc_into(str *dest, const str_slc src);
/**
* Copies n bytes of src into an already initialized str dest,
* resizing it if necessary, while overwriting all existing data.
+ * dest will be initialized if necessary.
*/
void str_ncopy_into(str *dest, const str *src, size_t count);
/**
* Copies n bytes of a C string src into an already initialized str dest,
* resizing it if necessary, while overwriting all existing data.
+ * dest will be initialized if necessary.
*/
void str_ncopy_cstr_into(str *dest, const char *src, size_t count);
/**
* Copies n bytes of a string slice src into an already initialized str dest,
* resizing it if necessary, while overwriting all existing data.
+ * dest will be initialized if necessary.
*/
void str_ncopy_str_slc_into(str *dest, const str_slc src, size_t count);
@@ -157,23 +163,23 @@ str str_dupe(const str *src);
/**
* Appends a str into an existing str, resizing the buffer if necessary.
*/
-void str_append(str *src, const str *new);
+void str_append(str *src, const str *new_str);
/**
* Appends a single character new into src, resizing the buffer if necessary.
*/
-void str_append_char(str *src, char new);
+void str_append_char(str *src, char new_char);
/**
* Appends a C string into an existing str, resizing the buffer if necessary.
*/
-void str_append_cstr(str *src, const char *new);
+void str_append_cstr(str *src, const char *new_cstr);
/**
* Appends a string slice into an existing str, resizing the buffer if
* necessary.
*/
-void str_append_str_slc(str *src, const str_slc new);
+void str_append_str_slc(str *src, const str_slc new_slc);
/**
* Removes the last character from src, returning it.
@@ -521,7 +527,9 @@ ptrdiff_t str_slc_find_char(const str_slc s, char c);
ptrdiff_t str_slc_find_char_right(const str_slc s, char c);
str str_from_after_delim(str *arg, char delimiter);
+str str_from_after_delim_str_slc(str_slc arg, char delimiter);
str str_from_before_delim(str *arg, char delimiter);
+str str_from_before_delim_str_slc(str_slc arg, char delimiter);
str_slc str_slc_from_after_delim(str_slc arg, char delimiter);
str_slc str_slc_from_before_delim(str_slc arg, char delimiter);
diff --git a/refactor.patch b/refactor.patch
deleted file mode 100644
index 6f57749..0000000
--- a/refactor.patch
+++ /dev/null
@@ -1,1060 +0,0 @@
-diff --git a/cla_parse.c b/cla_parse.c
-index 59c8bda..8d5db4f 100644
---- a/cla_parse.c
-+++ b/cla_parse.c
-@@ -25,31 +25,31 @@
-
- #include "globs.h"
- #include "str.h"
--//#include "declare.h"
--//#include "deps_resolve.h"
-+// #include "declare.h"
-+// #include "deps_resolve.h"
- #include "help.h"
--//#include "name_from_url.h"
--//#include "pkg_build.h"
-+// #include "name_from_url.h"
-+// #include "pkg_build.h"
- #include "pkg_create.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"
-+// #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(arg, large, small, code) if ( \
-- strcmp(arg, large) == 0 || strcmp(arg, small) == 0) code
-+#define COMMAND(arg, large, small, code) \
-+ if (strcmp(arg, large) == 0 || strcmp(arg, small) == 0) \
-+ code
-
--#define NOT_ENOUGH_ARGS(arg, next) \
-- printf("%s Not enough arguments! Try: `pkgit %s [%s]`\n", \
-- PRINT_ERROR, arg, next)
-+#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]));
-+ // repo_add(argv[i + 1], name_from_url(argv[i + 1]));
- } else {
- NOT_ENOUGH_ARGS(argv[i], "url");
- }
-@@ -58,50 +58,58 @@ void cmd_add(char **argv, int i) {
- void cmd_build(int argc, char **argv, int i, package pkg) {
- if (argv[i + 1]) {
- for (int j = i + 1; j < argc; j++) {
-- if (argv[j][0] == '-') continue;
-+ if (argv[j][0] == '-')
-+ continue;
- printf("build pkg %s\n", argv[j]);
-- //pkg = pkg_create(argv[j]);
-- //pkg_build(pkg);
-+ // pkg = pkg_create(argv[j]);
-+ // pkg_build(pkg);
- }
- } else {
- printf("build pkg .\n");
-- //pkg = pkg_create(".");
-- //pkg_build(pkg);
-+ // pkg = pkg_create(".");
-+ // pkg_build(pkg);
- }
- }
-
- void cmd_install(int argc, char **argv, int i, package pkg) {
- if (argv[i + 1]) {
- for (int j = i + 1; j < argc; j++) {
-- if (argv[j][0] == '-') continue;
-+ if (argv[j][0] == '-')
-+ continue;
- printf("install pkg %s\n", argv[j]);
-- //pkg = pkg_create(argv[j]);
-- //pkg_install(pkg);
-+ // pkg = pkg_create(argv[j]);
-+ // pkg_install(pkg);
- }
- } else {
-- //NOT_ENOUGH_ARGS(argv[i], "url/pkg");
-+ // NOT_ENOUGH_ARGS(argv[i], "url/pkg");
- }
- }
-
- void cmd_remove(int argc, char **argv, int i, package pkg) {
- if (argv[i + 1]) {
- for (int j = i + 1; j < argc; j++) {
-- if (argv[j][0] == '-') continue;
-+ if (argv[j][0] == '-')
-+ continue;
- printf("remove pkg %s\n", argv[j]);
-- //pkg = pkg_create(argv[j]);
-- //pkg_remove(pkg);
-+ // pkg = pkg_create(argv[j]);
-+ // pkg_remove(pkg);
- }
- } else {
-- //NOT_ENOUGH_ARGS(argv[i], "url/pkg");
-+ // 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': is_verbose = 0; break;
-- case 'f': is_forced = 1; break;
-- default: break;
-+ case 'q':
-+ is_verbose = 0;
-+ break;
-+ case 'f':
-+ is_forced = 1;
-+ break;
-+ default:
-+ break;
- }
- }
- }
-@@ -109,25 +117,49 @@ void flags_mod(char **argv, int i) {
- void flags_cmd(int argc, char **argv, int i, package pkg) {
- 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, pkg); break;
-- case 'c': /*deps_resolve();*/ printf("deps_resolve\n"); break;
-- case 'd': /*declare();*/ printf("declare\n"); break;
-- case 'i': cmd_install(argc, argv, i, pkg); break;
-- case 'r': cmd_remove(argc, argv, i, pkg); 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;
-+ case 'a':
-+ cmd_add(argv, i);
-+ break;
-+ case 'b':
-+ cmd_build(argc, argv, i, pkg);
-+ break;
-+ case 'c': /*deps_resolve();*/
-+ printf("deps_resolve\n");
-+ break;
-+ case 'd': /*declare();*/
-+ printf("declare\n");
-+ break;
-+ case 'i':
-+ cmd_install(argc, argv, i, pkg);
-+ break;
-+ case 'r':
-+ cmd_remove(argc, argv, i, pkg);
-+ 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, package pkg) {
- for (int i = 1; i < argc; i++) {
-- if (argv[i][0] != '-') continue;
-+ if (argv[i][0] != '-')
-+ continue;
- str_slc arg = str_slc_from_cstr(argv[i]);
- if (argv[i][1] == '-') {
- COMMAND(argv[i], "--quiet", "-q", { is_verbose = 0; });
-@@ -141,22 +173,26 @@ void flags_parse(int argc, char **argv, package pkg) {
-
- void cmds_parse(int argc, char **argv, package pkg) {
- for (int i = 1; i < argc; i++) {
-- COMMAND(argv[i], "--add", "a", { cmd_add(argv, i); });
-- COMMAND(argv[i], "--build", "b", { cmd_build(argc, argv, i, pkg); });
-- COMMAND(argv[i], "--install", "i", { cmd_install(argc, argv, i, pkg); });
-- COMMAND(argv[i], "--remove", "r", { cmd_remove(argc, argv, i, pkg); });
-- COMMAND(argv[i], "--update", "u", { /*update();*/ });
-- COMMAND(argv[i], "--declare", "d", { /*declare();*/ });
-- COMMAND(argv[i], "--list", "l", { /*pkgs_list();*/ });
-- COMMAND(argv[i], "--search", "s", { /*search(argv[i + 1]);*/ });
-- COMMAND(argv[i], "--version", "v", { printf("%s\n", VERSION); });
-- COMMAND(argv[i], "--help", "h", { help(); });
-- COMMAND(argv[i], "--check", "c", { /*deps_resolve();*/ });
-+ COMMAND(argv[i], "--add", "a", { cmd_add(argv, i); });
-+ COMMAND(argv[i], "--build", "b", { cmd_build(argc, argv, i, pkg); });
-+ COMMAND(argv[i], "--install", "i",
-+ { cmd_install(argc, argv, i, pkg); });
-+ COMMAND(argv[i], "--remove", "r", { cmd_remove(argc, argv, i, pkg); });
-+ COMMAND(argv[i], "--update", "u", {/*update();*/});
-+ COMMAND(argv[i], "--declare", "d", {/*declare();*/});
-+ COMMAND(argv[i], "--list", "l", {/*pkgs_list();*/});
-+ COMMAND(argv[i], "--search", "s", {/*search(argv[i + 1]);*/});
-+ COMMAND(argv[i], "--version", "v", { printf("%s\n", VERSION); });
-+ COMMAND(argv[i], "--help", "h", { help(); });
-+ COMMAND(argv[i], "--check", "c", {/*deps_resolve();*/});
- }
- }
-
- void cla_parse(int argc, char **argv) {
-- if (!argv[1]) { help(); return; }
-+ if (!argv[1]) {
-+ help();
-+ return;
-+ }
- package pkg = {0};
- flags_parse(argc, argv, pkg);
- cmds_parse(argc, argv, pkg);
-diff --git a/include/files.h b/include/files.h
-index 9fd1a71..24712e9 100644
---- a/include/files.h
-+++ b/include/files.h
-@@ -21,7 +21,6 @@
- #ifndef PKGIT_FILES_H
- #define PKGIT_FILES_H
-
--#include <sys/stat.h>
- #include <stdbool.h>
-
- bool file_exists(const char *path);
-diff --git a/include/globs.h b/include/globs.h
-index f44ab85..4611216 100644
---- a/include/globs.h
-+++ b/include/globs.h
-@@ -21,6 +21,9 @@
- #ifndef PKGIT_GLOBALS_H
- #define PKGIT_GLOBALS_H
-
-+#include "str.h"
-+#include <stdint.h>
-+
- #define VERSION "1.4.0_INDEV"
- #define RED "\x1b[0;31m"
- #define GREEN "\x1b[0;32m"
-@@ -90,48 +93,38 @@
- #endif
- #define unreachable panic("reached unreachable code")
-
--#define PRINT_PKGIT \
-- BOLD_YELLOW "[" BOLD_MAGENTA "pkgit" BOLD_YELLOW "]" COLOR_RESET
--#define PRINT_SUCCESS PRINT_PKGIT GREEN " [SUCCESS]" COLOR_RESET
--#define PRINT_SKIPPED PRINT_PKGIT BLUE " [SKIPPED]" COLOR_RESET
--#define PRINT_WARNING PRINT_PKGIT YELLOW " [WARNING]" COLOR_RESET
--#define PRINT_ERROR PRINT_PKGIT RED " [ERROR]" COLOR_RESET
-+#define PKGIT_PREFIX \
-+ BOLD_YELLOW "[" BOLD_MAGENTA "pkgit" BOLD_YELLOW "] " COLOR_RESET
-+#define PKGIT_PREFIX_SUCCESS PKGIT_PREFIX GREEN "[SUCCESS] " COLOR_RESET
-+#define PKGIT_PREFIX_INFO PKGIT_PREFIX BLUE "[INFO] " COLOR_RESET
-+#define PKGIT_PREFIX_WARNING PKGIT_PREFIX YELLOW "[WARNING] " COLOR_RESET
-+#define PKGIT_PREFIX_ERROR PKGIT_PREFIX RED "[ERROR] " COLOR_RESET
-
- #define MAX_REPOS 1000
- #define MAX_DIRS 100
- #define MAX_PATH_LEN 1024
-
--#include "str.h"
-+typedef struct {
-+ str name, url, version, target, src;
-+ bool is_local;
-+} package_t;
-
- typedef struct {
-- str name;
-- str url;
-- str version;
-- str target;
-- str src;
-- int is_local;
--} package;
--
--extern int is_verbose;
--extern int is_forced;
--extern int config_exists;
--
--extern str home_config_dir;
--extern str home_config_file;
--extern str home_repos_file;
--extern str root_config_dir;
--extern str root_config_file;
--extern str root_repos_file;
--extern int is_root_config;
--
--extern str config_dir;
--extern str config_file;
--extern str repos_file;
--
--extern str bin;
--extern str lib;
--extern str include;
--extern str src;
-+ bool verbose, force;
-+} cli_flags_t;
-+
-+typedef struct {
-+ str dir, name, content, repos;
-+ bool is_root_config;
-+} config_t;
-+
-+typedef struct {
-+ str prefix, bin, lib, include, src;
-+} install_dirs_t;
-+
-+extern cli_flags_t flags;
-+extern config_t cfg;
-+extern install_dirs_t inst_dirs;
-
- void init_vars(void);
- void free_vars(void);
-diff --git a/include/lua_vars.h b/include/lua_vars.h
-index dfc62d0..439a335 100644
---- a/include/lua_vars.h
-+++ b/include/lua_vars.h
-@@ -20,8 +20,10 @@
-
- #ifndef PKGIT_LUA_VARS_H
- #define PKGIT_LUA_VARS_H
--#include <lua.h>
-+
- #include <lauxlib.h>
-+#include <lua.h>
- #include <lualib.h>
-+
- void init_install_directories(void);
- #endif
-diff --git a/include/pkg_create.h b/include/pkg_create.h
-index 908b6fd..95e12c6 100644
---- a/include/pkg_create.h
-+++ b/include/pkg_create.h
-@@ -21,5 +21,5 @@
- #ifndef PKGIT_PKG_CREATE_H
- #define PKGIT_PKG_CREATE_H
- #include "globs.h"
--package pkg_create(str_slc *arg);
-+package_t pkg_create(str_slc arg);
- #endif
-diff --git a/inl b/inl
-deleted file mode 100644
-index e69de29..0000000
-diff --git a/src/files.c b/src/files.c
-index 8903557..7bfc507 100644
---- a/src/files.c
-+++ b/src/files.c
-@@ -19,6 +19,7 @@
- */
-
- #include "files.h"
-+#include <sys/stat.h>
-
- bool file_exists(const char *path) {
- struct stat buffer;
-diff --git a/src/globs.c b/src/globs.c
-index 61d3ea6..519e5f9 100644
---- a/src/globs.c
-+++ b/src/globs.c
-@@ -19,79 +19,46 @@
- */
-
- #include <stdlib.h>
--#include <stdio.h>
-
- #include "globs.h"
-
- #include "files.h"
-+#include "log.h"
- #include "lua_vars.h"
- #include "str.h"
-
--int is_verbose = 1;
--int is_forced = 0;
-+install_dirs_t inst_dirs = {0};
-+cli_flags_t flags = {0};
-+config_t cfg = {0};
-
--int is_root_config = 0;
--str home_config_dir;
--str home_config_file;
--str home_repos_file;
--str root_config_dir;
--str root_config_file;
--str root_repos_file;
--str config_dir;
--str config_file;
--str repos_file;
--
--str prefix_dir;
-+void init_vars(void) {
-+ if (file_exists("/etc/pkgit/repos.lua")) {
-+ cfg.dir = mstr("/etc/pkgit");
-+ cfg.name = mstr("/etc/pkgit/repos.lua");
-
--str bin;
--str lib;
--str include;
--str src;
-+ } else {
-+ const char *tmp = getenv("XDG_CONFIG_HOME");
-+ if (tmp) {
-+ cfg.dir = str_format("%s/pkgit", tmp);
-+ } else {
-+ cfg.dir = str_format("%s/.config/pkgit", getenv("HOME"));
-+ }
-+ cfg.name = str_concat_cstr(&cfg.dir, "/init.lua");
-+ }
-+ // TODO: read into cfg.content
-
--void init_vars(void) {
-- home_config_dir = str_format("%s/.config/pkgit", getenv("HOME"));
-- home_config_file = str_format("%s/init.lua", home_config_dir.data);
-- home_repos_file = str_format("%s/repos.lua", home_config_dir.data);
-- root_config_dir = str_from_cstr("/etc/pkgit");
-- root_config_file = str_format("%s/init.lua", root_config_dir.data);
-- root_repos_file = str_format("%s/repos.lua", root_config_dir.data);
-- str_copy_into(&config_dir, &home_config_dir);
-- if (file_exists(root_config_file.data)) str_copy_into(&config_dir, &root_config_dir);
-- config_file = str_format("%s/init.lua", config_dir.data);
-- repos_file = str_format("%s/repos.lua", config_dir.data);
-+ cfg.repos = str_format("%.*s/repos.lua", str_fmt(&cfg.dir));
- init_install_directories();
- }
-
- void free_vars(void) {
-- str_free(&home_config_dir);
-- str_free(&home_config_file);
-- str_free(&home_repos_file);
-- str_free(&root_config_dir);
-- str_free(&root_config_file);
-- str_free(&root_repos_file);
-- str_free(&config_dir);
-- str_free(&config_file);
-- str_free(&repos_file);
-+ str_free(&cfg.dir);
-+ str_free(&cfg.name);
-+ str_free(&cfg.content);
-+ str_free(&cfg.repos);
-+ str_free(&inst_dirs.prefix);
-+ str_free(&inst_dirs.bin);
-+ str_free(&inst_dirs.lib);
-+ str_free(&inst_dirs.include);
-+ str_free(&inst_dirs.src);
- }
--
--// old init_vars()
--//
--// is_root_config = file_exists(root_config);
--// if (is_root_config) snprintf(config_dir, MAX_PATH_LEN, "/etc/pkgit");
--// else snprintf(config_dir, MAX_PATH_LEN, "%s/.config/pkgit", home_dir);
--//
--// snprintf(config_file, MAX_PATH_LEN, "%s/init.lua", config_dir);
--// snprintf(repo_file, MAX_PATH_LEN, "%s/repos.lua", config_dir);
--//
--// config_exists = file_exists(root_config) || file_exists(home_config());
--//
--// snprintf(bin, MAX_PATH_LEN, "%s/.local/bin", home_dir);
--// snprintf(lib, MAX_PATH_LEN, "%s/.local/lib", home_dir);
--// snprintf(inc, MAX_PATH_LEN, "%s/.local/include", home_dir);
--// snprintf(src, MAX_PATH_LEN, "%s/.local/share/pkgit", home_dir);
--//
--// install_directories[0] = config_dir;
--// install_directories[1] = strdup(get_install_dir("bin"));
--// install_directories[2] = strdup(get_install_dir("lib"));
--// install_directories[3] = strdup(get_install_dir("inc"));
--// install_directories[4] = strdup(get_install_dir("src"));
-diff --git a/src/help.c b/src/help.c
-index 9bd05a2..8580844 100644
---- a/src/help.c
-+++ b/src/help.c
-@@ -33,30 +33,32 @@ void help(void) {
- } flag_t;
-
- static const flag_t cmd_flags[] = {
-- {"-a", "--add", "[url]", "add a repo"},
-- {"-b", "--build", "[path]", "build a package"},
-- {"-d", "--declare", "", "install all packages"},
-- {"-s", "--search", "[pkgs]", "find a package from your repos"},
-- {"-i", "--install", "[pkgs, urls]", "install a package/repo"},
-- {"-r", "--remove", "[pkgs]", "remove an installed package"},
-- {"-l", "--list", "", "list all installed packages"},
-- {"-u", "--update", "", "update all installed packages"},
-- {"-h", "--help", "", "display this help message"},
-- {"-v", "--version", "", "display version number"},
-- {"-c", "--check", "", "run package checks"},
-+ {"-a", "--add", "[url]", "add a repo"},
-+ {"-b", "--build", "[path]", "build a package"},
-+ {"-d", "--declare", "", "install all packages"},
-+ {"-s", "--search", "[pkgs]", "find a package from your repos"},
-+ {"-i", "--install", "[pkgs, urls]", "install a package/repo"},
-+ {"-r", "--remove", "[pkgs]", "remove an installed package"},
-+ {"-l", "--list", "", "list all installed packages"},
-+ {"-u", "--update", "", "update all installed packages"},
-+ {"-h", "--help", "", "display this help message"},
-+ {"-v", "--version", "", "display version number"},
-+ {"-c", "--check", "", "run package checks"},
- };
-
- static const flag_t mod_flags[] = {
-- {"-q", "--quiet", "", "add a repo"},
-- {"-f", "--force", "", "build a package"},
-+ {"-q", "--quiet", "", "add a repo"},
-+ {"-f", "--force", "", "build a package"},
- };
-
-- if (is_verbose) {
-+ if (flags.verbose) {
- printf(BOLD_MAGENTA " , \n");
- printf(BOLD_MAGENTA " / \\ \n");
- printf(BOLD_MAGENTA "_.--' '--._ \n");
-- printf(BOLD_MAGENTA "`'--, ,--'` " COLOR_RESET "pkgit " ITALIC GRAY "- package it!"COLOR_RESET"\n");
-- printf(BOLD_YELLOW " _- " BOLD_MAGENTA "\\ /" BOLD_YELLOW " -_ " MAGENTA VERSION COLOR_RESET "\n");
-+ printf(BOLD_MAGENTA "`'--, ,--'` " COLOR_RESET "pkgit " ITALIC GRAY
-+ "- package it!" COLOR_RESET "\n");
-+ printf(BOLD_YELLOW " _- " BOLD_MAGENTA "\\ /" BOLD_YELLOW
-+ " -_ " MAGENTA VERSION COLOR_RESET "\n");
- printf(BOLD_YELLOW "'-_ " BOLD_MAGENTA "'" BOLD_YELLOW " _-' \n");
- printf(BOLD_YELLOW " `'-.-'` " COLOR_RESET "\n");
- } else {
-@@ -66,14 +68,18 @@ void help(void) {
- printf("\n");
-
- printf(RED "subcommand flags" COLOR_RESET ":\n");
-- for (size_t i = 0; i < sizeof(cmd_flags)/sizeof(cmd_flags[0]); i++) {
-- printf(COLOR_RESET "\t" GREEN "%-2s" COLOR_RESET ", " YELLOW "%-12s" BLUE "%-16s" GRAY "# %s\n" COLOR_RESET,
-- cmd_flags[i].short_flag, cmd_flags[i].long_flag, cmd_flags[i].arg, cmd_flags[i].desc);
-+ for (size_t i = 0; i < sizeof(cmd_flags) / sizeof(cmd_flags[0]); i++) {
-+ printf(COLOR_RESET "\t" GREEN "%-2s" COLOR_RESET ", " YELLOW
-+ "%-12s" BLUE "%-16s" GRAY "# %s\n" COLOR_RESET,
-+ cmd_flags[i].short_flag, cmd_flags[i].long_flag,
-+ cmd_flags[i].arg, cmd_flags[i].desc);
- }
-
- printf("\n" RED "modifier flags" COLOR_RESET ":\n");
-- for (size_t i = 0; i < sizeof(mod_flags)/sizeof(mod_flags[0]); i++) {
-- printf(COLOR_RESET "\t" GREEN "%-2s" COLOR_RESET ", " YELLOW "%-12s" BLUE "%-16s" GRAY "# %s\n" COLOR_RESET,
-- mod_flags[i].short_flag, mod_flags[i].long_flag, mod_flags[i].arg, mod_flags[i].desc);
-+ for (size_t i = 0; i < sizeof(mod_flags) / sizeof(mod_flags[0]); i++) {
-+ printf(COLOR_RESET "\t" GREEN "%-2s" COLOR_RESET ", " YELLOW
-+ "%-12s" BLUE "%-16s" GRAY "# %s\n" COLOR_RESET,
-+ mod_flags[i].short_flag, mod_flags[i].long_flag,
-+ mod_flags[i].arg, mod_flags[i].desc);
- }
- }
-diff --git a/src/lua_globs.c b/src/lua_globs.c
-index f030acb..5a8e51c 100644
---- a/src/lua_globs.c
-+++ b/src/lua_globs.c
-@@ -18,12 +18,11 @@
-
- */
-
--#include <stdio.h>
--
- #include "lua_globs.h"
--
--#include "globs.h"
- #include "files.h"
-+#include "globs.h"
-+#include "log.h"
-+#include "str.h"
-
- lua_State *L = NULL;
- lua_State *B = NULL;
-@@ -34,7 +33,8 @@ void push_lua_path(lua_State *L, const char *new_path) {
- lua_getglobal(L, "package");
- lua_getfield(L, -1, "path");
- const char *current_path = lua_tostring(L, -1);
-- if (!current_path) current_path = "";
-+ if (!current_path)
-+ current_path = "";
- lua_pop(L, 1);
- lua_pushfstring(L, "%s;%s", current_path, new_path);
- lua_setfield(L, -2, "path");
-@@ -42,47 +42,37 @@ void push_lua_path(lua_State *L, const char *new_path) {
- }
-
- void init_lua_state(void) {
-- if (L != NULL) return;
-+ if (L != NULL)
-+ return;
- L = luaL_newstate();
- luaL_openlibs(L);
-- char lua_path[MAX_PATH_LEN + 20];
-- snprintf(lua_path, sizeof(lua_path), "%s/?.lua", config_dir.data);
-- push_lua_path(L, lua_path);
-- if (luaL_loadfile(L, config_file.data) || lua_pcall(L, 0, 0, 0)) {
-- printf(
-- "%s cannot run configuration script: %s\n",
-- PRINT_ERROR, lua_tostring(L, -1)
-- );
-- printf(
-- "%s to generate a configuration file, head into the",
-- PRINT_PKGIT
-- );
-- printf(
-- " root directory of the pkgit source and run `make defconfig`\n"
-- );
-+ str lua_path = str_format("%.*s/?.lua", str_fmt(&cfg.dir));
-+ push_lua_path(L, lua_path.data);
-+ if (luaL_loadfile(L, cfg.name.data) || lua_pcall(L, 0, 0, 0)) {
-+ log_error("cannot run configuration script: %s", lua_tostring(L, -1));
-+ log_pkgit("to generate a configuration file, head into the");
-+ log_pkgit(
-+ "root directory of the pkgit source and run `make defconfig`");
- exit(EXIT_FAILURE);
- }
-- if (file_exists(repos_file.data)) {
-- if (luaL_loadfile(L, repos_file.data) || lua_pcall(L, 0, 0, 0)) {
-- printf(
-- "%s cannot load repository file: %s\n",
-- PRINT_ERROR, lua_tostring(L, -1)
-- );
-+ if (file_exists(cfg.repos.data)) {
-+ if (luaL_loadfile(L, cfg.repos.data) || lua_pcall(L, 0, 0, 0)) {
-+ log_warn("cannot load repository file: %s", lua_tostring(L, -1));
- lua_pop(L, 1);
- }
- }
-+ str_free(&lua_path);
- config_loaded = true;
- }
-
- void init_bldit(void) {
-- if (B != NULL) return;
-+ if (B != NULL)
-+ return;
- B = luaL_newstate();
- luaL_openlibs(B);
- if (luaL_loadfile(B, "bldit.lua") || lua_pcall(B, 0, 0, 0)) {
-- if (is_verbose) printf(
-- "%s cannot run bldit script: %s\n",
-- PRINT_WARNING, lua_tostring(B, -1)
-- );
-+ if (flags.verbose)
-+ log_warn("cannot run bldit: %s", lua_tostring(B, -1));
- return;
- }
- bldit_loaded = true;
-@@ -96,11 +86,11 @@ void free_lua_state(void) {
- config_loaded = false;
- }
-
--lua_State *get_lua_state(void) { return L; }
-+lua_State *get_lua_state(void) {
-+ return L;
-+}
-
--void lua_isnt_type(char* variable, char* type) {
-- if (is_verbose) printf(
-- "%s init.lua: '%s' is not a %s.\n",
-- PRINT_ERROR, variable, type
-- );
-+void lua_isnt_type(char *variable, char *type) {
-+ if (flags.verbose)
-+ log_error("init.lua: '%s' is not a %s.", variable, type);
- }
-diff --git a/src/lua_vars.c b/src/lua_vars.c
-index 3519d7a..3fd2ddb 100644
---- a/src/lua_vars.c
-+++ b/src/lua_vars.c
-@@ -20,8 +20,8 @@
-
- #include "lua_vars.h"
-
--#include "lua_globs.h"
- #include "globs.h"
-+#include "lua_globs.h"
-
- void init_install_directories(void) {
- init_lua_state();
-@@ -32,37 +32,26 @@ void init_install_directories(void) {
- lua_isnt_type("install_directories", "table");
- return;
- }
-- //lua_pop(L, 1);
-
-- lua_getfield(L, -1, "bin");
-- if (!lua_isstring(L, -1)) {
-- lua_isnt_type("install_directories.bin", "string");
-- } else {
-- str_copy_cstr_into(&bin, lua_tostring(L, -1));
-- }
-- lua_pop(L, 1);
-+#define SETUP_INST_DIRS \
-+ X(bin) \
-+ X(lib) \
-+ X(include) \
-+ X(src)
-+
-+#define X(dir) \
-+ do { \
-+ lua_getfield(L, -1, #dir); \
-+ if (!lua_isstring(L, -1)) { \
-+ lua_isnt_type("install_directories." #dir, "string"); \
-+ } else { \
-+ str_copy_cstr_into(&inst_dirs.dir, lua_tostring(L, -1)); \
-+ } \
-+ lua_pop(L, 1); \
-+ } while (0);
-+
-+ SETUP_INST_DIRS
-+#undef X
-
-- lua_getfield(L, -1, "lib");
-- if (!lua_isstring(L, -1)) {
-- lua_isnt_type("install_directories.lib", "string");
-- } else {
-- str_copy_cstr_into(&lib, lua_tostring(L, -1));
-- }
-- lua_pop(L, 1);
--
-- lua_getfield(L, -1, "include");
-- if (!lua_isstring(L, -1)) {
-- lua_isnt_type("install_directories.include", "string");
-- } else {
-- str_copy_cstr_into(&include, lua_tostring(L, -1));
-- }
-- lua_pop(L, 1);
--
-- lua_getfield(L, -1, "src");
-- if (!lua_isstring(L, -1)) {
-- lua_isnt_type("install_directories.src", "string");
-- } else {
-- str_copy_cstr_into(&src, lua_tostring(L, -1));
-- }
- lua_pop(L, 1);
- }
-diff --git a/src/main.c b/src/main.c
-index 893e944..b8b9735 100644
---- a/src/main.c
-+++ b/src/main.c
-@@ -18,17 +18,16 @@
-
- */
-
--//#include "cla_parse.h"
-+// #include "cla_parse.h"
-+#include "globs.h"
- #include "pkg_create.h"
- #include "str.h"
--#include "globs.h"
-
--int main(int argc, char** argv) {
-+int main(int argc, char **argv) {
- (void)argc;
- init_vars();
-- str_slc arg = str_slc_from_cstr(argv[1]);
-- pkg_create(&arg);
-- //cla_parse(argc, argv);
-+ pkg_create(mstrslc(argv[1]));
-+ // cla_parse(argc, argv);
- free_vars();
- return 0;
- }
-diff --git a/src/pkg_create.c b/src/pkg_create.c
-index 79b4a78..9e3e765 100644
---- a/src/pkg_create.c
-+++ b/src/pkg_create.c
-@@ -1,6 +1,6 @@
- /*
-
-- pkgit - package it!
-+ pkgit - package_t it!
-
- Copyright (C) 2026 dacctal
- This program is free software: you can redistribute it and/or modify
-@@ -18,101 +18,79 @@
-
- */
-
--#include <unistd.h>
- #include <string.h>
--
--#include "pkg_create.h"
-+#include <unistd.h>
-
- #include "files.h"
- #include "globs.h"
-+#include "log.h"
-+#include "pkg_create.h"
- #include "str.h"
-
- static str get_destdir(str_slc cwd, str_slc arg) {
-- str destdir;
-- if (str_slc_first(arg) == '.') {
-- str_format_into(
-- &destdir, "%s/%s",
-- src, str_slc_from_after_delim(cwd, '/')
-- );
-- } else {
-- str_format_into(
-- &destdir, "%s/%s",
-- src, arg
-- );
-- }
-- return destdir;
-+ str_slc name = str_slc_from_after_delim(arg, '/');
-+ if (str_slc_first(arg) == '.')
-+ return str_format("%.*s/%.*s", str_fmt(&inst_dirs.src), str_fmt(&cwd));
-+ else
-+ return str_format("%.*s/%.*s", str_fmt(&inst_dirs.src), str_fmt(&name));
- }
-
--static str get_pkgsrc(package pkg) {
-- str src_dir;
-- if (pkg.is_local == 1) {
-- str_format_into(
-- &src_dir, "%s/%s",
-- src, pkg.name
-- );
-- } else {
-- str_format_into(
-- &src_dir, "%s/%s/%s",
-- src, pkg.name, pkg.version
-- );
-- }
-- return src_dir;
-+static str get_pkgsrc(package_t pkg) {
-+ if (pkg.is_local == 1)
-+ return str_format("%.*s/%.*s", str_fmt(&inst_dirs.src), pkg.name);
-+ else
-+ return str_format("%.*s/%.*s/%.*s", str_fmt(&inst_dirs.src),
-+ str_fmt(&pkg.name), str_fmt(&pkg.version));
- }
-
--package pkg_create(str_slc *arg) {
-- package pkg;
-- pkg.version = (str) {
-- .data = "HEAD",
-- .len = 4,
-- .cap = 4,
-+package_t pkg_create(str_slc arg) {
-+ package_t pkg = {
-+ .version = mstr("HEAD"),
-+ .is_local = false,
- };
-- pkg.is_local = false;
-+
- char cwd[MAX_PATH_LEN];
- getcwd(cwd, MAX_PATH_LEN);
-+
- str_slc cwd_slc = mstrslc(cwd);
- str cwd_str = mstr(cwd);
-- str_slc new_arg;
-- new_arg.data = arg->data;
-- new_arg.len = arg->len;
-- if (!new_arg.data) exit(EXIT_FAILURE);
-- str dest_dir = get_destdir(cwd_slc, new_arg);
-+ str dest_dir = get_destdir(cwd_slc, arg);
-+ str new_arg_str = str_from_str_slc(arg);
-+
- bool is_installed_locally = is_directory(dest_dir.data);
-
-- str new_arg_str = str_from_str_slc(new_arg);
- pkg.version = str_from_after_delim(&new_arg_str, '@');
-- str_println(&pkg.version);
- pkg.target = str_from_after_delim(&new_arg_str, ',');
-- str_println(&pkg.target);
-
- bool is_in_repos = false;
-- //for (size_t i = 0; i < cached_repos_count; i++) {
-+ // for (size_t i = 0; i < cached_repos_count; i++) {
- // if (strcmp(new_arg, cached_repos[i].source_key) == 0) {
- // is_in_repos = true;
- // break;
- // }
-- //}
-+ // }
-
-- if (strncmp(new_arg.data, "http", 4) == 0 || strncmp(new_arg.data, "ssh", 3) == 0) {
-+ if (strncmp(arg.data, "http", 4) == 0 || strncmp(arg.data, "ssh", 3) == 0) {
- pkg.url = new_arg_str;
- pkg.name = str_from_after_delim(&new_arg_str, '/');
-- } else if (strcmp(new_arg.data, ".") == 0) {
-- pkg.url = str_from_cstr("");
-+ } else if (str_slc_equal_cstr(arg, ".")) {
-+ pkg.url = mstr("");
- pkg.name = str_from_after_delim(&cwd_str, '/');
- pkg.is_local = true;
- } else if (is_in_repos) {
-- //for (size_t i = 0; i < cached_repos_count; i++) {
-- // if (strcmp(new_arg, cached_repos[i].source_key) == 0) {
-- // pkg.url = strdup(cached_repos[i].source_value);
-- // break;
-- // }
-- //}
-- pkg.name = new_arg_str;
-+ // for (size_t i = 0; i < cached_repos_count; i++) {
-+ // if (strcmp(new_arg, cached_repos[i].source_key) == 0) {
-+ // pkg.url = strdup(cached_repos[i].source_value);
-+ // break;
-+ // }
-+ // }
-+ pkg.name = new_arg_str;
- } else if (is_installed_locally) {
-- pkg.url = str_from_cstr("");
-+ pkg.url = mstr("");
- pkg.name = str_from_after_delim(&dest_dir, '/');
- pkg.is_local = true;
- } else {
-- printf("%s '%.*s' is not a valid package\n", PRINT_ERROR, str_fmt(&new_arg));
-+ log_error("'%.*s' is not a valid package", str_fmt(&arg));
- exit(EXIT_FAILURE);
- }
- pkg.src = get_pkgsrc(pkg);
-diff --git a/src/str.c b/src/str.c
-index 9e67b4a..c845ed5 100644
---- a/src/str.c
-+++ b/src/str.c
-@@ -44,15 +44,21 @@ along with this program.If not, see <https://www.gnu.org/licenses/>.
-
- // XXX: INTERNAL USE ONLY
- #define _strslc(str) \
-- (str_slc) { str->data, str->len }
-+ (str_slc) { \
-+ str->data, str->len \
-+ }
- #define _cstrslc(str) \
-- (str_slc) { str, strlen(str) }
-+ (str_slc) { \
-+ str, strlen(str) \
-+ }
- // XXX: since msvc/tcc and I presume cproc aren't smart enough to inline calls
- // where a str calls a str_slc function and vice versa, we optimize things
- // ourselves+reduce boilerplate
- #define _STRINGS_EQUAL
-
--str str_new(void) { return str_new_with_capacity(16); }
-+str str_new(void) {
-+ return str_new_with_capacity(16);
-+}
-
- str str_new_with_capacity(size_t cap) {
- str res = {0};
-@@ -62,9 +68,13 @@ str str_new_with_capacity(size_t cap) {
- return res;
- }
-
--str str_from_cstr(const char *s) { return str_from_str_slc(_cstrslc(s)); }
-+str str_from_cstr(const char *s) {
-+ return str_from_str_slc(_cstrslc(s));
-+}
-
--str mstr(const char *s) { return str_from_str_slc(_cstrslc(s)); }
-+str mstr(const char *s) {
-+ return str_from_str_slc(_cstrslc(s));
-+}
-
- str str_from_str_slc(const str_slc s) {
- str res = str_new_with_capacity(s.len + 1);
-@@ -429,13 +439,21 @@ size_t str_find_char_right(const str *s, char c) {
- return str_slc_find_char_right(_strslc(s), c);
- }
-
--void str_print(const str *s) { printf("%.*s", str_fmt(s)); }
-+void str_print(const str *s) {
-+ printf("%.*s", str_fmt(s));
-+}
-
--void str_println(const str *s) { printf("%.*s\n", str_fmt(s)); }
-+void str_println(const str *s) {
-+ printf("%.*s\n", str_fmt(s));
-+}
-
--void str_fprint(const str *s, FILE *f) { fprintf(f, "%.*s", str_fmt(s)); }
-+void str_fprint(const str *s, FILE *f) {
-+ fprintf(f, "%.*s", str_fmt(s));
-+}
-
--void str_fprintln(const str *s, FILE *f) { fprintf(f, "%.*s\n", str_fmt(s)); }
-+void str_fprintln(const str *s, FILE *f) {
-+ fprintf(f, "%.*s\n", str_fmt(s));
-+}
-
- str str_read_line_from_file(FILE *f) {
- size_t len = 0;
-@@ -475,11 +493,17 @@ bool str_write_to_file(const str *s, FILE *f) {
-
- // === str_slc implementation ===
-
--str_slc str_slc_from_str(const str *s) { return _strslc(s); }
-+str_slc str_slc_from_str(const str *s) {
-+ return _strslc(s);
-+}
-
--str_slc str_slc_from_cstr(const char *s) { return _cstrslc(s); }
-+str_slc str_slc_from_cstr(const char *s) {
-+ return _cstrslc(s);
-+}
-
--str_slc mstrslc(const char *s) { return (str_slc){s, strlen(s)}; }
-+str_slc mstrslc(const char *s) {
-+ return (str_slc){s, strlen(s)};
-+}
-
- str str_slc_concat(const str_slc lhs, const str_slc rhs) {
- str res = str_new();
-@@ -684,9 +708,13 @@ char str_slc_at(const str_slc s, size_t i) {
- return s.data[i];
- }
-
--void str_slc_print(const str_slc s) { printf("%.*s", str_fmt(&s)); }
-+void str_slc_print(const str_slc s) {
-+ printf("%.*s", str_fmt(&s));
-+}
-
--void str_slc_println(const str_slc s) { printf("%.*s\n", str_fmt(&s)); }
-+void str_slc_println(const str_slc s) {
-+ printf("%.*s\n", str_fmt(&s));
-+}
-
- void str_slc_fprint(const str_slc s, FILE *f) {
- fprintf(f, "%.*s", str_fmt(&s));
-@@ -717,27 +745,23 @@ ptrdiff_t str_slc_find_char_right(const str_slc s, char c) {
- str str_from_after_delim(str *arg, char delimiter) {
- size_t i = str_find_char_right(arg, delimiter);
- str res = str_slice_to_str(arg, i + 1, arg->len);
-- str_println(&res);
- return res;
- }
-
- str str_from_before_delim(str *arg, char delimiter) {
- size_t i = str_find_char(arg, delimiter);
- str res = str_slice_to_str(arg, i + 1, arg->len);
-- str_println(&res);
- return res;
- }
-
- str_slc str_slc_from_after_delim(str_slc arg, char delimiter) {
- size_t i = str_slc_find_char_right(arg, delimiter);
- str_slc res = str_slc_slice(arg, i + 1, arg.len);
-- str_slc_println(res);
- return res;
- }
-
- str_slc str_slc_from_before_delim(str_slc arg, char delimiter) {
- size_t i = str_slc_find_char(arg, delimiter);
- str_slc res = str_slc_slice(arg, i + 1, arg.len);
-- str_slc_println(res);
- return res;
- }
diff --git a/src/cla_parse.c b/src/cla_parse.c
index ab1e44c..4d824f4 100644
--- a/src/cla_parse.c
+++ b/src/cla_parse.c
@@ -31,7 +31,7 @@
#include "help.h"
// #include "name_from_url.h"
// #include "pkg_build.h"
-#include "pkg/create.h"
+#include "pkg.h"
// #include "pkg_search.h"
// #include "pkg_install.h"
// #include "pkg_list.h"
@@ -40,9 +40,8 @@
// #include "repo_add.h"
// #include "update.h"
-#define COMMAND(arg, large, small, code) \
- if (strcmp(arg, large) == 0 || strcmp(arg, small) == 0) \
- code
+#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))
@@ -59,7 +58,8 @@ void cmd_add(char **argv, int i) {
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;
+ if (argv[j][0] == '-')
+ continue;
printf("build pkg %s\n", argv[j]);
// str_slc arg = mstrslc(argv[j]);
// package_t pkg = pkg_create(arg);
@@ -76,7 +76,8 @@ void cmd_build(int argc, char **argv, int i) {
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;
+ if (argv[j][0] == '-')
+ continue;
printf("install pkg %s\n", argv[j]);
// str_slc arg = mstrslc(argv[j]);
// package_t pkg = pkg_create(arg);
@@ -90,7 +91,8 @@ void cmd_install(int argc, char **argv, int i) {
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;
+ if (argv[j][0] == '-')
+ continue;
printf("remove pkg %s\n", argv[j]);
// str_slc arg = mstrslc(argv[j]);
// package_t pkg = pkg_create(arg);
@@ -160,10 +162,14 @@ void flags_cmd(int argc, char **argv, int i) {
void flags_parse(int argc, char **argv) {
for (int i = 1; i < argc; i++) {
- if (argv[i][0] != '-') continue;
+ if (argv[i][0] != '-')
+ continue;
if (argv[i][1] == '-') {
- COMMAND(argv[i], "--quiet", "-q", { flags.verbose = false; });
- COMMAND(argv[i], "--force", "-f", { flags.force = true; });
+ if (COMMAND("--quiet", "-q"))
+ flags.verbose = false;
+ if (COMMAND("--force", "-f")) {
+ flags.force = true;
+ };
} else {
flags_mod(argv, i);
flags_cmd(argc, argv, i);
@@ -173,22 +179,48 @@ void flags_parse(int argc, char **argv) {
void cmds_parse(int argc, char **argv) {
for (int i = 1; i < argc; i++) {
- COMMAND(argv[i], "--add", "a", { cmd_add(argv, i); });
- COMMAND(argv[i], "--build", "b", { cmd_build(argc, argv, i); });
- COMMAND(argv[i], "--install", "i", { cmd_install(argc, argv, i); });
- COMMAND(argv[i], "--remove", "r", { cmd_remove(argc, argv, i); });
- COMMAND(argv[i], "--update", "u", {/*update();*/});
- COMMAND(argv[i], "--declare", "d", {/*declare();*/});
- COMMAND(argv[i], "--list", "l", {/*pkgs_list();*/});
- COMMAND(argv[i], "--search", "s", {/*search(argv[i + 1]);*/});
- COMMAND(argv[i], "--version", "v", { printf("%s\n", VERSION); });
- COMMAND(argv[i], "--help", "h", { help(); });
- COMMAND(argv[i], "--check", "c", {/*deps_resolve();*/});
+ 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) {
- if (!argv[1]) {
+ // default
+ flags.force = false;
+ flags.verbose = true;
+ if (argc == 1) {
help();
return;
}
diff --git a/src/globs.c b/src/globs.c
index 519e5f9..860bafb 100644
--- a/src/globs.c
+++ b/src/globs.c
@@ -35,7 +35,6 @@ void init_vars(void) {
if (file_exists("/etc/pkgit/repos.lua")) {
cfg.dir = mstr("/etc/pkgit");
cfg.name = mstr("/etc/pkgit/repos.lua");
-
} else {
const char *tmp = getenv("XDG_CONFIG_HOME");
if (tmp) {
diff --git a/src/help.c b/src/help.c
index 8580844..bacdcd9 100644
--- a/src/help.c
+++ b/src/help.c
@@ -62,13 +62,14 @@ void help(void) {
printf(BOLD_YELLOW "'-_ " BOLD_MAGENTA "'" BOLD_YELLOW " _-' \n");
printf(BOLD_YELLOW " `'-.-'` " COLOR_RESET "\n");
} else {
- printf("pkgit %s%s- package it!%s\n", ITALIC, GRAY, COLOR_RESET);
- printf("%s%s%s\n", MAGENTA, VERSION, COLOR_RESET);
+ printf(BOLD "pkgit " COLOR_RESET ITALIC GRAY "- package it!" COLOR_RESET
+ "\n");
+ printf("version " MAGENTA VERSION COLOR_RESET "\n");
}
printf("\n");
printf(RED "subcommand flags" COLOR_RESET ":\n");
- for (size_t i = 0; i < sizeof(cmd_flags) / sizeof(cmd_flags[0]); i++) {
+ for (size_t i = 0; i < LENGTH(cmd_flags); i++) {
printf(COLOR_RESET "\t" GREEN "%-2s" COLOR_RESET ", " YELLOW
"%-12s" BLUE "%-16s" GRAY "# %s\n" COLOR_RESET,
cmd_flags[i].short_flag, cmd_flags[i].long_flag,
@@ -76,7 +77,7 @@ void help(void) {
}
printf("\n" RED "modifier flags" COLOR_RESET ":\n");
- for (size_t i = 0; i < sizeof(mod_flags) / sizeof(mod_flags[0]); i++) {
+ for (size_t i = 0; i < LENGTH(mod_flags); i++) {
printf(COLOR_RESET "\t" GREEN "%-2s" COLOR_RESET ", " YELLOW
"%-12s" BLUE "%-16s" GRAY "# %s\n" COLOR_RESET,
mod_flags[i].short_flag, mod_flags[i].long_flag,
diff --git a/src/lua_globs.c b/src/lua_globs.c
index 5a8e51c..d6bd353 100644
--- a/src/lua_globs.c
+++ b/src/lua_globs.c
@@ -18,10 +18,12 @@
*/
-#include "lua_globs.h"
+#include <stdlib.h>
+
#include "files.h"
#include "globs.h"
#include "log.h"
+#include "lua_globs.h"
#include "str.h"
lua_State *L = NULL;
diff --git a/src/main.c b/src/main.c
index 5ac5bde..f67ef9d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -19,14 +19,16 @@
*/
// #include "cla_parse.h"
+#include "pkg.h"
#include "globs.h"
-#include "pkg_create.h"
#include "str.h"
int main(int argc, char **argv) {
(void)argc;
init_vars();
package_t pkg = pkg_create(mstrslc(argv[1]));
+ str_println(&pkg.name);
+ pkg_free(&pkg);
// cla_parse(argc, argv);
free_vars();
return 0;
diff --git a/src/pkg/.clangd b/src/pkg/.clangd
deleted file mode 100644
index 5022e8f..0000000
--- a/src/pkg/.clangd
+++ /dev/null
@@ -1,4 +0,0 @@
-CompileFlags:
- Add: [-I/usr/include/luajit-2.1, -I../include]
----
-UseTab: Always
diff --git a/src/pkg/create.c b/src/pkg_create.c
index 9e3e765..9517868 100644
--- a/src/pkg/create.c
+++ b/src/pkg_create.c
@@ -21,10 +21,11 @@
#include <string.h>
#include <unistd.h>
+#include "pkg.h"
+
#include "files.h"
#include "globs.h"
#include "log.h"
-#include "pkg_create.h"
#include "str.h"
static str get_destdir(str_slc cwd, str_slc arg) {
@@ -40,7 +41,7 @@ static str get_pkgsrc(package_t pkg) {
return str_format("%.*s/%.*s", str_fmt(&inst_dirs.src), pkg.name);
else
return str_format("%.*s/%.*s/%.*s", str_fmt(&inst_dirs.src),
- str_fmt(&pkg.name), str_fmt(&pkg.version));
+ str_fmt(&pkg.name), str_fmt(&pkg.version));
}
package_t pkg_create(str_slc arg) {
diff --git a/src/pkg_free.c b/src/pkg_free.c
new file mode 100644
index 0000000..2b1d670
--- /dev/null
+++ b/src/pkg_free.c
@@ -0,0 +1,9 @@
+#include "pkg.h"
+
+void pkg_free(package_t *pkg) {
+ str_free(&pkg->name);
+ str_free(&pkg->url);
+ str_free(&pkg->version);
+ str_free(&pkg->target);
+ str_free(&pkg->src);
+}
diff --git a/src/str.c b/src/str.c
index c845ed5..67fd709 100644
--- a/src/str.c
+++ b/src/str.c
@@ -160,12 +160,13 @@ void str_ncopy_into(str *dest, const str *src, size_t count) {
}
void str_ncopy_cstr_into(str *dest, const char *src, size_t count) {
- assert_str_is_valid(dest);
assert(src);
- dest->len = count;
- if (dest->cap < count + 1)
+ if (!str_is_valid(dest))
+ *dest = str_new_with_capacity(count + 1);
+ else if (dest->cap < count + 1)
str_reserve_exact(dest, count + 1);
memcpy(dest->data, src, count);
+ dest->len = count;
dest->data[count] = 0;
}
@@ -743,15 +744,21 @@ ptrdiff_t str_slc_find_char_right(const str_slc s, char c) {
}
str str_from_after_delim(str *arg, char delimiter) {
- size_t i = str_find_char_right(arg, delimiter);
- str res = str_slice_to_str(arg, i + 1, arg->len);
- return res;
+ return str_from_after_delim_str_slc(_strslc(arg), delimiter);
+}
+
+str str_from_after_delim_str_slc(str_slc arg, char delimiter) {
+ size_t i = str_slc_find_char_right(arg, delimiter);
+ return str_slc_slice_to_str(arg, i + 1, arg.len);
}
str str_from_before_delim(str *arg, char delimiter) {
- size_t i = str_find_char(arg, delimiter);
- str res = str_slice_to_str(arg, i + 1, arg->len);
- return res;
+ return str_from_before_delim_str_slc(_strslc(arg), delimiter);
+}
+
+str str_from_before_delim_str_slc(str_slc arg, char delimiter) {
+ size_t i = str_slc_find_char(arg, delimiter);
+ return str_slc_slice_to_str(arg, i + 1, arg.len);
}
str_slc str_slc_from_after_delim(str_slc arg, char delimiter) {