mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-12-23 05:15:09 +02:00
genex/: added support for multi-part components
This commit is contained in:
parent
5083973b9a
commit
0f0e732d3f
@ -91,11 +91,13 @@ next:
|
||||
|
||||
|
||||
void set_libs(struct node *node,
|
||||
const char *(*find_lib)(const char *sym, const char **canon))
|
||||
const char *(*find_lib)(const char *sym, const char **canon,
|
||||
int *units))
|
||||
{
|
||||
while (node) {
|
||||
if (!node->child) {
|
||||
node->lib = find_lib(node->name, &node->canon);
|
||||
node->lib =
|
||||
find_lib(node->name, &node->canon, &node->units);
|
||||
if (!node->lib) {
|
||||
fprintf(stderr, "symbol %s not found\n",
|
||||
node->name);
|
||||
|
@ -16,6 +16,7 @@ struct node {
|
||||
const char *name;
|
||||
const char *lib; /* NULL if not intermediate node */
|
||||
const char *canon; /* canonical name of component */
|
||||
int units; /* number of units */
|
||||
int indent; /* level of indentation (characters) */
|
||||
struct node *parent;
|
||||
struct node *child;
|
||||
@ -28,7 +29,8 @@ extern struct node *tree;
|
||||
|
||||
void read_tree(FILE *file);
|
||||
void set_libs(struct node *node,
|
||||
const char *(*find_lib)(const char *sym, const char **canon));
|
||||
const char *(*find_lib)(const char *sym, const char **canon,
|
||||
int *units));
|
||||
void dump_tree(void);
|
||||
|
||||
#endif /* !COMP_H */
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include "comp.h"
|
||||
#include "libs.h"
|
||||
#include "pdf.h"
|
||||
|
||||
|
||||
static void usage(const char *name)
|
||||
|
34
genex/libs.c
34
genex/libs.c
@ -9,9 +9,10 @@
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#define _GNU_SOURCE /* for strcasecmp */
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
@ -22,6 +23,7 @@
|
||||
|
||||
struct entry {
|
||||
const char *name;
|
||||
int units;
|
||||
struct entry *next;
|
||||
};
|
||||
|
||||
@ -32,7 +34,7 @@ static struct lib {
|
||||
} *libs = NULL;
|
||||
|
||||
|
||||
const char *lookup_sym(const char *name, const char **canon)
|
||||
const char *lookup_sym(const char *name, const char **canon, int *units)
|
||||
{
|
||||
const struct lib *lib;
|
||||
const struct entry *e;
|
||||
@ -42,12 +44,26 @@ const char *lookup_sym(const char *name, const char **canon)
|
||||
if (!strcasecmp(e->name, name)) {
|
||||
if (canon)
|
||||
*canon = e->name;
|
||||
if (units)
|
||||
*units = e->units;
|
||||
return lib->path;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static const char *field(const char *s, int n)
|
||||
{
|
||||
while (n-- && *s) {
|
||||
while (*s && !isspace(*s))
|
||||
s++;
|
||||
while (*s && isspace(*s))
|
||||
s++;
|
||||
}
|
||||
return *s ? s : NULL;
|
||||
}
|
||||
|
||||
|
||||
void add_lib(const char *path)
|
||||
{
|
||||
FILE *file;
|
||||
@ -55,8 +71,8 @@ void add_lib(const char *path)
|
||||
struct entry *e;
|
||||
char buf[1024]; /* @@@ */
|
||||
char *spc;
|
||||
const char *s;
|
||||
|
||||
|
||||
file = fopen(path, "r");
|
||||
if (!file) {
|
||||
perror(path);
|
||||
@ -72,6 +88,12 @@ void add_lib(const char *path)
|
||||
while (fgets(buf, sizeof(buf), file)) {
|
||||
if (strncmp(buf, "DEF ", 4))
|
||||
continue;
|
||||
s = field(buf, 7);
|
||||
if (!s) {
|
||||
fprintf(stderr, "DEF record lacks units field in %s\n",
|
||||
path);
|
||||
exit(1);
|
||||
}
|
||||
spc = strchr(buf+4, ' ');
|
||||
if (!spc) {
|
||||
fprintf(stderr, "invalid DEF line in %s\n", path);
|
||||
@ -80,6 +102,12 @@ void add_lib(const char *path)
|
||||
*spc = 0;
|
||||
e = alloc_type(struct entry);
|
||||
e->name = stralloc(buf+4);
|
||||
e->units = atoi(s);
|
||||
if (!e->units) {
|
||||
fprintf(stderr, "invalid number of units in %s\n",
|
||||
path);
|
||||
exit(1);
|
||||
}
|
||||
e->next = lib->comps;
|
||||
lib->comps = e;
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
#ifndef LIBS_H
|
||||
#define LIBS_H
|
||||
|
||||
const char *lookup_sym(const char *name, const char **canon);
|
||||
const char *lookup_sym(const char *name, const char **canon, int *units);
|
||||
void add_lib(const char *path);
|
||||
void add_libdir(const char *path);
|
||||
|
||||
|
34
genex/pdf.c
34
genex/pdf.c
@ -32,24 +32,26 @@ static int children(const struct node *node)
|
||||
static void convert_comp(const struct node *node, FILE *out)
|
||||
{
|
||||
char *tmp;
|
||||
int res;
|
||||
int i, res;
|
||||
|
||||
if (asprintf(&tmp, "./sym2xps '%s' '%s' '%s' '%s'",
|
||||
node->lib, node->canon, "tmp", "tmp.ps") < 0) {
|
||||
perror("asprintf");
|
||||
exit(1);
|
||||
for (i = 0; i != node->units; i++) {
|
||||
if (asprintf(&tmp, "./sym2xps '%s' '%s' %d '%s' '%s'",
|
||||
node->lib, node->canon, i+1, "tmp", "tmp.ps") < 0) {
|
||||
perror("asprintf");
|
||||
exit(1);
|
||||
}
|
||||
res = system(tmp);
|
||||
if (res < 0) {
|
||||
perror("system");
|
||||
exit(1);
|
||||
}
|
||||
if (res) {
|
||||
fprintf(stderr, "sym2xps returned %d\n", res);
|
||||
exit(1);
|
||||
}
|
||||
fflush(out);
|
||||
system("cat tmp.ps");
|
||||
}
|
||||
res = system(tmp);
|
||||
if (res < 0) {
|
||||
perror("system");
|
||||
exit(1);
|
||||
}
|
||||
if (res) {
|
||||
fprintf(stderr, "sym2xps returned %d\n", res);
|
||||
exit(1);
|
||||
}
|
||||
fflush(out);
|
||||
system("cat tmp.ps");
|
||||
}
|
||||
|
||||
|
||||
|
@ -14,15 +14,16 @@
|
||||
|
||||
usage()
|
||||
{
|
||||
echo "usage: $0 library symbol tmpdir outfile" 1>&2
|
||||
echo "usage: $0 library symbol unit tmpdir outfile" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
lib=$1
|
||||
sym=$2
|
||||
tmp=$3
|
||||
out=$4
|
||||
unit=$3
|
||||
tmp=$4
|
||||
out=$5
|
||||
|
||||
[ "$lib" ] && [ "$sym" ] && [ "$tmp" ] && [ "$out" ] || usage
|
||||
|
||||
@ -62,9 +63,9 @@ EELAYER 43 0
|
||||
EELAYER END
|
||||
\$Comp
|
||||
L X$sym ??
|
||||
U 1 1 00000000
|
||||
U $unit 1 00000000
|
||||
P $X $Y
|
||||
1 $X $Y
|
||||
$unit $X $Y
|
||||
1 0 0 -1
|
||||
\$EndComp
|
||||
\$EndSCHEMATC
|
||||
|
Loading…
Reference in New Issue
Block a user