Beispiel #1
0
/* -Qs, only 1 target for now */
static int query_search(alpm_db_t *localdb, const char *pkgname)
{
    int ret, found;
    const char *repo;
    alpm_list_t *i, *k, *dbcache, *groups;
    alpm_list_t *syncdbs;
    alpm_pkg_t *pkg;

    dbcache = alpm_db_get_pkgcache(localdb);
    syncdbs = alpm_option_get_syncdbs(config->handle);

    for (k = dbcache; k; k = k->next) {
        pkg = k->data;
        groups = NULL;

        if (!strcmp(pkgname, alpm_pkg_get_name(pkg))) {
            repo = which_db(syncdbs, pkgname, &groups);
            color_repo(repo);
            printf("%s%s %s%s", color.bold, pkgname,
                   color.bgreen, alpm_pkg_get_version(pkg));
            color_groups(groups);
            printf("%s %s\n", TAB, alpm_pkg_get_desc(pkg));
            found = 1;
        }
    }

    return found ? 0: -1;
}
Beispiel #2
0
static const char *color_print_repo (void *p, printpkgfn f)
{
	const char *info = (config.aur_foreign) ? f(p, 'r') : f(p, 's');
	if (info) {
		if (config.get_res) {
			dprintf (FD_RES, "%s/", info);
		}
		fprintf (stdout, "%s%s/%s", color_repo (info), info, color(C_NO));
	}
	info = f(p, 'n');
	if (config.get_res) {
		dprintf (FD_RES, "%s\n", info);
	}
	fprintf (stdout, "%s%s%s ", color(C_PKG), info, color(C_NO));
	return info;
}
Beispiel #3
0
/* For plain -Q, -Qs, -Ss */
void print_pkg_pretty(alpm_list_t *sdbs, pmpkg_t *pkg, enum dumplvl_t lvl)
{
	alpm_list_t *grp = NULL;
	const char *repo;
	int found_db, grpcnt;

	repo = which_db(sdbs, alpm_pkg_get_name(pkg), &grp);
	color_repo(repo);
	printf("%s%s %s%s%s", color.bold, alpm_pkg_get_name(pkg),
		   color.bgreen, alpm_pkg_get_version(pkg), color.nocolor);

	color_groups(grp);

	if (lvl == DUMP_Q_SEARCH) {
		printf("%s%s\n", TAB, alpm_pkg_get_desc(pkg));
	} else if (lvl == DUMP_S_SEARCH) {
		printf("%s%s", TAB, alpm_pkg_get_desc(pkg));
	}
}
Beispiel #4
0
void color_print_package (void * p, printpkgfn f)
{
	string_t *cstr;
	static int number=0;
	const char *info, *lver;
	char *ver=NULL;
	int aur=(f == aur_get_str);
	int grp=(f == alpm_grp_get_str);
	cstr=string_new ();

	/* Numbering list */
	if (config.numbering)
		cstr = string_fcat (cstr, "%s%d%s ",
		    color (C_NB), ++number, color (C_NO));

	/* repo/name */
	if (config.aur_foreign)
		info = f(p, 'r');
	else
		info = f(p, 's');
	if (info)
	{
		if (config.get_res) dprintf (FD_RES, "%s/", info);
		cstr = string_fcat (cstr, "%s%s/%s",
		    color_repo (info), info, color(C_NO));
	}
	info=f(p, 'n');
	if (config.get_res) dprintf (FD_RES, "%s\n", info);
	cstr = string_fcat (cstr, "%s%s%s ", color(C_PKG), info, color(C_NO));

	if (grp)
	{
		/* no more output for groups */
		fprintf (stdout, "%s\n", string_cstr (cstr));
		string_free (cstr);
		return;
	}

	/* Version
	 * different colors:
	 *   C_ORPHAN if package exists in AUR and is orphaned
	 *   C_OD if package exists and is out of date
	 *   C_VER otherwise
	 */
	lver = alpm_local_pkg_get_str (info, 'l');
	info = f(p, (config.aur_upgrades) ? 'V' : 'v');
	ver = STRDUP (info);
	info = (aur) ? f(p, 'm') : NULL;
	if (config.aur_foreign)
	{
		/* Compare foreign package with AUR */
		if (aur)
		{
			const char *lver_color = NULL;
			if (!info)
				lver_color=color(C_ORPHAN);
			else
			{
				info = f(p, 'o');
				if (info && info[0]=='1')
					lver_color=color(C_OD);
			}
			cstr = string_fcat (cstr, "%s%s%s",
			    (lver_color) ? lver_color : color(C_VER),
			    lver, color (C_NO));
			if (alpm_pkg_vercmp (ver, lver)>0)
				cstr = string_fcat (cstr, " ( aur: %s )", ver);
			fprintf (stdout, "%s\n", string_cstr (cstr));
			FREE (ver);
		}
		else
			fprintf (stdout, "%s %s%s%s\n", string_cstr (cstr),
				color(C_VER), lver, color(C_NO));
		string_free (cstr);
		return;
	}
	if (aur && !info)
		cstr = string_fcat (cstr, "%s%s%s", color(C_ORPHAN), ver, color (C_NO));
	else
		cstr = string_fcat (cstr, "%s%s%s", color(C_VER), ver, color (C_NO));

	/* show size */
	if (config.show_size)
	{
		info = f(p, 'r');
		if (info)
		{
			if (strcmp (info, "aur")!=0)
				cstr = string_fcat (cstr, " [%.2f M]",
				    (double) get_size_pkg (p) / (1024.0 * 1024));
		}
	}

	if (config.aur_upgrades)
	{
		fprintf (stdout, "%s\n", string_cstr (cstr));
		string_free (cstr);
		FREE (ver);
		return;
	}

	/* show groups */
	info = f(p, 'g');
	if (info)
	{
		cstr = string_fcat (cstr, " %s(%s)%s", color(C_GRP), info, color(C_NO));
	}

	/* show install information */
	if (lver)
	{
		info = f(p, 'r');
		if (info && strcmp (info, "local")!=0)
		{
			cstr = string_fcat (cstr, " %s[%s",
			    color(C_INSTALLED), _("installed"));
			if (strcmp (ver, lver)!=0)
			{
				cstr = string_fcat (cstr, ": %s%s%s%s",
				    color(C_LVER), lver, color (C_NO), color(C_INSTALLED));
			}
			cstr = string_fcat (cstr, "]%s", color(C_NO));
		}
	}
	/* ver no more needed */
	FREE (ver);

	/* Out of date status & votes */
	if (aur)
	{
		info = f(p, 'o');
		if (info && info[0]=='1')
		{
			cstr = string_fcat (cstr, " %s(%s)%s",
				color(C_OD), _("Out of Date"), color(C_NO));
		}
		info = f(p, 'w');
		if (info)
		{
			cstr = string_fcat (cstr, " %s(%s)%s",
			    color(C_VOTES), info, color(C_NO));
		}
	}

	/* Display computed string */
	fprintf (stdout, "%s\n", string_cstr (cstr));
	string_free (cstr);

	/* Description
	 * if -Q or -Sl or -Sg <target>, don't display description
	 */
	if (config.op != OP_SEARCH && config.op != OP_LIST_REPO_S) return;
	fprintf (stdout, "%s", color(C_DSC));
	indent (f(p, 'd'));
	fprintf (stdout, "%s", color(C_NO));
}