1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-23 05:48:06 +02:00

sch2fig/: new option -t template.fig to merge template file

This commit is contained in:
Werner Almesberger 2016-07-26 02:30:58 -03:00
parent 427e4d7d09
commit 09d436175a
3 changed files with 40 additions and 6 deletions

View File

@ -406,7 +406,7 @@ void fig_text(int x, int y, const char *s, unsigned size,
/* ----- FIG file header --------------------------------------------------- */
void fig_init(void)
static void fig_header(void)
{
printf("#FIG 3.2\n");
printf("Landscape\n");
@ -418,3 +418,24 @@ void fig_init(void)
printf("-2\n");
printf("1200 2\n");
}
void fig_init(const char *template)
{
FILE *file;
char buf[1000];
if (!template) {
fig_header();
return;
}
file = fopen(template, "r");
if (!file) {
perror(template);
exit(1);
}
while (fgets(buf, sizeof(buf), file))
printf("%s", buf);
fclose(file);
}

View File

@ -53,6 +53,6 @@ void fig_text(int x, int y, const char *s, unsigned size,
/* inititalization */
void fig_init(void);
void fig_init(const char *template);
#endif /* !FIG_H */

View File

@ -13,6 +13,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include "fig.h"
@ -57,20 +58,32 @@ static void read_file(const char *name, void *ctx,
static void usage(const char *name)
{
fprintf(stderr, "usage: %s [file.lib ...] file.sch\n", name);
fprintf(stderr,
"usage: %s [-t template.fig] [file.lib ...] file.sch\n", name);
exit(1);
}
int main(int argc, char **argv)
{
const char *template = NULL;
char c;
int arg;
if (argc < 2)
while ((c = getopt(argc, argv, "t:")) != EOF)
switch (c) {
case 't':
template = optarg;
break;
default:
usage(*argv);
}
if (argc - optind < 1)
usage(*argv);
fig_init();
for (arg = 1; arg != argc; arg++) {
fig_init(template);
for (arg = optind; arg != argc; arg++) {
if (arg == argc - 1) {
struct sch_ctx ctx;