FreeCalypso > hg > freecalypso-tools
comparison ringtools/fc-pwt-comp.c @ 885:16e259bff02b
fc-pwt-comp: explicitly reject empty input
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 03 Apr 2022 03:55:02 +0000 |
parents | 8eb1f60f6676 |
children |
comparison
equal
deleted
inserted
replaced
884:8eb1f60f6676 | 885:16e259bff02b |
---|---|
161 } | 161 } |
162 | 162 |
163 main(argc, argv) | 163 main(argc, argv) |
164 char **argv; | 164 char **argv; |
165 { | 165 { |
166 int nonempty; | |
167 | |
166 if (argc != 3) { | 168 if (argc != 3) { |
167 fprintf(stderr, "usage: %s src-file bin-file\n", argv[0]); | 169 fprintf(stderr, "usage: %s src-file bin-file\n", argv[0]); |
168 exit(1); | 170 exit(1); |
169 } | 171 } |
170 if (strcmp(argv[1], "-")) { | 172 if (strcmp(argv[1], "-")) { |
183 if (!outf) { | 185 if (!outf) { |
184 perror(outfname); | 186 perror(outfname); |
185 exit(1); | 187 exit(1); |
186 } | 188 } |
187 | 189 |
190 nonempty = 0; | |
188 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { | 191 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { |
189 parse_line_into_fields(); | 192 parse_line_into_fields(); |
190 if (!nfields) | 193 if (!nfields) |
191 continue; | 194 continue; |
192 if (nfields == 3) | 195 if (nfields == 3) |
196 else { | 199 else { |
197 fprintf(stderr, "%s line %d: invalid syntax\n", | 200 fprintf(stderr, "%s line %d: invalid syntax\n", |
198 infname, lineno); | 201 infname, lineno); |
199 exit(1); | 202 exit(1); |
200 } | 203 } |
201 } | 204 nonempty = 1; |
202 exit(0); | 205 } |
203 } | 206 if (nonempty) |
207 exit(0); | |
208 else { | |
209 fprintf(stderr, "error: %s is empty\n", infname); | |
210 exit(1); | |
211 } | |
212 } |