diff --git a/cameo/cameo.c b/cameo/cameo.c index 001ff7c..6f4ed48 100644 --- a/cameo/cameo.c +++ b/cameo/cameo.c @@ -21,14 +21,33 @@ #include "gerber.h" +extern int yyparse(void); +extern FILE *yyin; + + +static void run_script(const char *file) +{ + + if (file) { + yyin = fopen(file, "r"); + if (!yyin) { + perror(file); + exit(1); + } + } + yyparse(); +} + + static void usage(const char *name) { fprintf(stderr, "usage: %s [-d] r_mm [in.gnuplot [out.gnuplot]]\n" -" %s -g [-d] r_mm [in.gerber [out.gnuplot]]\n\n" +" %s -g [-d] r_mm [in.gerber [out.gnuplot]]\n" +" %s [script]\n\n" " -d put a dog-bone notch in each concave external corner\n" " -g input format is KiCad Gerber, not gnuplot\n" - , name, name); + , name, name, name); exit(1); } @@ -36,6 +55,7 @@ static void usage(const char *name) int main(int argc, char **argv) { char *in = NULL, *out = NULL; + char *end; int gerber = 0, dog_bone = 0; double r; struct path *paths; @@ -61,8 +81,17 @@ int main(int argc, char **argv) in = argv[optind+1]; /* fall through */ case 1: - r = atof(argv[optind]); + r = strtod(argv[optind], &end); + if (*end) { + if (argc-optind != 1) + usage(*argv); + run_script(argv[optind]); + return 0; + } break; + case 0: + run_script(NULL); + return 0; default: usage(*argv); }