mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2024-12-23 04:50:49 +02:00
gp2rml/gp2rml.c (main): use getopt
This commit is contained in:
parent
ecaffbb1fe
commit
ea11b88bee
@ -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) {
|
||||||
if (argc > 2 && !strcmp(argv[1], "-s")) {
|
case 's':
|
||||||
if (argc < 3)
|
z_scale = strtod(optarg &end);
|
||||||
usage(name);
|
|
||||||
z_scale = strtod(argv[2], &end);
|
|
||||||
if (*end)
|
if (*end)
|
||||||
usage(name);
|
usage(*argv);
|
||||||
argc -= 2;
|
break;
|
||||||
argv += 2;
|
default:
|
||||||
|
usage(*argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (argc) {
|
switch (argc - optind) {
|
||||||
case 4:
|
case 3:
|
||||||
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user