Root/genkicat/fped.c

1/*
2 * comp.c - Component libraries
3 *
4 * Copyright 2012 by Werner Almesberger
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#define _GNU_SOURCE /* for asprintf */
13#include <stdlib.h>
14#include <stdio.h>
15#include <string.h>
16
17#include "run.h"
18#include "libs.h"
19
20
21static void fped_add_lib(struct lib *lib, const char *path)
22{
23    FILE *file;
24    char buf[1024]; /* @@@ */
25    char *tmp, *nl;
26
27    asprintf(&tmp, "fped -k '%s' -", path);
28    file = popen(tmp, "r");
29    if (!file) {
30        perror(path);
31        exit(1);
32    }
33
34    while (fgets(buf, sizeof(buf), file)) {
35        if (strncmp(buf, "$MODULE ", 8))
36            continue;
37        nl = strchr(buf, '\n');
38        if (nl)
39            *nl = 0;
40        add_name(new_entry(lib, 1), buf+8);
41    }
42
43    pclose(file);
44}
45
46
47static void fped_ps_entry(FILE *file, const struct lib *lib,
48    const struct entry *e, int unit, int landscape)
49{
50    fprintf(file, "0 -40 translate\n");
51    run_cmd("fped -P -K -s x200 '%s' -1 '%s' '%s'",
52        e->file->path, e->names->s, "tmp.ps");
53    run_cmd("sed -i -e '/OUT pdfmark/d' tmp.ps");
54    cat(file, "tmp.ps");
55}
56
57
58struct lib fped_lib = {
59    .ext = ".fpd",
60    .add_lib = fped_add_lib,
61    .ps_entry = fped_ps_entry,
62};
63

Archive Download this file

Branches:
master



interactive