comparison 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
comparison
equal deleted inserted replaced
145:5e91200bf609 146:7ddfb9a67b0c
1 #include <ctype.h>
2 #include <string.h>
3 #include <strings.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include "struct.h"
7
8 extern struct flip_list *flip_list;
9
10 static char *infname;
11 static FILE *inf;
12 static char linebuf[256];
13 static int lineno;
14
15 static void
16 refdes_entry(entry)
17 char *entry;
18 {
19 struct flip_list *rp, **rpp;
20 char *dp;
21
22 for (rpp = &flip_list; rp = *rpp; rpp = &rp->next) {
23 if (!strcmp(rp->refdes, entry)) {
24 fprintf(stderr, "%s line %d: refdes %s given twice\n",
25 infname, lineno, entry);
26 exit(1);
27 }
28 }
29 rp = malloc(sizeof(struct flip_list) + strlen(entry) + 1);
30 dp = (char *)(rp + 1);
31 rp->refdes = dp;
32 strcpy(dp, entry);
33 rp->next = 0;
34 *rpp = rp;
35 }
36
37 static void
38 process_line()
39 {
40 char *cp, *np;
41
42 for (cp = linebuf; ; ) {
43 while (isspace(*cp))
44 cp++;
45 if (*cp == '\0' || *cp == '#')
46 break;
47 np = cp;
48 while (*cp && !isspace(*cp))
49 cp++;
50 if (*cp)
51 *cp++ = '\0';
52 refdes_entry(np);
53 }
54 }
55
56 read_flip_list(input_filename)
57 char *input_filename;
58 {
59 infname = input_filename;
60 inf = fopen(infname, "r");
61 if (!inf) {
62 perror(infname);
63 exit(1);
64 }
65 while (fgets(linebuf, sizeof linebuf, inf)) {
66 lineno++;
67 process_line();
68 }
69 fclose(inf);
70 return(0);
71 }