static int check_installed_pattern(const char *pattern) { int ret = 0; match_installed_pkgs(pattern, check_one_installed_pkg, &ret); return ret; }
static void check_pkg(const char *pkg, int *filecnt, int *pkgcnt, int allow_unmatched) { struct checkpattern_arg arg; char *pattern; arg.filecnt = *filecnt; arg.pkgcnt = *pkgcnt; arg.got_match = 0; if (match_installed_pkgs(pkg, checkpattern_fn, &arg) == -1) errx(EXIT_FAILURE, "Cannot process pkdbdb"); if (arg.got_match != 0) { *filecnt = arg.filecnt; *pkgcnt = arg.pkgcnt; return; } if (ispkgpattern(pkg)) { if (allow_unmatched) return; errx(EXIT_FAILURE, "No matching pkg for %s.", pkg); } pattern = xasprintf("%s-[0-9]*", pkg); if (match_installed_pkgs(pattern, checkpattern_fn, &arg) == -1) errx(EXIT_FAILURE, "Cannot process pkdbdb"); if (arg.got_match == 0) errx(EXIT_FAILURE, "cannot find package %s", pkg); free(pattern); *filecnt = arg.filecnt; *pkgcnt = arg.pkgcnt; }
static void set_unset_variable(char **argv, Boolean unset) { struct set_installed_info_arg arg; char *eq; char *variable; int ret = 0; if (argv[0] == NULL || argv[1] == NULL) usage(); variable = NULL; if (unset) { arg.variable = argv[0]; arg.value = NULL; } else { eq = NULL; if ((eq=strchr(argv[0], '=')) == NULL) usage(); variable = xmalloc(eq-argv[0]+1); strlcpy(variable, argv[0], eq-argv[0]+1); arg.variable = variable; arg.value = eq+1; if (strcmp(variable, AUTOMATIC_VARNAME) == 0 && strcasecmp(arg.value, "yes") != 0 && strcasecmp(arg.value, "no") != 0) { errx(EXIT_FAILURE, "unknown value `%s' for " AUTOMATIC_VARNAME, arg.value); } } if (strpbrk(arg.variable, "ABCDEFGHIJKLMNOPQRSTUVWXYZ") != NULL) { free(variable); errx(EXIT_FAILURE, "variable name must not contain uppercase letters"); } argv++; while (*argv != NULL) { arg.got_match = 0; if (match_installed_pkgs(*argv, set_installed_info_var, &arg) == -1) errx(EXIT_FAILURE, "Cannot process pkdbdb"); if (arg.got_match == 0) { char *pattern; if (ispkgpattern(*argv)) { warnx("no matching pkg for `%s'", *argv); ret++; } else { pattern = xasprintf("%s-[0-9]*", *argv); if (match_installed_pkgs(pattern, set_installed_info_var, &arg) == -1) errx(EXIT_FAILURE, "Cannot process pkdbdb"); if (arg.got_match == 0) { warnx("cannot find package %s", *argv); ++ret; } free(pattern); } } argv++; } if (ret > 0) exit(EXIT_FAILURE); free(variable); return; }