annotate netdiff/renpart/mainproc.c @ 139:bf188727e606

donl-rename-parts reader: no tEDAx-style escapes
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 07 Sep 2020 04:25:11 +0000
parents 77acb816727b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
138
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <ctype.h>
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <string.h>
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <strings.h>
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <stdio.h>
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <stdlib.h>
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include "struct.h"
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 extern struct part_rename *part_rename_list;
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #define MAX_FIELDS 2
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 static char *infname;
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 static FILE *inf;
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 static char linebuf[512];
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 static int lineno;
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 static char *fields[MAX_FIELDS];
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 static unsigned nfields;
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 static
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 get_line()
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 {
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 if (!fgets(linebuf, sizeof linebuf, inf))
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 return(0);
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 lineno++;
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 if (!index(linebuf, '\n')) {
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 fprintf(stderr, "%s line %d: missing newline\n",
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 infname, lineno);
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 exit(1);
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 }
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 return(1);
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 static void
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 parse_into_fields()
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 {
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 char *cp;
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 nfields = 0;
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 for (cp = linebuf; ; ) {
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 while (isspace(*cp))
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 cp++;
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 if (*cp == '\0' || *cp == '#')
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 break;
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 if (nfields >= MAX_FIELDS) {
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 fprintf(stderr, "%s line %d: too many fields\n",
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 infname, lineno);
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 exit(1);
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 fields[nfields++] = cp;
139
bf188727e606 donl-rename-parts reader: no tEDAx-style escapes
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
50 while (*cp && !isspace(*cp))
bf188727e606 donl-rename-parts reader: no tEDAx-style escapes
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
51 cp++;
bf188727e606 donl-rename-parts reader: no tEDAx-style escapes
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
52 if (*cp)
bf188727e606 donl-rename-parts reader: no tEDAx-style escapes
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
53 *cp++ = '\0';
138
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 }
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 static void
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 process_netpoint()
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 {
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 char *cp, *refdes;
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 struct part_rename *rp;
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 cp = index(fields[1], '.');
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 if (!cp) {
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 fprintf(stderr, "%s line %d: expected '.' not found\n",
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 infname, lineno);
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 exit(1);
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 }
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 *cp++ = '\0';
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 refdes = fields[1];
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 for (rp = part_rename_list; rp; rp = rp->next) {
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 if (!strcmp(refdes, rp->old)) {
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 refdes = rp->new;
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 break;
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 }
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 }
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 printf("%s\t%s.%s\n", fields[0], refdes, cp);
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 }
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 main_process(input_filename)
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 char *input_filename;
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 {
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 infname = input_filename;
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 inf = fopen(infname, "r");
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 if (!inf) {
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 perror(infname);
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 exit(1);
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 }
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 for (;;) {
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 if (!get_line())
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 break;
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 parse_into_fields();
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 if (!nfields)
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 continue;
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 if (nfields != 2) {
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 fprintf(stderr, "%s line %d: expected 2 fields\n",
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 infname, lineno);
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 exit(1);
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 }
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 process_netpoint();
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 }
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 fclose(inf);
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 return(0);
77acb816727b netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 }