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:
parent
ecaffbb1fe
commit
ea11b88bee
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* gp2rml.c - Convert from gnuplot to RML
|
||||
*
|
||||
* Written 2010-2013 by Werner Almesberger
|
||||
* Copyright 2010-2013 Werner Almesberger
|
||||
* Written 2010-2013, 2015 by Werner Almesberger
|
||||
* Copyright 2010-2013, 2015 Werner Almesberger
|
||||
*
|
||||
* 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
|
||||
@ -35,6 +35,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.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;
|
||||
char *end;
|
||||
int i;
|
||||
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")) {
|
||||
if (argc < 3)
|
||||
usage(name);
|
||||
z_scale = strtod(argv[2], &end);
|
||||
if (*end)
|
||||
usage(name);
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
}
|
||||
|
||||
switch (argc) {
|
||||
case 4:
|
||||
switch (argc - optind) {
|
||||
case 3:
|
||||
file = stdin;
|
||||
break;
|
||||
case 5:
|
||||
file = fopen(argv[4], "r");
|
||||
case 4:
|
||||
file = fopen(argv[optind + 3], "r");
|
||||
if (!file) {
|
||||
perror(argv[4]);
|
||||
perror(argv[optind + 3]);
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
usage(name);
|
||||
usage(*argv);
|
||||
}
|
||||
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
|
||||
* mkmk-simple
|
||||
@ -240,7 +240,7 @@ int main(int argc, const char **argv)
|
||||
if (!i && *end && !strcmp(end, "mm"))
|
||||
continue;
|
||||
if (*end || p[i] <= 0)
|
||||
usage(name);
|
||||
usage(*argv);
|
||||
}
|
||||
|
||||
process_file(file);
|
||||
|
Loading…
Reference in New Issue
Block a user