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-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"
|
|
|
|
#include "gui.h"
|
|
|
|
|
|
|
|
|
|
|
|
extern void scan_empty(void);
|
|
|
|
extern int yyparse(void);
|
|
|
|
|
2009-08-10 16:51:51 +03:00
|
|
|
char *save_file = NULL;
|
|
|
|
|
2009-08-03 19:12:47 +03:00
|
|
|
|
|
|
|
static void load_file(const char *name)
|
|
|
|
{
|
|
|
|
reporter = report_parse_error;
|
|
|
|
run_cpp_on_file(name);
|
|
|
|
(void) yyparse();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-10 16:51:51 +03:00
|
|
|
static void usage(const char *name)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "usage: %s [in_file [out_file]]\n", name);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-03 19:12:47 +03:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2009-08-10 16:51:51 +03:00
|
|
|
const char *name = *argv;
|
2009-08-03 19:12:47 +03:00
|
|
|
int error;
|
|
|
|
|
|
|
|
error = gui_init(&argc, &argv);
|
|
|
|
if (error)
|
|
|
|
return error;
|
2009-08-10 16:51:51 +03:00
|
|
|
switch (argc) {
|
|
|
|
case 1:
|
2009-08-03 19:12:47 +03:00
|
|
|
scan_empty();
|
|
|
|
(void) yyparse();
|
2009-08-10 16:51:51 +03:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
save_file = argv[2];
|
|
|
|
/* fall through */
|
|
|
|
case 2:
|
2009-08-03 19:12:47 +03:00
|
|
|
load_file(argv[1]);
|
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
|
|
|
|
|
|
|
if (!part_name)
|
|
|
|
part_name = stralloc("_");
|
|
|
|
|
2009-08-03 19:12:47 +03:00
|
|
|
reporter = report_to_stderr;
|
|
|
|
if (!instantiate())
|
|
|
|
return 1;
|
|
|
|
// inst_debug();
|
2009-08-05 13:35:48 +03:00
|
|
|
error = gui_main();
|
2009-08-03 19:12:47 +03:00
|
|
|
if (error)
|
|
|
|
return error;
|
2009-08-05 13:35:48 +03:00
|
|
|
|
2009-08-06 07:56:47 +03:00
|
|
|
// dump(stdout);
|
2009-08-05 13:35:48 +03:00
|
|
|
|
2009-08-03 19:12:47 +03:00
|
|
|
return 0;
|
|
|
|
}
|