1 #include <errno.h>
2 #include "hpscat.h"
3 #include "paper.h"
4
5 extern int totalpages;
6 static int converted;
7 char *tmpfn;
8
9 void
convert(s)10 convert(s)
11 char *s;
12 {
13 int i;
14 char *args[5]; /* for execvp */
15 extern void execute PROT((char **));
16 #ifdef HPS
17 if(hcode==KSC) {
18 #else
19 if(hcode==Johap) {
20 #endif
21 converted = 0;
22 return;
23 }
24 tmpfn = tempnam("/tmp", "hpscat");
25 for(i=0; i<4; i++)
26 args[i] = (char *)malloc(256);
27 strcpy(args[0], Converter);
28 strcpy(args[2], s);
29 strcpy(args[3], tmpfn);
30 args[4] = (char *) 0;
31 switch(hcode) {
32 #ifdef HPS
33 case Johap: strcpy(args[1], fromJH); break;
34 #else
35 case KSC: strcpy(args[1], fromKS); break;
36 #endif
37 case Nbyte: strcpy(args[1], fromN); break;
38 case ISO: strcpy(args[1], fromI); break;
39 default: /* NOTREACHED */ return;
40 }
41 execute(args);
42 fclose(fp);
43 fp = fopen(tmpfn,"r");
44 converted = 1;
45 }
46
47 void
execute(args)48 execute(args)
49 char **args;
50 {
51 int pid, status;
52 if((pid=fork()) < 0) {
53 perror("fork");
54 exit(1);
55 }
56 if(pid==0) {
57 execvp(args[0], args);
58 perror("execvp");
59 exit(1);
60 }
61 while(wait(&status)!=pid);
62 }
63
64 void
endfile()65 endfile()
66 {
67 fprintf(ofp,"%%%%Trailer\n%%%%Pages: %d\n",pageno);
68 fclose(fp);
69 if(ofp!=stdout) fclose(ofp);
70 if(converted) unlink(tmpfn);
71 fprintf(stderr,"%2d page%c\n", pageno, (pageno<2)? ' ':'s');
72 totalpages += pageno;
73 }
74
75 #define U1 "\033[4m" /* underline on */
76 #define U2 "\033[7m" /* inverse on */
77 #define U0 "\033[0m" /* underline off */
78
79 char *ver = "1.3.1";
80
81 void
usage(prg)82 usage(prg)
83 char *prg;
84 {
85 fprintf(stderr,"\t\t\t %shpscat v%s%s\n", U2, ver, U0);
86 fprintf(stderr,"\t\t\t\t\tby jbkang@csone.kaist.ac.kr\n");
87 fprintf(stderr,"\t\t\t\t\trevision by jshin@minerva.cis.yale.edu\n");
88 fprintf(stderr," Usage : %s [options] files ...\n\n", prg);
89 fprintf(stderr," %slayout options (default is -l)%s\n", U1, U0);
90 fprintf(stderr,"\t-l, -l3 : landscape 2 columns, 3 columns\n");
91 fprintf(stderr,"\t-p, -p2 : portrait 1 column, 2 columns\n");
92 fprintf(stderr," %scode options (default is -ks)%s\n", U1, U0);
93 fprintf(stderr,"\t-ks, -N, -16, -i : ksc5601, N-byte, johap, iso2022-1 code\n");
94 fprintf(stderr," %sfont options%s\n", U1, U0);
95 fprintf(stderr,"\t-bf : use boldface english font\n");
96 #ifdef ADV_HFONT
97 fprintf(stderr,"\t-hf<hangul font> : sets Hangul font(default is %s)\n",
98 hfontname[DEF_HFONT]);
99 #else
100 fprintf(stderr,"\t-hf<hangul font> : sets Hangul font(default is %s)\n",
101 DEF_HFONT);
102 #endif
103 fprintf(stderr,"\t <hangul font> can be\n");
104 fprintf(stderr,"\t name of any Hangul font available to you\n");
105 #ifdef ADV_HFONT
106 fprintf(stderr,"\t including but not limited to\n\t ");
107 { _hfont temp;
108 for ( temp=Munjo; temp < userfont-1; temp++)
109 fprintf(stderr,"%s%s", hfontname[temp],(temp % 5 == 4 ) ?
110 "\n\t " : "," );
111 fprintf(stderr, "%s.\n",hfontname[temp]);
112 }
113 #endif
114 fprintf(stderr,"\t-tf<title font> : sets font for title(default is %s)\n",
115 DEF_TFONT);
116 fprintf(stderr,"\t-fs#: set font size for text [%d~%d] (default is -fs%d)\n",
117 Smallest, Largest, Defaultsize);
118 fprintf(stderr," %soptions for papertype and margins%s\n", U1, U0);
119 fprintf(stderr,"\t-p<paper type> : set paper type(default:%s)\n",
120 papersize[DEFPAP].name);
121 fprintf(stderr,"\t valid paper types are \n");
122 fprintf(stderr,"\t ");
123 { PAPER temp;
124 for ( temp=a3; temp < user-1; temp++)
125 fprintf(stderr,"%s%s", papersize[temp].name,(temp%5==4) ?
126 ",\n\t " : "," );
127 fprintf(stderr, "%s.\n",papersize[temp].name);
128 }
129 fprintf(stderr,"\t-pw<paper width> : set the width of paper\n");
130 fprintf(stderr,"\t-ph<paper height> : set the height of paper\n");
131 fprintf(stderr,"\t-mbm<length> : set min. bottom margin\n");
132 fprintf(stderr,"\t-mlm<length> : set min. left margin\n");
133 fprintf(stderr,"\t only necessary for a printer with unusually wide\n");
134 fprintf(stderr,"\t non-printable area\n");
135 fprintf(stderr,"\t-sw<length> : set shaded area width\n");
136 fprintf(stderr,"\t-sn<length> : set shaded area width when -nl is used.\n");
137 fprintf(stderr,"\t where <width> and <height> are <number><unit>.\n");
138 fprintf(stderr,"\t <unit> can be omitted or one of following\n\t ");
139 { UNIT temp;
140 for ( temp=milimeter; temp < null; temp++)
141 fprintf(stderr,"%s%s", unit[temp].sym,temp==null-1 ? ".\n":",");
142 fprintf(stderr,"\t When omitted, standard PS unit(1/72 inch) is assumed.\n");
143 }
144 fprintf(stderr," %smisc options%s\n", U1, U0);
145 fprintf(stderr,"\t-f : output to `filename.ps' (default is stdout)\n");
146 fprintf(stderr,"\t-T<title> : document title to be put \n");
147 fprintf(stderr,"\t-nb : no outline box\n");
148 fprintf(stderr,"\t-nl : no line number\n");
149 fprintf(stderr,"\t-nh : no header\n");
150 fprintf(stderr,"\t-nf : no footer\n");
151 fprintf(stderr,"\t-nn : don't use 1:2 font width proportion (not narrowed)\n");
152
153 fprintf(stderr,"\t-cheat : no actual output. just count pages\n\n");
154 fprintf(stderr," options can be set in ~/.hpscatrc in the form \"name = value\"\n");
155 fprintf(stderr,"\t\tnames can be : layout, code, bold, narrow, size,paper\n");
156 fprintf(stderr,"\t\t paperwidth,paperheight,hangulfont,titlefont,\n");
157 fprintf(stderr,"\t\t min_bot_margin,min_left_mar,\n");
158 fprintf(stderr,"\t\t shade_width,shade_width_nl\n");
159 fprintf(stderr,"\t\tvalues can be : l, l3, p, p2 (for layout)\n");
160 fprintf(stderr,"\t\t ks, N, 16, i (for code)\n");
161 fprintf(stderr,"\t\t true, false (for bold and narrow)\n");
162 fprintf(stderr,"\t\t number in point (for size)\n");
163 fprintf(stderr,"\t\t <length><unit> (for paperwidth/height/margin)\n");
164
165 exit(0);
166 }
167
168 void
fatal(s)169 fatal(s)
170 char *s;
171 {
172 fprintf(stderr,"? %s\n", s);
173 exit(1);
174 }
175
176 /*** EOF ***/
177