Root/genkicat/genkicat.c

1/*
2 * genkicat.c - Generate catalog of expanded components or footprints
3 *
4 * Copyright 2012 by Werner Almesberger
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12
13#include <stdlib.h>
14#include <stdio.h>
15#include <unistd.h>
16#include <string.h>
17
18#include "tree.h"
19#include "libs.h"
20#include "pdf.h"
21#include "genkicat.h"
22
23
24int quiet = 0;
25
26
27static void usage(const char *name)
28{
29    fprintf(stderr,
30"usage: %s [-F] [-d|-D] [-p] [-P] [-q] [-L libdir ...] [-l lib ...]\n"
31" %*s [-t title.ps] hierarchy [descriptions ...]\n\n"
32" -d dump the tree instead of generating a PDF\n"
33" -D dump all the canonical component names (without aliases)\n"
34" -F use fped footprints instead of KiCad components\n"
35" -L libdir search all libraries in the specified directory\n"
36" -l lib search the specified library\n"
37" -p use portrait orientation; default: landscape\n"
38" -P generate Postscript instead of PDF (mainly for debugging)\n"
39" -q don't show progress\n"
40" -t title.ps Postscript file with title page\n"
41    , name, (int) strlen(name), "");
42    exit(1);
43}
44
45
46int main(int argc, char **argv)
47{
48    struct lib *lib = &comp_lib;
49    FILE *file;
50    int c;
51    int opt_dump_tree = 0, opt_dump_comp = 0, postscript = 0, portrait = 0;
52    const char *title_page = NULL;
53    char **arg;
54
55    while ((c = getopt(argc, argv, "dDFL:l:Ppqt:")) != EOF)
56        switch (c) {
57        case 'd':
58            opt_dump_tree = 1;
59            break;
60        case 'D':
61            opt_dump_comp = 1;
62            break;
63        case 'F':
64            lib = &fped_lib;
65            break;
66        case 'L':
67            add_libdir(lib, optarg);
68            break;
69        case 'l':
70            add_lib(lib, optarg);
71            break;
72        case 'P':
73            postscript = 1;
74            break;
75        case 'p':
76            portrait = 1;
77            break;
78        case 'q':
79            quiet = 1;
80            break;
81        case 't':
82            title_page = optarg;
83            break;
84        default:
85            usage(*argv);
86        }
87
88    if (opt_dump_tree && opt_dump_comp)
89        usage(*argv);
90
91    switch (argc-optind) {
92    case 1:
93    case 2:
94        break;
95    default:
96        usage(*argv);
97    }
98
99    file = fopen(argv[optind], "r");
100    if (!file) {
101        perror(argv[optind]);
102        exit(1);
103    }
104    read_tree(file);
105    fclose(file);
106    set_libs(lib, tree);
107
108    for (arg = argv+optind+1; *arg; arg++) {
109        file = fopen(*arg, "r");
110        if (!file) {
111            perror(*arg);
112            exit(1);
113        }
114        read_desc(file);
115        fclose(file);
116    }
117    if (opt_dump_tree)
118        dump_tree();
119    else if (opt_dump_comp)
120        dump_comp();
121    else
122        make_pdf(!postscript, portrait, title_page);
123    return 0;
124}
125

Archive Download this file

Branches:
master



interactive