gp2rml/gp2rml.c |
1 | 1 | /* |
2 | 2 | * gp2rml.c - Convert from gnuplot to RML |
3 | 3 | * |
4 | | * Written 2010-2013 by Werner Almesberger |
5 | | * Copyright 2010-2013 Werner Almesberger |
| 4 | * Written 2010-2013, 2015 by Werner Almesberger |
| 5 | * Copyright 2010-2013, 2015 Werner Almesberger |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
35 | 35 | |
36 | 36 | #include <stdlib.h> |
37 | 37 | #include <stdio.h> |
| 38 | #include <unistd.h> |
38 | 39 | #include <string.h> |
39 | 40 | #include <math.h> |
40 | 41 | |
... | ... | |
197 | 198 | } |
198 | 199 | |
199 | 200 | |
200 | | int main(int argc, const char **argv) |
| 201 | int main(int argc, char *const *argv) |
201 | 202 | { |
202 | | const char *name; |
203 | 203 | FILE *file; |
204 | 204 | char *end; |
205 | 205 | int i; |
206 | 206 | double p[3]; |
| 207 | int c; |
| 208 | |
| 209 | while ((c = getopt(argc, argv, "s:")) != EOF) |
| 210 | switch (c) { |
| 211 | case 's': |
| 212 | z_scale = strtod(optarg &end); |
| 213 | if (*end) |
| 214 | usage(*argv); |
| 215 | break; |
| 216 | default: |
| 217 | usage(*argv); |
| 218 | } |
207 | 219 | |
208 | | name = *argv; |
209 | | |
210 | | if (argc > 2 && !strcmp(argv[1], "-s")) { |
211 | | if (argc < 3) |
212 | | usage(name); |
213 | | z_scale = strtod(argv[2], &end); |
214 | | if (*end) |
215 | | usage(name); |
216 | | argc -= 2; |
217 | | argv += 2; |
218 | | } |
219 | | |
220 | | switch (argc) { |
221 | | case 4: |
| 220 | switch (argc - optind) { |
| 221 | case 3: |
222 | 222 | file = stdin; |
223 | 223 | break; |
224 | | case 5: |
225 | | file = fopen(argv[4], "r"); |
| 224 | case 4: |
| 225 | file = fopen(argv[optind + 3], "r"); |
226 | 226 | if (!file) { |
227 | | perror(argv[4]); |
| 227 | perror(argv[optind + 3]); |
228 | 228 | return 1; |
229 | 229 | } |
230 | 230 | break; |
231 | 231 | default: |
232 | | usage(name); |
| 232 | usage(*argv); |
233 | 233 | } |
234 | 234 | for (i = 0; i != 3; i++) { |
235 | | p[i] = strtod(argv[i+1], &end); |
| 235 | p[i] = strtod(argv[optind + i], &end); |
236 | 236 | /* |
237 | 237 | * Allow the clearance to have a unit, for consistency in |
238 | 238 | * mkmk-simple |
... | ... | |
240 | 240 | if (!i && *end && !strcmp(end, "mm")) |
241 | 241 | continue; |
242 | 242 | if (*end || p[i] <= 0) |
243 | | usage(name); |
| 243 | usage(*argv); |
244 | 244 | } |
245 | 245 | |
246 | 246 | process_file(file); |