annotate netdiff/flip2pin/readlist.c @ 146:7ddfb9a67b0c

netdiff: donl-flip2pin utility written, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 15 Nov 2020 03:32:48 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 static char *infname;
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 static FILE *inf;
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 static char linebuf[256];
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 static int lineno;
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 static void
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 refdes_entry(entry)
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 char *entry;
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 struct flip_list *rp, **rpp;
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 char *dp;
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 for (rpp = &flip_list; rp = *rpp; rpp = &rp->next) {
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 if (!strcmp(rp->refdes, entry)) {
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 fprintf(stderr, "%s line %d: refdes %s given twice\n",
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 infname, lineno, entry);
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 exit(1);
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 }
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 }
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 rp = malloc(sizeof(struct flip_list) + strlen(entry) + 1);
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 dp = (char *)(rp + 1);
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 rp->refdes = dp;
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 strcpy(dp, entry);
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 rp->next = 0;
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 *rpp = rp;
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
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 static void
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 process_line()
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 {
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 char *cp, *np;
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 for (cp = linebuf; ; ) {
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 while (isspace(*cp))
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 cp++;
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 if (*cp == '\0' || *cp == '#')
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 break;
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 np = cp;
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 while (*cp && !isspace(*cp))
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 cp++;
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (*cp)
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 *cp++ = '\0';
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 refdes_entry(np);
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 }
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 read_flip_list(input_filename)
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 char *input_filename;
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 {
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 infname = input_filename;
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 inf = fopen(infname, "r");
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 if (!inf) {
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 perror(infname);
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 exit(1);
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 while (fgets(linebuf, sizeof linebuf, inf)) {
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 lineno++;
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 process_line();
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 fclose(inf);
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 return(0);
7ddfb9a67b0c netdiff: donl-flip2pin utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 }