Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 154405 | Differences between
and this patch

Collapse All | Expand All

(-)portage-utils-20061111/main.c (-52 / +155 lines)
Lines 71-76 int rematch(const char *, const char *, Link Here
71
static char *rmspace(char *);
71
static char *rmspace(char *);
72
72
73
void initialize_portage_env(void);
73
void initialize_portage_env(void);
74
void initialize_overlays (char portdir_overlay[]);
74
void initialize_ebuild_flat(void);
75
void initialize_ebuild_flat(void);
75
void reinitialize_ebuild_flat(void);
76
void reinitialize_ebuild_flat(void);
76
void reinitialize_as_needed(void);
77
void reinitialize_as_needed(void);
Lines 85-97 static int quiet = 0; Link Here
85
static char pretend = 0;
86
static char pretend = 0;
86
static char reinitialize = 0;
87
static char reinitialize = 0;
87
static char reinitialize_metacache = 0;
88
static char reinitialize_metacache = 0;
88
static char portdir[_Q_PATH_MAX] = "/usr/portage";
89
static char portarch[20] = "";
89
static char portarch[20] = "";
90
static char portvdb[] = "var/db/pkg";
90
static char portvdb[] = "var/db/pkg";
91
static char portcachedir[] = "metadata/cache";
91
static char portcachedir[] = "metadata/cache";
92
static char portroot[_Q_PATH_MAX] = "/";
92
static char portroot[_Q_PATH_MAX] = "/";
93
static char config_protect[_Q_PATH_MAX] = "/etc/";
93
static char config_protect[_Q_PATH_MAX] = "/etc/";
94
94
95
typedef struct overlay_t overlay_t;
96
struct overlay_t {
97
	char name[64];
98
	char path[_Q_PATH_MAX];
99
	struct overlay_t *next;
100
};
101
102
static overlay_t *overlay_gentoo = NULL;
103
95
char pkgdir[512] = "/usr/portage/packages/";
104
char pkgdir[512] = "/usr/portage/packages/";
96
char port_tmpdir[512] = "/var/tmp/portage/";
105
char port_tmpdir[512] = "/var/tmp/portage/";
97
106
Lines 201-210 static void usage(int status, const char Link Here
201
	for (i = 0; opts[i].name; ++i) {
210
	for (i = 0; opts[i].name; ++i) {
202
		assert(help[i] != NULL); /* this assert is a life saver when adding new applets. */
211
		assert(help[i] != NULL); /* this assert is a life saver when adding new applets. */
203
		if (opts[i].has_arg == no_argument)
212
		if (opts[i].has_arg == no_argument)
204
			printf("  -%c, --%-15s%s*%s %s\n", opts[i].val,
213
			printf("  -%c, --%-16s%s*%s %s\n", opts[i].val,
205
				opts[i].name, RED, NORM, _(help[i]));
214
				opts[i].name, RED, NORM, _(help[i]));
206
		else
215
		else
207
			printf("  -%c, --%-8s %s<arg>%s %s*%s %s\n", opts[i].val,
216
			printf("  -%c, --%-9s %s<arg>%s %s*%s %s\n", opts[i].val,
208
				opts[i].name, DKBLUE, NORM, RED, NORM, _(help[i]));
217
				opts[i].name, DKBLUE, NORM, RED, NORM, _(help[i]));
209
	}
218
	}
210
	exit(status);
219
	exit(status);
Lines 469-485 char *strincr_var(const char *name, char Link Here
469
	return (char *) value;
478
	return (char *) value;
470
}
479
}
471
480
481
void initialize_overlays (char portdir_overlay[])
482
{
483
	short merror = 0;
484
	char buf[BUFSIZE], file[_Q_PATH_MAX], *s, *p, *t;
485
	overlay_t *cur_overlay;
486
	FILE *repo_nameFP;
487
	s = portdir_overlay;
488
	cur_overlay = overlay_gentoo;
489
490
	while (*s) {
491
		cur_overlay->next = xmalloc (sizeof (*cur_overlay->next));
492
		cur_overlay = cur_overlay->next;
493
		cur_overlay->next = NULL;
494
495
		if ((p=strchr(s,' ')))
496
			*p = 0;
497
498
		snprintf(cur_overlay->path, sizeof(cur_overlay->path), "%s%s", portroot, s);
499
500
		/* find the name for the overlay */
501
		strncpy(file, cur_overlay->path, _Q_PATH_MAX);
502
		strncat(file, "/profiles/repo_name", _Q_PATH_MAX);
503
		if ((repo_nameFP = fopen(file, "r")))
504
		{
505
			if (!(fgets(buf, sizeof(buf),repo_nameFP)))
506
				merror++;
507
508
			rmspace(buf);
509
			if ((t = strchr(buf,'\n')))
510
				*t = 0;
511
512
			strncpy(cur_overlay->name, buf, sizeof(cur_overlay->name));
513
514
			fclose(repo_nameFP);
515
516
		} else
517
			merror++;
518
519
		if (merror) {
520
			/* delete trailing '/' */
521
			t = cur_overlay->path + strlen(cur_overlay->path) - 1;
522
			if (*t == '/')
523
				*t = 0;
524
525
			strncpy(cur_overlay->name, basename(cur_overlay->path), sizeof(cur_overlay->name));
526
			merror=0;
527
		}
528
529
		if (p)
530
			s = p+1;
531
		else
532
			break;
533
	}
534
535
}
536
537
472
void initialize_portage_env(void)
538
void initialize_portage_env(void)
473
{
539
{
474
	char nocolor = 0;
540
	char nocolor = 0;
475
	int i, f;
541
	int i, f;
476
	struct stat st;
542
	struct stat st;
477
	FILE *fp;
543
	FILE *fp;
544
	char tmp_portdir[_Q_PATH_MAX];
545
	char portdir_overlay[2048] = "";
546
478
	char buf[BUFSIZE], *s, *p;
547
	char buf[BUFSIZE], *s, *p;
479
548
480
	char profile[_Q_PATH_MAX], portage_file[_Q_PATH_MAX];
549
	char profile[_Q_PATH_MAX], portage_file[_Q_PATH_MAX];
550
481
	const char *files[] = {portage_file, "/etc/make.globals", "/etc/make.conf"};
551
	const char *files[] = {portage_file, "/etc/make.globals", "/etc/make.conf"};
482
	typedef enum { _Q_BOOL, _Q_STR, _Q_ISTR } var_types;
552
	typedef enum { _Q_BOOL, _Q_STR, _Q_ISTR } var_types;
553
483
	struct {
554
	struct {
484
		const char *name;
555
		const char *name;
485
		const size_t name_len;
556
		const size_t name_len;
Lines 493-505 void initialize_portage_env(void) Link Here
493
		{"CONFIG_PROTECT",   14, _Q_STR,  config_protect, sizeof(config_protect)},
564
		{"CONFIG_PROTECT",   14, _Q_STR,  config_protect, sizeof(config_protect)},
494
		{"NOCOLOR",           7, _Q_BOOL, &nocolor,       1},
565
		{"NOCOLOR",           7, _Q_BOOL, &nocolor,       1},
495
		{"FEATURES",          8, _Q_ISTR, features,       sizeof(features)},
566
		{"FEATURES",          8, _Q_ISTR, features,       sizeof(features)},
496
		{"PORTDIR",           7, _Q_STR,  portdir,        sizeof(portdir)},
567
		{"PORTDIR",           7, _Q_STR,  tmp_portdir,    sizeof(tmp_portdir)},
568
		{"PORTDIR_OVERLAY",  15, _Q_ISTR, portdir_overlay,sizeof(portdir_overlay)},
497
		{"PORTAGE_BINHOST",  15, _Q_STR,  binhost,        sizeof(binhost)},
569
		{"PORTAGE_BINHOST",  15, _Q_STR,  binhost,        sizeof(binhost)},
498
		{"PORTAGE_TMPDIR",   14, _Q_STR,  port_tmpdir,    sizeof(port_tmpdir)},
570
		{"PORTAGE_TMPDIR",   14, _Q_STR,  port_tmpdir,    sizeof(port_tmpdir)},
499
		{"PKGDIR",            6, _Q_STR,  pkgdir,         sizeof(pkgdir)},
571
		{"PKGDIR",            6, _Q_STR,  pkgdir,         sizeof(pkgdir)},
500
		{"ROOT",              4, _Q_STR,  portroot,       sizeof(portroot)}
572
		{"ROOT",              4, _Q_STR,  portroot,       sizeof(portroot)}
501
	};
573
	};
502
574
575
	overlay_gentoo = xmalloc(sizeof(*overlay_gentoo));
576
	strcpy(overlay_gentoo->name,"gentoo");
577
	strncpy(tmp_portdir, "/usr/portage", sizeof(tmp_portdir));
578
	overlay_gentoo->next = NULL;
579
503
	if ((p = strchr(portroot, '/')) != NULL)
580
	if ((p = strchr(portroot, '/')) != NULL)
504
		if (strlen(p) != 1)
581
		if (strlen(p) != 1)
505
			strncat(portroot, "/", sizeof(portroot));
582
			strncat(portroot, "/", sizeof(portroot));
Lines 591-596 void initialize_portage_env(void) Link Here
591
		no_colors();
668
		no_colors();
592
	else
669
	else
593
		color_remap();
670
		color_remap();
671
672
673
	snprintf(overlay_gentoo->path, sizeof(overlay_gentoo->path),"%s%s", portroot, tmp_portdir);
674
675
	/* now we initiliase the overlay chained list with overlay_gentoo as the first 'item'  */
676
	initialize_overlays(portdir_overlay);
677
594
}
678
}
595
679
596
enum {
680
enum {
Lines 619-637 const char *initialize_flat(int cache_ty Link Here
619
	int a, b, c, d, e, i;
703
	int a, b, c, d, e, i;
620
	int frac, secs, count;
704
	int frac, secs, count;
621
	FILE *fp;
705
	FILE *fp;
706
	overlay_t *cur_overlay;
622
707
623
	a = b = c = d = e = i = 0;
708
	a = b = c = d = e = i = 0;
624
	count = frac = secs = 0;
709
	count = frac = secs = 0;
710
	cur_overlay = overlay_gentoo;
625
711
626
	cache_file = (cache_type == CACHE_EBUILD ? CACHE_EBUILD_FILE : CACHE_METADATA_FILE);
712
	cache_file = (cache_type == CACHE_EBUILD ? CACHE_EBUILD_FILE : CACHE_METADATA_FILE);
627
713
628
	if (chdir(portdir) != 0) {
714
	if (chdir(overlay_gentoo->path) != 0) {
629
		warnp("chdir to PORTDIR '%s' failed", portdir);
715
		warnp("chdir to PORTDIR '%s' failed", overlay_gentoo->path);
630
		goto ret;
716
		goto ret;
631
	}
717
	}
632
718
633
	if (cache_type == CACHE_METADATA && chdir(portcachedir) != 0) {
719
	if (cache_type == CACHE_METADATA && chdir(portcachedir) != 0) {
634
		warnp("chdir to portage cache '%s/%s' failed", portdir, portcachedir);
720
		warnp("chdir to portage cache '%s/%s' failed", overlay_gentoo->path, portcachedir);
635
		goto ret;
721
		goto ret;
636
	}
722
	}
637
723
Lines 647-710 const char *initialize_flat(int cache_ty Link Here
647
733
648
	unlink(cache_file);
734
	unlink(cache_file);
649
	if (errno != ENOENT) {
735
	if (errno != ENOENT) {
650
		warnfp("unlinking '%s/%s' failed", portdir, cache_file);
736
		warnfp("unlinking '%s/%s' failed", overlay_gentoo->path, cache_file);
651
		goto ret;
737
		goto ret;
652
	}
738
	}
653
739
654
	if ((fp = fopen(cache_file, "w")) == NULL) {
740
	if ((fp = fopen(cache_file, "w")) == NULL) {
655
		warnfp("opening '%s/%s' failed", portdir, cache_file);
741
		warnfp("opening '%s/%s' failed", overlay_gentoo->path, cache_file);
656
		goto ret;
742
		goto ret;
657
	}
743
	}
658
744
659
	gettimeofday(&start, NULL);
745
	gettimeofday(&start, NULL);
660
746
661
	if ((a = scandir(".", &category, filter_hidden, alphasort)) < 0)
747
	do {
662
		goto ret;
748
		if (cur_overlay == overlay_gentoo || chdir(cur_overlay->path) == 0) {
663
749
			if ((a = scandir(".", &category, filter_hidden, alphasort)) < 0)
664
	for (i = 0; i < a; i++) {
665
		stat(category[i]->d_name, &st);
666
		if (!S_ISDIR(st.st_mode))
667
			continue;
668
		if (strchr(category[i]->d_name, '-') == NULL)
669
			if ((strncmp(category[i]->d_name, "virtual", 7)) != 0)
670
				continue;
750
				continue;
671
751
672
		if ((b = scandir(category[i]->d_name, &pn, filter_hidden, alphasort)) < 0)
752
			for (i = 0; i < a; i++) {
673
			continue;
753
				stat(category[i]->d_name, &st);
674
		for (c = 0; c < b; c++) {
754
				if (!S_ISDIR(st.st_mode))
675
			char de[_Q_PATH_MAX];
755
					continue;
756
				if (strchr(category[i]->d_name, '-') == NULL)
757
					if ((strncmp(category[i]->d_name, "virtual", 7)) != 0)
758
						continue;
676
759
677
			snprintf(de, sizeof(de), "%s/%s", category[i]->d_name, pn[c]->d_name);
760
				if ((b = scandir(category[i]->d_name, &pn, filter_hidden, alphasort)) < 0)
761
					continue;
762
				for (c = 0; c < b; c++) {
763
					char de[_Q_PATH_MAX];
678
764
679
			if (stat(de, &st) < 0)
765
					snprintf(de, sizeof(de), "%s/%s", category[i]->d_name, pn[c]->d_name);
680
				continue;
681
766
682
			switch (cache_type) {
767
					if (stat(de, &st) < 0)
683
			case CACHE_EBUILD:
768
						continue;
684
				if (!S_ISDIR(st.st_mode))
769
685
					continue;
770
					switch (cache_type) {
686
				break;
771
					case CACHE_EBUILD:
687
			case CACHE_METADATA:
772
						if (!S_ISDIR(st.st_mode))
688
				if (S_ISREG(st.st_mode))
773
							continue;
689
					fprintf(fp, "%s\n", de);
774
						break;
690
				continue;
775
					case CACHE_METADATA:
691
				break;
776
						if (S_ISREG(st.st_mode))
692
			}
777
							fprintf(fp, "%s\n", de);
693
			if ((e = scandir(de, &eb, filter_hidden, alphasort)) < 0)
778
						continue;
694
				continue;
779
						break;
695
			for (d = 0; d < e; d++) {
780
					}
696
				if ((p = strrchr(eb[d]->d_name, '.')) != NULL)
781
					if ((e = scandir(de, &eb, filter_hidden, alphasort)) < 0)
697
					if (strcmp(p, ".ebuild") == 0) {
782
						continue;
698
						count++;
783
					for (d = 0; d < e; d++) {
699
						fprintf(fp, "%s/%s/%s\n", category[i]->d_name, pn[c]->d_name, eb[d]->d_name);
784
						if ((p = strrchr(eb[d]->d_name, '.')) != NULL)
785
							if (strcmp(p, ".ebuild") == 0) {
786
								count++;
787
								fprintf(fp, "%s::%s/%s/%s\n", cur_overlay->name, category[i]->d_name, pn[c]->d_name, eb[d]->d_name);
788
							}
700
					}
789
					}
790
					while (d--) free(eb[d]);
791
					free(eb);
792
				}
793
				while (b--) free(pn[b]);
794
				free(pn);
701
			}
795
			}
702
			while (d--) free(eb[d]);
796
		} else
703
			free(eb);
797
			warnp("chdir to '%s' failed, skipping the %s repository", cur_overlay->path, cur_overlay->name);
704
		}
798
705
		while (b--) free(pn[b]);
799
	} while ((cur_overlay = cur_overlay->next));
706
		free(pn);
800
707
	}
708
	fclose(fp);
801
	fclose(fp);
709
	while (a--) free(category[a]);
802
	while (a--) free(category[a]);
710
	free(category);
803
	free(category);
Lines 723-729 const char *initialize_flat(int cache_ty Link Here
723
816
724
	warn("Finished %u entries in %d.%06d seconds", count, secs, frac);
817
	warn("Finished %u entries in %d.%06d seconds", count, secs, frac);
725
	if (secs > 100)
818
	if (secs > 100)
726
		warn("You should consider a faster file system such as reiserfs for PORTDIR='%s'", portdir);
819
		warn("You should consider a faster file system such as reiserfs for PORTDIR='%s'", overlay_gentoo->path);
727
ret:
820
ret:
728
	return cache_file;
821
	return cache_file;
729
}
822
}
Lines 732-739 ret: Link Here
732
825
733
void reinitialize_ebuild_flat(void)
826
void reinitialize_ebuild_flat(void)
734
{
827
{
735
	if ((chdir(portdir)) != 0) {
828
	if ((chdir(overlay_gentoo->path)) != 0) {
736
		warnp("chdir to PORTDIR '%s' failed", portdir);
829
		warnp("chdir to PORTDIR '%s' failed", overlay_gentoo->path);
737
		return;
830
		return;
738
	}
831
	}
739
	unlink(CACHE_EBUILD_FILE);
832
	unlink(CACHE_EBUILD_FILE);
Lines 1006-1015 fuckit: Link Here
1006
	return cpf;
1099
	return cpf;
1007
}
1100
}
1008
1101
1102
/* free overlays */
1103
void free_overlays(overlay_t *overlay);
1104
void free_overlays(overlay_t *overlay)
1105
{
1106
	if (overlay->next)
1107
		free_overlays(overlay->next);
1108
	free(overlay);
1109
}
1110
1009
void cleanup()
1111
void cleanup()
1010
{
1112
{
1011
	reinitialize_as_needed();
1113
	reinitialize_as_needed();
1012
	free_sets(virtuals);
1114
	free_sets(virtuals);
1115
	free_overlays(overlay_gentoo);
1013
	fclose(stderr);
1116
	fclose(stderr);
1014
}
1117
}
1015
1118
(-)portage-utils-20061111/q.c (-1 / +13 lines)
Lines 7-21 Link Here
7
 * Copyright 2005-2006 Mike Frysinger  - <vapier@gentoo.org>
7
 * Copyright 2005-2006 Mike Frysinger  - <vapier@gentoo.org>
8
 */
8
 */
9
9
10
#define Q_FLAGS "irm" COMMON_FLAGS
10
#define Q_FLAGS "ilrm" COMMON_FLAGS
11
static struct option const q_long_opts[] = {
11
static struct option const q_long_opts[] = {
12
	{"install",      no_argument, NULL, 'i'},
12
	{"install",      no_argument, NULL, 'i'},
13
	{"ls-overlays",  no_argument, NULL, 'l'},
13
	{"reinitialize", no_argument, NULL, 'r'},
14
	{"reinitialize", no_argument, NULL, 'r'},
14
	{"metacache",    no_argument, NULL, 'm'},
15
	{"metacache",    no_argument, NULL, 'm'},
15
	COMMON_LONG_OPTS
16
	COMMON_LONG_OPTS
16
};
17
};
17
static const char *q_opts_help[] = {
18
static const char *q_opts_help[] = {
18
	"Install symlinks for applets",
19
	"Install symlinks for applets",
20
	"List configured overlays",
19
	"Reinitialize ebuild cache",
21
	"Reinitialize ebuild cache",
20
	"Reinitialize metadata cache",
22
	"Reinitialize metadata cache",
21
	COMMON_OPTS_HELP
23
	COMMON_OPTS_HELP
Lines 70-75 int q_main(int argc, char **argv) Link Here
70
	int i;
72
	int i;
71
	char *p;
73
	char *p;
72
	APPLET func;
74
	APPLET func;
75
	overlay_t * cur_overlay;
73
76
74
	if (argc == 0)
77
	if (argc == 0)
75
		return 1;
78
		return 1;
Lines 89-94 int q_main(int argc, char **argv) Link Here
89
		COMMON_GETOPTS_CASES(q)
92
		COMMON_GETOPTS_CASES(q)
90
		case 'm': reinitialize_metacache = 1; break;
93
		case 'm': reinitialize_metacache = 1; break;
91
		case 'r': reinitialize = 1; break;
94
		case 'r': reinitialize = 1; break;
95
		case 'l': {
96
			printf("\n%sOverlay(s) :%s\n\n", GREEN, NORM);
97
			cur_overlay=overlay_gentoo;
98
			do {
99
				printf("   Name : %s%-20.20s%s \tlocation : %s%s%s\n", CYAN, cur_overlay->name, NORM, CYAN, cur_overlay->path, NORM);
100
			} while ((cur_overlay=cur_overlay->next));
101
			fputc('\n', stdout);
102
			return 0;
103
			}
92
		case 'i': {
104
		case 'i': {
93
			char buf[_Q_PATH_MAX];
105
			char buf[_Q_PATH_MAX];
94
			/* always bzero a buffer before using readlink() */
106
			/* always bzero a buffer before using readlink() */
(-)portage-utils-20061111/qcache.c (-10 / +10 lines)
Lines 512-521 int qcache_traverse(void (*func)(qcache_ Link Here
512
	int i, j, k, len, num_cat, num_pkg, num_ebuild;
512
	int i, j, k, len, num_cat, num_pkg, num_ebuild;
513
	struct direct **categories, **packages, **ebuilds;
513
	struct direct **categories, **packages, **ebuilds;
514
514
515
	len = sizeof(char) * (strlen(QCACHE_EDB) + strlen(portdir) + 1);
515
	len = sizeof(char) * (strlen(QCACHE_EDB) + strlen(overlay_gentoo->path) + 1);
516
	catpath = xmalloc(len);
516
	catpath = xmalloc(len);
517
	memset(catpath, 0, len);
517
	memset(catpath, 0, len);
518
	snprintf(catpath, len, "%s%s", QCACHE_EDB, portdir);
518
	snprintf(catpath, len, "%s%s", QCACHE_EDB, overlay_gentoo->path);
519
519
520
	if (-1 == (num_cat = scandir(catpath, &categories, qcache_file_select, alphasort))) {
520
	if (-1 == (num_cat = scandir(catpath, &categories, qcache_file_select, alphasort))) {
521
		err("%s %s", catpath, strerror(errno));
521
		err("%s %s", catpath, strerror(errno));
Lines 527-536 int qcache_traverse(void (*func)(qcache_ Link Here
527
527
528
	/* traverse categories */
528
	/* traverse categories */
529
	for (i = 0; i < num_cat; i++) {
529
	for (i = 0; i < num_cat; i++) {
530
		len = sizeof(char) * (strlen(portdir) + strlen("/") + strlen(categories[i]->d_name) + 1);
530
		len = sizeof(char) * (strlen(overlay_gentoo->path) + strlen("/") + strlen(categories[i]->d_name) + 1);
531
		pkgpath = xmalloc(len);
531
		pkgpath = xmalloc(len);
532
		memset(pkgpath, 0, len);
532
		memset(pkgpath, 0, len);
533
		snprintf(pkgpath, len, "%s/%s", portdir, categories[i]->d_name);
533
		snprintf(pkgpath, len, "%s/%s", overlay_gentoo->path, categories[i]->d_name);
534
534
535
		if (-1 == (num_pkg = scandir(pkgpath, &packages, qcache_file_select, alphasort))) {
535
		if (-1 == (num_pkg = scandir(pkgpath, &packages, qcache_file_select, alphasort))) {
536
			warn("%s %s", catpath, strerror(errno));
536
			warn("%s %s", catpath, strerror(errno));
Lines 552-561 int qcache_traverse(void (*func)(qcache_ Link Here
552
552
553
		/* traverse packages */
553
		/* traverse packages */
554
		for (j = 0; j < num_pkg; j++) {
554
		for (j = 0; j < num_pkg; j++) {
555
			len = sizeof(char) * (strlen(portdir) + strlen("/") + strlen(categories[i]->d_name) + strlen("/") + strlen(packages[j]->d_name) + 1);
555
			len = sizeof(char) * (strlen(overlay_gentoo->path) + strlen("/") + strlen(categories[i]->d_name) + strlen("/") + strlen(packages[j]->d_name) + 1);
556
			ebuildpath = xmalloc(len);
556
			ebuildpath = xmalloc(len);
557
			memset(ebuildpath, 0, len);
557
			memset(ebuildpath, 0, len);
558
			snprintf(ebuildpath, len, "%s/%s/%s", portdir, categories[i]->d_name, packages[j]->d_name);
558
			snprintf(ebuildpath, len, "%s/%s/%s", overlay_gentoo->path, categories[i]->d_name, packages[j]->d_name);
559
559
560
			if (-1 == (num_ebuild = scandir(ebuildpath, &ebuilds, qcache_ebuild_select, qcache_vercmp))) {
560
			if (-1 == (num_ebuild = scandir(ebuildpath, &ebuilds, qcache_ebuild_select, qcache_vercmp))) {
561
				warn("%s %s", ebuildpath, strerror(errno));
561
				warn("%s %s", ebuildpath, strerror(errno));
Lines 773-782 void qcache_stats(qcache_data *data) Link Here
773
		for (i = 0; archlist[i]; i++)
773
		for (i = 0; archlist[i]; i++)
774
			architectures++;
774
			architectures++;
775
775
776
		len = sizeof(char) * (strlen(QCACHE_EDB) + strlen(portdir) + 1);
776
		len = sizeof(char) * (strlen(QCACHE_EDB) + strlen(overlay_gentoo->path) + 1);
777
		catpath = xmalloc(len);
777
		catpath = xmalloc(len);
778
		memset(catpath, 0, len);
778
		memset(catpath, 0, len);
779
		snprintf(catpath, len, "%s%s", QCACHE_EDB, portdir);
779
		snprintf(catpath, len, "%s%s", QCACHE_EDB, overlay_gentoo->path);
780
780
781
		if (-1 == (numcat = scandir(catpath, &categories, qcache_file_select, alphasort))) {
781
		if (-1 == (numcat = scandir(catpath, &categories, qcache_file_select, alphasort))) {
782
			err("%s %s", catpath, strerror(errno));
782
			err("%s %s", catpath, strerror(errno));
Lines 928-938 int qcache_init() Link Here
928
	char *filename;
928
	char *filename;
929
	unsigned int len;
929
	unsigned int len;
930
930
931
	len      = sizeof(char) * (strlen(portdir) + strlen("/profiles/arch.list") + 1);
931
	len      = sizeof(char) * (strlen(overlay_gentoo->path) + strlen("/profiles/arch.list") + 1);
932
	filename = xmalloc(len);
932
	filename = xmalloc(len);
933
933
934
	memset(filename, 0, len);
934
	memset(filename, 0, len);
935
	snprintf(filename, len, "%s/profiles/arch.list", portdir);
935
	snprintf(filename, len, "%s/profiles/arch.list", overlay_gentoo->path);
936
936
937
	if (NULL == (archlist = qcache_read_lines(filename))) {
937
	if (NULL == (archlist = qcache_read_lines(filename))) {
938
		free(filename);
938
		free(filename);
(-)portage-utils-20061111/qgrep.c (-4 / +63 lines)
Lines 10-20 Link Here
10
10
11
#ifdef APPLET_qgrep
11
#ifdef APPLET_qgrep
12
12
13
#define QGREP_FLAGS "IiHce" COMMON_FLAGS
13
#define QGREP_FLAGS "IiHo:ce" COMMON_FLAGS
14
static struct option const qgrep_long_opts[] = {
14
static struct option const qgrep_long_opts[] = {
15
	{"invert-match",  no_argument, NULL, 'I'},
15
	{"invert-match",  no_argument, NULL, 'I'},
16
	{"ignore-case",   no_argument, NULL, 'i'},
16
	{"ignore-case",   no_argument, NULL, 'i'},
17
	{"with-filename", no_argument, NULL, 'H'},
17
	{"with-filename", no_argument, NULL, 'H'},
18
	{"overlay",        a_argument, NULL, 'o'},
18
	{"count",         no_argument, NULL, 'c'},
19
	{"count",         no_argument, NULL, 'c'},
19
	{"regexp",        no_argument, NULL, 'e'},
20
	{"regexp",        no_argument, NULL, 'e'},
20
	COMMON_LONG_OPTS
21
	COMMON_LONG_OPTS
Lines 23-28 static const char *qgrep_opts_help[] = { Link Here
23
	"Select non-matching lines",
24
	"Select non-matching lines",
24
	"Ignore case distinctions",
25
	"Ignore case distinctions",
25
	"Print the filename for each match",
26
	"Print the filename for each match",
27
	"Only consider the <arg> overlay",
26
	"Only print a count of matching lines per FILE",
28
	"Only print a count of matching lines per FILE",
27
	"Use PATTERN as a regular expression",
29
	"Use PATTERN as a regular expression",
28
	COMMON_OPTS_HELP
30
	COMMON_OPTS_HELP
Lines 34-40 int qgrep_main(int argc, char **argv) Link Here
34
{
36
{
35
	int i;
37
	int i;
36
	int count = 0;
38
	int count = 0;
37
	char *p;
39
	short myerror = 0, repo = 0;
40
	char overlay_name[64], repo_search[64];
41
	char *p, *str;
38
	char do_count, do_regex;
42
	char do_count, do_regex;
39
	char show_filename;
43
	char show_filename;
40
	FILE *fp;
44
	FILE *fp;
Lines 42-51 int qgrep_main(int argc, char **argv) Link Here
42
	char buf0[BUFSIZ];
46
	char buf0[BUFSIZ];
43
	int reflags = REG_NOSUB;
47
	int reflags = REG_NOSUB;
44
	char invert_match = 0;
48
	char invert_match = 0;
49
	overlay_t *cur_overlay, *overlay_tmp;
45
50
46
	typedef char *(*FUNC) (char *, char *);
51
	typedef char *(*FUNC) (char *, char *);
47
	FUNC strfunc = (FUNC) strstr;
52
	FUNC strfunc = (FUNC) strstr;
48
53
54
	cur_overlay = overlay_gentoo;
55
	overlay_name[0] = 0;
56
	repo_search[0] = 0;
57
49
	DBG("argc=%d argv[0]=%s argv[1]=%s",
58
	DBG("argc=%d argv[0]=%s argv[1]=%s",
50
	    argc, argv[0], argc > 1 ? argv[1] : "NULL?");
59
	    argc, argv[0], argc > 1 ? argv[1] : "NULL?");
51
60
Lines 58-69 int qgrep_main(int argc, char **argv) Link Here
58
			strfunc = (FUNC) strcasestr;
67
			strfunc = (FUNC) strcasestr;
59
			reflags |= REG_ICASE;
68
			reflags |= REG_ICASE;
60
			break;
69
			break;
70
		case 'H': show_filename = 1; break;
71
		case 'o':
72
			repo = 1;
73
			strncpy(repo_search, optarg, sizeof(repo_search));
74
			break;
61
		case 'c': do_count = 1; break;
75
		case 'c': do_count = 1; break;
62
		case 'e': do_regex = 1; break;
76
		case 'e': do_regex = 1; break;
63
		case 'H': show_filename = 1; break;
64
		COMMON_GETOPTS_CASES(qgrep)
77
		COMMON_GETOPTS_CASES(qgrep)
65
		}
78
		}
66
	}
79
	}
80
81
	if (repo) {
82
		do {
83
			if (!strncmp(cur_overlay->name, repo_search, sizeof(cur_overlay->name)))
84
				break;
85
		} while ((cur_overlay=cur_overlay->next));
86
		if (NULL == cur_overlay)
87
			err("%s : Unknown overlay, try 'q --ls-overlays'", repo_search);
88
	}
89
67
	if (argc == optind)
90
	if (argc == optind)
68
		qgrep_usage(EXIT_FAILURE);
91
		qgrep_usage(EXIT_FAILURE);
69
92
Lines 73-78 int qgrep_main(int argc, char **argv) Link Here
73
		return 1;
96
		return 1;
74
	while ((fgets(ebuild, sizeof(ebuild), fp)) != NULL) {
97
	while ((fgets(ebuild, sizeof(ebuild), fp)) != NULL) {
75
		FILE *newfp;
98
		FILE *newfp;
99
		if ((p = strchr(ebuild, ':')))
100
		{
101
			*p = 0;
102
			str = p+2;			/* separator is '::' */
103
			p = ebuild;
104
			if (repo && strncmp(repo_search, p, sizeof(repo_search)))
105
				continue;
106
			if (strncmp(overlay_name, p, sizeof(overlay_name))) {
107
				overlay_tmp=overlay_gentoo;
108
				do {
109
					if (!strncmp(overlay_tmp->name, p, sizeof(overlay_tmp->name)))
110
						break;
111
				} while ((overlay_tmp=overlay_tmp->next));
112
				if (overlay_tmp) {
113
					cur_overlay = overlay_tmp;
114
					if (chdir(cur_overlay->path) != 0) {
115
						warnp("chdir to PORTDIR '%s' failed", cur_overlay->path);
116
						myerror=1;
117
					}
118
				} else
119
					myerror=1;
120
121
				strncpy(overlay_name, p, sizeof(overlay_name));
122
			}
123
			strcpy(ebuild, str);
124
		} else
125
			myerror=1;
126
127
		if (myerror) {
128
			if (!reinitialize)
129
				warnf("(cache update pending) %s : Unknown overlay", overlay_name);
130
			reinitialize = 1;
131
			myerror=0;
132
			continue;
133
		}
134
76
		if ((p = strchr(ebuild, '\n')) != NULL)
135
		if ((p = strchr(ebuild, '\n')) != NULL)
77
			*p = 0;
136
			*p = 0;
78
		if ((newfp = fopen(ebuild, "r")) != NULL) {
137
		if ((newfp = fopen(ebuild, "r")) != NULL) {
Lines 102-108 int qgrep_main(int argc, char **argv) Link Here
102
				count++;
161
				count++;
103
				if (do_count) continue;
162
				if (do_count) continue;
104
				if (verbose || show_filename) {
163
				if (verbose || show_filename) {
105
					printf("%s:", ebuild);
164
					printf("%s::%s:", cur_overlay->name, ebuild);
106
					if (verbose > 1) printf("%d:", lineno);
165
					if (verbose > 1) printf("%d:", lineno);
107
					printf(" ");
166
					printf(" ");
108
				}
167
				}
(-)portage-utils-20061111/qsearch.c (-11 / +91 lines)
Lines 9-18 Link Here
9
9
10
#ifdef APPLET_qsearch
10
#ifdef APPLET_qsearch
11
11
12
#define QSEARCH_FLAGS "acsSNH" COMMON_FLAGS
12
#define QSEARCH_FLAGS "aco:psSNH" COMMON_FLAGS
13
static struct option const qsearch_long_opts[] = {
13
static struct option const qsearch_long_opts[] = {
14
	{"all",       no_argument, NULL, 'a'},
14
	{"all",       no_argument, NULL, 'a'},
15
	{"cache",     no_argument, NULL, 'c'},
15
	{"cache",     no_argument, NULL, 'c'},
16
	{"overlay",    a_argument, NULL, 'o'},
17
	{"show-path", no_argument, NULL, 'p'},
16
	{"search",    no_argument, NULL, 's'},
18
	{"search",    no_argument, NULL, 's'},
17
	{"desc",       a_argument, NULL, 'S'},
19
	{"desc",       a_argument, NULL, 'S'},
18
	{"name-only", no_argument, NULL, 'N'},
20
	{"name-only", no_argument, NULL, 'N'},
Lines 22-27 static struct option const qsearch_long_ Link Here
22
static const char *qsearch_opts_help[] = {
24
static const char *qsearch_opts_help[] = {
23
	"List the descriptions of every package in the cache",
25
	"List the descriptions of every package in the cache",
24
	"Use the portage cache",
26
	"Use the portage cache",
27
	"Search only in the <arg> overlay",
28
	"Show the path to the ebuild",
25
	"Regex search package basenames",
29
	"Regex search package basenames",
26
	"Regex search package descriptions",
30
	"Regex search package descriptions",
27
	"Only show package name",
31
	"Only show package name",
Lines 40-52 int qsearch_main(int argc, char **argv) Link Here
40
	char last[126] = "";
44
	char last[126] = "";
41
	char dp[126] = "";
45
	char dp[126] = "";
42
	char bp[126] = "";
46
	char bp[126] = "";
43
	char *p, *q, *str;
47
	short repo = 0;
48
	char repo_search[64];
49
	char *p, *q, *str, overlay_name[64];
44
	char *search_me = NULL;
50
	char *search_me = NULL;
45
	char show_homepage = 0, show_name_only = 0;
51
	char show_homepage = 0, show_name_only = 0, show_path_to_ebuild = 0;
46
	char search_desc = 0, search_all = 0, search_name = 1, search_cache = CACHE_EBUILD;
52
	char search_desc = 0, search_all = 0, search_name = 1, search_cache = CACHE_EBUILD;
47
	const char *search_vars[] = { "DESCRIPTION=", "HOMEPAGE=" };
53
	const char *search_vars[] = { "DESCRIPTION=", "HOMEPAGE=" };
48
	size_t search_len;
54
	size_t search_len;
49
	int i, idx=0;
55
	overlay_t *cur_overlay, *overlay_tmp;
56
	int i, idx=0, myerror=0;
57
58
	cur_overlay = overlay_gentoo;
59
	overlay_name[0] = 0;
60
	repo_search[0] = 0;
50
61
51
	DBG("argc=%d argv[0]=%s argv[1]=%s",
62
	DBG("argc=%d argv[0]=%s argv[1]=%s",
52
	    argc, argv[0], argc > 1 ? argv[1] : "NULL?");
63
	    argc, argv[0], argc > 1 ? argv[1] : "NULL?");
Lines 56-61 int qsearch_main(int argc, char **argv) Link Here
56
		COMMON_GETOPTS_CASES(qsearch)
67
		COMMON_GETOPTS_CASES(qsearch)
57
		case 'a': search_all = 1; break;
68
		case 'a': search_all = 1; break;
58
		case 'c': search_cache = CACHE_METADATA; break;
69
		case 'c': search_cache = CACHE_METADATA; break;
70
		case 'o': repo = 1; strncpy(repo_search, optarg, sizeof(repo_search)); break;
71
		case 'p': show_path_to_ebuild = 1; break;
59
		case 's': search_desc = 0; search_name = 1; break;
72
		case 's': search_desc = 0; search_name = 1; break;
60
		case 'S': search_desc = 1; search_name = 0; break;
73
		case 'S': search_desc = 1; search_name = 0; break;
61
		case 'N': show_name_only = 1; break;
74
		case 'N': show_name_only = 1; break;
Lines 63-68 int qsearch_main(int argc, char **argv) Link Here
63
		}
76
		}
64
	}
77
	}
65
78
79
	if (repo) {
80
		do {
81
			if (! strncmp(cur_overlay->name, repo_search, sizeof(cur_overlay->name)))
82
				break;
83
		} while ((cur_overlay=cur_overlay->next));
84
		if (NULL == cur_overlay)
85
			err("%s : Unknown overlay, try 'q --ls-overlays'", repo_search);
86
	}
87
88
66
	if (search_all) {
89
	if (search_all) {
67
		search_desc = 1;
90
		search_desc = 1;
68
		search_name = 0;
91
		search_name = 0;
Lines 93-103 int qsearch_main(int argc, char **argv) Link Here
93
			if ((pcache = cache_read_file(ebuild)) != NULL) {
116
			if ((pcache = cache_read_file(ebuild)) != NULL) {
94
				if ((strcmp(pcache->atom->PN, last)) != 0) {
117
				if ((strcmp(pcache->atom->PN, last)) != 0) {
95
					strncpy(last, pcache->atom->PN, sizeof(last));
118
					strncpy(last, pcache->atom->PN, sizeof(last));
96
					if ((rematch(search_me, (search_desc ? pcache->DESCRIPTION : ebuild), REG_EXTENDED | REG_ICASE)) == 0)
119
					if ((rematch(search_me, (search_desc ? pcache->DESCRIPTION : ebuild), REG_EXTENDED | REG_ICASE)) == 0) {
97
						printf("%s%s/%s%s%s %s\n", BOLD, pcache->atom->CATEGORY, BLUE,
120
						if (show_path_to_ebuild) {
98
						       pcache->atom->PN, NORM,
121
							printf("%s%s/%s%s%s::%s\t %s%s/%s/\n",
99
						       (show_name_only ? "" :
122
							BOLD, pcache->atom->CATEGORY,
100
						        (show_homepage ? pcache->HOMEPAGE : pcache->DESCRIPTION)));
123
							BLUE, pcache->atom->PN,
124
							YELLOW,cur_overlay->name, NORM,
125
							cur_overlay->path, dirname(ebuild));
126
						} else {
127
							printf("%s%s/%s%s%s::%s %s%s\n",
128
							BOLD, pcache->atom->CATEGORY,
129
							BLUE, pcache->atom->PN,
130
							YELLOW,cur_overlay->name, NORM,
131
							(show_name_only ? "" :
132
							(show_homepage ? pcache->HOMEPAGE : pcache->DESCRIPTION)));
133
						}
134
					}
101
				}
135
				}
102
				cache_free(pcache);
136
				cache_free(pcache);
103
			} else {
137
			} else {
Lines 110-115 int qsearch_main(int argc, char **argv) Link Here
110
144
111
		case CACHE_EBUILD: {
145
		case CACHE_EBUILD: {
112
			FILE *ebuildfp;
146
			FILE *ebuildfp;
147
			if ((p = strchr(ebuild, ':')))
148
			{
149
				*p = 0;
150
				str = p+2;			/* separator is '::' */
151
				p = ebuild;
152
				if (repo && strncmp(repo_search, p, sizeof(repo_search)))
153
					continue;
154
				if (strncmp(overlay_name, p, sizeof(overlay_name))) {
155
					last[0] = 0;
156
					overlay_tmp=overlay_gentoo;
157
					do {
158
						if (!strncmp(overlay_tmp->name, p, sizeof(overlay_tmp->name)))
159
							break;
160
					} while ((overlay_tmp=overlay_tmp->next));
161
162
					if (overlay_tmp) {
163
						cur_overlay = overlay_tmp;
164
						if (chdir(cur_overlay->path) != 0) {
165
							warnp("chdir to '%s' failed", cur_overlay->path);
166
							myerror=1;
167
						}
168
					} else
169
						myerror=1;
170
171
					strncpy(overlay_name, p, sizeof(overlay_name));
172
				}
173
				strcpy(ebuild, str);
174
			} else
175
				myerror=1;
176
177
			if (myerror) {
178
				if (!reinitialize)
179
					warnf("(cache update pending) %s : Unknown overlay", overlay_name);
180
				reinitialize = 1;
181
				myerror=0;
182
				continue;
183
			}
184
113
			str = xstrdup(ebuild);
185
			str = xstrdup(ebuild);
114
			p = (char *) dirname(str);
186
			p = (char *) dirname(str);
115
187
Lines 134-142 int qsearch_main(int argc, char **argv) Link Here
134
							// doing operations with them.
206
							// doing operations with them.
135
							strncpy(dp, p, sizeof(dp));
207
							strncpy(dp, p, sizeof(dp));
136
							strncpy(bp, p, sizeof(bp));
208
							strncpy(bp, p, sizeof(bp));
137
							printf("%s%s/%s%s%s %s\n",
209
							if (show_path_to_ebuild) {
138
								BOLD, dirname(dp), BLUE, basename(bp), NORM,
210
								printf("%s%s/%s%s%s::%s\t %s%s/%s/\n",
211
								BOLD, dirname(dp), BLUE, basename(bp),
212
								YELLOW,cur_overlay->name, NORM,
213
								cur_overlay->path, dirname(ebuild));
214
							} else {
215
								printf("%s%s/%s%s%s::%s %s%s\n",
216
								BOLD, dirname(dp), BLUE, basename(bp),
217
								YELLOW,cur_overlay->name, NORM,
139
								(show_name_only ? "" : q));
218
								(show_name_only ? "" : q));
219
							}
140
							break;
220
							break;
141
						}
221
						}
142
					}
222
					}
(-)portage-utils-20061111/quse.c (-86 / +188 lines)
Lines 14-23 Link Here
14
 quse -Ke --  nls
14
 quse -Ke --  nls
15
*/
15
*/
16
16
17
#define QUSE_FLAGS "eavKLDF:N" COMMON_FLAGS
17
#define QUSE_FLAGS "eao:vKLDF:N" COMMON_FLAGS
18
static struct option const quse_long_opts[] = {
18
static struct option const quse_long_opts[] = {
19
	{"exact",     no_argument, NULL, 'e'},
19
	{"exact",     no_argument, NULL, 'e'},
20
	{"all",       no_argument, NULL, 'a'},
20
	{"all",       no_argument, NULL, 'a'},
21
	{"overlay",    a_argument, NULL, 'o'},
21
	{"keywords",  no_argument, NULL, 'K'},
22
	{"keywords",  no_argument, NULL, 'K'},
22
	{"license",   no_argument, NULL, 'L'},
23
	{"license",   no_argument, NULL, 'L'},
23
	{"describe",  no_argument, NULL, 'D'},
24
	{"describe",  no_argument, NULL, 'D'},
Lines 28-33 static struct option const quse_long_opt Link Here
28
static const char *quse_opts_help[] = {
29
static const char *quse_opts_help[] = {
29
	"Show exact non regexp matching using strcmp",
30
	"Show exact non regexp matching using strcmp",
30
	"Show annoying things in IUSE",
31
	"Show annoying things in IUSE",
32
	"Only consider the <arg> overlay",
31
	"Use the KEYWORDS vs IUSE",
33
	"Use the KEYWORDS vs IUSE",
32
	"Use the LICENSE vs IUSE",
34
	"Use the LICENSE vs IUSE",
33
	"Describe the USE flag",
35
	"Describe the USE flag",
Lines 38-44 static const char *quse_opts_help[] = { Link Here
38
static const char quse_rcsid[] = "$Id: quse.c,v 1.53 2006/11/09 00:18:05 vapier Exp $";
40
static const char quse_rcsid[] = "$Id: quse.c,v 1.53 2006/11/09 00:18:05 vapier Exp $";
39
#define quse_usage(ret) usage(ret, QUSE_FLAGS, quse_long_opts, quse_opts_help, lookup_applet_idx("quse"))
41
#define quse_usage(ret) usage(ret, QUSE_FLAGS, quse_long_opts, quse_opts_help, lookup_applet_idx("quse"))
40
42
41
int quse_describe_flag(int ind, int argc, char **argv);
43
int quse_describe_flag(int ind, short repo, char repo_search[], int argc, char **argv);
42
44
43
char quse_name_only = 0;
45
char quse_name_only = 0;
44
46
Lines 81-87 static void print_highlighted_use_flags( Link Here
81
	}
83
	}
82
}
84
}
83
85
84
int quse_describe_flag(int ind, int argc, char **argv)
86
int quse_describe_flag(int ind, short repo, char repo_search[], int argc, char **argv)
85
{
87
{
86
#define NUM_SEARCH_FILES ARR_SIZE(search_files)
88
#define NUM_SEARCH_FILES ARR_SIZE(search_files)
87
	char buf[BUFSIZE], *p;
89
	char buf[BUFSIZE], *p;
Lines 91-211 int quse_describe_flag(int ind, int argc Link Here
91
	FILE *fp[NUM_SEARCH_FILES];
93
	FILE *fp[NUM_SEARCH_FILES];
92
	DIR *d;
94
	DIR *d;
93
	struct dirent *de;
95
	struct dirent *de;
96
	overlay_t *cur_overlay;
94
97
95
	for (i = 0; i < NUM_SEARCH_FILES; ++i) {
98
	cur_overlay=overlay_gentoo;
96
		snprintf(buf, sizeof(buf), "%s/profiles/%s", portdir, search_files[i]);
97
		if ((fp[i] = fopen(buf, "r")) == NULL)
98
			warnp("skipping %s", search_files[i]);
99
	}
100
99
101
	for (i = ind; i < argc; i++) {
100
	do {
102
		s = strlen(argv[i]);
101
		if (repo && strncmp(repo_search, cur_overlay->name, sizeof(repo_search)))
102
			continue;
103
		for (i = 0; i < NUM_SEARCH_FILES; ++i) {
104
			snprintf(buf, sizeof(buf), "%s/profiles/%s", cur_overlay->path, search_files[i]);
105
			if ((fp[i] = fopen(buf, "r")) == NULL)
106
				if (verbose )
107
					warnp("skipping %s for the %s overlay", search_files[i], cur_overlay->name);
108
		}
103
109
104
		for (f = 0; f < NUM_SEARCH_FILES; ++f) {
110
		for (i = ind; i < argc; i++) {
105
			if (fp[f] == NULL)
111
			s = strlen(argv[i]);
106
				continue;
107
112
108
			while (fgets(buf, sizeof(buf), fp[f]) != NULL) {
113
			for (f = 0; f < NUM_SEARCH_FILES; ++f) {
109
				if (buf[0] == '#' || buf[0] == '\n')
114
				if (fp[f] == NULL)
110
					continue;
115
					continue;
111
116
112
				if ((p = strrchr(buf, '\n')) != NULL)
117
				while (fgets(buf, sizeof(buf), fp[f]) != NULL) {
113
					*p = '\0';
118
					if (buf[0] == '#' || buf[0] == '\n')
119
						continue;
114
120
115
				switch (f) {
121
					if ((p = strrchr(buf, '\n')) != NULL)
116
					case 0: /* Global use.desc */
122
						*p = '\0';
117
						if (!strncmp(buf, argv[i], s))
118
							if (buf[s] == ' ' && buf[s+1] == '-') {
119
								printf(" %sglobal%s:%s%s%s: %s\n", BOLD, NORM, BLUE, argv[i], NORM, buf+s+3);
120
								goto skip_file;
121
							}
122
						break;
123
123
124
					case 1: /* Local use.local.desc */
124
					switch (f) {
125
						if ((p = strchr(buf, ':')) == NULL)
125
						case 0: /* Global use.desc */
126
							if (!strncmp(buf, argv[i], s))
127
								if (buf[s] == ' ' && buf[s+1] == '-') {
128
									if (cur_overlay == overlay_gentoo)
129
										printf(" %sglobal%s:%s%s%s: %s\n", BOLD, NORM, BLUE, argv[i], NORM, buf+s+3);
130
									else
131
										printf(" (%s) %sglobal%s:%s%s%s: %s\n", cur_overlay->name, BOLD, NORM, BLUE, argv[i], NORM, buf+s+3);
132
									goto skip_file;
133
								}
126
							break;
134
							break;
127
						++p;
128
						if (!strncmp(p, argv[i], s)) {
129
							if (p[s] == ' ' && p[s+1] == '-') {
130
								*p = '\0';
131
								printf(" %slocal%s:%s%s%s:%s%s%s %s\n", BOLD, NORM, BLUE, argv[i], NORM, BOLD, buf, NORM, p+s+3);
132
							}
133
						}
134
						break;
135
135
136
					case 2: /* Architectures arch.list */
136
						case 1: /* Local use.local.desc */
137
						if (!strcmp(buf, argv[i])) {
137
							if ((p = strchr(buf, ':')) == NULL)
138
							printf(" %sarch%s:%s%s%s: %s architecture\n", BOLD, NORM, BLUE, argv[i], NORM, argv[i]);
138
								break;
139
							goto skip_file;
139
							++p;
140
						}
140
							if (!strncmp(p, argv[i], s)) {
141
						break;
141
								if (p[s] == ' ' && p[s+1] == '-') {
142
									*p = '\0';
143
									if (cur_overlay == overlay_gentoo)
144
										printf(" %slocal%s:%s%s%s:%s%s%s %s\n", BOLD, NORM, BLUE, argv[i], NORM, BOLD, buf, NORM, p+s+3);
145
									else
146
										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);
147
								}
148
							}
149
							break;
142
150
143
					case 3: /* Languages lang.desc */
151
						case 2: /* Architectures arch.list */
144
						if (!strncmp(buf, argv[i], s))
152
							if (!strcmp(buf, argv[i])) {
145
							if (buf[s] == ' ' && buf[s+1] == '-') {
153
								if (cur_overlay == overlay_gentoo)
146
								printf(" %slang%s:%s%s%s: %s lingua\n", BOLD, NORM, BLUE, argv[i], NORM, buf+s+3);
154
									printf(" %sarch%s:%s%s%s: %s architecture\n", BOLD, NORM, BLUE, argv[i], NORM, argv[i]);
155
								else
156
									printf(" (%s) %sarch%s:%s%s%s: %s architecture\n", cur_overlay->name, BOLD, NORM, BLUE, argv[i], NORM, argv[i]);
147
								goto skip_file;
157
								goto skip_file;
148
							}
158
							}
149
						break;
159
							break;
160
161
						case 3: /* Languages lang.desc */
162
							if (!strncmp(buf, argv[i], s))
163
								if (buf[s] == ' ' && buf[s+1] == '-') {
164
									if (cur_overlay == overlay_gentoo)
165
										printf(" %slang%s:%s%s%s: %s lingua\n", BOLD, NORM, BLUE, argv[i], NORM, buf+s+3);
166
									else
167
										printf(" (%s) %slang%s:%s%s%s: %s lingua\n", cur_overlay->name, BOLD, NORM, BLUE, argv[i], NORM, buf+s+3);
168
									goto skip_file;
169
								}
170
							break;
171
					}
150
				}
172
				}
151
			}
152
173
153
skip_file:
174
skip_file:
154
			rewind(fp[f]);
175
				rewind(fp[f]);
176
			}
177
178
			if (i == (argc - 1))
179
				for (f=0; f<NUM_SEARCH_FILES; ++f)
180
					if (fp[f]) {
181
						fclose(fp[f]);
182
						fp[f] = NULL;
183
					}
155
		}
184
		}
156
	}
157
185
158
	for (f=0; f<NUM_SEARCH_FILES; ++f)
186
	} while ((cur_overlay=cur_overlay->next));
159
		fclose(fp[f]);
160
187
161
	/* now scan the desc dir */
188
	/* now scan the desc dir */
162
	snprintf(buf, sizeof(buf), "%s/profiles/desc/", portdir);
189
	cur_overlay=overlay_gentoo;
163
	d = opendir(buf);
190
	do {
164
	while ((de = readdir(d)) != NULL) {
191
		if (repo && strncmp(repo_search, cur_overlay->name, sizeof(repo_search)))
165
		if (strcmp(de->d_name+strlen(de->d_name)-5, ".desc"))
166
			continue;
192
			continue;
167
193
		snprintf(buf, sizeof(buf), "%s/profiles/desc/", cur_overlay->path);
168
		snprintf(buf, sizeof(buf), "%s/profiles/desc/%s", portdir, de->d_name);
194
		if (!(d = opendir(buf))) {
169
		if ((fp[0]=fopen(buf, "r")) == NULL) {
195
			if (verbose)
170
			warn("Could not open '%s' for reading; skipping", de->d_name);
196
				warn("Could not open %s -> skipping", buf);
171
			continue;
197
			continue;
172
		}
198
		}
199
		while ((de = readdir(d)) != NULL) {
200
			if (strcmp(de->d_name+strlen(de->d_name)-5, ".desc"))
201
				continue;
173
202
174
		while (fgets(buf, sizeof(buf), fp[0]) != NULL) {
203
			snprintf(buf, sizeof(buf), "%s/profiles/desc/%s", cur_overlay->path, de->d_name);
175
			if (buf[0] == '#' || buf[0] == '\n')
204
			if ((fp[0]=fopen(buf, "r")) == NULL) {
205
				warn("Could not open '%s' for reading; skipping", de->d_name);
176
				continue;
206
				continue;
207
			}
177
208
178
			if ((p = strrchr(buf, '\n')) != NULL)
209
			while (fgets(buf, sizeof(buf), fp[0]) != NULL) {
179
				*p = '\0';
210
				if (buf[0] == '#' || buf[0] == '\n')
211
					continue;
212
213
				if ((p = strrchr(buf, '\n')) != NULL)
214
					*p = '\0';
180
215
181
			if ((p = strchr(buf, '-')) == NULL) {
216
				if ((p = strchr(buf, '-')) == NULL) {
182
invalid_line:
217
invalid_line:
183
				warn("Invalid line in '%s': %s", de->d_name, buf);
218
					warn("Invalid line in '%s': %s", de->d_name, buf);
184
				continue;
219
					continue;
185
			}
220
				}
186
			while (p[-1] != ' ' && p[1] != ' ') {
221
				while (p[-1] != ' ' && p[1] != ' ') {
187
				/* maybe the flag has a '-' in it ... */
222
					/* maybe the flag has a '-' in it ... */
188
				if ((p = strchr(p+1, '-')) == NULL)
223
					if ((p = strchr(p+1, '-')) == NULL)
189
					goto invalid_line;
224
						goto invalid_line;
190
			}
225
				}
191
			p[-1] = '\0';
226
				p[-1] = '\0';
192
			p += 2;
227
				p += 2;
193
228
194
			for (i = ind; i < argc; i++)
229
				for (i = ind; i < argc; i++)
195
				if (!strcmp(argv[i], buf))
230
					if (!strcmp(argv[i], buf)) {
196
					printf(" %s%s%s:%s%s%s: %s\n", BOLD, de->d_name, NORM, BLUE, argv[i], NORM, p);
231
						if (cur_overlay == overlay_gentoo)
197
		}
232
							printf(" %s%s%s:%s%s%s: %s\n", BOLD, de->d_name, NORM, BLUE, argv[i], NORM, p);
198
		close(f);
233
						else
199
	}
234
							printf(" (%s) %s%s%s:%s%s%s: %s\n", cur_overlay->name, BOLD, de->d_name, NORM, BLUE, argv[i], NORM, p);
200
	closedir(d);
235
					}
201
236
237
			}
238
			fclose(fp[0]);
239
		}
240
		closedir(d);
241
	} while ((cur_overlay=cur_overlay->next));
202
	return 0;
242
	return 0;
203
}
243
}
204
244
205
int quse_main(int argc, char **argv)
245
int quse_main(int argc, char **argv)
206
{
246
{
207
	FILE *fp;
247
	FILE *fp;
208
	char *p;
248
	char *p, *str;
249
	short myerror = 0, repo = 0;
250
	char repo_search[64];
251
	char overlay_name[64];
209
252
210
	char buf0[_Q_PATH_MAX];
253
	char buf0[_Q_PATH_MAX];
211
	char buf1[_Q_PATH_MAX];
254
	char buf1[_Q_PATH_MAX];
Lines 218-223 int quse_main(int argc, char **argv) Link Here
218
	short quse_all = 0;
261
	short quse_all = 0;
219
	int regexp_matching = 1, i, idx = 0;
262
	int regexp_matching = 1, i, idx = 0;
220
	size_t search_len;
263
	size_t search_len;
264
	overlay_t *cur_overlay, *overlay_tmp;
265
266
	cur_overlay = overlay_gentoo;
267
	overlay_name[0] = 0;
268
	repo_search[0] = 0;
221
269
222
	DBG("argc=%d argv[0]=%s argv[1]=%s",
270
	DBG("argc=%d argv[0]=%s argv[1]=%s",
223
	    argc, argv[0], argc > 1 ? argv[1] : "NULL?");
271
	    argc, argv[0], argc > 1 ? argv[1] : "NULL?");
Lines 226-231 int quse_main(int argc, char **argv) Link Here
226
		switch (i) {
274
		switch (i) {
227
		case 'e': regexp_matching = 0; break;
275
		case 'e': regexp_matching = 0; break;
228
		case 'a': quse_all = 1; break;
276
		case 'a': quse_all = 1; break;
277
		case 'o':
278
			repo = 1;
279
			strncpy(repo_search, optarg, sizeof(repo_search));
280
			break;
229
		case 'K': idx = 1; break;
281
		case 'K': idx = 1; break;
230
		case 'L': idx = 2; break;
282
		case 'L': idx = 2; break;
231
		case 'D': idx = -1; break;
283
		case 'D': idx = -1; break;
Lines 234-244 int quse_main(int argc, char **argv) Link Here
234
		COMMON_GETOPTS_CASES(quse)
286
		COMMON_GETOPTS_CASES(quse)
235
		}
287
		}
236
	}
288
	}
237
	if (argc == optind && !quse_all && idx >= 0)
289
290
	if (repo) {
291
		do {
292
			if (!strncmp(cur_overlay->name, repo_search, sizeof(cur_overlay->name)))
293
				break;
294
		} while ((cur_overlay=cur_overlay->next));
295
		if (NULL == cur_overlay)
296
			err("%s : Unknown overlay, try 'q --ls-overlays'", repo_search);
297
	}
298
299
	if (argc == optind && !quse_all && idx >= 0) {
300
		if (idx == 3)
301
			free(search_vars+idx);
238
		quse_usage(EXIT_FAILURE);
302
		quse_usage(EXIT_FAILURE);
303
	}
239
304
240
	if (idx == -1)
305
	if (idx == -1)
241
		return quse_describe_flag(optind, argc, argv);
306
		return quse_describe_flag(optind, repo, repo_search, argc, argv);
242
307
243
	if (quse_all) optind = argc;
308
	if (quse_all) optind = argc;
244
	initialize_ebuild_flat();	/* sets our pwd to $PORTDIR */
309
	initialize_ebuild_flat();	/* sets our pwd to $PORTDIR */
Lines 250-255 int quse_main(int argc, char **argv) Link Here
250
		return 1;
315
		return 1;
251
	while ((fgets(ebuild, sizeof(ebuild), fp)) != NULL) {
316
	while ((fgets(ebuild, sizeof(ebuild), fp)) != NULL) {
252
		FILE *newfp;
317
		FILE *newfp;
318
		if ((p = strchr(ebuild, ':')))
319
		{
320
			*p = 0;
321
			str = p+2;			/* separator is '::' */
322
			p = ebuild;
323
			if (repo && strncmp(repo_search, p, sizeof(repo_search)))
324
				continue;
325
			if (strncmp(overlay_name, p, sizeof(overlay_name))) {
326
				overlay_tmp=overlay_gentoo;
327
				do {
328
					if (!strncmp(overlay_tmp->name, p, sizeof(overlay_tmp->name)))
329
						break;
330
				} while ((overlay_tmp=overlay_tmp->next));
331
				if (overlay_tmp)
332
				{
333
					cur_overlay = overlay_tmp;
334
					if (chdir(cur_overlay->path) != 0) {
335
						warnp("chdir to PORTDIR '%s' failed", cur_overlay->path);
336
						myerror=1;
337
					}
338
				} else
339
					myerror=1;
340
341
				strncpy(overlay_name, cur_overlay->name, sizeof(overlay_name));
342
			}
343
			strcpy(ebuild, str);
344
		} else
345
			myerror=1;
346
347
		if (myerror) {
348
			if (!reinitialize)
349
				warnf("(cache update pending) %s : Unknown overlay", overlay_name);
350
			reinitialize = 1;
351
			myerror=0;
352
			continue;
353
		}
354
253
		if ((p = strchr(ebuild, '\n')) != NULL)
355
		if ((p = strchr(ebuild, '\n')) != NULL)
254
			*p = 0;
356
			*p = 0;
255
		if ((newfp = fopen(ebuild, "r")) != NULL) {
357
		if ((newfp = fopen(ebuild, "r")) != NULL) {
Lines 375-381 int quse_main(int argc, char **argv) Link Here
375
					if (verbose > 3)
477
					if (verbose > 3)
376
						printf("%s %s %s ", *user ? user : "MISSING", *revision ? revision : "MISSING", *date ? date : "MISSING");
478
						printf("%s %s %s ", *user ? user : "MISSING", *revision ? revision : "MISSING", *date ? date : "MISSING");
377
479
378
					printf("%s%s%s ", CYAN, ebuild, NORM);
480
					printf("%s%s::%s%s ", CYAN, cur_overlay->name, ebuild, NORM);
379
					print_highlighted_use_flags(&buf0[search_len+1], optind, argc, argv);
481
					print_highlighted_use_flags(&buf0[search_len+1], optind, argc, argv);
380
					puts(NORM);
482
					puts(NORM);
381
					if (verbose > 1) {
483
					if (verbose > 1) {
Lines 383-389 int quse_main(int argc, char **argv) Link Here
383
						int ARGC = 0;
485
						int ARGC = 0;
384
						makeargv(&buf0[search_len+1], &ARGC, &ARGV);
486
						makeargv(&buf0[search_len+1], &ARGC, &ARGV);
385
						if (ARGC > 0) {
487
						if (ARGC > 0) {
386
							quse_describe_flag(1, ARGC, ARGV);
488
							quse_describe_flag(1, repo, repo_search, ARGC, ARGV);
387
							for (i = 0; i < ARGC; i++)
489
							for (i = 0; i < ARGC; i++)
388
								free(ARGV[i]);
490
								free(ARGV[i]);
389
							free(ARGV);
491
							free(ARGV);
(-)portage-utils-20061111/tests/install/dotest (-1 / +1 lines)
Lines 7-13 die() { Link Here
7
7
8
cp ../../q .
8
cp ../../q .
9
./q -i || die "./q -i"
9
./q -i || die "./q -i"
10
for app in $(./q -Ch | grep ' : ' | awk '{print $1}') ; do
10
for app in $(./q -Ch | grep -v 'Usage' | grep ' : ' | awk '{print $1}') ; do
11
	[ ! -e $app ] && die "$app does not exist"
11
	[ ! -e $app ] && die "$app does not exist"
12
done
12
done
13
echo "PASSED"
13
echo "PASSED"

Return to bug 154405