FreeCalypso > hg > ueda-linux
annotate netdiff/flip2pin/mainproc.c @ 150:bcf011f6d7a5
KWH020ST23-F01.fp created
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 22 Jun 2021 22:20:53 +0000 |
parents | 7ddfb9a67b0c |
children |
rev | line source |
---|---|
146
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <ctype.h> |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include <string.h> |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include <strings.h> |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include <stdio.h> |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdlib.h> |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include "struct.h" |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 extern struct flip_list *flip_list; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #define MAX_FIELDS 2 |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 static char *infname; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 static FILE *inf; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 static char linebuf[512]; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 static int lineno; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 static char *fields[MAX_FIELDS]; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 static unsigned nfields; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 static |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 get_line() |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 { |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 if (!fgets(linebuf, sizeof linebuf, inf)) |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 return(0); |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 lineno++; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (!index(linebuf, '\n')) { |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 fprintf(stderr, "%s line %d: missing newline\n", |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 infname, lineno); |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 exit(1); |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 } |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 return(1); |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 } |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 static void |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 parse_into_fields() |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 { |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 char *cp; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 nfields = 0; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 for (cp = linebuf; ; ) { |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 while (isspace(*cp)) |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 cp++; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 if (*cp == '\0' || *cp == '#') |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 break; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 if (nfields >= MAX_FIELDS) { |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 fprintf(stderr, "%s line %d: too many fields\n", |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 infname, lineno); |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 exit(1); |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 fields[nfields++] = cp; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 while (*cp && !isspace(*cp)) |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 cp++; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 if (*cp) |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 *cp++ = '\0'; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 } |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 } |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 static void |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 process_netpoint() |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 { |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 char *cp, *refdes, *pin; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 struct flip_list *rp; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 cp = index(fields[1], '.'); |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 if (!cp) { |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 fprintf(stderr, "%s line %d: expected '.' not found\n", |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 infname, lineno); |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 exit(1); |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 } |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 *cp++ = '\0'; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 refdes = fields[1]; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 pin = cp; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 for (rp = flip_list; rp; rp = rp->next) { |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 if (!strcmp(refdes, rp->refdes)) |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 break; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 } |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 if (rp) { |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 if (!strcmp(pin, "1")) |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 pin = "2"; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 else if (!strcmp(pin, "2")) |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 pin = "1"; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 else { |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 fprintf(stderr, |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 "%s line %d: flip pin number is not 1 or 2\n", |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 infname, lineno); |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 exit(1); |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 } |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 } |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 printf("%s\t%s.%s\n", fields[0], refdes, pin); |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 } |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 main_process(input_filename) |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 char *input_filename; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 { |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 infname = input_filename; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 inf = fopen(infname, "r"); |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 if (!inf) { |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 perror(infname); |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 exit(1); |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 } |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 for (;;) { |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 if (!get_line()) |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 break; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 parse_into_fields(); |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 if (!nfields) |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 continue; |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 if (nfields != 2) { |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 fprintf(stderr, "%s line %d: expected 2 fields\n", |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 infname, lineno); |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 exit(1); |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 } |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 process_netpoint(); |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 } |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 fclose(inf); |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 return(0); |
7ddfb9a67b0c
netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 } |