diff options
| author | dacctal <donotcontactmevia@email.invalid> | 2026-07-01 11:08:21 +0000 |
|---|---|---|
| committer | dacctal <donotcontactmevia@email.invalid> | 2026-07-01 11:08:21 +0000 |
| commit | fe3caeefac7a2081f5c9db90bf5c821624a71082 (patch) | |
| tree | d954657fe8f8ed8b28404739f33685ad0f0ae0fd | |
| parent | 166b788d61a443a1576f8b56abdf06fea5a2178e (diff) | |
checkpoint!
| -rw-r--r-- | .clang-format | 321 | ||||
| -rw-r--r-- | .clangd (renamed from src/.clangd) | 0 | ||||
| -rw-r--r-- | include/log.h | 17 | ||||
| -rw-r--r-- | include/pkg/create.h (renamed from include/pkg_create.h) | 0 | ||||
| -rw-r--r-- | include/vec.h | 98 | ||||
| -rw-r--r-- | src/cla_parse.c (renamed from cla_parse.c) | 80 | ||||
| -rw-r--r-- | src/log.c | 19 | ||||
| -rw-r--r-- | src/main.c | 2 | ||||
| -rw-r--r-- | src/pkg/.clangd | 4 | ||||
| -rw-r--r-- | src/pkg/create.c (renamed from src/pkg_create.c) | 0 |
10 files changed, 499 insertions, 42 deletions
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/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 index 95e12c6..95e12c6 100644 --- a/include/pkg_create.h +++ b/include/pkg/create.h 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 <https://www.gnu.org/licenses/>. + +*/ + +#ifndef PKGIT_VEC_H +#define PKGIT_VEC_H + +#include <assert.h> +#include <stdbool.h> +#include <stddef.h> +#include <stdlib.h> + +#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/cla_parse.c b/src/cla_parse.c index 8d5db4f..ab1e44c 100644 --- a/cla_parse.c +++ b/src/cla_parse.c @@ -24,13 +24,14 @@ #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/create.h" // #include "pkg_search.h" // #include "pkg_install.h" // #include "pkg_list.h" @@ -55,47 +56,48 @@ void cmd_add(char **argv, int i) { } } -void cmd_build(int argc, char **argv, int i, package pkg) { +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]); - // pkg = pkg_create(argv[j]); - // pkg_build(pkg); + // str_slc arg = mstrslc(argv[j]); + // package_t pkg = pkg_create(arg); + // pkg_build(pkg); } } else { printf("build pkg .\n"); - // pkg = pkg_create("."); - // pkg_build(pkg); + // str_slc arg = mstrslc("."); + // package_t pkg = pkg_create(arg); + // pkg_build(pkg); } } -void cmd_install(int argc, char **argv, int i, package 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; + if (argv[j][0] == '-') continue; printf("install pkg %s\n", argv[j]); - // pkg = pkg_create(argv[j]); - // pkg_install(pkg); + // str_slc arg = mstrslc(argv[j]); + // package_t pkg = pkg_create(arg); + // 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) { +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]); - // pkg = pkg_create(argv[j]); - // pkg_remove(pkg); + // str_slc arg = mstrslc(argv[j]); + // package_t pkg = pkg_create(arg); + // pkg_remove(pkg); } } else { - // NOT_ENOUGH_ARGS(argv[i], "url/pkg"); + NOT_ENOUGH_ARGS(argv[i], "url/pkg"); } } @@ -103,10 +105,10 @@ 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; + flags.verbose = false; break; case 'f': - is_forced = 1; + flags.force = true; break; default: break; @@ -114,14 +116,14 @@ void flags_mod(char **argv, int i) { } } -void flags_cmd(int argc, char **argv, int i, package pkg) { +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, pkg); + cmd_build(argc, argv, i); break; case 'c': /*deps_resolve();*/ printf("deps_resolve\n"); @@ -130,10 +132,10 @@ void flags_cmd(int argc, char **argv, int i, package pkg) { printf("declare\n"); break; case 'i': - cmd_install(argc, argv, i, pkg); + cmd_install(argc, argv, i); break; case 'r': - cmd_remove(argc, argv, i, pkg); + cmd_remove(argc, argv, i); break; case 'u': /*update();*/ printf("update\n"); @@ -156,28 +158,25 @@ void flags_cmd(int argc, char **argv, int i, package pkg) { } } -void flags_parse(int argc, char **argv, package pkg) { +void flags_parse(int argc, char **argv) { for (int i = 1; i < argc; i++) { - if (argv[i][0] != '-') - continue; - str_slc arg = str_slc_from_cstr(argv[i]); + if (argv[i][0] != '-') continue; if (argv[i][1] == '-') { - COMMAND(argv[i], "--quiet", "-q", { is_verbose = 0; }); - COMMAND(argv[i], "--force", "-f", { is_forced = 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, pkg); + flags_cmd(argc, argv, i); } } } -void cmds_parse(int argc, char **argv, package pkg) { +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, 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], "--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();*/}); @@ -193,7 +192,6 @@ void cla_parse(int argc, char **argv) { help(); return; } - package pkg = {0}; - flags_parse(argc, argv, pkg); - cmds_parse(argc, argv, pkg); + 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 <stdarg.h> +#include <stdio.h> + +#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 @@ -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 index 9e3e765..9e3e765 100644 --- a/src/pkg_create.c +++ b/src/pkg/create.c |
