pm

barely a pack manager
git clone git://z3bra.org/pm
Log | Files | Refs | README | LICENSE

commit 1e3c9cc7bfb79be2052b44e6c9c70c95ad0c185b
parent d17c5f2b5394540d33d5751943f0b9d5e5d5d8df
Author: z3bra <willyatmailoodotorg>
Date:   Sun May  1 23:50:01 +0200

Add ARGLOOP() macro to arg.h

Diffstat:
arg.h | 16++++++++++++++++
pm.c | 12+++++-------
2 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/arg.h b/arg.h @@ -29,6 +29,20 @@ extern char *argv0; argc_ = argv[0][0];\ switch (argc_) +#define ARGLOOP() while((argc>0 && *argv)||(!argc && !feof(stdin))){\ + char *lf_;\ + char argi_[LINE_MAX];\ + memset(argi_, 0, LINE_MAX);\ + if (argc>0) {\ + strncpy(argi_, *(argv++), LINE_MAX);\ + } else {\ + fgets(argi_, LINE_MAX, stdin);\ + }\ + if (strnlen(argi_, LINE_MAX) > 0) {\ + lf_ = strrchr(argi_, '\n');\ + if (lf_){ *lf_ = 0; } + + /* Handles obsolete -NUM syntax */ #define ARGNUM case '0':\ case '1':\ @@ -60,6 +74,8 @@ extern char *argv0; (&argv[0][1]) :\ (argc--, argv++, argv[0]))) +#define ARGI() argi_ + #define LNGARG() &argv[0][0] #endif diff --git a/pm.c b/pm.c @@ -771,16 +771,14 @@ main (int argc, char **argv) case ACTION_INSTALL: case ACTION_UPDATE: case ACTION_DELETE: - while ((n = ARGV_OR_STDIN(argc, argv)) != NULL) { + ARGLOOP(){ if (action == ACTION_INSTALL) - r += install(rootfs, datadir, n); + r += install(rootfs, datadir, ARGI()); if (action == ACTION_UPDATE) - r += update(rootfs, datadir, n); + r += update(rootfs, datadir, ARGI()); if (action == ACTION_DELETE) - r += delete(rootfs, datadir, n); - - free(n); - } + r += delete(rootfs, datadir, ARGI()); + }ARGEND; break; case ACTION_INSPECT: if (inspect(datadir, n) != 0)