View | Details | Raw Unified
Collapse All | Expand All

(-) portage-utils-20061116/main.c (-52 / +155 lines)
 Lines 71-76   int rematch(const char *, const char *, Link Here 
static char *rmspace(char *);
static char *rmspace(char *);
void initialize_portage_env(void);
void initialize_portage_env(void);
void initialize_overlays (char portdir_overlay[]);
void initialize_ebuild_flat(void);
void initialize_ebuild_flat(void);
void reinitialize_ebuild_flat(void);
void reinitialize_ebuild_flat(void);
void reinitialize_as_needed(void);
void reinitialize_as_needed(void);
 Lines 85-97   static int quiet = 0; Link Here 
static char pretend = 0;
static char pretend = 0;
static char reinitialize = 0;
static char reinitialize = 0;
static char reinitialize_metacache = 0;
static char reinitialize_metacache = 0;
static char portdir[_Q_PATH_MAX] = "/usr/portage";
static char portarch[20] = "";
static char portarch[20] = "";
static char portvdb[] = "var/db/pkg";
static char portvdb[] = "var/db/pkg";
static char portcachedir[] = "metadata/cache";
static char portcachedir[] = "metadata/cache";
static char portroot[_Q_PATH_MAX] = "/";
static char portroot[_Q_PATH_MAX] = "/";
static char config_protect[_Q_PATH_MAX] = "/etc/";
static char config_protect[_Q_PATH_MAX] = "/etc/";
typedef struct overlay_t overlay_t;
struct overlay_t {
	char name[64];
	char path[_Q_PATH_MAX];
	struct overlay_t *next;
};
static overlay_t *overlay_gentoo = NULL;
char pkgdir[512] = "/usr/portage/packages/";
char pkgdir[512] = "/usr/portage/packages/";
char port_tmpdir[512] = "/var/tmp/portage/";
char port_tmpdir[512] = "/var/tmp/portage/";
 Lines 201-210   static void usage(int status, const char Link Here 
	for (i = 0; opts[i].name; ++i) {
	for (i = 0; opts[i].name; ++i) {
		assert(help[i] != NULL); /* this assert is a life saver when adding new applets. */
		assert(help[i] != NULL); /* this assert is a life saver when adding new applets. */
		if (opts[i].has_arg == no_argument)
		if (opts[i].has_arg == no_argument)
			printf("  -%c, --%-15s%s*%s %s\n", opts[i].val,
			printf("  -%c, --%-16s%s*%s %s\n", opts[i].val,
				opts[i].name, RED, NORM, _(help[i]));
				opts[i].name, RED, NORM, _(help[i]));
		else
		else
			printf("  -%c, --%-8s %s<arg>%s %s*%s %s\n", opts[i].val,
			printf("  -%c, --%-9s %s<arg>%s %s*%s %s\n", opts[i].val,
				opts[i].name, DKBLUE, NORM, RED, NORM, _(help[i]));
				opts[i].name, DKBLUE, NORM, RED, NORM, _(help[i]));
	}
	}
	exit(status);
	exit(status);
 Lines 469-485   char *strincr_var(const char *name, char Link Here 
	return (char *) value;
	return (char *) value;
}
}
void initialize_overlays (char portdir_overlay[])
{
	short merror = 0;
	char buf[BUFSIZE], file[_Q_PATH_MAX], *s, *p, *t;
	overlay_t *cur_overlay;
	FILE *repo_nameFP;
	s = portdir_overlay;
	cur_overlay = overlay_gentoo;
	while (*s) {
		cur_overlay->next = xmalloc (sizeof (*cur_overlay->next));
		cur_overlay = cur_overlay->next;
		cur_overlay->next = NULL;
		if ((p=strchr(s,' ')))
			*p = 0;
		snprintf(cur_overlay->path, sizeof(cur_overlay->path), "%s%s", portroot, s);
		/* find the name for the overlay */
		strncpy(file, cur_overlay->path, _Q_PATH_MAX);
		strncat(file, "/profiles/repo_name", _Q_PATH_MAX);
		if ((repo_nameFP = fopen(file, "r")))
		{
			if (!(fgets(buf, sizeof(buf),repo_nameFP)))
				merror++;
			rmspace(buf);
			if ((t = strchr(buf,'\n')))
				*t = 0;
			strncpy(cur_overlay->name, buf, sizeof(cur_overlay->name));
			fclose(repo_nameFP);
		} else
			merror++;
		if (merror) {
			/* delete trailing '/' */
			t = cur_overlay->path + strlen(cur_overlay->path) - 1;
			if (*t == '/')
				*t = 0;
			strncpy(cur_overlay->name, basename(cur_overlay->path), sizeof(cur_overlay->name));
			merror=0;
		}
		if (p)
			s = p+1;
		else
			break;
	}
}
void initialize_portage_env(void)
void initialize_portage_env(void)
{
{
	char nocolor = 0;
	char nocolor = 0;
	int i, f;
	int i, f;
	struct stat st;
	struct stat st;
	FILE *fp;
	FILE *fp;
	char tmp_portdir[_Q_PATH_MAX];
	char portdir_overlay[2048] = "";
	char buf[BUFSIZE], *s, *p;
	char buf[BUFSIZE], *s, *p;
	char profile[_Q_PATH_MAX], portage_file[_Q_PATH_MAX];
	char profile[_Q_PATH_MAX], portage_file[_Q_PATH_MAX];
	const char *files[] = {portage_file, "/etc/make.globals", "/etc/make.conf"};
	const char *files[] = {portage_file, "/etc/make.globals", "/etc/make.conf"};
	typedef enum { _Q_BOOL, _Q_STR, _Q_ISTR } var_types;
	typedef enum { _Q_BOOL, _Q_STR, _Q_ISTR } var_types;
	struct {
	struct {
		const char *name;
		const char *name;
		const size_t name_len;
		const size_t name_len;
 Lines 493-505   void initialize_portage_env(void) Link Here 
		{"CONFIG_PROTECT",   14, _Q_STR,  config_protect, sizeof(config_protect)},
		{"CONFIG_PROTECT",   14, _Q_STR,  config_protect, sizeof(config_protect)},
		{"NOCOLOR",           7, _Q_BOOL, &nocolor,       1},
		{"NOCOLOR",           7, _Q_BOOL, &nocolor,       1},
		{"FEATURES",          8, _Q_ISTR, features,       sizeof(features)},
		{"FEATURES",          8, _Q_ISTR, features,       sizeof(features)},
		{"PORTDIR",           7, _Q_STR,  portdir,        sizeof(portdir)},
		{"PORTDIR",           7, _Q_STR,  tmp_portdir,    sizeof(tmp_portdir)},
		{"PORTDIR_OVERLAY",  15, _Q_ISTR, portdir_overlay,sizeof(portdir_overlay)},
		{"PORTAGE_BINHOST",  15, _Q_STR,  binhost,        sizeof(binhost)},
		{"PORTAGE_BINHOST",  15, _Q_STR,  binhost,        sizeof(binhost)},
		{"PORTAGE_TMPDIR",   14, _Q_STR,  port_tmpdir,    sizeof(port_tmpdir)},
		{"PORTAGE_TMPDIR",   14, _Q_STR,  port_tmpdir,    sizeof(port_tmpdir)},
		{"PKGDIR",            6, _Q_STR,  pkgdir,         sizeof(pkgdir)},
		{"PKGDIR",            6, _Q_STR,  pkgdir,         sizeof(pkgdir)},
		{"ROOT",              4, _Q_STR,  portroot,       sizeof(portroot)}
		{"ROOT",              4, _Q_STR,  portroot,       sizeof(portroot)}
	};
	};
	overlay_gentoo = xmalloc(sizeof(*overlay_gentoo));
	strcpy(overlay_gentoo->name,"gentoo");
	strncpy(tmp_portdir, "/usr/portage", sizeof(tmp_portdir));
	overlay_gentoo->next = NULL;
	if ((p = strchr(portroot, '/')) != NULL)
	if ((p = strchr(portroot, '/')) != NULL)
		if (strlen(p) != 1)
		if (strlen(p) != 1)
			strncat(portroot, "/", sizeof(portroot));
			strncat(portroot, "/", sizeof(portroot));
 Lines 591-596   void initialize_portage_env(void) Link Here 
		no_colors();
		no_colors();
	else
	else
		color_remap();
		color_remap();
	snprintf(overlay_gentoo->path, sizeof(overlay_gentoo->path),"%s%s", portroot, tmp_portdir);
	/* now we initiliase the overlay chained list with overlay_gentoo as the first 'item'  */
	initialize_overlays(portdir_overlay);
}
}
enum {
enum {
 Lines 619-637   const char *initialize_flat(int cache_ty Link Here 
	int a, b, c, d, e, i;
	int a, b, c, d, e, i;
	int frac, secs, count;
	int frac, secs, count;
	FILE *fp;
	FILE *fp;
	overlay_t *cur_overlay;
	a = b = c = d = e = i = 0;
	a = b = c = d = e = i = 0;
	count = frac = secs = 0;
	count = frac = secs = 0;
	cur_overlay = overlay_gentoo;
	cache_file = (cache_type == CACHE_EBUILD ? CACHE_EBUILD_FILE : CACHE_METADATA_FILE);
	cache_file = (cache_type == CACHE_EBUILD ? CACHE_EBUILD_FILE : CACHE_METADATA_FILE);
	if (chdir(portdir) != 0) {
	if (chdir(overlay_gentoo->path) != 0) {
		warnp("chdir to PORTDIR '%s' failed", portdir);
		warnp("chdir to PORTDIR '%s' failed", overlay_gentoo->path);
		goto ret;
		goto ret;
	}
	}
	if (cache_type == CACHE_METADATA && chdir(portcachedir) != 0) {
	if (cache_type == CACHE_METADATA && chdir(portcachedir) != 0) {
		warnp("chdir to portage cache '%s/%s' failed", portdir, portcachedir);
		warnp("chdir to portage cache '%s/%s' failed", overlay_gentoo->path, portcachedir);
		goto ret;
		goto ret;
	}
	}
 Lines 647-710   const char *initialize_flat(int cache_ty Link Here 
	unlink(cache_file);
	unlink(cache_file);
	if (errno != ENOENT) {
	if (errno != ENOENT) {
		warnfp("unlinking '%s/%s' failed", portdir, cache_file);
		warnfp("unlinking '%s/%s' failed", overlay_gentoo->path, cache_file);
		goto ret;
		goto ret;
	}
	}
	if ((fp = fopen(cache_file, "w")) == NULL) {
	if ((fp = fopen(cache_file, "w")) == NULL) {
		warnfp("opening '%s/%s' failed", portdir, cache_file);
		warnfp("opening '%s/%s' failed", overlay_gentoo->path, cache_file);
		goto ret;
		goto ret;
	}
	}
	gettimeofday(&start, NULL);
	gettimeofday(&start, NULL);
	if ((a = scandir(".", &category, filter_hidden, alphasort)) < 0)
	do {
		goto ret;
		if (cur_overlay == overlay_gentoo || chdir(cur_overlay->path) == 0) {
			if ((a = scandir(".", &category, filter_hidden, alphasort)) < 0)
	for (i = 0; i < a; i++) {
		stat(category[i]->d_name, &st);
		if (!S_ISDIR(st.st_mode))
			continue;
		if (strchr(category[i]->d_name, '-') == NULL)
			if ((strncmp(category[i]->d_name, "virtual", 7)) != 0)
				continue;
				continue;
		if ((b = scandir(category[i]->d_name, &pn, filter_hidden, alphasort)) < 0)
			for (i = 0; i < a; i++) {
			continue;
				stat(category[i]->d_name, &st);
		for (c = 0; c < b; c++) {
				if (!S_ISDIR(st.st_mode))
			char de[_Q_PATH_MAX];
					continue;
				if (strchr(category[i]->d_name, '-') == NULL)
					if ((strncmp(category[i]->d_name, "virtual", 7)) != 0)
						continue;
			snprintf(de, sizeof(de), "%s/%s", category[i]->d_name, pn[c]->d_name);
				if ((b = scandir(category[i]->d_name, &pn, filter_hidden, alphasort)) < 0)
					continue;
				for (c = 0; c < b; c++) {
					char de[_Q_PATH_MAX];
			if (stat(de, &st) < 0)
					snprintf(de, sizeof(de), "%s/%s", category[i]->d_name, pn[c]->d_name);
				continue;
			switch (cache_type) {
					if (stat(de, &st) < 0)
			case CACHE_EBUILD:
						continue;
				if (!S_ISDIR(st.st_mode))
					continue;
					switch (cache_type) {
				break;
					case CACHE_EBUILD:
			case CACHE_METADATA:
						if (!S_ISDIR(st.st_mode))
				if (S_ISREG(st.st_mode))
							continue;
					fprintf(fp, "%s\n", de);
						break;
				continue;
					case CACHE_METADATA:
				break;
						if (S_ISREG(st.st_mode))
			}
							fprintf(fp, "%s\n", de);
			if ((e = scandir(de, &eb, filter_hidden, alphasort)) < 0)
						continue;
				continue;
						break;
			for (d = 0; d < e; d++) {
					}
				if ((p = strrchr(eb[d]->d_name, '.')) != NULL)
					if ((e = scandir(de, &eb, filter_hidden, alphasort)) < 0)
					if (strcmp(p, ".ebuild") == 0) {
						continue;
						count++;
					for (d = 0; d < e; d++) {
						fprintf(fp, "%s/%s/%s\n", category[i]->d_name, pn[c]->d_name, eb[d]->d_name);
						if ((p = strrchr(eb[d]->d_name, '.')) != NULL)
							if (strcmp(p, ".ebuild") == 0) {
								count++;
								fprintf(fp, "%s::%s/%s/%s\n", cur_overlay->name, category[i]->d_name, pn[c]->d_name, eb[d]->d_name);
							}
					}
					}
					while (d--) free(eb[d]);
					free(eb);
				}
				while (b--) free(pn[b]);
				free(pn);
			}
			}
			while (d--) free(eb[d]);
		} else
			free(eb);
			warnp("chdir to '%s' failed, skipping the %s repository", cur_overlay->path, cur_overlay->name);
		}
		while (b--) free(pn[b]);
	} while ((cur_overlay = cur_overlay->next));
		free(pn);
	}
	fclose(fp);
	fclose(fp);
	while (a--) free(category[a]);
	while (a--) free(category[a]);
	free(category);
	free(category);
 Lines 723-729   const char *initialize_flat(int cache_ty Link Here 
	warn("Finished %u entries in %d.%06d seconds", count, secs, frac);
	warn("Finished %u entries in %d.%06d seconds", count, secs, frac);
	if (secs > 100)
	if (secs > 100)
		warn("You should consider a faster file system such as reiserfs for PORTDIR='%s'", portdir);
		warn("You should consider a faster file system such as reiserfs for PORTDIR='%s'", overlay_gentoo->path);
ret:
ret:
	return cache_file;
	return cache_file;
}
}
 Lines 732-739   ret: Link Here 
void reinitialize_ebuild_flat(void)
void reinitialize_ebuild_flat(void)
{
{
	if ((chdir(portdir)) != 0) {
	if ((chdir(overlay_gentoo->path)) != 0) {
		warnp("chdir to PORTDIR '%s' failed", portdir);
		warnp("chdir to PORTDIR '%s' failed", overlay_gentoo->path);
		return;
		return;
	}
	}
	unlink(CACHE_EBUILD_FILE);
	unlink(CACHE_EBUILD_FILE);
 Lines 1006-1015   fuckit: Link Here 
	return cpf;
	return cpf;
}
}
/* free overlays */
void free_overlays(overlay_t *overlay);
void free_overlays(overlay_t *overlay)
{
	if (overlay->next)
		free_overlays(overlay->next);
	free(overlay);
}
void cleanup()
void cleanup()
{
{
	reinitialize_as_needed();
	reinitialize_as_needed();
	free_sets(virtuals);
	free_sets(virtuals);
	free_overlays(overlay_gentoo);
	fclose(stderr);
	fclose(stderr);
}
}
(-) portage-utils-20061116/q.c (-1 / +13 lines)
 Lines 7-21    Link Here 
 * Copyright 2005-2006 Mike Frysinger  - <vapier@gentoo.org>
 * Copyright 2005-2006 Mike Frysinger  - <vapier@gentoo.org>
 */
 */
#define Q_FLAGS "irm" COMMON_FLAGS
#define Q_FLAGS "ilrm" COMMON_FLAGS
static struct option const q_long_opts[] = {
static struct option const q_long_opts[] = {
	{"install",      no_argument, NULL, 'i'},
	{"install",      no_argument, NULL, 'i'},
	{"ls-overlays",  no_argument, NULL, 'l'},
	{"reinitialize", no_argument, NULL, 'r'},
	{"reinitialize", no_argument, NULL, 'r'},
	{"metacache",    no_argument, NULL, 'm'},
	{"metacache",    no_argument, NULL, 'm'},
	COMMON_LONG_OPTS
	COMMON_LONG_OPTS
};
};
static const char *q_opts_help[] = {
static const char *q_opts_help[] = {
	"Install symlinks for applets",
	"Install symlinks for applets",
	"List configured overlays",
	"Reinitialize ebuild cache",
	"Reinitialize ebuild cache",
	"Reinitialize metadata cache",
	"Reinitialize metadata cache",
	COMMON_OPTS_HELP
	COMMON_OPTS_HELP
 Lines 70-75   int q_main(int argc, char **argv) Link Here 
	int i;
	int i;
	char *p;
	char *p;
	APPLET func;
	APPLET func;
	overlay_t * cur_overlay;
	if (argc == 0)
	if (argc == 0)
		return 1;
		return 1;
 Lines 89-94   int q_main(int argc, char **argv) Link Here 
		COMMON_GETOPTS_CASES(q)
		COMMON_GETOPTS_CASES(q)
		case 'm': reinitialize_metacache = 1; break;
		case 'm': reinitialize_metacache = 1; break;
		case 'r': reinitialize = 1; break;
		case 'r': reinitialize = 1; break;
		case 'l': {
			printf("\n%sOverlay(s) :%s\n\n", GREEN, NORM);
			cur_overlay=overlay_gentoo;
			do {
				printf("   Name : %s%-20.20s%s \tlocation : %s%s%s\n", CYAN, cur_overlay->name, NORM, CYAN, cur_overlay->path, NORM);
			} while ((cur_overlay=cur_overlay->next));
			fputc('\n', stdout);
			return 0;
			}
		case 'i': {
		case 'i': {
			char buf[_Q_PATH_MAX];
			char buf[_Q_PATH_MAX];
			/* always bzero a buffer before using readlink() */
			/* always bzero a buffer before using readlink() */
(-) portage-utils-20061116/qcache.c (-10 / +10 lines)
 Lines 512-521   int qcache_traverse(void (*func)(qcache_ Link Here 
	int i, j, k, len, num_cat, num_pkg, num_ebuild;
	int i, j, k, len, num_cat, num_pkg, num_ebuild;
	struct direct **categories, **packages, **ebuilds;
	struct direct **categories, **packages, **ebuilds;
	len = sizeof(char) * (strlen(QCACHE_EDB) + strlen(portdir) + 1);
	len = sizeof(char) * (strlen(QCACHE_EDB) + strlen(overlay_gentoo->path) + 1);
	catpath = xmalloc(len);
	catpath = xmalloc(len);
	memset(catpath, 0, len);
	memset(catpath, 0, len);
	snprintf(catpath, len, "%s%s", QCACHE_EDB, portdir);
	snprintf(catpath, len, "%s%s", QCACHE_EDB, overlay_gentoo->path);
	if (-1 == (num_cat = scandir(catpath, &categories, qcache_file_select, alphasort))) {
	if (-1 == (num_cat = scandir(catpath, &categories, qcache_file_select, alphasort))) {
		err("%s %s", catpath, strerror(errno));
		err("%s %s", catpath, strerror(errno));
 Lines 527-536   int qcache_traverse(void (*func)(qcache_ Link Here 
	/* traverse categories */
	/* traverse categories */
	for (i = 0; i < num_cat; i++) {
	for (i = 0; i < num_cat; i++) {
		len = sizeof(char) * (strlen(portdir) + strlen("/") + strlen(categories[i]->d_name) + 1);
		len = sizeof(char) * (strlen(overlay_gentoo->path) + strlen("/") + strlen(categories[i]->d_name) + 1);
		pkgpath = xmalloc(len);
		pkgpath = xmalloc(len);
		memset(pkgpath, 0, len);
		memset(pkgpath, 0, len);
		snprintf(pkgpath, len, "%s/%s", portdir, categories[i]->d_name);
		snprintf(pkgpath, len, "%s/%s", overlay_gentoo->path, categories[i]->d_name);
		if (-1 == (num_pkg = scandir(pkgpath, &packages, qcache_file_select, alphasort))) {
		if (-1 == (num_pkg = scandir(pkgpath, &packages, qcache_file_select, alphasort))) {
			warn("%s %s", catpath, strerror(errno));
			warn("%s %s", catpath, strerror(errno));
 Lines 552-561   int qcache_traverse(void (*func)(qcache_ Link Here 
		/* traverse packages */
		/* traverse packages */
		for (j = 0; j < num_pkg; j++) {
		for (j = 0; j < num_pkg; j++) {
			len = sizeof(char) * (strlen(portdir) + strlen("/") + strlen(categories[i]->d_name) + strlen("/") + strlen(packages[j]->d_name) + 1);
			len = sizeof(char) * (strlen(overlay_gentoo->path) + strlen("/") + strlen(categories[i]->d_name) + strlen("/") + strlen(packages[j]->d_name) + 1);
			ebuildpath = xmalloc(len);
			ebuildpath = xmalloc(len);
			memset(ebuildpath, 0, len);
			memset(ebuildpath, 0, len);
			snprintf(ebuildpath, len, "%s/%s/%s", portdir, categories[i]->d_name, packages[j]->d_name);
			snprintf(ebuildpath, len, "%s/%s/%s", overlay_gentoo->path, categories[i]->d_name, packages[j]->d_name);
			if (-1 == (num_ebuild = scandir(ebuildpath, &ebuilds, qcache_ebuild_select, qcache_vercmp))) {
			if (-1 == (num_ebuild = scandir(ebuildpath, &ebuilds, qcache_ebuild_select, qcache_vercmp))) {
				warn("%s %s", ebuildpath, strerror(errno));
				warn("%s %s", ebuildpath, strerror(errno));
 Lines 773-782   void qcache_stats(qcache_data *data) Link Here 
		for (i = 0; archlist[i]; i++)
		for (i = 0; archlist[i]; i++)
			architectures++;
			architectures++;
		len = sizeof(char) * (strlen(QCACHE_EDB) + strlen(portdir) + 1);
		len = sizeof(char) * (strlen(QCACHE_EDB) + strlen(overlay_gentoo->path) + 1);
		catpath = xmalloc(len);
		catpath = xmalloc(len);
		memset(catpath, 0, len);
		memset(catpath, 0, len);
		snprintf(catpath, len, "%s%s", QCACHE_EDB, portdir);
		snprintf(catpath, len, "%s%s", QCACHE_EDB, overlay_gentoo->path);
		if (-1 == (numcat = scandir(catpath, &categories, qcache_file_select, alphasort))) {
		if (-1 == (numcat = scandir(catpath, &categories, qcache_file_select, alphasort))) {
			err("%s %s", catpath, strerror(errno));
			err("%s %s", catpath, strerror(errno));
 Lines 928-938   int qcache_init() Link Here 
	char *filename;
	char *filename;
	unsigned int len;
	unsigned int len;
	len      = sizeof(char) * (strlen(portdir) + strlen("/profiles/arch.list") + 1);
	len      = sizeof(char) * (strlen(overlay_gentoo->path) + strlen("/profiles/arch.list") + 1);
	filename = xmalloc(len);
	filename = xmalloc(len);
	memset(filename, 0, len);
	memset(filename, 0, len);
	snprintf(filename, len, "%s/profiles/arch.list", portdir);
	snprintf(filename, len, "%s/profiles/arch.list", overlay_gentoo->path);
	if (NULL == (archlist = qcache_read_lines(filename))) {
	if (NULL == (archlist = qcache_read_lines(filename))) {
		free(filename);
		free(filename);
(-) portage-utils-20061116/qgrep.c (-4 / +63 lines)
 Lines 10-20    Link Here 
#ifdef APPLET_qgrep
#ifdef APPLET_qgrep
#define QGREP_FLAGS "IiHce" COMMON_FLAGS
#define QGREP_FLAGS "IiHo:ce" COMMON_FLAGS
static struct option const qgrep_long_opts[] = {
static struct option const qgrep_long_opts[] = {
	{"invert-match",  no_argument, NULL, 'I'},
	{"invert-match",  no_argument, NULL, 'I'},
	{"ignore-case",   no_argument, NULL, 'i'},
	{"ignore-case",   no_argument, NULL, 'i'},
	{"with-filename", no_argument, NULL, 'H'},
	{"with-filename", no_argument, NULL, 'H'},
	{"overlay",        a_argument, NULL, 'o'},
	{"count",         no_argument, NULL, 'c'},
	{"count",         no_argument, NULL, 'c'},
	{"regexp",        no_argument, NULL, 'e'},
	{"regexp",        no_argument, NULL, 'e'},
	COMMON_LONG_OPTS
	COMMON_LONG_OPTS
 Lines 23-28   static const char *qgrep_opts_help[] = { Link Here 
	"Select non-matching lines",
	"Select non-matching lines",
	"Ignore case distinctions",
	"Ignore case distinctions",
	"Print the filename for each match",
	"Print the filename for each match",
	"Only consider the <arg> overlay",
	"Only print a count of matching lines per FILE",
	"Only print a count of matching lines per FILE",
	"Use PATTERN as a regular expression",
	"Use PATTERN as a regular expression",
	COMMON_OPTS_HELP
	COMMON_OPTS_HELP
 Lines 34-40   int qgrep_main(int argc, char **argv) Link Here 
{
{
	int i;
	int i;
	int count = 0;
	int count = 0;
	char *p;
	short myerror = 0, repo = 0;
	char overlay_name[64], repo_search[64];
	char *p, *str;
	char do_count, do_regex;
	char do_count, do_regex;
	char show_filename;
	char show_filename;
	FILE *fp;
	FILE *fp;
 Lines 42-51   int qgrep_main(int argc, char **argv) Link Here 
	char buf0[BUFSIZ];
	char buf0[BUFSIZ];
	int reflags = REG_NOSUB;
	int reflags = REG_NOSUB;
	char invert_match = 0;
	char invert_match = 0;
	overlay_t *cur_overlay, *overlay_tmp;
	typedef char *(*FUNC) (char *, char *);
	typedef char *(*FUNC) (char *, char *);
	FUNC strfunc = (FUNC) strstr;
	FUNC strfunc = (FUNC) strstr;
	cur_overlay = overlay_gentoo;
	overlay_name[0] = 0;
	repo_search[0] = 0;
	DBG("argc=%d argv[0]=%s argv[1]=%s",
	DBG("argc=%d argv[0]=%s argv[1]=%s",
	    argc, argv[0], argc > 1 ? argv[1] : "NULL?");
	    argc, argv[0], argc > 1 ? argv[1] : "NULL?");
 Lines 58-69   int qgrep_main(int argc, char **argv) Link Here 
			strfunc = (FUNC) strcasestr;
			strfunc = (FUNC) strcasestr;
			reflags |= REG_ICASE;
			reflags |= REG_ICASE;
			break;
			break;
		case 'H': show_filename = 1; break;
		case 'o':
			repo = 1;
			strncpy(repo_search, optarg, sizeof(repo_search));
			break;
		case 'c': do_count = 1; break;
		case 'c': do_count = 1; break;
		case 'e': do_regex = 1; break;
		case 'e': do_regex = 1; break;
		case 'H': show_filename = 1; break;
		COMMON_GETOPTS_CASES(qgrep)
		COMMON_GETOPTS_CASES(qgrep)
		}
		}
	}
	}
	if (repo) {
		do {
			if (!strncmp(cur_overlay->name, repo_search, sizeof(cur_overlay->name)))
				break;
		} while ((cur_overlay=cur_overlay->next));
		if (NULL == cur_overlay)
			err("%s : Unknown overlay, try 'q --ls-overlays'", repo_search);
	}
	if (argc == optind)
	if (argc == optind)
		qgrep_usage(EXIT_FAILURE);
		qgrep_usage(EXIT_FAILURE);
 Lines 73-78   int qgrep_main(int argc, char **argv) Link Here 
		return 1;
		return 1;
	while ((fgets(ebuild, sizeof(ebuild), fp)) != NULL) {
	while ((fgets(ebuild, sizeof(ebuild), fp)) != NULL) {
		FILE *newfp;
		FILE *newfp;
		if ((p = strchr(ebuild, ':')))
		{
			*p = 0;
			str = p+2;			/* separator is '::' */
			p = ebuild;
			if (repo && strncmp(repo_search, p, sizeof(repo_search)))
				continue;
			if (strncmp(overlay_name, p, sizeof(overlay_name))) {
				overlay_tmp=overlay_gentoo;
				do {
					if (!strncmp(overlay_tmp->name, p, sizeof(overlay_tmp->name)))
						break;
				} while ((overlay_tmp=overlay_tmp->next));
				if (overlay_tmp) {
					cur_overlay = overlay_tmp;
					if (chdir(cur_overlay->path) != 0) {
						warnp("chdir to PORTDIR '%s' failed", cur_overlay->path);
						myerror=1;
					}
				} else
					myerror=1;
				strncpy(overlay_name, p, sizeof(overlay_name));
			}
			strcpy(ebuild, str);
		} else
			myerror=1;
		if (myerror) {
			if (!reinitialize)
				warnf("(cache update pending) %s : Unknown overlay", overlay_name);
			reinitialize = 1;
			myerror=0;
			continue;
		}
		if ((p = strchr(ebuild, '\n')) != NULL)
		if ((p = strchr(ebuild, '\n')) != NULL)
			*p = 0;
			*p = 0;
		if ((newfp = fopen(ebuild, "r")) != NULL) {
		if ((newfp = fopen(ebuild, "r")) != NULL) {
 Lines 102-108   int qgrep_main(int argc, char **argv) Link Here 
				count++;
				count++;
				if (do_count) continue;
				if (do_count) continue;
				if (verbose || show_filename) {
				if (verbose || show_filename) {
					printf("%s:", ebuild);
					printf("%s::%s:", cur_overlay->name, ebuild);
					if (verbose > 1) printf("%d:", lineno);
					if (verbose > 1) printf("%d:", lineno);
					printf(" ");
					printf(" ");
				}
				}
(-) portage-utils-20061116/qsearch.c (-11 / +91 lines)
 Lines 9-18    Link Here 
#ifdef APPLET_qsearch
#ifdef APPLET_qsearch
#define QSEARCH_FLAGS "acsSNH" COMMON_FLAGS
#define QSEARCH_FLAGS "aco:psSNH" COMMON_FLAGS
static struct option const qsearch_long_opts[] = {
static struct option const qsearch_long_opts[] = {
	{"all",       no_argument, NULL, 'a'},
	{"all",       no_argument, NULL, 'a'},
	{"cache",     no_argument, NULL, 'c'},
	{"cache",     no_argument, NULL, 'c'},
	{"overlay",    a_argument, NULL, 'o'},
	{"show-path", no_argument, NULL, 'p'},
	{"search",    no_argument, NULL, 's'},
	{"search",    no_argument, NULL, 's'},
	{"desc",       a_argument, NULL, 'S'},
	{"desc",       a_argument, NULL, 'S'},
	{"name-only", no_argument, NULL, 'N'},
	{"name-only", no_argument, NULL, 'N'},
 Lines 22-27   static struct option const qsearch_long_ Link Here 
static const char *qsearch_opts_help[] = {
static const char *qsearch_opts_help[] = {
	"List the descriptions of every package in the cache",
	"List the descriptions of every package in the cache",
	"Use the portage cache",
	"Use the portage cache",
	"Search only in the <arg> overlay",
	"Show the path to the ebuild",
	"Regex search package basenames",
	"Regex search package basenames",
	"Regex search package descriptions",
	"Regex search package descriptions",
	"Only show package name",
	"Only show package name",
 Lines 40-52   int qsearch_main(int argc, char **argv) Link Here 
	char last[126] = "";
	char last[126] = "";
	char dp[126] = "";
	char dp[126] = "";
	char bp[126] = "";
	char bp[126] = "";
	char *p, *q, *str;
	short repo = 0;
	char repo_search[64];
	char *p, *q, *str, overlay_name[64];
	char *search_me = NULL;
	char *search_me = NULL;
	char show_homepage = 0, show_name_only = 0;
	char show_homepage = 0, show_name_only = 0, show_path_to_ebuild = 0;
	char search_desc = 0, search_all = 0, search_name = 1, search_cache = CACHE_EBUILD;
	char search_desc = 0, search_all = 0, search_name = 1, search_cache = CACHE_EBUILD;
	const char *search_vars[] = { "DESCRIPTION=", "HOMEPAGE=" };
	const char *search_vars[] = { "DESCRIPTION=", "HOMEPAGE=" };
	size_t search_len;
	size_t search_len;
	int i, idx=0;
	overlay_t *cur_overlay, *overlay_tmp;
	int i, idx=0, myerror=0;
	cur_overlay = overlay_gentoo;
	overlay_name[0] = 0;
	repo_search[0] = 0;
	DBG("argc=%d argv[0]=%s argv[1]=%s",
	DBG("argc=%d argv[0]=%s argv[1]=%s",
	    argc, argv[0], argc > 1 ? argv[1] : "NULL?");
	    argc, argv[0], argc > 1 ? argv[1] : "NULL?");
 Lines 56-61   int qsearch_main(int argc, char **argv) Link Here 
		COMMON_GETOPTS_CASES(qsearch)
		COMMON_GETOPTS_CASES(qsearch)
		case 'a': search_all = 1; break;
		case 'a': search_all = 1; break;
		case 'c': search_cache = CACHE_METADATA; break;
		case 'c': search_cache = CACHE_METADATA; break;
		case 'o': repo = 1; strncpy(repo_search, optarg, sizeof(repo_search)); break;
		case 'p': show_path_to_ebuild = 1; break;
		case 's': search_desc = 0; search_name = 1; break;
		case 's': search_desc = 0; search_name = 1; break;
		case 'S': search_desc = 1; search_name = 0; break;
		case 'S': search_desc = 1; search_name = 0; break;
		case 'N': show_name_only = 1; break;
		case 'N': show_name_only = 1; break;
 Lines 63-68   int qsearch_main(int argc, char **argv) Link Here 
		}
		}
	}
	}
	if (repo) {
		do {
			if (! strncmp(cur_overlay->name, repo_search, sizeof(cur_overlay->name)))
				break;
		} while ((cur_overlay=cur_overlay->next));
		if (NULL == cur_overlay)
			err("%s : Unknown overlay, try 'q --ls-overlays'", repo_search);
	}
	if (search_all) {
	if (search_all) {
		search_desc = 1;
		search_desc = 1;
		search_name = 0;
		search_name = 0;
 Lines 93-103   int qsearch_main(int argc, char **argv) Link Here 
			if ((pcache = cache_read_file(ebuild)) != NULL) {
			if ((pcache = cache_read_file(ebuild)) != NULL) {
				if ((strcmp(pcache->atom->PN, last)) != 0) {
				if ((strcmp(pcache->atom->PN, last)) != 0) {
					strncpy(last, pcache->atom->PN, sizeof(last));
					strncpy(last, pcache->atom->PN, sizeof(last));
					if ((rematch(search_me, (search_desc ? pcache->DESCRIPTION : ebuild), REG_EXTENDED | REG_ICASE)) == 0)
					if ((rematch(search_me, (search_desc ? pcache->DESCRIPTION : ebuild), REG_EXTENDED | REG_ICASE)) == 0) {
						printf("%s%s/%s%s%s %s\n", BOLD, pcache->atom->CATEGORY, BLUE,
						if (show_path_to_ebuild) {
						       pcache->atom->PN, NORM,
							printf("%s%s/%s%s%s::%s\t %s%s/%s/\n",
						       (show_name_only ? "" :
							BOLD, pcache->atom->CATEGORY,
						        (show_homepage ? pcache->HOMEPAGE : pcache->DESCRIPTION)));
							BLUE, pcache->atom->PN,
							YELLOW,cur_overlay->name, NORM,
							cur_overlay->path, dirname(ebuild));
						} else {
							printf("%s%s/%s%s%s::%s %s%s\n",
							BOLD, pcache->atom->CATEGORY,
							BLUE, pcache->atom->PN,
							YELLOW,cur_overlay->name, NORM,
							(show_name_only ? "" :
							(show_homepage ? pcache->HOMEPAGE : pcache->DESCRIPTION)));
						}
					}
				}
				}
				cache_free(pcache);
				cache_free(pcache);
			} else {
			} else {
 Lines 110-115   int qsearch_main(int argc, char **argv) Link Here 
		case CACHE_EBUILD: {
		case CACHE_EBUILD: {
			FILE *ebuildfp;
			FILE *ebuildfp;
			if ((p = strchr(ebuild, ':')))
			{
				*p = 0;
				str = p+2;			/* separator is '::' */
				p = ebuild;
				if (repo && strncmp(repo_search, p, sizeof(repo_search)))
					continue;
				if (strncmp(overlay_name, p, sizeof(overlay_name))) {
					last[0] = 0;
					overlay_tmp=overlay_gentoo;
					do {
						if (!strncmp(overlay_tmp->name, p, sizeof(overlay_tmp->name)))
							break;
					} while ((overlay_tmp=overlay_tmp->next));
					if (overlay_tmp) {
						cur_overlay = overlay_tmp;
						if (chdir(cur_overlay->path) != 0) {
							warnp("chdir to '%s' failed", cur_overlay->path);
							myerror=1;
						}
					} else
						myerror=1;
					strncpy(overlay_name, p, sizeof(overlay_name));
				}
				strcpy(ebuild, str);
			} else
				myerror=1;
			if (myerror) {
				if (!reinitialize)
					warnf("(cache update pending) %s : Unknown overlay", overlay_name);
				reinitialize = 1;
				myerror=0;
				continue;
			}
			str = xstrdup(ebuild);
			str = xstrdup(ebuild);
			p = (char *) dirname(str);
			p = (char *) dirname(str);
 Lines 134-142   int qsearch_main(int argc, char **argv) Link Here 
							// doing operations with them.
							// doing operations with them.
							strncpy(dp, p, sizeof(dp));
							strncpy(dp, p, sizeof(dp));
							strncpy(bp, p, sizeof(bp));
							strncpy(bp, p, sizeof(bp));
							printf("%s%s/%s%s%s %s\n",
							if (show_path_to_ebuild) {
								BOLD, dirname(dp), BLUE, basename(bp), NORM,
								printf("%s%s/%s%s%s::%s\t %s%s/%s/\n",
								BOLD, dirname(dp), BLUE, basename(bp),
								YELLOW,cur_overlay->name, NORM,
								cur_overlay->path, dirname(ebuild));
							} else {
								printf("%s%s/%s%s%s::%s %s%s\n",
								BOLD, dirname(dp), BLUE, basename(bp),
								YELLOW,cur_overlay->name, NORM,
								(show_name_only ? "" : q));
								(show_name_only ? "" : q));
							}
							break;
							break;
						}
						}
					}
					}
(-) portage-utils-20061116/quse.c (-86 / +190 lines)
 Lines 14-23    Link Here 
 quse -Ke --  nls
 quse -Ke --  nls
*/
*/
#define QUSE_FLAGS "eavKLDF:N" COMMON_FLAGS
#define QUSE_FLAGS "eao:vKLDF:N" COMMON_FLAGS
static struct option const quse_long_opts[] = {
static struct option const quse_long_opts[] = {
	{"exact",     no_argument, NULL, 'e'},
	{"exact",     no_argument, NULL, 'e'},
	{"all",       no_argument, NULL, 'a'},
	{"all",       no_argument, NULL, 'a'},
	{"overlay",    a_argument, NULL, 'o'},
	{"keywords",  no_argument, NULL, 'K'},
	{"keywords",  no_argument, NULL, 'K'},
	{"license",   no_argument, NULL, 'L'},
	{"license",   no_argument, NULL, 'L'},
	{"describe",  no_argument, NULL, 'D'},
	{"describe",  no_argument, NULL, 'D'},
 Lines 28-33   static struct option const quse_long_opt Link Here 
static const char *quse_opts_help[] = {
static const char *quse_opts_help[] = {
	"Show exact non regexp matching using strcmp",
	"Show exact non regexp matching using strcmp",
	"Show annoying things in IUSE",
	"Show annoying things in IUSE",
	"Only consider the <arg> overlay",
	"Use the KEYWORDS vs IUSE",
	"Use the KEYWORDS vs IUSE",
	"Use the LICENSE vs IUSE",
	"Use the LICENSE vs IUSE",
	"Describe the USE flag",
	"Describe the USE flag",
 Lines 38-44   static const char *quse_opts_help[] = { Link Here 
static const char quse_rcsid[] = "$Id: quse.c,v 1.53 2006/11/09 00:18:05 vapier Exp $";
static const char quse_rcsid[] = "$Id: quse.c,v 1.53 2006/11/09 00:18:05 vapier Exp $";
#define quse_usage(ret) usage(ret, QUSE_FLAGS, quse_long_opts, quse_opts_help, lookup_applet_idx("quse"))
#define quse_usage(ret) usage(ret, QUSE_FLAGS, quse_long_opts, quse_opts_help, lookup_applet_idx("quse"))
int quse_describe_flag(int ind, int argc, char **argv);
int quse_describe_flag(int ind, short repo, char repo_search[], int argc, char **argv);
char quse_name_only = 0;
char quse_name_only = 0;
 Lines 81-87   static void print_highlighted_use_flags( Link Here 
	}
	}
}
}
int quse_describe_flag(int ind, int argc, char **argv)
int quse_describe_flag(int ind, short repo, char repo_search[], int argc, char **argv)
{
{
#define NUM_SEARCH_FILES ARR_SIZE(search_files)
#define NUM_SEARCH_FILES ARR_SIZE(search_files)
	char buf[BUFSIZE], *p;
	char buf[BUFSIZE], *p;
 Lines 91-211   int quse_describe_flag(int ind, int argc Link Here 
	FILE *fp[NUM_SEARCH_FILES];
	FILE *fp[NUM_SEARCH_FILES];
	DIR *d;
	DIR *d;
	struct dirent *de;
	struct dirent *de;
	overlay_t *cur_overlay;
	for (i = 0; i < NUM_SEARCH_FILES; ++i) {
	cur_overlay=overlay_gentoo;
		snprintf(buf, sizeof(buf), "%s/profiles/%s", portdir, search_files[i]);
		if ((fp[i] = fopen(buf, "r")) == NULL)
			warnp("skipping %s", search_files[i]);
	}
	for (i = ind; i < argc; i++) {
	do {
		s = strlen(argv[i]);
		if (repo && strncmp(repo_search, cur_overlay->name, sizeof(repo_search)))
			continue;
		for (i = 0; i < NUM_SEARCH_FILES; ++i) {
			snprintf(buf, sizeof(buf), "%s/profiles/%s", cur_overlay->path, search_files[i]);
			if ((fp[i] = fopen(buf, "r")) == NULL)
				if (verbose )
					warnp("skipping %s for the %s overlay", search_files[i], cur_overlay->name);
		}
		for (f = 0; f < NUM_SEARCH_FILES; ++f) {
		for (i = ind; i < argc; i++) {
			if (fp[f] == NULL)
			s = strlen(argv[i]);
				continue;
			while (fgets(buf, sizeof(buf), fp[f]) != NULL) {
			for (f = 0; f < NUM_SEARCH_FILES; ++f) {
				if (buf[0] == '#' || buf[0] == '\n')
				if (fp[f] == NULL)
					continue;
					continue;
				if ((p = strrchr(buf, '\n')) != NULL)
				while (fgets(buf, sizeof(buf), fp[f]) != NULL) {
					*p = '\0';
					if (buf[0] == '#' || buf[0] == '\n')
						continue;
				switch (f) {
					if ((p = strrchr(buf, '\n')) != NULL)
					case 0: /* Global use.desc */
						*p = '\0';
						if (!strncmp(buf, argv[i], s))
							if (buf[s] == ' ' && buf[s+1] == '-') {
								printf(" %sglobal%s:%s%s%s: %s\n", BOLD, NORM, BLUE, argv[i], NORM, buf+s+3);
								goto skip_file;
							}
						break;
					case 1: /* Local use.local.desc */
					switch (f) {
						if ((p = strchr(buf, ':')) == NULL)
						case 0: /* Global use.desc */
							if (!strncmp(buf, argv[i], s))
								if (buf[s] == ' ' && buf[s+1] == '-') {
									if (cur_overlay == overlay_gentoo)
										printf(" %sglobal%s:%s%s%s: %s\n", BOLD, NORM, BLUE, argv[i], NORM, buf+s+3);
									else
										printf(" (%s) %sglobal%s:%s%s%s: %s\n", cur_overlay->name, BOLD, NORM, BLUE, argv[i], NORM, buf+s+3);
									goto skip_file;
								}
							break;
							break;
						++p;
						if (!strncmp(p, argv[i], s)) {
							if (p[s] == ' ' && p[s+1] == '-') {
								*p = '\0';
								printf(" %slocal%s:%s%s%s:%s%s%s %s\n", BOLD, NORM, BLUE, argv[i], NORM, BOLD, buf, NORM, p+s+3);
							}
						}
						break;
					case 2: /* Architectures arch.list */
						case 1: /* Local use.local.desc */
						if (!strcmp(buf, argv[i])) {
							if ((p = strchr(buf, ':')) == NULL)
							printf(" %sarch%s:%s%s%s: %s architecture\n", BOLD, NORM, BLUE, argv[i], NORM, argv[i]);
								break;
							goto skip_file;
							++p;
						}
							if (!strncmp(p, argv[i], s)) {
						break;
								if (p[s] == ' ' && p[s+1] == '-') {
									*p = '\0';
									if (cur_overlay == overlay_gentoo)
										printf(" %slocal%s:%s%s%s:%s%s%s %s\n", BOLD, NORM, BLUE, argv[i], NORM, BOLD, buf, NORM, p+s+3);
									else
										printf(" (%s) %slocal%s:%s%s%s:%s%s%s %s\n", cur_overlay->name, BOLD, NORM, BLUE, argv[i], NORM, BOLD, buf, NORM, p+s+3);
								}
							}
							break;
					case 3: /* Languages lang.desc */
						case 2: /* Architectures arch.list */
						if (!strncmp(buf, argv[i], s))
							if (!strcmp(buf, argv[i])) {
							if (buf[s] == ' ' && buf[s+1] == '-') {
								if (cur_overlay == overlay_gentoo)
								printf(" %slang%s:%s%s%s: %s lingua\n", BOLD, NORM, BLUE, argv[i], NORM, buf+s+3);
									printf(" %sarch%s:%s%s%s: %s architecture\n", BOLD, NORM, BLUE, argv[i], NORM, argv[i]);
								else
									printf(" (%s) %sarch%s:%s%s%s: %s architecture\n", cur_overlay->name, BOLD, NORM, BLUE, argv[i], NORM, argv[i]);
								goto skip_file;
								goto skip_file;
							}
							}
						break;
							break;
						case 3: /* Languages lang.desc */
							if (!strncmp(buf, argv[i], s))
								if (buf[s] == ' ' && buf[s+1] == '-') {
									if (cur_overlay == overlay_gentoo)
										printf(" %slang%s:%s%s%s: %s lingua\n", BOLD, NORM, BLUE, argv[i], NORM, buf+s+3);
									else
										printf(" (%s) %slang%s:%s%s%s: %s lingua\n", cur_overlay->name, BOLD, NORM, BLUE, argv[i], NORM, buf+s+3);
									goto skip_file;
								}
							break;
					}
				}
				}
			}
skip_file:
skip_file:
			rewind(fp[f]);
				rewind(fp[f]);
			}
			if (i == (argc - 1))
				for (f=0; f<NUM_SEARCH_FILES; ++f)
					if (fp[f]) {
						fclose(fp[f]);
						fp[f] = NULL;
					}
		}
		}
	}
	for (f=0; f<NUM_SEARCH_FILES; ++f)
	} while ((cur_overlay=cur_overlay->next));
		fclose(fp[f]);
	/* now scan the desc dir */
	/* now scan the desc dir */
	snprintf(buf, sizeof(buf), "%s/profiles/desc/", portdir);
	cur_overlay=overlay_gentoo;
	d = opendir(buf);
	do {
	while ((de = readdir(d)) != NULL) {
		if (repo && strncmp(repo_search, cur_overlay->name, sizeof(repo_search)))
		if (strcmp(de->d_name+strlen(de->d_name)-5, ".desc"))
			continue;
			continue;
		snprintf(buf, sizeof(buf), "%s/profiles/desc/", cur_overlay->path);
		snprintf(buf, sizeof(buf), "%s/profiles/desc/%s", portdir, de->d_name);
		if (!(d = opendir(buf))) {
		if ((fp[0]=fopen(buf, "r")) == NULL) {
			if (verbose)
			warn("Could not open '%s' for reading; skipping", de->d_name);
				warn("Could not open %s -> skipping", buf);
			continue;
			continue;
		}
		}
		while ((de = readdir(d)) != NULL) {
			if (strcmp(de->d_name+strlen(de->d_name)-5, ".desc"))
				continue;
		while (fgets(buf, sizeof(buf), fp[0]) != NULL) {
			snprintf(buf, sizeof(buf), "%s/profiles/desc/%s", cur_overlay->path, de->d_name);
			if (buf[0] == '#' || buf[0] == '\n')
			if ((fp[0]=fopen(buf, "r")) == NULL) {
				warn("Could not open '%s' for reading; skipping", de->d_name);
				continue;
				continue;
			}
			if ((p = strrchr(buf, '\n')) != NULL)
			while (fgets(buf, sizeof(buf), fp[0]) != NULL) {
				*p = '\0';
				if (buf[0] == '#' || buf[0] == '\n')
					continue;
				if ((p = strrchr(buf, '\n')) != NULL)
					*p = '\0';
			if ((p = strchr(buf, '-')) == NULL) {
				if ((p = strchr(buf, '-')) == NULL) {
invalid_line:
invalid_line:
				warn("Invalid line in '%s': %s", de->d_name, buf);
					warn("Invalid line in '%s': %s", de->d_name, buf);
				continue;
					continue;
			}
				}
			while (p[-1] != ' ' && p[1] != ' ') {
				while (p[-1] != ' ' && p[1] != ' ') {
				/* maybe the flag has a '-' in it ... */
					/* maybe the flag has a '-' in it ... */
				if ((p = strchr(p+1, '-')) == NULL)
					if ((p = strchr(p+1, '-')) == NULL)
					goto invalid_line;
						goto invalid_line;
			}
				}
			p[-1] = '\0';
				p[-1] = '\0';
			p += 2;
				p += 2;
			for (i = ind; i < argc; i++)
				for (i = ind; i < argc; i++)
				if (!strcmp(argv[i], buf))
					if (!strcmp(argv[i], buf)) {
					printf(" %s%s%s:%s%s%s: %s\n", BOLD, de->d_name, NORM, BLUE, argv[i], NORM, p);
						if (cur_overlay == overlay_gentoo)
		}
							printf(" %s%s%s:%s%s%s: %s\n", BOLD, de->d_name, NORM, BLUE, argv[i], NORM, p);
		close(f);
						else
	}
							printf(" (%s) %s%s%s:%s%s%s: %s\n", cur_overlay->name, BOLD, de->d_name, NORM, BLUE, argv[i], NORM, p);
	closedir(d);
					}
			}
			fclose(fp[0]);
		}
		closedir(d);
	} while ((cur_overlay=cur_overlay->next));
	return 0;
	return 0;
}
}
int quse_main(int argc, char **argv)
int quse_main(int argc, char **argv)
{
{
	FILE *fp;
	FILE *fp;
	char *p;
	char *p, *str;
	short myerror = 0, repo = 0;
	char repo_search[64];
	char overlay_name[64];
	char buf0[_Q_PATH_MAX];
	char buf0[_Q_PATH_MAX];
	char buf1[_Q_PATH_MAX];
	char buf1[_Q_PATH_MAX];
 Lines 218-223   int quse_main(int argc, char **argv) Link Here 
	short quse_all = 0;
	short quse_all = 0;
	int regexp_matching = 1, i, idx = 0;
	int regexp_matching = 1, i, idx = 0;
	size_t search_len;
	size_t search_len;
	overlay_t *cur_overlay, *overlay_tmp;
	cur_overlay = overlay_gentoo;
	overlay_name[0] = 0;
	repo_search[0] = 0;
	DBG("argc=%d argv[0]=%s argv[1]=%s",
	DBG("argc=%d argv[0]=%s argv[1]=%s",
	    argc, argv[0], argc > 1 ? argv[1] : "NULL?");
	    argc, argv[0], argc > 1 ? argv[1] : "NULL?");
 Lines 226-231   int quse_main(int argc, char **argv) Link Here 
		switch (i) {
		switch (i) {
		case 'e': regexp_matching = 0; break;
		case 'e': regexp_matching = 0; break;
		case 'a': quse_all = 1; break;
		case 'a': quse_all = 1; break;
		case 'o':
			repo = 1;
			strncpy(repo_search, optarg, sizeof(repo_search));
			break;
		case 'K': idx = 1; break;
		case 'K': idx = 1; break;
		case 'L': idx = 2; break;
		case 'L': idx = 2; break;
		case 'D': idx = -1; break;
		case 'D': idx = -1; break;
 Lines 234-244   int quse_main(int argc, char **argv) Link Here 
		COMMON_GETOPTS_CASES(quse)
		COMMON_GETOPTS_CASES(quse)
		}
		}
	}
	}
	if (argc == optind && !quse_all && idx >= 0)
	if (repo) {
		do {
			if (!strncmp(cur_overlay->name, repo_search, sizeof(cur_overlay->name)))
				break;
		} while ((cur_overlay=cur_overlay->next));
		if (NULL == cur_overlay)
			err("%s : Unknown overlay, try 'q --ls-overlays'", repo_search);
	}
	if (argc == optind && !quse_all && idx >= 0) {
		if (idx == 3)
			free(search_vars[idx]);
		quse_usage(EXIT_FAILURE);
		quse_usage(EXIT_FAILURE);
	}
	if (idx == -1)
	if (idx == -1)
		return quse_describe_flag(optind, argc, argv);
		return quse_describe_flag(optind, repo, repo_search, argc, argv);
	if (quse_all) optind = argc;
	if (quse_all) optind = argc;
	initialize_ebuild_flat();	/* sets our pwd to $PORTDIR */
	initialize_ebuild_flat();	/* sets our pwd to $PORTDIR */
 Lines 250-255   int quse_main(int argc, char **argv) Link Here 
		return 1;
		return 1;
	while ((fgets(ebuild, sizeof(ebuild), fp)) != NULL) {
	while ((fgets(ebuild, sizeof(ebuild), fp)) != NULL) {
		FILE *newfp;
		FILE *newfp;
		if ((p = strchr(ebuild, ':')))
		{
			*p = 0;
			str = p+2;			/* separator is '::' */
			p = ebuild;
			if (repo && strncmp(repo_search, p, sizeof(repo_search)))
				continue;
			if (strncmp(overlay_name, p, sizeof(overlay_name))) {
				overlay_tmp=overlay_gentoo;
				do {
					if (!strncmp(overlay_tmp->name, p, sizeof(overlay_tmp->name)))
						break;
				} while ((overlay_tmp=overlay_tmp->next));
				if (overlay_tmp)
				{
					cur_overlay = overlay_tmp;
					if (chdir(cur_overlay->path) != 0) {
						warnp("chdir to PORTDIR '%s' failed", cur_overlay->path);
						myerror=1;
					}
				} else
					myerror=1;
				strncpy(overlay_name, cur_overlay->name, sizeof(overlay_name));
			}
			strcpy(ebuild, str);
		} else
			myerror=1;
		if (myerror) {
			if (!reinitialize)
				warnf("(cache update pending) %s : Unknown overlay", overlay_name);
			reinitialize = 1;
			myerror=0;
			continue;
		}
		if ((p = strchr(ebuild, '\n')) != NULL)
		if ((p = strchr(ebuild, '\n')) != NULL)
			*p = 0;
			*p = 0;
		if ((newfp = fopen(ebuild, "r")) != NULL) {
		if ((newfp = fopen(ebuild, "r")) != NULL) {
 Lines 375-381   int quse_main(int argc, char **argv) Link Here 
					if (verbose > 3)
					if (verbose > 3)
						printf("%s %s %s ", *user ? user : "MISSING", *revision ? revision : "MISSING", *date ? date : "MISSING");
						printf("%s %s %s ", *user ? user : "MISSING", *revision ? revision : "MISSING", *date ? date : "MISSING");
					printf("%s%s%s ", CYAN, ebuild, NORM);
					printf("%s%s::%s%s ", CYAN, cur_overlay->name, ebuild, NORM);
					print_highlighted_use_flags(&buf0[search_len+1], optind, argc, argv);
					print_highlighted_use_flags(&buf0[search_len+1], optind, argc, argv);
					puts(NORM);
					puts(NORM);
					if (verbose > 1) {
					if (verbose > 1) {
 Lines 383-389   int quse_main(int argc, char **argv) Link Here 
						int ARGC = 0;
						int ARGC = 0;
						makeargv(&buf0[search_len+1], &ARGC, &ARGV);
						makeargv(&buf0[search_len+1], &ARGC, &ARGV);
						if (ARGC > 0) {
						if (ARGC > 0) {
							quse_describe_flag(1, ARGC, ARGV);
							quse_describe_flag(1, repo, repo_search, ARGC, ARGV);
							for (i = 0; i < ARGC; i++)
							for (i = 0; i < ARGC; i++)
								free(ARGV[i]);
								free(ARGV[i]);
							free(ARGV);
							free(ARGV);
 Lines 400-405   int quse_main(int argc, char **argv) Link Here 
		}
		}
	}
	}
	fclose(fp);
	fclose(fp);
	if (idx == 3)
		free(search_vars[idx]);
	return EXIT_SUCCESS;
	return EXIT_SUCCESS;
}
}
(-) portage-utils-20061116/tests/install/dotest (-1 / +1 lines)
 Lines 7-13   die() { Link Here 
cp ../../q .
cp ../../q .
./q -i || die "./q -i"
./q -i || die "./q -i"
for app in $(./q -Ch | grep ' : ' | awk '{print $1}') ; do
for app in $(./q -Ch | grep -v 'Usage' | grep ' : ' | awk '{print $1}') ; do
	[ ! -e $app ] && die "$app does not exist"
	[ ! -e $app ] && die "$app does not exist"
done
done
echo "PASSED"
echo "PASSED"