1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-26 18:42:28 +02:00

sch2fig/lib-parse.c (lib_parse): parse entire file, not just one line

This commit is contained in:
Werner Almesberger 2016-08-01 13:10:51 -03:00
parent 07eb87e25f
commit f0f2303fc3
3 changed files with 8 additions and 17 deletions

View File

@ -17,6 +17,7 @@
#include "util.h" #include "util.h"
#include "text.h" #include "text.h"
#include "file.h"
#include "lib.h" #include "lib.h"
@ -129,8 +130,9 @@ static bool parse_arc(struct lib_obj *obj, const char *line)
/* ----- Library parser ---------------------------------------------------- */ /* ----- Library parser ---------------------------------------------------- */
bool lib_parse(struct lib *lib, const char *line) static bool lib_parse_line(void *user, const char *line)
{ {
struct lib *lib = user;
int n = 0; int n = 0;
unsigned points; unsigned points;
struct lib_obj *obj; struct lib_obj *obj;
@ -251,17 +253,16 @@ bool lib_parse(struct lib *lib, const char *line)
} }
void lib_reset(struct lib *lib) void lib_parse(struct lib *lib, const char *file)
{ {
lib->state = lib_skip; lib->state = lib_skip;
lib->lineno = 0; lib->lineno = 0;
file_read(file, lib_parse_line, lib);
} }
void lib_init(struct lib *lib) void lib_init(struct lib *lib)
{ {
lib_reset(lib);
lib->comps = NULL; lib->comps = NULL;
lib->next_comp = &lib->comps; lib->next_comp = &lib->comps;
} }

View File

@ -118,8 +118,7 @@ const struct comp *lib_find(const struct lib *lib, const char *name);
bool lib_field_visible(const struct comp *comp, int n); bool lib_field_visible(const struct comp *comp, int n);
void lib_render(const struct comp *comp, unsigned unit, const int m[6]); void lib_render(const struct comp *comp, unsigned unit, const int m[6]);
bool lib_parse(struct lib *lib, const char *line); void lib_parse(struct lib *lib, const char *file);
void lib_init(struct lib *lib); void lib_init(struct lib *lib);
void lib_reset(struct lib *lib);
#endif /* !LIB_H */ #endif /* !LIB_H */

View File

@ -21,7 +21,6 @@
#include "fig.h" #include "fig.h"
#include "cairo.h" #include "cairo.h"
#include "gfx.h" #include "gfx.h"
#include "file.h"
#include "lib.h" #include "lib.h"
#include "sch.h" #include "sch.h"
#include "main.h" #include "main.h"
@ -34,12 +33,6 @@ static struct gfx_ops const *ops_list[] = {
}; };
static bool do_lib_parse(void *user, const char *line)
{
return lib_parse(user, line);
}
void usage(const char *name) void usage(const char *name)
{ {
fprintf(stderr, fprintf(stderr,
@ -83,10 +76,8 @@ int main(int argc, char *const *argv)
usage(*argv); usage(*argv);
lib_init(&lib); lib_init(&lib);
for (arg = optind; arg != dashdash - 1; arg++) { for (arg = optind; arg != dashdash - 1; arg++)
lib_reset(&lib); lib_parse(&lib, argv[arg]);
file_read(argv[arg], do_lib_parse, &lib);
}
if (dashdash == argc) { if (dashdash == argc) {
gfx_argc = 1; gfx_argc = 1;