Root/cameo/cameo.c

1/*
2 * cameo.c - Toolpath adaptation and machine control
3 *
4 * Written 2010-2011 by Werner Almesberger
5 * Copyright 2010-2011 Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#include <stdlib.h>
15#include <stdio.h>
16#include <unistd.h>
17
18#include "path.h"
19#include "ops.h"
20#include "gnuplot.h"
21#include "gerber.h"
22
23
24extern int yyparse(void);
25extern FILE *yyin;
26
27
28static void run_script(const char *file)
29{
30
31    if (file) {
32        yyin = fopen(file, "r");
33        if (!yyin) {
34            perror(file);
35            exit(1);
36        }
37    }
38    yyparse();
39}
40
41
42static void usage(const char *name)
43{
44    fprintf(stderr,
45"usage: %s [-d] r_mm [in.gnuplot [out.gnuplot]]\n"
46" %s -g [-d] r_mm [in.gerber [out.gnuplot]]\n"
47" %s [script]\n\n"
48" -d put a dog-bone notch in each concave external corner\n"
49" -g input format is KiCad Gerber, not gnuplot\n"
50    , name, name, name);
51    exit(1);
52}
53
54
55int main(int argc, char **argv)
56{
57    char *in = NULL, *out = NULL;
58    char *end;
59    int gerber = 0, dog_bone = 0;
60    double r;
61    struct path *paths;
62    int c;
63
64    while ((c = getopt(argc, argv, "dg")) != EOF)
65        switch (c) {
66        case 'd':
67            dog_bone = 1;
68            break;
69        case 'g':
70            gerber = 1;
71            break;
72        default:
73            usage(*argv);
74        }
75
76    switch (argc-optind) {
77    case 3:
78        out = argv[optind+2];
79        /* fall through */
80    case 2:
81        in = argv[optind+1];
82        /* fall through */
83    case 1:
84        r = strtod(argv[optind], &end);
85        if (*end) {
86            if (argc-optind != 1)
87                usage(*argv);
88            run_script(argv[optind]);
89            return 0;
90        }
91        break;
92    case 0:
93        run_script(NULL);
94        return 0;
95    default:
96        usage(*argv);
97    }
98
99    if (gerber)
100        paths = gerber_read(in, r);
101    else
102        paths = gnuplot_read(in, r);
103    paths = tool_comp_paths(paths, dog_bone, 0); /* @@@ memory leak */
104    gnuplot_write(out, paths);
105
106    return 0;
107}
108

Archive Download this file

Branches:
master



interactive