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-20061007/applets.h (-18 / +18 lines)
Lines 47-70 struct applet_t { Link Here
47
	const char *desc;
47
	const char *desc;
48
} applets[] = {
48
} applets[] = {
49
	/* q must always be the first applet */
49
	/* q must always be the first applet */
50
	{"q",         q_main,         "<applet> <args>", "virtual applet"},
50
	{"q",         q_main,         "<applet> <args>", "virtual applet"		},
51
	{"qatom",     qatom_main,     "<pkg>",           "split atom strings"},
51
	{"qatom",     qatom_main,     "<pkg>",           "split atom strings"		},
52
	{"qcache",    qcache_main,    "<action> <args>", "search the metadata cache"},
52
	{"qcache",    qcache_main,    "<action> <args>", "search the metadata cache"	},
53
	{"qcheck",    qcheck_main,    "<pkgname>",       "verify mtimes/digests"},
53
	{"qcheck",    qcheck_main,    "<pkgname>",       "verify mtimes/digests"	},
54
	{"qdepends",  qdepends_main,  "<pkgname>",       "show dependency info"},
54
	{"qdepends",  qdepends_main,  "<pkgname>",       "show dependency info"		},
55
	{"qfile",     qfile_main,     "<filename>",      "list all pkgs owning files"},
55
	{"qfile",     qfile_main,     "<filename>",      "list all pkgs owning files"	},
56
	{"qglsa",     qglsa_main,     "<action> <list>", "check GLSAs against system"},
56
	{"qgrep",     qgrep_main,     "<misc args>",     "grep in ebuilds"		},
57
	{"qgrep",     qgrep_main,     "<misc args>",     "grep in ebuilds"},
57
	{"qlist",     qlist_main,     "<pkgname>",       "list files owned by pkgname"	},
58
	{"qlist",     qlist_main,     "<pkgname>",       "list files owned by pkgname"},
58
	{"qlop",      qlop_main,      "<pkgname>",       "paludis log analyzer"		},
59
	{"qlop",      qlop_main,      "<pkgname>",       "emerge log analyzer"},
59
	{"qpkg",      qpkg_main,      "<misc args>",     "manipulate Gentoo binpkgs"	},
60
	{"qmerge",    qmerge_main,    "<pkgnames>",      "fetch and merge binary package"},
60
	{"qsearch",   qsearch_main,   "<regex>",         "search pkgname/desc"		},
61
	{"qpkg",      qpkg_main,      "<misc args>",     "manipulate Gentoo binpkgs"},
61
	{"qsize",     qsize_main,     "<pkgname>",       "calculate size usage"		},
62
	{"qpy",      qpy_main,      "<misc args>",     "python interface"},
62
	{"qtbz2",     qtbz2_main,     "<misc args>",     "manipulate tbz2 packages"	},
63
	{"qsearch",   qsearch_main,   "<regex>",         "search pkgname/desc"},
63
	{"quse",      quse_main,      "<useflag>",       "find pkgs using useflags"	},
64
	{"qsize",     qsize_main,     "<pkgname>",       "calculate size usage"},
64
	{"qxpak",     qxpak_main,     "<misc args>",     "manipulate xpak archives"	},
65
	{"qtbz2",     qtbz2_main,     "<misc args>",     "manipulate tbz2 packages"},
65
	{"qmerge",    qmerge_main,    "<pkgnames>",      "fetch and merge binary package"},	
66
	{"quse",      quse_main,      "<useflag>",       "find pkgs using useflags"},
66
	{"qglsa",     qglsa_main,     "<action> <list>", NULL				},		/* "check GLSAs against system" */
67
	{"qxpak",     qxpak_main,     "<misc args>",     "manipulate xpak archives"},
67
	{"qpy",       qpy_main,       "<misc args>",     NULL				},		/* "python interface" */
68
68
69
69
70
	/* aliases for equery capatability */
70
	/* aliases for equery capatability */
(-)portage-utils-20061007/main.c (-62 / +168 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 200-209 static void usage(int status, const char Link Here
200
	for (i = 0; opts[i].name; ++i) {
209
	for (i = 0; opts[i].name; ++i) {
201
		assert(help[i] != NULL); /* this assert is a life saver when adding new applets. */
210
		assert(help[i] != NULL); /* this assert is a life saver when adding new applets. */
202
		if (opts[i].has_arg == no_argument)
211
		if (opts[i].has_arg == no_argument)
203
			printf("  -%c, --%-15s%s*%s %s\n", opts[i].val,
212
			printf("  -%c, --%-16s%s*%s %s\n", opts[i].val,
204
				opts[i].name, RED, NORM, _(help[i]));
213
				opts[i].name, RED, NORM, _(help[i]));
205
		else
214
		else
206
			printf("  -%c, --%-8s %s<arg>%s %s*%s %s\n", opts[i].val,
215
			printf("  -%c, --%-9s %s<arg>%s %s*%s %s\n", opts[i].val,
207
				opts[i].name, DKBLUE, NORM, RED, NORM, _(help[i]));
216
				opts[i].name, DKBLUE, NORM, RED, NORM, _(help[i]));
208
	}
217
	}
209
	exit(status);
218
	exit(status);
Lines 465-481 char *strincr_var(const char *name, char Link Here
465
	return (char *) value;
474
	return (char *) value;
466
}
475
}
467
476
477
void initialize_overlays (char portdir_overlay[])
478
{
479
	short merror = 0;
480
	char buf[BUFSIZE], file[_Q_PATH_MAX], *s, *p, *t;
481
	overlay_t *cur_overlay;
482
	FILE *repo_nameFP;
483
	s = portdir_overlay;
484
	cur_overlay = overlay_gentoo;
485
486
	while (*s) {
487
		cur_overlay->next = (overlay_t *) xmalloc ( sizeof (*cur_overlay->next));
488
		cur_overlay = cur_overlay->next;
489
		cur_overlay->next = NULL;
490
491
		if ( (p=strchr(s,' ')))
492
			*p = 0;
493
494
		strncpy(cur_overlay->path, s, sizeof(cur_overlay->path));
495
496
		/* find the name for the overlay */
497
		strncpy(file, cur_overlay->path, _Q_PATH_MAX);
498
		strncat(file, "/profiles/repo_name", _Q_PATH_MAX);
499
		if (( repo_nameFP = fopen(file, "r") ))
500
		{
501
			if ( ! ( fgets(buf, sizeof(buf),repo_nameFP)) )
502
				merror++;
503
504
			rmspace(buf);
505
			if ( (t = strchr(buf,'\n')))
506
				*t = 0;
507
508
			strncpy(cur_overlay->name, buf, sizeof(cur_overlay->name));
509
510
			fclose(repo_nameFP);
511
512
		} else 
513
			merror++;
514
515
		if (merror) {
516
			/* delete trailing '/' */
517
			t = cur_overlay->path + strlen(cur_overlay->path) - 1;
518
			if ( *t == '/' )
519
				*t = 0;
520
521
			strncpy(cur_overlay->name, basename(cur_overlay->path), sizeof(cur_overlay->name));
522
			merror=0;
523
		}
524
525
		if (p)
526
			s = p+1;
527
		else
528
			break;
529
	}
530
	
531
}
532
533
468
void initialize_portage_env(void)
534
void initialize_portage_env(void)
469
{
535
{
470
	char nocolor = 0;
536
	char nocolor = 0;
471
	int i, f;
537
	int i, f;
472
	struct stat st;
538
	struct stat st;
473
	FILE *fp;
539
	FILE *fp;
540
	char tmp_portdir[_Q_PATH_MAX];
541
	char portdir_overlay[2048] = "";
542
474
	char buf[BUFSIZE], *s, *p;
543
	char buf[BUFSIZE], *s, *p;
475
544
476
	char profile[_Q_PATH_MAX], portage_file[_Q_PATH_MAX];
545
	char profile[_Q_PATH_MAX], portage_file[_Q_PATH_MAX];
546
477
	const char *files[] = {portage_file, "/etc/make.globals", "/etc/make.conf"};
547
	const char *files[] = {portage_file, "/etc/make.globals", "/etc/make.conf"};
478
	typedef enum { _Q_BOOL, _Q_STR, _Q_ISTR } var_types;
548
	typedef enum { _Q_BOOL, _Q_STR, _Q_ISTR } var_types;
549
	
479
	struct {
550
	struct {
480
		const char *name;
551
		const char *name;
481
		const size_t name_len;
552
		const size_t name_len;
Lines 483-501 void initialize_portage_env(void) Link Here
483
		char *value;
554
		char *value;
484
		const size_t value_len;
555
		const size_t value_len;
485
	} vars_to_read[] = {
556
	} vars_to_read[] = {
486
		{"ACCEPT_LICENSE", 14, _Q_STR,  accept_license, sizeof(accept_license)},
557
		{"ACCEPT_LICENSE",	14, _Q_STR,	accept_license,		 sizeof(accept_license)		},
487
		{"INSTALL_MASK", 12, _Q_ISTR,  install_mask, sizeof(install_mask)},
558
		{"INSTALL_MASK",	12, _Q_ISTR,	install_mask,		 sizeof(install_mask)		},
488
		{"ARCH",    4, _Q_STR,  portarch, sizeof(portarch)},
559
		{"ARCH",		4, _Q_STR,	portarch,		 sizeof(portarch)		},
489
		{"CONFIG_PROTECT",    14, _Q_STR,  config_protect, sizeof(config_protect)},
560
		{"CONFIG_PROTECT",	14, _Q_STR,	config_protect,		 sizeof(config_protect)		},
490
		{"NOCOLOR", 7, _Q_BOOL, &nocolor, 1},
561
		{"NOCOLOR",		7, _Q_BOOL,	&nocolor,		 1				},
491
		{"FEATURES",8, _Q_ISTR,  features, sizeof(features)},
562
		{"FEATURES",		8, _Q_ISTR,	features,		 sizeof(features)		},
492
		{"PORTDIR", 7, _Q_STR,  portdir, sizeof(portdir)},
563
		{"PORTDIR",		7, _Q_STR,	tmp_portdir,		 sizeof(tmp_portdir)		},
493
		{"PORTAGE_BINHOST",   15, _Q_STR,  binhost, sizeof(binhost)},
564
		{"PORTDIR_OVERLAY",	15, _Q_ISTR,	portdir_overlay,	 sizeof(portdir_overlay)	},
494
		{"PORTAGE_TMPDIR",    14, _Q_STR,  port_tmpdir, sizeof(port_tmpdir)},
565
		{"PORTAGE_BINHOST",	15, _Q_STR,	binhost,		 sizeof(binhost)		},
495
		{"PKGDIR",  6, _Q_STR,  pkgdir, sizeof(pkgdir)},
566
		{"PORTAGE_TMP",		9, _Q_STR,	port_tmpdir,		 sizeof(port_tmpdir)		},
496
		{"ROOT",    4, _Q_STR,  portroot, sizeof(portroot)}
567
		{"PKGDIR",		6, _Q_STR,	pkgdir,			 sizeof(pkgdir)			},
568
		{"ROOT",		4, _Q_STR,	portroot,		 sizeof(portroot)		}
497
	};
569
	};
498
570
571
	overlay_gentoo = (overlay_t*) xmalloc(sizeof(*overlay_gentoo));
572
	strcpy(overlay_gentoo->name,"gentoo");
573
	strcpy(overlay_gentoo->path,"/usr/portage");
574
	overlay_gentoo->next = NULL;
575
576
499
	if ((p = strchr(portroot, '/')) != NULL)
577
	if ((p = strchr(portroot, '/')) != NULL)
500
		if (strlen(p) != 1)
578
		if (strlen(p) != 1)
501
			strncat(portroot, "/", sizeof(portroot));
579
			strncat(portroot, "/", sizeof(portroot));
Lines 587-592 void initialize_portage_env(void) Link Here
587
		no_colors();
665
		no_colors();
588
	else
666
	else
589
		color_remap();
667
		color_remap();
668
669
670
	strncpy(overlay_gentoo->path, tmp_portdir, sizeof(overlay_gentoo->path));
671
672
	/* now we initiliase the overlay chained list with overlay_gentoo the first 'item'  */
673
	initialize_overlays(portdir_overlay);
674
590
}
675
}
591
676
592
enum {
677
enum {
Lines 615-633 const char *initialize_flat(int cache_ty Link Here
615
	int a, b, c, d, e, i;
700
	int a, b, c, d, e, i;
616
	int frac, secs, count;
701
	int frac, secs, count;
617
	FILE *fp;
702
	FILE *fp;
703
	overlay_t *cur_overlay;
618
704
619
	a = b = c = d = e = i = 0;
705
	a = b = c = d = e = i = 0;
620
	count = frac = secs = 0;
706
	count = frac = secs = 0;
707
	cur_overlay = overlay_gentoo;
621
708
622
	cache_file = (cache_type == CACHE_EBUILD ? CACHE_EBUILD_FILE : CACHE_METADATA_FILE);
709
	cache_file = (cache_type == CACHE_EBUILD ? CACHE_EBUILD_FILE : CACHE_METADATA_FILE);
623
710
624
	if (chdir(portdir) != 0) {
711
	if (chdir(overlay_gentoo->path) != 0) {
625
		warnp("chdir to PORTDIR '%s' failed", portdir);
712
		warnp("chdir to PORTDIR '%s' failed", overlay_gentoo->path);
626
		goto ret;
713
		goto ret;
627
	}
714
	}
628
715
629
	if (cache_type == CACHE_METADATA && chdir(portcachedir) != 0) {
716
	if (cache_type == CACHE_METADATA && chdir(portcachedir) != 0) {
630
		warnp("chdir to portage cache '%s/%s' failed", portdir, portcachedir);
717
		warnp("chdir to paludis cache '%s/%s' failed", overlay_gentoo->path, portcachedir);
631
		goto ret;
718
		goto ret;
632
	}
719
	}
633
720
Lines 643-706 const char *initialize_flat(int cache_ty Link Here
643
730
644
	unlink(cache_file);
731
	unlink(cache_file);
645
	if (errno != ENOENT) {
732
	if (errno != ENOENT) {
646
		warnfp("unlinking '%s/%s' failed", portdir, cache_file);
733
		warnfp("unlinking '%s/%s' failed", overlay_gentoo->path, cache_file);
647
		goto ret;
734
		goto ret;
648
	}
735
	}
649
736
650
	if ((fp = fopen(cache_file, "w")) == NULL) {
737
	if ((fp = fopen(cache_file, "w")) == NULL) {
651
		warnfp("opening '%s/%s' failed", portdir, cache_file);
738
		warnfp("opening '%s/%s' failed", overlay_gentoo->path, cache_file);
652
		goto ret;
739
		goto ret;
653
	}
740
	}
654
741
655
	gettimeofday(&start, NULL);
742
	gettimeofday(&start, NULL);
656
743
657
	if ((a = scandir(".", &category, filter_hidden, alphasort)) < 0)
744
	do {
658
		goto ret;
745
		if ( cur_overlay == overlay_gentoo || chdir(cur_overlay->path) == 0) {
659
746
			if ((a = scandir(".", &category, filter_hidden, alphasort)) < 0)
660
	for (i = 0 ; i < a; i++) {
661
		stat(category[i]->d_name, &st);
662
		if (!S_ISDIR(st.st_mode))
663
			continue;
664
		if (strchr(category[i]->d_name, '-') == NULL)
665
			if ((strncmp(category[i]->d_name, "virtual", 7)) != 0)
666
				continue;
747
				continue;
667
748
668
		if ((b = scandir(category[i]->d_name, &pn, filter_hidden, alphasort)) < 0)
749
			for (i = 0 ; i < a; i++) {
669
			continue;
750
				stat(category[i]->d_name, &st);
670
		for (c = 0; c < b; c++) {
751
				if (!S_ISDIR(st.st_mode))
671
			char de[_Q_PATH_MAX];
752
					continue;
753
				if (strchr(category[i]->d_name, '-') == NULL)
754
					if ((strncmp(category[i]->d_name, "virtual", 7)) != 0)
755
						continue;
672
756
673
			snprintf(de, sizeof(de), "%s/%s", category[i]->d_name, pn[c]->d_name);
757
				if ((b = scandir(category[i]->d_name, &pn, filter_hidden, alphasort)) < 0)
758
					continue;
759
				for (c = 0; c < b; c++) {
760
					char de[_Q_PATH_MAX];
674
761
675
			if (stat(de, &st) < 0)
762
					snprintf(de, sizeof(de), "%s/%s", category[i]->d_name, pn[c]->d_name);
676
				continue;
677
763
678
			switch (cache_type) {
764
					if (stat(de, &st) < 0)
679
			case CACHE_EBUILD:
765
						continue;
680
				if (!S_ISDIR(st.st_mode))
766
681
					continue;
767
					switch (cache_type) {
682
				break;
768
					case CACHE_EBUILD:
683
			case CACHE_METADATA:
769
						if (!S_ISDIR(st.st_mode))
684
				if (S_ISREG(st.st_mode))
770
							continue;
685
					fprintf(fp, "%s\n", de);
771
						break;
686
				continue;
772
					case CACHE_METADATA:
687
				break;
773
						if (S_ISREG(st.st_mode))
688
			}
774
							fprintf(fp, "%s\n", de);
689
			if ((e = scandir(de, &eb, filter_hidden, alphasort)) < 0)
775
						continue;
690
				continue;
776
						break;
691
			for (d = 0 ; d < e; d++) {
692
				if ((p = strrchr(eb[d]->d_name, '.')) != NULL)
693
					if (strcmp(p, ".ebuild") == 0) {
694
						count++;
695
						fprintf(fp, "%s/%s/%s\n", category[i]->d_name, pn[c]->d_name, eb[d]->d_name);
696
					}
777
					}
778
					if ((e = scandir(de, &eb, filter_hidden, alphasort)) < 0)
779
						continue;
780
					for (d = 0 ; d < e; d++) {
781
						if ((p = strrchr(eb[d]->d_name, '.')) != NULL)
782
							if (strcmp(p, ".ebuild") == 0) {
783
								count++;
784
								fprintf(fp, "%s::%s/%s/%s\n", cur_overlay->name, category[i]->d_name, pn[c]->d_name, eb[d]->d_name);
785
							}
786
					}
787
					while(d--)
788
						free(eb[d]);
789
					free(eb);
790
				}
791
				while(b--)
792
					free(pn[b]);
793
				free(pn);
697
			}
794
			}
698
			while(d--) free(eb[d]);
795
		} else
699
			free(eb);
796
			warnp("chdir to PORTDIR '%s' failed, skipping the %s repository", cur_overlay->path, cur_overlay->name);
700
		}
797
701
		while(b--) free(pn[b]);
798
	} while ( (cur_overlay = cur_overlay->next));
702
		free(pn);
799
703
	}
704
	fclose(fp);
800
	fclose(fp);
705
	while(a--) free(category[a]);
801
	while(a--) free(category[a]);
706
	free(category);
802
	free(category);
Lines 720-726 const char *initialize_flat(int cache_ty Link Here
720
816
721
	warn("Finished %u entries in %d.%06d seconds", count, secs, frac);
817
	warn("Finished %u entries in %d.%06d seconds", count, secs, frac);
722
	if (secs > 100)
818
	if (secs > 100)
723
		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);
724
ret:
820
ret:
725
	return cache_file;
821
	return cache_file;
726
}
822
}
Lines 729-736 ret: Link Here
729
825
730
void reinitialize_ebuild_flat(void)
826
void reinitialize_ebuild_flat(void)
731
{
827
{
732
	if ((chdir(portdir)) != 0) {
828
	if ((chdir(overlay_gentoo->path)) != 0) {
733
		warnp("chdir to PORTDIR '%s' failed", portdir);
829
		warnp("chdir to PORTDIR '%s' failed", overlay_gentoo->path);
734
		return;
830
		return;
735
	}
831
	}
736
	unlink(CACHE_EBUILD_FILE);
832
	unlink(CACHE_EBUILD_FILE);
Lines 1002-1010 fuckit: Link Here
1002
	return cpf;
1098
	return cpf;
1003
}
1099
}
1004
1100
1101
/* free overlays */
1102
void free_overlays(overlay_t *overlay);
1103
void free_overlays(overlay_t *overlay)
1104
{
1105
	if ( overlay->next )
1106
		free_overlays(overlay->next);
1107
	free(overlay);
1108
}
1109
1005
void cleanup() {
1110
void cleanup() {
1006
	reinitialize_as_needed();
1111
	reinitialize_as_needed();
1007
	free_sets(virtuals);
1112
	free_sets(virtuals);
1113
	free_overlays(overlay_gentoo);
1008
	fclose(stderr);
1114
	fclose(stderr);
1009
}
1115
}
1010
1116
(-)portage-utils-20061007/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-20061007/qcache.c (-10 / +10 lines)
Lines 498-507 int qcache_traverse(void (*func)(qcache_ Link Here
498
	int i, j, k, len, num_cat, num_pkg, num_ebuild;
498
	int i, j, k, len, num_cat, num_pkg, num_ebuild;
499
	struct direct **categories, **packages, **ebuilds;
499
	struct direct **categories, **packages, **ebuilds;
500
500
501
	len = sizeof(char) * (strlen(QCACHE_EDB) + strlen(portdir) + 1);
501
	len = sizeof(char) * (strlen(QCACHE_EDB) + strlen(overlay_gentoo->path) + 1);
502
	catpath = (char *) xmalloc(len);
502
	catpath = (char *) xmalloc(len);
503
	memset(catpath,0,len);
503
	memset(catpath,0,len);
504
	snprintf(catpath,len,"%s%s",QCACHE_EDB,portdir);
504
	snprintf(catpath,len,"%s%s",QCACHE_EDB,overlay_gentoo->path);
505
505
506
	if (-1 == (num_cat = scandir(catpath, &categories, qcache_file_select, alphasort))) {
506
	if (-1 == (num_cat = scandir(catpath, &categories, qcache_file_select, alphasort))) {
507
		err("%s %s", catpath, strerror(errno));
507
		err("%s %s", catpath, strerror(errno));
Lines 513-522 int qcache_traverse(void (*func)(qcache_ Link Here
513
513
514
	/* traverse categories */
514
	/* traverse categories */
515
	for (i = 0; i < num_cat; i++) {
515
	for (i = 0; i < num_cat; i++) {
516
		len = sizeof(char) * (strlen(portdir) + strlen("/") + strlen(categories[i]->d_name) + 1);
516
		len = sizeof(char) * (strlen(overlay_gentoo->path) + strlen("/") + strlen(categories[i]->d_name) + 1);
517
		pkgpath = (char *) xmalloc(len);
517
		pkgpath = (char *) xmalloc(len);
518
		memset(pkgpath, 0, len);
518
		memset(pkgpath, 0, len);
519
		snprintf(pkgpath,len,"%s/%s",portdir,categories[i]->d_name);
519
		snprintf(pkgpath,len,"%s/%s",overlay_gentoo->path,categories[i]->d_name);
520
520
521
		if (-1 == (num_pkg = scandir(pkgpath, &packages, qcache_file_select, alphasort))) {
521
		if (-1 == (num_pkg = scandir(pkgpath, &packages, qcache_file_select, alphasort))) {
522
			warn("%s %s", catpath, strerror(errno));
522
			warn("%s %s", catpath, strerror(errno));
Lines 538-547 int qcache_traverse(void (*func)(qcache_ Link Here
538
538
539
		/* traverse packages */
539
		/* traverse packages */
540
		for (j = 0; j < num_pkg; j++) {
540
		for (j = 0; j < num_pkg; j++) {
541
			len = sizeof(char) * (strlen(portdir) + strlen("/") + strlen(categories[i]->d_name) + strlen("/") + strlen(packages[j]->d_name) + 1);
541
			len = sizeof(char) * (strlen(overlay_gentoo->path) + strlen("/") + strlen(categories[i]->d_name) + strlen("/") + strlen(packages[j]->d_name) + 1);
542
			ebuildpath = (char *) xmalloc(len);
542
			ebuildpath = (char *) xmalloc(len);
543
			memset(ebuildpath, 0, len);
543
			memset(ebuildpath, 0, len);
544
			snprintf(ebuildpath,len,"%s/%s/%s",portdir,categories[i]->d_name,packages[j]->d_name);
544
			snprintf(ebuildpath,len,"%s/%s/%s",overlay_gentoo->path,categories[i]->d_name,packages[j]->d_name);
545
545
546
			if (-1 == (num_ebuild = scandir(ebuildpath, &ebuilds, qcache_ebuild_select, qcache_vercmp))) {
546
			if (-1 == (num_ebuild = scandir(ebuildpath, &ebuilds, qcache_ebuild_select, qcache_vercmp))) {
547
				warn("%s %s", ebuildpath, strerror(errno));
547
				warn("%s %s", ebuildpath, strerror(errno));
Lines 754-763 void qcache_stats(qcache_data *data) { Link Here
754
		for (i = 0; archlist[i]; i++)
754
		for (i = 0; archlist[i]; i++)
755
			architectures++;
755
			architectures++;
756
756
757
		len = sizeof(char) * (strlen(QCACHE_EDB) + strlen(portdir) + 1);
757
		len = sizeof(char) * (strlen(QCACHE_EDB) + strlen(overlay_gentoo->path) + 1);
758
		catpath = (char *) xmalloc(len);
758
		catpath = (char *) xmalloc(len);
759
		memset(catpath,0,len);
759
		memset(catpath,0,len);
760
		snprintf(catpath,len,"%s%s",QCACHE_EDB,portdir);
760
		snprintf(catpath,len,"%s%s",QCACHE_EDB,overlay_gentoo->path);
761
761
762
		if (-1 == (numcat = scandir(catpath, &categories, qcache_file_select, alphasort))) {
762
		if (-1 == (numcat = scandir(catpath, &categories, qcache_file_select, alphasort))) {
763
			err("%s %s", catpath, strerror(errno));
763
			err("%s %s", catpath, strerror(errno));
Lines 914-924 int qcache_init() { Link Here
914
	char *filename;
914
	char *filename;
915
	unsigned int len;
915
	unsigned int len;
916
916
917
	len      = sizeof(char) * (strlen(portdir) + strlen("/profiles/arch.list") + 1);
917
	len      = sizeof(char) * (strlen(overlay_gentoo->path) + strlen("/profiles/arch.list") + 1);
918
	filename = (char *) xmalloc(len);
918
	filename = (char *) xmalloc(len);
919
919
920
	memset(filename,0,len);
920
	memset(filename,0,len);
921
	snprintf(filename,len,"%s/profiles/arch.list",portdir);
921
	snprintf(filename,len,"%s/profiles/arch.list",overlay_gentoo->path);
922
922
923
	if (NULL == (archlist = qcache_read_lines(filename))) {
923
	if (NULL == (archlist = qcache_read_lines(filename))) {
924
		free(filename);
924
		free(filename);
(-)portage-utils-20061007/qgrep.c (-4 / +49 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-66 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
	}
Lines 73-78 int qgrep_main(int argc, char **argv) Link Here
73
		return 1;
86
		return 1;
74
	while ((fgets(ebuild, sizeof(ebuild), fp)) != NULL) {
87
	while ((fgets(ebuild, sizeof(ebuild), fp)) != NULL) {
75
		FILE *newfp;
88
		FILE *newfp;
89
		if ( ( p = strchr(ebuild, ':')))
90
		{
91
			*p = 0;
92
			str = p+2;			/* separator is '::' */
93
			p = ebuild;
94
			if ( repo && strncmp(repo_search, p, sizeof( repo_search)))
95
				continue;
96
			if ( strcmp(overlay_name, p))
97
			{
98
				for ( overlay_tmp=overlay_gentoo ; overlay_tmp->next ; overlay_tmp=overlay_tmp->next )
99
				{
100
					if ( ! strncmp(overlay_tmp->name, p, sizeof(overlay_tmp->name)))
101
						break;
102
				}
103
				if ( ! strncmp(overlay_tmp->name, p, sizeof(overlay_tmp->name)))
104
				{
105
					cur_overlay = overlay_tmp;
106
					if (chdir(cur_overlay->path) != 0) {
107
						warnp("chdir to PORTDIR '%s' failed", cur_overlay->path);
108
						myerror=1;
109
					}
110
				} else 
111
					myerror=1;
112
				if ( myerror) {
113
					myerror=0;
114
					continue;
115
				}
116
				strncpy(overlay_name, cur_overlay->name, sizeof(overlay_name));
117
			}
118
			strcpy(ebuild, str) ;
119
		}
120
76
		if ((p = strchr(ebuild, '\n')) != NULL)
121
		if ((p = strchr(ebuild, '\n')) != NULL)
77
			*p = 0;
122
			*p = 0;
78
		if ((newfp = fopen(ebuild, "r")) != NULL) {
123
		if ((newfp = fopen(ebuild, "r")) != NULL) {
Lines 102-108 int qgrep_main(int argc, char **argv) Link Here
102
				count++;
147
				count++;
103
				if (do_count) continue;
148
				if (do_count) continue;
104
				if (verbose || show_filename) {
149
				if (verbose || show_filename) {
105
					printf("%s:", ebuild); 
150
					printf("%s::%s:", cur_overlay->name, ebuild); 
106
					if (verbose > 1) printf("%d:", lineno);
151
					if (verbose > 1) printf("%d:", lineno);
107
					printf(" ");
152
					printf(" ");
108
				}
153
				}
(-)portage-utils-20061007/qsearch.c (-11 / +78 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 93-103 int qsearch_main(int argc, char **argv) Link Here
93
			if ((pcache = cache_read_file(ebuild)) != NULL) {
106
			if ((pcache = cache_read_file(ebuild)) != NULL) {
94
				if ((strcmp(pcache->atom->PN, last)) != 0) {
107
				if ((strcmp(pcache->atom->PN, last)) != 0) {
95
					strncpy(last, pcache->atom->PN, sizeof(last));
108
					strncpy(last, pcache->atom->PN, sizeof(last));
96
					if ((rematch(search_me, (search_desc ? pcache->DESCRIPTION : ebuild), REG_EXTENDED | REG_ICASE)) == 0)
109
					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,
110
						if ( show_path_to_ebuild) {
98
						       pcache->atom->PN, NORM,
111
							printf("%s%s/%s%s%s::%s\t %s%s/%s/\n",	
99
						       (show_name_only ? "" :
112
							BOLD, pcache->atom->CATEGORY,
100
						        (show_homepage ? pcache->HOMEPAGE : pcache->DESCRIPTION)));
113
							BLUE, pcache->atom->PN,
114
							YELLOW,cur_overlay->name, NORM,
115
							cur_overlay->path, dirname(ebuild));
116
						} else {
117
							printf("%s%s/%s%s%s::%s %s%s\n",
118
							BOLD, pcache->atom->CATEGORY,
119
							BLUE, pcache->atom->PN,
120
							YELLOW,cur_overlay->name, NORM,
121
							(show_name_only ? "" : 
122
							(show_homepage ? pcache->HOMEPAGE : pcache->DESCRIPTION)));
123
						}
124
					}
101
				}
125
				}
102
				cache_free(pcache);
126
				cache_free(pcache);
103
			} else {
127
			} else {
Lines 110-115 int qsearch_main(int argc, char **argv) Link Here
110
134
111
		case CACHE_EBUILD: {
135
		case CACHE_EBUILD: {
112
			FILE *ebuildfp;
136
			FILE *ebuildfp;
137
			if ( ( p = strchr(ebuild, ':')))
138
			{
139
				*p = 0;
140
				str = p+2;			/* separator is '::' */
141
				p = ebuild;
142
				if ( repo && strncmp( repo_search, p, sizeof(repo_search)))
143
					continue;
144
				if ( strcmp(overlay_name, p))
145
				{
146
					for ( overlay_tmp=overlay_gentoo ; overlay_tmp->next ; overlay_tmp=overlay_tmp->next )
147
					{
148
						if ( ! strncmp(overlay_tmp->name, p, sizeof(overlay_tmp->name)))
149
							break;
150
					}
151
					if ( ! strncmp(overlay_tmp->name, p, sizeof(overlay_tmp->name)))
152
					{
153
						cur_overlay = overlay_tmp;
154
						if (chdir(cur_overlay->path) != 0) {
155
							warnp("chdir to PORTDIR '%s' failed", cur_overlay->path);
156
							myerror=1;
157
						}
158
					} else 
159
						myerror=1;
160
					if ( myerror) {
161
						if (!reinitialize)
162
							warnfp("(cache update pending) %s", ebuild);
163
						reinitialize = 1;
164
						break;
165
					}
166
					strncpy(overlay_name, cur_overlay->name, sizeof(overlay_name));
167
				}
168
				strcpy(ebuild, str) ;		/* separator is '::' */
169
			}
170
113
			str = xstrdup(ebuild);
171
			str = xstrdup(ebuild);
114
			p = (char *) dirname(str);
172
			p = (char *) dirname(str);
115
173
Lines 134-143 int qsearch_main(int argc, char **argv) Link Here
134
							// doing operations with them.
192
							// doing operations with them.
135
							strncpy(dp, p, sizeof(dp));
193
							strncpy(dp, p, sizeof(dp));
136
							strncpy(bp, p, sizeof(bp));
194
							strncpy(bp, p, sizeof(bp));
137
							printf("%s%s/%s%s%s %s\n", 
195
							if ( show_path_to_ebuild) {
138
								BOLD, dirname(dp), BLUE, basename(bp), NORM,
196
								printf("%s%s/%s%s%s::%s\t %s%s/%s/\n",
197
								BOLD, dirname(dp), BLUE, basename(bp),
198
								YELLOW,cur_overlay->name, NORM,
199
								cur_overlay->path, dirname(ebuild));
200
							} else {
201
								printf("%s%s/%s%s%s::%s %s%s\n",
202
								BOLD, dirname(dp), BLUE, basename(bp),
203
								YELLOW,cur_overlay->name, NORM,
139
								(show_name_only ? "" : q));
204
								(show_name_only ? "" : q));
205
							}
140
							break;
206
							break;
207
141
						}
208
						}
142
					}
209
					}
143
					fclose(ebuildfp);
210
					fclose(ebuildfp);
(-)portage-utils-20061007/quse.c (-86 / +176 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.52 2006/06/10 14:01:21 vapier Exp $";
40
static const char quse_rcsid[] = "$Id: quse.c,v 1.52 2006/06/10 14:01:21 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 80-86 static void print_highlighted_use_flags( Link Here
80
	}
82
	}
81
}
83
}
82
84
83
int quse_describe_flag(int ind, int argc, char **argv)
85
int quse_describe_flag(int ind, short repo, char repo_search[], int argc, char **argv)
84
{
86
{
85
#define NUM_SEARCH_FILES ARR_SIZE(search_files)
87
#define NUM_SEARCH_FILES ARR_SIZE(search_files)
86
	char buf[BUFSIZE], *p;
88
	char buf[BUFSIZE], *p;
Lines 90-210 int quse_describe_flag(int ind, int argc Link Here
90
	FILE *fp[NUM_SEARCH_FILES];
92
	FILE *fp[NUM_SEARCH_FILES];
91
	DIR *d;
93
	DIR *d;
92
	struct dirent *de;
94
	struct dirent *de;
95
	overlay_t *cur_overlay;
93
96
94
	for (i = 0; i < NUM_SEARCH_FILES; ++i) {
97
	cur_overlay=overlay_gentoo;
95
		snprintf(buf, sizeof(buf), "%s/profiles/%s", portdir, search_files[i]);
96
		if ((fp[i] = fopen(buf, "r")) == NULL)
97
			warnp("skipping %s", search_files[i]);
98
	}
99
98
100
	for (i = ind; i < argc; i++) {
99
	do {
101
		s = strlen(argv[i]);
100
		if ( repo && strncmp(repo_search, cur_overlay->name, sizeof( repo_search)))
101
			continue;
102
		for (i = 0; i < NUM_SEARCH_FILES; ++i) {
103
			snprintf(buf, sizeof(buf), "%s/profiles/%s", cur_overlay->path, search_files[i]);
104
			if ((fp[i] = fopen(buf, "r")) == NULL)
105
				if ( verbose )
106
					warnp("skipping %s for the %s overlay", search_files[i], cur_overlay->name);
107
		}
102
108
103
		for (f = 0; f < NUM_SEARCH_FILES; ++f) {
109
		for (i = ind; i < argc; i++) {
104
			if (fp[f] == NULL)
110
			s = strlen(argv[i]);
105
				continue;
106
111
107
			while (fgets(buf, sizeof(buf), fp[f]) != NULL) {
112
			for (f = 0; f < NUM_SEARCH_FILES; ++f) {
108
				if (buf[0] == '#' || buf[0] == '\n')
113
				if (fp[f] == NULL)
109
					continue;
114
					continue;
110
115
111
				if ((p = strrchr(buf, '\n')) != NULL)
116
				while (fgets(buf, sizeof(buf), fp[f]) != NULL) {
112
					*p = '\0';
117
					if (buf[0] == '#' || buf[0] == '\n')
118
						continue;
113
119
114
				switch (f) {
120
					if ((p = strrchr(buf, '\n')) != NULL)
115
					case 0: /* Global use.desc */
121
						*p = '\0';
116
						if (!strncmp(buf, argv[i], s))
117
							if (buf[s] == ' ' && buf[s+1] == '-') {
118
								printf(" %sglobal%s:%s%s%s: %s\n", BOLD, NORM, BLUE, argv[i], NORM, buf+s+3);
119
								goto skip_file;
120
							}
121
						break;
122
122
123
					case 1: /* Local use.local.desc */
123
					switch (f) {
124
						if ((p = strchr(buf, ':')) == NULL)
124
						case 0: /* Global use.desc */
125
							if (!strncmp(buf, argv[i], s))
126
								if (buf[s] == ' ' && buf[s+1] == '-') {
127
									if ( cur_overlay == overlay_gentoo )
128
										printf(" %sglobal%s:%s%s%s: %s\n", BOLD, NORM, BLUE, argv[i], NORM, buf+s+3);
129
									else 
130
										printf(" (%s) %sglobal%s:%s%s%s: %s\n", cur_overlay->name, BOLD, NORM, BLUE, argv[i], NORM, buf+s+3);
131
									goto skip_file;
132
								}
125
							break;
133
							break;
126
						++p;
127
						if (!strncmp(p, argv[i], s)) {
128
							if (p[s] == ' ' && p[s+1] == '-') {
129
								*p = '\0';
130
								printf(" %slocal%s:%s%s%s:%s%s%s %s\n", BOLD, NORM, BLUE, argv[i], NORM, BOLD, buf, NORM, p+s+3);
131
							}
132
						}
133
						break;
134
134
135
					case 2: /* Architectures arch.list */
135
						case 1: /* Local use.local.desc */
136
						if (!strcmp(buf, argv[i])) {
136
							if ((p = strchr(buf, ':')) == NULL)
137
							printf(" %sarch%s:%s%s%s: %s architecture\n", BOLD, NORM, BLUE, argv[i], NORM, argv[i]);
137
								break;
138
							goto skip_file;
138
							++p;
139
						}
139
							if (!strncmp(p, argv[i], s)) {
140
						break;
140
								if (p[s] == ' ' && p[s+1] == '-') {
141
									*p = '\0';
142
									if ( cur_overlay == overlay_gentoo )
143
										printf(" %slocal%s:%s%s%s:%s%s%s %s\n", BOLD, NORM, BLUE, argv[i], NORM, BOLD, buf, NORM, p+s+3);
144
									else 
145
										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);
146
								}
147
							}
148
							break;
141
149
142
					case 3: /* Languages lang.desc */
150
						case 2: /* Architectures arch.list */
143
						if (!strncmp(buf, argv[i], s))
151
							if (!strcmp(buf, argv[i])) {
144
							if (buf[s] == ' ' && buf[s+1] == '-') {
152
								if ( cur_overlay == overlay_gentoo )
145
								printf(" %slang%s:%s%s%s: %s lingua\n", BOLD, NORM, BLUE, argv[i], NORM, buf+s+3);
153
									printf(" %sarch%s:%s%s%s: %s architecture\n", BOLD, NORM, BLUE, argv[i], NORM, argv[i]);
154
								else 
155
									printf(" (%s) %sarch%s:%s%s%s: %s architecture\n", cur_overlay->name, BOLD, NORM, BLUE, argv[i], NORM, argv[i]);
146
								goto skip_file;
156
								goto skip_file;
147
							}
157
							}
148
						break;
158
							break;
159
160
						case 3: /* Languages lang.desc */
161
							if (!strncmp(buf, argv[i], s))
162
								if (buf[s] == ' ' && buf[s+1] == '-') {
163
									if ( cur_overlay == overlay_gentoo )
164
										printf(" %slang%s:%s%s%s: %s lingua\n", BOLD, NORM, BLUE, argv[i], NORM, buf+s+3);
165
									else 
166
										printf(" (%s) %slang%s:%s%s%s: %s lingua\n", cur_overlay->name, BOLD, NORM, BLUE, argv[i], NORM, buf+s+3);
167
									goto skip_file;
168
								}
169
							break;
170
					}
149
				}
171
				}
150
			}
151
172
152
skip_file:
173
skip_file:
153
			rewind(fp[f]);
174
				rewind(fp[f]);
175
			}
176
177
			if ( i == (argc - 1) )
178
				for (f=0; f<NUM_SEARCH_FILES; ++f) 
179
					if ( fp[f] ) {
180
						fclose(fp[f]);
181
						fp[f] = NULL;
182
					}
154
		}
183
		}
155
	}
156
184
157
	for (f=0; f<NUM_SEARCH_FILES; ++f)
185
	} while ( (cur_overlay=cur_overlay->next));
158
		fclose(fp[f]);
159
186
160
	/* now scan the desc dir */
187
	/* now scan the desc dir */
161
	snprintf(buf, sizeof(buf), "%s/profiles/desc/", portdir);
188
	cur_overlay=overlay_gentoo;
162
	d = opendir(buf);
189
	do {
163
	while ((de = readdir(d)) != NULL) {
190
		if ( repo && strncmp(repo_search, cur_overlay->name, sizeof( repo_search)))
164
		if (strcmp(de->d_name+strlen(de->d_name)-5, ".desc"))
165
			continue;
191
			continue;
166
192
		snprintf(buf, sizeof(buf), "%s/profiles/desc/", cur_overlay->path);
167
		snprintf(buf, sizeof(buf), "%s/profiles/desc/%s", portdir, de->d_name);
193
		if ( ! (d = opendir(buf))) {
168
		if ((fp[0]=fopen(buf, "r")) == NULL) {
194
			if ( verbose ) 
169
			warn("Could not open '%s' for reading; skipping", de->d_name);
195
				warn("Could not open %s -> skipping", buf); 
170
			continue;
196
			continue;
171
		}
197
		}
198
		while ((de = readdir(d)) != NULL) {
199
			if (strcmp(de->d_name+strlen(de->d_name)-5, ".desc"))
200
				continue;
172
201
173
		while (fgets(buf, sizeof(buf), fp[0]) != NULL) {
202
			snprintf(buf, sizeof(buf), "%s/profiles/desc/%s", cur_overlay->path, de->d_name);
174
			if (buf[0] == '#' || buf[0] == '\n')
203
			if ((fp[0]=fopen(buf, "r")) == NULL) {
204
				warn("Could not open '%s' for reading; skipping", de->d_name);
175
				continue;
205
				continue;
206
			}
207
208
			while (fgets(buf, sizeof(buf), fp[0]) != NULL) {
209
				if (buf[0] == '#' || buf[0] == '\n')
210
					continue;
176
211
177
			if ((p = strrchr(buf, '\n')) != NULL)
212
				if ((p = strrchr(buf, '\n')) != NULL)
178
				*p = '\0';
213
					*p = '\0';
179
214
180
			if ((p = strchr(buf, '-')) == NULL) {
215
				if ((p = strchr(buf, '-')) == NULL) {
181
invalid_line:
216
invalid_line:
182
				warn("Invalid line in '%s': %s", de->d_name, buf);
217
					warn("Invalid line in '%s': %s", de->d_name, buf);
183
				continue;
218
					continue;
184
			}
219
				}
185
			while (p[-1] != ' ' && p[1] != ' ') {
220
				while (p[-1] != ' ' && p[1] != ' ') {
186
				/* maybe the flag has a '-' in it ... */
221
					/* maybe the flag has a '-' in it ... */
187
				if ((p = strchr(p+1, '-')) == NULL)
222
					if ((p = strchr(p+1, '-')) == NULL)
188
					goto invalid_line;
223
						goto invalid_line;
189
			}
224
				}
190
			p[-1] = '\0';
225
				p[-1] = '\0';
191
			p += 2;
226
				p += 2;
192
227
193
			for (i = ind; i < argc; i++)
228
				for (i = ind; i < argc; i++)
194
				if (!strcmp(argv[i], buf))
229
					if (!strcmp(argv[i], buf)) {
195
					printf(" %s%s%s:%s%s%s: %s\n", BOLD, de->d_name, NORM, BLUE, argv[i], NORM, p);
230
						if ( cur_overlay == overlay_gentoo )
196
		}
231
							printf(" %s%s%s:%s%s%s: %s\n", BOLD, de->d_name, NORM, BLUE, argv[i], NORM, p);
197
		close(f);
232
						else
198
	}
233
							printf(" (%s) %s%s%s:%s%s%s: %s\n", cur_overlay->name, BOLD, de->d_name, NORM, BLUE, argv[i], NORM, p);
199
	closedir(d);
234
					}
200
235
236
			}
237
			fclose(fp[0]);
238
		}
239
		closedir(d);
240
	} while ( (cur_overlay=cur_overlay->next));
201
	return 0;
241
	return 0;
202
}
242
}
203
243
204
int quse_main(int argc, char **argv)
244
int quse_main(int argc, char **argv)
205
{
245
{
206
	FILE *fp;
246
	FILE *fp;
207
	char *p;
247
	char *p, *str;
248
	short myerror = 0, repo = 0;
249
	char repo_search[64];
250
	char overlay_name[64];
208
251
209
	char buf0[_Q_PATH_MAX];
252
	char buf0[_Q_PATH_MAX];
210
	char buf1[_Q_PATH_MAX];
253
	char buf1[_Q_PATH_MAX];
Lines 217-222 int quse_main(int argc, char **argv) Link Here
217
	short quse_all = 0;
260
	short quse_all = 0;
218
	int regexp_matching = 1, i, idx = 0;
261
	int regexp_matching = 1, i, idx = 0;
219
	size_t search_len;
262
	size_t search_len;
263
	overlay_t *cur_overlay, *overlay_tmp;
264
265
	cur_overlay = overlay_gentoo;
266
	overlay_name[0] = 0;
267
	repo_search[0] = 0;
220
268
221
	DBG("argc=%d argv[0]=%s argv[1]=%s",
269
	DBG("argc=%d argv[0]=%s argv[1]=%s",
222
	    argc, argv[0], argc > 1 ? argv[1] : "NULL?");
270
	    argc, argv[0], argc > 1 ? argv[1] : "NULL?");
Lines 225-230 int quse_main(int argc, char **argv) Link Here
225
		switch (i) {
273
		switch (i) {
226
		case 'e': regexp_matching = 0; break;
274
		case 'e': regexp_matching = 0; break;
227
		case 'a': quse_all = 1; break;
275
		case 'a': quse_all = 1; break;
276
		case 'o': 
277
			repo = 1;
278
			strncpy(repo_search, optarg, sizeof(repo_search));
279
			break;
228
		case 'K': idx = 1; break;
280
		case 'K': idx = 1; break;
229
		case 'L': idx = 2; break;
281
		case 'L': idx = 2; break;
230
		case 'D': idx = -1; break;
282
		case 'D': idx = -1; break;
Lines 233-243 int quse_main(int argc, char **argv) Link Here
233
		COMMON_GETOPTS_CASES(quse)
285
		COMMON_GETOPTS_CASES(quse)
234
		}
286
		}
235
	}
287
	}
236
	if (argc == optind && !quse_all && idx >= 0)
288
	if (argc == optind && !quse_all && idx >= 0) {
289
		if ( idx == 3 )
290
			free(search_vars+idx);
237
		quse_usage(EXIT_FAILURE);
291
		quse_usage(EXIT_FAILURE);
292
	}
238
293
239
	if (idx == -1)
294
	if (idx == -1)
240
		return quse_describe_flag(optind, argc, argv);
295
		return quse_describe_flag(optind, repo, repo_search, argc, argv);
241
296
242
	if (quse_all) optind = argc;
297
	if (quse_all) optind = argc;
243
	initialize_ebuild_flat();	/* sets our pwd to $PORTDIR */
298
	initialize_ebuild_flat();	/* sets our pwd to $PORTDIR */
Lines 249-254 int quse_main(int argc, char **argv) Link Here
249
		return 1;
304
		return 1;
250
	while ((fgets(ebuild, sizeof(ebuild), fp)) != NULL) {
305
	while ((fgets(ebuild, sizeof(ebuild), fp)) != NULL) {
251
		FILE *newfp;
306
		FILE *newfp;
307
		if ( ( p = strchr(ebuild, ':')))
308
		{
309
			*p = 0;
310
			str = p+2;			/* separator is '::' */
311
			p = ebuild;
312
			if ( repo && strncmp( repo_search, p, sizeof(repo_search)))
313
				continue;
314
			if ( strcmp(overlay_name, p))
315
			{
316
				for ( overlay_tmp=overlay_gentoo ; overlay_tmp->next ; overlay_tmp=overlay_tmp->next )
317
				{
318
					if ( ! strncmp(overlay_tmp->name, p, sizeof(overlay_tmp->name)))
319
						break;
320
				}
321
				if ( ! strncmp(overlay_tmp->name, p, sizeof(overlay_tmp->name)))
322
				{
323
					cur_overlay = overlay_tmp;
324
					if (chdir(cur_overlay->path) != 0) {
325
						warnp("chdir to PORTDIR '%s' failed", cur_overlay->path);
326
						myerror=1;
327
					}
328
				} else 
329
					myerror=1;
330
				if ( myerror) {
331
					if (!reinitialize)
332
						warnf("(cache update pending) %s : %s", ebuild, strerror(errno));
333
					reinitialize = 1;
334
					myerror=0;
335
					continue;
336
				}
337
				strncpy(overlay_name, cur_overlay->name, sizeof(overlay_name));
338
			}
339
			strcpy(ebuild, str) ;
340
		}
341
252
		if ((p = strchr(ebuild, '\n')) != NULL)
342
		if ((p = strchr(ebuild, '\n')) != NULL)
253
			*p = 0;
343
			*p = 0;
254
		if ((newfp = fopen(ebuild, "r")) != NULL) {
344
		if ((newfp = fopen(ebuild, "r")) != NULL) {
Lines 374-380 int quse_main(int argc, char **argv) Link Here
374
					if (verbose > 3)
464
					if (verbose > 3)
375
						printf("%s %s %s ", *user ? user : "MISSING", *revision ? revision : "MISSING", *date ? date : "MISSING");
465
						printf("%s %s %s ", *user ? user : "MISSING", *revision ? revision : "MISSING", *date ? date : "MISSING");
376
466
377
					printf("%s%s%s ", CYAN, ebuild, NORM);
467
					printf("%s%s::%s%s ", CYAN, cur_overlay->name, ebuild, NORM);
378
					print_highlighted_use_flags(&buf0[search_len+1], optind, argc, argv);
468
					print_highlighted_use_flags(&buf0[search_len+1], optind, argc, argv);
379
					puts(NORM);
469
					puts(NORM);
380
					if (verbose > 1) {
470
					if (verbose > 1) {
Lines 382-388 int quse_main(int argc, char **argv) Link Here
382
						int ARGC = 0;
472
						int ARGC = 0;
383
						makeargv(&buf0[search_len+1], &ARGC, &ARGV);
473
						makeargv(&buf0[search_len+1], &ARGC, &ARGV);
384
						if (ARGC > 0) {
474
						if (ARGC > 0) {
385
							quse_describe_flag(1, ARGC, ARGV);
475
							quse_describe_flag(1, repo, repo_search, ARGC, ARGV);
386
							for (i = 0; i < ARGC; i++)
476
							for (i = 0; i < ARGC; i++)
387
								free(ARGV[i]);
477
								free(ARGV[i]);
388
							free(ARGV);
478
							free(ARGV);

Return to bug 154405