1 |
vapier 13/09/29 09:14:14 |
2 |
|
3 |
Modified: qdepends.c |
4 |
Log: |
5 |
qdepends: add a --format mode to make testing easier |
6 |
|
7 |
Revision Changes Path |
8 |
1.60 portage-utils/qdepends.c |
9 |
|
10 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qdepends.c?rev=1.60&view=markup |
11 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qdepends.c?rev=1.60&content-type=text/plain |
12 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qdepends.c?r1=1.59&r2=1.60 |
13 |
|
14 |
Index: qdepends.c |
15 |
=================================================================== |
16 |
RCS file: /var/cvsroot/gentoo-projects/portage-utils/qdepends.c,v |
17 |
retrieving revision 1.59 |
18 |
retrieving revision 1.60 |
19 |
diff -u -r1.59 -r1.60 |
20 |
--- qdepends.c 29 Sep 2013 06:44:39 -0000 1.59 |
21 |
+++ qdepends.c 29 Sep 2013 09:14:14 -0000 1.60 |
22 |
@@ -1,7 +1,7 @@ |
23 |
/* |
24 |
* Copyright 2005-2010 Gentoo Foundation |
25 |
* Distributed under the terms of the GNU General Public License v2 |
26 |
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/qdepends.c,v 1.59 2013/09/29 06:44:39 vapier Exp $ |
27 |
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/qdepends.c,v 1.60 2013/09/29 09:14:14 vapier Exp $ |
28 |
* |
29 |
* Copyright 2005-2010 Ned Ludd - <solar@g.o> |
30 |
* Copyright 2005-2010 Mike Frysinger - <vapier@g.o> |
31 |
@@ -9,7 +9,7 @@ |
32 |
|
33 |
#ifdef APPLET_qdepends |
34 |
|
35 |
-#define QDEPENDS_FLAGS "drpaNk:Q:" COMMON_FLAGS |
36 |
+#define QDEPENDS_FLAGS "drpafNk:Q:" COMMON_FLAGS |
37 |
static struct option const qdepends_long_opts[] = { |
38 |
{"depend", no_argument, NULL, 'd'}, |
39 |
{"rdepend", no_argument, NULL, 'r'}, |
40 |
@@ -18,6 +18,7 @@ |
41 |
{"query", a_argument, NULL, 'Q'}, |
42 |
{"name-only", no_argument, NULL, 'N'}, |
43 |
{"all", no_argument, NULL, 'a'}, |
44 |
+ {"format", no_argument, NULL, 'f'}, |
45 |
COMMON_LONG_OPTS |
46 |
}; |
47 |
static const char * const qdepends_opts_help[] = { |
48 |
@@ -28,9 +29,10 @@ |
49 |
"Query reverse deps", |
50 |
"Only show package name", |
51 |
"Show all DEPEND info", |
52 |
+ "Pretty format specified depend strings", |
53 |
COMMON_OPTS_HELP |
54 |
}; |
55 |
-static const char qdepends_rcsid[] = "$Id: qdepends.c,v 1.59 2013/09/29 06:44:39 vapier Exp $"; |
56 |
+static const char qdepends_rcsid[] = "$Id: qdepends.c,v 1.60 2013/09/29 09:14:14 vapier Exp $"; |
57 |
#define qdepends_usage(ret) usage(ret, QDEPENDS_FLAGS, qdepends_long_opts, qdepends_opts_help, lookup_applet_idx("qdepends")) |
58 |
|
59 |
static char qdep_name_only = 0; |
60 |
@@ -57,8 +59,12 @@ |
61 |
typedef struct _dep_node dep_node; |
62 |
|
63 |
/* prototypes */ |
64 |
-#define dep_dump_tree(r) _dep_dump_tree(r,0) |
65 |
-_q_static void _dep_dump_tree(const dep_node *root, int space); |
66 |
+#ifdef NDEBUG |
67 |
+# define dep_dump_tree(r) |
68 |
+#else |
69 |
+# define dep_dump_tree(r) _dep_print_tree(stdout, r, 0) |
70 |
+#endif |
71 |
+_q_static void _dep_print_tree(FILE *fp, const dep_node *root, size_t space); |
72 |
void dep_burn_tree(dep_node *root); |
73 |
char *dep_flatten_tree(const dep_node *root); |
74 |
_q_static void _dep_attach(dep_node *root, dep_node *attach_me, int type); |
75 |
@@ -251,25 +257,57 @@ |
76 |
return NULL; |
77 |
} |
78 |
|
79 |
-_q_static void _dep_dump_tree(const dep_node *root, int space) |
80 |
+_q_static void _dep_print_tree(FILE *fp, const dep_node *root, size_t space) |
81 |
{ |
82 |
-#ifndef EBUG |
83 |
- return; |
84 |
-#endif |
85 |
+ size_t s; |
86 |
|
87 |
- int spaceit = space; |
88 |
assert(root); |
89 |
- if (root->type == DEP_NULL) goto this_node_sucks; |
90 |
+ if (root->type == DEP_NULL) |
91 |
+ goto this_node_sucks; |
92 |
+ |
93 |
+ for (s = space; s; --s) |
94 |
+ fprintf(fp, "\t"); |
95 |
|
96 |
- while (spaceit--) printf("\t"); |
97 |
- printf("Node [%s]: ", _dep_names[root->type]); |
98 |
+ if (verbose > 1) |
99 |
+ fprintf(fp, "Node [%s]: ", _dep_names[root->type]); |
100 |
/*printf("Node %p [%s] %p %p %p: ", root, _dep_names[root->type], root->parent, root->neighbor, root->children);*/ |
101 |
- if (root->info) printf("'%s'", root->info); |
102 |
- printf("\n"); |
103 |
+ if (root->type == DEP_OR) |
104 |
+ fprintf(fp, "|| ("); |
105 |
+ if (root->info) { |
106 |
+ fprintf(fp, "%s", root->info); |
107 |
+ /* If there is only one child, be nice to one-line: foo? ( pkg ) */ |
108 |
+ if (root->type == DEP_USE) |
109 |
+ fprintf(fp, "? ("); |
110 |
+ } |
111 |
+ fprintf(fp, "\n"); |
112 |
|
113 |
- if (root->children) _dep_dump_tree(root->children, space+1); |
114 |
-this_node_sucks: |
115 |
- if (root->neighbor) _dep_dump_tree(root->neighbor, space); |
116 |
+ if (root->children) |
117 |
+ _dep_print_tree(fp, root->children, space+1); |
118 |
+ |
119 |
+ if (root->type == DEP_OR || root->type == DEP_USE) { |
120 |
+ for (s = space; s; --s) |
121 |
+ fprintf(fp, "\t"); |
122 |
+ fprintf(fp, ")\n"); |
123 |
+ } |
124 |
+ this_node_sucks: |
125 |
+ if (root->neighbor) |
126 |
+ _dep_print_tree(fp, root->neighbor, space); |
127 |
+} |
128 |
+ |
129 |
+_q_static void dep_print_depend(FILE *fp, const char *depend) |
130 |
+{ |
131 |
+ dep_node *dep_tree = dep_grow_tree(depend); |
132 |
+ if (dep_tree == NULL) |
133 |
+ return; |
134 |
+ |
135 |
+ if (!quiet) |
136 |
+ fprintf(fp, "DEPEND=\"\n"); |
137 |
+ |
138 |
+ _dep_print_tree(fp, dep_tree, 1); |
139 |
+ |
140 |
+ dep_burn_tree(dep_tree); |
141 |
+ if (!quiet) |
142 |
+ fprintf(fp, "\"\n"); |
143 |
} |
144 |
|
145 |
void dep_burn_tree(dep_node *root) |
146 |
@@ -478,6 +516,7 @@ |
147 |
}; |
148 |
q_vdb_pkg_cb *cb; |
149 |
int i; |
150 |
+ bool do_format = false; |
151 |
const char *query = NULL; |
152 |
const char *depend_file; |
153 |
const char *depend_files[] = { "DEPEND", "RDEPEND", "PDEPEND", NULL, NULL }; |
154 |
@@ -498,11 +537,21 @@ |
155 |
case 'a': depend_file = NULL; break; |
156 |
case 'Q': query = optarg; break; |
157 |
case 'N': qdep_name_only = 1; break; |
158 |
+ case 'f': do_format = true; break; |
159 |
} |
160 |
} |
161 |
- if ((argc == optind) && (query == NULL)) |
162 |
+ if ((argc == optind) && (query == NULL) && !do_format) |
163 |
qdepends_usage(EXIT_FAILURE); |
164 |
|
165 |
+ if (do_format) { |
166 |
+ while (optind < argc) { |
167 |
+ dep_print_depend(stdout, argv[optind++]); |
168 |
+ if (optind < argc) |
169 |
+ fprintf(stdout, "\n"); |
170 |
+ } |
171 |
+ return EXIT_SUCCESS; |
172 |
+ } |
173 |
+ |
174 |
state.depend_file = depend_file; |
175 |
state.query = query; |
176 |
cb = query ? qdepends_vdb_deep_cb : qdepends_main_vdb_cb; |