/[gentoo-projects]/portage-utils/qatom.c
Gentoo

Contents of /portage-utils/qatom.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (show annotations) (download) (as text)
Mon Apr 22 04:36:28 2013 UTC (15 months ago) by vapier
Branch: MAIN
Changes since 1.8: +5 -4 lines
File MIME type: text/x-csrc
qatom: check # of args before running main code

1 /*
2 * Copyright 2005-2008 Gentoo Foundation
3 * Distributed under the terms of the GNU General Public License v2
4 * $Header: /var/cvsroot/gentoo-projects/portage-utils/qatom.c,v 1.8 2011/02/21 01:33:47 vapier Exp $
5 *
6 * Copyright 2005-2008 Ned Ludd - <solar@gentoo.org>
7 * Copyright 2005-2008 Mike Frysinger - <vapier@gentoo.org>
8 */
9
10 #ifdef APPLET_qatom
11
12 #define QATOM_FLAGS "c" COMMON_FLAGS
13 static struct option const qatom_long_opts[] = {
14 {"compare", no_argument, NULL, 'c'},
15 COMMON_LONG_OPTS
16 };
17 static const char * const qatom_opts_help[] = {
18 "Compare two atoms",
19 COMMON_OPTS_HELP
20 };
21
22 static const char qatom_rcsid[] = "$Id: qatom.c,v 1.8 2011/02/21 01:33:47 vapier Exp $";
23 #define qatom_usage(ret) usage(ret, QATOM_FLAGS, qatom_long_opts, qatom_opts_help, lookup_applet_idx("qatom"))
24
25 int qatom_main(int argc, char **argv)
26 {
27 enum qatom_atom { _EXPLODE=0, _COMPARE } action = _EXPLODE;
28 depend_atom *atom;
29 int i;
30
31 DBG("argc=%d argv[0]=%s argv[1]=%s",
32 argc, argv[0], argc > 1 ? argv[1] : "NULL?");
33
34 while ((i = GETOPT_LONG(QATOM, qatom, "")) != -1) {
35 switch (i) {
36 case 'c': action = _COMPARE; break;
37 COMMON_GETOPTS_CASES(qatom)
38 }
39 }
40
41 if (argc == optind)
42 qatom_usage(EXIT_FAILURE);
43
44 if (action == _COMPARE && (argc - optind) % 2)
45 err("compare needs even number of arguments");
46
47 for (i = optind; i < argc; ++i) {
48 switch (action) {
49 case _COMPARE:
50 printf("%s %s %s\n", argv[i], booga[atom_compare_str(argv[i], argv[i+1])], argv[i+1]);
51 ++i;
52 break;
53 case _EXPLODE:
54 atom = atom_explode(argv[i]);
55 if (!atom) {
56 warnf("failed exploding atom %s", argv[i]);
57 continue;
58 }
59 printf("%s %s %s", atom->CATEGORY, atom->PN, atom->PV);
60 if (verbose || atom->PR_int)
61 printf(" r%i", atom->PR_int);
62 if (atom->SLOT)
63 printf(" :%s", atom->SLOT);
64 if (verbose > 1)
65 printf(" %c", (atom->letter ? : '-'));
66 putchar('\n');
67 atom_implode(atom);
68 }
69 }
70
71 return EXIT_SUCCESS;
72 }
73
74 #else
75 DEFINE_APPLET_STUB(qatom)
76 #endif

  ViewVC Help
Powered by ViewVC 1.1.20