nkiss

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/nkiss
Log | Files | Refs

commit ce303420e58d25a62a4a55092f7fe2cae070bad2
parent 8b300b6d3278953cbfdab66841b88e70f7d5a191
Author: Nihal Jere <nihal@nihaljere.xyz>
Date:   Wed, 17 Feb 2021 13:09:33 -0600

kiss.c: add kiss_search

Diffstat:
Mkiss.c | 46++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+), 0 deletions(-)

diff --git a/kiss.c b/kiss.c @@ -1,4 +1,5 @@ #include <dirent.h> +#include <fnmatch.h> #include <stdlib.h> #include <stdio.h> #include <string.h> @@ -56,6 +57,41 @@ kiss_list_names(char *names[], int len) } } +void +kiss_search(const char *kiss_path, char *pattern) +{ + char *repo, path[strlen(kiss_path)], pkgs[1024][64]; + int pkgcount; + + memccpy(path, kiss_path, '\0', strlen(kiss_path)); + + if ((repo = strtok(path, ":")) == NULL) + die("Invalid KISS_PATH."); + + /* iterate through KISS_PATH */ + do { + /* clear pkgs array */ + for (int i = 0; i < 1024; i++) + pkgs[i][0] = '\0'; + + pkgcount = pkg_match(repo, pkgs, pattern); + + for (int i = 0; i < pkgcount; i++) { + printf("%s/%s\n", repo, pkgs[i]); + } + } while ((repo = strtok(NULL, ":")) != NULL); + + repo = KISS_INSTALLED; + for (int i = 0; i < 1024; i++) + pkgs[i][0] = '\0'; + + pkgcount = pkg_match(repo, pkgs, pattern); + + for (int i = 0; i < pkgcount; i++) { + printf("%s/%s\n", repo, pkgs[i]); + } +} + int main(int argc, char *argv[]) { char *kiss_path; @@ -70,5 +106,15 @@ int main(int argc, char *argv[]) kiss_list_names(&argv[2], argc-2); else kiss_list_all(); + + goto end; + } + + if (strcmp(argv[1], "search") == 0 && argc > 2) { + kiss_search(kiss_path, argv[2]); + goto end; } + +end: + return 0; }