2012-03-31 00:53:51 +03:00
|
|
|
/*
|
2012-07-13 02:14:45 +03:00
|
|
|
* genkicat.c - Generate catalog of expanded components or footprints
|
2012-03-31 00:53:51 +03:00
|
|
|
*
|
|
|
|
* Copyright 2012 by Werner Almesberger
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
2012-04-17 14:17:34 +03:00
|
|
|
#include <string.h>
|
2012-03-31 00:53:51 +03:00
|
|
|
|
2012-06-26 03:12:26 +03:00
|
|
|
#include "tree.h"
|
2012-07-12 04:27:22 +03:00
|
|
|
#include "libs.h"
|
2012-04-12 05:10:42 +03:00
|
|
|
#include "pdf.h"
|
2012-07-13 02:12:08 +03:00
|
|
|
#include "genkicat.h"
|
2012-04-19 00:44:22 +03:00
|
|
|
|
|
|
|
|
|
|
|
int quiet = 0;
|
2012-03-31 00:53:51 +03:00
|
|
|
|
|
|
|
|
|
|
|
static void usage(const char *name)
|
|
|
|
{
|
2012-04-16 21:55:48 +03:00
|
|
|
fprintf(stderr,
|
2012-07-13 01:20:50 +03:00
|
|
|
"usage: %s [-F] [-d|-D] [-p] [-P] [-q] [-L libdir ...] [-l lib ...]\n"
|
2012-12-21 05:11:14 +02:00
|
|
|
" %*s [-t title.ps] hierarchy [descriptions ...]\n\n"
|
|
|
|
" -d dump the tree instead of generating a PDF\n"
|
|
|
|
" -D dump all the canonical component names (without aliases)\n"
|
|
|
|
" -F use fped footprints instead of KiCad components\n"
|
|
|
|
" -L libdir search all libraries in the specified directory\n"
|
|
|
|
" -l lib search the specified library\n"
|
|
|
|
" -p use portrait orientation; default: landscape\n"
|
|
|
|
" -P generate Postscript instead of PDF (mainly for debugging)\n"
|
|
|
|
" -q don't show progress\n"
|
|
|
|
" -t title.ps Postscript file with title page\n"
|
2012-04-17 14:17:34 +03:00
|
|
|
, name, (int) strlen(name), "");
|
2012-03-31 00:53:51 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2012-07-12 06:29:21 +03:00
|
|
|
struct lib *lib = &comp_lib;
|
2012-03-31 00:53:51 +03:00
|
|
|
FILE *file;
|
|
|
|
int c;
|
2012-04-18 04:18:12 +03:00
|
|
|
int opt_dump_tree = 0, opt_dump_comp = 0, postscript = 0, portrait = 0;
|
2012-12-21 05:11:14 +02:00
|
|
|
const char *title_page = NULL;
|
2012-04-17 11:39:32 +03:00
|
|
|
char **arg;
|
2012-03-31 00:53:51 +03:00
|
|
|
|
2012-12-21 05:11:14 +02:00
|
|
|
while ((c = getopt(argc, argv, "dDFL:l:Ppqt:")) != EOF)
|
2012-03-31 00:53:51 +03:00
|
|
|
switch (c) {
|
2012-04-17 11:43:46 +03:00
|
|
|
case 'd':
|
2012-04-18 04:18:12 +03:00
|
|
|
opt_dump_tree = 1;
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
opt_dump_comp = 1;
|
2012-04-17 11:43:46 +03:00
|
|
|
break;
|
2012-07-12 06:58:12 +03:00
|
|
|
case 'F':
|
|
|
|
lib = &fped_lib;
|
|
|
|
break;
|
2012-03-31 00:53:51 +03:00
|
|
|
case 'L':
|
2012-07-12 06:29:21 +03:00
|
|
|
add_libdir(lib, optarg);
|
2012-03-31 00:53:51 +03:00
|
|
|
break;
|
|
|
|
case 'l':
|
2012-07-12 06:29:21 +03:00
|
|
|
add_lib(lib, optarg);
|
2012-03-31 00:53:51 +03:00
|
|
|
break;
|
2012-04-17 14:17:34 +03:00
|
|
|
case 'P':
|
|
|
|
postscript = 1;
|
|
|
|
break;
|
2012-04-17 14:21:14 +03:00
|
|
|
case 'p':
|
|
|
|
portrait = 1;
|
|
|
|
break;
|
2012-04-19 00:44:22 +03:00
|
|
|
case 'q':
|
|
|
|
quiet = 1;
|
|
|
|
break;
|
2012-12-21 05:11:14 +02:00
|
|
|
case 't':
|
|
|
|
title_page = optarg;
|
|
|
|
break;
|
2012-03-31 00:53:51 +03:00
|
|
|
default:
|
|
|
|
usage(*argv);
|
|
|
|
}
|
|
|
|
|
2012-04-18 04:18:12 +03:00
|
|
|
if (opt_dump_tree && opt_dump_comp)
|
|
|
|
usage(*argv);
|
|
|
|
|
2012-04-17 11:39:32 +03:00
|
|
|
switch (argc-optind) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
break;
|
|
|
|
default:
|
2012-03-31 00:53:51 +03:00
|
|
|
usage(*argv);
|
2012-04-17 11:39:32 +03:00
|
|
|
}
|
2012-03-31 00:53:51 +03:00
|
|
|
|
|
|
|
file = fopen(argv[optind], "r");
|
|
|
|
if (!file) {
|
|
|
|
perror(argv[optind]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
read_tree(file);
|
|
|
|
fclose(file);
|
2012-07-12 06:29:21 +03:00
|
|
|
set_libs(lib, tree);
|
2012-04-17 11:39:32 +03:00
|
|
|
|
|
|
|
for (arg = argv+optind+1; *arg; arg++) {
|
|
|
|
file = fopen(*arg, "r");
|
|
|
|
if (!file) {
|
|
|
|
perror(*arg);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
read_desc(file);
|
|
|
|
fclose(file);
|
|
|
|
}
|
2012-04-18 04:18:12 +03:00
|
|
|
if (opt_dump_tree)
|
2012-04-17 11:43:46 +03:00
|
|
|
dump_tree();
|
2012-04-18 04:18:12 +03:00
|
|
|
else if (opt_dump_comp)
|
|
|
|
dump_comp();
|
2012-04-17 11:43:46 +03:00
|
|
|
else
|
2012-12-21 05:11:14 +02:00
|
|
|
make_pdf(!postscript, portrait, title_page);
|
2012-03-31 00:53:51 +03:00
|
|
|
return 0;
|
|
|
|
}
|