commit 8d7ebeb64ea675995c767d1a9f24ac547b5e5c31
parent 11ba69309fc7f694dba7b861bf6f3f2c48eed68b
Author: Nihal Jere <nihal@nihaljere.xyz>
Date: Wed, 17 Feb 2021 10:47:18 -0600
kiss.c: add kiss_list_all
Diffstat:
A | Makefile | | | 2 | ++ |
M | kiss.c | | | 44 | ++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,2 @@
+all:
+ gcc -Werror kiss.c pkg.c util.c
diff --git a/kiss.c b/kiss.c
@@ -1,10 +1,50 @@
+#include <dirent.h>
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
+#include "pkg.h"
#include "util.h"
char *argv0;
+void
+kiss_list_all()
+{
+ DIR *db;
+ char pkgs[1024][64];
+ char ver[256];
+
+ if ((db = opendir(KISS_INSTALLED)) == NULL)
+ die("couldn't open package database:");
+
+ int pkgcount = 0;
+ for (struct dirent *pkg = readdir(db); pkg != NULL; pkg = readdir(db)) {
+ if (pkg->d_type != DT_DIR || pkg->d_name[0] == '.')
+ continue;
+
+ if (strlen(pkg->d_name) >= 64) {
+ closedir(db);
+ die("kiss_list: '%s' is too long of a package name", pkg->d_name);
+ }
+
+ strcpy(pkgs[pkgcount], pkg->d_name);
+
+ pkgcount++;
+ if (pkgcount > 1024) {
+ closedir(db);
+ die("kiss_list: too many packages to list!");
+ }
+ }
+
+ qsort(pkgs, pkgcount, LEN(pkgs[0]), vstrcmp);
+
+ for (int i = 0; i < pkgcount; i++) {
+ pkg_version(KISS_INSTALLED, pkgs[i], ver);
+ printf("%s %s", pkgs[i], ver);
+ }
+}
+
int main(int argc, char *argv[])
{
char *kiss_path;
@@ -13,4 +53,8 @@ int main(int argc, char *argv[])
if ((kiss_path = getenv("KISS_PATH")) == NULL)
die("KISS_PATH unset.");
puts(kiss_path);
+
+ if (strcmp(argv[1], "list") == 0) {
+ kiss_list_all();
+ }
}