2016-07-22 06:04:42 +03:00
|
|
|
/*
|
|
|
|
* main.c - Convert Eeschema schematics to FIG
|
|
|
|
*
|
|
|
|
* Written 2016 by Werner Almesberger
|
|
|
|
* Copyright 2016 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2016-07-22 05:54:32 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "fig.h"
|
|
|
|
#include "lib.h"
|
|
|
|
#include "sch.h"
|
|
|
|
|
|
|
|
|
|
|
|
static bool do_sch_parse(void *ctx, const char *line)
|
|
|
|
{
|
|
|
|
return sch_parse(ctx, line);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool do_lib_parse(void *ctx, const char *line)
|
|
|
|
{
|
|
|
|
return lib_parse(ctx, line);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void read_file(const char *name, void *ctx,
|
|
|
|
bool (*parse)(void *ctx, const char *line))
|
|
|
|
{
|
|
|
|
FILE *file;
|
|
|
|
char buf[1000];
|
|
|
|
char *nl;
|
|
|
|
|
|
|
|
file = fopen(name, "r");
|
2016-07-22 06:19:19 +03:00
|
|
|
if (!file) {
|
|
|
|
perror(name);
|
|
|
|
exit(1);
|
|
|
|
}
|
2016-07-22 05:54:32 +03:00
|
|
|
while (fgets(buf, sizeof(buf), file)) {
|
|
|
|
nl = strchr(buf, '\n');
|
|
|
|
if (nl)
|
|
|
|
*nl = 0;
|
|
|
|
if (!parse(ctx, buf))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fclose(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void usage(const char *name)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "usage: %s [file.lib ...] file.sch\n", name);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int arg;
|
|
|
|
|
|
|
|
if (argc < 2)
|
|
|
|
usage(*argv);
|
|
|
|
|
|
|
|
fig_init();
|
|
|
|
for (arg = 1; arg != argc; arg++) {
|
|
|
|
if (arg == argc - 1) {
|
|
|
|
struct sch_ctx ctx;
|
|
|
|
|
|
|
|
sch_init(&ctx);
|
|
|
|
read_file(argv[arg], &ctx, do_sch_parse);
|
|
|
|
} else {
|
|
|
|
struct lib_ctx ctx;
|
|
|
|
|
|
|
|
lib_init(&ctx);
|
|
|
|
read_file(argv[arg], &ctx, do_lib_parse);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|