mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-26 07:54:06 +02:00
97 lines
1.6 KiB
C
97 lines
1.6 KiB
C
/*
|
|
* pdf.c - Generate PDF
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
#define _GNU_SOURCE
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
#include "comp.h"
|
|
#include "pdf.h"
|
|
|
|
|
|
static int children(const struct node *node)
|
|
{
|
|
int n = 0;
|
|
|
|
while (node) {
|
|
n++;
|
|
node = node->next;
|
|
}
|
|
return n;
|
|
}
|
|
|
|
|
|
static void convert_comp(const struct node *node, FILE *out)
|
|
{
|
|
char *tmp;
|
|
int res;
|
|
|
|
if (asprintf(&tmp, "./sym2xps '%s' '%s' '%s' '%s'",
|
|
node->lib, node->canon, "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");
|
|
}
|
|
|
|
|
|
static void convert_tree(const struct node *node, FILE *out)
|
|
{
|
|
while (node) {
|
|
fprintf(out, "[ /Title (%s) /Count %d /OUT pdfmark\n",
|
|
node->name, -children(node->child));
|
|
if (node->child)
|
|
convert_tree(node->child, out);
|
|
else
|
|
convert_comp(node, out);
|
|
node = node->next;
|
|
}
|
|
}
|
|
|
|
|
|
void make_pdf(void)
|
|
{
|
|
FILE *out;
|
|
int res;
|
|
|
|
#if 0
|
|
out = popen(
|
|
"gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=- -f -",
|
|
"w");
|
|
#else
|
|
out = popen("cat", "w");
|
|
#endif
|
|
if (!out) {
|
|
perror("gs");
|
|
exit(1);
|
|
}
|
|
convert_tree(tree, out);
|
|
res = pclose(out);
|
|
if (res < 0) {
|
|
perror("pclose");
|
|
exit(1);
|
|
}
|
|
if (res) {
|
|
fprintf(stderr, "exit status %d\n", res);
|
|
exit(1);
|
|
}
|
|
}
|