1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-06-25 08:47:39 +03:00

eeshow/kicad/pro.c: KiCad profile processing (to find file names)

This commit is contained in:
Werner Almesberger 2016-08-22 22:19:54 -03:00
parent e46f8382f3
commit 49d603aca3
3 changed files with 135 additions and 1 deletions

View File

@ -16,7 +16,7 @@ NAME = eeshow
OBJS = main.o version.o \
kicad/sch-parse.o kicad/sch-render.o kicad/lib-parse.o \
kicad/lib-render.o kicad/dwg.o kicad/delta.o kicad/sexpr.o \
kicad/pl-parse.o kicad/pl-render.o kicad/ext.o \
kicad/pl-parse.o kicad/pl-render.o kicad/ext.o kicad/pro.o \
gui/gui.o gui/over.o gui/style.o gui/aoi.o gui/fmt-pango.o gui/input.o \
gui/progress.o gui/glabel.o gui/sheet.o gui/history.o gui/render.o \
gui/help.o gui/icons.o \

110
eeshow/kicad/pro.c Normal file
View File

@ -0,0 +1,110 @@
/*
* kicad/pro.c - KiCad profile
*
* 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.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "misc/util.h"
#include "file/file.h"
#include "kicad/ext.h"
#include "kicad/pro.h"
struct pro_ctx {
enum pro_state {
pro_idle,
pro_libs, // [eeschema/libraries]
pro_editor, // [schematic_editor]
} state;
struct file_names *fn;
};
static bool pro_parse_line(const struct file *file,
void *user, const char *line)
{
struct pro_ctx *pro = user;
char *s;
if (strbegins(line, "[eeschema/libraries]")) {
pro->state = pro_libs;
return 1;
}
if (strbegins(line, "[schematic_editor]")) {
pro->state = pro_editor;
return 1;
}
if (*line == '[') {
pro->state = pro_idle;
return 1;
}
switch (pro->state) {
case pro_idle:
break;
case pro_libs:
if (sscanf(line, "LibName%*u=%ms", &s) == 1) {
char *dot;
pro->fn->n_libs++;
pro->fn->libs = realloc_type_n(pro->fn->libs,
const char *, pro->fn->n_libs);
dot = strrchr(s, '.');
if (!dot || strcmp(dot, ".lib")) {
s = realloc_size(s, strlen(s) + 5);
strcat(s, ".lib");
}
pro->fn->libs[pro->fn->n_libs - 1] = s;
return 1;
}
break;
case pro_editor:
if (sscanf(line, "PageLayoutDescrFile=%ms", &s) == 1) {
free((void *) pro->fn->pl);
pro->fn->pl = s;
return 1;
}
break;
default:
abort();
}
return 1;
}
struct file_names *pro_parse_file(struct file *file,
const struct file_names *fn_default)
{
struct pro_ctx pro = {
.state = pro_idle,
.fn = clone_file_names(fn_default),
};
if (!file_read(file, pro_parse_line, &pro)) {
free_file_names(pro.fn);
free(pro.fn);
return NULL;
}
if (!pro.fn->sch) {
char *s, *dot;
assert(pro.fn->pro);
s = stralloc(pro.fn->pro);
dot = strchr(s, '.');
strcpy(dot, ".sch");
pro.fn->sch = s;
}
return pro.fn;
}

24
eeshow/kicad/pro.h Normal file
View File

@ -0,0 +1,24 @@
/*
* kicad/pro.h - KiCad profile
*
* 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.
*/
#ifndef KICAD_PRO_H
#define KICAD_PRO_H
#include "kicad/ext.h"
#include "file/file.h"
struct file_names *pro_parse_file(struct file *file,
const struct file_names *fn_default);
#endif /* !KICAD_PRO_H */