Gentoo Archives: gentoo-commits

From: "Mike Frysinger (vapier)" <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-projects commit in portage-utils: qmerge.c
Date: Thu, 24 Feb 2011 01:29:38
Message-Id: 20110224012927.CF9D020054@flycatcher.gentoo.org
1 vapier 11/02/24 01:29:27
2
3 Modified: qmerge.c
4 Log:
5 use a proper linked list structure for the package todo rather than building up and breaking down strings all the time
6
7 Revision Changes Path
8 1.104 portage-utils/qmerge.c
9
10 file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qmerge.c?rev=1.104&view=markup
11 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qmerge.c?rev=1.104&content-type=text/plain
12 diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qmerge.c?r1=1.103&r2=1.104
13
14 Index: qmerge.c
15 ===================================================================
16 RCS file: /var/cvsroot/gentoo-projects/portage-utils/qmerge.c,v
17 retrieving revision 1.103
18 retrieving revision 1.104
19 diff -u -r1.103 -r1.104
20 --- qmerge.c 23 Feb 2011 22:58:51 -0000 1.103
21 +++ qmerge.c 24 Feb 2011 01:29:27 -0000 1.104
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/qmerge.c,v 1.103 2011/02/23 22:58:51 vapier Exp $
27 + * $Header: /var/cvsroot/gentoo-projects/portage-utils/qmerge.c,v 1.104 2011/02/24 01:29:27 vapier Exp $
28 *
29 * Copyright 2005-2010 Ned Ludd - <solar@g.o>
30 * Copyright 2005-2010 Mike Frysinger - <vapier@g.o>
31 @@ -55,7 +55,7 @@
32 COMMON_OPTS_HELP
33 };
34
35 -static const char qmerge_rcsid[] = "$Id: qmerge.c,v 1.103 2011/02/23 22:58:51 vapier Exp $";
36 +static const char qmerge_rcsid[] = "$Id: qmerge.c,v 1.104 2011/02/24 01:29:27 vapier Exp $";
37 #define qmerge_usage(ret) usage(ret, QMERGE_FLAGS, qmerge_long_opts, qmerge_opts_help, lookup_applet_idx("qmerge"))
38
39 char search_pkgs = 0;
40 @@ -67,6 +67,7 @@
41 char nomd5 = 0;
42 char qmerge_strict = 0;
43 char update_only = 0;
44 +const char Packages[] = "Packages";
45
46 /*
47 "CHOST", "DEPEND", "DESCRIPTION", "EAPI",
48 @@ -96,18 +97,13 @@
49
50 int interactive_rename(const char *, const char *, struct pkg_t *);
51 void fetch(const char *, const char *);
52 -void qmerge_initialize(const char *);
53 char *best_version(const char *, const char *);
54 void pkg_fetch(int, depend_atom *, struct pkg_t *);
55 void pkg_merge(int, depend_atom *, struct pkg_t *);
56 int pkg_unmerge(const char *, const char *);
57 int unlink_empty(char *);
58 -void pkg_process(int, char **, struct pkg_t *);
59 void print_Pkg(int, struct pkg_t *);
60 -int parse_packages(const char *, int, char **);
61 -int match_pkg(const char *, struct pkg_t *);
62 int pkg_verify_checksums(char *, struct pkg_t *, depend_atom *, int strict, int display);
63 -int unmerge_packages(int, char **);
64 char *find_binpkg(const char *);
65
66 struct pkg_t *grab_binpkg_info(const char *);
67 @@ -184,7 +180,7 @@
68 fflush(stderr);
69 }
70
71 -void qmerge_initialize(const char *Packages)
72 +static void qmerge_initialize(void)
73 {
74 if (strlen(BUSYBOX))
75 if (access(BUSYBOX, X_OK) != 0)
76 @@ -930,6 +926,8 @@
77
78 snprintf(buf, sizeof(buf), "%s/%s.tbz2", pkgdir, pkg->PF);
79 unlink(buf);
80 +
81 + printf("%s>>>%s %s%s%s/%s%s%s\n", YELLOW, NORM, WHITE, atom->CATEGORY, NORM, CYAN, atom->PN, NORM);
82 }
83
84 int pkg_unmerge(const char *cat, const char *pkgname)
85 @@ -1113,37 +1111,36 @@
86 return -1;
87 }
88
89 -int match_pkg(const char *name, struct pkg_t *pkg)
90 +static int match_pkg(queue *ll, struct pkg_t *pkg)
91 {
92 depend_atom *atom;
93 char buf[255], buf2[255];
94 int match = 0;
95 - char *ptr;
96
97 snprintf(buf, sizeof(buf), "%s/%s", pkg->CATEGORY, pkg->PF);
98 if ((atom = atom_explode(buf)) == NULL)
99 errf("%s/%s is not a valid atom", pkg->CATEGORY, pkg->PF);
100
101 /* verify this is the requested package */
102 - if (strcmp(name, buf) == 0)
103 + if (strcmp(ll->name, buf) == 0)
104 match = 1;
105
106 - if (strcmp(name, pkg->PF) == 0)
107 + if (strcmp(ll->name, pkg->PF) == 0)
108 match = 2;
109
110 snprintf(buf2, sizeof(buf2), "%s/%s", pkg->CATEGORY, atom->PN);
111
112 - if (strcmp(name, buf2) == 0)
113 + if (strcmp(ll->name, buf2) == 0)
114 match = 3;
115
116 - if (strcmp(name, atom->PN) == 0)
117 + if (strcmp(ll->name, atom->PN) == 0)
118 match = 4;
119
120 if (match)
121 goto match_done;
122
123 - if ((ptr = strchr(name, ':')) != NULL) {
124 - depend_atom *subatom = atom_explode(name);
125 + if (ll->item) {
126 + depend_atom *subatom = atom_explode(ll->name);
127 if (subatom == NULL)
128 goto match_done;
129 if (strcmp(atom->PN, subatom->PN) == 0)
130 @@ -1200,28 +1197,26 @@
131 return ret;
132 }
133
134 -void pkg_process(int argc, char **argv, struct pkg_t *pkg)
135 +static void pkg_process(queue *todo, struct pkg_t *pkg)
136 {
137 + queue *ll;
138 depend_atom *atom;
139 char buf[255];
140 - int i;
141 -
142 - memset(buf, 0, sizeof(buf));
143
144 snprintf(buf, sizeof(buf), "%s/%s", pkg->CATEGORY, pkg->PF);
145 if ((atom = atom_explode(buf)) == NULL)
146 errf("%s/%s is not a valid atom", pkg->CATEGORY, pkg->PF);
147
148 - for (i = 1; i < argc; i++) {
149 - if (argv[i][0] == '-')
150 - continue;
151 -
152 - /* verify this is the requested package */
153 - if (match_pkg(argv[i], pkg) < 1)
154 - continue;
155 + ll = todo;
156 + while (ll) {
157 + if (ll->name[0] != '-' && match_pkg(ll, pkg)) {
158 + /* fetch all requested packages */
159 + pkg_fetch(0, atom, pkg);
160 + }
161
162 - pkg_fetch(0, atom, pkg);
163 + ll = ll->next;
164 }
165 +
166 /* free the atom */
167 atom_implode(atom);
168 }
169 @@ -1349,13 +1344,13 @@
170 if ((p = best_version(pkg->CATEGORY, atom->PN)) != NULL) {
171 if (*p) {
172 int ret;
173 - char *icolor = (char *) RED;
174 + const char *icolor = RED;
175 ret = atom_compare_str(buf, p);
176 switch (ret) {
177 - case EQUAL: icolor = (char *) RED; break;
178 - case NEWER: icolor = (char *) YELLOW; break;
179 - case OLDER: icolor = (char *) BLUE; break;
180 - default: icolor = (char *) NORM; break;
181 + case EQUAL: icolor = RED; break;
182 + case NEWER: icolor = YELLOW; break;
183 + case OLDER: icolor = BLUE; break;
184 + default: icolor = NORM; break;
185 }
186 printf(" %sInstalled%s:%s %s%s%s\n", DKGREEN, YELLOW, NORM, icolor, p, NORM);
187 }
188 @@ -1363,28 +1358,30 @@
189 atom_implode(atom);
190 }
191
192 -int unmerge_packages(int argc, char **argv)
193 +static int unmerge_packages(queue *todo)
194 {
195 depend_atom *atom;
196 char *p;
197 - int i;
198
199 - if (argc == optind)
200 - return 1;
201 -
202 - for (i = 1; i < argc; i++) {
203 + while (todo) {
204 char buf[512];
205
206 - if (argv[i][0] == '-')
207 - continue;
208 + if (todo->name[0] == '-')
209 + goto next;
210
211 - p = best_version(NULL, argv[i]);
212 - if (!*p) continue;
213 - if ((atom = atom_explode(p)) == NULL) continue;
214 + p = best_version(NULL, todo->name);
215 + if (!*p)
216 + goto next;
217 + if ((atom = atom_explode(p)) == NULL)
218 + goto next;
219 atom2str(atom, buf, sizeof(buf));
220 pkg_unmerge(atom->CATEGORY, buf);
221 atom_implode(atom);
222 +
223 + next:
224 + todo = todo->next;
225 }
226 +
227 return 0;
228 }
229
230 @@ -1392,7 +1389,6 @@
231 {
232 FILE *fp;
233 char buf[BUFSIZ];
234 - char value[BUFSIZ];
235 char *p;
236 depend_atom *atom;
237
238 @@ -1449,28 +1445,26 @@
239 if ((p = strchr(buf, '\n')) != NULL)
240 *p = 0;
241
242 - memset(value, 0, sizeof(value));
243 if ((p = strchr(buf, ':')) == NULL)
244 continue;
245 if ((p = strchr(buf, ' ')) == NULL)
246 continue;
247 *p = 0;
248 ++p;
249 - strncpy(value, p, sizeof(value));
250
251 if (*buf) {
252 /* we dont need all the info */
253 if (strcmp(buf, "RDEPEND:") == 0)
254 - strncpy(pkg->RDEPEND, value, sizeof(Pkg.RDEPEND));
255 + strncpy(pkg->RDEPEND, p, sizeof(Pkg.RDEPEND));
256 if (strcmp(buf, "PF:") == 0)
257 - strncpy(pkg->PF, value, sizeof(Pkg.PF));
258 + strncpy(pkg->PF, p, sizeof(Pkg.PF));
259 if (strcmp(buf, "CATEGORY:") == 0)
260 - strncpy(pkg->CATEGORY, value, sizeof(Pkg.CATEGORY));
261 + strncpy(pkg->CATEGORY, p, sizeof(Pkg.CATEGORY));
262 if (strcmp(buf, "REPO:") == 0)
263 - strncpy(pkg->REPO, value, sizeof(Pkg.REPO));
264 + strncpy(pkg->REPO, p, sizeof(Pkg.REPO));
265
266 if (strcmp(buf, "CPV:") == 0) {
267 - if ((atom = atom_explode(value)) != NULL) {
268 + if ((atom = atom_explode(p)) != NULL) {
269 snprintf(buf, sizeof(buf), "%s-%s", atom->PN, atom->PV);
270 if (atom->PR_int)
271 snprintf(buf, sizeof(buf), "%s-%s-r%i", atom->PN, atom->PV, atom->PR_int);
272 @@ -1480,15 +1474,15 @@
273 }
274 }
275 if (strcmp(buf, "SLOT:") == 0)
276 - strncpy(pkg->SLOT, value, sizeof(Pkg.SLOT));
277 + strncpy(pkg->SLOT, p, sizeof(Pkg.SLOT));
278 if (strcmp(buf, "USE:") == 0)
279 - strncpy(pkg->USE, value, sizeof(Pkg.USE));
280 + strncpy(pkg->USE, p, sizeof(Pkg.USE));
281
282 /* checksums. We must have 1 or the other unless --*/
283 if (strcmp(buf, "MD5:") == 0)
284 - strncpy(pkg->MD5, value, sizeof(Pkg.MD5));
285 + strncpy(pkg->MD5, p, sizeof(Pkg.MD5));
286 if (strcmp(buf, "SHA1:") == 0)
287 - strncpy(pkg->SHA1, value, sizeof(Pkg.SHA1));
288 + strncpy(pkg->SHA1, p, sizeof(Pkg.SHA1));
289 }
290 }
291 fclose(fp);
292 @@ -1500,7 +1494,6 @@
293 {
294 FILE *fp;
295 char buf[BUFSIZ];
296 - char value[BUFSIZ];
297 char *p;
298 char PF[sizeof(Pkg.PF)];
299 char CATEGORY[sizeof(Pkg.CATEGORY)];
300 @@ -1550,19 +1543,17 @@
301 if ((p = strchr(buf, '\n')) != NULL)
302 *p = 0;
303
304 - memset(&value, 0, sizeof(value));
305 if ((p = strchr(buf, ':')) == NULL)
306 continue;
307 if ((p = strchr(buf, ' ')) == NULL)
308 continue;
309 *p = 0;
310 ++p;
311 - strncpy(value, p, sizeof(value));
312
313 if (*buf) {
314 if (strcmp(buf, "CPV:") == 0) {
315 depend_atom *atom;
316 - if ((atom = atom_explode(value)) != NULL) {
317 + if ((atom = atom_explode(p)) != NULL) {
318 snprintf(buf, sizeof(buf), "%s-%s", atom->PN, atom->PV);
319 if (atom->PR_int)
320 snprintf(buf, sizeof(buf), "%s-%s-r%i", atom->PN, atom->PV, atom->PR_int);
321 @@ -1572,22 +1563,20 @@
322 }
323 }
324 if (strcmp(buf, "PF:") == 0)
325 - strncpy(PF, value, sizeof(PF));
326 + strncpy(PF, p, sizeof(PF));
327 if (strcmp(buf, "CATEGORY:") == 0)
328 - strncpy(CATEGORY, value, sizeof(CATEGORY));
329 + strncpy(CATEGORY, p, sizeof(CATEGORY));
330 }
331 }
332 fclose(fp);
333 return best_match;
334 }
335
336 -int parse_packages(const char *Packages, int argc, char **argv)
337 +static int parse_packages(queue *todo)
338 {
339 FILE *fp;
340 - char buf[BUFSIZ];
341 - char value[BUFSIZ];
342 - char *p;
343 - int i;
344 + size_t buflen;
345 + char *buf, *p;
346 long lineno = 0;
347
348 if ((fp = fopen(Packages, "r")) == NULL)
349 @@ -1595,23 +1584,27 @@
350
351 memset(&Pkg, 0, sizeof(Pkg));
352
353 - while (fgets(buf, sizeof(buf), fp) != NULL) {
354 + buf = NULL;
355 + while (getline(&buf, &buflen, fp) != -1) {
356 lineno++;
357 if (*buf == '\n') {
358 if ((strlen(Pkg.PF) > 0) && (strlen(Pkg.CATEGORY) > 0)) {
359 - struct pkg_t *pkg = xmalloc(sizeof(struct pkg_t));
360 - memcpy(pkg, &Pkg, sizeof(struct pkg_t));
361 + struct pkg_t *pkg = xmalloc(sizeof(*pkg));
362 + *pkg = Pkg;
363 +
364 if (search_pkgs) {
365 - if (argc != optind) {
366 - for (i = 0; i < argc; i++)
367 - if ((match_pkg(argv[i], pkg) > 0) || (strcmp(argv[i], pkg->CATEGORY) == 0))
368 + if (todo) {
369 + queue *ll = todo;
370 + while (ll) {
371 + if ((match_pkg(ll, pkg) > 0) || (strcmp(ll->name, pkg->CATEGORY) == 0))
372 print_Pkg(verbose, pkg);
373 - } else {
374 + ll = ll->next;
375 + }
376 + } else
377 print_Pkg(verbose, pkg);
378 - }
379 - } else {
380 - pkg_process(argc, argv, pkg);
381 - }
382 + } else
383 + pkg_process(todo, pkg);
384 +
385 free(pkg);
386 }
387 memset(&Pkg, 0, sizeof(Pkg));
388 @@ -1620,115 +1613,137 @@
389 if ((p = strchr(buf, '\n')) != NULL)
390 *p = 0;
391
392 - memset(&value, 0, sizeof(value));
393 if ((p = strchr(buf, ':')) == NULL)
394 continue;
395 if ((p = strchr(buf, ' ')) == NULL)
396 continue;
397 *p = 0;
398 ++p;
399 - strncpy(value, p, sizeof(value));
400
401 switch (*buf) {
402 case 'U':
403 - if (strcmp(buf, "USE:") == 0) strncpy(Pkg.USE, value, sizeof(Pkg.USE));
404 + if (strcmp(buf, "USE:") == 0) strncpy(Pkg.USE, p, sizeof(Pkg.USE));
405 break;
406 case 'P':
407 - if (strcmp(buf, "PF:") == 0) strncpy(Pkg.PF, value, sizeof(Pkg.PF));
408 + if (strcmp(buf, "PF:") == 0) strncpy(Pkg.PF, p, sizeof(Pkg.PF));
409 break;
410 case 'S':
411 - if (strcmp(buf, "SIZE:") == 0) Pkg.SIZE = atol(value);
412 - if (strcmp(buf, "SLOT:") == 0) strncpy(Pkg.SLOT, value, sizeof(Pkg.SLOT));
413 - if (strcmp(buf, "SHA1:") == 0) strncpy(Pkg.SHA1, value, sizeof(Pkg.SHA1));
414 + if (strcmp(buf, "SIZE:") == 0) Pkg.SIZE = atol(p);
415 + if (strcmp(buf, "SLOT:") == 0) strncpy(Pkg.SLOT, p, sizeof(Pkg.SLOT));
416 + if (strcmp(buf, "SHA1:") == 0) strncpy(Pkg.SHA1, p, sizeof(Pkg.SHA1));
417 break;
418 case 'M':
419 - if (strcmp(buf, "MD5:") == 0) strncpy(Pkg.MD5, value, sizeof(Pkg.MD5));
420 + if (strcmp(buf, "MD5:") == 0) strncpy(Pkg.MD5, p, sizeof(Pkg.MD5));
421 break;
422 case 'R':
423 - if (strcmp(buf, "REPO:") == 0) strncpy(Pkg.REPO, value, sizeof(Pkg.REPO));
424 - if (strcmp(buf, "RDEPEND:") == 0) strncpy(Pkg.RDEPEND, value, sizeof(Pkg.RDEPEND));
425 + if (strcmp(buf, "REPO:") == 0) strncpy(Pkg.REPO, p, sizeof(Pkg.REPO));
426 + if (strcmp(buf, "RDEPEND:") == 0) strncpy(Pkg.RDEPEND, p, sizeof(Pkg.RDEPEND));
427 break;
428 case 'L':
429 - if (strcmp(buf, "LICENSE:") == 0) strncpy(Pkg.LICENSE, value, sizeof(Pkg.LICENSE));
430 + if (strcmp(buf, "LICENSE:") == 0) strncpy(Pkg.LICENSE, p, sizeof(Pkg.LICENSE));
431 break;
432 case 'C':
433 - if (strcmp(buf, "CATEGORY:") == 0) strncpy(Pkg.CATEGORY, value, sizeof(Pkg.CATEGORY));
434 + if (strcmp(buf, "CATEGORY:") == 0) strncpy(Pkg.CATEGORY, p, sizeof(Pkg.CATEGORY));
435 if (strcmp(buf, "CPV:") == 0) {
436 depend_atom *atom;
437 - if ((atom = atom_explode(value)) != NULL) {
438 - snprintf(buf, sizeof(buf), "%s-%s", atom->PN, atom->PV);
439 + if ((atom = atom_explode(p)) != NULL) {
440 if (atom->PR_int)
441 - snprintf(buf, sizeof(buf), "%s-%s-r%i", atom->PN, atom->PV, atom->PR_int);
442 - strncpy(Pkg.PF, buf, sizeof(Pkg.PF));
443 + snprintf(Pkg.PF, sizeof(Pkg.PF), "%s-%s-r%i", atom->PN, atom->PV, atom->PR_int);
444 + else
445 + snprintf(Pkg.PF, sizeof(Pkg.PF), "%s-%s", atom->PN, atom->PV);
446 strncpy(Pkg.CATEGORY, atom->CATEGORY, sizeof(Pkg.CATEGORY));
447 atom_implode(atom);
448 }
449 }
450 break;
451 case 'D':
452 - if (strcmp(buf, "DESC:") == 0) strncpy(Pkg.DESC, value, sizeof(Pkg.DESC));
453 + if (strcmp(buf, "DESC:") == 0) strncpy(Pkg.DESC, p, sizeof(Pkg.DESC));
454 break;
455 default:
456 break;
457 }
458 - memset(&buf, 0, sizeof(buf));
459 }
460 +
461 + free(buf);
462 fclose(fp);
463 +
464 return 0;
465 }
466
467 -queue *get_world(void);
468 -queue *get_world(void)
469 +static queue *qmerge_add_set_atom(char *satom, queue *set)
470 +{
471 + char *p;
472 + const char *slot;
473 +
474 + if ((p = strchr(satom, ':')) != NULL) {
475 + *p = 0;
476 + slot = p + 1;
477 + } else
478 + slot = "0";
479 +
480 + return add_set(satom, slot, set);
481 +}
482 +
483 +static queue *qmerge_add_set_file(const char *file, queue *set)
484 {
485 FILE *fp;
486 - char buf[BUFSIZ];
487 - queue *world = NULL;
488 - char fname[_Q_PATH_MAX];
489 + size_t buflen;
490 + char *buf;
491 + const char *fname;
492
493 - if (*portroot && strcmp(portroot, "/") != 0)
494 - snprintf(fname, sizeof(fname), "%s/var/lib/portage/world", portroot);
495 - else
496 - strncpy(fname, "/var/lib/portage/world", sizeof(fname));
497 + /* Find the file to read */
498 + if (*portroot && strcmp(portroot, "/") != 0) {
499 + size_t len, flen;
500 + char *f;
501 +
502 + len = strlen(portroot);
503 + flen = strlen(file) + 1;
504 + fname = f = alloca(len + flen);
505 + memcpy(f, portroot, len);
506 + memcpy(f + len, file, flen);
507 + } else
508 + fname = file;
509
510 if ((fp = fopen(fname, "r")) == NULL) {
511 - warnp("fopen(\"%s\", \"r\"); = -1", fname);
512 + warnp("unable to read set file %s", fname);
513 return NULL;
514 }
515
516 - while (fgets(buf, sizeof(buf), fp) != NULL) {
517 - char *p;
518 - char *slot = (char *) "0";
519 -
520 + /* Load each entry */
521 + buf = NULL;
522 + while (getline(&buf, &buflen, fp) != -1) {
523 rmspace(buf);
524 -
525 - if ((p = strchr(buf, ':')) != NULL) {
526 - *p = 0;
527 - slot = p + 1;
528 - }
529 - world = add_set(buf, slot, world);
530 + set = qmerge_add_set_atom(buf, set);
531 }
532 + free(buf);
533 +
534 fclose(fp);
535 - return world;
536 +
537 + return set;
538 }
539
540 -queue *qmerge_load_set(char *, queue *);
541 -queue *qmerge_load_set(char *buf, queue *set)
542 +static queue *qmerge_add_set(char *buf, queue *set)
543 {
544 - if (set != NULL)
545 - return set;
546 if (strcmp(buf, "world") == 0)
547 - return get_world();
548 + return qmerge_add_set_file("/var/lib/portage/world", set);
549 if (strcmp(buf, "all") == 0)
550 return get_vdb_atoms(0);
551 - return NULL;
552 + /* XXX: Should load custom sets here */
553 + return qmerge_add_set_atom(buf, set);
554 +}
555 +
556 +static int qmerge_run(queue *todo)
557 +{
558 + if (uninstall)
559 + return unmerge_packages(todo);
560 + else
561 + return parse_packages(todo);
562 }
563
564 int qmerge_main(int argc, char **argv)
565 {
566 int i, ret;
567 - const char Packages[] = "Packages";
568 - int ARGC = argc;
569 - char **ARGV = argv;
570 + queue *todo;
571
572 if (argc < 2)
573 qmerge_usage(EXIT_FAILURE);
574 @@ -1761,78 +1776,43 @@
575 }
576 }
577
578 - if (uninstall) {
579 - if (interactive) {
580 - int save_pretend = pretend;
581 - int save_verbose = verbose;
582 - int save_quiet = quiet;
583 -
584 - pretend = 100;
585 - verbose = 0;
586 - quiet = 1;
587 - ret = unmerge_packages(argc, argv);
588 - if (ret || save_pretend)
589 - return ret;
590 + /* Expand any portage sets on the command line */
591 + todo = NULL;
592 + for (i = optind; i < argc; ++i)
593 + todo = qmerge_add_set(argv[i], todo);
594 +
595 + if (!uninstall)
596 + qmerge_initialize();
597 +
598 + /* Make sure the user wants to do it */
599 + if (interactive) {
600 + int save_pretend = pretend;
601 + int save_verbose = verbose;
602 + int save_quiet = quiet;
603 +
604 + pretend = 100;
605 + verbose = 0;
606 + quiet = 1;
607 + ret = qmerge_run(todo);
608 + if (ret || save_pretend)
609 + return ret;
610
611 + if (uninstall) {
612 if (!prompt("OK to unmerge these packages"))
613 return 0;
614 -
615 - pretend = save_pretend;
616 - verbose = save_verbose;
617 - quiet = save_quiet;
618 + } else {
619 + if (!prompt("OK to merge these packages"))
620 + return 0;
621 }
622
623 - return unmerge_packages(argc, argv);
624 + pretend = save_pretend;
625 + verbose = save_verbose;
626 + quiet = save_quiet;
627 }
628
629 - ARGC = argc;
630 - ARGV = argv;
631 -
632 - qmerge_initialize(Packages);
633 -
634 - if (optind < argc) {
635 - queue *world = NULL;
636 - int ind = optind;
637 - while (ind < argc) {
638 - size_t size = 0;
639 - i = ind;
640 - ind++;
641 -
642 - if ((world = qmerge_load_set(argv[i], world)) == NULL)
643 - continue;
644 -
645 - if (world != NULL) {
646 - queue *ll;
647 - char *ptr;
648 -
649 - for (ll = world; ll != NULL; ll = ll->next)
650 - size += (strlen(ll->name) + 1);
651 - if (size < 1)
652 - continue;
653 -
654 - size += (strlen(argv[0]) + 1);
655 - ptr = xmalloc(size);
656 - sprintf(ptr, "%s ", argv[0]);
657 -
658 - for (ll = world; ll != NULL; ll = ll->next) {
659 - char *p = NULL;
660 - xasprintf(&p, "%s ", ll->name);
661 - strcat(ptr, p);
662 - free(p);
663 - }
664 - ARGC = 0;
665 - ARGV = NULL;
666 - /* this will leak mem */
667 - /* follow_rdepends = 0; */
668 - makeargv(ptr, &ARGC, &ARGV);
669 -
670 - free(ptr);
671 - free_sets(world);
672 - world = NULL;
673 - }
674 - }
675 - }
676 - return parse_packages(Packages, ARGC, ARGV);
677 + ret = qmerge_run(todo);
678 + free_sets(todo);
679 + return ret;
680 }
681
682 #else