comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:cd92449fdb51
1 #include <sys/types.h>
2 #include <stdio.h>
3 #include "../libuschem/schemstruct.h"
4
5 extern char *malloc();
6
7 extern int optind;
8 extern char *optarg;
9
10 extern char *MCLfile;
11
12 extern struct schem *read_schem();
13
14 extern char default_prefs_pathname[];
15
16 struct schem **schem_pages;
17 int npages;
18 char *prefs_file = default_prefs_pathname;
19 int printsize_x = 1224, printsize_y = 792, printmargin;
20
21 main(argc, argv)
22 char **argv;
23 {
24 register int c;
25 register struct schem *schem;
26
27 while ((c = getopt(argc, argv, "I:m:M:p:P:")) != EOF)
28 switch (c) {
29 case 'I':
30 add_symfile_dir(optarg);
31 break;
32 case 'm':
33 printmargin = atoi(optarg);
34 break;
35 case 'M':
36 MCLfile = optarg;
37 break;
38 case 'p':
39 prefs_file = optarg;
40 break;
41 case 'P':
42 set_paper_size(optarg);
43 break;
44 default:
45 usage: fprintf(stderr, "usage: %s [-options] schemfile...\n",
46 argv[0]);
47 exit(1);
48 }
49 if (!argv[optind])
50 goto usage;
51 npages = argc - optind;
52
53 read_MCL();
54 hash_MCL();
55 set_default_sympath();
56 read_pinouts();
57
58 schem_pages = (struct schem **) malloc(sizeof(struct schem *) * npages);
59 if (!schem_pages) {
60 perror("malloc");
61 exit(1);
62 }
63 for (c = 0; c < npages; c++) {
64 schem = read_schem(argv[optind+c]);
65 if (!schem->is_graph) {
66 fprintf(stderr,
67 "%s: non-graphical schematic cannot be printed\n",
68 schem->orig_filename);
69 exit(1);
70 }
71 schem_pages[c] = schem;
72 match_schem_to_mcl(schem);
73 load_graphsyms(schem);
74 instantiate_graphsym_pins(schem, 0); /* for SymOnPin */
75 }
76
77 emit_header();
78 emit_prolog();
79 emit_setup();
80 for (c = 0; c < npages; c++)
81 print_schem_page(c);
82 puts("%%Trailer");
83 puts("%%EOF");
84
85 exit(0);
86 }
87
88 emit_header()
89 {
90 puts("%!PS-Adobe-3.0");
91 puts("%%Creator: uschem-print");
92 puts("%%LanguageLevel: 2");
93 puts("%%Orientation: Landscape");
94 printf("%%%%Pages: %d\n", npages);
95 puts("%%EndComments");
96 }
97
98 emit_setup()
99 {
100 puts("%%BeginSetup");
101 printf("/printsize_x %d def\n", printsize_x);
102 printf("/printsize_y %d def\n", printsize_y);
103 puts("<< /PageSize [printsize_x printsize_y] >> setpagedevice");
104 printf("/printmargin %d def\n", printmargin);
105 puts("$uschem begin");
106 emit_file(prefs_file);
107 puts("end");
108 puts("%%EndSetup");
109 }
110
111 emit_file(pathname)
112 char *pathname;
113 {
114 register FILE *f;
115 char buf[512];
116 register int cc;
117
118 f = fopen(pathname, "r");
119 if (!f) {
120 perror(pathname);
121 exit(1);
122 }
123 while ((cc = fread(buf, 1, sizeof buf, f)) > 0)
124 fwrite(buf, 1, cc, stdout);
125 fclose(f);
126 }