ckiss

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 934bb3f405fd968f99fc3395d6fed1844ea3c0ce
parent 758210469db3aa50481d8338206a8190057bebe5
Author: aabacchus <ben@bvnf.space>
Date:   Fri, 21 Apr 2023 19:47:46 +0100

finish list

Diffstat:
MREADME | 2+-
Msrc/list.c | 41+++++++++++++++++++++++++----------------
Msrc/main.c | 2+-
3 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/README b/README @@ -9,7 +9,7 @@ An implementation of the kiss package manager in C. [ ] checksum [ ] download [ ] install -[.] list +[x] list [ ] remove [ ] search [ ] update diff --git a/src/list.c b/src/list.c @@ -5,6 +5,26 @@ #include <string.h> #include "kiss.h" +void +pkg_print(char *pkg, struct env *e) { + char *p = concat(e->sys_db, "/", pkg, "/version", NULL); + char *buf = NULL; + size_t bufn = 0; + FILE *f = fopen(p, "r"); + if (f == NULL) { + die2(pkg, "not found"); + } + + if (getline(&buf, &bufn, f) == -1) die_perror("getline"); + char *sp = strchr(buf, ' '); + if (sp) *sp = '-'; + + printf("%s %s", pkg, buf); + + free(p); + fclose(f); +} + int list(int argc, char **argv, struct env *e) { struct dirent *dp; @@ -25,25 +45,14 @@ list(int argc, char **argv, struct env *e) { } if (dp->d_name[0] == '.') continue; - - char *p = concat(e->sys_db, "/", dp->d_name, "/version", NULL); - - char *buf = NULL; - size_t bufn = 0; - FILE *f = fopen(p, "r"); - if (f == NULL) die_perror(p); - - if (getline(&buf, &bufn, f) == -1) die_perror("getline"); - char *sp = strchr(buf, ' '); - if (sp) *sp = '-'; - - printf("%s %s", dp->d_name, buf); - - free(p); - fclose(f); + pkg_print(dp->d_name, e); } while (dp != NULL); done: closedir(d); + } else { + for (int i = 1; i < argc; i++) { + pkg_print(argv[i], e); + } } return 0; } diff --git a/src/main.c b/src/main.c @@ -6,7 +6,7 @@ char *c1, *c2, *c3; noreturn void usage(int r) { mylog("kiss [l] [pkg]..."); - mylog("list List installed packages"); + mylog("list List installed packages"); exit(r); }