FreeCalypso > hg > ueda-linux
comparison 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 |
comparison
equal
deleted
inserted
replaced
37:ce887659d12e | 38:aa0539cc3d41 |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 #include <ctype.h> | |
4 #include <string.h> | |
5 #include <strings.h> | |
6 | |
7 char *input_filename; | |
8 int input_lineno; | |
9 char input_line_buf[1024], input_line_starkw[64]; | |
10 | |
11 #define MAX_FIELDS 63 | |
12 char *input_line_fields[MAX_FIELDS+1]; | |
13 int input_line_nfields; | |
14 | |
15 static FILE *inf; | |
16 | |
17 open_input_file() | |
18 { | |
19 inf = fopen(input_filename, "r"); | |
20 if (!inf) { | |
21 perror(input_filename); | |
22 exit(1); | |
23 } | |
24 return(0); | |
25 } | |
26 | |
27 get_input_line() | |
28 { | |
29 char *cp; | |
30 | |
31 if (!fgets(input_line_buf, sizeof input_line_buf, inf)) | |
32 return(0); | |
33 input_lineno++; | |
34 cp = index(input_line_buf, '\n'); | |
35 if (!cp) { | |
36 fprintf(stderr, "%s line %d: missing newline\n", | |
37 input_filename, input_lineno); | |
38 exit(1); | |
39 } | |
40 *cp = '\0'; | |
41 if (cp > input_line_buf && cp[-1] == '\r') | |
42 *--cp = '\0'; | |
43 return(1); | |
44 } | |
45 | |
46 parse_starline() | |
47 { | |
48 char *cp, *srcstr; | |
49 | |
50 srcstr = input_line_buf + 1; | |
51 cp = index(srcstr, '*'); | |
52 if (!cp) { | |
53 fprintf(stderr, "%s line %d: opening '*' but no closing '*'\n", | |
54 input_filename, input_lineno); | |
55 exit(1); | |
56 } | |
57 *cp = '\0'; | |
58 if (strlen(srcstr) + 1 > sizeof input_line_starkw) { | |
59 fprintf(stderr, "%s line %d: star keyword is too long\n", | |
60 input_filename, input_lineno); | |
61 exit(1); | |
62 } | |
63 strcpy(input_line_starkw, srcstr); | |
64 *cp = '*'; | |
65 } | |
66 | |
67 parse_input_line_fields() | |
68 { | |
69 char *cp; | |
70 int n; | |
71 | |
72 cp = input_line_buf; | |
73 for (n = 0; ; ) { | |
74 while (isspace(*cp)) | |
75 cp++; | |
76 if (!*cp) | |
77 break; | |
78 if (n >= MAX_FIELDS) { | |
79 fprintf(stderr, | |
80 "%s line %d: number of fields exceeds limit\n", | |
81 input_filename, input_lineno); | |
82 exit(1); | |
83 } | |
84 input_line_fields[n++] = cp; | |
85 while (*cp && !isspace(*cp)) | |
86 cp++; | |
87 if (*cp) | |
88 *cp++ = '\0'; | |
89 } | |
90 input_line_fields[n] = 0; | |
91 input_line_nfields = n; | |
92 } |