FreeCalypso > hg > ueda-linux
annotate ueda/mclutils/csvattr.c @ 138:77acb816727b
netdiff: donl-rename-parts put together
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 07 Sep 2020 04:02:14 +0000 |
parents | 125fc4ef7eb0 |
children |
rev | line source |
---|---|
131
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This program generates a CSV output listing all components in their |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * MCL order and carrying a selected set of attributes as columns. |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdlib.h> |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <string.h> |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <strings.h> |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <unistd.h> |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include "../libueda/mcl.h" |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 extern char *MCLfile; |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 extern struct component components[]; |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 extern int ncomponents; |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 extern char *get_comp_attr(); |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 main(argc, argv) |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 char **argv; |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 { |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 extern int optind; |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 register int c, ai; |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 register struct component *comp; |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 register char *attr; |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 while ((c = getopt(argc, argv, "M:")) != EOF) |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 switch (c) { |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 case 'M': |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 MCLfile = optarg; |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 break; |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 default: |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 /* getopt prints the error message */ |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 exit(1); |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 } |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 read_MCL(); |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 /* emit CSV header */ |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 fputs("Refdes", stdout); |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 for (ai = optind; ai < argc; ai++) |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 printf(",%s", argv[ai]); |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 putchar('\n'); |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 for (comp = components, c = 0; c < ncomponents; comp++, c++) { |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 fputs(comp->name, stdout); |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 for (ai = optind; ai < argc; ai++) { |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 attr = get_comp_attr(comp, argv[ai]); |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 if (!attr) |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 attr = ""; |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 printf(",%s", attr); |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 putchar('\n'); |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 } |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 exit(0); |
125fc4ef7eb0
ueda-csvattr program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 } |