From fe3caeefac7a2081f5c9db90bf5c821624a71082 Mon Sep 17 00:00:00 2001 From: dacctal Date: Wed, 1 Jul 2026 11:08:21 +0000 Subject: checkpoint! --- include/log.h | 17 +++++++++ include/pkg/create.h | 25 ++++++++++++++ include/pkg_create.h | 25 -------------- include/vec.h | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 140 insertions(+), 25 deletions(-) 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 (limited to 'include') 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 -- cgit v1.2.3