From: Nathan Wagner Date: Fri, 15 Feb 2019 12:04:53 +0000 (+0000) Subject: allow partial package ids in packagehash X-Git-Tag: v0.5.0~10 X-Git-Url: https://pd.if.org/git/?p=zpackage;a=commitdiff_plain;h=daab48f84d0b7faed09a41afab9f9fccf1356b8f allow partial package ids in packagehash Added a -v option to prepend the (found) package id to hashes. --- diff --git a/doc/zpm-packagehash.8 b/doc/zpm-packagehash.8 index 4760198..7024e82 100644 --- a/doc/zpm-packagehash.8 +++ b/doc/zpm-packagehash.8 @@ -1,25 +1,20 @@ -.TH zpm-packagehash 8 2019-02-14 "ZPM 0.3" +.TH zpm-packagehash 8 2019-02-15 "ZPM 0.3" .SH NAME zpm-packagehash \- run packagehash .SH SYNOPSIS - case 'f': dbfile = optarg; break; - case 's': set = 1; break; - case 'S': clear = 1; break; - case 'c': check = 1; break; - case 'q': quiet = 1; break; - case 'e': showcurrent = 1; break; .B zpm packagehash [ .BI -f " pkgfile" ] [ -.B -sScqe +.B -sScqev ] .RI [ package ] .SH DESCRIPTION \fBzpm-packagehash\fR -calculates, prints, or sets the hash of a package. The package must -be specified as a complete package triple. +calculates, prints, or sets the hash of a package. The package may +be specified as a partial package id, which will be looked up as +if by zpm-findpkg. .SH OPTIONS .TP \-f @@ -37,6 +32,9 @@ check the package hash against one given as an additional argument \-q Don't output anything to stdout. .TP +\-v +When printing hashes, prepend the package id and a space character. +.TP \-e Show the current package hash, rather than the calculated one. .SH EXAMPLES @@ -53,3 +51,4 @@ ZPMDB Nathan Wagner .SH SEE ALSO .BR zpm (8) +.BR zpm-findpkg (8) diff --git a/src/packagehash.c b/src/packagehash.c index 6d5b912..ee4f676 100644 --- a/src/packagehash.c +++ b/src/packagehash.c @@ -13,13 +13,14 @@ void usage(void) { } int main(int ac, char **av){ - int opt; + int opt, argn; struct zpm pkg; char *dbfile; int set = 0, clear = 0, showcurrent = 0; - int check = 0; - int quiet = 0; + int check = 0, quiet = 0, checkfail = 0, verbose = 0; + char hash[ZPM_HASH_STRLEN+1]; + char *pkgid = 0, *current = 0, *display = hash; dbfile = getenv("ZPMDB"); if (!dbfile) { @@ -31,7 +32,7 @@ int main(int ac, char **av){ * show current -e * check -c */ - while ((opt = getopt(ac, av, "f:sScqe")) != -1) { + while ((opt = getopt(ac, av, "f:sScqev")) != -1) { switch (opt) { case 'f': dbfile = optarg; break; case 's': set = 1; break; @@ -39,25 +40,25 @@ int main(int ac, char **av){ case 'c': check = 1; break; case 'q': quiet = 1; break; case 'e': showcurrent = 1; break; + case 'v': verbose = 1; break; default: usage(); exit(EXIT_FAILURE); break; } } - int argn = optind; + argn = optind; if (!dbfile) { fprintf(stderr, "must specify db\n"); return 1; } - char *pkgid = av[argn]; - char hash[ZPM_HASH_STRLEN+1]; - char *current = 0, *display = hash; - int checkfail = 0; - if (zpm_open(&pkg, dbfile)) { + pkgid = zpm_findpkg(&pkg, av[argn], NULL); + if (!pkgid) { + exit(EXIT_FAILURE); + } if (check || showcurrent) { current = zpm_db_string(&pkg, "select hash from packages_pkgid where pkgid = %Q", pkgid); } @@ -81,6 +82,9 @@ int main(int ac, char **av){ zpm_close(&pkg); if (display && !quiet) { + if (verbose) { + printf("%s ", pkgid); + } printf("%s\n", display); } free(current);