1 /***************************************************************************
2 * Copyright (C) 1991,1992 by Wei Sun (william@cs.anu.edu.au)
3 * All Rights Reserved
4 * Version 2.02
5 *
6 *File:gbinit.c
7 *
8 * DISTRIBUTION:
9 * This program is NOT in public domain.
10 * It can be freely distributed for non-commercial purposes only,
11 * and THERE IS NO WARRANTY FOR THIS PROGRAM.
12 ****************************************************************************/
13
14 #include "gb2ps.h"
15 char pathname[50];
16
init(arg,arglist)17 int init(arg,arglist)
18 int arg;
19 char **arglist;
20 {
21 char** i;
22 int k=0;
23
24 *cfont_name=0;
25 out = stdout;
26
27 for (i=arglist+1; i<arglist+arg; i++)
28 switch (**i) {
29 case '-':
30 switch (*((*i)+1)) {
31 case 'y':
32 strcpy (styear,*(++i));
33 break;
34 case 'm':
35 strcpy(stmonth,*(++i));
36 break;
37 case 'i':
38 strcpy(stissue,*(++i));
39 break;
40 case 't':
41 coverpage_flag=FALSE;
42 break;
43 case 'f':
44 format_flag=TRUE;
45 break;
46 case 'p':
47 pageno_flag=FALSE;
48 break;
49 case 'b':
50 sscanf(*(++i),"%d",&page_begin_print);
51 if (page_begin_print<1) page_begin_print=1;
52 break;
53 case 'e':
54 sscanf(*(++i),"%d",&page_end_print);
55 if (page_end_print<1) page_end_print= -1;
56 else page_end_print+=1;
57 break;
58 case 'h':
59
60 default:
61 printf("gb2ps\t[-h][-y year][-m month][-i issue][-p][-t][-f][-b page_no]\n\t[-e page_no] input_file [output_file]\n\n");
62 exit(0);
63 }
64 break;
65 default:
66 switch(k) {
67 case 0:
68 if ((strncasecmp(*i,"cm",2)==0)&&(strlen(*i)==10)) {
69 sprintf(styear,"19%c%c",(*i)[2],(*i)[3]);
70 sprintf(stmonth,"%d",((*i)[4]-'0')*10+((*i)[5]-'0'));
71 sprintf(stissue,"%d",1+
72 (islower((*i)[6])?((*i)[6]-'a'):((*i)[6]-'A')));
73 }
74 strcpy(filename,*i);
75 if ((in=fopen(*i,"r"))==NULL) {
76 printf("Can't open input file -> %s\n",*i);
77 exit (1);
78 }
79 k++;
80 break;
81 case 1:
82 if ((out=fopen(*i,"w"))==NULL) {
83 printf("Can't open output file -> %s\n",*i);
84 exit (1);
85 }
86 k++;
87 break;
88 }
89 }
90
91 if (k<2) {
92 printf("gb2ps\t[-h][-y year][-m month][-i issue][-p][-t][-f][-b page_no]\n\
93 \t[-e page_no] input_file [output_file]\n\n");
94 if (k<1)
95 printf("Input file name not supplied.\n");
96 else
97 printf("Output file name not supplied.\n");
98 exit (1);
99 }
100
101 if (*pathname==0) {
102 if (getenv("CFONT")!=NULL)
103 strcpy(pathname,getenv("CFONT"));
104 else
105 strcpy (pathname,CFONT);
106 }
107
108 strcpy(cfont_name,pathname); strcat(cfont_name,SONGTI);
109 if ((cfont = fopen (cfont_name, "r"))!=NULL) {
110 CHFONT[0].fp=cfont;
111 strcpy(CHFONT[0].name,"SONG 24");
112 CHFONT[0].height=10;
113 CHFONT[0].width=10;
114 }
115 else
116 {
117 fprintf(stderr,"Cannot open the chinese font file -> %s\n",
118 cfont_name);
119 exit (1);
120 }
121
122 strcpy(cfont_name,pathname); strcat(cfont_name,KEITI);
123 if ((cfont = fopen (cfont_name, "r"))!=NULL) {
124 CHFONT[1].fp=cfont;
125 strcpy(CHFONT[1].name,"KEI 24");
126 CHFONT[1].height=10;
127 CHFONT[1].width=10;
128 }
129 else
130 {
131 fprintf(stderr,"Warnning: cannot open the chinese font file -> %s, use %s instead.\n",cfont_name,SONGTI);
132 CHFONT[1]=CHFONT[0];
133 }
134
135 strcpy(cfont_name,pathname); strcat(cfont_name,FANGSONGTI);
136 if ((cfont = fopen (cfont_name, "r"))!=NULL) {
137 CHFONT[2].fp=cfont;
138 strcpy(CHFONT[2].name,"FANG SONG 24");
139 CHFONT[2].height=10;
140 CHFONT[2].width=10;
141 }
142 else
143 {
144 fprintf(stderr,"Warnning: cannot open the chinese font file -> %s, use %s instead.\n",cfont_name,SONGTI);
145 CHFONT[2]=CHFONT[0];
146 }
147
148 strcpy(cfont_name,pathname); strcat(cfont_name,HEITI);
149 if ((cfont = fopen (cfont_name, "r"))!=NULL) {
150 CHFONT[3].fp=cfont;
151 strcpy(CHFONT[3].name,"HEI 24");
152 CHFONT[3].height=10;
153 CHFONT[3].width=10;
154 }
155 else
156 {
157 fprintf(stderr,"Warnning: cannot open the chinese font file -> %s, use %s instead.\n",cfont_name,SONGTI);
158 CHFONT[3]=CHFONT[0];
159 }
160
161 strcpy(cfont_name,pathname); strcat(cfont_name,FANTI);
162 if ((cfont = fopen (cfont_name, "r"))!=NULL) {
163 CHFONT[4].fp=cfont;
164 strcpy(CHFONT[4].name,"FAN 24");
165 CHFONT[4].height=10;
166 CHFONT[4].width=10;
167 }
168 else
169 {
170 fprintf(stderr,"Warnning: cannot open the chinese font file -> %s, use %s instead.\n",cfont_name,SONGTI);
171 CHFONT[4]=CHFONT[0];
172 }
173
174 strcpy(cfont_name,pathname); strcat(cfont_name,USERDEF);
175 if ((cfont = fopen (cfont_name, "r"))!=NULL) {
176 CHFONT[5].fp=cfont;
177 strcpy(CHFONT[5].name,"USER 24");
178 CHFONT[5].height=10;
179 CHFONT[5].width=10;
180 }
181 else
182 {
183 CHFONT[5]=CHFONT[0];
184 }
185
186 return k;
187 }
188
189 void
cleanup(i)190 cleanup(i)
191 int i;
192 {
193 switch(i) {
194 case 2: fclose(out);
195 case 1: fclose(in);
196 }
197 cfont=CHFONT[0].fp;
198 fclose (CHFONT[0].fp);
199 if (cfont!=CHFONT[1].fp) fclose(CHFONT[1].fp);
200 if (cfont!=CHFONT[2].fp) fclose(CHFONT[2].fp);
201 if (cfont!=CHFONT[3].fp) fclose(CHFONT[3].fp);
202 if (cfont!=CHFONT[4].fp) fclose(CHFONT[4].fp);
203 if (cfont!=CHFONT[5].fp) fclose(CHFONT[5].fp);
204 }
205