2012-03-31 00:53:51 +03:00
|
|
|
/*
|
2012-06-26 03:14:48 +03:00
|
|
|
* comp.c - Component libraries
|
2012-03-31 00:53:51 +03:00
|
|
|
*
|
|
|
|
* 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>
|
2012-04-12 05:10:42 +03:00
|
|
|
#include <ctype.h>
|
2012-03-31 00:53:51 +03:00
|
|
|
#include <string.h>
|
|
|
|
|
2012-07-12 05:16:03 +03:00
|
|
|
#include "run.h"
|
2012-07-12 04:27:22 +03:00
|
|
|
#include "libs.h"
|
2012-03-31 00:53:51 +03:00
|
|
|
|
|
|
|
|
2012-04-12 05:10:42 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-12 05:16:03 +03:00
|
|
|
static void comp_add_lib(struct lib *lib, const char *path)
|
2012-03-31 00:53:51 +03:00
|
|
|
{
|
|
|
|
FILE *file;
|
2012-04-17 14:45:20 +03:00
|
|
|
struct entry *e = NULL;
|
2012-03-31 00:53:51 +03:00
|
|
|
char buf[1024]; /* @@@ */
|
2012-04-17 15:53:02 +03:00
|
|
|
char *name, *spc;
|
2012-04-12 05:10:42 +03:00
|
|
|
const char *s;
|
2012-03-31 00:53:51 +03:00
|
|
|
|
|
|
|
file = fopen(path, "r");
|
|
|
|
if (!file) {
|
|
|
|
perror(path);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (fgets(buf, sizeof(buf), file)) {
|
2012-04-17 14:45:20 +03:00
|
|
|
if (!strncmp(buf, "ALIAS ", 6) && e)
|
|
|
|
add_name(e, buf+6);
|
2012-03-31 00:53:51 +03:00
|
|
|
if (strncmp(buf, "DEF ", 4))
|
|
|
|
continue;
|
2012-04-12 05:10:42 +03:00
|
|
|
s = field(buf, 7);
|
|
|
|
if (!s) {
|
|
|
|
fprintf(stderr, "DEF record lacks units field in %s\n",
|
|
|
|
path);
|
|
|
|
exit(1);
|
|
|
|
}
|
2012-04-17 15:53:02 +03:00
|
|
|
name = buf+4;
|
|
|
|
if (*name == '~')
|
|
|
|
name++;
|
|
|
|
spc = strchr(name, ' ');
|
2012-03-31 00:53:51 +03:00
|
|
|
if (!spc) {
|
|
|
|
fprintf(stderr, "invalid DEF line in %s\n", path);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
*spc = 0;
|
2012-07-12 04:27:22 +03:00
|
|
|
e = new_entry(lib, atoi(s));
|
2012-04-12 05:10:42 +03:00
|
|
|
if (!e->units) {
|
|
|
|
fprintf(stderr, "invalid number of units in %s\n",
|
|
|
|
path);
|
|
|
|
exit(1);
|
|
|
|
}
|
2012-07-12 04:27:22 +03:00
|
|
|
add_name(e, name);
|
2012-03-31 00:53:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-12 06:25:43 +03:00
|
|
|
static void comp_ps_entry(FILE *file, const struct lib *lib,
|
2012-07-12 08:41:42 +03:00
|
|
|
const struct entry *e, int unit, int landscape)
|
2012-07-12 05:16:03 +03:00
|
|
|
{
|
2012-07-12 08:41:42 +03:00
|
|
|
if (!landscape)
|
|
|
|
fprintf(file, "-120 700 translate -90 rotate\n");
|
2012-07-12 05:16:03 +03:00
|
|
|
run_cmd("sym2xps '%s' '%s' %d '%s' '%s'",
|
|
|
|
e->file->path, e->names->s, unit+1, "tmp", "tmp.ps");
|
|
|
|
cat(file, "tmp.ps");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-12 04:27:22 +03:00
|
|
|
struct lib comp_lib = {
|
|
|
|
.ext = ".lib",
|
2012-07-12 05:16:03 +03:00
|
|
|
.add_lib = comp_add_lib,
|
|
|
|
.ps_entry = comp_ps_entry,
|
2012-07-12 04:27:22 +03:00
|
|
|
};
|