FreeCalypso > hg > ueda-linux
annotate netdiff/renpart/mainproc.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 | |
children | bf188727e606 |
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; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 while (*cp) { |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 if (isspace(*cp)) { |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 *cp++ = '\0'; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 break; |
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 if (*cp++ != '\\') |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 continue; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 switch (*cp++) { |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 case '\\': |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 case 'n': |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 case 'r': |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 case 't': |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 case ' ': |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 case '\t': |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 continue; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 default: |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 fprintf(stderr, "%s line %d: invalid escape\n", |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 infname, lineno); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 exit(1); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 } |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 } |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 } |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 } |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 static void |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 process_netpoint() |
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 char *cp, *refdes; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 struct part_rename *rp; |
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 cp = index(fields[1], '.'); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 if (!cp) { |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 fprintf(stderr, "%s line %d: expected '.' not found\n", |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 infname, lineno); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 exit(1); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 } |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 *cp++ = '\0'; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 refdes = fields[1]; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 for (rp = part_rename_list; rp; rp = rp->next) { |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 if (!strcmp(refdes, rp->old)) { |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 refdes = rp->new; |
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 } |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 } |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 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
|
95 } |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 main_process(input_filename) |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 char *input_filename; |
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 infname = input_filename; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 inf = fopen(infname, "r"); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 if (!inf) { |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 perror(infname); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 exit(1); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 } |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 for (;;) { |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 if (!get_line()) |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 break; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 parse_into_fields(); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 if (!nfields) |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 continue; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 if (nfields != 2) { |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 fprintf(stderr, "%s line %d: expected 2 fields\n", |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 infname, lineno); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 exit(1); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 } |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 process_netpoint(); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 } |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 fclose(inf); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 return(0); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 } |