mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-05 18:16:16 +02:00
84 lines
1.5 KiB
C
84 lines
1.5 KiB
C
/*
|
|
* comp.c - Component libraries
|
|
*
|
|
* Copyright 2012 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 <ctype.h>
|
|
#include <string.h>
|
|
|
|
#include "util.h"
|
|
#include "libs.h"
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
|
|
static void add_comp_lib(struct lib *lib, const char *path)
|
|
{
|
|
FILE *file;
|
|
struct entry *e = NULL;
|
|
char buf[1024]; /* @@@ */
|
|
char *name, *spc;
|
|
const char *s;
|
|
|
|
file = fopen(path, "r");
|
|
if (!file) {
|
|
perror(path);
|
|
exit(1);
|
|
}
|
|
|
|
while (fgets(buf, sizeof(buf), file)) {
|
|
if (!strncmp(buf, "ALIAS ", 6) && e)
|
|
add_name(e, buf+6);
|
|
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);
|
|
}
|
|
name = buf+4;
|
|
if (*name == '~')
|
|
name++;
|
|
spc = strchr(name, ' ');
|
|
if (!spc) {
|
|
fprintf(stderr, "invalid DEF line in %s\n", path);
|
|
exit(1);
|
|
}
|
|
*spc = 0;
|
|
e = new_entry(lib, atoi(s));
|
|
if (!e->units) {
|
|
fprintf(stderr, "invalid number of units in %s\n",
|
|
path);
|
|
exit(1);
|
|
}
|
|
add_name(e, name);
|
|
}
|
|
|
|
fclose(file);
|
|
}
|
|
|
|
|
|
struct lib comp_lib = {
|
|
.ext = ".lib",
|
|
.add_lib = add_comp_lib,
|
|
};
|