mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2025-04-21 12:27:27 +03:00
ptrude/: proper command-line handling; open -d for debug mode
This commit is contained in:
@@ -10,18 +10,107 @@
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "path.h"
|
||||
#include "ptrude.h"
|
||||
|
||||
|
||||
int main(void)
|
||||
int debug = 0;
|
||||
|
||||
|
||||
static FILE *open_file(const char *name, const char *mode)
|
||||
{
|
||||
const struct path *path;
|
||||
FILE *file;
|
||||
|
||||
path = load_path(stdin);
|
||||
path = round_path(path, 1, 0.1);
|
||||
save_path(stdout, path);
|
||||
if (!strcmp(name, "-"))
|
||||
return strcmp(mode, "r") ? stdout : stdin;
|
||||
|
||||
file = fopen(name, mode);
|
||||
if (!file) {
|
||||
perror(name);
|
||||
exit(1);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
static void close_file(FILE *file)
|
||||
{
|
||||
if (file == stdin || file == stdout)
|
||||
return;
|
||||
if (fclose(file) == EOF) {
|
||||
perror("fclose");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void usage(const char *name)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: %s shape radius tolerance\n"
|
||||
"%6s %s path shape radius tolerance\n",
|
||||
name, "", name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
FILE *file;
|
||||
const struct path *path = NULL, *shape;
|
||||
double r, d;
|
||||
char *end;
|
||||
int c;
|
||||
|
||||
while ((c = getopt(argc, argv, "d")) != EOF)
|
||||
switch (c) {
|
||||
case 'd':
|
||||
debug = 1;
|
||||
break;
|
||||
default:
|
||||
usage(*argv);
|
||||
}
|
||||
|
||||
switch (argc-optind) {
|
||||
case 3:
|
||||
break;
|
||||
case 4:
|
||||
file = open_file(argv[optind], "r");
|
||||
path = load_path(file);
|
||||
close_file(file);
|
||||
break;
|
||||
default:
|
||||
usage(*argv);
|
||||
}
|
||||
|
||||
file = open_file(argv[argc-3], "r");
|
||||
shape = load_path(file);
|
||||
close_file(file);
|
||||
|
||||
r = strtod(argv[argc-2], &end);
|
||||
if (*end || r <= 0)
|
||||
usage(*argv);
|
||||
d = strtod(argv[argc-1], &end);
|
||||
if (*end || d <= 0)
|
||||
usage (*argv);
|
||||
|
||||
if (path) {
|
||||
/*
|
||||
* We split the error budget evenly between path and shape.
|
||||
*/
|
||||
path = round_path(path, r, sqrt(d));
|
||||
shape = round_path(shape, r, sqrt(d));
|
||||
/* ... now all that's missing is the extrusion :-) */
|
||||
} else {
|
||||
shape = round_path(shape, r, d);
|
||||
save_path(stdout, shape);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user