From owner-p4-projects@FreeBSD.ORG Sat Oct 23 20:08:17 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id ACFA91065672; Sat, 23 Oct 2010 20:08:17 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6D57F106566C for ; Sat, 23 Oct 2010 20:08:17 +0000 (UTC) (envelope-from dforsyth@FreeBSD.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 586528FC12 for ; Sat, 23 Oct 2010 20:08:17 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id o9NK8H86097018 for ; Sat, 23 Oct 2010 20:08:17 GMT (envelope-from dforsyth@FreeBSD.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id o9NK8HwM097015 for perforce@freebsd.org; Sat, 23 Oct 2010 20:08:17 GMT (envelope-from dforsyth@FreeBSD.org) Date: Sat, 23 Oct 2010 20:08:17 GMT Message-Id: <201010232008.o9NK8HwM097015@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to dforsyth@FreeBSD.org using -f From: David Forsythe To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 185022 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 23 Oct 2010 20:08:17 -0000 http://p4web.freebsd.org/@@185022?ac=10 Change 185022 by dforsyth@skunk on 2010/10/23 20:07:36 Rewrite pkg_info to use new design Affected files ... .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/database.c#5 edit .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/database.h#5 edit .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/file.c#3 edit .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/file.h#3 edit .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg.c#6 edit .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg.h#6 edit .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg_freebsd.c#4 delete .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg_freebsd.h#4 delete .. //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg_pkg.h#5 edit .. //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_dump/pkg_dump.c#4 edit .. //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_info/pkg_info.c#3 edit Differences ... ==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/database.c#5 (text+ko) ==== ==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/database.h#5 (text+ko) ==== ==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/file.c#3 (text+ko) ==== ==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/file.h#3 (text+ko) ==== ==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg.c#6 (text+ko) ==== @@ -53,6 +53,12 @@ return (pkg->name); } +const char * +pkg_format_revision(struct pkg *pkg) +{ + return (pkg->format_revision); +} + void _pkg_set_name(struct pkg *pkg, const char *name) { ==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg.h#6 (text+ko) ==== ==== //depot/projects/soc2010/dforsyth_libpkg/libpkg/pkg_pkg.h#5 (text+ko) ==== @@ -16,6 +16,7 @@ const char *pkg_comment(struct pkg *); const char *pkg_description(struct pkg *); +const char *pkg_format_revision(struct pkg *); void _pkg_set_origin(struct pkg *, const char *); ==== //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_dump/pkg_dump.c#4 (text+ko) ==== @@ -60,53 +60,13 @@ printf("\n"); } + + pkg = pkg_db_get(db, "vim-lite-7.3.21"); + printf("second: %s\n", pkg_name(pkg)); + free(pkgs); pkg_db_finish(db); return (0); -#if 0 - for (pkgname = *pkglist; pkgname != NULL; pkgname++) { - p = pkg_db_get(db, pkgname); - - printf("Package Name: %s\n", pkg_info(p, "name")); - printf("\tOrigin: %s\n", pkg_info(p, "origin")); - printf("\tFiles:\n"); - - pkgfiles = pkg_info_files(p); - pkgdeps = pkg_depends(p); - pkgcon = pkg_conflicts(p); - - pkgdeps = pkg_info_list(p, "dependencies"); - - - - while (pkg_freebsd_get_next_file(p, &f) == PKG_OK) { - printf("\t\t%s/%s\n", - pkg_freebsd_file_get_prefix(&f), - pkg_freebsd_file_get_pathname(&f)); - printf("\t\t\tMD5: %s\n", pkg_freebsd_file_get_hash(&f)); - printf("\t\t\tIgnored: %s\n", - (pkg_freebsd_file_get_ignored(&f) ? - "TRUE" : - "FALSE")); - } - printf("\tDependencies:\n"); - while (pkg_freebsd_get_next_dependency(p, &d) == PKG_OK) { - printf("\t\t%s\n", pkg_freebsd_dependency_get_name(&d)); - printf("\t\t\tOrigin: %s\n", - pkg_freebsd_dependency_get_origin(&d)); - } - printf("\tConflicts:\n"); - list = pkg_info(p, "conflicts", "expr"); - while (pkg_freebsd_get_next_conflict(p, &c) == PKG_OK) { - printf("\t\t%s\n", pkg_freebsd_conflict_get_expression(&c)); - } - - pkg_db_finish(db, p); - } - - pkg_db_free(db); -#endif } - ==== //depot/projects/soc2010/dforsyth_libpkg/pkg_install/pkg_info/pkg_info.c#3 (text+ko) ==== @@ -13,8 +13,6 @@ #include /* Libpkg base. */ #include -/* FreeBSD package and database. */ -#include #if 0 /* FreeBSD routines. */ @@ -108,9 +106,10 @@ static int pkg_info(struct info_config *); static int pattern_match(match_t, const char *, const char *); static int pkg_info_hash_match(struct pkg_file *); -static void print_chunk(struct pkg *, const char *(*)(struct pkg *), - const char *, struct info_config *); +static void print_chunk(const char *, const char *, struct info_config *); +#if 0 static void print_file(const char *, const char *, struct info_config *); +#endif /* Configuration for pkg_info run. */ struct info_config c; @@ -364,104 +363,83 @@ int r; int s; unsigned int match_count; + struct pkg_list *pkgs; + struct pkg_file_list *files; struct pkg_target *pt; - struct pkg_file f; FILE *pkg_fp; (void)pkg_fp; - char *target; - struct stat sb; - const char *pathname; + // char *target; + // struct stat sb; + // const char *pathname; char path[PATH_MAX]; - struct pkg_database *db; - struct pkg *p; + struct pkg_db *db; + struct pkg *pkg; + struct pkg_file *file; + + db = pkg_db_create(); + s = pkg_db_open(db, _c->database_location); - db = pkg_freebsd_database_create(); - p = pkg_freebsd_create(); - s = pkg_database_open(db, _c->database_location, 0); if (s != PKG_OK) { warnx("Error opening database"); - pkg_database_release(db); - pkg_release(p); + pkg_db_finish(db); return (1); } r = 0; - if (FLAGGED(_c->show_flags, SHOW_PKGNAME)) { - while (pkg_database_get_next_pkg(db, p, _c->skip_flags) == - PKG_OK) { + pkgs = pkg_db_all(db); + if (_c->show_flags & SHOW_PKGNAME) { + TAILQ_FOREACH(pkg, pkgs, next) { if (!_c->quiet) { printf("%s", _c->info_prefix); } - printf("%s\n", pkg_freebsd_get_name(p)); + printf("%s\n", pkg_name(pkg)); } } else if (_c->check_package != NULL) { - while (pkg_database_get_next_pkg(db, p, _c->skip_flags) == - PKG_OK) { - if (strcmp(_c->check_package, - pkg_freebsd_get_name(p)) == 0) { - /* Get out. */ - pkg_database_close(db); - pkg_database_release(db); - pkg_release(p); - return (0); - } + r = 1; + TAILQ_FOREACH(pkg, pkgs, next) { + if (strcmp(_c->check_package, pkg_name(pkg)) == 0) + r = 0; } - r = 1; } else if (!STAILQ_EMPTY(&_c->which)) { - /* Clean up the targets. */ STAILQ_FOREACH(pt, &_c->which, next) { - if (stat(pt->target, &sb) < 0) { - target = pkg_exec_run("/usr/bin/which %s", - pt->target); - if (target != NULL) { - warnx("Can't find %s\n", pt->target); - } else { - strcpy(pt->target, target); - } + if (access(pt->target, F_OK) < 0) { + /* Check target with which. */ } } - pkg_database_rewind(db); - while (pkg_database_get_next_pkg(db, p, _c->skip_flags) == - PKG_OK) { - while (pkg_freebsd_get_next_file(p, &f) == PKG_OK) { - pathname = pkg_freebsd_file_get_pathname(&f); - strcpy(path, pkg_freebsd_file_get_prefix(&f)); - strcat(path, "/"); - strcat(path, pathname); + TAILQ_FOREACH(pkg, pkgs, next) { + files = pkg_files(pkg); + TAILQ_FOREACH(file, files, next) { + snprintf(path, PATH_MAX, "%s/%s", + pkg_file_prefix(file), + pkg_file_pathname(file)); STAILQ_FOREACH(pt, &_c->which, next) { - if (strcmp(path, pt->target) == 0) { - printf("%s was installed by " - "package %s\n", pt->target, - pkg_freebsd_get_name(p)); - } + printf("%s was installed by package " + "%s\n", pt->target, + pkg_name(pkg)); } } + + // pkg_file_list_release(files); } } else if (_c->lookup_origin != NULL) { - if (!_c->quiet) { - printf("The following installed package(s) has %s " - "origin:\n", _c->lookup_origin); - } - while (pkg_database_get_next_pkg(db, p, _c->skip_flags) == - PKG_OK) { - if (strcmp(_c->lookup_origin, - pkg_freebsd_get_origin(p)) == 0) { - printf("%s\n", pkg_freebsd_get_name(p)); - } + if (!_c->quiet) + printf("The following installed packages(s) has %s " + "origin:\n", _c->lookup_origin); + TAILQ_FOREACH(pkg, pkgs, next) { + if (strcmp(_c->lookup_origin, pkg_origin(pkg)) == 0) + printf("%s\n", pkg_name(pkg)); } } else { match_count = 0; - while (pkg_database_get_next_pkg(db, p, _c->skip_flags) == - PKG_OK) { + TAILQ_FOREACH(pkg, pkgs, next) { if (_c->match == MATCH_ALL) { - info_show(p, _c); + info_show(pkg, _c); match_count++; } else { STAILQ_FOREACH(pt, &_c->targets, next) { if (pattern_match(_c->match, - pkg_freebsd_get_name(p), - pt->target)) { - info_show(p, _c); + pkg_name(pkg), pt->target)) { + info_show(pkg, _c); match_count++; } } @@ -488,9 +466,7 @@ } } - pkg_database_close(db); - pkg_database_release(db); - pkg_release(p); + pkg_db_finish(db); return (r); } @@ -523,6 +499,7 @@ { (void)string; (void)pattern; + /* I have no desire to write this. */ return (1); } @@ -557,86 +534,90 @@ } static int -info_show(struct pkg *_p, struct info_config *_c) +info_show(struct pkg *pkg, struct info_config *_c) { /* TODO: Break this up into smaller functions to make it readable. Too * many levels of indentation. */ - const char *show; const char *prefix; const char *last_prefix; + + // struct pkg_conflict_list *conflicts; + struct pkg_depend_list *depends; + struct pkg_file_list *files; + + // struct pkg_conflict *conflict; + struct pkg_depend *depend; + struct pkg_file *file; - struct pkg_conflict cn; - struct pkg_dependency dp; - struct pkg_file fl; + if (FLAGGED(_c->show_flags, SHOW_INDEX)) + printf("%-19s %s\n", pkg_name(pkg), pkg_comment(pkg)); + else { + if (!_c->quiet) + printf("%sInformation for %s:\n\n", _c->info_prefix, + pkg_name(pkg)); + else + printf("%s%s:", _c->info_prefix, pkg_name(pkg)); - if (FLAGGED(_c->show_flags, SHOW_INDEX)) { - /* No newline because _data_read picks that up from the file. */ - printf("%-19s %s", pkg_freebsd_get_name(_p), - pkg_freebsd_get_comment(_p)); - } else { - if (!_c->quiet) { - printf("%sInformation for %s:\n\n", _c->info_prefix, - pkg_freebsd_get_name(_p)); - } else { - printf("%s%s:", _c->info_prefix, - pkg_freebsd_get_name(_p)); - } - if (FLAGGED(_c->show_flags, SHOW_PLIST)) { + if (_c->show_flags & SHOW_PLIST) + if (!_c->quiet) + printf("%sPacking list:\n", _c->info_prefix); + + if (_c->show_flags & SHOW_PLIST) /* TODO: Write a show plist function for this flag * because the output is jacked in this case. */ - if (!_c->quiet) { + if (!_c->quiet) printf("%sPacking list:\n", _c->info_prefix); + + if (_c->show_flags & SHOW_COMMENT) + print_chunk(pkg_comment(pkg), "Comment:\n", _c); + + if (_c->show_flags & SHOW_CONFLICTS) { + if (!_c->quiet) {} +#if 0 + TAILQ_FOREACH(conflict, conflicts, next) { + printf((_c->quiet ? "@conflicts: %s\n" : + "Conflicts %s\n"), + pkg_conflict_expr(conflict)); } +#endif } - if (FLAGGED(_c->show_flags, SHOW_COMMENT)) { - print_chunk(_p, pkg_freebsd_get_comment, "Comment:\n", - _c); - } - if (FLAGGED(_c->show_flags, SHOW_CONFLICTS)) { - if (!_c->quiet) { - /* Eh, no title on this one... */ - } - while (pkg_freebsd_get_next_conflict(_p, &cn) == - PKG_OK) { - printf((_c->quiet ? "@conflicts: %s\n" : - "Conflicts: %s\n"), - pkg_freebsd_conflict_get_expression(&cn)); - } - } - if (FLAGGED(_c->show_flags, SHOW_DEPEND)) { - if (!_c->quiet) { + + if (_c->show_flags & SHOW_DEPEND) { + if (!_c->quiet) printf("%sDepends on:\n", _c->info_prefix); - } - while (pkg_freebsd_get_next_dependency(_p, &dp) == - PKG_OK) { - show = pkg_freebsd_dependency_get_name(&dp); - printf((_c->quiet ? "@pkgdep: %s\n" : - "Dependency: %s\n"), show); - show = pkg_freebsd_dependency_get_origin(&dp); - printf((_c->quiet ? "@comment DEPORIGIN:%s\n" : - "\tdependency origin: %s\n"), show); + + depends = pkg_depends(pkg); + TAILQ_FOREACH(depend, depends, next) { + printf((_c->quiet ? "@pkgdep: %s\n" : + "Dependency: %s\n"), + pkg_depend_name(depend)); + printf((_c->quiet ? "@comment DEPORIGIN: %s\n" : + "\tdependency origin: %s\n"), + pkg_depend_origin(depend)); } /* Separator. */ printf("\n"); } - if (FLAGGED(_c->show_flags, SHOW_REQBY)) { - if (!_c->quiet) { + + if (_c->show_flags & SHOW_REQBY) { + if (_c->quiet) printf("%sRequired by:\n", _c->info_prefix); - } - while ((show = pkg_freebsd_get_next_required_by(_p)) != - NULL) { - printf("%s\n", show); - } + +#if 0 + TAILQ_FOREACH(reqby, reqbys, next) + printf("%s\n", pkg_reqby_name(reqby)); +#endif } - if (FLAGGED(_c->show_flags, SHOW_DESCRIPTION)) { - print_chunk(_p, pkg_freebsd_get_description, - "Description\n", _c); - } - if (FLAGGED(_c->show_flags, SHOW_DISPLAY)) { - print_chunk(_p, pkg_freebsd_get_display, - "Install notice:\n", _c); - } - if (FLAGGED(_c->show_flags, SHOW_REQUIRE)) { + + if (_c->show_flags & SHOW_DESCRIPTION) + print_chunk(pkg_description(pkg), "Description\n", _c); + +#if 0 + if (_c->show_flags & SHOW_DISPLAY) + print_chunk(pkg_display(pkg), "Install notice:\n", _c); +#endif + + if (_c->show_flags & SHOW_REQUIRE) { #if 0 show = pkg_freebsd_get_require(_p); if (show != NULL) { @@ -645,113 +626,104 @@ } #endif } - if (FLAGGED(_c->show_flags, SHOW_INSTALL)) { - show = pkg_freebsd_get_install_script_path(_p); - if (show != NULL) { - print_file(show, "Install script:\n", _c); - } - show = pkg_freebsd_get_post_install_script_path(_p); - if (show != NULL) { - print_file(show, "Post-install script:\n", _c); - } + +#if 0 + if (_c->show_flags & SHOW_INSTALL) { + /* TODO: check if these exist before printing them. */ + print_file(pkg_install_script(pkg), + "Install script:\n", _c); + print_file(pkg_post_install_script(pkg), + "Post-install script:\n", _c); } - if (FLAGGED(_c->show_flags, SHOW_DEINSTALL)) { - show = pkg_freebsd_get_deinstall_script_path(_p); - if (show != NULL) { - print_file(show, "Deinstall script:\n", _c); - } - show = pkg_freebsd_get_post_deinstall_script_path(_p); - if (show != NULL) { - print_file(show, "Post-deinstall script:\n", _c); - } + + if (_c->show_flags & SHOW_DEINSTALL) { + print_file(pkg_deinstall_script(pkg), + "Deinstall script:\n", _c); + print_file(pkg_post_deinstall_script(pkg), + "Post-deinstall script:\n", _c); } - if (FLAGGED(_c->show_flags, SHOW_MTREE)) { - } - if (FLAGGED(_c->show_flags, SHOW_PREFIX)) { + + if (_c->show_flags & SHOW_MTREE) ; + + + if (_c->show_flags & SHOW_PREFIX) { /* XXX: I need to think about how to deal with this. * For now, only dump prefix when using SHOW_FILE * aswell. */ } - if (FLAGGED(_c->show_flags, SHOW_FILES)) { - /* Not the same as showing files for SHOW_PLIST. - * */ - if (!_c->quiet) { - printf("%sFiles:\n", _c->info_prefix); - } +#endif + if (_c->show_flags & SHOW_FILES) { + /* Not the same as showing files for SHOW_PLIST. */ + if (!_c->quiet) printf("%sFiles:\n", _c->info_prefix); + prefix = NULL; last_prefix = NULL; - while (pkg_freebsd_get_next_file(_p, &fl) == PKG_OK) { - if (last_prefix == NULL) { - last_prefix = - pkg_freebsd_file_get_prefix(&fl); - } else { - /* Check the prefix to see if it's - * changed. */ - prefix = - pkg_freebsd_file_get_prefix(&fl); - if (strcmp(prefix, last_prefix) == 0) { + + files = pkg_files(pkg); + TAILQ_FOREACH(file, files, next) { + if (last_prefix == NULL) + pkg_file_prefix(file); + else { + /* Check to see is the prefix has + * changes. */ + prefix = pkg_file_prefix(file); + if (strcmp(prefix, last_prefix) == 0) last_prefix = prefix; - } } - if (!pkg_freebsd_file_get_ignored(&fl)) { + + if (!pkg_file_ignore(file)) printf("%s/%s\n", last_prefix, - pkg_freebsd_file_get_pathname(&fl)); - } + pkg_file_pathname(file)); } } - if (FLAGGED(_c->show_flags, SHOW_SIZE)) { - } - if (FLAGGED(_c->show_flags, SHOW_CHECKSUM_CHECK)) { - if (!_c->quiet) { + + if (_c->show_flags & SHOW_SIZE) {} + + if (_c->show_flags & SHOW_CHECKSUM_CHECK) { + if (_c->quiet) printf("%sMismatched Checksums:\n", - _c->info_prefix); - } - while (pkg_freebsd_get_next_file(_p, &fl) == PKG_OK) { - if (pkg_info_hash_match(&fl)) { - if (!_c->verbose) { - /* - * This is gross, but I need - * some help with the 80 column - * barrier in this function :) - */ - continue; - } - printf("%s/%s matched the original MD5 " - "checksum\n", - pkg_freebsd_file_get_prefix(&fl), - pkg_freebsd_file_get_pathname(&fl)); - } else { + _c->info_prefix); + + files = pkg_files(pkg); + TAILQ_FOREACH(file, files, next) { + if (pkg_info_hash_match(file)) { + if (_c->verbose) + printf("%s/%s matched the " + "original MD5 " + "checksum\n", + pkg_file_prefix(file), + pkg_file_pathname(file)); + } else printf("%s/%s fails the original MD5 " - "checksum\n", - pkg_freebsd_file_get_prefix(&fl), - pkg_freebsd_file_get_pathname(&fl)); - } + "checksum\n", + pkg_file_prefix(file), + pkg_file_pathname(file)); } } - if (FLAGGED(_c->show_flags, SHOW_ORIGIN)) { - if (!_c->quiet) { - printf("%sOrigin:\n", _c->info_prefix); - } - printf("%s\n", pkg_freebsd_get_origin(_p)); + + if (_c->show_flags & SHOW_ORIGIN) { + if (_c->quiet) printf("%sOrigin:\n", _c->info_prefix); + + printf("%s\n", pkg_origin(pkg)); } - if (FLAGGED(_c->show_flags, SHOW_FMTREV)) { - if (!_c->quiet) { + + if (_c->show_flags & SHOW_FMTREV) { + if (_c->quiet) printf("%sFormat revision:\n", _c->info_prefix); - } - printf("%s\n", pkg_freebsd_get_format_revision(_p)); + + printf("%s\n", pkg_format_revision(pkg)); } + } - /* A bit of seperation. */ - if (!FLAGGED(_c->show_flags, SHOW_INDEX)) { - /* Adds an extra newline to SHOW_INDEX dumps. */ - printf("\n"); - } + /* Adds an extra newline to SHOW_INDEX dumps. */ + if (!(_c->show_flags & SHOW_INDEX)) printf("\n"); + return (0); } static int -pkg_info_hash_match(struct pkg_file *f) +pkg_info_hash_match(struct pkg_file *file) { char path[PATH_MAX]; char hash[33]; @@ -760,14 +732,10 @@ char link_buf[PATH_MAX]; struct stat sb; - _pkg_util_path_join(path, pkg_freebsd_file_get_prefix(f), - pkg_freebsd_file_get_pathname(f)); + snprintf(path, PATH_MAX, "%s/%s", pkg_file_prefix(file), + pkg_file_pathname(file)); + if (lstat(path, &sb) < 0) { - /* - * Technically, we're better than the current pkg_info here. - * pkg_info reports that a file doesn't exist just because it - * can't open it. That's a bug. - */ warnx("%s does not exist", path); return (0); } @@ -780,56 +748,43 @@ calc_hash = NULL; if (S_ISLNK(sb.st_mode)) { link_len = readlink(path, link_buf, PATH_MAX); - if (link_len > 0) { + + if (link_len > 0) calc_hash = MD5Data(link_buf, link_len, hash); - } - } else if (S_ISREG(sb.st_mode)) { + } else if (S_ISREG(sb.st_mode)) calc_hash = MD5File(path, hash); - } - if (calc_hash != NULL) { - if (strcmp(calc_hash, pkg_freebsd_file_get_hash(f)) != 0) { - return (0); - } else { - return (1); - } - } + + if (calc_hash != NULL) + return ((strcmp(calc_hash, pkg_file_hash(file)) == 0 ? 1 : 0)); return (0); } static void -print_chunk(struct pkg *p, const char *(*get_callback) (struct pkg *), - const char *title, struct info_config *_c) +print_chunk(const char *chunk, const char *title, struct info_config *_c) { - const char *chunk; + if (!_c->quiet) printf("%s%s", _c->info_prefix, title); - if (!_c->quiet) { - printf("%s%s", _c->info_prefix, title); - } - - chunk = get_callback(p); - if (chunk != NULL) { - printf("%s", chunk); - } + if (chunk != NULL) printf("%s", chunk); } +#if 0 static void print_file(const char *pathname, const char *title, struct info_config *_c) { FILE *fp; char line[LINE_MAX]; - if (!_c->quiet) { - printf("%s%s", _c->info_prefix, title); - } + if (!_c->quiet) printf("%s%s", _c->info_prefix, title); fp = fopen(pathname, "r"); - if (fp == NULL) { + if (fp == NULL) warnx("Error: %s: Can't open '%s' for reading!\n", __func__, pathname); - } - while (fgets(line, LINE_MAX, fp) != NULL) { + + while (fgets(line, LINE_MAX, fp) != NULL) printf("%s", line); - } + printf("\n"); } +#endif