mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-30 00:22:27 +02:00
gencat/: move script execution from pdf.c to run.c
This commit is contained in:
parent
1b6bf60c56
commit
2875940239
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
PREFIX ?= /usr/local
|
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
|
SHELL = /bin/bash
|
||||||
CFLAGS = -Wall -g
|
CFLAGS = -Wall -g
|
||||||
|
51
gencat/pdf.c
51
gencat/pdf.c
@ -9,16 +9,15 @@
|
|||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "gencat.h"
|
#include "gencat.h"
|
||||||
#include "tree.h"
|
#include "tree.h"
|
||||||
#include "libs.h"
|
#include "libs.h"
|
||||||
|
#include "run.h"
|
||||||
#include "pdf.h"
|
#include "pdf.h"
|
||||||
|
|
||||||
|
|
||||||
@ -279,39 +278,9 @@ static void print_comment(FILE *file, const struct line *comment)
|
|||||||
/* ----- Component conversion ---------------------------------------------- */
|
/* ----- 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)
|
static void convert_comp(const struct node *node, FILE *out)
|
||||||
{
|
{
|
||||||
char *tmp;
|
int i;
|
||||||
int i, res;
|
|
||||||
|
|
||||||
for (i = 0; i != node->e->units; i++) {
|
for (i = 0; i != node->e->units; i++) {
|
||||||
if (!quiet) {
|
if (!quiet) {
|
||||||
@ -321,21 +290,9 @@ static void convert_comp(const struct node *node, FILE *out)
|
|||||||
make_title(out, node, i);
|
make_title(out, node, i);
|
||||||
if (!i && node->comment)
|
if (!i && node->comment)
|
||||||
print_comment(out, 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,
|
node->e->file->path, node->e->names->s, i+1,
|
||||||
"tmp", "tmp.ps") < 0) {
|
"tmp", "tmp.ps");
|
||||||
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);
|
|
||||||
}
|
|
||||||
fprintf(out, "gsave %s\n", format.comp_setup);
|
fprintf(out, "gsave %s\n", format.comp_setup);
|
||||||
cat(out, "tmp.ps");
|
cat(out, "tmp.ps");
|
||||||
fprintf(out, "\ngrestore\n");
|
fprintf(out, "\ngrestore\n");
|
||||||
|
70
gencat/run.c
Normal file
70
gencat/run.c
Normal 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
18
gencat/run.h
Normal 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 */
|
Loading…
Reference in New Issue
Block a user