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-20070115/libq/atom_compare.c (-1 / +17 lines)
Lines 43-53 int atom_compare(const depend_atom * con Link Here
43
43
44
	/* check version */
44
	/* check version */
45
	if (a1->PV && a2->PV) {
45
	if (a1->PV && a2->PV) {
46
		int i;
46
		char *s1, *s2;
47
		char *s1, *s2;
47
		unsigned int n1, n2;
48
		unsigned int n1, n2;
48
		/* first we compare the version [1.0]z_alpha1 */
49
		/* first we compare the version [1.0]z_alpha1 */
49
		s1 = a1->PV;
50
		s1 = a1->PV;
50
		s2 = a2->PV;
51
		s2 = a2->PV;
52
		/* treat the case of svn/live/scm/cvs.. version */
53
		n1=n2=0;
54
		for (i=0; i<ARR_SIZE(atom_version_str); ++i) {
55
			if (!strcmp(s1,&atom_version_str[i].version[1]))
56
				n1=1;
57
			if (!strcmp(s2,&atom_version_str[i].version[1]))
58
				n2=1;
59
		}
60
		if (n1+n2) {
61
			if (n1==n2)
62
				goto same_version;
63
			else
64
				return (n1<n2 ? OLDER : NEWER);
65
		}
66
51
		while (s1 || s2) {
67
		while (s1 || s2) {
52
			if (s1 && s2) {
68
			if (s1 && s2) {
53
				/* deal with leading zeros */
69
				/* deal with leading zeros */
Lines 101-107 int atom_compare(const depend_atom * con Link Here
101
		/* fall through to -r# check below */
117
		/* fall through to -r# check below */
102
	} else if (a1->PV || a2->PV)
118
	} else if (a1->PV || a2->PV)
103
		return NOT_EQUAL;
119
		return NOT_EQUAL;
104
120
same_version:
105
	if (a1->PR_int == a2->PR_int)
121
	if (a1->PR_int == a2->PR_int)
106
		return EQUAL;
122
		return EQUAL;
107
	else if (a1->PR_int < a2->PR_int)
123
	else if (a1->PR_int < a2->PR_int)
(-)portage-utils-20070115/libq/atom_explode.c (+33 lines)
Lines 13-20 Link Here
13
13
14
typedef enum { VER_ALPHA=0, VER_BETA, VER_PRE, VER_RC, VER_NORM, VER_P } atom_suffixes;
14
typedef enum { VER_ALPHA=0, VER_BETA, VER_PRE, VER_RC, VER_NORM, VER_P } atom_suffixes;
15
const char * const atom_suffixes_str[] = { "_alpha", "_beta", "_pre", "_rc", "_/*bogus*/", "_p", NULL };
15
const char * const atom_suffixes_str[] = { "_alpha", "_beta", "_pre", "_rc", "_/*bogus*/", "_p", NULL };
16
const struct {
17
	const char *version;
18
	const size_t version_len;
19
} atom_version_str[] = {
20
	{"-scm", 4},
21
	{"-cvs", 4},
22
	{"-svn", 4},
23
	{"-live", 5},
24
	{"-9999", 5}
25
};
26
27
16
28
17
typedef struct {
29
typedef struct {
30
	char *OVERLAY;
18
	char *CATEGORY;
31
	char *CATEGORY;
19
	char *PN;
32
	char *PN;
20
	int PR_int;
33
	int PR_int;
Lines 61-66 depend_atom *atom_explode(const char *at Link Here
61
	ret->suffix = VER_NORM;
74
	ret->suffix = VER_NORM;
62
	memcpy(ret->CATEGORY, atom, slen);
75
	memcpy(ret->CATEGORY, atom, slen);
63
76
77
	/* find the OVERLAY, if present */
78
	if ((ptr_tmp=strstr(ret->CATEGORY, "::"))) {
79
		if (*(ptr_tmp+2))
80
			ret->OVERLAY = ptr_tmp + 2;
81
		else
82
			ret->OVERLAY = NULL;
83
		*ptr_tmp = 0;
84
		ptr_tmp = NULL;
85
	}
86
64
	/* break up the CATEOGRY and PVR */
87
	/* break up the CATEOGRY and PVR */
65
	if ((ptr = strrchr(ret->CATEGORY, '/')) != NULL) {
88
	if ((ptr = strrchr(ret->CATEGORY, '/')) != NULL) {
66
		ret->PN = ptr+1;
89
		ret->PN = ptr+1;
Lines 144-149 eat_version: Link Here
144
			ret->PV = ptr_tmp+1;
167
			ret->PV = ptr_tmp+1;
145
			ret->PV[-1] = '\0';
168
			ret->PV[-1] = '\0';
146
			goto found_pv;
169
			goto found_pv;
170
		}
171
172
		 for (i=0; i<ARR_SIZE(atom_version_str); ++i)
173
			if ((ptr_tmp = strstr(ret->PN, atom_version_str[i].version)) && ptr_tmp == ret->PN+strlen(ret->PN)-atom_version_str[i].version_len)
174
				break;
175
176
		if (ptr_tmp && *ptr_tmp) {
177
			ret->PV = ptr_tmp+1;
178
			ret->PV[-1] = '\0';
179
			goto found_pv;
147
		} else {
180
		} else {
148
			/* atom has no version */
181
			/* atom has no version */
149
			ret->PV = ret->PVR = NULL;
182
			ret->PV = ret->PVR = NULL;
(-)portage-utils-20070115/main.c (-58 / +189 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[_Q_PATH_MAX] = "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
	char cache[_Q_PATH_MAX];
100
	struct overlay_t *next;
101
};
102
103
static overlay_t *first_overlay = NULL;
104
/* temporary workaround ? */
105
static overlay_t *overlay_gentoo = NULL;
106
95
char pkgdir[512] = "/usr/portage/packages/";
107
char pkgdir[512] = "/usr/portage/packages/";
96
char port_tmpdir[512] = "/var/tmp/portage/";
108
char port_tmpdir[512] = "/var/tmp/portage/";
97
109
Lines 201-210 static void usage(int status, const char Link Here
201
	for (i = 0; opts[i].name; ++i) {
213
	for (i = 0; opts[i].name; ++i) {
202
		assert(help[i] != NULL); /* this assert is a life saver when adding new applets. */
214
		assert(help[i] != NULL); /* this assert is a life saver when adding new applets. */
203
		if (opts[i].has_arg == no_argument)
215
		if (opts[i].has_arg == no_argument)
204
			printf("  -%c, --%-15s%s*%s %s\n", opts[i].val,
216
			printf("  -%c, --%-16s%s*%s %s\n", opts[i].val,
205
				opts[i].name, RED, NORM, _(help[i]));
217
				opts[i].name, RED, NORM, _(help[i]));
206
		else
218
		else
207
			printf("  -%c, --%-8s %s<arg>%s %s*%s %s\n", opts[i].val,
219
			printf("  -%c, --%-9s %s<arg>%s %s*%s %s\n", opts[i].val,
208
				opts[i].name, DKBLUE, NORM, RED, NORM, _(help[i]));
220
				opts[i].name, DKBLUE, NORM, RED, NORM, _(help[i]));
209
	}
221
	}
210
	exit(status);
222
	exit(status);
Lines 467-483 char *strincr_var(const char *name, char Link Here
467
	return (char *) value;
479
	return (char *) value;
468
}
480
}
469
481
482
void initialize_overlays (char portdir_overlay[])
483
{
484
	short merror = 0;
485
	char buf[BUFSIZE], file[_Q_PATH_MAX], *s, *p, *t;
486
	overlay_t *cur_overlay;
487
	FILE *repo_nameFP;
488
	s = portdir_overlay;
489
490
	first_overlay = xmalloc(sizeof(*first_overlay));
491
	cur_overlay = first_overlay;
492
493
	while (*s) {
494
		/* except on the first loop */
495
		if (s!=portdir_overlay) {
496
			cur_overlay->next = xmalloc (sizeof (*cur_overlay->next));
497
			cur_overlay = cur_overlay->next;
498
		}
499
		cur_overlay->next = NULL;
500
501
		if ((p=strchr(s,' ')))
502
			*p = 0;
503
504
		snprintf(cur_overlay->path, sizeof(cur_overlay->path), "%s%s", (strcmp(portroot, "/") ? portroot : ""), s);
505
506
		/* find the name for the overlay */
507
		snprintf(file, sizeof(file), "%s/profiles/repo_name", cur_overlay->path);
508
509
		if ((repo_nameFP = fopen(file, "r"))) {
510
			if (!(fgets(buf, sizeof(buf),repo_nameFP)))
511
				merror++;
512
			rmspace(buf);
513
			if ((t = strchr(buf,'\n')))
514
				*t = 0;
515
			strncpy(cur_overlay->name, buf, sizeof(cur_overlay->name));
516
517
			fclose(repo_nameFP);
518
		} else
519
			merror++;
520
521
		if (merror) {
522
			/* delete trailing '/' */
523
			t = cur_overlay->path + strlen(cur_overlay->path) - 1;
524
			if (*t == '/')
525
				*t = 0;
526
			strncpy(file, cur_overlay->path, sizeof(file));
527
			strncpy(cur_overlay->name, basename(file), sizeof(cur_overlay->name));
528
			merror=0;
529
		}
530
531
		if (!strncmp(cur_overlay->name, "gentoo", sizeof(cur_overlay->name))) {
532
			snprintf(cur_overlay->cache, sizeof(cur_overlay->cache), "%s/%s", cur_overlay->path, portcachedir);
533
			overlay_gentoo = cur_overlay;
534
		} else
535
			strcpy(cur_overlay->cache, "/var/empty");
536
537
		if (p)
538
			s = p+1; /* because portdir_overlay has no trailing space */
539
		else
540
			break;
541
	}
542
543
}
544
545
470
void initialize_portage_env(void)
546
void initialize_portage_env(void)
471
{
547
{
472
	char nocolor = 0;
548
	char nocolor = 0;
473
	int i, f;
549
	int i, f;
474
	struct stat st;
550
	struct stat st;
475
	FILE *fp;
551
	FILE *fp;
552
	char tmp_portdir[_Q_PATH_MAX];
476
	char buf[BUFSIZE], *s, *p;
553
	char buf[BUFSIZE], *s, *p;
477
554
478
	char profile[_Q_PATH_MAX], portage_file[_Q_PATH_MAX];
555
	char profile[_Q_PATH_MAX], portage_file[_Q_PATH_MAX];
556
	char portdir_overlay[BUFSIZE] = "";
557
479
	const char *files[] = {portage_file, "/etc/make.globals", "/etc/make.conf"};
558
	const char *files[] = {portage_file, "/etc/make.globals", "/etc/make.conf"};
480
	typedef enum { _Q_BOOL, _Q_STR, _Q_ISTR } var_types;
559
	typedef enum { _Q_BOOL, _Q_STR, _Q_ISTR } var_types;
560
481
	struct {
561
	struct {
482
		const char *name;
562
		const char *name;
483
		const size_t name_len;
563
		const size_t name_len;
Lines 491-497 void initialize_portage_env(void) Link Here
491
		{"CONFIG_PROTECT",   14, _Q_STR,  config_protect, sizeof(config_protect)},
571
		{"CONFIG_PROTECT",   14, _Q_STR,  config_protect, sizeof(config_protect)},
492
		{"NOCOLOR",           7, _Q_BOOL, &nocolor,       1},
572
		{"NOCOLOR",           7, _Q_BOOL, &nocolor,       1},
493
		{"FEATURES",          8, _Q_ISTR, features,       sizeof(features)},
573
		{"FEATURES",          8, _Q_ISTR, features,       sizeof(features)},
494
		{"PORTDIR",           7, _Q_STR,  portdir,        sizeof(portdir)},
574
		{"PORTDIR",           7, _Q_STR,  tmp_portdir,    sizeof(tmp_portdir)},
575
		{"PORTDIR_OVERLAY",  15, _Q_ISTR, portdir_overlay,sizeof(portdir_overlay)},
495
		{"PORTAGE_BINHOST",  15, _Q_STR,  binhost,        sizeof(binhost)},
576
		{"PORTAGE_BINHOST",  15, _Q_STR,  binhost,        sizeof(binhost)},
496
		{"PORTAGE_TMPDIR",   14, _Q_STR,  port_tmpdir,    sizeof(port_tmpdir)},
577
		{"PORTAGE_TMPDIR",   14, _Q_STR,  port_tmpdir,    sizeof(port_tmpdir)},
497
		{"PKGDIR",            6, _Q_STR,  pkgdir,         sizeof(pkgdir)},
578
		{"PKGDIR",            6, _Q_STR,  pkgdir,         sizeof(pkgdir)},
Lines 589-594 void initialize_portage_env(void) Link Here
589
		no_colors();
670
		no_colors();
590
	else
671
	else
591
		color_remap();
672
		color_remap();
673
674
	snprintf(tmp_portdir, sizeof(tmp_portdir), "%s/%s", (strcmp(portroot, "/") ? portroot : ""), portvdb);
675
	strncpy(portvdb, tmp_portdir, sizeof(portvdb));
676
	strincr_var("PORTDIR_OVERLAY", tmp_portdir, portdir_overlay, sizeof(portdir_overlay));
677
678
	/* now we initiliase the overlay chained list */
679
	initialize_overlays(portdir_overlay);
680
592
}
681
}
593
682
594
enum {
683
enum {
Lines 617-636 const char *initialize_flat(int cache_ty Link Here
617
	int a, b, c, d, e, i;
706
	int a, b, c, d, e, i;
618
	int frac, secs, count;
707
	int frac, secs, count;
619
	FILE *fp;
708
	FILE *fp;
709
	overlay_t *cur_overlay;
620
710
621
	a = b = c = d = e = i = 0;
711
	a = b = c = d = e = i = 0;
622
	count = frac = secs = 0;
712
	count = frac = secs = 0;
713
	cur_overlay = first_overlay;
623
714
624
	cache_file = (cache_type == CACHE_EBUILD ? CACHE_EBUILD_FILE : CACHE_METADATA_FILE);
715
	cache_file = (cache_type == CACHE_EBUILD ? CACHE_EBUILD_FILE : CACHE_METADATA_FILE);
625
716
626
	if (chdir(portdir) != 0) {
717
	/* SAM review without gentoo! */
627
		warnp("chdir to PORTDIR '%s' failed", portdir);
718
	if (cache_type == CACHE_METADATA) {
628
		goto ret;
719
		if (chdir(overlay_gentoo->cache) != 0) {
629
	}
720
			warnp("chdir to portage cache '%s' failed", overlay_gentoo->cache);
630
721
			goto ret;
631
	if (cache_type == CACHE_METADATA && chdir(portcachedir) != 0) {
722
		}
632
		warnp("chdir to portage cache '%s/%s' failed", portdir, portcachedir);
723
	} else {
633
		goto ret;
724
		if (chdir(overlay_gentoo->path) != 0) {
725
			warnp("chdir to PORTDIR '%s' failed", overlay_gentoo->path);
726
			goto ret;
727
		}
634
	}
728
	}
635
729
636
	if ((stat(cache_file, &st)) != (-1))
730
	if ((stat(cache_file, &st)) != (-1))
Lines 645-708 const char *initialize_flat(int cache_ty Link Here
645
739
646
	unlink(cache_file);
740
	unlink(cache_file);
647
	if (errno != ENOENT) {
741
	if (errno != ENOENT) {
648
		warnfp("unlinking '%s/%s' failed", portdir, cache_file);
742
		/* SAM review without gentoo! */
743
		warnfp("unlinking '%s/%s' failed", overlay_gentoo->path, cache_file);
649
		goto ret;
744
		goto ret;
650
	}
745
	}
651
746
747
	/* SAM review without gentoo! */
652
	if ((fp = fopen(cache_file, "w")) == NULL) {
748
	if ((fp = fopen(cache_file, "w")) == NULL) {
653
		warnfp("opening '%s/%s' failed", portdir, cache_file);
749
		warnfp("opening '%s/%s' failed", (cache_type == CACHE_EBUILD ? overlay_gentoo->path : overlay_gentoo->cache), cache_file);
654
		goto ret;
750
		goto ret;
655
	}
751
	}
656
752
657
	gettimeofday(&start, NULL);
753
	gettimeofday(&start, NULL);
658
754
659
	if ((a = scandir(".", &category, filter_hidden, alphasort)) < 0)
755
	do {
660
		goto ret;
756
		switch (cache_type) {
661
757
		case CACHE_EBUILD:
662
	for (i = 0; i < a; i++) {
758
			if (chdir(cur_overlay->path) != 0) {
663
		stat(category[i]->d_name, &st);
759
				warnp("chdir to '%s' failed, skipping the %s repository", cur_overlay->path, cur_overlay->name);
664
		if (!S_ISDIR(st.st_mode))
665
			continue;
666
		if (strchr(category[i]->d_name, '-') == NULL)
667
			if ((strncmp(category[i]->d_name, "virtual", 7)) != 0)
668
				continue;
760
				continue;
669
761
			}
670
		if ((b = scandir(category[i]->d_name, &pn, filter_hidden, alphasort)) < 0)
762
			break;
763
		case CACHE_METADATA:
764
			if (!strcmp(cur_overlay->cache, "/var/empty")) {
765
				if (verbose)
766
					warnp("No cache defined for the %s repository", cur_overlay->name);
767
				continue;
768
			} else if (chdir(cur_overlay->cache) != 0) {
769
				warnp("chdir to '%s' failed, skipping the %s repository",cur_overlay->cache, cur_overlay->name);
770
				continue;
771
			}
772
			break;
773
		}
774
		if ((a = scandir(".", &category, filter_hidden, alphasort)) < 0)
671
			continue;
775
			continue;
672
		for (c = 0; c < b; c++) {
673
			char de[_Q_PATH_MAX];
674
776
675
			snprintf(de, sizeof(de), "%s/%s", category[i]->d_name, pn[c]->d_name);
777
		for (i = 0; i < a; i++) {
778
			stat(category[i]->d_name, &st);
779
			if (!S_ISDIR(st.st_mode))
780
				continue;
781
			if (strchr(category[i]->d_name, '-') == NULL)
782
				if ((strncmp(category[i]->d_name, "virtual", 7)) != 0)
783
					continue;
676
784
677
			if (stat(de, &st) < 0)
785
			if ((b = scandir(category[i]->d_name, &pn, filter_hidden, alphasort)) < 0)
678
				continue;
786
				continue;
787
			for (c = 0; c < b; c++) {
788
				char de[_Q_PATH_MAX];
679
789
680
			switch (cache_type) {
790
				snprintf(de, sizeof(de), "%s/%s", category[i]->d_name, pn[c]->d_name);
681
			case CACHE_EBUILD:
791
682
				if (!S_ISDIR(st.st_mode))
792
				if (stat(de, &st) < 0)
683
					continue;
793
					continue;
684
				break;
794
685
			case CACHE_METADATA:
795
				switch (cache_type) {
686
				if (S_ISREG(st.st_mode))
796
				case CACHE_EBUILD:
687
					fprintf(fp, "%s\n", de);
797
					if (!S_ISDIR(st.st_mode))
688
				continue;
798
						continue;
689
				break;
799
					break;
690
			}
800
				case CACHE_METADATA:
691
			if ((e = scandir(de, &eb, filter_hidden, alphasort)) < 0)
801
					if (S_ISREG(st.st_mode))
692
				continue;
802
						fprintf(fp, "%s::%s\n", de, cur_overlay->name);
693
			for (d = 0; d < e; d++) {
803
					continue;
694
				if ((p = strrchr(eb[d]->d_name, '.')) != NULL)
804
					break;
695
					if (strcmp(p, ".ebuild") == 0) {
805
				}
696
						count++;
806
				if ((e = scandir(de, &eb, filter_hidden, alphasort)) < 0)
697
						fprintf(fp, "%s/%s/%s\n", category[i]->d_name, pn[c]->d_name, eb[d]->d_name);
807
					continue;
698
					}
808
				for (d = 0; d < e; d++) {
809
					if ((p = strrchr(eb[d]->d_name, '.')) != NULL)
810
						if (strcmp(p, ".ebuild") == 0) {
811
							count++;
812
							fprintf(fp, "%s/%s/%s::%s\n", category[i]->d_name, pn[c]->d_name, eb[d]->d_name, cur_overlay->name);
813
						}
814
				}
815
				while (d--) free(eb[d]);
816
				free(eb);
699
			}
817
			}
700
			while (d--) free(eb[d]);
818
			while (b--) free(pn[b]);
701
			free(eb);
819
			free(pn);
702
		}
820
		}
703
		while (b--) free(pn[b]);
821
	} while ((cur_overlay = cur_overlay->next));
704
		free(pn);
822
705
	}
706
	fclose(fp);
823
	fclose(fp);
707
	while (a--) free(category[a]);
824
	while (a--) free(category[a]);
708
	free(category);
825
	free(category);
Lines 721-727 const char *initialize_flat(int cache_ty Link Here
721
838
722
	warn("Finished %u entries in %d.%06d seconds", count, secs, frac);
839
	warn("Finished %u entries in %d.%06d seconds", count, secs, frac);
723
	if (secs > 100)
840
	if (secs > 100)
724
		warn("You should consider a faster file system such as reiserfs for PORTDIR='%s'", portdir);
841
		warn("You should consider a faster file system such as reiserfs for repositories");
725
ret:
842
ret:
726
	return cache_file;
843
	return cache_file;
727
}
844
}
Lines 730-737 ret: Link Here
730
847
731
void reinitialize_ebuild_flat(void)
848
void reinitialize_ebuild_flat(void)
732
{
849
{
733
	if ((chdir(portdir)) != 0) {
850
	if ((chdir(first_overlay->path)) != 0) {
734
		warnp("chdir to PORTDIR '%s' failed", portdir);
851
		warnp("chdir to PORTDIR '%s' failed", first_overlay->path);
735
		return;
852
		return;
736
	}
853
	}
737
	unlink(CACHE_EBUILD_FILE);
854
	unlink(CACHE_EBUILD_FILE);
Lines 766-773 typedef struct { Link Here
766
} portage_cache;
883
} portage_cache;
767
884
768
void cache_free(portage_cache *cache);
885
void cache_free(portage_cache *cache);
769
portage_cache *cache_read_file(const char *file);
886
portage_cache *cache_read_file(char *file);
770
portage_cache *cache_read_file(const char *file)
887
portage_cache *cache_read_file(char *file)
771
{
888
{
772
	struct stat s;
889
	struct stat s;
773
	char *ptr;
890
	char *ptr;
Lines 775-782 portage_cache *cache_read_file(const cha Link Here
775
	portage_cache *ret = NULL;
892
	portage_cache *ret = NULL;
776
	size_t len;
893
	size_t len;
777
894
895
	if ((ptr = strstr(file, "::")))
896
		*ptr = 0;
778
	if ((f = fopen(file, "r")) == NULL)
897
	if ((f = fopen(file, "r")) == NULL)
779
		goto err;
898
		goto err;
899
	if (ptr)
900
		*ptr = ':';
780
901
781
	if (fstat(fileno(f), &s) != 0)
902
	if (fstat(fileno(f), &s) != 0)
782
		goto err;
903
		goto err;
Lines 1004-1013 fuckit: Link Here
1004
	return cpf;
1125
	return cpf;
1005
}
1126
}
1006
1127
1128
/* free overlays */
1129
void free_overlays(overlay_t *overlay);
1130
void free_overlays(overlay_t *overlay)
1131
{
1132
	if (overlay->next)
1133
		free_overlays(overlay->next);
1134
	free(overlay);
1135
}
1136
1007
void cleanup()
1137
void cleanup()
1008
{
1138
{
1009
	reinitialize_as_needed();
1139
	reinitialize_as_needed();
1010
	free_sets(virtuals);
1140
	free_sets(virtuals);
1141
	free_overlays(first_overlay);
1011
	fclose(stderr);
1142
	fclose(stderr);
1012
}
1143
}
1013
1144
(-)portage-utils-20070115/man/q.1 (-1 / +4 lines)
Lines 61-71 quse <useflag> Link Here
61
qxpak <misc args>
61
qxpak <misc args>
62
: manipulate xpak archives
62
: manipulate xpak archives
63
.PP
63
.PP
64
Options: \fB\-[irmvqChV]\fR
64
Options: \fB\-[ilrmvqChV]\fR
65
.TP
65
.TP
66
\fB\-i\fR, \fB\-\-install\fR
66
\fB\-i\fR, \fB\-\-install\fR
67
* Install symlinks for applets
67
* Install symlinks for applets
68
.TP
68
.TP
69
\fB\-l\fR, \fB\-\-ls\-overlays\fR
70
* List configured overlays
71
.TP
69
\fB\-r\fR, \fB\-\-reinitialize\fR
72
\fB\-r\fR, \fB\-\-reinitialize\fR
70
* Reinitialize ebuild cache
73
* Reinitialize ebuild cache
71
.TP
74
.TP
(-)portage-utils-20070115/man/qgrep.1 (+5 lines)
Lines 16-21 Options: \fB\-[IiHcevqChV]\fR Link Here
16
\fB\-H\fR, \fB\-\-with\-filename\fR
16
\fB\-H\fR, \fB\-\-with\-filename\fR
17
* Print the filename for each match
17
* Print the filename for each match
18
.TP
18
.TP
19
\fB\-o\fR, \fB\-\-overlay\fR
20
<arg>
21
.BR
22
 * Only consider the <arg> overlay
23
.TP
19
\fB\-c\fR, \fB\-\-count\fR
24
\fB\-c\fR, \fB\-\-count\fR
20
* Only print a count of matching lines per FILE
25
* Only print a count of matching lines per FILE
21
.TP
26
.TP
(-)portage-utils-20070115/man/qsearch.1 (-1 / +9 lines)
Lines 5-11 qsearch \- search pkgname/desc Link Here
5
.B qsearch
5
.B qsearch
6
\fI<regex>\fR
6
\fI<regex>\fR
7
.SH DESCRIPTION
7
.SH DESCRIPTION
8
Options: \fB\-[acsSNHvqChV]\fR
8
Options: \fB\-[aco\fR:psSNHvqChV]
9
.TP
9
.TP
10
\fB\-a\fR, \fB\-\-all\fR
10
\fB\-a\fR, \fB\-\-all\fR
11
* List the descriptions of every package in the cache
11
* List the descriptions of every package in the cache
Lines 13-18 Options: \fB\-[acsSNHvqChV]\fR Link Here
13
\fB\-c\fR, \fB\-\-cache\fR
13
\fB\-c\fR, \fB\-\-cache\fR
14
* Use the portage cache
14
* Use the portage cache
15
.TP
15
.TP
16
\fB\-o\fR, \fB\-\-overlay\fR
17
<arg>
18
.BR
19
 * Search only in the <arg> overlay
20
.TP
21
\fB\-p\fR, \fB\-\-show\-path\fR
22
* Show the path to the ebuild
23
.TP
16
\fB\-s\fR, \fB\-\-search\fR
24
\fB\-s\fR, \fB\-\-search\fR
17
* Regex search package basenames
25
* Regex search package basenames
18
.TP
26
.TP
(-)portage-utils-20070115/man/quse.1 (-1 / +6 lines)
Lines 5-11 quse \- find pkgs using useflags Link Here
5
.B quse
5
.B quse
6
\fI<useflag>\fR
6
\fI<useflag>\fR
7
.SH DESCRIPTION
7
.SH DESCRIPTION
8
Options: \fB\-[eavKLDF:NvqChV]\fR
8
Options: \fB\-[eao\fR:vKLDF:NvqChV]
9
.TP
9
.TP
10
\fB\-e\fR, \fB\-\-exact\fR
10
\fB\-e\fR, \fB\-\-exact\fR
11
* Show exact non regexp matching using strcmp
11
* Show exact non regexp matching using strcmp
Lines 13-18 Options: \fB\-[eavKLDF:NvqChV]\fR Link Here
13
\fB\-a\fR, \fB\-\-all\fR
13
\fB\-a\fR, \fB\-\-all\fR
14
* Show annoying things in IUSE
14
* Show annoying things in IUSE
15
.TP
15
.TP
16
\fB\-o\fR, \fB\-\-overlay\fR
17
<arg>
18
.BR
19
 * Only consider the <arg> overlay
20
.TP
16
\fB\-K\fR, \fB\-\-keywords\fR
21
\fB\-K\fR, \fB\-\-keywords\fR
17
* Use the KEYWORDS vs IUSE
22
* Use the KEYWORDS vs IUSE
18
.TP
23
.TP
(-)portage-utils-20070115/qatom.c (+1 lines)
Lines 60-65 int qatom_main(int argc, char **argv) Link Here
60
				printf(" r%i", atom->PR_int);
60
				printf(" r%i", atom->PR_int);
61
			if (verbose > 1)
61
			if (verbose > 1)
62
				printf(" %c", (atom->letter ? : '-'));
62
				printf(" %c", (atom->letter ? : '-'));
63
			printf(" %s", atom->OVERLAY);
63
			putchar('\n');
64
			putchar('\n');
64
			atom_implode(atom);
65
			atom_implode(atom);
65
		}
66
		}
(-)portage-utils-20070115/q.c (-1 / +15 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=first_overlay;
98
			do {
99
				printf("   Name : %s%-20.20s%s \tlocation : %s%-60.60s%s \tmetadata : %s%-60.60s%s\n",
100
				                        CYAN, cur_overlay->name, NORM, CYAN, cur_overlay->path, NORM,
101
							CYAN, cur_overlay->cache, NORM);
102
			} while ((cur_overlay=cur_overlay->next));
103
			fputc('\n', stdout);
104
			return 0;
105
			}
92
		case 'i': {
106
		case 'i': {
93
			char buf[_Q_PATH_MAX];
107
			char buf[_Q_PATH_MAX];
94
			/* always bzero a buffer before using readlink() */
108
			/* always bzero a buffer before using readlink() */
(-)portage-utils-20070115/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-20070115/qcheck.c (-5 / +5 lines)
Lines 49-58 int qcheck_main(int argc, char **argv) Link Here
49
	if ((argc == optind) && !search_all)
49
	if ((argc == optind) && !search_all)
50
		qcheck_usage(EXIT_FAILURE);
50
		qcheck_usage(EXIT_FAILURE);
51
51
52
	if (chdir(portroot))
52
	if (chdir(portvdb))
53
		errp("could not chdir(%s) for ROOT", portroot);
53
		errp("could not chdir(%s) for VDB", portvdb);
54
54
55
	if (chdir(portvdb) != 0 || (dir = opendir(".")) == NULL)
55
	if ((dir = opendir(".")) == NULL)
56
		return EXIT_FAILURE;
56
		return EXIT_FAILURE;
57
57
58
	/* open /var/db/pkg */
58
	/* open /var/db/pkg */
Lines 84-90 int qcheck_main(int argc, char **argv) Link Here
84
					continue;
84
					continue;
85
			}
85
			}
86
86
87
			snprintf(buf, sizeof(buf), "%s%s/%s/%s/CONTENTS", portroot, portvdb,
87
			snprintf(buf, sizeof(buf), "%s/%s/%s/CONTENTS", portvdb,
88
			         dentry->d_name, de->d_name);
88
			         dentry->d_name, de->d_name);
89
			if ((fp = fopen(buf, "r")) == NULL)
89
			if ((fp = fopen(buf, "r")) == NULL)
90
				continue;
90
				continue;
Lines 199-205 free_and_more_hash: Link Here
199
			fclose(fp);
199
			fclose(fp);
200
			if (qc_update) {
200
			if (qc_update) {
201
				fclose(fpx);
201
				fclose(fpx);
202
				snprintf(buf, sizeof(buf), "%s%s/%s/%s/CONTENTS", portroot, portvdb,
202
				snprintf(buf, sizeof(buf), "%s/%s/%s/CONTENTS", portvdb,
203
					dentry->d_name, de->d_name);
203
					dentry->d_name, de->d_name);
204
				strcpy(buffer, buf);
204
				strcpy(buffer, buf);
205
				strncat(buffer, "~", sizeof(buffer));
205
				strncat(buffer, "~", sizeof(buffer));
(-)portage-utils-20070115/qdepends.c (-10 / +10 lines)
Lines 359-368 int qdepends_main_vdb(const char *depend Link Here
359
	char depend[16384], use[8192];
359
	char depend[16384], use[8192];
360
	dep_node *dep_tree;
360
	dep_node *dep_tree;
361
361
362
	if (chdir(portroot))
362
	if (chdir(portvdb))
363
		errp("could not chdir(%s) for ROOT", portroot);
363
		errp("could not chdir(%s) for VDB", portvdb);
364
364
365
	if (chdir(portvdb) != 0 || (dir = opendir(".")) == NULL)
365
	if ((dir = opendir(".")) == NULL)
366
		return EXIT_FAILURE;
366
		return EXIT_FAILURE;
367
367
368
	/* open /var/db/pkg */
368
	/* open /var/db/pkg */
Lines 390-396 int qdepends_main_vdb(const char *depend Link Here
390
				continue;
390
				continue;
391
391
392
			IF_DEBUG(warn("matched %s/%s", dentry->d_name, de->d_name));
392
			IF_DEBUG(warn("matched %s/%s", dentry->d_name, de->d_name));
393
			snprintf(buf, sizeof(buf), "%s%s/%s/%s/%s", portroot, portvdb,
393
			snprintf(buf, sizeof(buf), "%s/%s/%s/%s", portvdb,
394
			         dentry->d_name, de->d_name, depend_file);
394
			         dentry->d_name, de->d_name, depend_file);
395
395
396
			/* >=portage-2.1_pre3 wont ensure these files always exist.
396
			/* >=portage-2.1_pre3 wont ensure these files always exist.
Lines 421-427 int qdepends_main_vdb(const char *depend Link Here
421
				printf("%s%s/%s%s%s: ", BOLD, dentry->d_name, BLUE, de->d_name, NORM);
421
				printf("%s%s/%s%s%s: ", BOLD, dentry->d_name, BLUE, de->d_name, NORM);
422
			}
422
			}
423
423
424
			snprintf(buf, sizeof(buf), "%s%s/%s/%s/USE", portroot, portvdb,
424
			snprintf(buf, sizeof(buf), "%s/%s/%s/USE", portvdb,
425
			         dentry->d_name, de->d_name);
425
			         dentry->d_name, de->d_name);
426
426
427
			if (access(buf, R_OK) != 0) {
427
			if (access(buf, R_OK) != 0) {
Lines 468-477 int qdepends_vdb_deep(const char *depend Link Here
468
	char depend[16384], use[8192];
468
	char depend[16384], use[8192];
469
	dep_node *dep_tree;
469
	dep_node *dep_tree;
470
470
471
	if (chdir(portroot))
471
	if (chdir(portvdb))
472
		errp("could not chdir(%s) for ROOT", portroot);
472
		errp("could not chdir(%s) for VDB", portvdb);
473
473
474
	if (chdir(portvdb) != 0 || (dir = opendir(".")) == NULL)
474
	if ((dir = opendir(".")) == NULL)
475
		return EXIT_FAILURE;
475
		return EXIT_FAILURE;
476
476
477
	/* open /var/db/pkg */
477
	/* open /var/db/pkg */
Lines 487-493 int qdepends_vdb_deep(const char *depend Link Here
487
				continue;
487
				continue;
488
488
489
			IF_DEBUG(warn("matched %s/%s", dentry->d_name, de->d_name));
489
			IF_DEBUG(warn("matched %s/%s", dentry->d_name, de->d_name));
490
			snprintf(buf, sizeof(buf), "%s%s/%s/%s/%s", portroot, portvdb,
490
			snprintf(buf, sizeof(buf), "%s/%s/%s/%s", portvdb,
491
			         dentry->d_name, de->d_name, depend_file);
491
			         dentry->d_name, de->d_name, depend_file);
492
492
493
			if (access(buf, R_OK) != 0)
493
			if (access(buf, R_OK) != 0)
Lines 504-510 int qdepends_vdb_deep(const char *depend Link Here
504
			IF_DEBUG(puts(depend));
504
			IF_DEBUG(puts(depend));
505
			IF_DEBUG(dep_dump_tree(dep_tree));
505
			IF_DEBUG(dep_dump_tree(dep_tree));
506
506
507
			snprintf(buf, sizeof(buf), "%s%s/%s/%s/USE", portroot, portvdb,
507
			snprintf(buf, sizeof(buf), "%s/%s/%s/USE", portvdb,
508
			         dentry->d_name, de->d_name);
508
			         dentry->d_name, de->d_name);
509
			assert(eat_file(buf, use, sizeof(use)) == 1);
509
			assert(eat_file(buf, use, sizeof(use)) == 1);
510
			for (ptr = use; *ptr; ++ptr)
510
			for (ptr = use; *ptr; ++ptr)
(-)portage-utils-20070115/qfile.c (-5 / +3 lines)
Lines 600-615 int qfile_main(int argc, char **argv) Link Here
600
		if (nb_of_queries < 0)
600
		if (nb_of_queries < 0)
601
			goto exit;
601
			goto exit;
602
602
603
		if (chdir(portroot)
603
		if (chdir(portvdb) != 0 || (dir = opendir(".")) == NULL) {
604
				|| chdir(portvdb) != 0
604
			warnp("could not chdir(%s) for installed packages database", portvdb);
605
				|| (dir = opendir(".")) == NULL) {
606
			warnp("could not chdir(ROOT/%s) for installed packages database", portvdb);
607
			goto exit;
605
			goto exit;
608
		}
606
		}
609
607
610
		/* Iteration over VDB categories */
608
		/* Iteration over VDB categories */
611
		while (nb_of_queries && (dentry = q_vdb_get_next_dir(dir))) {
609
		while (nb_of_queries && (dentry = q_vdb_get_next_dir(dir))) {
612
			snprintf(path, _Q_PATH_MAX, "%s/%s/%s", qfile_args->real_root, portvdb, dentry->d_name);
610
			snprintf(path, _Q_PATH_MAX, "%s/%s", portvdb, dentry->d_name);
613
			qfile(path, (assume_root_prefix ? root_prefix : NULL), qfile_args);
611
			qfile(path, (assume_root_prefix ? root_prefix : NULL), qfile_args);
614
		}
612
		}
615
613
(-)portage-utils-20070115/qgrep.c (-4 / +72 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-39 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;
39
	short myerror = 0, repo = 0, bad_overlay=0;
40
	char overlay_name[64], repo_search[64];
37
	char *p;
41
	char *p;
38
	char do_count, do_regex;
42
	char do_count, do_regex;
39
	char show_filename;
43
	char show_filename;
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 = first_overlay;
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 75-80 int qgrep_main(int argc, char **argv) Link Here
75
		FILE *newfp;
98
		FILE *newfp;
76
		if ((p = strchr(ebuild, '\n')) != NULL)
99
		if ((p = strchr(ebuild, '\n')) != NULL)
77
			*p = 0;
100
			*p = 0;
101
102
		/* find the overlay, we're working on, and change to the
103
		 * corresponding (location|cache) directory */
104
		if ((p = strchr(ebuild, ':'))) {
105
			/* delete the ::overlay */
106
			*p = 0;
107
108
			/* restrict the search to one overlay if the users wants it */
109
			if (repo && strncmp(repo_search, p+2, sizeof(repo_search)))
110
				continue;
111
			if (bad_overlay && !strncmp(overlay_name, p+2, sizeof(overlay_name)))
112
				continue;
113
			else {
114
				if (strncmp(overlay_name, p+2, sizeof(overlay_name))) {
115
					overlay_tmp=first_overlay;
116
					do {
117
						if (!strncmp(overlay_tmp->name, p+2, sizeof(overlay_tmp->name)))
118
							break;
119
					} while ((overlay_tmp=overlay_tmp->next));
120
121
					if (overlay_tmp) {
122
						cur_overlay = overlay_tmp;
123
						if (chdir(cur_overlay->path) != 0) {
124
							warnp("chdir to '%s' failed", cur_overlay->path);
125
							myerror = 1;
126
						} else
127
							bad_overlay = 0;
128
					} else
129
						myerror = 1;
130
131
					strncpy(overlay_name, p+2, sizeof(overlay_name));
132
				}
133
			}
134
		} else
135
			myerror=1;
136
137
		if (myerror) {
138
			if (!reinitialize)
139
				warnf("(cache update pending) %s : Unknown overlay", overlay_name);
140
			bad_overlay = 1;
141
			myerror = 0;
142
			reinitialize = 1;
143
			continue;
144
		}
145
78
		if ((newfp = fopen(ebuild, "r")) != NULL) {
146
		if ((newfp = fopen(ebuild, "r")) != NULL) {
79
			unsigned int lineno = 0;
147
			unsigned int lineno = 0;
80
			count = 0;
148
			count = 0;
Lines 102-108 int qgrep_main(int argc, char **argv) Link Here
102
				count++;
170
				count++;
103
				if (do_count) continue;
171
				if (do_count) continue;
104
				if (verbose || show_filename) {
172
				if (verbose || show_filename) {
105
					printf("%s:", ebuild);
173
					printf("%s::%s:", cur_overlay->name, ebuild);
106
					if (verbose > 1) printf("%d:", lineno);
174
					if (verbose > 1) printf("%d:", lineno);
107
					printf(" ");
175
					printf(" ");
108
				}
176
				}
Lines 110-116 int qgrep_main(int argc, char **argv) Link Here
110
			}
178
			}
111
			fclose(newfp);
179
			fclose(newfp);
112
			if (do_count && count) {
180
			if (do_count && count) {
113
				if (verbose || show_filename) printf("%s:", ebuild);
181
				if (verbose || show_filename) printf("%s::%s:", cur_overlay->name, ebuild);
114
				printf("%d", count);
182
				printf("%d", count);
115
				puts("");
183
				puts("");
116
			}
184
			}
(-)portage-utils-20070115/qsearch.c (-11 / +121 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
	char debuild[126] = "";
48
	short repo = 0;
49
	char repo_search[64];
50
	char *p, *q, *str, overlay_name[64];
44
	char *search_me = NULL;
51
	char *search_me = NULL;
45
	char show_homepage = 0, show_name_only = 0;
52
	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;
53
	char search_desc = 0, search_all = 0, search_name = 1, search_cache = CACHE_EBUILD;
47
	const char *search_vars[] = { "DESCRIPTION=", "HOMEPAGE=" };
54
	const char *search_vars[] = { "DESCRIPTION=", "HOMEPAGE=" };
48
	size_t search_len;
55
	size_t search_len;
49
	int i, idx=0;
56
	overlay_t *cur_overlay, *overlay_tmp;
57
	int i, idx=0, myerror=0, bad_overlay=0;
58
59
	cur_overlay = first_overlay;
60
	overlay_name[0] = 0;
61
	repo_search[0] = 0;
62
	str = NULL;
50
63
51
	DBG("argc=%d argv[0]=%s argv[1]=%s",
64
	DBG("argc=%d argv[0]=%s argv[1]=%s",
52
	    argc, argv[0], argc > 1 ? argv[1] : "NULL?");
65
	    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)
69
		COMMON_GETOPTS_CASES(qsearch)
57
		case 'a': search_all = 1; break;
70
		case 'a': search_all = 1; break;
58
		case 'c': search_cache = CACHE_METADATA; break;
71
		case 'c': search_cache = CACHE_METADATA; break;
72
		case 'o': repo = 1; strncpy(repo_search, optarg, sizeof(repo_search)); break;
73
		case 'p': show_path_to_ebuild = 1; break;
59
		case 's': search_desc = 0; search_name = 1; break;
74
		case 's': search_desc = 0; search_name = 1; break;
60
		case 'S': search_desc = 1; search_name = 0; break;
75
		case 'S': search_desc = 1; search_name = 0; break;
61
		case 'N': show_name_only = 1; break;
76
		case 'N': show_name_only = 1; break;
Lines 63-68 int qsearch_main(int argc, char **argv) Link Here
63
		}
78
		}
64
	}
79
	}
65
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
		if (search_cache == CACHE_METADATA && !strncmp(cur_overlay->cache,"/var/empty",sizeof(cur_overlay->cache)))
89
			err("No cache defined for the '%s' overlay", cur_overlay->name);
90
	}
91
92
66
	if (search_all) {
93
	if (search_all) {
67
		search_desc = 1;
94
		search_desc = 1;
68
		search_name = 0;
95
		search_name = 0;
Lines 86-91 int qsearch_main(int argc, char **argv) Link Here
86
		if (!ebuild[0])
113
		if (!ebuild[0])
87
			continue;
114
			continue;
88
115
116
		/* find the overlay, we're working on, and change to the
117
		 * corresponding (location|cache) directory */
118
		if ((p = strchr(ebuild, ':'))) {
119
			/* separator is '::' */
120
			/* restrict the search to one overlay if the users wants it */
121
			if (repo && strncmp(repo_search, p+2, sizeof(repo_search)))
122
				continue;
123
			if (bad_overlay && !strncmp(overlay_name, p+2, sizeof(overlay_name)))
124
				continue;
125
			if (strncmp(overlay_name, p+2, sizeof(overlay_name))) {
126
				last[0] = 0;
127
				overlay_tmp=first_overlay;
128
				do {
129
					if (!strncmp(overlay_tmp->name, p+2, sizeof(overlay_tmp->name)))
130
						break;
131
				} while ((overlay_tmp=overlay_tmp->next));
132
133
				if (overlay_tmp) {
134
					cur_overlay=overlay_tmp;
135
					switch (search_cache) {
136
					case CACHE_EBUILD:
137
						if (chdir(cur_overlay->path) != 0) {
138
							warnp("chdir to '%s' failed", cur_overlay->path);
139
							myerror = 1;
140
							continue;
141
						} else
142
							bad_overlay = 0;
143
						break;
144
					case CACHE_METADATA:
145
						if (chdir(cur_overlay->cache) != 0) {
146
							warnp("chdir to '%s' failed, skipping the %s repository", cur_overlay->cache, cur_overlay->name);
147
							myerror = 1;
148
							continue;
149
						} else
150
							bad_overlay = 0;
151
						break;
152
					}
153
				} else
154
					myerror = 1;
155
				strncpy(overlay_name, p+2, sizeof(overlay_name));
156
			}
157
		} else
158
			myerror++;
159
160
		if (myerror) {
161
			if (!reinitialize)
162
				warnf("(cache update pending) %s : Unknown overlay", overlay_name);
163
			bad_overlay = 1;
164
			myerror = 0;
165
			reinitialize = 1;
166
			continue;
167
		}
168
169
89
		switch (search_cache) {
170
		switch (search_cache) {
90
171
91
		case CACHE_METADATA: {
172
		case CACHE_METADATA: {
Lines 93-103 int qsearch_main(int argc, char **argv) Link Here
93
			if ((pcache = cache_read_file(ebuild)) != NULL) {
174
			if ((pcache = cache_read_file(ebuild)) != NULL) {
94
				if ((strcmp(pcache->atom->PN, last)) != 0) {
175
				if ((strcmp(pcache->atom->PN, last)) != 0) {
95
					strncpy(last, pcache->atom->PN, sizeof(last));
176
					strncpy(last, pcache->atom->PN, sizeof(last));
96
					if ((rematch(search_me, (search_desc ? pcache->DESCRIPTION : ebuild), REG_EXTENDED | REG_ICASE)) == 0)
177
					if (!search_all && (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,
178
						cache_free(pcache);
98
						       pcache->atom->PN, NORM,
179
						continue;
99
						       (show_name_only ? "" :
180
					}
100
						        (show_homepage ? pcache->HOMEPAGE : pcache->DESCRIPTION)));
181
182
					if (show_path_to_ebuild) {
183
						/* delete the ::overlay */
184
						*p = 0;
185
						strncpy(debuild, ebuild, sizeof(debuild));
186
						printf("%s%s/%s%s%s::%s\t %s%s/%s/\n",
187
						BOLD, pcache->atom->CATEGORY,
188
						BLUE, pcache->atom->PN,
189
						YELLOW, pcache->atom->OVERLAY, NORM,
190
						cur_overlay->path, dirname(debuild));
191
					} else {
192
						printf("%s%s/%s%s%s::%s %s%s\n",
193
						BOLD, pcache->atom->CATEGORY,
194
						BLUE, pcache->atom->PN,
195
						YELLOW, pcache->atom->OVERLAY, NORM,
196
						(show_name_only ? "" :
197
						(show_homepage ? pcache->HOMEPAGE : pcache->DESCRIPTION)));
198
					}
101
				}
199
				}
102
				cache_free(pcache);
200
				cache_free(pcache);
103
			} else {
201
			} else {
Lines 110-115 int qsearch_main(int argc, char **argv) Link Here
110
208
111
		case CACHE_EBUILD: {
209
		case CACHE_EBUILD: {
112
			FILE *ebuildfp;
210
			FILE *ebuildfp;
211
			/* delete the ::overlay */
212
			*p = 0;
213
113
			str = xstrdup(ebuild);
214
			str = xstrdup(ebuild);
114
			p = (char *) dirname(str);
215
			p = (char *) dirname(str);
115
216
Lines 134-142 int qsearch_main(int argc, char **argv) Link Here
134
							/* doing operations with them. */
235
							/* doing operations with them. */
135
							strncpy(dp, p, sizeof(dp));
236
							strncpy(dp, p, sizeof(dp));
136
							strncpy(bp, p, sizeof(bp));
237
							strncpy(bp, p, sizeof(bp));
137
							printf("%s%s/%s%s%s %s\n",
238
							strncpy(debuild, ebuild, sizeof(debuild));
138
								BOLD, dirname(dp), BLUE, basename(bp), NORM,
239
							if (show_path_to_ebuild) {
240
								printf("%s%s/%s%s%s::%s\t %s%s/%s/\n",
241
								BOLD, dirname(dp), BLUE, basename(bp),
242
								YELLOW, cur_overlay->name, NORM,
243
								cur_overlay->path, dirname(debuild));
244
							} else {
245
								printf("%s%s/%s%s%s::%s %s%s\n",
246
								BOLD, dirname(dp), BLUE, basename(bp),
247
								YELLOW, cur_overlay->name, NORM,
139
								(show_name_only ? "" : q));
248
								(show_name_only ? "" : q));
249
							}
140
							break;
250
							break;
141
						}
251
						}
142
					}
252
					}
(-)portage-utils-20070115/quse.c (-91 / +207 lines)
Lines 1-7 Link Here
1
/*
1
/*
2
 * Copyright 2005-2006 Gentoo Foundation
2
 * Copyright 2005-2006 Gentoo Foundation
3
 * Distributed under the terms of the GNU General Public License v2
3
 * Distributed under the terms of the GNU General Public License v2
4
 * $Header: /var/cvsroot/gentoo-projects/portage-utils/quse.c,v 1.55 2007/01/09 13:15:43 vapier Exp $
4
 * $Header: /var/cvsroot/gentoo-projects/portage-utils/quse.c,v 1.54 2006/12/25 16:38:37 solar Exp $
5
 *
5
 *
6
 * Copyright 2005-2006 Ned Ludd        - <solar@gentoo.org>
6
 * Copyright 2005-2006 Ned Ludd        - <solar@gentoo.org>
7
 * Copyright 2005-2006 Mike Frysinger  - <vapier@gentoo.org>
7
 * Copyright 2005-2006 Mike Frysinger  - <vapier@gentoo.org>
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 35-44 static const char *quse_opts_help[] = { Link Here
35
	"Only show package name",
37
	"Only show package name",
36
	COMMON_OPTS_HELP
38
	COMMON_OPTS_HELP
37
};
39
};
38
static const char quse_rcsid[] = "$Id: quse.c,v 1.55 2007/01/09 13:15:43 vapier Exp $";
40
static const char quse_rcsid[] = "$Id: quse.c,v 1.54 2006/12/25 16:38:37 solar 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-205 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=first_overlay;
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>2)
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 (overlay_gentoo && 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 (overlay_gentoo && 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 (overlay_gentoo && 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 (overlay_gentoo && 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
		if (fp[f] != NULL)
160
			fclose(fp[f]);
161
187
162
	/* now scan the desc dir */
188
	/* now scan the desc dir */
163
	snprintf(buf, sizeof(buf), "%s/profiles/desc/", portdir);
189
	cur_overlay=first_overlay;
164
	d = opendir(buf);
190
	do {
165
	while ((de = readdir(d)) != NULL) {
191
		if (repo && strncmp(repo_search, cur_overlay->name, sizeof(repo_search)))
166
		if (strcmp(de->d_name+strlen(de->d_name)-5, ".desc"))
167
			continue;
192
			continue;
168
193
		snprintf(buf, sizeof(buf), "%s/profiles/desc/", cur_overlay->path);
169
		snprintf(buf, sizeof(buf), "%s/profiles/desc/%s", portdir, de->d_name);
194
		if (!(d = opendir(buf))) {
170
		if ((fp[0]=fopen(buf, "r")) == NULL) {
195
			if (verbose>2)
171
			warn("Could not open '%s' for reading; skipping", de->d_name);
196
				warn("Could not open %s -> skipping", buf);
172
			continue;
197
			continue;
173
		}
198
		}
199
		while ((de = readdir(d)) != NULL) {
200
			if (strcmp(de->d_name+strlen(de->d_name)-5, ".desc"))
201
				continue;
174
202
175
		while (fgets(buf, sizeof(buf), fp[0]) != NULL) {
203
			snprintf(buf, sizeof(buf), "%s/profiles/desc/%s", cur_overlay->path, de->d_name);
176
			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);
177
				continue;
206
				continue;
207
			}
178
208
179
			if ((p = strrchr(buf, '\n')) != NULL)
209
			while (fgets(buf, sizeof(buf), fp[0]) != NULL) {
180
				*p = '\0';
210
				if (buf[0] == '#' || buf[0] == '\n')
211
					continue;
181
212
182
			if ((p = strchr(buf, '-')) == NULL) {
213
				if ((p = strrchr(buf, '\n')) != NULL)
214
					*p = '\0';
215
216
				if ((p = strchr(buf, '-')) == NULL) {
183
invalid_line:
217
invalid_line:
184
				warn("Invalid line in '%s': %s", de->d_name, buf);
218
					warn("Invalid line in '%s': %s", de->d_name, buf);
185
				continue;
219
					continue;
186
			}
220
				}
187
			while (p[-1] != ' ' && p[1] != ' ') {
221
				while (p[-1] != ' ' && p[1] != ' ') {
188
				/* maybe the flag has a '-' in it ... */
222
					/* maybe the flag has a '-' in it ... */
189
				if ((p = strchr(p+1, '-')) == NULL)
223
					if ((p = strchr(p+1, '-')) == NULL)
190
					goto invalid_line;
224
						goto invalid_line;
191
			}
225
				}
192
			p[-1] = '\0';
226
				p[-1] = '\0';
193
			p += 2;
227
				p += 2;
194
228
195
			for (i = ind; i < argc; i++)
229
				for (i = ind; i < argc; i++)
196
				if (!strcmp(argv[i], buf))
230
					if (!strcmp(argv[i], buf)) {
197
					printf(" %s%s%s:%s%s%s: %s\n", BOLD, de->d_name, NORM, BLUE, argv[i], NORM, p);
231
						if (overlay_gentoo && cur_overlay == overlay_gentoo)
198
		}
232
							printf(" %s%s%s:%s%s%s: %s\n", BOLD, de->d_name, NORM, BLUE, argv[i], NORM, p);
199
		close(f);
233
						else
200
	}
234
							printf(" (%s) %s%s%s:%s%s%s: %s\n", cur_overlay->name, BOLD, de->d_name, NORM, BLUE, argv[i], NORM, p);
201
	closedir(d);
235
					}
202
236
237
			}
238
			fclose(fp[0]);
239
		}
240
		closedir(d);
241
	} while ((cur_overlay=cur_overlay->next));
203
	return 0;
242
	return 0;
204
}
243
}
205
244
Lines 207-212 int quse_main(int argc, char **argv) Link Here
207
{
246
{
208
	FILE *fp;
247
	FILE *fp;
209
	char *p;
248
	char *p;
249
	short myerror = 0, repo = 0;
250
	char repo_search[64];
251
	char overlay_name[64];
210
252
211
	char buf0[_Q_PATH_MAX];
253
	char buf0[_Q_PATH_MAX];
212
	char buf1[_Q_PATH_MAX];
254
	char buf1[_Q_PATH_MAX];
Lines 217-224 int quse_main(int argc, char **argv) Link Here
217
	const char *search_var = NULL;
259
	const char *search_var = NULL;
218
	const char *search_vars[] = { "IUSE=", "KEYWORDS=", "LICENSE=", search_var };
260
	const char *search_vars[] = { "IUSE=", "KEYWORDS=", "LICENSE=", search_var };
219
	short quse_all = 0;
261
	short quse_all = 0;
220
	int regexp_matching = 1, i, idx = 0;
262
	int regexp_matching = 1, i, idx = 0, bad_overlay = 0;
221
	size_t search_len;
263
	size_t search_len;
264
	overlay_t *cur_overlay, *overlay_tmp;
265
266
	cur_overlay = first_overlay;
267
	overlay_name[0] = 0;
268
	repo_search[0] = 0;
222
269
223
	DBG("argc=%d argv[0]=%s argv[1]=%s",
270
	DBG("argc=%d argv[0]=%s argv[1]=%s",
224
	    argc, argv[0], argc > 1 ? argv[1] : "NULL?");
271
	    argc, argv[0], argc > 1 ? argv[1] : "NULL?");
Lines 227-232 int quse_main(int argc, char **argv) Link Here
227
		switch (i) {
274
		switch (i) {
228
		case 'e': regexp_matching = 0; break;
275
		case 'e': regexp_matching = 0; break;
229
		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;
230
		case 'K': idx = 1; break;
281
		case 'K': idx = 1; break;
231
		case 'L': idx = 2; break;
282
		case 'L': idx = 2; break;
232
		case 'D': idx = -1; break;
283
		case 'D': idx = -1; break;
Lines 235-247 int quse_main(int argc, char **argv) Link Here
235
		COMMON_GETOPTS_CASES(quse)
286
		COMMON_GETOPTS_CASES(quse)
236
		}
287
		}
237
	}
288
	}
238
	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]);
239
		quse_usage(EXIT_FAILURE);
302
		quse_usage(EXIT_FAILURE);
303
	}
240
304
241
	if (idx == -1)
305
	if (idx == -1)
242
		return quse_describe_flag(optind, argc, argv);
306
		return quse_describe_flag(optind, repo, repo_search, argc, argv);
243
307
244
	if (quse_all) optind = argc;
245
	initialize_ebuild_flat();	/* sets our pwd to $PORTDIR */
308
	initialize_ebuild_flat();	/* sets our pwd to $PORTDIR */
246
309
247
	search_len = strlen(search_vars[idx]);
310
	search_len = strlen(search_vars[idx]);
Lines 253-258 int quse_main(int argc, char **argv) Link Here
253
		FILE *newfp;
316
		FILE *newfp;
254
		if ((p = strchr(ebuild, '\n')) != NULL)
317
		if ((p = strchr(ebuild, '\n')) != NULL)
255
			*p = 0;
318
			*p = 0;
319
		if ((p = strchr(ebuild, ':')))
320
		{
321
			/* delete the ::overlay */
322
			*p = 0;
323
			if (repo && strncmp(repo_search, p+2, sizeof(repo_search)))
324
				continue;
325
			if (bad_overlay && !strncmp(overlay_name, p+2, sizeof(overlay_name)))
326
				continue;
327
			else {
328
				if (strncmp(overlay_name, p+2, sizeof(overlay_name))) {
329
					overlay_tmp=first_overlay;
330
					do {
331
						if (!strncmp(overlay_tmp->name, p+2, sizeof(overlay_tmp->name)))
332
							break;
333
					} while ((overlay_tmp=overlay_tmp->next));
334
					if (overlay_tmp)
335
					{
336
						cur_overlay = overlay_tmp;
337
						if (chdir(cur_overlay->path) != 0) {
338
							warnp("chdir to '%s' failed", cur_overlay->path);
339
							myerror=1;
340
						} else
341
							bad_overlay = 0;
342
					} else
343
						myerror=1;
344
					strncpy(overlay_name, p+2, sizeof(overlay_name));
345
				}
346
			}
347
		} else
348
			myerror=1;
349
350
		if (myerror) {
351
			if (!reinitialize)
352
				warnf("(cache update pending) %s : Unknown overlay", overlay_name);
353
			bad_overlay = 1;
354
			myerror = 0;
355
			reinitialize = 1;
356
			continue;
357
		}
358
359
		if ((quse_all) && optind!=argc) {
360
			for (i=optind;i<argc;i++)
361
				if ((strstr(ebuild,argv[i])))
362
					break;
363
			if (i==argc)
364
				continue;
365
		}
366
256
		if ((newfp = fopen(ebuild, "r")) != NULL) {
367
		if ((newfp = fopen(ebuild, "r")) != NULL) {
257
			unsigned int lineno = 0;
368
			unsigned int lineno = 0;
258
			char revision[sizeof(buf0)];
369
			char revision[sizeof(buf0)];
Lines 376-390 int quse_main(int argc, char **argv) Link Here
376
					if (verbose > 3)
487
					if (verbose > 3)
377
						printf("%s %s %s ", *user ? user : "MISSING", *revision ? revision : "MISSING", *date ? date : "MISSING");
488
						printf("%s %s %s ", *user ? user : "MISSING", *revision ? revision : "MISSING", *date ? date : "MISSING");
378
489
379
					printf("%s%s%s ", CYAN, ebuild, NORM);
490
					printf("%s%s::%s%s ", CYAN, cur_overlay->name, ebuild, NORM);
380
					print_highlighted_use_flags(&buf0[search_len+1], optind, argc, argv);
491
					if (quse_all)
492
                                                print_highlighted_use_flags(&buf0[search_len+1], argc, argc, argv);
493
					else
494
						print_highlighted_use_flags(&buf0[search_len+1], optind, argc, argv);
381
					puts(NORM);
495
					puts(NORM);
382
					if (verbose > 1) {
496
					if (verbose > 1) {
383
						char **ARGV = NULL;
497
						char **ARGV = NULL;
384
						int ARGC = 0;
498
						int ARGC = 0;
385
						makeargv(&buf0[search_len+1], &ARGC, &ARGV);
499
						makeargv(&buf0[search_len+1], &ARGC, &ARGV);
386
						if (ARGC > 0) {
500
						if (ARGC > 0) {
387
							quse_describe_flag(1, ARGC, ARGV);
501
							quse_describe_flag(1, 0, repo_search, ARGC, ARGV);
388
							for (i = 0; i < ARGC; i++)
502
							for (i = 0; i < ARGC; i++)
389
								free(ARGV[i]);
503
								free(ARGV[i]);
390
							free(ARGV);
504
							free(ARGV);
Lines 401-406 int quse_main(int argc, char **argv) Link Here
401
		}
515
		}
402
	}
516
	}
403
	fclose(fp);
517
	fclose(fp);
518
	if (idx == 3)
519
		free(search_vars[idx]);
404
	return EXIT_SUCCESS;
520
	return EXIT_SUCCESS;
405
}
521
}
406
522

Return to bug 154405