aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordacctal <donotcontactmevia@email.invalid>2026-06-29 18:29:38 +0000
committerdacctal <donotcontactmevia@email.invalid>2026-06-29 18:29:38 +0000
commitb8a96b5fa7ccb6b170b1fb40c5ea4efe4519e568 (patch)
treedf85e5ad0cbfcc78da3e7450672e1a753b7cd9b0
parentd85350854dca4c6495cb78c89ff4934c7a908509 (diff)
initialized rewrite
-rw-r--r--bldit.lua60
-rw-r--r--config/init.lua247
-rw-r--r--docs/pkgit.1188
-rw-r--r--include/add_repo.h26
-rw-r--r--include/banned.h47
-rw-r--r--include/build.h28
-rw-r--r--include/cla_parse.h26
-rw-r--r--include/cmd_out.h26
-rw-r--r--include/copy_install.h26
-rw-r--r--include/create_pkg.h28
-rw-r--r--include/declare.h24
-rw-r--r--include/fetch_git.h28
-rw-r--r--include/fetch_pwd.h28
-rw-r--r--include/fetch_src.h28
-rw-r--r--include/files.h25
-rw-r--r--include/help.h26
-rw-r--r--include/install_pkg.h28
-rw-r--r--include/is_updated.h27
-rw-r--r--include/link_install.h26
-rw-r--r--include/list_pkgs.h26
-rw-r--r--include/lua_build.h26
-rw-r--r--include/lua_state.h60
-rw-r--r--include/name_from_url.h26
-rw-r--r--include/pkgit_string.h27
-rw-r--r--include/remove_pkg.h28
-rw-r--r--include/resolve_deps.h24
-rw-r--r--include/search.h24
-rw-r--r--include/set_install_directories.h26
-rw-r--r--include/setup_dirs.h26
-rw-r--r--include/setup_pkgit.h26
-rw-r--r--include/update_all.h26
-rw-r--r--include/update_pkg.h28
-rw-r--r--include/vars.h146
-rw-r--r--src/add_repo.c57
-rw-r--r--src/build.c39
-rw-r--r--src/cla_parse.c155
-rw-r--r--src/cmd_out.c62
-rw-r--r--src/create_pkg.c143
-rw-r--r--src/declare.c37
-rw-r--r--src/fetch_git.c105
-rw-r--r--src/fetch_pwd.c73
-rw-r--r--src/fetch_src.c80
-rw-r--r--src/files.c163
-rw-r--r--src/help.c56
-rw-r--r--src/install_pkg.c126
-rw-r--r--src/is_updated.c59
-rw-r--r--src/list_pkgs.c50
-rw-r--r--src/lua_build.c62
-rw-r--r--src/lua_state.c915
-rw-r--r--src/main.c37
-rw-r--r--src/name_from_url.c40
-rw-r--r--src/pkgit_string.c60
-rw-r--r--src/remove_pkg.c118
-rw-r--r--src/resolve_deps.c44
-rw-r--r--src/search.c37
-rw-r--r--src/set_install_directories.c83
-rw-r--r--src/setup_dirs.c34
-rw-r--r--src/setup_pkgit.c29
-rw-r--r--src/update_all.c59
-rw-r--r--src/update_pkg.c44
-rw-r--r--src/vars.c220
61 files changed, 93 insertions, 4355 deletions
diff --git a/bldit.lua b/bldit.lua
deleted file mode 100644
index 442cb4f..0000000
--- a/bldit.lua
+++ /dev/null
@@ -1,60 +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/>.
-
-]]
-
-bldit_version = "1.4.0"
-package_version = "1.4.0"
-
-global_dependencies = {
- luajit = {
- url = "https://luajit.org/git/luajit.git",
- version = "v2.1",
- target = "default",
- },
- git = {
- url = "https://github.com/git/git",
- version = "HEAD",
- target = "default",
- },
-}
-
-targets = {
- default = {
- build = function()
- return os.execute("make")
- end,
- install = function()
- return os.execute("make install PREFIX="..prefix)
- end,
- uninstall = function()
- return os.execute("make uninstall PREFIX="..prefix)
- end,
- },
- quiet = {
- build = function()
- return os.execute("make &>/tmp/pkgit_build.log")
- end,
- install = function()
- return os.execute("make install PREFIX="..prefix.." &>/tmp/pkgit_build.log")
- end,
- uninstall = function()
- return os.execute("make uninstall PREFIX="..prefix.." &>/tmp/pkgit_build.log")
- end,
- },
-}
diff --git a/config/init.lua b/config/init.lua
deleted file mode 100644
index 0557a89..0000000
--- a/config/init.lua
+++ /dev/null
@@ -1,247 +0,0 @@
---[[ introduction
-
- this is the pkgit configuration template.
- every configuration file is written in lua,
- the embeddable high-level programming language.
-
- for info on how to write lua, check out
- this website for documentation:
- https://www.lua.org/pil/contents.html
-
- all variables that are
- set by default are designed to
- work out of the box. be sure to
- keep the global variables global,
- as they need to be global in
- order for them to work with
- each other effectively.
-
- `local install_directories`, for
- example, will not work well in
- most cases.
-
-]]
-
---[[ prefix
-
- the prefix variable is necessary
- for custom install paths, which
- bldit maintainers should be
- respecting with their recipes.
-
- if you want to install packages
- without root, it's easist to
- create a home variable and
- append that to your prefix.
-
-]]
-local home = os.getenv("HOME")
-prefix = home.."/.local"
-
---[[ install_directories
-
- install_directories is an essential
- table that pkgit needs in order to
- function. this is how it determines
- where you install your packages to.
-
- it's most convenient when combined
- with `prefix` which allows for a
- more dynamic definition of your
- install directories.
-
-]]
-install_directories = {
- bin = prefix.."/bin", -- binaries (executables)
- -- the value of `bin` should also be set in your shell's $PATH
- include = prefix.."/include", -- C headers
- lib = prefix.."/lib", -- libraries (shared objects)
- src = prefix.."/share/pkgit", -- source code
-}
-
---[[ repositories
-
- this is where all your repos need to
- end up. every repo has a name, which
- can be written out normally
- (`name = {...}`), or for some repos,
- it might be necessary to wrap it in
- quotes (`["name"] = {...}`).
- that name can be used in a pkgit
- command to be installed.
- ( `pkgit --install [repo]` )
-
- each of these repos must be structured
- as a lua table. the structure is
- demonstrated below.
-
-]]
-repositories = {
- pkgit = {
- url = "https://git.symlinx.net/pkgit",
- --[[ repo example
-
- no targets table or dependencies are actually needed in
- this specific case, pkgit has a bldit.lua which guarantees
- that it will compile & install (as long as `install_directories`
- and `prefix` are set up).
-
- if you do make a targets table here, it will take priority
- over the bldit.lua in the repo, and your build system
- autodetection config ( `build_systems = {...}` )
-
- more about `targets` in the global `build_systems` table.
-
- ]]
- --dependencies = {
- -- name = {
- -- url = {...},
- -- version = "...",
- -- target = "...",
- -- },
- --},
- --targets = {
- -- default = {
- -- build = function()
- -- return os.execute("make")
- --
- -- -- ^ make sure to return the exit code of os.execute ^ --
- --
- -- end,
- -- install = function()
- -- return os.execute("make install PREFIX="..prefix)
- -- end,
- -- uninstall = function()
- -- return os.execute("make uninstall PREFIX="..prefix)
- -- end,
- -- }
- --}
- },
-}
-
---[[ build_systems
-
- this table contains all of the automatic
- build system detection necessary for pkgit
- to work without bldit.lua or `repositories = {...}`.
-
- this works by creating a table named after the
- filename associated with the build system that
- is found in the root directory of a package.
-
- by associating a filename with a build system,
- pkgit can dynamically compile and install any
- package, given that they use the build system
- according to the standard (or otherwise
- generally popular) usage guidelines.
-
-]]
-build_systems = {
- ["Makefile"] = {
- --[[ targets
-
- briefly mentioned above in `repositories`,
- the `targets` subtable is a standard that's
- consistent across all the different methods
- to build a package using pkgit; meaning
- you can write the same `targets` subtable
- in `repositories.<pkg>`, `bldit.lua`, and
- right here in `build_systems`.
-
- this table comes with two templates;
- `default` and `quiet`. the first is pretty
- self-explanatory; this is what you'd define
- as the default intended behavior of the
- build system.
-
- `quiet` is similar to `default`, in the sense
- that it inherits the default intended behavior,
- except that it does so while printing nothing
- to the terminal. instead, ideally, it would
- output its logs to a temporary file accessible
- by the user running the command.
-
- this is why the default logs in this example
- are located in `/tmp` and not `/var/log`,
- because the user typically has full access to
- `/tmp`, and normally not `/var/log`.
-
- ]]
- targets = {
- default = {
- build = function()
- return os.execute("make")
- end,
- install = function()
- return os.execute("make install PREFIX="..prefix)
- end,
- uninstall = function()
- return os.execute("make uninstall PREFIX="..prefix)
- end,
- },
- quiet = {
- build = function()
- return os.execute("make &>/tmp/pkgit_build.log")
- end,
- install = function()
- return os.execute("make install PREFIX="..prefix.." &>/tmp/pkgit_build.log")
- end,
- uninstall = function()
- return os.execute("make uninstall PREFIX="..prefix.." &>/tmp/pkgit_build.log")
- end,
- },
- }
- },
- ["meson.build"] = {
- targets = {
- default = {
- build = function()
- return os.execute("meson setup build --prefix "..prefix.." && meson compile -C build")
- end,
- install = function()
- return os.execute("cd build && meson install")
- end,
- uninstall = function()
- return os.execute("cd build && ninja uninstall")
- end,
- },
- quiet = {
- build = function()
- return os.execute("meson setup build --prefix "..prefix.." &>/tmp/pkgit_build.log && meson compile -C build &>/tmp/pkgit_build.log")
- end,
- install = function()
- return os.execute("cd build && meson install &>/tmp/pkgit_build.log")
- end,
- uninstall = function()
- return os.execute("cd build && ninja uninstall &>/tmp/pkgit_build.log")
- end,
- },
- }
- },
- ["CMakeLists.txt"] = {
- targets = {
- default = {
- build = function()
- return os.execute("cmake -B build && cmake --build build")
- end,
- install = function()
- return os.execute("cmake --build . --target install")
- end,
- uninstall = function()
- return os.execute("xargs rm < install_manifest.txt")
- end,
- },
- quiet = {
- build = function()
- return os.execute("cmake -B build &>/tmp/pkgit_build.log && cmake --build build &>/tmp/pkgit_build.log")
- end,
- install = function()
- return os.execute("cmake --build . --target install &>/tmp/pkgit_build.log")
- end,
- uninstall = function()
- return os.execute("xargs rm < install_manifest.txt &>/tmp/pkgit_build.log")
- end,
- },
- }
- },
-}
diff --git a/docs/pkgit.1 b/docs/pkgit.1
deleted file mode 100644
index 4606acd..0000000
--- a/docs/pkgit.1
+++ /dev/null
@@ -1,188 +0,0 @@
-.TH PKGIT 1 "2026-06-22" "git.symlinx.net/pkgit" "User Commands"
-.SH NAME
-pkgit \- an unconventional package manager
-.SH SYNOPSIS
-.B pkgit
-.RI [ options ] " " <package>
-.br
-.B pkgit
-.RI [ options ] " " <command> " " [arguments]
-.SH DESCRIPTION
-.B pkgit
-is an unconventional package manager designed to compile and install packages directly from their git repository.
-.PP
-Commands in
-.B pkgit
-follow a standard structure:
-.PP
-.RS
-.B pkgit
-.RI [ \-\-flag | \-f ] " " <package>
-.RE
-.PP
-Flags have two forms: long (e.g., \fB\-\-install\fR) and short (e.g., \fB\-i\fR).
-The short form uses the first letter of the long counterpart. Short flags
-can be chained together into a single argument. For example,
-.B \-qif
-combines
-.BR \-\-quiet ,
-.BR \-\-install ,
-and
-.BR \-\-force .
-.SH WARNING
-Due to the nature of
-.BR pkgit ,
-you are solely responsible for vetting the repositories that you add to your system. Use at your own risk.
-.SH COMPILATION
-To compile
-.B pkgit
-from source, enter the project directory and run one of the following:
-.PP
-.RS
-.B make
-.RE
-or
-.RS
-.B pkgit \-\-build
-.RE
-.PP
-Both methods will create an executable in the root directory of the project.
-.PP
-You may also want to generate a base configuration file. Run the following as a regular user to generate the config in
-.IR ~/.config/pkgit :
-.PP
-.RS
-.B make defconfig
-.RE
-.PP
-Alternatively, run as root (using
-.B sudo
-or
-.BR doas )
-to generate the system-wide config in
-.IR /etc/pkgit :
-.PP
-.RS
-.B sudo make defconfig
-.RE
-.SH INSTALLATION
-After compiling, install the package with root privileges:
-.PP
-.RS
-.B make install
-.RE
-.PP
-If you do not have root privileges, or prefer a local installation, you can specify an install location using the
-.B PREFIX
-variable. A common choice is
-.IR ~/.local :
-.PP
-.RS
-.B make install PREFIX="~/.local"
-.RE
-.SH ENVIRONMENT
-Before using programs installed via
-.BR pkgit ,
-ensure the binary path is added to your shell's
-.BR PATH .
-For a local installation (e.g.,
-.IR ~/.local/bin ),
-add the following to your shell configuration:
-.PP
-.TP
-.B Bash / Zsh
-export PATH="$HOME/.local/bin:$PATH"
-.TP
-.B Fish
-fish_add_path $HOME/.local/bin
-.TP
-.B Csh / Tcsh
-setenv PATH $HOME/.local/bin:$PATH
-.SH OPTIONS
-These options modify the behavior of commands.
-.TP
-.BR \-q ", " \-\-quiet
-Minimize logs output to stdout.
-.TP
-.BR \-f ", " \-\-force
-Force the package to be installed, even if it is already installed.
-.SH COMMANDS
-.TP
-.BR \-i ", " \-\-install " \fI<target>\fR"
-Install a package. Assuming the respective repository has been added,
-you can specify the package by name. The \fI<target>\fR argument supports
-several syntax variations:
-.RS
-.TP
-.B Basic install
-.B pkgit \-\-install
-.I pkg_name
-.TP
-.B Specific version
-.B pkgit \-\-install
-.IR pkg_name @ version
-.TP
-.B Specific target
-.B pkgit \-\-install
-.IR pkg_name , target
-(Target is based on configuration in
-.I bldit.lua
-or
-.IR init.lua ).
-.TP
-.B Combined target and version
-.B pkgit \-\-install
-.IR pkg_name , target @ version
-or
-.B pkgit \-\-install
-.IR pkg_name @ version , target
-(Order does not matter as long as the package name is first).
-.TP
-.B Repo install
-.B pkgit \-\-install
-.I url.git
-(Installs directly from a git URL. Works with target and version syntax).
-.TP
-.B Local install
-.B pkgit \-\-install " ."
-(Installs from the local code repository in the current directory,
-taking advantage of pkgit's build system autodetection).
-.RE
-.TP
-.BR \-b ", " \-\-build " \fI[/path/to/project]\fR"
-(Best for developers) Act as a meta-build-system to automatically compile
-any supported project. Can be run from the project's root directory
-without specifying the path.
-.TP
-.BR \-r ", " \-\-remove " \fI<pkg_name>\fR"
-Remove (uninstall) an installed package.
-.TP
-.BR \-u ", " \-\-update
-Update all installed packages.
-.TP
-.BR \-d ", " \-\-declare
-Use the configuration file as a package declaration file to declare
-and install all packages at once.
-.SH EXAMPLES
-.TP
-Install a package quietly, forcing the installation:
-.B pkgit \-qif
-.I mypackage
-.TP
-Install a specific version and target of a package:
-.B pkgit \-i
-.I mypackage,mytarget@1.0.0
-.TP
-Install a package directly from a git repository:
-.B pkgit \-\-install
-.I https://github.com/heather7283/pipemixer
-.TP
-Build the project in the current directory:
-.B pkgit \-\-build
-.SH SEE ALSO
-.BR git (1),
-.BR lua (1)
-.SH AUTHORS
-.B pkgit
-is developed and maintained by the contributors at
-.IR git.symlinx.net/pkgit .)'
diff --git a/include/add_repo.h b/include/add_repo.h
deleted file mode 100644
index 5b32bd7..0000000
--- a/include/add_repo.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-
- pkgit - package it!
-
- Copyright (C) 2026 dacctal
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-*/
-
-#ifndef ADD_REPO_H
-#define ADD_REPO_H
-
-void add_repo(const char *repo, const char *repo_name);
-
-#endif \ No newline at end of file
diff --git a/include/banned.h b/include/banned.h
deleted file mode 100644
index 2b934c8..0000000
--- a/include/banned.h
+++ /dev/null
@@ -1,47 +0,0 @@
-#ifndef BANNED_H
-#define BANNED_H
-
-/*
- * This header lists functions that have been banned from our code base,
- * because they're too easy to misuse (and even if used correctly,
- * complicate audits). Including this header turns them into compile-time
- * errors.
- */
-
-#define BANNED(func) sorry_##func##_is_a_banned_function
-
-#undef strcpy
-#define strcpy(x,y) BANNED(strcpy)
-#undef strcat
-#define strcat(x,y) BANNED(strcat)
-#undef strncpy
-#define strncpy(x,y,n) BANNED(strncpy)
-#undef strncat
-#define strncat(x,y,n) BANNED(strncat)
-#undef strtok
-#define strtok(x,y) BANNED(strtok)
-#undef strtok_r
-#define strtok_r(x,y,z) BANNED(strtok_r)
-
-#undef sprintf
-#undef vsprintf
-#define sprintf(...) BANNED(sprintf)
-#define vsprintf(...) BANNED(vsprintf)
-
-#undef gmtime
-#define gmtime(t) BANNED(gmtime)
-#undef localtime
-#define localtime(t) BANNED(localtime)
-#undef ctime
-#define ctime(t) BANNED(ctime)
-#undef ctime_r
-#define ctime_r(t, buf) BANNED(ctime_r)
-#undef asctime
-#define asctime(t) BANNED(asctime)
-#undef asctime_r
-#define asctime_r(t, buf) BANNED(asctime_r)
-
-#undef mktemp
-#define mktemp(x) BANNED(mktemp)
-
-#endif /* BANNED_H */
diff --git a/include/build.h b/include/build.h
deleted file mode 100644
index 18c08fd..0000000
--- a/include/build.h
+++ /dev/null
@@ -1,28 +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 BUILD_H
-#define BUILD_H
-
-#include "vars.h"
-
-void build(Pkg pkg);
-
-#endif \ No newline at end of file
diff --git a/include/cla_parse.h b/include/cla_parse.h
deleted file mode 100644
index 19ae172..0000000
--- a/include/cla_parse.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-
- pkgit - package it!
-
- Copyright (C) 2026 dacctal
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-*/
-
-#ifndef CLA_PARSE_H
-#define CLA_PARSE_H
-
-void cla_parse(int argc, char **argv);
-
-#endif \ No newline at end of file
diff --git a/include/cmd_out.h b/include/cmd_out.h
deleted file mode 100644
index 1b5a35a..0000000
--- a/include/cmd_out.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-
- pkgit - package it!
-
- Copyright (C) 2026 dacctal
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-*/
-
-#ifndef CMD_OUT_H
-#define CMD_OUT_H
-
-char* cmd_out(const char *cmd);
-
-#endif \ No newline at end of file
diff --git a/include/copy_install.h b/include/copy_install.h
deleted file mode 100644
index 18ff679..0000000
--- a/include/copy_install.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-
- pkgit - package it!
-
- Copyright (C) 2026 dacctal
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-*/
-
-#ifndef COPY_INSTALL_H
-#define COPY_INSTALL_H
-
-void copy_install(const char *build_dir);
-
-#endif \ No newline at end of file
diff --git a/include/create_pkg.h b/include/create_pkg.h
deleted file mode 100644
index 0bad45d..0000000
--- a/include/create_pkg.h
+++ /dev/null
@@ -1,28 +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 CREATE_PKG_H
-#define CREATE_PKG_H
-
-#include "vars.h"
-
-Pkg create_pkg(const char *arg);
-
-#endif \ No newline at end of file
diff --git a/include/declare.h b/include/declare.h
deleted file mode 100644
index 7a3fd41..0000000
--- a/include/declare.h
+++ /dev/null
@@ -1,24 +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 DECLARE
-#define DECLARE
-void declare(void);
-#endif
diff --git a/include/fetch_git.h b/include/fetch_git.h
deleted file mode 100644
index b27661e..0000000
--- a/include/fetch_git.h
+++ /dev/null
@@ -1,28 +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 FETCH_GIT_H
-#define FETCH_GIT_H
-
-#include "vars.h"
-
-int fetch_git(Pkg pkg);
-
-#endif \ No newline at end of file
diff --git a/include/fetch_pwd.h b/include/fetch_pwd.h
deleted file mode 100644
index e64689b..0000000
--- a/include/fetch_pwd.h
+++ /dev/null
@@ -1,28 +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 FETCH_PWD_H
-#define FETCH_PWD_H
-
-#include "vars.h"
-
-void fetch_pwd(Pkg pkg);
-
-#endif \ No newline at end of file
diff --git a/include/fetch_src.h b/include/fetch_src.h
deleted file mode 100644
index fd647d5..0000000
--- a/include/fetch_src.h
+++ /dev/null
@@ -1,28 +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 FETCH_SRC_H
-#define FETCH_SRC_H
-
-#include "vars.h"
-
-void fetch_src(Pkg pkg);
-
-#endif \ No newline at end of file
diff --git a/include/files.h b/include/files.h
deleted file mode 100644
index cc72ace..0000000
--- a/include/files.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 FILES
-#define FILES
-const char *get_filename_ext(const char *filename);
-void cpdir(const char *path, const char *dest);
-#endif
diff --git a/include/help.h b/include/help.h
deleted file mode 100644
index c194be4..0000000
--- a/include/help.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-
- pkgit - package it!
-
- Copyright (C) 2026 dacctal
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-*/
-
-#ifndef HELP_H
-#define HELP_H
-
-void help(void);
-
-#endif \ No newline at end of file
diff --git a/include/install_pkg.h b/include/install_pkg.h
deleted file mode 100644
index c35d8e3..0000000
--- a/include/install_pkg.h
+++ /dev/null
@@ -1,28 +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 INSTALL_PKG_H
-#define INSTALL_PKG_H
-
-#include "vars.h"
-
-void install_pkg(Pkg pkg);
-
-#endif \ No newline at end of file
diff --git a/include/is_updated.h b/include/is_updated.h
deleted file mode 100644
index 769cc61..0000000
--- a/include/is_updated.h
+++ /dev/null
@@ -1,27 +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 IS_UPDATED_H
-#define IS_UPDATED_H
-
-bool is_updated(const char *src);
-bool is_bldit_usable(void);
-
-#endif \ No newline at end of file
diff --git a/include/link_install.h b/include/link_install.h
deleted file mode 100644
index 084559b..0000000
--- a/include/link_install.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-
- pkgit - package it!
-
- Copyright (C) 2026 dacctal
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-*/
-
-#ifndef LINK_INSTALL_H
-#define LINK_INSTALL_H
-
-void link_install(const char *build_dir);
-
-#endif \ No newline at end of file
diff --git a/include/list_pkgs.h b/include/list_pkgs.h
deleted file mode 100644
index 3ae6900..0000000
--- a/include/list_pkgs.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-
- pkgit - package it!
-
- Copyright (C) 2026 dacctal
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-*/
-
-#ifndef LIST_PKGS_H
-#define LIST_PKGS_H
-
-void list_pkgs(void);
-
-#endif \ No newline at end of file
diff --git a/include/lua_build.h b/include/lua_build.h
deleted file mode 100644
index 70c2e8b..0000000
--- a/include/lua_build.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-
- pkgit - package it!
-
- Copyright (C) 2026 dacctal
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-*/
-
-#ifndef LUA_BUILD_H
-#define LUA_BUILD_H
-
-bool lua_build(const char *repository, const char *target, const char *path);
-
-#endif \ No newline at end of file
diff --git a/include/lua_state.h b/include/lua_state.h
deleted file mode 100644
index d8457ad..0000000
--- a/include/lua_state.h
+++ /dev/null
@@ -1,60 +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 LUA_STATE_H
-#define LUA_STATE_H
-
-#include <lua.h>
-#include <lauxlib.h>
-#include <lualib.h>
-
-#include "vars.h"
-
-extern Map cached_install_directories;
-extern Repo cached_repos[MAX_REPOS];
-extern size_t cached_repos_count;
-extern Map cached_build_systems;
-
-void push_lua_path(lua_State *L, const char *new_path);
-void init_lua_state(void);
-void free_lua_state(void);
-lua_State* get_lua_state(void);
-const char* get_privilege_escalator(void);
-
-void cache_repos(void);
-void cache_build_systems(void);
-void cache_install_directories(void);
-void cache_prefix_directory(void);
-bool on_update(lua_State *L);
-bool target_loop_on_update(lua_State *L, const char* lua_file, const char *target);
-bool repo_build(const char *repository, const char *target);
-bool repo_install(const char *repository, const char *target);
-bool repo_uninstall(const char *repository, const char *target);
-bool bldit(const char *target);
-bool bldit_install(const char *target);
-bool bldit_uninstall(const char *target);
-bool config_build(const char *path, const char *target);
-bool config_install(const char *path, const char *target);
-bool config_uninstall(const char *path, const char *target);
-
-char* bldit_getver(void);
-char* bldit_pkg_getver(void);
-
-#endif \ No newline at end of file
diff --git a/include/name_from_url.h b/include/name_from_url.h
deleted file mode 100644
index ab2761b..0000000
--- a/include/name_from_url.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-
- pkgit - package it!
-
- Copyright (C) 2026 dacctal
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-*/
-
-#ifndef NAME_FROM_URL_H
-#define NAME_FROM_URL_H
-
-char* name_from_url(const char *url);
-
-#endif \ No newline at end of file
diff --git a/include/pkgit_string.h b/include/pkgit_string.h
new file mode 100644
index 0000000..ae6098c
--- /dev/null
+++ b/include/pkgit_string.h
@@ -0,0 +1,27 @@
+#ifndef PKGIT_STRING_H
+#define PKGIT_STRING_H
+#include <stddef.h>
+
+typedef struct {
+ char* data;
+ size_t len;
+} str_s;
+
+typedef struct {
+ char* data;
+ size_t cap;
+ size_t len;
+} str;
+
+#define format_string(s) (int)((s).len), (s).data
+// Usage: printf("%.*s", format_string(ss));
+
+void print_slice(str_s s);
+str_s slice_from_cstr(char* cstr);
+int slice_eq(str_s a, str_s b);
+int slice_starts_with(str_s slice, str_s prefix);
+str_s slice_take(str_s slice, size_t n);
+str_s slice_drop(str_s slice, size_t n);
+str_s slice_trim(str_s slice);
+
+#endif
diff --git a/include/remove_pkg.h b/include/remove_pkg.h
deleted file mode 100644
index 4ac5ca0..0000000
--- a/include/remove_pkg.h
+++ /dev/null
@@ -1,28 +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 REMOVE_PKG_H
-#define REMOVE_PKG_H
-
-#include "vars.h"
-
-void remove_pkg(Pkg pkg);
-
-#endif \ No newline at end of file
diff --git a/include/resolve_deps.h b/include/resolve_deps.h
deleted file mode 100644
index 1e0b8ee..0000000
--- a/include/resolve_deps.h
+++ /dev/null
@@ -1,24 +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 RESOLVE_DEPS_H
-#define RESOLVE_DEPS_H
-void resolve_deps(void);
-#endif
diff --git a/include/search.h b/include/search.h
deleted file mode 100644
index a316a71..0000000
--- a/include/search.h
+++ /dev/null
@@ -1,24 +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 FIND
-#define FIND
-void search(const char* arg);
-#endif
diff --git a/include/set_install_directories.h b/include/set_install_directories.h
deleted file mode 100644
index 22886e1..0000000
--- a/include/set_install_directories.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-
- pkgit - package it!
-
- Copyright (C) 2026 dacctal
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-*/
-
-#ifndef SET_INSTALL_DIRECTORIES_H
-#define SET_INSTALL_DIRECTORIES_H
-
-void set_install_directories(void);
-
-#endif \ No newline at end of file
diff --git a/include/setup_dirs.h b/include/setup_dirs.h
deleted file mode 100644
index 4490948..0000000
--- a/include/setup_dirs.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-
- pkgit - package it!
-
- Copyright (C) 2026 dacctal
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-*/
-
-#ifndef SETUP_DIRS_H
-#define SETUP_DIRS_H
-
-void setup_dirs(void);
-
-#endif \ No newline at end of file
diff --git a/include/setup_pkgit.h b/include/setup_pkgit.h
deleted file mode 100644
index 9554969..0000000
--- a/include/setup_pkgit.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-
- pkgit - package it!
-
- Copyright (C) 2026 dacctal
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-*/
-
-#ifndef SETUP_PKGIT_H
-#define SETUP_PKGIT_H
-
-void setup_pkgit(void);
-
-#endif \ No newline at end of file
diff --git a/include/update_all.h b/include/update_all.h
deleted file mode 100644
index 022c92b..0000000
--- a/include/update_all.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-
- pkgit - package it!
-
- Copyright (C) 2026 dacctal
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-*/
-
-#ifndef UPDATE_ALL_H
-#define UPDATE_ALL_H
-
-void update_all(void);
-
-#endif \ No newline at end of file
diff --git a/include/update_pkg.h b/include/update_pkg.h
deleted file mode 100644
index 8d3a993..0000000
--- a/include/update_pkg.h
+++ /dev/null
@@ -1,28 +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 UPDATE_PKG_H
-#define UPDATE_PKG_H
-
-#include "vars.h"
-
-void update_pkg(Pkg pkg);
-
-#endif \ No newline at end of file
diff --git a/include/vars.h b/include/vars.h
deleted file mode 100644
index c76b742..0000000
--- a/include/vars.h
+++ /dev/null
@@ -1,146 +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 VARS_H
-#define VARS_H
-
-#include <stdbool.h>
-#include <stddef.h>
-#include "banned.h"
-
-#define MAX_REPOS 1000
-#define MAX_DIRS 100
-#define MAX_PATH_LEN 1024
-
-typedef struct {
- char *key;
- char *value;
-} KeyValue;
-
-typedef struct {
- char *key;
- char *value;
-} MapItem;
-
-typedef struct {
- MapItem *items;
- size_t size;
- size_t capacity;
-} Map;
-
-typedef struct {
- char *url;
- char *version;
-} Dependency;
-
-typedef struct {
- char *source_key;
- char *source_value;
- char *version;
- Dependency *dependencies;
- size_t dep_count;
- int build_ref;
- int pre_install_ref;
- int install_ref;
- int post_install_ref;
-} Repo;
-
-typedef struct {
- char *url;
- char *name;
- const char *target;
- char *ver;
- char src[MAX_PATH_LEN];
- bool is_local;
-} Pkg;
-
-extern bool is_symlink_install;
-extern bool is_verbose;
-extern bool is_auto_installed;
-extern bool is_forced;
-extern bool config_exists;
-
-extern char home_dir[MAX_PATH_LEN];
-extern char prefix_dir[MAX_PATH_LEN];
-
-extern char root_config[MAX_PATH_LEN];
-extern bool is_root_config;
-extern char config_dir[MAX_PATH_LEN];
-extern char config_file[MAX_PATH_LEN];
-extern char repo_file[MAX_PATH_LEN];
-
-extern char bin[MAX_PATH_LEN];
-extern char lib[MAX_PATH_LEN];
-extern char inc[MAX_PATH_LEN];
-extern char src[MAX_PATH_LEN];
-
-extern char *install_directories[5];
-
-extern const char *version;
-
-extern const char *red;
-extern const char *green;
-extern const char *yellow;
-extern const char *blue;
-extern const char *magenta;
-extern const char *cyan;
-extern const char *gray;
-extern const char *bright_red;
-extern const char *bright_green;
-extern const char *bright_yellow;
-extern const char *bright_blue;
-extern const char *bright_magenta;
-extern const char *bright_cyan;
-extern const char *bright_gray;
-extern const char *bold_red;
-extern const char *bold_green;
-extern const char *bold_yellow;
-extern const char *bold_blue;
-extern const char *bold_magenta;
-extern const char *bold_cyan;
-extern const char *bold_gray;
-extern const char *bold_white;
-extern const char *bold_bright_red;
-extern const char *bold_bright_green;
-extern const char *bold_bright_yellow;
-extern const char *bold_bright_blue;
-extern const char *bold_bright_magenta;
-extern const char *bold_bright_cyan;
-extern const char *bold_bright_gray;
-extern const char *italic;
-extern const char *color_reset;
-
-extern const char *print_pkgit;
-extern const char *print_success;
-extern const char *print_skipped;
-extern const char *print_warning;
-extern const char *print_error;
-
-void init_vars(void);
-const char* get_install_dir(const char *key);
-bool file_exists(const char *path);
-bool is_directory(const char *path);
-int mkdir_p(const char *path);
-
-void map_init(Map *map);
-void map_put(Map *map, char *key, char *value);
-char* map_get(Map *map, const char *key);
-
-#endif
diff --git a/src/add_repo.c b/src/add_repo.c
deleted file mode 100644
index 949c992..0000000
--- a/src/add_repo.c
+++ /dev/null
@@ -1,57 +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/>.
-
-*/
-
-#include <stdio.h>
-#include <string.h>
-#include <stdbool.h>
-
-#include "add_repo.h"
-#include "vars.h"
-
-void add_repo(const char *repo, const char *repo_name) {
- bool is_previous_repos = false;
- char rfile_line[1024];
- char rfile_contents[8192] = {0};
-
- if (file_exists(repo_file)) {
- FILE *rfile = fopen(repo_file, "r");
- if (rfile) {
- while (fgets(rfile_line, sizeof(rfile_line), rfile)) {
- size_t current_len = strlen(rfile_contents);
- size_t remaining = sizeof(rfile_contents) - current_len;
- if (remaining > 1) {
- snprintf(rfile_contents + current_len, remaining, "%s", rfile_line);
- } else {
- break;
- }
- }
- fclose(rfile);
- is_previous_repos = true;
- }
- }
-
- char *previous_repos = is_previous_repos ? rfile_contents : "";
-
- FILE *wfile = fopen(repo_file, "w");
- if (wfile) {
- fprintf(wfile, "%srepositories[\"%s\"] = { url = \"%s\" }\n", previous_repos, repo_name, repo);
- fclose(wfile);
- }
-}
diff --git a/src/build.c b/src/build.c
deleted file mode 100644
index fd524ea..0000000
--- a/src/build.c
+++ /dev/null
@@ -1,39 +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/>.
-
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "build.h"
-
-#include "lua_build.h"
-#include "vars.h"
-
-void build(Pkg pkg) {
- char cwd[MAX_PATH_LEN];
- getcwd(cwd, MAX_PATH_LEN);
- if (strcmp(pkg.src, cwd) != 0 && !pkg.is_local) chdir(pkg.src);
-
- if (lua_build(pkg.name, pkg.target, pkg.is_local ? cwd : pkg.src)) return;
- printf("%s no usable build system was found\n", print_error);
- exit(EXIT_FAILURE);
-} \ No newline at end of file
diff --git a/src/cla_parse.c b/src/cla_parse.c
deleted file mode 100644
index b30202d..0000000
--- a/src/cla_parse.c
+++ /dev/null
@@ -1,155 +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/>.
-
-*/
-
-#include <stdio.h>
-#include <string.h>
-
-#include "cla_parse.h"
-
-#include "add_repo.h"
-#include "build.h"
-#include "create_pkg.h"
-#include "declare.h"
-#include "search.h"
-#include "help.h"
-#include "install_pkg.h"
-#include "list_pkgs.h"
-#include "name_from_url.h"
-#include "remove_pkg.h"
-#include "resolve_deps.h"
-#include "update_all.h"
-#include "vars.h"
-
-#define COMMAND(large, small, code) \
- if (strcmp(argv[i], large) == 0 || strcmp(argv[i], small) == 0) code
-
-#define NOT_ENOUGH_ARGS(arg, next) \
- printf("%s Not enough arguments! Try: `pkgit %s [%s]`\n", \
- print_error, arg, next)
-
-void cmd_add(char **argv, int i) {
- if (argv[i + 1]) {
- add_repo(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, Pkg pkg) {
- if (argv[i + 1]) {
- for (int j = i + 1; j < argc; j++) {
- if (argv[j][0] == '-') continue;
- pkg = create_pkg(argv[j]);
- build(pkg);
- }
- } else {
- pkg = create_pkg(".");
- build(pkg);
- }
-}
-
-void cmd_install(int argc, char **argv, int i, Pkg pkg) {
- if (argv[i + 1]) {
- for (int j = i + 1; j < argc; j++) {
- if (argv[j][0] == '-') continue;
- pkg = create_pkg(argv[j]);
- install_pkg(pkg);
- }
- } else {
- NOT_ENOUGH_ARGS(argv[i], "url/pkg");
- }
-}
-
-void cmd_remove(int argc, char **argv, int i, Pkg pkg) {
- if (argv[i + 1]) {
- for (int j = i + 1; j < argc; j++) {
- if (argv[j][0] == '-') continue;
- pkg = create_pkg(argv[j]);
- remove_pkg(pkg);
- }
- } else {
- NOT_ENOUGH_ARGS(argv[i], "url/pkg");
- }
-}
-
-void mod_flags(char **argv, int i) {
- for (size_t j = 1; j < strlen(argv[i]); j++) {
- switch (argv[i][j]) {
- case 'q': is_verbose = false; break;
- case 'f': is_forced = true; break;
- default: break;
- }
- }
-}
-
-void cmd_flags(int argc, char **argv, int i, Pkg 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 'i': cmd_install(argc, argv, i, pkg); break;
- case 'r': cmd_remove(argc, argv, i, pkg); break;
- case 'u': update_all(); break;
- case 'd': declare(); break;
- case 'l': list_pkgs(); break;
- case 's': search(argv[i + 1]); break;
- case 'v': printf("%s\n", version); break;
- case 'h': help(); break;
- case 'c': resolve_deps(); break;
- default: break;
- }
- }
-}
-
-void parse_flags(int argc, char **argv, Pkg pkg) {
- for (int i = 1; i < argc; i++) {
- if (argv[i][0] != '-') continue;
- if (argv[i][1] == '-') {
- COMMAND("--quiet", "-q", { is_verbose = false; });
- COMMAND("--force", "-f", { is_forced = true; });
- } else {
- mod_flags(argv, i);
- cmd_flags(argc, argv, i, pkg);
- }
- }
-}
-
-void parse_cmds(int argc, char **argv, Pkg pkg) {
- for (int i = 1; i < argc; i++) {
- COMMAND("--add", "a", { cmd_add(argv, i); });
- COMMAND("--build", "b", { cmd_build(argc, argv, i, pkg); });
- COMMAND("--install", "i", { cmd_install(argc, argv, i, pkg); });
- COMMAND("--remove", "r", { cmd_remove(argc, argv, i, pkg); });
- COMMAND("--update", "u", { update_all(); });
- COMMAND("--declare", "d", { declare(); });
- COMMAND("--list", "l", { list_pkgs(); });
- COMMAND("--search", "s", { search(argv[i + 1]); });
- COMMAND("--version", "v", { printf("%s\n", version); });
- COMMAND("--help", "h", { help(); });
- COMMAND("--check", "c", { resolve_deps(); });
- }
-}
-
-void cla_parse(int argc, char **argv) {
- if (!argv[1]) { help(); return; }
- Pkg pkg = {0};
- parse_flags(argc, argv, pkg);
- parse_cmds(argc, argv, pkg);
-} \ No newline at end of file
diff --git a/src/cmd_out.c b/src/cmd_out.c
deleted file mode 100644
index f2d6bf4..0000000
--- a/src/cmd_out.c
+++ /dev/null
@@ -1,62 +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/>.
-
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdbool.h>
-
-#include "cmd_out.h"
-
-char* cmd_out(const char *cmd) {
- FILE *pipe = popen(cmd, "r");
- if (!pipe) return strdup("");
-
- char buffer[128];
- size_t total_size = 0;
- size_t capacity = 256;
- char *result = malloc(capacity);
- if (!result) {
- pclose(pipe);
- return strdup("");
- }
- result[0] = '\0';
-
- while (fgets(buffer, sizeof(buffer), pipe) != NULL) {
- size_t len = strlen(buffer);
- // Ensure enough space for the new chunk + 1 byte for '\0'
- if (total_size + len + 1 > capacity) {
- capacity *= 2;
- char *new_result = realloc(result, capacity);
- if (!new_result) {
- free(result);
- pclose(pipe);
- return strdup("");
- }
- result = new_result;
- }
-
- snprintf(result + total_size, capacity - total_size, "%s", buffer);
- total_size += len;
- }
-
- pclose(pipe);
- return result;
-}
diff --git a/src/create_pkg.c b/src/create_pkg.c
deleted file mode 100644
index 12b6a63..0000000
--- a/src/create_pkg.c
+++ /dev/null
@@ -1,143 +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/>.
-
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "create_pkg.h"
-#include "lua_state.h"
-#include "name_from_url.h"
-#include "vars.h"
-
-bool is_in_repos(char *arg) {
- for (size_t i = 0; i < cached_repos_count; i++)
- if (strcmp(arg, cached_repos[i].source_key) == 0)
- return true;
- return false;
-}
-
-Pkg pkg_from_repo(char* arg) {
- Pkg pkg = {0};
- for (size_t i = 0; i < cached_repos_count; i++) {
- if (strcmp(arg, cached_repos[i].source_key) == 0) {
- pkg.url = strdup(cached_repos[i].source_value);
- break;
- }
- }
- pkg.name = arg;
- return pkg;
-}
-
-char* get_destdir(char* cwd, char* arg) {
- char dest_dir[MAX_PATH_LEN];
- if (arg[0] == '.') {
- snprintf(dest_dir, sizeof(dest_dir), "%s/%s",
- get_install_dir("src"), name_from_url(cwd));
- } else {
- snprintf(dest_dir, sizeof(dest_dir), "%s/%s",
- get_install_dir("src"), arg);
- }
- return strdup(dest_dir);
-}
-
-void rmdotgit(Pkg pkg) {
- if (
- strlen(pkg.name) > 4 &&
- strncmp(pkg.name + strlen(pkg.name) - 4, ".git", 4) == 0
- ) pkg.name[strlen(pkg.name) - 4] = '\0';
-}
-
-char* get_pkgsrc(Pkg pkg) {
- char src_dir[MAX_PATH_LEN];
- if (pkg.is_local) {
- snprintf(src_dir, sizeof(src_dir), "%s/%s",
- get_install_dir("src"), pkg.name);
- } else {
- snprintf(src_dir, sizeof(src_dir), "%s/%s/%s",
- get_install_dir("src"), pkg.name, pkg.ver);
- }
- return strdup(src_dir);
-}
-
-Pkg create_pkg(const char *arg) {
- Pkg pkg = {0};
- pkg.ver = "HEAD";
- pkg.is_local = false;
- char cwd[MAX_PATH_LEN];
- getcwd(cwd, MAX_PATH_LEN);
- char *new_arg = strdup(arg);
- if (!new_arg) exit(EXIT_FAILURE);
- char* dest_dir = get_destdir(cwd, new_arg);
- bool is_installed_locally = is_directory(dest_dir);
-
- char *verptr = strchr(new_arg, '@');
- char *trgptr = strchr(new_arg, ',');
- for (size_t i = 0; i < cached_repos_count; i++) {
- if (strcmp(cached_repos[i].source_key, new_arg) != 0) continue;
- pkg.ver = cached_repos[i].version;
- }
- if (verptr) {
- pkg.ver = verptr + 1;
- *verptr = '\0';
- }
- if (trgptr) {
- pkg.target = trgptr + 1;
- *trgptr = '\0';
- } else {
- pkg.target = is_verbose ? "default" : "quiet";
- }
-
- 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(new_arg, "http", 4) == 0 || strncmp(new_arg, "ssh", 3) == 0) {
- pkg.url = strdup(new_arg);
- pkg.name = name_from_url(new_arg);
- } else if (strcmp(new_arg, ".") == 0) {
- pkg.url = "";
- pkg.name = name_from_url(cwd);
- 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;
- } else if (is_installed_locally) {
- pkg.url = "";
- pkg.name = name_from_url(dest_dir);
- pkg.is_local = true;
- } else {
- printf("%s '%s' is not a valid package\n", print_error, new_arg);
- exit(EXIT_FAILURE);
- }
- rmdotgit(pkg);
- snprintf(pkg.src, MAX_PATH_LEN, "%s", get_pkgsrc(pkg));
- return pkg;
-} \ No newline at end of file
diff --git a/src/declare.c b/src/declare.c
deleted file mode 100644
index 2841cf9..0000000
--- a/src/declare.c
+++ /dev/null
@@ -1,37 +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/>.
-
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "declare.h"
-#include "create_pkg.h"
-#include "update_pkg.h"
-#include "lua_state.h"
-
-void declare(void) {
- init_lua_state();
- cache_repos();
- for (size_t i = 0; i < cached_repos_count; i++) {
- Pkg pkg = create_pkg(cached_repos[i].source_value);
- update_pkg(pkg);
- }
-}
diff --git a/src/fetch_git.c b/src/fetch_git.c
deleted file mode 100644
index 2640f9c..0000000
--- a/src/fetch_git.c
+++ /dev/null
@@ -1,105 +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/>.
-
-*/
-
-#include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/wait.h>
-#include <unistd.h>
-
-#include "fetch_git.h"
-
-#include "lua_state.h"
-#include "vars.h"
-
-int fetch_git(Pkg pkg) {
- pid_t pid = fork();
- if (pid == 0) {
- if (!is_verbose) {
- int nullfd = open("/dev/null", O_WRONLY);
- if (nullfd >= 0) {
- dup2(nullfd, STDOUT_FILENO);
- dup2(nullfd, STDERR_FILENO);
- close(nullfd);
- }
- }
- const char *argv[12];
- int i = 0;
- argv[i++] = "git";
- argv[i++] = "-c";
- argv[i++] = "advice.detachedHead=false";
- argv[i++] = "clone";
- if (strcmp(pkg.ver, "HEAD") != 0) {
- argv[i++] = "--branch";
- argv[i++] = pkg.ver;
- }
- argv[i++] = "--recursive";
- argv[i++] = "--depth";
- argv[i++] = "1";
- argv[i++] = pkg.url;
- argv[i++] = pkg.src;
- argv[i] = NULL;
- execvp("git", (char *const *)argv);
- _exit(127);
- }
-
- int status;
- waitpid(pid, &status, 0);
- int result = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
- if (result != 0) {
- pid_t pid = fork();
- if (pid == 0) {
- if (!is_verbose) {
- int nullfd = open("/dev/null", O_WRONLY);
- if (nullfd >= 0) {
- dup2(nullfd, STDOUT_FILENO);
- dup2(nullfd, STDERR_FILENO);
- close(nullfd);
- }
- }
- const char *argv[12];
- int i = 0;
- argv[i++] = "git";
- argv[i++] = "-c";
- argv[i++] = "advice.detachedHead=false";
- argv[i++] = "clone";
- if (strcmp(pkg.ver, "HEAD") != 0) {
- argv[i++] = "--branch";
- argv[i++] = pkg.ver;
- }
- argv[i++] = "--recursive";
- argv[i++] = pkg.url;
- argv[i++] = pkg.src;
- argv[i] = NULL;
- execvp("git", (char *const *)argv);
- _exit(127);
- }
-
- int status;
- waitpid(pid, &status, 0);
- result = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
- if (result != 0) printf(
- "%s git clone failed: %d\n",
- print_warning, result
- );
- }
-
- return result;
-} \ No newline at end of file
diff --git a/src/fetch_pwd.c b/src/fetch_pwd.c
deleted file mode 100644
index 32edd79..0000000
--- a/src/fetch_pwd.c
+++ /dev/null
@@ -1,73 +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/>.
-
-*/
-
-#include <stdio.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <ftw.h>
-#include <unistd.h>
-
-#include "fetch_pwd.h"
-#include "vars.h"
-
-static const char *pwd_dst;
-
-static int copy_entry(
- const char *fpath, const struct stat *sb,
- int typeflag, struct FTW *ftwbuf
-) {
- (void)ftwbuf;
- const char *rel = fpath;
- if (rel[0] == '.' && rel[1] == '/') rel += 2;
- if (rel[0] == '\0') return 0;
-
- char dst[MAX_PATH_LEN];
- snprintf(dst, sizeof(dst), "%s/%s", pwd_dst, rel);
-
- if (typeflag == FTW_D) {
- mkdir(dst, 0755);
- } else if (typeflag == FTW_F) {
- int src_fd = open(fpath, O_RDONLY);
- if (src_fd < 0) return -1;
-
- int dst_fd = open(dst, O_WRONLY | O_CREAT | O_TRUNC, sb->st_mode & 07777);
- if (dst_fd < 0) { close(src_fd); return -1; }
-
- char buf[8192];
- ssize_t n;
- while ((n = read(src_fd, buf, sizeof(buf))) > 0) {
- ssize_t written = 0;
- while (written < n) {
- ssize_t ret = write(dst_fd, buf + written, n - written);
- if (ret < 0) { close(src_fd); close(dst_fd); return -1; }
- written += ret;
- }
- }
-
- close(src_fd);
- close(dst_fd);
- }
- return 0;
-}
-
-void fetch_pwd(Pkg pkg) {
- pwd_dst = pkg.src;
- nftw(".", copy_entry, 64, FTW_PHYS);
-} \ No newline at end of file
diff --git a/src/fetch_src.c b/src/fetch_src.c
deleted file mode 100644
index 69b1ec9..0000000
--- a/src/fetch_src.c
+++ /dev/null
@@ -1,80 +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/>.
-
-*/
-
-#include <ftw.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#include "fetch_git.h"
-#include "fetch_src.h"
-#include "vars.h"
-
-static int remove_tree(
- const char *fpath, const struct stat *sb,
- int typeflag, struct FTW *ftwbuf
-) {
- (void)sb;
- (void)ftwbuf;
- if (typeflag == FTW_F || typeflag == FTW_SL) {
- unlink(fpath);
- } else if (typeflag == FTW_DP) {
- rmdir(fpath);
- }
- return 0;
-}
-
-void fetch_src(Pkg pkg) {
- if (is_verbose)
- printf(
- "%s target source directory: %s\n",
- print_pkgit, pkg.src
- );
- if (file_exists(pkg.src)) {
- if (is_verbose) printf(
- "%s %s already exists. deleting...\n",
- print_pkgit, pkg.src
- );
- chdir("..");
- nftw(pkg.src, remove_tree, 64, FTW_DEPTH | FTW_PHYS);
- }
- if (strcmp(pkg.url, "") == 0) {
- if (is_verbose) printf(
- "%s creating directory %s...\n",
- print_pkgit, pkg.src
- );
- mkdir_p(pkg.src);
- return;
- }
- if (fetch_git(pkg) == 0) {
- if (is_verbose) printf(
- "%s cloned into %s\n",
- print_pkgit, pkg.src
- );
- return;
- }
- printf(
- "%s no fetch methods worked.\n",
- print_error
- );
- exit(EXIT_FAILURE);
-} \ No newline at end of file
diff --git a/src/files.c b/src/files.c
deleted file mode 100644
index 9f13759..0000000
--- a/src/files.c
+++ /dev/null
@@ -1,163 +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/>.
-
-*/
-
-#include <dirent.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-const char *get_filename_ext(const char *filename) {
- const char *dot = strrchr(filename, '.');
- if (!dot || dot == filename) return "";
- return dot + 1;
-}
-
-static int write_all(int fd, const void *buf, size_t size) {
- while (size) {
- ssize_t written = write(fd, buf, size);
- if (written < 0) {
- return -1;
- }
-
- size -= written;
- buf = (const char *)buf + written;
- }
-
- return 0;
-}
-
-static int copy_file_content(int src_fd, int dst_fd) {
- char buf[4096];
- ssize_t readed;
- while ((readed = read(src_fd, buf, sizeof(buf))) > 0) {
- if (write_all(dst_fd, buf, readed) < 0) {
- perror("write_all");
- return -1;
- }
- }
-
- if (readed < 0) {
- perror("read");
- return -1;
- }
-
- return 0;
-}
-
-static int copy_at(int src_dir_fd, const char *src_path, int dst_dir_fd, const char *dst_path);
-
-static int copy_dir_content(int src_fd, int dst_fd) {
- int ret = -1;
- // duplicate the descriptor to prevent closedir from closing original one
- src_fd = dup(src_fd);
- if (src_fd < 0) {
- perror("dup");
- goto cleanup0;
- }
-
- DIR *src_dir = fdopendir(src_fd);
- if (!src_dir) {
- perror("fdopendir");
- close(src_fd);
- goto cleanup0;
- }
-
- for (struct dirent *ent; (errno = 0, ent = readdir(src_dir));) {
- if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) {
- continue;
- }
-
- if (copy_at(src_fd, ent->d_name, dst_fd, ent->d_name) < 0) {
- goto cleanup1;
- }
- }
-
- if (errno != 0) {
- perror("readdir");
- goto cleanup1;
- }
-
- ret = 0;
-
- cleanup1:
- closedir(src_dir);
- cleanup0:
- return ret;
-}
-
-static int copy_at(int src_dir_fd, const char *src_path, int dst_dir_fd, const char *dst_path) {
- int ret = -1;
- int src_fd = openat(src_dir_fd, src_path, O_NOFOLLOW | O_RDONLY);
- if (src_fd < 0) {
- perror("openat");
- goto cleanup0;
- }
-
- struct stat stat;
- if (fstat(src_fd, &stat) < 0) {
- perror("fstat");
- goto cleanup1;
- }
-
- int dst_oflag = O_NOFOLLOW;
- if (S_ISDIR(stat.st_mode)) {
- if (mkdirat(dst_dir_fd, dst_path, stat.st_mode) < 0) {
- perror("mkdirat");
- goto cleanup1;
- }
-
- dst_oflag |= O_RDONLY | O_DIRECTORY;
- } else {
- dst_oflag |= O_WRONLY | O_CREAT | O_EXCL;
- }
-
- int dst_fd = openat(dst_dir_fd, dst_path, dst_oflag, stat.st_mode);
- if (dst_fd < 0) {
- perror("openat");
- goto cleanup1;
- }
-
- switch (stat.st_mode & S_IFMT) {
- case S_IFDIR:
- ret = copy_dir_content(src_fd, dst_fd);
- break;
- case S_IFREG:
- ret = copy_file_content(src_fd, dst_fd);
- break;
- default:
- fprintf(stderr, "copy_at: unsupported file inode type\n");
- }
- goto cleanup2;
-
- cleanup2:
- close(dst_fd);
- cleanup1:
- close(src_fd);
- cleanup0:
- return ret;
-}
-
-void cpdir(const char *src_path, const char *dst_path) {
- copy_at(AT_FDCWD, src_path, AT_FDCWD, dst_path);
-}
diff --git a/src/help.c b/src/help.c
deleted file mode 100644
index 1cb4e6b..0000000
--- a/src/help.c
+++ /dev/null
@@ -1,56 +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/>.
-
-*/
-
-#include <stdio.h>
-
-#include "help.h"
-#include "vars.h"
-
-void help(void) {
- if (is_verbose) {
- printf("%s , \n", bold_magenta);
- printf("%s / \\ \n", bold_magenta);
- printf("%s_.--' '--._ \n", bold_magenta);
- printf("%s`'--, ,--'` %spkgit %s%s- package it!%s\n", bold_magenta, color_reset, italic, gray, color_reset);
- printf("%s _- %s\\ /%s -_ %s%s%s\n", bold_yellow, bold_magenta, bold_yellow, magenta, version, color_reset);
- printf("%s'-_ %s'%s _-' \n", bold_yellow, bold_magenta, bold_yellow);
- printf("%s `'-.-'` %s\n", bold_yellow, color_reset);
- } else {
- printf("pkgit %s%s- package it!%s\n", italic, gray, color_reset);
- printf("%s%s%s\n", magenta, version, color_reset);
- }
- printf("\n");
- printf("%ssubcommand flags%s:\n", red, color_reset);
- printf("%s %s-a%s, %s--add %s[url] %s# add a repo\n", color_reset, green, color_reset, yellow, blue, gray);
- printf("%s %s-b%s, %s--build %s[path] %s# build a package\n", color_reset, green, color_reset, yellow, blue, gray);
- printf("%s %s-d%s, %s--declare %s# install all packages\n", color_reset, green, color_reset, yellow, gray);
- printf("%s %s-s%s, %s--search %s[pkgs] %s# find a package from your repos\n", color_reset, green, color_reset, yellow, blue, gray);
- printf("%s %s-i%s, %s--install %s[pkgs, urls] %s# install a package/repo\n", color_reset, green, color_reset, yellow, blue, gray);
- printf("%s %s-r%s, %s--remove %s[pkgs] %s# remove an installed package\n", color_reset, green, color_reset, yellow, blue, gray);
- printf("%s %s-l%s, %s--list %s# list all installed packages\n", color_reset, green, color_reset, yellow, gray);
- printf("%s %s-u%s, %s--update %s# update all installed packages\n", color_reset, green, color_reset, yellow, gray);
- printf("%s %s-h%s, %s--help %s# display this help message\n", color_reset, green, color_reset, yellow, gray);
- printf("%s %s-v%s, %s--version %s# display version number\n", color_reset, green, color_reset, yellow, gray);
- printf("%s %s-c%s, %s--check %s# run package checks\n", color_reset, green, color_reset, yellow, gray);
- printf("\n");
- printf("%smodifier flags%s:\n", red, color_reset);
- printf("%s %s-q%s, %s--quiet %s# run without logging to terminal\n", color_reset, green, color_reset, yellow, gray);
- printf("%s %s-f%s, %s--force %s# force an operation like 'install'\n", color_reset, green, color_reset, yellow, gray);
-}
diff --git a/src/install_pkg.c b/src/install_pkg.c
deleted file mode 100644
index c233976..0000000
--- a/src/install_pkg.c
+++ /dev/null
@@ -1,126 +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/>.
-
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "add_repo.h"
-#include "build.h"
-#include "fetch_src.h"
-#include "files.h"
-#include "install_pkg.h"
-#include "lua_state.h"
-#include "name_from_url.h"
-#include "vars.h"
-
-void install_pkg(Pkg pkg) {
- if (is_directory(pkg.src)) {
- if (!is_forced) {
- if (is_verbose) printf(
- "%s %s is already installed.\n",
- print_skipped, pkg.name
- );
- return;
- } else {
- if (is_verbose) printf(
- "%s %s is already installed.\n",
- print_warning, pkg.name
- );
- }
- }
- char cwd[MAX_PATH_LEN];
- getcwd(cwd, MAX_PATH_LEN);
- if (strcmp(pkg.src, cwd) != 0) chdir(pkg.src);
-
- if (pkg.is_local) {
- cpdir(cwd, pkg.src);
- } else {
- printf(
- "%s fetching %s%s%s\n",
- print_pkgit, green, pkg.name, color_reset
- );
- fetch_src(pkg);
- if (is_verbose) printf(
- "%s fetched %s%s%s\n",
- print_pkgit, green, pkg.name, color_reset
- );
- }
-
- printf(
- "%s building %s%s%s\n",
- print_pkgit, green, pkg.name, color_reset
- );
- build(pkg);
- if (is_verbose) printf(
- "%s built %s%s%s\n",
- print_pkgit, green, pkg.name, color_reset
- );
-
- printf(
- "%s installing %s%s%s\n",
- print_pkgit, green, pkg.name, color_reset
- );
- bool install_success = false;
- if (!install_success && repo_install(pkg.name, pkg.target))
- install_success = true;
- if (!install_success && bldit_install(pkg.target))
- install_success = true;
- if (!install_success && config_install(pkg.src, pkg.target))
- install_success = true;
- if (!install_success) {
- printf(
- "%s no install function availible for package: %s\n",
- print_error, pkg.name
- );
- return;
- }
- printf(
- "%s installed %s%s%s\n",
- print_success, green, pkg.name, color_reset
- );
-
- bool repo_exists = false;
- for (size_t i = 0; i < cached_repos_count; i++) {
- char *repo_name = name_from_url(cached_repos[i].source_key);
- if (strcmp(repo_name, pkg.name) == 0) { repo_exists = true; }
- free(repo_name);
- }
-
- if (!repo_exists) {
- printf(
- "%s adding %s%s%s\n",
- print_pkgit, green, pkg.name, color_reset
- );
- if (pkg.url && strlen(pkg.url) > 0) {
- add_repo(pkg.url, pkg.name);
- }
- printf(
- "%s added %s%s%s\n",
- print_pkgit, green, pkg.name, color_reset
- );
- } else {
- if (is_verbose) printf(
- "%s repo already exists, done\n",
- print_pkgit
- );
- }
-} \ No newline at end of file
diff --git a/src/is_updated.c b/src/is_updated.c
deleted file mode 100644
index f9d31aa..0000000
--- a/src/is_updated.c
+++ /dev/null
@@ -1,59 +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/>.
-
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdbool.h>
-#include <unistd.h>
-
-#include "is_updated.h"
-
-#include "cmd_out.h"
-#include "lua_state.h"
-
-bool is_updated(const char *src) {
- bool result = false;
- if (src && strlen(src) > 0 && chdir(src) != 0) return result;
- char *bldit_pkgver = bldit_pkg_getver();
- char *git_tag = cmd_out("git tag | tail -n 1");
- result = (strstr(git_tag, bldit_pkgver) != NULL && strlen(bldit_pkgver) != 0);
- char *git_pull = cmd_out("git pull");
- result = (strstr(git_pull, "Already up to date.") != NULL);
- free(git_tag);
- free(git_pull);
- free(bldit_pkgver);
- return result;
-}
-
-bool is_bldit_usable(void) {
- char* bldit_version = bldit_getver();
- if (!bldit_version) return false;
- if (strcmp(bldit_version, version) == 0) return true;
- bool prev_pass = false;
- for (size_t i = 0; i < strlen(bldit_version); i++) {
- if (bldit_version[i] == '.') continue;
- if ((bldit_version[i] - '0') <= (version[i] - '0')) {
- prev_pass = ((bldit_version[i] - '0') != (version[i] - '0'));
- continue;
- } else return prev_pass;
- }
- return true;
-} \ No newline at end of file
diff --git a/src/list_pkgs.c b/src/list_pkgs.c
deleted file mode 100644
index 365e9b8..0000000
--- a/src/list_pkgs.c
+++ /dev/null
@@ -1,50 +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/>.
-
-*/
-
-#include <dirent.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/stat.h>
-
-#include "lua_state.h"
-#include "vars.h"
-
-void list_pkgs(void) {
- char* src_code = map_get(&cached_install_directories, "src");
- struct dirent* dirent_ptr;
- DIR* dir_ptr = opendir(src_code);
-
- if (dir_ptr == NULL) {
- fprintf(
- stderr,
- "%s could not open %s\n",
- print_pkgit, src_code
- );
- return;
- }
-
- while ((dirent_ptr = readdir(dir_ptr)) != NULL) {
- if (
- strcmp(dirent_ptr->d_name, "..") == 0 ||
- strcmp(dirent_ptr->d_name, ".") == 0
- ) continue;
- printf("%s\n", dirent_ptr->d_name);
- }
-} \ No newline at end of file
diff --git a/src/lua_build.c b/src/lua_build.c
deleted file mode 100644
index 520117c..0000000
--- a/src/lua_build.c
+++ /dev/null
@@ -1,62 +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/>.
-
-*/
-
-#include <stdio.h>
-#include <stdbool.h>
-
-#include "lua_build.h"
-
-#include "is_updated.h"
-#include "lua_state.h"
-#include "vars.h"
-
-bool lua_build(const char *repository, const char *target, const char *path) {
- if (is_verbose) printf(
- "%s attempting init.lua: 'repositories.%s.build'\n",
- print_pkgit, repository
- );
- if (repo_build(repository, target)) { return true; }
- if (is_verbose) printf(
- "%s failed init.lua: 'repositories.%s.build'\n",
- print_warning, repository
- );
-
- if (is_verbose) printf(
- "%s attempting bldit.lua\n",
- print_pkgit
- );
- if (bldit(target)) { return true; }
- if (is_verbose) printf(
- "%s failed bldit.lua\n",
- print_warning
- );
-
- if (is_verbose) printf(
- "%s attempting init.lua: 'build_systems'\n",
- print_pkgit
- );
- if (config_build(path, target)) { return true; }
- if (is_verbose) printf(
- "%s failed init.lua: 'build_systems'\n",
- print_warning
- );
-
- return false;
-} \ No newline at end of file
diff --git a/src/lua_state.c b/src/lua_state.c
deleted file mode 100644
index 9ba71de..0000000
--- a/src/lua_state.c
+++ /dev/null
@@ -1,915 +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/>.
-
-*/
-
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "create_pkg.h"
-#include "install_pkg.h"
-#include "is_updated.h"
-#include "lua_state.h"
-#include "vars.h"
-
-static lua_State *L = NULL;
-static bool config_loaded = false;
-
-static lua_State *B = NULL;
-static bool bldit_loaded = false;
-
-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 = "";
- lua_pop(L, 1);
- lua_pushfstring(L, "%s;%s", current_path, new_path);
- lua_setfield(L, -2, "path");
- lua_pop(L, 1);
-}
-
-void init_lua_state(void) {
- 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);
- push_lua_path(L, lua_path);
- if (luaL_loadfile(L, config_file) || 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"
- );
- exit(EXIT_FAILURE);
- }
- if (file_exists(repo_file)) {
- if (luaL_loadfile(L, repo_file) || lua_pcall(L, 0, 0, 0)) {
- printf(
- "%s cannot load repository file: %s\n",
- print_error, lua_tostring(L, -1)
- );
- lua_pop(L, 1);
- }
- }
- config_loaded = true;
-}
-
-void init_bldit(void) {
- 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)
- );
- return;
- }
- bldit_loaded = true;
-}
-
-void free_lua_state(void) {
- if (L != NULL) {
- lua_close(L);
- L = NULL;
- }
- config_loaded = false;
-}
-
-lua_State *get_lua_state(void) { return L; }
-
-const char* get_privilege_escalator(void) {
- lua_getglobal(L, "privilege_escalator");
- if (!lua_isstring(L, -1)) {
- printf(
- "%s init.lua: 'privilege_escalator' is not a string.\n",
- print_error
- );
- return "";
- }
- const char* privilege_escalator = lua_tostring(L, -1);
- lua_pop(L, 1);
- return privilege_escalator;
-}
-
-void cache_prefix_directory(void) {
- lua_getglobal(L, "prefix");
- if (!lua_isstring(L, -1)) {
- printf(
- "%s init.lua: 'prefix' is not a string.\n",
- print_error
- );
- return;
- }
- snprintf(prefix_dir, MAX_PATH_LEN, "%s", lua_tostring(L, -1));
- lua_pop(L, 1);
-}
-
-void cache_install_directories(void) {
- if (!config_loaded || !lua_istable(L, -1)) {
- lua_getglobal(L, "install_directories");
- }
- if (!lua_istable(L, -1)) {
- printf(
- "%s init.lua: 'install_directories' is not a table.\n",
- print_error
- );
- return;
- }
- lua_pushnil(L);
- while (lua_next(L, -2) != 0) {
- const char *key = lua_tostring(L, -2);
- const char *value = lua_tostring(L, -1);
- if (key && value) {
- map_put(&cached_install_directories, strdup(key), strdup(value));
- }
- lua_pop(L, 1);
- }
- lua_pop(L, 1);
-}
-
-void install_dependencies(lua_State *L) {
- while (lua_next(L, -2) != 0) {
- const char *depname = lua_tostring(L, -2);
- if (depname && lua_istable(L, -1)) {
- lua_getfield(L, -1, "url");
- const char *dep_url = lua_tostring(L, -1);
- lua_pop(L, 1);
- lua_getfield(L, -1, "version");
- const char *dep_version = lua_tostring(L, -1);
- lua_pop(L, 1);
- Pkg pkg = create_pkg(dep_url);
- pkg.ver = strdup(dep_version);
- const int top = lua_gettop(L);
- char cwd[PATH_MAX];
- if (getcwd(cwd, sizeof(cwd)) != NULL) {
- install_pkg(pkg);
- chdir(cwd);
- }
- lua_settop(L, top);
- }
- lua_pop(L, 1);
- }
-}
-
-bool on_update(lua_State *L) {
- const char* lua_file = "init.lua";
- lua_getglobal(L, "on_update");
- if (!lua_isfunction(L, -1)) {
- if (is_verbose) printf(
- "%s %s: 'on_update' is not a function.\n",
- print_warning, lua_file
- );
- lua_pop(L, 2);
- return false;
- }
- if (lua_pcall(L, 0, 1, 0) != LUA_OK) {
- printf(
- "%s %s: 'on_update' function borked: %s\n",
- print_error, lua_file, lua_tostring(L, -1)
- );
- lua_pop(L, 2);
- return false;
- }
- if ((int)lua_tonumber(L, -1) != 0) if (is_verbose) {
- printf(
- "%s %s: 'on_update' failed: %s\n",
- print_error, lua_file, lua_tostring(L, -1)
- );
- lua_pop(L, 2);
- return false;
- }
- lua_pop(L, 2);
- return true;
-}
-
-bool target_loop_on_update(
- lua_State *L, const char* lua_file, const char *target
-) {
- lua_getfield(L, -1, target);
- if (!lua_istable(L, -1)) {
- if (is_verbose) printf(
- "%s %s: 'targets.%s' is not a table.\n",
- print_warning, lua_file, target
- );
- lua_pop(L, 1);
- if (strcmp(target, "quiet") == 0) {
- target_loop_on_update(L, lua_file, "default");
- lua_pop(L, 1);
- }
- return false;
- }
- lua_getfield(L, -1, "on_update");
- if (!lua_isfunction(L, -1)) {
- if (is_verbose) printf(
- "%s %s: 'targets.%s.on_update' is not a function.\n",
- print_warning, lua_file, target
- );
- lua_pop(L, 3);
- return false;
- }
- if (lua_pcall(L, 0, 1, 0) != LUA_OK) {
- printf(
- "%s %s: 'targets.%s.on_update' function borked: %s\n",
- print_error, lua_file, target, lua_tostring(L, -1)
- );
- lua_pop(L, 3);
- return false;
- }
- if ((int)lua_tonumber(L, -1) != 0) if (is_verbose) {
- printf(
- "%s %s: 'targets.%s.on_update' failed: %s\n",
- print_error, lua_file, target, lua_tostring(L, -1)
- );
- lua_pop(L, 3);
- return false;
- }
- lua_pop(L, 3);
- return true;
-}
-
-bool target_loop_build(
- lua_State *L, const char* lua_file, const char *target
-) {
- lua_getfield(L, -1, target);
- if (!lua_istable(L, -1)) {
- if (is_verbose) printf(
- "%s %s: 'targets.%s' is not a table.\n",
- print_warning, lua_file, target
- );
- lua_pop(L, 1);
- if (strcmp(target, "quiet") == 0) {
- target_loop_build(L, lua_file, "default");
- lua_pop(L, 1);
- }
- return false;
- }
- lua_getfield(L, -1, "dependencies");
- if (lua_istable(L, -1)) {
- lua_pushnil(L);
- install_dependencies(L);
- }
- lua_pop(L, 1);
- lua_getfield(L, -1, "build");
- if (!lua_isfunction(L, -1)) {
- if (is_verbose) printf(
- "%s %s: 'targets.%s.build' is not a function.\n",
- print_warning, lua_file, target
- );
- lua_pop(L, 3);
- return false;
- }
- if (lua_pcall(L, 0, 1, 0) != LUA_OK) {
- printf(
- "%s %s: 'targets.%s.build' function borked: %s\n",
- print_error, lua_file, target, lua_tostring(L, -1)
- );
- lua_pop(L, 3);
- return false;
- }
- if ((int)lua_tonumber(L, -1) != 0) if (is_verbose) {
- printf(
- "%s %s: 'targets.%s.build' failed: %s\n",
- print_error, lua_file, target, lua_tostring(L, -1)
- );
- lua_pop(L, 3);
- return false;
- }
- lua_pop(L, 3);
- return true;
-}
-
-bool target_loop_install(
- lua_State *L, const char* lua_file,
- const char *target
-) {
- lua_getfield(L, -1, target);
- if (!lua_istable(L, -1)) {
- if (is_verbose) printf(
- "%s %s: 'targets.%s' is not a table.\n",
- print_warning, lua_file, target
- );
- lua_pop(L, 1);
- if (strcmp(target, "quiet") == 0) {
- target_loop_install(L, lua_file, "default");
- lua_pop(L, 1);
- }
- return false;
- }
- lua_getfield(L, -1, "pre_install");
- if (!lua_isfunction(L, -1)) {
- if (is_verbose) printf(
- "%s %s: 'targets.%s.pre_install' is not a function.\n",
- print_warning, lua_file, target
- );
- } else if (lua_pcall(L, 0, 1, 0) != LUA_OK) {
- if (is_verbose) printf(
- "%s %s: 'targets.%s.pre_install' function borked: %s\n",
- print_warning, lua_file, target, lua_tostring(L, -1)
- );
- if ((int)lua_tonumber(L, -1) != 0) if (is_verbose) {
- printf(
- "%s %s: 'targets.%s.pre_install' failed: %d\n",
- print_error, lua_file, target, (int)lua_tonumber(L, -1)
- );
- return false;
- }
- }
- lua_pop(L, 1);
- lua_getfield(L, -1, "install");
- if (!lua_isfunction(L, -1)) {
- if (is_verbose) printf(
- "%s %s: 'targets.%s.install' is not a function.\n",
- print_warning, lua_file, target
- );
- lua_pop(L, 1);
- return false;
- }
- if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
- if (is_verbose) printf(
- "%s %s: 'targets.%s.install' function borked: %s\n",
- print_warning, lua_file, target, lua_tostring(L, -1)
- );
- lua_pop(L, 1);
- return false;
- }
- if ((int)lua_tonumber(L, -1) != 0) if (is_verbose) {
- printf(
- "%s %s: 'targets.%s.install' failed: %d\n",
- print_error, lua_file, target, (int)lua_tonumber(L, -1)
- );
- lua_pop(L, 1);
- return false;
- }
- lua_pop(L, 1);
- lua_getfield(L, -1, "post_install");
- if (!lua_isfunction(L, -1)) {
- if (is_verbose) printf(
- "%s %s: 'targets.%s.post_install' is not a function.\n",
- print_warning, lua_file, target
- );
- } else if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
- if (is_verbose) printf(
- "%s %s: 'targets.%s.post_install' function borked: %s\n",
- print_warning, lua_file, target, lua_tostring(L, -1)
- );
- if ((int)lua_tonumber(L, -1) != 0) if (is_verbose) {
- printf(
- "%s %s: 'targets.%s.post_install' failed: %s\n",
- print_error, lua_file, target, lua_tostring(L, -1)
- );
- }
- }
- lua_pop(L, 1);
- return true;
-}
-
-bool target_loop_uninstall(lua_State *L, const char *lua_file, const char *target) {
- lua_getfield(L, -1, target);
- if (!lua_istable(L, -1)) {
- if (is_verbose) printf(
- "%s %s: 'targets.%s' is not a table.\n",
- print_warning, lua_file, target
- );
- lua_pop(L, 1);
- if (strcmp(target, "quiet") == 0) {
- target_loop_uninstall(L, lua_file, "default");
- lua_pop(L, 1);
- }
- return false;
- }
- lua_getfield(L, -1, "uninstall");
- if (!lua_isfunction(L, -1)) {
- if (is_verbose) printf(
- "%s %s: 'targets.%s.uninstall' is not a function.\n",
- print_warning, lua_file, target
- );
- lua_pop(L, 1);
- return false;
- }
- if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
- if (is_verbose) printf(
- "%s %s: 'targets.%s.uninstall' function borked: %s\n",
- print_warning, lua_file, target, lua_tostring(L, -1)
- );
- lua_pop(L, 1);
- return false;
- }
- if ((int)lua_tonumber(L, -1) != 0) if (is_verbose) {
- printf(
- "%s %s: 'targets.%s.uninstall' failed: %s\n",
- print_error, lua_file, target, lua_tostring(L, -1)
- );
- lua_pop(L, 1);
- return false;
- }
- lua_pop(L, 1);
- return true;
-}
-
-bool repo_build(const char *repository, const char *target) {
- lua_getglobal(L, "repositories");
- if (!config_loaded || !lua_istable(L, -1)) {
- if (is_verbose) printf(
- "%s init.lua: 'repositories' is not a table.\n",
- print_warning
- );
- lua_pop(L, 1);
- return false;
- }
- lua_getfield(L, -1, repository);
- if (!lua_istable(L, -1)) {
- if (is_verbose) printf(
- "%s init.lua: 'repositories.%s' is not a table.\n",
- print_warning, repository
- );
- lua_pop(L, 2);
- return false;
- }
-
- lua_getfield(L, -1, "dependencies");
- if (!lua_istable(L, -1)) {
- if (is_verbose) printf(
- "%s init.lua: 'repositories.%s.dependencies' is not a table.\n",
- print_warning, repository
- );
- } else {
- lua_pushnil(L);
- install_dependencies(L);
- }
- lua_pop(L, 1);
-
- lua_getfield(L, -1, "targets");
- if (!lua_istable(L, -1)) {
- if (is_verbose) printf(
- "%s init.lua: 'repositories.%s.targets' is not a table.\n",
- print_warning, repository
- );
- return false;
- }
- bool target_loop_success = target_loop_build(L, "init.lua", target);
- lua_pop(L, 3);
- return target_loop_success;
-}
-
-bool repo_install(const char *repository, const char* target) {
- if (!access(prefix_dir, W_OK)) {
- lua_pushfstring(L, "%s", "");
- lua_setglobal(L, "privilege_escalator");
- lua_pop(L, 1);
- }
- lua_getglobal(L, "repositories");
- if (!config_loaded || !lua_istable(L, -1)) {
- if (is_verbose) printf(
- "%s init.lua: 'repositories' is not a table.\n",
- print_warning
- );
- lua_pop(L, 1);
- return false;
- }
- lua_getfield(L, -1, repository);
- if (!lua_istable(L, -1)) {
- if (is_verbose) printf(
- "%s init.lua: 'repositories.%s' is not a table.\n",
- print_warning, repository
- );
- lua_pop(L, 2);
- return false;
- }
- lua_getfield(L, -1, "targets");
- if (!lua_istable(L, -1)) {
- if (is_verbose) printf(
- "%s init.lua: 'repositories.%s.targets' is not a table.\n",
- print_warning, repository
- );
- return false;
- }
- bool target_loop_success = target_loop_install(L, "init.lua", target);
- lua_pop(L, 3);
- return target_loop_success;
-}
-
-bool repo_uninstall(const char *repository, const char *target) {
- if (!access(prefix_dir, W_OK)) {
- lua_pushfstring(L, "%s", get_privilege_escalator());
- lua_setglobal(L, "privilege_escalator");
- lua_pop(L, 1);
- }
- lua_getglobal(L, "repositories");
- if (!config_loaded || !lua_istable(L, -1)) {
- if (is_verbose) printf(
- "%s init.lua: 'repositories' is not a table.\n",
- print_warning
- );
- lua_pop(L, 1);
- return false;
- }
- lua_getfield(L, -1, repository);
- if (!lua_istable(L, -1)) {
- if (is_verbose) printf(
- "%s init.lua: 'repositories.%s' is not a table.\n",
- print_warning, repository
- );
- lua_pop(L, 2);
- return false;
- }
- lua_getfield(L, -1, "targets");
- if (!lua_istable(L, -1)) {
- if (is_verbose) printf(
- "%s init.lua: 'repositories.%s.targets' is not a table.\n",
- print_warning, repository
- );
- return false;
- }
- bool target_loop_success = target_loop_uninstall(L, "init.lua", target);
- lua_pop(L, 2);
- return target_loop_success;
-}
-
-char* bldit_getver(void) {
- init_bldit();
- lua_getglobal(B, "bldit_version");
- if (!lua_isstring(B, -1)) {
- if (is_verbose) printf(
- "%s bldit.lua: 'bldit_version' is not a string.\n",
- print_warning
- );
- lua_pop(B, 1);
- return NULL;
- }
- const char* bldit_version = lua_tostring(B, -1);
- lua_pop(B, 1);
- return strdup(bldit_version);
-}
-
-char* bldit_pkg_getver(void) {
- init_bldit();
- lua_getglobal(B, "package_version");
- if (!lua_isstring(B, -1)) {
- if (is_verbose) printf(
- "%s bldit.lua: 'package_version' is not a string.\n",
- print_warning
- );
- lua_pop(B, 1);
- return strdup("");
- }
- const char* package_version = lua_tostring(B, -1);
- lua_pop(B, 1);
- return strdup(package_version);
-}
-
-bool bldit(const char *target) {
- lua_State *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)
- );
- lua_close(B);
- return false;
- }
- if (!is_bldit_usable()) {
- printf(
- "%s bldit version is newer than the installed pkgit version\n",
- print_error
- );
- printf(
- "%s consider updating pkgit\n",
- print_pkgit
- );
- if (!is_forced) return false;
- }
- lua_pushfstring(B, "%s", prefix_dir);
- lua_setglobal(B, "prefix");
- lua_pop(B, 1);
- lua_getglobal(B, "dependencies");
- if (!lua_istable(B, -1)) {
- if (is_verbose) printf(
- "%s bldit.lua: 'dependencies' is not a table.\n", print_warning
- );
- } else {
- lua_pushnil(B);
- install_dependencies(B);
- }
- lua_pop(B, 1);
- lua_getglobal(B, "targets");
- if (!lua_istable(B, -1)) {
- if (is_verbose) printf(
- "%s bldit.lua: 'targets' is not a table.\n", print_warning
- );
- lua_close(B);
- return false;
- }
- bool target_loop_success = target_loop_build(B, "bldit.lua", target);
- lua_pop(B, 2);
- lua_close(B);
- return target_loop_success;
-}
-
-bool bldit_install(const char *target) {
- lua_State *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)
- );
- lua_close(B);
- return false;
- }
- if (!is_bldit_usable()) {
- printf(
- "%s bldit version is newer than the installed pkgit version\n",
- print_error
- );
- printf(
- "%s consider updating pkgit\n",
- print_pkgit
- );
- if (!is_forced) return false;
- }
- lua_pushfstring(B, "%s", prefix_dir);
- lua_setglobal(B, "prefix");
- lua_pop(B, 1);
- if (!access(prefix_dir, W_OK)) {
- lua_pushfstring(B, "%s", get_privilege_escalator());
- lua_setglobal(B, "privilege_escalator");
- lua_pop(B, 1);
- }
- lua_getglobal(B, "targets");
- if (!lua_istable(B, -1)) {
- if (is_verbose) printf(
- "%s bldit.lua: 'targets' is not a table.\n",
- print_warning
- );
- lua_pop(B, 1);
- lua_close(B);
- return false;
- }
- bool target_loop_success = target_loop_install(B, "bldit.lua", target);
- lua_pop(B, 1);
- lua_close(B);
- return target_loop_success;
-}
-
-bool bldit_uninstall(const char *target) {
- lua_State *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)
- );
- lua_close(B);
- return false;
- }
- if (!is_bldit_usable()) {
- printf(
- "%s bldit version is newer than the installed pkgit version\n",
- print_error
- );
- printf(
- "%s consider updating pkgit\n",
- print_pkgit
- );
- if (!is_forced) return false;
- }
- lua_pushfstring(B, "%s", prefix_dir);
- lua_setglobal(B, "prefix");
- lua_pop(B, 1);
- if (!access(prefix_dir, W_OK)) {
- lua_pushfstring(B, "%s", get_privilege_escalator());
- lua_setglobal(B, "privilege_escalator");
- lua_pop(B, 1);
- }
- lua_getglobal(B, "targets");
- if (!lua_istable(B, -1)) {
- if (is_verbose) printf(
- "%s bldit.lua: 'targets' is not a table.\n",
- print_warning
- );
- lua_close(B);
- return false;
- }
- lua_getfield(B, -1, target);
- if (!lua_istable(B, -1)) {
- if (is_verbose) printf(
- "%s bldit.lua: 'targets.%s' is not a table.\n",
- print_warning, target
- );
- lua_pop(B, 2);
- lua_close(B);
- return false;
- }
- lua_getglobal(B, "targets");
- if (!lua_istable(B, -1)) {
- if (is_verbose) printf("%s bldit.lua: 'targets' is not a table.\n", print_warning);
- lua_close(B);
- return false;
- }
- bool target_loop_success = target_loop_uninstall(B, "bldit.lua", target);
- lua_pop(B, 1);
- lua_close(B);
- return target_loop_success;
-}
-
-void cache_repos(void) {
- cached_repos_count = 0;
- lua_getglobal(L, "repositories");
- if (!config_loaded || !lua_istable(L, -1)) {
- printf(
- "%s init.lua: 'repositories' is not a table.\n",
- print_error
- );
- lua_pop(L, 1);
- return;
- }
- lua_pushnil(L);
- while (lua_next(L, -2) != 0) {
- const char *repo_name = lua_tostring(L, -2);
- if (!repo_name || !lua_istable(L, -1)) {
- printf("%s init.lua: 'repositories.%s' is not a table\n", print_error, repo_name);
- lua_pop(L, 1);
- continue;
- }
- Repo *repo = &cached_repos[cached_repos_count];
- repo->source_key = strdup(repo_name);
- lua_getfield(L, -1, "url");
- const char *url = lua_tostring(L, -1);
- repo->source_value = url ? strdup(url) : strdup("");
- lua_pop(L, 1);
- lua_getfield(L, -1, "version");
- const char *version = lua_tostring(L, -1);
- repo->version = version ? strdup(version) : strdup("HEAD");
- lua_pop(L, 1);
- lua_pop(L, 1);
- cached_repos_count++;
- }
- lua_pop(L, 1);
-}
-
-void cache_build_systems(void) {
- if (!config_loaded) {
- lua_getglobal(L, "build_systems");
- } else if (!lua_istable(L, -1)) {
- lua_getglobal(L, "build_systems");
- }
- if (!lua_istable(L, -1)) {
- printf("%s init.lua: 'build_systems' is not a table.\n", print_error);
- return;
- }
- lua_pushnil(L);
- while (lua_next(L, -2) != 0) {
- const char *key = lua_tostring(L, -2);
- if (lua_isfunction(L, -1) == 0) {
- printf("%s init.lua: 'build_systems.%s' is not a function\n", print_error, key);
- lua_pop(L, 1);
- continue;
- }
- map_put(&cached_build_systems, strdup(key), "");
- lua_pop(L, 1);
- }
- lua_pop(L, 1);
-}
-
-bool config_build(const char *path, const char *target) {
- lua_getglobal(L, "build_systems");
- if (!config_loaded || !lua_istable(L, -1)) {
- lua_pop(L, 1);
- return false;
- }
- bool target_loop_success = false;
- lua_pushnil(L);
- while (lua_next(L, -2) != 0) {
- const char *key = lua_tostring(L, -2);
- if (!lua_istable(L, -1)) {
- lua_pop(L, 1);
- continue;
- }
- char file_path[MAX_PATH_LEN];
- snprintf(file_path, sizeof(file_path), "%s/%s", path, key);
- if (access(file_path, F_OK) != 0) {
- lua_pop(L, 1);
- continue;
- }
- lua_getfield(L, -1, "targets");
- if (!lua_istable(L, -1)) {
- if (is_verbose) printf("%s init.lua: 'targets' is not a table.\n", print_warning);
- lua_pop(L, 1);
- continue;
- }
- target_loop_success = target_loop_build(L, "init.lua", target);
- lua_pop(L, 1);
- }
- lua_pop(L, 1);
- return target_loop_success;
-}
-
-bool config_install(const char *path, const char *target) {
- if (!access(prefix_dir, W_OK)) {
- lua_pushfstring(L, "%s", get_privilege_escalator());
- lua_setglobal(L, "privilege_escalator");
- lua_pop(L, 1);
- }
- lua_getglobal(L, "build_systems");
- if (!config_loaded || !lua_istable(L, -1)) {
- lua_pop(L, 1);
- return false;
- }
- lua_pushnil(L);
- bool target_loop_success = false;
- while (lua_next(L, -2) != 0) {
- const char *key = lua_tostring(L, -2);
- if (!lua_istable(L, -1)) {
- lua_pop(L, 1);
- continue;
- }
- char file_path[MAX_PATH_LEN];
- snprintf(file_path, sizeof(file_path), "%s/%s", path, key);
- if (access(file_path, F_OK) != 0) {
- lua_pop(L, 1);
- continue;
- }
- lua_getfield(L, -1, "targets");
- if (!lua_istable(L, -1)) {
- if (is_verbose) printf(
- "%s init.lua: 'build_systems.%s.targets' is not a table.\n",
- print_warning, key
- );
- lua_close(L);
- return false;
- }
- target_loop_success = target_loop_install(L, "init.lua", target);
- lua_pop(L, 2);
- }
- lua_pop(L, 1);
- return target_loop_success;
-}
-
-bool config_uninstall(const char *path, const char *target) {
- if (!access(prefix_dir, W_OK)) {
- lua_pushfstring(L, "%s", get_privilege_escalator());
- lua_setglobal(L, "privilege_escalator");
- lua_pop(L, 1);
- }
- lua_getglobal(L, "build_systems");
- if (!config_loaded || !lua_istable(L, -1)) {
- lua_pop(L, 1);
- return false;
- }
- lua_pushnil(L);
- bool target_loop_success = false;
- while (lua_next(L, -2) != 0) {
- const char *key = lua_tostring(L, -2);
- if (!lua_istable(L, -1)) {
- lua_pop(L, 1);
- continue;
- }
- char file_path[MAX_PATH_LEN];
- snprintf(file_path, sizeof(file_path), "%s/%s", path, key);
- if (access(file_path, F_OK) != 0) {
- lua_pop(L, 1);
- continue;
- }
- lua_getfield(L, -1, "targets");
- if (!lua_istable(L, -1)) {
- if (is_verbose) printf(
- "%s init.lua: 'build_systems.%s.targets' is not a table.\n",
- print_warning, key
- );
- lua_close(L);
- return false;
- }
- target_loop_success = target_loop_uninstall(L, "init.lua", target);
- lua_pop(L, 2);
- }
- lua_pop(L, 1);
- return target_loop_success;
-}
diff --git a/src/main.c b/src/main.c
index 6265db1..fd0732c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,34 +1,9 @@
-/*
+#include <stdio.h>
- pkgit - package it!
+#include "pkgit_string.h"
- 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/>.
-
-*/
-
-#include "cla_parse.h"
-#include "lua_state.h"
-#include "setup_pkgit.h"
-#include "vars.h"
-
-int main(int argc, char *argv[]) {
- init_vars();
- init_lua_state();
- setup_pkgit();
- cache_repos();
- cla_parse(argc, argv);
- free_lua_state();
+int main(int argc, char** argv) {
+ str_s slice = slice_trim(slice_from_cstr(" hello world "));
+ printf("[%.*s]\n", format_string(slice));
return 0;
-} \ No newline at end of file
+}
diff --git a/src/name_from_url.c b/src/name_from_url.c
deleted file mode 100644
index c1efc6f..0000000
--- a/src/name_from_url.c
+++ /dev/null
@@ -1,40 +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/>.
-
-*/
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include "name_from_url.h"
-
-char* name_from_url(const char *url) {
- size_t len = strlen(url);
- char* after_git = strdup(url);
- const char *end = after_git + len;
- while (end > after_git && *(end-1) == '/')
- end--;
- if (strncmp(end-4, ".git", 4) == 0)
- end -= 4;
- const char *last_slash = end;
- while (last_slash > after_git && *(last_slash-1) != '/')
- last_slash--;
- if (last_slash < end) return strndup(last_slash, end - last_slash);
- else return strndup(after_git, end - after_git);
-}
diff --git a/src/pkgit_string.c b/src/pkgit_string.c
new file mode 100644
index 0000000..cbcc200
--- /dev/null
+++ b/src/pkgit_string.c
@@ -0,0 +1,60 @@
+#include <ctype.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "pkgit_string.h"
+
+void print_slice(str_s slice) {
+ for (size_t i = 0; i < slice.len; i++) {
+ putchar(slice.data[i]);
+ }
+}
+
+str_s slice_from_cstr(char* cstr) {
+ return (str_s) {
+ .data = cstr,
+ .len = strlen(cstr),
+ };
+}
+
+int slice_eq(str_s a, str_s b) {
+ if (a.len != b.len) return 0;
+ for (size_t i = 0; i < a.len; i++) {
+ if (a.data[i] != b.data[i]) return 0;
+ }
+ return 1;
+}
+
+int slice_starts_with(str_s slice, str_s prefix) {
+ if (prefix.len > slice.len) return 0;
+ for (size_t i = 0; i < prefix.len; i++) {
+ if (slice.data[i] != prefix.data[i]) return 0;
+ }
+ return 1;
+}
+
+str_s slice_take(str_s slice, size_t n) {
+ if (n > slice.len) n = slice.len;
+ return (str_s) {
+ .data = slice.data,
+ .len = n
+ };
+}
+
+str_s slice_drop(str_s slice, size_t n) {
+ if (n > slice.len) n = slice.len;
+ return (str_s) {
+ .data = slice.data + n,
+ .len = slice.len - n
+ };
+}
+
+str_s slice_trim(str_s slice) {
+ while (slice.len > 0 && isspace((unsigned char)slice.data[0])) {
+ slice = slice_drop(slice, 1);
+ }
+ while (slice.len > 0 && isspace((unsigned char)slice.data[slice.len - 1])) {
+ slice = slice_take(slice, slice.len - 1);
+ }
+ return slice;
+}
diff --git a/src/remove_pkg.c b/src/remove_pkg.c
deleted file mode 100644
index 71d2f2f..0000000
--- a/src/remove_pkg.c
+++ /dev/null
@@ -1,118 +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/>.
-
-*/
-
-#include <ftw.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#include "lua_state.h"
-#include "remove_pkg.h"
-#include "vars.h"
-
-static int remove_installed(
- const char *src_path, const struct stat *sb,
- int typeflag, struct FTW *ftwbuf
-) {
- (void)sb;
- (void)ftwbuf;
-
- if (typeflag == FTW_F) {
- const char *filename = src_path + ftwbuf->base;
- const char *ext = strrchr(filename, '.');
- if (!ext)
- ext = "";
-
- if (strncmp(ext, ".so", 3) == 0) {
- char dest[MAX_PATH_LEN];
- snprintf(dest, sizeof(dest), "%s/%s", get_install_dir("lib"), filename);
- if (file_exists(dest))
- remove(dest);
- } else if (access(src_path, X_OK) == 0) {
- if (
- strcmp(ext, ".sample") != 0 &&
- strcmp(filename, "bldit") != 0 &&
- strcmp(filename, "build.sh") != 0 &&
- strcmp(filename, "compile.sh") != 0
- ) {
- char dest[MAX_PATH_LEN];
- snprintf(dest, sizeof(dest), "%s/%s", get_install_dir("bin"), filename);
- if (file_exists(dest))
- remove(dest);
- }
- } else if (strcmp(ext, ".h") == 0) {
- char dest[MAX_PATH_LEN];
- snprintf(dest, sizeof(dest), "%s/%s", get_install_dir("include"),
- filename);
- if (file_exists(dest))
- remove(dest);
- }
- }
- return 0;
-}
-
-static int remove_tree(
- const char *fpath, const struct stat *sb,
- int typeflag, struct FTW *ftwbuf
-) {
- (void)sb;
- (void)ftwbuf;
- if (typeflag == FTW_F || typeflag == FTW_SL) {
- unlink(fpath);
- } else if (typeflag == FTW_DP) {
- rmdir(fpath);
- }
- return 0;
-}
-
-void remove_pkg(Pkg pkg) {
- if (!is_directory(pkg.src)) {
- printf("%s %s is not installed!\n", print_pkgit, pkg.name);
- return;
- }
- chdir(pkg.src);
-
- bool uninstall_available = false;
- if (!uninstall_available) if (repo_uninstall(pkg.name, pkg.target))
- uninstall_available = true;
- if (!uninstall_available) if (bldit_uninstall(pkg.target))
- uninstall_available = true;
- if (!uninstall_available) if (config_uninstall(pkg.src, pkg.target))
- uninstall_available = true;
-
- if (!uninstall_available) printf(
- "%s no uninstall function availible for package: %s\n",
- print_error, pkg.name
- );
-
- nftw(pkg.src, remove_installed, 64, FTW_PHYS);
- const char *last_slash = strrchr(pkg.src, '/');
- char target[MAX_PATH_LEN];
- if (last_slash && last_slash != pkg.src) {
- size_t parent_len = last_slash - pkg.src;
- snprintf(target, sizeof(target), "%.*s", (int)parent_len, pkg.src);
- } else {
- snprintf(target, sizeof(target), "%s", pkg.src);
- }
- nftw(pkg.src, remove_tree, 64, FTW_DEPTH | FTW_PHYS);
- printf("%s removed %s\n", print_success, pkg.name);
-} \ No newline at end of file
diff --git a/src/resolve_deps.c b/src/resolve_deps.c
deleted file mode 100644
index 32118f0..0000000
--- a/src/resolve_deps.c
+++ /dev/null
@@ -1,44 +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/>.
-
-*/
-
-#include <stdio.h>
-#include <unistd.h>
-
-#include "resolve_deps.h"
-
-void resolve_deps(void) {
- const char *frame_top = " (c _c)";
- const char *frame1_bot = "_/ \\-";
- const char *frame2_bot = "-/ \\_";
-
- printf("\033[2J\033[H");
- printf("Unfortunately due to budget issues, we could not afford a progress bar. Enjoy this instead:\n\n");
-
- for (int i = 0; i < 16; i++) {
- printf("%s\n%s\n", frame_top, i % 2 == 0 ? frame1_bot : frame2_bot);
- for (int j = 0; j <= i; j++) printf(".");
- printf("\n");
- fflush(stdout);
- sleep(1);
- if (i < 15) printf("\033[3A");
- }
- printf("\n");
- printf("Dependencies resolved! (this does nothing)\n");
-}
diff --git a/src/search.c b/src/search.c
deleted file mode 100644
index 19f9963..0000000
--- a/src/search.c
+++ /dev/null
@@ -1,37 +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/>.
-
-*/
-
-#include <stdio.h>
-#include <string.h>
-
-#include "lua_state.h"
-#include "search.h"
-
-void search(const char* arg) {
- if (!arg) {
- for (size_t i = 0; i < cached_repos_count; i++)
- printf("%s\n", cached_repos[i].source_key);
- return;
- }
- for (size_t i = 0; i < cached_repos_count; i++) {
- if (!strstr(cached_repos[i].source_key, arg)) continue;
- printf("%s\n", cached_repos[i].source_key);
- }
-}
diff --git a/src/set_install_directories.c b/src/set_install_directories.c
deleted file mode 100644
index e7a62e0..0000000
--- a/src/set_install_directories.c
+++ /dev/null
@@ -1,83 +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/>.
-
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "lua_state.h"
-#include "set_install_directories.h"
-#include "vars.h"
-
-void set_install_directories(void) {
- lua_State *L = get_lua_state();
- cache_prefix_directory();
- lua_getglobal(L, "install_directories");
- if (!lua_istable(L, -1)) {
- printf(
- "%slua variable 'install_directories' is not a table.\n",
- print_error
- );
- }
- lua_pushnil(L);
- while (lua_next(L, -2) != 0) {
- const char *key = lua_tostring(L, -2);
- const char *value = lua_tostring(L, -1);
- if (key && value) {
- map_put(&cached_install_directories, strdup(key), strdup(value));
- }
- lua_pop(L, 1);
- }
-}
-
-void map_init(Map *map) {
- map->items = NULL;
- map->size = 0;
- map->capacity = 0;
-}
-
-void map_put(Map *map, char *key, char *value) {
- for (size_t i = 0; i < map->size; i++) {
- if (strcmp(map->items[i].key, key) == 0) {
- free(map->items[i].value);
- map->items[i].value = value;
- free(key);
- return;
- }
- }
- if (map->size >= map->capacity) {
- size_t new_capacity = map->capacity == 0 ? 8 : map->capacity * 2;
- MapItem *new_items = realloc(map->items, new_capacity * sizeof(MapItem));
- if (!new_items) return;
- map->items = new_items;
- map->capacity = new_capacity;
- }
- map->items[map->size].key = key;
- map->items[map->size].value = value;
- map->size++;
-}
-
-char *map_get(Map *map, const char *key) {
- for (size_t i = 0; i < map->size; i++) {
- if (strcmp(map->items[i].key, key) != 0) continue;
- return map->items[i].value;
- }
- return NULL;
-} \ No newline at end of file
diff --git a/src/setup_dirs.c b/src/setup_dirs.c
deleted file mode 100644
index e675f2d..0000000
--- a/src/setup_dirs.c
+++ /dev/null
@@ -1,34 +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/>.
-
-*/
-
-#include <string.h>
-#include <sys/stat.h>
-
-#include "setup_dirs.h"
-#include "vars.h"
-
-void setup_dirs(void) {
- mkdir_p(config_dir);
- for (int i = 0; i < 5; i++) {
- if (install_directories[i] && strlen(install_directories[i]) <= 0) continue;
- if (file_exists(install_directories[i])) continue;
- mkdir_p(install_directories[i]);
- }
-} \ No newline at end of file
diff --git a/src/setup_pkgit.c b/src/setup_pkgit.c
deleted file mode 100644
index fa7404e..0000000
--- a/src/setup_pkgit.c
+++ /dev/null
@@ -1,29 +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/>.
-
-*/
-
-#include <unistd.h>
-
-#include "set_install_directories.h"
-#include "setup_dirs.h"
-
-void setup_pkgit(void) {
- set_install_directories();
- setup_dirs();
-} \ No newline at end of file
diff --git a/src/update_all.c b/src/update_all.c
deleted file mode 100644
index 4ff750d..0000000
--- a/src/update_all.c
+++ /dev/null
@@ -1,59 +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/>.
-
-*/
-
-#include <dirent.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include "update_all.h"
-#include "create_pkg.h"
-#include "update_pkg.h"
-#include "lua_state.h"
-#include "vars.h"
-
-void update_all(void) {
- init_lua_state();
- cache_repos();
- struct dirent* dirent_ptr;
- DIR* dir_ptr;
- if ((dir_ptr = opendir(get_install_dir("src"))) == NULL) {
- fprintf(
- stderr, "%s could not open %s\n",
- print_pkgit, get_install_dir("src")
- );
- }
- while ((dirent_ptr = readdir(dir_ptr)) != NULL) {
- if (
- strcmp(dirent_ptr->d_name, "..") == 0 ||
- strcmp(dirent_ptr->d_name, ".") == 0
- ) continue;
- for (size_t i = 0; i < cached_repos_count; i++) {
- if (strcmp(dirent_ptr->d_name, cached_repos[i].source_key) != 0) continue;
- Pkg pkg = create_pkg(cached_repos[i].source_value);
- update_pkg(pkg);
- }
- }
- closedir(dir_ptr);
- on_update(get_lua_state());
-} \ No newline at end of file
diff --git a/src/update_pkg.c b/src/update_pkg.c
deleted file mode 100644
index cbe7521..0000000
--- a/src/update_pkg.c
+++ /dev/null
@@ -1,44 +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/>.
-
-*/
-
-#include <stdio.h>
-#include <string.h>
-
-#include "update_pkg.h"
-
-#include "install_pkg.h"
-#include "is_updated.h"
-#include "lua_state.h"
-
-void update_pkg(Pkg pkg) {
- if (is_updated(pkg.src)) {
- printf(
- "%s %s%s%s is already up to date.\n",
- print_skipped, green, pkg.name, color_reset
- );
- return;
- }
- printf(
- "%s Updating package: %s%s%s\n",
- print_pkgit, green, pkg.name, color_reset
- );
- install_pkg(pkg);
- target_loop_on_update(get_lua_state(), "init.lua", pkg.target);
-} \ No newline at end of file
diff --git a/src/vars.c b/src/vars.c
deleted file mode 100644
index ea573e1..0000000
--- a/src/vars.c
+++ /dev/null
@@ -1,220 +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/>.
-
-*/
-
-#include <errno.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#include "vars.h"
-
-bool is_symlink_install = false;
-bool is_verbose = true;
-bool is_auto_installed = true;
-bool is_forced = false;
-bool config_exists = false;
-
-char home_dir[MAX_PATH_LEN] = {0};
-char prefix_dir[MAX_PATH_LEN] = {0};
-
-char root_config[MAX_PATH_LEN] = "/etc/pkgit/init.lua";
-bool is_root_config = false;
-char config_dir[MAX_PATH_LEN] = {0};
-char config_file[MAX_PATH_LEN] = {0};
-char repo_file[MAX_PATH_LEN] = {0};
-
-char bin[MAX_PATH_LEN] = {0};
-char lib[MAX_PATH_LEN] = {0};
-char inc[MAX_PATH_LEN] = {0};
-char src[MAX_PATH_LEN] = {0};
-
-char *install_directories[5] = {NULL};
-
-Map cached_install_directories = {0};
-Repo cached_repos[MAX_REPOS];
-size_t cached_repos_count = 0;
-Map cached_build_systems = {0};
-
-char home_config_buf[MAX_PATH_LEN] = {0};
-char *home_config(void) {
- snprintf(
- home_config_buf, MAX_PATH_LEN,
- "%s/.config/pkgit/init.lua",
- home_dir
- );
- return home_config_buf;
-}
-
-const char *get_install_dir(const char *key) {
- for (size_t i = 0; i < cached_install_directories.size; i++) {
- if (strcmp(cached_install_directories.items[i].key, key) == 0) {
- return cached_install_directories.items[i].value;
- }
- }
- return "";
-}
-
-const char *version = "1.4.0_INDEV";
-
-const char *red = "\x1b[0;31m";
-const char *green = "\x1b[0;32m";
-const char *yellow = "\x1b[0;33m";
-const char *blue = "\x1b[0;34m";
-const char *magenta = "\x1b[0;35m";
-const char *cyan = "\x1b[0;36m";
-const char *gray = "\x1b[0;37m";
-const char *bright_red = "\x1b[0;91m";
-const char *bright_green = "\x1b[0;92m";
-const char *bright_yellow = "\x1b[0;93m";
-const char *bright_blue = "\x1b[0;94m";
-const char *bright_magenta = "\x1b[0;95m";
-const char *bright_cyan = "\x1b[0;96m";
-const char *bright_gray = "\x1b[0;97m";
-const char *bold_red = "\x1b[1;31m";
-const char *bold_green = "\x1b[1;32m";
-const char *bold_yellow = "\x1b[1;33m";
-const char *bold_blue = "\x1b[1;34m";
-const char *bold_magenta = "\x1b[1;35m";
-const char *bold_cyan = "\x1b[1;36m";
-const char *bold_gray = "\x1b[1;37m";
-const char *bold_white = "\x1b[1;38m";
-const char *bold_bright_red = "\x1b[1;91m";
-const char *bold_bright_green = "\x1b[1;92m";
-const char *bold_bright_yellow = "\x1b[1;93m";
-const char *bold_bright_blue = "\x1b[1;94m";
-const char *bold_bright_magenta = "\x1b[1;95m";
-const char *bold_bright_cyan = "\x1b[1;96m";
-const char *bold_bright_gray = "\x1b[1;97m";
-const char *italic = "\x1b[3m";
-const char *color_reset = "\x1b[0m";
-
-const char *print_pkgit;
-const char *print_success;
-const char *print_skipped;
-const char *print_warning;
-const char *print_error;
-
-int mkdir_p(const char *path) {
- char tmp[MAX_PATH_LEN];
- char *p = NULL;
- size_t len;
- snprintf(tmp, sizeof(tmp), "%s", path);
- len = strlen(tmp);
- if (tmp[len - 1] == '/') {
- tmp[len - 1] = 0;
- }
- for (p = tmp + 1; *p; p++) {
- if (*p == '/') {
- *p = 0;
- if (mkdir(tmp, 0755) != 0 && errno != EEXIST) {
- return -1;
- }
- *p = '/';
- }
- }
- if (mkdir(tmp, 0755) != 0 && errno != EEXIST) {
- return -1;
- }
- return 0;
-}
-
-bool file_exists(const char *path) {
- struct stat buffer;
- return (stat(path, &buffer) == 0);
-}
-
-bool is_directory(const char *path) {
- struct stat statbuf;
- if (stat(path, &statbuf) != 0) {
- return false;
- }
- return S_ISDIR(statbuf.st_mode);
-}
-
-void init_vars(void) {
- char *home = getenv("HOME");
- if (home) snprintf(home_dir, MAX_PATH_LEN, "%s", home);
- else snprintf(home_dir, MAX_PATH_LEN, "/root");
-
- 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"));
-
- static char print_pkgit_buf[256];
- snprintf(
- print_pkgit_buf, sizeof(print_pkgit_buf),
- "%s[%s%s%s]%s",
- bold_yellow, bold_magenta, "pkgit",
- bold_yellow, color_reset
- );
- print_pkgit = print_pkgit_buf;
-
- static char print_success_buf[256];
- snprintf(
- print_success_buf, sizeof(print_success_buf),
- "%s%s [SUCCESS]%s",
- print_pkgit, green, color_reset
- );
- print_success = print_success_buf;
-
- static char print_skipped_buf[256];
- snprintf(
- print_skipped_buf, sizeof(print_skipped_buf),
- "%s%s [SKIP]%s",
- print_pkgit, blue, color_reset
- );
- print_skipped = print_skipped_buf;
-
- static char print_warning_buf[256];
- snprintf(
- print_warning_buf, sizeof(print_warning_buf),
- "%s%s [WARN]%s",
- print_pkgit, yellow, color_reset
- );
- print_warning = print_warning_buf;
-
- static char print_error_buf[256];
- snprintf(
- print_error_buf, sizeof(print_error_buf),
- "%s%s [ERROR]%s",
- print_pkgit, red, color_reset
- );
- print_error = print_error_buf;
-}