annotate pads2gpcb/readpads.c @ 38:aa0539cc3d41

pads2gpcb project started, skeleton compiles
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Mon, 11 Jan 2016 04:56:51 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
1 #include <stdio.h>
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
2 #include <stdlib.h>
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
3 #include <ctype.h>
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
4 #include <string.h>
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <strings.h>
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
6
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
7 char *input_filename;
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
8 int input_lineno;
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
9 char input_line_buf[1024], input_line_starkw[64];
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
10
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
11 #define MAX_FIELDS 63
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
12 char *input_line_fields[MAX_FIELDS+1];
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
13 int input_line_nfields;
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
14
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
15 static FILE *inf;
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
16
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
17 open_input_file()
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
18 {
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
19 inf = fopen(input_filename, "r");
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
20 if (!inf) {
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
21 perror(input_filename);
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
22 exit(1);
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
23 }
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
24 return(0);
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
25 }
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
26
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
27 get_input_line()
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
28 {
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
29 char *cp;
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
30
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
31 if (!fgets(input_line_buf, sizeof input_line_buf, inf))
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
32 return(0);
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
33 input_lineno++;
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
34 cp = index(input_line_buf, '\n');
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
35 if (!cp) {
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
36 fprintf(stderr, "%s line %d: missing newline\n",
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
37 input_filename, input_lineno);
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
38 exit(1);
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
39 }
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
40 *cp = '\0';
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
41 if (cp > input_line_buf && cp[-1] == '\r')
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
42 *--cp = '\0';
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
43 return(1);
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
44 }
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
45
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
46 parse_starline()
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
47 {
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
48 char *cp, *srcstr;
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
49
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
50 srcstr = input_line_buf + 1;
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
51 cp = index(srcstr, '*');
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
52 if (!cp) {
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
53 fprintf(stderr, "%s line %d: opening '*' but no closing '*'\n",
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
54 input_filename, input_lineno);
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
55 exit(1);
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
56 }
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
57 *cp = '\0';
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
58 if (strlen(srcstr) + 1 > sizeof input_line_starkw) {
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
59 fprintf(stderr, "%s line %d: star keyword is too long\n",
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
60 input_filename, input_lineno);
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
61 exit(1);
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
62 }
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
63 strcpy(input_line_starkw, srcstr);
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
64 *cp = '*';
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
65 }
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
66
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
67 parse_input_line_fields()
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
68 {
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
69 char *cp;
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
70 int n;
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
71
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
72 cp = input_line_buf;
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
73 for (n = 0; ; ) {
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
74 while (isspace(*cp))
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
75 cp++;
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
76 if (!*cp)
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
77 break;
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
78 if (n >= MAX_FIELDS) {
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
79 fprintf(stderr,
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
80 "%s line %d: number of fields exceeds limit\n",
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
81 input_filename, input_lineno);
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
82 exit(1);
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
83 }
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
84 input_line_fields[n++] = cp;
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
85 while (*cp && !isspace(*cp))
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
86 cp++;
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
87 if (*cp)
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
88 *cp++ = '\0';
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
89 }
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
90 input_line_fields[n] = 0;
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
91 input_line_nfields = n;
aa0539cc3d41 pads2gpcb project started, skeleton compiles
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
92 }