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