package

simple and robust package manager
Log | Files | Refs | README

commit c2117457b370fdddffc97e6249934ddf9de264d1
parent 1fc4aa8923d93a1060269cef29cfddcd34462e94
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sat, 19 Jan 2019 15:35:43 +0100

homogenize all usage and arg parsing

Diffstat:
Mpackage-add.c | 8+-------
Mpackage-build.c | 28++++++++++++----------------
Mpackage-dep.c | 11+++++++----
Mpackage-install.c | 17+----------------
4 files changed, 21 insertions(+), 43 deletions(-)

diff --git a/package-add.c b/package-add.c @@ -12,12 +12,6 @@ #include "forkexec.h" void -usage(char *argv0) -{ - log_usage(argv0, "-p pkgdir -d defdir package[/version]"); -} - -void die_nomem(void) { log_fatal_sys_1(100, "malloc"); @@ -41,7 +35,7 @@ main(int argc, char **argv) break; } - if (!*av) usage(*argv); + if (!*av) log_usage(*argv, "[-p pkgdir] [-d defdir] package[/version]"); if (!stat_isdir(def)) log_fatal_sys_1(101, def); if (!stat_isdir(pkg)) log_fatal_sys_1(101, pkg); diff --git a/package-build.c b/package-build.c @@ -31,14 +31,10 @@ untar(void) static int patch(package const *p, char *def) { - char const *argv[] = { "patch", "-N", NULL }; char const *d[2]; stralloc sa; size_t n; - size_t m; DIR *dp = NULL; - struct dirent *de; - int i; int fd = -1; int ret = -1; @@ -51,7 +47,10 @@ patch(package const *p, char *def) d[0] = "default"; d[1] = p->ver; - for (i = 0; i < 2; ++i) { + for (int i = 0; i < 2; ++i) { + struct dirent *de; + size_t m; + sa.n = n; if (!stralloc_cats(&sa, d[i])) goto err; if (!stralloc_cats(&sa, "/patch/")) goto err; @@ -63,6 +62,8 @@ patch(package const *p, char *def) goto err; } while ((de = readdir(dp)) != NULL) { + char const *argv[] = { "patch", "-N", NULL }; + if (str_equal(de->d_name, ".")) continue; if (str_equal(de->d_name, "..")) continue; @@ -70,8 +71,11 @@ patch(package const *p, char *def) if (!stralloc_cats(&sa, de->d_name)) goto err; if (!stralloc_cat0(&sa)) goto err; if ((fd = open_read(sa.x)) == -1) goto err; + buffer_puts(buffer_1, argv[0]); buffer_puts(buffer_1, " "); + buffer_puts(buffer_1, argv[1]); buffer_puts(buffer_1, " "); + buffer_puts(buffer_1, sa.x); buffer_puts(buffer_1, "\n"); + buffer_flush(buffer_1); if ((ret = forkexec_redir(argv, 0, fd)) != 0) goto err; - if (write(1, "\n", 1) == -1) goto err; close(fd); } closedir(dp); @@ -79,7 +83,7 @@ patch(package const *p, char *def) err: if (fd >= 0) close(fd); stralloc_free(&sa); - if (ret == 0) closedir(dp); + if (ret != 0) closedir(dp); return ret; } @@ -139,7 +143,6 @@ build(package const *p, char const *def) if (!stralloc_cat0(&sa)) goto err; argv[0] = sa.x; if (stat_isfile(sa.x)) { ret = forkexec_redir(argv, 2, 1); goto err; } - err: stralloc_free(&sa); return ret; @@ -214,13 +217,6 @@ err: return ret; } -void -usage(char const *argv0, char const *param) -{ - log_error_2("missing parameter: ", param); - log_usage(argv0, "-p pkgdir -d defdir packageage[/version]"); -} - int main(int argc, char **argv) { @@ -240,7 +236,7 @@ main(int argc, char **argv) break; } - if (!*av) usage(*argv, "packageage[/version]"); + if (!*av) log_usage(*argv, "[-p pkgdir] [-d defdir] packageage[/version]"); tain_now(&tn); id[tain_fmt(&tn, id)] = '\0'; diff --git a/package-dep.c b/package-dep.c @@ -15,16 +15,19 @@ main(int argc, char **argv) { (void)argc; (void)argv; - char *def; + char *def = PACKAGE_DEF; genalloc ga; size_t i; size_t n; package p; + char **av = argv; - if (argc != 2) log_usage(*argv, "packageage[/version]"); - ++argv; + while (*++av) { + if (str_equal(*av, "-d")) { if (!(def = *++av)) break; continue; } + break; + } - def = "/etc/pack"; + if (!*av) log_usage(*argv, "[-d defdir] package[/version]"); if (!stat_isdir(def)) log_fatal_sys_1(101, def); diff --git a/package-install.c b/package-install.c @@ -11,19 +11,6 @@ die_nomem(void) log_fatal_sys_1(100, "malloc"); } -void -die_usage(char const *argv0) -{ - log_usage(argv0, "-r rootdir package[/version]"); -} - -void -die_param(char const *argv0, char const *param) -{ - log_error_2("missing parameter ", param); - die_usage(argv0); -} - int main(int argc, char **argv) { @@ -45,9 +32,7 @@ main(int argc, char **argv) break; } - if (!def) die_param(*argv, "-d"); - if (!pkg) die_param(*argv, "-p"); - if (!*av) die_usage(*argv); + if (!*av) log_usage(*argv, "[-r rootdir] package[/version]"); if (!stat_isdir(def)) log_fatal_sys_1(101, def); if (!stat_isdir(root)) log_fatal_sys_1(101, root);