pm

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

commit ff4971919f603107c9a8f0144f6b3f174c0f3fb2
parent 7f7c044bcd9ba084b1b40b31e32efa4ff03ca72e
Author: z3bra <willyatmailoodotorg>
Date:   Sun Apr 24 22:59:58 +0200

Move argv/stdin checks into a macro

Diffstat:
pm.c | 14++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/pm.c b/pm.c @@ -14,6 +14,14 @@ #include "arg.h" +/* + * Macro to return the next argument from argv if argc is higher than 0. + * In case argv is 0, it will read and return the next line from stdin. + */ +#define ARGV_OR_STDIN(argc, argv) ((argc>0) ? \ + *argv ? strdup(*(argv++)) : NULL : \ + slurp(0)) + #define PACK_ROOT (getenv("ROOT")?getenv("ROOT"):"") #define PACK_DATA "var/pm" #define PACK_BUFF_SIZE 8192 @@ -143,6 +151,7 @@ base_name(char *path) return b ? b + 1 : path; } + /* * Fills the array passed as argument with lines read from the file descriptor. * Returns the number of lines read @@ -170,6 +179,7 @@ slurp(int fd) return path; } + /* * Check for collisions between the filesystem and the tarball */ @@ -717,6 +727,7 @@ pack_free(struct pack *p) free(p); } + int main (int argc, char **argv) { @@ -760,8 +771,7 @@ main (int argc, char **argv) case ACTION_INSTALL: case ACTION_UPDATE: case ACTION_DELETE: - /* These action require a read from stdin if no arg is given */ - while ((n = (argc > 0) ? *argv ? strdup(*argv++) : NULL : slurp(0))) { + while ((n = ARGV_OR_STDIN(argc, argv)) != NULL) { if (action == ACTION_INSTALL) r += install(rootfs, datadir, n); if (action == ACTION_UPDATE)