kisslinux / kiss

KISS Linux - Package Manager
https://kisslinux.github.io
MIT License
464 stars 62 forks source link

write some functions in C #301

Closed aabacchus closed 5 months ago

aabacchus commented 2 years ago

Below is one way of integrating some C programs into the package manager. At the moment they are individual binaries but in the future the main functions of each program could be used as self contained functions in a library. See https://github.com/kisslinux/website/blob/68db287bdf5b12e78d50c4b17f9a27c6a3d4eec6/site/blog/20210711a.txt#L261-L275 for one of Dylan's ideas.

I have not implemented the opt-in/out idea but this could be achieved with a simple environment variable check.

With these patches, the package manager expects the binaries to be found in /usr/lib/kiss/. A patch to support this for the kiss build file in repo is below. Either the directory /usr/lib/kiss/ can be prepended to $PATH, or absolute paths could be used when the programs are called. Maybe it would be best to call the binaries kiss_owner etc rather than just owner and use them in /usr/lib/kiss prepended to $PATH.

I have started with two C programs; each replaces one instance of parsing ls. This fixes the problem in #289 and should be a bit faster.

Both C programs are written in ISO C90 (-std=c89) and use only libc functions from POSIX.

diff --git a/core/kiss/build b/core/kiss/build
index 08d78cbf..b61bbb52 100755
--- a/core/kiss/build
+++ b/core/kiss/build
@@ -2,7 +2,8 @@

 mkdir -p \
     "$1/usr/bin" \
-    "$1/usr/share/doc/kiss"
+    "$1/usr/lib/kiss" \
+    "$1/usr/share/doc/kiss/lib"

 cp -f  kiss contrib/*  "$1/usr/bin"
 cp -f  docs/site/*.txt "$1/usr/share/doc/kiss"
@@ -12,3 +13,10 @@ rm -f \
     "$1/usr/share/doc/kiss/README.txt" \
     "$1/usr/share/doc/kiss/post.txt" \
     "$1/usr/share/doc/kiss/tidbits.txt"
+
+# Disable warning as CFLAGS must work this way.
+# shellcheck disable=2086
+for bin in owner rwx; do
+    "$CC" -o "$1/usr/lib/kiss/$bin" "bin/$bin.c" $CFLAGS -static
+    cp -f "bin/$bin.c" "$1/usr/share/doc/kiss/lib/$bin.c"
+done

Thoughts are welcome, this is just one idea of an improvement.