void print_info(struct pkg * const pkg, unsigned int options) { struct pkg_category *cat = NULL; struct pkg_dep *dep = NULL; struct pkg_dir *dir = NULL; struct pkg_file *file = NULL; struct pkg_group *group = NULL; struct pkg_license *lic = NULL; struct pkg_option *option = NULL; struct pkg_shlib *shlib = NULL; struct pkg_user *user = NULL; bool multirepos_enabled = false; bool print_tag = false; bool show_locks = false; char size[7]; const char *name, *version, *prefix, *origin, *reponame, *repourl; const char *maintainer, *www, *comment, *desc, *message, *arch; const char *repopath; const char *tab; char *m; unsigned opt; int64_t flatsize, newflatsize, newpkgsize; lic_t licenselogic; bool locked; int cout = 0; /* Number of characters output */ int info_num; /* Number of different data items to print */ pkg_config_bool(PKG_CONFIG_MULTIREPOS, &multirepos_enabled); pkg_get(pkg, PKG_NAME, &name, PKG_VERSION, &version, PKG_PREFIX, &prefix, PKG_ORIGIN, &origin, PKG_REPONAME, &reponame, PKG_REPOURL, &repourl, PKG_MAINTAINER, &maintainer, PKG_WWW, &www, PKG_COMMENT, &comment, PKG_DESC, &desc, PKG_FLATSIZE, &flatsize, PKG_NEW_FLATSIZE, &newflatsize, PKG_NEW_PKGSIZE, &newpkgsize, PKG_LICENSE_LOGIC, &licenselogic, PKG_MESSAGE, &message, PKG_ARCH, &arch, PKG_REPOPATH, &repopath, PKG_LOCKED, &locked); if (!multirepos_enabled) pkg_config_string(PKG_CONFIG_REPO, &repourl); if (options & INFO_RAW) { /* Not for remote packages */ if (pkg_type(pkg) != PKG_REMOTE) { pkg_emit_manifest(pkg, &m); printf("%s\n", m); free(m); } return; } /* Show locking status when requested to display it and the package is locally installed */ if (pkg_type(pkg) == PKG_INSTALLED && (options & INFO_LOCKED) != 0) show_locks = true; if (!quiet) { /* Print a tag-line identifying the package -- either NAMEVER, ORIGIN or NAME (in that order of preference). This may be the only output from this function */ if (options & INFO_TAG_NAMEVER) cout = printf("%s-%s", name, version); else if (options & INFO_TAG_ORIGIN) cout = printf("%s", origin); else if (options & INFO_TAG_NAME) cout = printf("%s", name); } /* Don't display a tab if quiet, retains compatibility. */ tab = quiet ? "" : "\t"; /* If we printed a tag, and there are no other items to print, then just return now. If there's only one single-line item to print, show it at column 32 on the same line. If there's one multi-line item to print, start a new line. If there is more than one item to print per pkg, use 'key : value' style to show on a new line. */ info_num = 0; for (opt = 0x1U; opt <= INFO_LASTFIELD; opt <<= 1) if ((opt & options) != 0) info_num++; if (info_num == 0 && cout > 0) { printf("\n"); return; } if (info_num == 1) { /* Only one item to print */ print_tag = false; if (!quiet) { if (options & INFO_MULTILINE) printf(":\n"); else { if (cout < 31) cout = 31 - cout; else cout = 1; printf("%*s", cout, " "); } } } else { /* Several items to print */ print_tag = true; if (!quiet) printf("\n"); } for (opt = 0x1; opt <= INFO_LASTFIELD; opt <<= 1) { if ((opt & options) == 0) continue; switch (opt) { case INFO_NAME: if (print_tag) printf("%-15s: ", "Name"); printf("%s\n", name); break; case INFO_VERSION: if (print_tag) printf("%-15s: ", "Version"); printf("%s\n", version); break; case INFO_ORIGIN: if (print_tag) printf("%-15s: ", "Origin"); printf("%s\n", origin); break; case INFO_PREFIX: if (print_tag) printf("%-15s: ", "Prefix"); printf("%s\n", prefix); break; case INFO_REPOSITORY: if (pkg_type(pkg) == PKG_REMOTE && repourl != NULL && repourl[0] != '\0') { if (print_tag) printf("%-15s: ", "Repository"); printf("%s [%s]\n", reponame, repourl); } else if (!print_tag) printf("\n"); break; case INFO_CATEGORIES: if (pkg_list_count(pkg, PKG_CATEGORIES) > 0) { if (print_tag) printf("%-15s: ", "Categories"); if (pkg_categories(pkg, &cat) == EPKG_OK) printf("%s", pkg_category_name(cat)); while (pkg_categories(pkg, &cat) == EPKG_OK) printf(" %s", pkg_category_name(cat)); printf("\n"); } else if (!print_tag) printf("\n"); break; case INFO_LICENSES: if (pkg_list_count(pkg, PKG_LICENSES) > 0) { if (print_tag) printf("%-15s: ", "Licenses"); if (pkg_licenses(pkg, &lic) == EPKG_OK) printf("%s", pkg_license_name(lic)); while (pkg_licenses(pkg, &lic) == EPKG_OK) { if (licenselogic != 1) printf(" %c", licenselogic); printf(" %s", pkg_license_name(lic)); } printf("\n"); } else if (!print_tag) printf("\n"); break; case INFO_MAINTAINER: if (print_tag) printf("%-15s: ", "Maintainer"); printf("%s\n", maintainer); break; case INFO_WWW: if (print_tag) printf("%-15s: ", "WWW"); printf("%s\n", www); break; case INFO_COMMENT: if (print_tag) printf("%-15s: ", "Comment"); printf("%s\n", comment); break; case INFO_OPTIONS: if (pkg_list_count(pkg, PKG_OPTIONS) > 0) { if (print_tag) printf("%-15s:\n", "Options"); while (pkg_options(pkg, &option) == EPKG_OK) printf("%s%-15s: %s\n", tab, pkg_option_opt(option), pkg_option_value(option)); } break; case INFO_SHLIBS_REQUIRED: if (pkg_list_count(pkg, PKG_SHLIBS_REQUIRED) > 0) { if (print_tag) printf("%-15s:\n", "Shared Libs required"); while (pkg_shlibs_required(pkg, &shlib) == EPKG_OK) printf("%s%s\n", tab, pkg_shlib_name(shlib)); } break; case INFO_SHLIBS_PROVIDED: if (pkg_list_count(pkg, PKG_SHLIBS_PROVIDED) > 0) { if (print_tag) printf("%-15s:\n", "Shared Libs provided"); while (pkg_shlibs_provided(pkg, &shlib) == EPKG_OK) printf("%s%s\n", tab, pkg_shlib_name(shlib)); } break; case INFO_FLATSIZE: if (pkg_type(pkg) == PKG_INSTALLED || pkg_type(pkg) == PKG_FILE) humanize_number(size, sizeof(size), flatsize,"B", HN_AUTOSCALE, 0); else humanize_number(size, sizeof(size), newflatsize,"B", HN_AUTOSCALE, 0); if (print_tag) printf("%-15s: ", "Flat size"); printf("%s\n", size); break; case INFO_PKGSIZE: /* Remote pkgs only */ if (pkg_type(pkg) == PKG_REMOTE) { humanize_number(size, sizeof(size), newpkgsize,"B", HN_AUTOSCALE, 0); if (print_tag) printf("%-15s: ", "Pkg size"); printf("%s\n", size); } else if (!print_tag) printf("\n"); break; case INFO_DESCR: if (print_tag) printf("%-15s:\n", "Description"); printf("%s\n", desc); break; case INFO_MESSAGE: if (message) { if (print_tag) printf("%-15s:\n", "Message"); printf("%s\n", message); } break; case INFO_DEPS: if (pkg_list_count(pkg, PKG_DEPS) > 0) { if (print_tag) printf("%-15s:\n", "Depends on"); while (pkg_deps(pkg, &dep) == EPKG_OK) { printf("%s%s-%s", tab, pkg_dep_name(dep), pkg_dep_version(dep)); if (show_locks && pkg_dep_is_locked(dep)) printf(" (*)"); printf("\n"); } } break; case INFO_RDEPS: if (pkg_list_count(pkg, PKG_RDEPS) > 0) { if (print_tag) printf("%-15s:\n", "Required by"); while (pkg_rdeps(pkg, &dep) == EPKG_OK) { printf("%s%s-%s", tab, pkg_dep_name(dep), pkg_dep_version(dep)); if (show_locks && pkg_dep_is_locked(dep)) printf(" (*)"); printf("\n"); } } break; case INFO_FILES: /* Installed pkgs only */ if (pkg_type(pkg) != PKG_REMOTE && pkg_list_count(pkg, PKG_FILES) > 0) { if (print_tag) printf("%-15s:\n", "Files"); while (pkg_files(pkg, &file) == EPKG_OK) printf("%s%s\n", tab, pkg_file_path(file)); } break; case INFO_DIRS: /* Installed pkgs only */ if (pkg_type(pkg) != PKG_REMOTE && pkg_list_count(pkg, PKG_DIRS) > 0) { if (print_tag) printf("%-15s:\n", "Directories"); while (pkg_dirs(pkg, &dir) == EPKG_OK) printf("%s%s\n", tab, pkg_dir_path(dir)); } break; case INFO_USERS: /* Installed pkgs only */ if (pkg_type(pkg) != PKG_REMOTE && pkg_list_count(pkg, PKG_USERS) > 0) { if (print_tag) printf("%-15s: ", "Users"); if (pkg_users(pkg, &user) == EPKG_OK) printf("%s", pkg_user_name(user)); while (pkg_users(pkg, &user) == EPKG_OK) printf(" %s", pkg_user_name(user)); printf("\n"); } break; case INFO_GROUPS: /* Installed pkgs only */ if (pkg_type(pkg) != PKG_REMOTE && pkg_list_count(pkg, PKG_GROUPS) > 0) { if (print_tag) printf("%-15s: ", "Groups"); if (pkg_groups(pkg, &group) == EPKG_OK) printf("%s", pkg_group_name(group)); while (pkg_groups(pkg, &group) == EPKG_OK) printf(" %s", pkg_group_name(group)); printf("\n"); } break; case INFO_ARCH: if (print_tag) printf("%-15s: ", "Architecture"); printf("%s\n", arch); break; case INFO_REPOURL: if (pkg_type(pkg) == PKG_REMOTE && repourl != NULL && repourl[0] != '\0') { if (print_tag) printf("%-15s: ", "Pkg URL"); if (repourl[strlen(repourl) -1] == '/') printf("%s%s\n", repourl, repopath); else printf("%s/%s\n", repourl, repopath); } else if (!print_tag) printf("\n"); break; case INFO_LOCKED: if (print_tag) printf("%-15s: ", "Locked"); printf("%s\n", locked ? "yes" : "no"); break; } } }
static void print_query(struct pkg *pkg, char *qstr, char multiline) { struct sbuf *output = sbuf_new_auto(); struct pkg_dep *dep = NULL; struct pkg_category *cat = NULL; struct pkg_option *option = NULL; struct pkg_file *file = NULL; struct pkg_dir *dir = NULL; struct pkg_license *lic = NULL; struct pkg_user *user = NULL; struct pkg_group *group = NULL; struct pkg_script *scripts = NULL; switch (multiline) { case 'd': while (pkg_deps(pkg, &dep) == EPKG_OK) { format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_get(output)); break; } case 'r': while (pkg_rdeps(pkg, &dep) == EPKG_OK) { format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_get(output)); } break; case 'C': while (pkg_categories(pkg, &cat) == EPKG_OK) { format_str(pkg, output, qstr, cat); printf("%s\n", sbuf_get(output)); } break; case 'O': while (pkg_options(pkg, &option) == EPKG_OK) { format_str(pkg, output, qstr, option); printf("%s\n", sbuf_get(output)); } break; case 'F': while (pkg_files(pkg, &file) == EPKG_OK) { format_str(pkg, output, qstr, file); printf("%s\n", sbuf_get(output)); } break; case 'D': while (pkg_dirs(pkg, &dir) == EPKG_OK) { format_str(pkg, output, qstr, dir); printf("%s\n", sbuf_get(output)); } break; case 'L': while (pkg_licenses(pkg, &lic) == EPKG_OK) { format_str(pkg, output, qstr, lic); printf("%s\n", sbuf_get(output)); } break; case 'U': while (pkg_users(pkg, &user) == EPKG_OK) { format_str(pkg, output, qstr, user); printf("%s\n", sbuf_get(output)); } break; case 'G': while (pkg_users(pkg, &user) == EPKG_OK) { format_str(pkg, output, qstr, group); printf("%s\n", sbuf_get(output)); } break; case 'S': while (pkg_scripts(pkg, &scripts) == EPKG_OK) { format_str(pkg, output, qstr, scripts); printf("%s\n", sbuf_get(output)); } break; default: format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_get(output)); break; } sbuf_delete(output); }
void print_query(struct pkg *pkg, char *qstr, char multiline) { struct sbuf *output = sbuf_new_auto(); struct pkg_dep *dep = NULL; struct pkg_category *cat = NULL; struct pkg_option *option = NULL; struct pkg_file *file = NULL; struct pkg_dir *dir = NULL; struct pkg_license *lic = NULL; struct pkg_user *user = NULL; struct pkg_group *group = NULL; struct pkg_shlib *shlib = NULL; struct pkg_note *note = NULL; switch (multiline) { case 'd': while (pkg_deps(pkg, &dep) == EPKG_OK) { format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_data(output)); } break; case 'r': while (pkg_rdeps(pkg, &dep) == EPKG_OK) { format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_data(output)); } break; case 'C': while (pkg_categories(pkg, &cat) == EPKG_OK) { format_str(pkg, output, qstr, cat); printf("%s\n", sbuf_data(output)); } break; case 'O': while (pkg_options(pkg, &option) == EPKG_OK) { format_str(pkg, output, qstr, option); printf("%s\n", sbuf_data(output)); } break; case 'F': while (pkg_files(pkg, &file) == EPKG_OK) { format_str(pkg, output, qstr, file); printf("%s\n", sbuf_data(output)); } break; case 'D': while (pkg_dirs(pkg, &dir) == EPKG_OK) { format_str(pkg, output, qstr, dir); printf("%s\n", sbuf_data(output)); } break; case 'L': while (pkg_licenses(pkg, &lic) == EPKG_OK) { format_str(pkg, output, qstr, lic); printf("%s\n", sbuf_data(output)); } break; case 'U': while (pkg_users(pkg, &user) == EPKG_OK) { format_str(pkg, output, qstr, user); printf("%s\n", sbuf_data(output)); } break; case 'G': while (pkg_groups(pkg, &group) == EPKG_OK) { format_str(pkg, output, qstr, group); printf("%s\n", sbuf_data(output)); } break; case 'B': while (pkg_shlibs_required(pkg, &shlib) == EPKG_OK) { format_str(pkg, output, qstr, shlib); printf("%s\n", sbuf_data(output)); } break; case 'b': while (pkg_shlibs_provided(pkg, &shlib) == EPKG_OK) { format_str(pkg, output, qstr, shlib); printf("%s\n", sbuf_data(output)); } break; case 'A': while (pkg_annotations(pkg, ¬e) == EPKG_OK) { format_str(pkg, output, qstr, note); printf("%s\n", sbuf_data(output)); } break; default: format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_data(output)); break; } sbuf_delete(output); }
void print_query(struct pkg *pkg, char *qstr, char multiline) { struct sbuf *output = sbuf_new_auto(); struct pkg_dep *dep = NULL; struct pkg_option *option = NULL; struct pkg_file *file = NULL; struct pkg_dir *dir = NULL; char *buf; struct pkg_kv *kv; switch (multiline) { case 'd': while (pkg_deps(pkg, &dep) == EPKG_OK) { format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_data(output)); } break; case 'r': while (pkg_rdeps(pkg, &dep) == EPKG_OK) { format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_data(output)); } break; case 'C': buf = NULL; while (pkg_categories(pkg, &buf) == EPKG_OK) { format_str(pkg, output, qstr, buf); printf("%s\n", sbuf_data(output)); } break; case 'O': while (pkg_options(pkg, &option) == EPKG_OK) { format_str(pkg, output, qstr, option); printf("%s\n", sbuf_data(output)); } break; case 'F': while (pkg_files(pkg, &file) == EPKG_OK) { format_str(pkg, output, qstr, file); printf("%s\n", sbuf_data(output)); } break; case 'D': while (pkg_dirs(pkg, &dir) == EPKG_OK) { format_str(pkg, output, qstr, dir); printf("%s\n", sbuf_data(output)); } break; case 'L': buf = NULL; while (pkg_licenses(pkg, &buf) == EPKG_OK) { format_str(pkg, output, qstr, buf); printf("%s\n", sbuf_data(output)); } break; case 'U': buf = NULL; while (pkg_users(pkg, &buf) == EPKG_OK) { format_str(pkg, output, qstr, buf); printf("%s\n", sbuf_data(output)); } break; case 'G': buf = NULL; while (pkg_groups(pkg, &buf) == EPKG_OK) { format_str(pkg, output, qstr, buf); printf("%s\n", sbuf_data(output)); } break; case 'B': buf = NULL; while (pkg_shlibs_required(pkg, &buf) == EPKG_OK) { format_str(pkg, output, qstr, buf); printf("%s\n", sbuf_data(output)); } break; case 'b': buf = NULL; while (pkg_shlibs_provided(pkg, &buf) == EPKG_OK) { format_str(pkg, output, qstr, buf); printf("%s\n", sbuf_data(output)); } break; case 'A': pkg_get(pkg, PKG_ANNOTATIONS, &kv); while (kv != NULL) { format_str(pkg, output, qstr, kv); printf("%s\n", sbuf_data(output)); kv = kv->next; } break; default: format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_data(output)); break; } sbuf_delete(output); }
void print_query(struct pkg *pkg, char *qstr, char multiline) { struct sbuf *output = sbuf_new_auto(); struct pkg_dep *dep = NULL; struct pkg_option *option = NULL; struct pkg_file *file = NULL; struct pkg_dir *dir = NULL; struct pkg_user *user = NULL; struct pkg_group *group = NULL; struct pkg_shlib *shlib = NULL; const pkg_object *o, *list; pkg_iter it; switch (multiline) { case 'd': while (pkg_deps(pkg, &dep) == EPKG_OK) { format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_data(output)); } break; case 'r': while (pkg_rdeps(pkg, &dep) == EPKG_OK) { format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_data(output)); } break; case 'C': it = NULL; pkg_get(pkg, PKG_CATEGORIES, &list); while ((o = pkg_object_iterate(list, &it))) { format_str(pkg, output, qstr, o); printf("%s\n", sbuf_data(output)); } break; case 'O': while (pkg_options(pkg, &option) == EPKG_OK) { format_str(pkg, output, qstr, option); printf("%s\n", sbuf_data(output)); } break; case 'F': while (pkg_files(pkg, &file) == EPKG_OK) { format_str(pkg, output, qstr, file); printf("%s\n", sbuf_data(output)); } break; case 'D': while (pkg_dirs(pkg, &dir) == EPKG_OK) { format_str(pkg, output, qstr, dir); printf("%s\n", sbuf_data(output)); } break; case 'L': it = NULL; pkg_get(pkg, PKG_LICENSES, &list); while ((o = pkg_object_iterate(list, &it))) { format_str(pkg, output, qstr, o); printf("%s\n", sbuf_data(output)); } break; case 'U': while (pkg_users(pkg, &user) == EPKG_OK) { format_str(pkg, output, qstr, user); printf("%s\n", sbuf_data(output)); } break; case 'G': while (pkg_groups(pkg, &group) == EPKG_OK) { format_str(pkg, output, qstr, group); printf("%s\n", sbuf_data(output)); } break; case 'B': while (pkg_shlibs_required(pkg, &shlib) == EPKG_OK) { format_str(pkg, output, qstr, shlib); printf("%s\n", sbuf_data(output)); } break; case 'b': while (pkg_shlibs_provided(pkg, &shlib) == EPKG_OK) { format_str(pkg, output, qstr, shlib); printf("%s\n", sbuf_data(output)); } break; case 'A': it = NULL; pkg_get(pkg, PKG_ANNOTATIONS, &list); while ((o = pkg_object_iterate(list, &it))) { format_str(pkg, output, qstr, o); printf("%s\n", sbuf_data(output)); } break; default: format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_data(output)); break; } sbuf_delete(output); }