void list_display_linebreak(const char *title, const alpm_list_t *list, unsigned short maxcols) { unsigned short len = 0; if(title) { len = (unsigned short)string_length(title) + 1; printf("%s ", title); } if(!list) { printf("%s\n", _("None")); } else { const alpm_list_t *i; /* Print the first element */ indentprint((const char *)list->data, len, maxcols); printf("\n"); /* Print the rest */ for(i = alpm_list_next(list); i; i = alpm_list_next(i)) { size_t j; for(j = 1; j <= len; j++) { printf(" "); } indentprint((const char *)i->data, len, maxcols); printf("\n"); } } }
/* Display the content of a sync package */ void dump_pkg_sync(PM_PKG *pkg, char *treename) { char *tmp1, *tmp2; if(pkg == NULL) { return; } printf(_("Repository : %s\n"), treename); printf(_("Name : %s\n"), (char *)pacman_pkg_getinfo(pkg, PM_PKG_NAME)); printf(_("Version : %s\n"), (char *)pacman_pkg_getinfo(pkg, PM_PKG_VERSION)); PM_LIST_display(_("Groups :"), pacman_pkg_getinfo(pkg, PM_PKG_GROUPS)); PM_LIST_display(_("Provides :"), pacman_pkg_getinfo(pkg, PM_PKG_PROVIDES)); PM_LIST_display(_("Depends On :"), pacman_pkg_getinfo(pkg, PM_PKG_DEPENDS)); PM_LIST_display(_("Removes :"), pacman_pkg_getinfo(pkg, PM_PKG_REMOVES)); PM_LIST_display(_("Conflicts With :"), pacman_pkg_getinfo(pkg, PM_PKG_CONFLICTS)); PM_LIST_display(_("Replaces :"), pacman_pkg_getinfo(pkg, PM_PKG_REPLACES)); printf(_("Size (compressed) : %ld\n"), (long)pacman_pkg_getinfo(pkg, PM_PKG_SIZE)); printf(_("Size (installed) : %ld\n"), (long)pacman_pkg_getinfo(pkg, PM_PKG_USIZE)); printf(_("Description : ")); indentprint(pacman_pkg_getinfo(pkg, PM_PKG_DESC), 20); tmp1 = (char *)pacman_pkg_getinfo(pkg, PM_PKG_MD5SUM); if (tmp1 != NULL && tmp1[0] != '\0') { printf(_("\nMD5 Sum : %s"), (char *)pacman_pkg_getinfo(pkg, PM_PKG_MD5SUM)); } tmp2 = (char *)pacman_pkg_getinfo(pkg, PM_PKG_SHA1SUM); if (tmp2 != NULL && tmp2[0] != '\0') { printf(_("\nSHA1 Sum : %s"), (char *)pacman_pkg_getinfo(pkg, PM_PKG_SHA1SUM)); } printf("\n"); }
/* search the local database for a matching package */ static int query_search(alpm_list_t *targets) { alpm_list_t *i, *searchlist; int freelist; alpm_db_t *db_local = alpm_option_get_localdb(config->handle); /* if we have a targets list, search for packages matching it */ if(targets) { searchlist = alpm_db_search(db_local, targets); freelist = 1; } else { searchlist = alpm_db_get_pkgcache(db_local); freelist = 0; } if(searchlist == NULL) { return 1; } for(i = searchlist; i; i = alpm_list_next(i)) { alpm_list_t *grp; alpm_pkg_t *pkg = alpm_list_getdata(i); if(!config->quiet) { printf("local/%s %s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg)); } else { printf("%s", alpm_pkg_get_name(pkg)); } if(!config->quiet) { if((grp = alpm_pkg_get_groups(pkg)) != NULL) { alpm_list_t *k; printf(" ("); for(k = grp; k; k = alpm_list_next(k)) { const char *group = alpm_list_getdata(k); printf("%s", group); if(alpm_list_next(k)) { /* only print a spacer if there are more groups */ printf(" "); } } printf(")"); } /* we need a newline and initial indent first */ printf("\n "); indentprint(alpm_pkg_get_desc(pkg), 4); } printf("\n"); } /* we only want to free if the list was a search list */ if(freelist) { alpm_list_free(searchlist); } return 0; }
void string_display(const char *title, const char *string, unsigned short cols) { if(title) { printf("%s ", title); } if(string == NULL || string[0] == '\0') { printf(_("None")); } else { /* compute the length of title + a space */ size_t len = string_length(title) + 1; indentprint(string, (unsigned short)len, cols); } printf("\n"); }
/* Display the content of an installed package */ void dump_pkg_full(PM_PKG *pkg, int level) { char *date, *type; if(pkg == NULL) { return; } printf(_("Name : %s\n"), (char *)pacman_pkg_getinfo(pkg, PM_PKG_NAME)); printf(_("Version : %s\n"), (char *)pacman_pkg_getinfo(pkg, PM_PKG_VERSION)); PM_LIST_display(_("Groups :"), pacman_pkg_getinfo(pkg, PM_PKG_GROUPS)); printf(_("Packager : %s\n"), (char *)pacman_pkg_getinfo(pkg, PM_PKG_PACKAGER)); printf("URL : %s\n", (char *)pacman_pkg_getinfo(pkg, PM_PKG_URL)); PM_LIST_display(_("License :"), pacman_pkg_getinfo(pkg, PM_PKG_LICENSE)); printf(_("Architecture : %s\n"), (char *)pacman_pkg_getinfo(pkg, PM_PKG_ARCH)); printf(_("Size : %ld\n"), (long int)pacman_pkg_getinfo(pkg, PM_PKG_SIZE)); date = pacman_pkg_getinfo(pkg, PM_PKG_BUILDDATE); printf(_("Build Date : %s %s\n"), date, strlen(date) ? "UTC" : ""); type = pacman_pkg_getinfo(pkg, PM_PKG_BUILDTYPE); printf(_("Build Type : %s\n"), strlen(type) ? type : _("Unknown")); date = pacman_pkg_getinfo(pkg, PM_PKG_INSTALLDATE); printf(_("Install Date : %s %s\n"), date, strlen(date) ? "UTC" : ""); printf(_("Install Script : %s\n"), pacman_pkg_getinfo(pkg, PM_PKG_SCRIPLET) ? _("Yes") : _("No")); printf(_("Reason : ")); switch((long)pacman_pkg_getinfo(pkg, PM_PKG_REASON)) { case PM_PKG_REASON_EXPLICIT: printf(_("Explicitly installed\n")); break; case PM_PKG_REASON_DEPEND: printf(_("Installed as a dependency for another package\n")); break; default: printf(_("Unknown\n")); break; } PM_LIST_display(_("Provides :"), pacman_pkg_getinfo(pkg, PM_PKG_PROVIDES)); PM_LIST_display(_("Depends On :"), pacman_pkg_getinfo(pkg, PM_PKG_DEPENDS)); PM_LIST_display(_("Removes :"), pacman_pkg_getinfo(pkg, PM_PKG_REMOVES)); PM_LIST_display(_("Required By :"), pacman_pkg_getinfo(pkg, PM_PKG_REQUIREDBY)); PM_LIST_display(_("Conflicts With :"), pacman_pkg_getinfo(pkg, PM_PKG_CONFLICTS)); printf(_("Description : ")); indentprint(pacman_pkg_getinfo(pkg, PM_PKG_DESC), 17); printf("\n"); if(level > 1) { PM_LIST *i; char *root; pacman_get_option(PM_OPT_ROOT, (long *)&root); fprintf(stdout, "\n"); for(i = pacman_list_first(pacman_pkg_getinfo(pkg, PM_PKG_BACKUP)); i; i = pacman_list_next(i)) { struct stat buf; char path[PATH_MAX]; char *str = strdup(pacman_list_getdata(i)); char *ptr = index(str, '\t'); if(ptr == NULL) { FREE(str); continue; } *ptr = '\0'; ptr++; snprintf(path, PATH_MAX-1, "%s%s", root, str); if(!stat(path, &buf)) { char *md5sum = pacman_get_md5sum(path); char *sha1sum = pacman_get_sha1sum(path); if(md5sum == NULL && sha1sum == NULL) { ERR(NL, _("error calculating md5sum or sha1sum for %s\n"), path); FREE(str); continue; } if((sha1sum && !strcmp(sha1sum, ptr)) || (md5sum && !strcmp(md5sum, ptr))) { printf(_("NOT MODIFIED\t%s\n"), path); } else { printf(_("MODIFIED\t%s\n"), path); } FREE(md5sum); FREE(sha1sum); } else { printf(_("MISSING\t\t%s\n"), path); } FREE(str); } } printf("\n"); }
void signature_display(const char *title, alpm_siglist_t *siglist, unsigned short maxcols) { unsigned short len = 0; if(title) { len = (unsigned short)string_length(title) + 1; printf("%s ", title); } if(siglist->count == 0) { printf(_("None")); } else { size_t i; for(i = 0; i < siglist->count; i++) { char *sigline; const char *status, *validity, *name; int ret; alpm_sigresult_t *result = siglist->results + i; /* Don't re-indent the first result */ if(i != 0) { size_t j; for(j = 1; j <= len; j++) { printf(" "); } } switch(result->status) { case ALPM_SIGSTATUS_VALID: status = _("Valid"); break; case ALPM_SIGSTATUS_KEY_EXPIRED: status = _("Key expired"); break; case ALPM_SIGSTATUS_SIG_EXPIRED: status = _("Expired"); break; case ALPM_SIGSTATUS_INVALID: status = _("Invalid"); break; case ALPM_SIGSTATUS_KEY_UNKNOWN: status = _("Key unknown"); break; case ALPM_SIGSTATUS_KEY_DISABLED: status = _("Key disabled"); break; default: status = _("Signature error"); break; } switch(result->validity) { case ALPM_SIGVALIDITY_FULL: validity = _("full trust"); break; case ALPM_SIGVALIDITY_MARGINAL: validity = _("marginal trust"); break; case ALPM_SIGVALIDITY_NEVER: validity = _("never trust"); break; case ALPM_SIGVALIDITY_UNKNOWN: default: validity = _("unknown trust"); break; } name = result->key.uid ? result->key.uid : result->key.fingerprint; ret = pm_asprintf(&sigline, _("%s, %s from \"%s\""), status, validity, name); if(ret == -1) { pm_printf(ALPM_LOG_ERROR, _("failed to allocate string\n")); continue; } indentprint(sigline, len, maxcols); printf("\n"); free(sigline); } } }
/** * Display the details of a search. * @param db the database we're searching * @param targets the targets we're searching for * @param show_status show if the package is also in the local db */ int dump_pkg_search(alpm_db_t *db, alpm_list_t *targets, int show_status) { int freelist = 0; alpm_db_t *db_local; alpm_list_t *i, *searchlist; unsigned short cols; const colstr_t *colstr = &config->colstr; if(show_status) { db_local = alpm_get_localdb(config->handle); } /* if we have a targets list, search for packages matching it */ if(targets) { searchlist = alpm_db_search(db, targets); freelist = 1; } else { searchlist = alpm_db_get_pkgcache(db); freelist = 0; } if(searchlist == NULL) { return 1; } cols = getcols(fileno(stdout)); for(i = searchlist; i; i = alpm_list_next(i)) { alpm_list_t *grp; alpm_pkg_t *pkg = i->data; if(config->quiet) { fputs(alpm_pkg_get_name(pkg), stdout); } else { printf("%s%s/%s%s %s%s%s", colstr->repo, alpm_db_get_name(db), colstr->title, alpm_pkg_get_name(pkg), colstr->version, alpm_pkg_get_version(pkg), colstr->nocolor); if((grp = alpm_pkg_get_groups(pkg)) != NULL) { alpm_list_t *k; printf(" %s(", colstr->groups); for(k = grp; k; k = alpm_list_next(k)) { const char *group = k->data; fputs(group, stdout); if(alpm_list_next(k)) { /* only print a spacer if there are more groups */ putchar(' '); } } printf(")%s", colstr->nocolor); } if(show_status) { print_installed(db_local, pkg); } /* we need a newline and initial indent first */ fputs("\n ", stdout); indentprint(alpm_pkg_get_desc(pkg), 4, cols); } fputc('\n', stdout); } /* we only want to free if the list was a search list */ if(freelist) { alpm_list_free(searchlist); } return 0; }