1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2024-12-22 23:26:27 +02:00

gp2rml/gp2rml.c (main): use getopt

This commit is contained in:
Werner Almesberger 2015-05-22 10:46:37 -03:00
parent ecaffbb1fe
commit ea11b88bee

View File

@ -1,8 +1,8 @@
/* /*
* gp2rml.c - Convert from gnuplot to RML * gp2rml.c - Convert from gnuplot to RML
* *
* Written 2010-2013 by Werner Almesberger * Written 2010-2013, 2015 by Werner Almesberger
* Copyright 2010-2013 Werner Almesberger * Copyright 2010-2013, 2015 Werner Almesberger
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -35,6 +35,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h>
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
@ -197,42 +198,41 @@ static void usage(const char *name)
} }
int main(int argc, const char **argv) int main(int argc, char *const *argv)
{ {
const char *name;
FILE *file; FILE *file;
char *end; char *end;
int i; int i;
double p[3]; double p[3];
int c;
name = *argv; while ((c = getopt(argc, argv, "s:")) != EOF)
switch (c) {
case 's':
z_scale = strtod(optarg &end);
if (*end)
usage(*argv);
break;
default:
usage(*argv);
}
if (argc > 2 && !strcmp(argv[1], "-s")) { switch (argc - optind) {
if (argc < 3) case 3:
usage(name);
z_scale = strtod(argv[2], &end);
if (*end)
usage(name);
argc -= 2;
argv += 2;
}
switch (argc) {
case 4:
file = stdin; file = stdin;
break; break;
case 5: case 4:
file = fopen(argv[4], "r"); file = fopen(argv[optind + 3], "r");
if (!file) { if (!file) {
perror(argv[4]); perror(argv[optind + 3]);
return 1; return 1;
} }
break; break;
default: default:
usage(name); usage(*argv);
} }
for (i = 0; i != 3; i++) { for (i = 0; i != 3; i++) {
p[i] = strtod(argv[i+1], &end); p[i] = strtod(argv[optind + i], &end);
/* /*
* Allow the clearance to have a unit, for consistency in * Allow the clearance to have a unit, for consistency in
* mkmk-simple * mkmk-simple
@ -240,7 +240,7 @@ int main(int argc, const char **argv)
if (!i && *end && !strcmp(end, "mm")) if (!i && *end && !strcmp(end, "mm"))
continue; continue;
if (*end || p[i] <= 0) if (*end || p[i] <= 0)
usage(name); usage(*argv);
} }
process_file(file); process_file(file);