From fe3caeefac7a2081f5c9db90bf5c821624a71082 Mon Sep 17 00:00:00 2001 From: dacctal Date: Wed, 1 Jul 2026 11:08:21 +0000 Subject: checkpoint! --- .clang-format | 321 +++++++++++++++++++++++++++++++++++++++++++++++++++ .clangd | 4 + cla_parse.c | 199 ------------------------------- include/log.h | 17 +++ include/pkg/create.h | 25 ++++ include/pkg_create.h | 25 ---- include/vec.h | 98 ++++++++++++++++ src/.clangd | 4 - src/cla_parse.c | 197 +++++++++++++++++++++++++++++++ src/log.c | 19 +++ src/main.c | 2 +- src/pkg/.clangd | 4 + src/pkg/create.c | 98 ++++++++++++++++ src/pkg_create.c | 98 ---------------- 14 files changed, 784 insertions(+), 327 deletions(-) create mode 100644 .clang-format create mode 100644 .clangd delete mode 100644 cla_parse.c create mode 100644 include/log.h create mode 100644 include/pkg/create.h delete mode 100644 include/pkg_create.h create mode 100644 include/vec.h delete mode 100644 src/.clangd create mode 100644 src/cla_parse.c create mode 100644 src/log.c create mode 100644 src/pkg/.clangd create mode 100644 src/pkg/create.c delete mode 100644 src/pkg_create.c diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..a729ffe --- /dev/null +++ b/.clang-format @@ -0,0 +1,321 @@ +--- +Language: Cpp +AlignAfterOpenBracket: true +AccessModifierOffset: -2 +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: true + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveShortCaseStatements: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCaseArrows: false + AlignCaseColons: false +AlignConsecutiveTableGenBreakingDAGArgColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveTableGenCondOperatorColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveTableGenDefinitionColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + AlignFunctionPointers: false + PadOperators: false +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 +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AllowShortNamespacesOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AttributeMacros: + - __capability +BinPackArguments: true +BinPackLongBracedList: true +BinPackParameters: BinPack +BitFieldColonSpacing: Both +BracedInitializerIndentWidth: -1 +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterExternBlock: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +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 +BreakBeforeTemplateCloser: false +BreakBeforeTernaryOperators: true +BreakBinaryOperations: Never +BreakConstructorInitializers: BeforeColon +BreakFunctionDefinitionParameters: false +BreakInheritanceList: BeforeColon +BreakStringLiterals: true +BreakTemplateDeclarations: MultiLine +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: AlignFirstComment +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +EnumTrailingComma: Leave +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: false +IndentExportBlock: true +IndentExternBlock: AfterExternBlock +IndentGotoLabels: true +IndentPPDirectives: None +IndentRequiresClause: true +IndentWidth: 4 +IndentWrappedFunctionNames: false +InsertBraces: false +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 + DecimalMinDigits: 0 + HexMinDigits: 0 +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLines: + AtEndOfFile: false + AtStartOfBlock: true + AtStartOfFile: true +KeepFormFeed: false +LambdaBodyIndentation: Signature +LineEnding: DeriveLF +MacroBlockBegin: '' +MacroBlockEnd: '' +MainIncludeChar: Quote +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +NumericLiteralCase: + ExponentLetter: Leave + HexDigit: Leave + Prefix: Leave + Suffix: Leave +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +OneLineFormatOffRegex: '' +PackConstructorInitializers: BinPack +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakBeforeMemberAccess: 150 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakScopeResolution: 500 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +PPIndentWidth: -1 +QualifierAlignment: Leave +ReferenceAlignment: Pointer +ReflowComments: Always +RemoveBracesLLVM: false +RemoveEmptyLinesInUnwrappedLines: false +RemoveParentheses: Leave +RemoveSemicolon: false +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SkipMacroDefinitionBody: false +SortIncludes: + Enabled: true + IgnoreCase: false + IgnoreExtension: false +SortJavaStaticImport: Before +SortUsingDeclarations: LexicographicNumeric +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterOperatorKeyword: false +SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeJsonColon: false +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterNot: false + AfterOverloadedOperator: false + AfterPlacementOperator: true + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBraces: Never +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInContainerLiterals: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParens: Never +SpacesInParensOptions: + ExceptDoubleParentheses: false + InCStyleCasts: false + InConditionalStatements: false + InEmptyParentheses: false + Other: false +SpacesInSquareBrackets: false +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TableGenBreakInsideDAGArg: DontBreak +TabWidth: 4 +UseTab: Always +VerilogBreakBetweenInstancePorts: true +WhitespaceSensitiveMacros: + - BOOST_PP_STRINGIZE + - CF_SWIFT_NAME + - NS_SWIFT_NAME + - PP_STRINGIZE + - STRINGIZE +WrapNamespaceBodyWithEmptyLines: Leave +... + diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..5022e8f --- /dev/null +++ b/.clangd @@ -0,0 +1,4 @@ +CompileFlags: + Add: [-I/usr/include/luajit-2.1, -I../include] +--- +UseTab: Always diff --git a/cla_parse.c b/cla_parse.c deleted file mode 100644 index 8d5db4f..0000000 --- a/cla_parse.c +++ /dev/null @@ -1,199 +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 "str.h" -// #include "declare.h" -// #include "deps_resolve.h" -#include "help.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" - -#define COMMAND(arg, large, small, code) \ - if (strcmp(arg, large) == 0 || strcmp(arg, small) == 0) \ - code - -#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, package pkg) { - if (argv[i + 1]) { - for (int j = i + 1; j < argc; j++) { - if (argv[j][0] == '-') - continue; - printf("build pkg %s\n", argv[j]); - // pkg = pkg_create(argv[j]); - // pkg_build(pkg); - } - } else { - printf("build pkg .\n"); - // 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; - printf("install pkg %s\n", argv[j]); - // pkg = pkg_create(argv[j]); - // pkg_install(pkg); - } - } else { - // 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; - printf("remove pkg %s\n", argv[j]); - // pkg = pkg_create(argv[j]); - // 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': - is_verbose = 0; - break; - case 'f': - is_forced = 1; - break; - default: - break; - } - } -} - -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; - } - } -} - -void flags_parse(int argc, char **argv, package pkg) { - for (int i = 1; i < argc; i++) { - 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; }); - COMMAND(argv[i], "--force", "-f", { is_forced = 1; }); - } else { - flags_mod(argv, i); - flags_cmd(argc, argv, i, 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();*/}); - } -} - -void cla_parse(int argc, char **argv) { - if (!argv[1]) { - help(); - return; - } - package pkg = {0}; - flags_parse(argc, argv, pkg); - cmds_parse(argc, argv, pkg); -} diff --git a/include/log.h b/include/log.h new file mode 100644 index 0000000..5b275cc --- /dev/null +++ b/include/log.h @@ -0,0 +1,17 @@ +#ifndef PKGIT_LOG_H +#define PKGIT_LOG_H + +// XXX: im lazy. +#define PKGIT_PREFIX_PKGIT PKGIT_PREFIX +#define LOG_FUNCTIONS \ + X(error, ERROR) \ + X(warn, WARNING) \ + X(info, INFO) \ + X(success, SUCCESS) \ + X(pkgit, PKGIT) + +#endif + +#define X(n, N) void log_##n(const char *format, ...); +LOG_FUNCTIONS +#undef X diff --git a/include/pkg/create.h b/include/pkg/create.h new file mode 100644 index 0000000..95e12c6 --- /dev/null +++ b/include/pkg/create.h @@ -0,0 +1,25 @@ +/* + + 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_PKG_CREATE_H +#define PKGIT_PKG_CREATE_H +#include "globs.h" +package_t pkg_create(str_slc arg); +#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 . - -*/ - -#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/vec.h b/include/vec.h new file mode 100644 index 0000000..498fac4 --- /dev/null +++ b/include/vec.h @@ -0,0 +1,98 @@ +/* + + 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_VEC_H +#define PKGIT_VEC_H + +#include +#include +#include +#include + +#define VEC_INITIAL_SIZE 5 + +#define VEC_DECL(T, name) \ + typedef struct { \ + T *data; \ + size_t len; \ + size_t cap; \ + } name + +#define vec_append(v, item) \ + do { \ + if ((v)->len + 1 > (v)->cap) { \ + if ((v)->cap == 0) \ + (v)->cap = VEC_INITIAL_SIZE; \ + else \ + (v)->cap += ((v)->cap >> 1); \ + (v)->data = realloc((v)->data, sizeof(*(v)->data) * (v)->cap); \ + check_alloc((v)->data); \ + } \ + (v)->data[(v)->len++] = (item); \ + } while (0) + +#define vec_clear(v) \ + do { \ + memset((v)->data, 0, sizeof(*(v)->data) * (v)->cap); \ + (v)->len = 0; \ + } while (0) + +#define vec_free(v) \ + do { \ + if ((v)->data) { \ + free((v)->data); \ + (v)->data = NULL; \ + } \ + } while (0) + +#define vec_reserve(v, amt) \ + do { \ + if (amt >= (v)->len) { \ + (v)->data = realloc((v)->data, sizeof(*(v)->data) * amt); \ + check_alloc((v)->data); \ + (v)->cap = amt; \ + } \ + } while (0) + +#define vec_append_many(v, itms, itms_len) \ + do { \ + if ((v)->len + itms_len > (v)->cap) { \ + (v)->cap += itms_len; \ + (v)->data = realloc((v)->data, sizeof(*(v)->data) * (v)->cap); \ + check_alloc((v)->data); \ + } \ + memcpy(&(v)->data[(v)->len], itms, sizeof(*(v)->data) * itms_len); \ + (v)->len += itms_len; \ + } while (0) + +#define vec_last(v) ((v)->data[(assert((v)->len > 0), (v)->len - 1)]) + +#define vec_at(v, pos) \ + ((v)->data[(assert(0 <= (pos) && (pos) < (v)->len), pos)]) + +#define vec_pop(v) ((v)->data[(assert((v)->len > 0), --(v)->len)]) + +#define vec_pop_many(v, count) \ + do { \ + assert(count < (v)->len); \ + (v)->len -= count; \ + } while (0) + +#endif // PKGIT_VEC_H diff --git a/src/.clangd b/src/.clangd deleted file mode 100644 index 5022e8f..0000000 --- a/src/.clangd +++ /dev/null @@ -1,4 +0,0 @@ -CompileFlags: - Add: [-I/usr/include/luajit-2.1, -I../include] ---- -UseTab: Always diff --git a/src/cla_parse.c b/src/cla_parse.c new file mode 100644 index 0000000..ab1e44c --- /dev/null +++ b/src/cla_parse.c @@ -0,0 +1,197 @@ +/* + + 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/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" + +#define COMMAND(arg, large, small, code) \ + if (strcmp(arg, large) == 0 || strcmp(arg, small) == 0) \ + code + +#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] == '-') { + COMMAND(argv[i], "--quiet", "-q", { flags.verbose = false; }); + COMMAND(argv[i], "--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++) { + 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();*/}); + } +} + +void cla_parse(int argc, char **argv) { + if (!argv[1]) { + help(); + return; + } + flags_parse(argc, argv); + cmds_parse(argc, argv); +} diff --git a/src/log.c b/src/log.c new file mode 100644 index 0000000..078afde --- /dev/null +++ b/src/log.c @@ -0,0 +1,19 @@ + +#include +#include + +#include "globs.h" +#include "log.h" + +#define X(n, N) \ + void log_##n(const char *format, ...) { \ + va_list args; \ + va_start(args, format); \ + eprintf(PKGIT_PREFIX_##N); \ + vfprintf(stderr, format, args); \ + eprintf("\n"); \ + va_end(args); \ + } + +LOG_FUNCTIONS +#undef X diff --git a/src/main.c b/src/main.c index b8b9735..5ac5bde 100644 --- a/src/main.c +++ b/src/main.c @@ -26,7 +26,7 @@ int main(int argc, char **argv) { (void)argc; init_vars(); - pkg_create(mstrslc(argv[1])); + package_t pkg = pkg_create(mstrslc(argv[1])); // cla_parse(argc, argv); free_vars(); return 0; diff --git a/src/pkg/.clangd b/src/pkg/.clangd new file mode 100644 index 0000000..5022e8f --- /dev/null +++ b/src/pkg/.clangd @@ -0,0 +1,4 @@ +CompileFlags: + Add: [-I/usr/include/luajit-2.1, -I../include] +--- +UseTab: Always diff --git a/src/pkg/create.c b/src/pkg/create.c new file mode 100644 index 0000000..9e3e765 --- /dev/null +++ b/src/pkg/create.c @@ -0,0 +1,98 @@ +/* + + pkgit - package_t 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 "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_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_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_t pkg_create(str_slc arg) { + package_t pkg = { + .version = mstr("HEAD"), + .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 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); + + pkg.version = str_from_after_delim(&new_arg_str, '@'); + pkg.target = str_from_after_delim(&new_arg_str, ','); + + bool is_in_repos = false; + // 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(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 (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; + } else if (is_installed_locally) { + pkg.url = mstr(""); + pkg.name = str_from_after_delim(&dest_dir, '/'); + pkg.is_local = true; + } else { + log_error("'%.*s' is not a valid package", str_fmt(&arg)); + exit(EXIT_FAILURE); + } + pkg.src = get_pkgsrc(pkg); + return pkg; +} diff --git a/src/pkg_create.c b/src/pkg_create.c deleted file mode 100644 index 9e3e765..0000000 --- a/src/pkg_create.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - - pkgit - package_t 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 "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_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_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_t pkg_create(str_slc arg) { - package_t pkg = { - .version = mstr("HEAD"), - .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 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); - - pkg.version = str_from_after_delim(&new_arg_str, '@'); - pkg.target = str_from_after_delim(&new_arg_str, ','); - - bool is_in_repos = false; - // 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(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 (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; - } else if (is_installed_locally) { - pkg.url = mstr(""); - pkg.name = str_from_after_delim(&dest_dir, '/'); - pkg.is_local = true; - } else { - log_error("'%.*s' is not a valid package", str_fmt(&arg)); - exit(EXIT_FAILURE); - } - pkg.src = get_pkgsrc(pkg); - return pkg; -} -- cgit v1.2.3