FreeCalypso > hg > ueda-linux
diff ueda/uschem-print/main.c @ 0:cd92449fdb51
initial import of ueda and ifctf-part-lib from ifctfvax CVS
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 20 Jul 2015 00:24:37 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ueda/uschem-print/main.c Mon Jul 20 00:24:37 2015 +0000 @@ -0,0 +1,126 @@ +#include <sys/types.h> +#include <stdio.h> +#include "../libuschem/schemstruct.h" + +extern char *malloc(); + +extern int optind; +extern char *optarg; + +extern char *MCLfile; + +extern struct schem *read_schem(); + +extern char default_prefs_pathname[]; + +struct schem **schem_pages; +int npages; +char *prefs_file = default_prefs_pathname; +int printsize_x = 1224, printsize_y = 792, printmargin; + +main(argc, argv) + char **argv; +{ + register int c; + register struct schem *schem; + + while ((c = getopt(argc, argv, "I:m:M:p:P:")) != EOF) + switch (c) { + case 'I': + add_symfile_dir(optarg); + break; + case 'm': + printmargin = atoi(optarg); + break; + case 'M': + MCLfile = optarg; + break; + case 'p': + prefs_file = optarg; + break; + case 'P': + set_paper_size(optarg); + break; + default: +usage: fprintf(stderr, "usage: %s [-options] schemfile...\n", + argv[0]); + exit(1); + } + if (!argv[optind]) + goto usage; + npages = argc - optind; + + read_MCL(); + hash_MCL(); + set_default_sympath(); + read_pinouts(); + + schem_pages = (struct schem **) malloc(sizeof(struct schem *) * npages); + if (!schem_pages) { + perror("malloc"); + exit(1); + } + for (c = 0; c < npages; c++) { + schem = read_schem(argv[optind+c]); + if (!schem->is_graph) { + fprintf(stderr, + "%s: non-graphical schematic cannot be printed\n", + schem->orig_filename); + exit(1); + } + schem_pages[c] = schem; + match_schem_to_mcl(schem); + load_graphsyms(schem); + instantiate_graphsym_pins(schem, 0); /* for SymOnPin */ + } + + emit_header(); + emit_prolog(); + emit_setup(); + for (c = 0; c < npages; c++) + print_schem_page(c); + puts("%%Trailer"); + puts("%%EOF"); + + exit(0); +} + +emit_header() +{ + puts("%!PS-Adobe-3.0"); + puts("%%Creator: uschem-print"); + puts("%%LanguageLevel: 2"); + puts("%%Orientation: Landscape"); + printf("%%%%Pages: %d\n", npages); + puts("%%EndComments"); +} + +emit_setup() +{ + puts("%%BeginSetup"); + printf("/printsize_x %d def\n", printsize_x); + printf("/printsize_y %d def\n", printsize_y); + puts("<< /PageSize [printsize_x printsize_y] >> setpagedevice"); + printf("/printmargin %d def\n", printmargin); + puts("$uschem begin"); + emit_file(prefs_file); + puts("end"); + puts("%%EndSetup"); +} + +emit_file(pathname) + char *pathname; +{ + register FILE *f; + char buf[512]; + register int cc; + + f = fopen(pathname, "r"); + if (!f) { + perror(pathname); + exit(1); + } + while ((cc = fread(buf, 1, sizeof buf, f)) > 0) + fwrite(buf, 1, cc, stdout); + fclose(f); +}