From fe50addf65ecfee3a5b03357b8d54ad34356b934 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 14 Dec 2010 16:17:29 -0300 Subject: [PATCH] cameo: added invocation with an optional script - cameo.c (usage, main): third form of invocation: cameo [script] - cameo.c (run_script, main): run yyparse --- cameo/cameo.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) 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); }