int matchinstalled;
int suppressinstalled;
int onlylocalinstalled;
+ int foundonly;
int verbose;
int dbrepos;
};
free(pkgfile);
}
-void print_pkghash(jsw_hash_t *hash, int json) {
+void print_pkghash(jsw_hash_t *hash, int json, int idonly) {
const char *pkgid, *file;
char *fmt;
- char *sep;
+ char *sep = "\n";
int count = 0;
-
- fmt = json ? "\"%s\": \"%s\"" : "%s:%s";
- sep = json ? ", " : "\n";
+ char *start = "";
+ char *end = "";
if (json) {
- printf("{ ");
+ sep = ", ";
+ if (idonly) {
+ fmt = "\"%s\"";
+ start = "[ ";
+ end = " ]\n";
+ } else {
+ fmt = "\"%s\": \"%s\"";
+ start = "{ ";
+ end = " }\n";
+ }
+ } else {
+ if (idonly) {
+ fmt = "%s";
+ start = "";
+ end = "";
+ } else {
+ fmt = "%s:%s";
+ start = "";
+ end = "";
+ }
}
+ printf("%s", start);
+
if (jsw_hsize(hash) > 0) {
for (jsw_hreset(hash); jsw_hitem(hash); jsw_hnext(hash)) {
pkgid = jsw_hkey(hash);
if (count++) {
printf("%s", sep);
}
- printf(fmt, pkgid, file);
+ if (idonly) {
+ printf(fmt, pkgid);
+ } else {
+ printf(fmt, pkgid, file);
+ }
}
+ if (!json) printf("\n");
}
- if (json) printf(" }");
- printf("\n");
+ printf("%s", end);
}
int main(int ac, char *av[]) {
- int option, argn;
- int findlibs = 0, json = 0;
+ int option, argn, rv = 0;
+ int findlibs = 0, json = 0, idonly = 0;
struct pkgloc *found;
jsw_hash_t *packages, *check, *forlibs, *nolib;
jsw_atree_t *nfound;
*/
int output = 1;
- while ((option = getopt(ac, av, "ljqPRDvp:r:d:MiIO")) != -1) {
+ while ((option = getopt(ac, av, "fljqPRDvp:r:d:MiIOn")) != -1) {
switch (option) {
case 'l': findlibs = 1; break;
case 'j': json = 1; break;
case 'I': opt.suppressinstalled = 1; break;
/* only find localdb pkgs if installed */
case 'O': opt.onlylocalinstalled = 1; break;
+ case 'f': opt.foundonly = 1; break;
case 'd': opt.localdb = optarg; break;
case 'p': opt.pkgdir = optarg; break;
case 'r': opt.repodir = optarg; break;
*/
case 'M': opt.matchallpkgfile = 1; break;
case 'v': opt.verbose++; break;
+ case 'n': idonly = 1; break;
default:
exit(EXIT_FAILURE);
break;
if (output) {
if (jsw_hsize(packages)) {
- print_pkghash(packages, json);
+ print_pkghash(packages, json, idonly);
}
if (jsw_hsize(forlibs)) {
- print_pkghash(forlibs, json);
+ print_pkghash(forlibs, json, idonly);
}
}
file = jsw_hitem(nolib);
fprintf(stderr, "no lib found %s:%s\n", pkgid, file);
}
+ rv = 1;
}
- if (jsw_asize(nfound) > 0) {
+ if (jsw_asize(nfound) > 0 && !opt.foundonly) {
jsw_atrav_t *i;
i = jsw_atnew();
char *pkgstr;
for (pkgstr = jsw_atfirst(i, nfound); pkgstr; pkgstr = jsw_atnext(i)) {
fprintf(stderr, "%s: not found\n", pkgstr);
}
+ rv = 1;
}
- return jsw_asize(nfound) > 0 || jsw_hsize(nolib) > 0 ? 1 : 0;
+ return rv;
}