1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-26 11:46:14 +02:00

gencat/: move script execution from pdf.c to run.c

This commit is contained in:
Werner Almesberger 2012-07-11 23:07:59 -03:00
parent 1b6bf60c56
commit 2875940239
4 changed files with 93 additions and 48 deletions

View File

@ -11,7 +11,7 @@
PREFIX ?= /usr/local
OBJS = gencat.o tree.o libs.o comp.o pdf.o
OBJS = gencat.o tree.o libs.o run.o comp.o pdf.o
SHELL = /bin/bash
CFLAGS = -Wall -g

View File

@ -9,16 +9,15 @@
* (at your option) any later version.
*/
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include "util.h"
#include "gencat.h"
#include "tree.h"
#include "libs.h"
#include "run.h"
#include "pdf.h"
@ -279,39 +278,9 @@ static void print_comment(FILE *file, const struct line *comment)
/* ----- Component conversion ---------------------------------------------- */
static void cat(FILE *out, const char *name)
{
FILE *in;
char buf[10000]; /* pick any good size */
size_t got, wrote;
in = fopen(name, "r");
if (!in) {
perror(name);
exit(1);
}
while (1) {
got = fread(buf, 1, sizeof(buf), in);
if (!got)
break;
wrote = fwrite(buf, 1, got, out);
if (wrote != got) {
perror("fwrite");
exit(1);
}
}
if (ferror(in)) {
perror(name);
exit(1);
}
fclose(in);
}
static void convert_comp(const struct node *node, FILE *out)
{
char *tmp;
int i, res;
int i;
for (i = 0; i != node->e->units; i++) {
if (!quiet) {
@ -321,21 +290,9 @@ static void convert_comp(const struct node *node, FILE *out)
make_title(out, node, i);
if (!i && node->comment)
print_comment(out, node->comment);
if (asprintf(&tmp, "sym2xps '%s' '%s' %d '%s' '%s'",
run_cmd("sym2xps '%s' '%s' %d '%s' '%s'",
node->e->file->path, node->e->names->s, 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);
}
"tmp", "tmp.ps");
fprintf(out, "gsave %s\n", format.comp_setup);
cat(out, "tmp.ps");
fprintf(out, "\ngrestore\n");

70
gencat/run.c Normal file
View File

@ -0,0 +1,70 @@
/*
* run.c - Run helper scripts
*
* 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 /* for vasprintf */
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include "run.h"
void run_cmd(const char *fmt, ...)
{
va_list ap;
char *tmp;
int res;
va_start(ap, fmt);
if (vasprintf(&tmp, fmt, ap) < 0) {
perror("vasprintf");
exit(1);
}
res = system(tmp);
if (res < 0) {
perror("system");
exit(1);
}
if (res) {
fprintf(stderr, "sym2xps returned %d\n", res);
exit(1);
}
}
void cat(FILE *out, const char *name)
{
FILE *in;
char buf[10000]; /* pick any good size */
size_t got, wrote;
in = fopen(name, "r");
if (!in) {
perror(name);
exit(1);
}
while (1) {
got = fread(buf, 1, sizeof(buf), in);
if (!got)
break;
wrote = fwrite(buf, 1, got, out);
if (wrote != got) {
perror("fwrite");
exit(1);
}
}
if (ferror(in)) {
perror(name);
exit(1);
}
fclose(in);
}

18
gencat/run.h Normal file
View File

@ -0,0 +1,18 @@
/*
* run.h - Run helper scripts
*
* 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.
*/
#ifndef RUN_H
#define RUN_H
void run_cmd(const char *fmt, ...);
void cat(FILE *out, const char *name);
#endif /* !RUN_H */