2009-08-03 19:12:47 +03:00
|
|
|
/*
|
|
|
|
* fped.c - Footprint editor, main function
|
|
|
|
*
|
|
|
|
* Written 2009 by Werner Almesberger
|
|
|
|
* Copyright 2009 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-08-10 16:51:51 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2009-08-11 23:17:39 +03:00
|
|
|
#include <unistd.h>
|
2009-08-03 19:12:47 +03:00
|
|
|
|
|
|
|
#include "cpp.h"
|
2009-08-07 03:48:06 +03:00
|
|
|
#include "util.h"
|
2009-08-03 19:12:47 +03:00
|
|
|
#include "error.h"
|
|
|
|
#include "obj.h"
|
|
|
|
#include "inst.h"
|
2009-08-11 23:17:39 +03:00
|
|
|
#include "file.h"
|
2009-08-03 19:12:47 +03:00
|
|
|
#include "gui.h"
|
2009-08-21 11:34:17 +03:00
|
|
|
#include "delete.h"
|
2009-08-16 07:12:37 +03:00
|
|
|
#include "fpd.h"
|
2009-08-03 19:12:47 +03:00
|
|
|
|
|
|
|
|
2009-08-11 23:17:39 +03:00
|
|
|
char *save_file_name = NULL;
|
2009-08-10 16:51:51 +03:00
|
|
|
|
2009-08-03 19:12:47 +03:00
|
|
|
|
|
|
|
static void load_file(const char *name)
|
|
|
|
{
|
2009-08-12 02:26:38 +03:00
|
|
|
if (file_exists(name) == 1) {
|
|
|
|
reporter = report_parse_error;
|
|
|
|
run_cpp_on_file(name);
|
|
|
|
} else {
|
|
|
|
scan_empty();
|
|
|
|
}
|
2009-08-03 19:12:47 +03:00
|
|
|
(void) yyparse();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-10 16:51:51 +03:00
|
|
|
static void usage(const char *name)
|
|
|
|
{
|
2009-08-11 23:17:39 +03:00
|
|
|
fprintf(stderr, "usage: %s [-k|-p] [in_file [out_file]]\n\n", name);
|
|
|
|
fprintf(stderr, " -k write KiCad output, then exit\n");
|
|
|
|
fprintf(stderr, " -p write Postscript output, then exit\n");
|
2009-08-10 16:51:51 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-03 19:12:47 +03:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2009-08-30 09:04:00 +03:00
|
|
|
char *name = *argv;
|
|
|
|
char **fake_argv;
|
|
|
|
char *args[2];
|
|
|
|
int fake_argc;
|
|
|
|
int error, batch;
|
2009-08-11 23:17:39 +03:00
|
|
|
int batch_write_kicad = 0, batch_write_ps = 0;
|
|
|
|
int c;
|
2009-08-03 19:12:47 +03:00
|
|
|
|
2009-08-11 23:17:39 +03:00
|
|
|
while ((c = getopt(argc, argv, "kp")) != EOF)
|
|
|
|
switch (c) {
|
|
|
|
case 'k':
|
|
|
|
batch_write_kicad = 1;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
batch_write_ps = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage(name);
|
|
|
|
}
|
|
|
|
|
2009-08-30 09:04:00 +03:00
|
|
|
batch = batch_write_kicad || batch_write_ps;
|
|
|
|
|
|
|
|
if (!batch) {
|
|
|
|
args[0] = name;
|
|
|
|
args[1] = NULL;
|
|
|
|
fake_argc = 1;
|
|
|
|
fake_argv = args;
|
|
|
|
error = gui_init(&fake_argc, &fake_argv);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2009-08-11 23:17:39 +03:00
|
|
|
switch (argc-optind) {
|
|
|
|
case 0:
|
2009-08-03 19:12:47 +03:00
|
|
|
scan_empty();
|
|
|
|
(void) yyparse();
|
2009-08-10 16:51:51 +03:00
|
|
|
break;
|
2009-08-11 23:17:39 +03:00
|
|
|
case 1:
|
|
|
|
load_file(argv[optind]);
|
|
|
|
save_file_name = argv[optind];
|
|
|
|
break;
|
2009-08-10 16:51:51 +03:00
|
|
|
case 2:
|
2009-08-11 23:17:39 +03:00
|
|
|
load_file(argv[optind]);
|
|
|
|
save_file_name = argv[optind+1];
|
|
|
|
if (!strcmp(save_file_name, "-"))
|
|
|
|
save_file_name = NULL;
|
2009-08-10 16:51:51 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage(name);
|
2009-08-03 19:12:47 +03:00
|
|
|
}
|
2009-08-07 03:48:06 +03:00
|
|
|
|
2009-08-17 23:42:51 +03:00
|
|
|
if (!pkg_name)
|
|
|
|
pkg_name = stralloc("_");
|
2009-08-07 03:48:06 +03:00
|
|
|
|
2009-08-03 19:12:47 +03:00
|
|
|
reporter = report_to_stderr;
|
|
|
|
if (!instantiate())
|
|
|
|
return 1;
|
2009-08-11 23:17:39 +03:00
|
|
|
|
|
|
|
if (batch_write_kicad)
|
|
|
|
write_kicad();
|
|
|
|
if (batch_write_ps)
|
|
|
|
write_ps();
|
2009-08-30 09:04:00 +03:00
|
|
|
if (!batch) {
|
2009-08-21 11:34:17 +03:00
|
|
|
error = gui_main();
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
purge();
|
|
|
|
inst_revert();
|
|
|
|
obj_cleanup();
|
|
|
|
unique_cleanup();
|
2009-08-05 13:35:48 +03:00
|
|
|
|
2009-08-03 19:12:47 +03:00
|
|
|
return 0;
|
|
|
|
}
|