add
This commit is contained in:
parent
8477327a46
commit
c15ce40c44
4 changed files with 1981 additions and 0 deletions
1252
src/cmd/file.c
Normal file
1252
src/cmd/file.c
Normal file
File diff suppressed because it is too large
Load diff
23
src/cmd/postscript/text2post/mkfile
Normal file
23
src/cmd/postscript/text2post/mkfile
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
<$PLAN9/src/mkhdr
|
||||||
|
|
||||||
|
<../config
|
||||||
|
|
||||||
|
COMMONDIR=../common
|
||||||
|
|
||||||
|
TARG=text2post
|
||||||
|
|
||||||
|
OFILES=text2post.$O\
|
||||||
|
|
||||||
|
HFILES=$COMMONDIR/comments.h\
|
||||||
|
$COMMONDIR/path.h\
|
||||||
|
|
||||||
|
BIN=$POSTBIN
|
||||||
|
<$PLAN9/src/mkone
|
||||||
|
|
||||||
|
CFLAGS=-c -D'PROGRAMVERSION="0.1"' -D'DOROUND=1' -I$COMMONDIR
|
||||||
|
|
||||||
|
install:V: $POSTLIB/pjw.char.ps
|
||||||
|
|
||||||
|
$POSTLIB/pjw.char.ps: pjw.char.ps
|
||||||
|
cp $prereq $target
|
||||||
|
|
||||||
142
src/cmd/postscript/text2post/pjw.char.ps
Normal file
142
src/cmd/postscript/text2post/pjw.char.ps
Normal file
|
|
@ -0,0 +1,142 @@
|
||||||
|
%!PS-Adobe-3.0 EPSF-3.0
|
||||||
|
%%BoundingBox: 1 -1 199 258
|
||||||
|
%%Creator: MetaPost
|
||||||
|
%%CreationDate: 1994.06.28:1046
|
||||||
|
/pjw1 {
|
||||||
|
37 211 moveto
|
||||||
|
37 206 lineto
|
||||||
|
41 206 lineto
|
||||||
|
43 212 lineto
|
||||||
|
44 212 46 212 46 210 curveto
|
||||||
|
41 198 35 186 35 174 curveto
|
||||||
|
50 174 66 175 81 173 curveto
|
||||||
|
81 171 lineto
|
||||||
|
61 171 lineto
|
||||||
|
61 170 lineto
|
||||||
|
86 170 lineto
|
||||||
|
88 168 89 166 90 164 curveto
|
||||||
|
101 164 111 169 122 172 curveto
|
||||||
|
139 172 lineto
|
||||||
|
125 194 115 219 93 233 curveto
|
||||||
|
87 234 80 236 74 235 curveto
|
||||||
|
64 229 54 224 46 217 curveto
|
||||||
|
45 217 44 217 44 218 curveto
|
||||||
|
61 242 lineto
|
||||||
|
67 248 72 258 82 258 curveto
|
||||||
|
94 257 107 256 119 254 curveto
|
||||||
|
134 247 147 239 161 231 curveto
|
||||||
|
180 231 lineto
|
||||||
|
180 226 174 228 171 226 curveto
|
||||||
|
178 220 185 214 192 207 curveto
|
||||||
|
189 207 187 207 187 205 curveto
|
||||||
|
190 205 193 204 196 203 curveto
|
||||||
|
198 193 202 181 193 181 curveto
|
||||||
|
193 177 198 175 198 171 curveto
|
||||||
|
196 171 194 171 194 169 curveto
|
||||||
|
195 165 196 161 198 157 curveto
|
||||||
|
194 147 193 135 184 130 curveto
|
||||||
|
180 130 lineto
|
||||||
|
169 107 lineto
|
||||||
|
171 103 176 104 180 104 curveto
|
||||||
|
180 93 176 81 166 76 curveto
|
||||||
|
162 76 157 77 155 80 curveto
|
||||||
|
153 80 152 80 151 80 curveto
|
||||||
|
151 71 lineto
|
||||||
|
155 71 lineto
|
||||||
|
155 68 153 65 152 63 curveto
|
||||||
|
145 62 lineto
|
||||||
|
141 47 144 31 144 15 curveto
|
||||||
|
141 0 lineto
|
||||||
|
124 0 107 -1 90 1 curveto
|
||||||
|
72 36 lineto
|
||||||
|
86 48 105 49 122 54 curveto
|
||||||
|
122 54 lineto
|
||||||
|
110 61 97 65 84 69 curveto
|
||||||
|
81 71 78 73 78 76 curveto
|
||||||
|
86 77 93 77 101 77 curveto
|
||||||
|
106 79 113 79 113 84 curveto
|
||||||
|
95 86 77 87 59 89 curveto
|
||||||
|
59 92 61 95 64 95 curveto
|
||||||
|
69 88 80 92 89 92 curveto
|
||||||
|
95 92 104 90 104 96 curveto
|
||||||
|
93 97 lineto
|
||||||
|
87 103 82 109 77 115 curveto
|
||||||
|
89 116 101 117 113 118 curveto
|
||||||
|
99 154 lineto
|
||||||
|
90 154 87 144 82 138 curveto
|
||||||
|
77 132 73 124 66 120 curveto
|
||||||
|
63 120 59 119 59 122 curveto
|
||||||
|
62 123 66 123 66 126 curveto
|
||||||
|
58 126 50 127 42 128 curveto
|
||||||
|
34 137 lineto
|
||||||
|
34 140 34 144 31 144 curveto
|
||||||
|
30 135 31 125 31 116 curveto
|
||||||
|
25 116 22 122 19 127 curveto
|
||||||
|
16 131 15 136 12 139 curveto
|
||||||
|
5 139 15 127 9 127 curveto
|
||||||
|
3 133 3 142 1 150 curveto
|
||||||
|
1 158 6 166 9 173 curveto
|
||||||
|
18 186 25 199 35 211 curveto
|
||||||
|
closepath
|
||||||
|
} bind def
|
||||||
|
|
||||||
|
/pjw2 {
|
||||||
|
27 112 moveto
|
||||||
|
40 75 lineto
|
||||||
|
40 74 38 73 37 73 curveto
|
||||||
|
25 87 lineto
|
||||||
|
17 112 lineto
|
||||||
|
closepath
|
||||||
|
43 154 moveto
|
||||||
|
43 167 lineto
|
||||||
|
41 167 38 167 39 169 curveto
|
||||||
|
57 171 lineto
|
||||||
|
74 167 lineto
|
||||||
|
74 166 73 165 72 165 curveto
|
||||||
|
64 164 56 162 49 158 curveto
|
||||||
|
48 154 45 149 49 149 curveto
|
||||||
|
51 151 53 152 55 154 curveto
|
||||||
|
87 153 lineto
|
||||||
|
87 144 80 136 74 129 curveto
|
||||||
|
64 128 53 126 43 129 curveto
|
||||||
|
37 135 lineto
|
||||||
|
37 138 36 141 36 145 curveto
|
||||||
|
40 145 lineto
|
||||||
|
41 148 42 151 43 154 curveto closepath
|
||||||
|
108 145 moveto
|
||||||
|
119 145 130 143 141 140 curveto
|
||||||
|
146 134 155 129 149 126 curveto
|
||||||
|
138 124 126 123 116 129 curveto
|
||||||
|
113 134 108 139 108 145 curveto
|
||||||
|
closepath
|
||||||
|
114 96 moveto
|
||||||
|
116 103 118 110 121 117 curveto
|
||||||
|
128 117 134 112 139 107 curveto
|
||||||
|
139 101 137 96 132 93 curveto
|
||||||
|
closepath
|
||||||
|
134 162 moveto
|
||||||
|
115 162 lineto
|
||||||
|
115 162 115 163 115 164 curveto
|
||||||
|
134 164 lineto
|
||||||
|
closepath
|
||||||
|
117 73 moveto
|
||||||
|
115 78 121 81 125 85 curveto
|
||||||
|
129 85 lineto
|
||||||
|
130 83 131 81 131 79 curveto
|
||||||
|
128 74 lineto
|
||||||
|
124 74 121 73 117 73 curveto closepath
|
||||||
|
141 119 moveto
|
||||||
|
134 119 126 117 126 123 curveto
|
||||||
|
131 123 136 122 141 121 curveto
|
||||||
|
closepath
|
||||||
|
} bind def
|
||||||
|
|
||||||
|
/pw {
|
||||||
|
%% pop
|
||||||
|
gsave
|
||||||
|
pointsize .0022 mul dup scale
|
||||||
|
currentpoint translate
|
||||||
|
pjw1 pjw2 eofill
|
||||||
|
grestore
|
||||||
|
6 0 rmoveto
|
||||||
|
} bind def
|
||||||
564
src/cmd/postscript/text2post/text2post.c
Normal file
564
src/cmd/postscript/text2post/text2post.c
Normal file
|
|
@ -0,0 +1,564 @@
|
||||||
|
#include <u.h>
|
||||||
|
#include <libc.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <bio.h>
|
||||||
|
#include <comments.h>
|
||||||
|
#include <path.h>
|
||||||
|
|
||||||
|
#define UNKNOWNCHAR unsharp("#9/postscript/prologues/pjw.char.ps")
|
||||||
|
|
||||||
|
char *optnames = "a:c:f:l:m:n:o:p:s:t:x:y:P:";
|
||||||
|
|
||||||
|
Biobuf *bstdin, *bstdout, *bstderr;
|
||||||
|
Biobuf *Bstdin, *Bstdout, *Bstderr;
|
||||||
|
int char_no = 0; /* character to be done on a line */
|
||||||
|
int line_no = 0; /* line number on a page */
|
||||||
|
int page_no = 0; /* page number in a document */
|
||||||
|
int in_string; /* Boolean, to know whether or not we are inside a Postscript string */
|
||||||
|
int spaces = 0;
|
||||||
|
int tabs = 0;
|
||||||
|
int pages_printed;
|
||||||
|
double aspectratio = 1.0;
|
||||||
|
int copies = 1;
|
||||||
|
double magnification = 1.0;
|
||||||
|
int landscape = 0;
|
||||||
|
int formsperpage = 1;
|
||||||
|
int linesperpage = 66;
|
||||||
|
int pointsize = 10;
|
||||||
|
double xoffset = .25;
|
||||||
|
double yoffset = .25;
|
||||||
|
char *passthrough = 0;
|
||||||
|
static int pplistmaxsize=0;
|
||||||
|
|
||||||
|
unsigned char *pplist=0; /* bitmap list for storing pages to print */
|
||||||
|
|
||||||
|
struct strtab {
|
||||||
|
int size;
|
||||||
|
char *str;
|
||||||
|
int used;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct strtab charcode[256] = {
|
||||||
|
{4, "\\000"}, {4, "\\001"}, {4, "\\002"}, {4, "\\003"},
|
||||||
|
{4, "\\004"}, {4, "\\005"}, {4, "\\006"}, {4, "\\007"},
|
||||||
|
{4, "\\010"}, {4, "\\011"}, {4, "\\012"}, {4, "\\013"},
|
||||||
|
{4, "\\014"}, {4, "\\015"}, {4, "\\016"}, {4, "\\017"},
|
||||||
|
{4, "\\020"}, {4, "\\021"}, {4, "\\022"}, {4, "\\023"},
|
||||||
|
{4, "\\024"}, {4, "\\025"}, {4, "\\026"}, {4, "\\027"},
|
||||||
|
{4, "\\030"}, {4, "\\031"}, {4, "\\032"}, {4, "\\033"},
|
||||||
|
{4, "\\034"}, {4, "\\035"}, {4, "\\036"}, {4, "\\037"},
|
||||||
|
{1, " "}, {1, "!"}, {1, "\""}, {1, "#"},
|
||||||
|
{1, "$"}, {1, "%"}, {1, "&"}, {1, "'"},
|
||||||
|
{2, "\\("}, {2, "\\)"}, {1, "*"}, {1, "+"},
|
||||||
|
{1, ","}, {1, "-"}, {1, "."}, {1, "/"},
|
||||||
|
{1, "0"}, {1, "1"}, {1, "2"}, {1, "3"},
|
||||||
|
{1, "4"}, {1, "5"}, {1, "6"}, {1, "7"},
|
||||||
|
{1, "8"}, {1, "9"}, {1, ":"}, {1, ";"},
|
||||||
|
{1, "<"}, {1, "="}, {1, ">"}, {1, "?"},
|
||||||
|
{1, "@"}, {1, "A"}, {1, "B"}, {1, "C"},
|
||||||
|
{1, "D"}, {1, "E"}, {1, "F"}, {1, "G"},
|
||||||
|
{1, "H"}, {1, "I"}, {1, "J"}, {1, "K"},
|
||||||
|
{1, "L"}, {1, "M"}, {1, "N"}, {1, "O"},
|
||||||
|
{1, "P"}, {1, "Q"}, {1, "R"}, {1, "S"},
|
||||||
|
{1, "T"}, {1, "U"}, {1, "V"}, {1, "W"},
|
||||||
|
{1, "X"}, {1, "Y"}, {1, "Z"}, {1, "["},
|
||||||
|
{2, "\\\\"}, {1, "]"}, {1, "^"}, {1, "_"},
|
||||||
|
{1, "`"}, {1, "a"}, {1, "b"}, {1, "c"},
|
||||||
|
{1, "d"}, {1, "e"}, {1, "f"}, {1, "g"},
|
||||||
|
{1, "h"}, {1, "i"}, {1, "j"}, {1, "k"},
|
||||||
|
{1, "l"}, {1, "m"}, {1, "n"}, {1, "o"},
|
||||||
|
{1, "p"}, {1, "q"}, {1, "r"}, {1, "s"},
|
||||||
|
{1, "t"}, {1, "u"}, {1, "v"}, {1, "w"},
|
||||||
|
{1, "x"}, {1, "y"}, {1, "z"}, {1, "{"},
|
||||||
|
{1, "|"}, {1, "}"}, {1, "~"}, {4, "\\177"},
|
||||||
|
{4, "\\200"}, {4, "\\201"}, {4, "\\202"}, {4, "\\203"},
|
||||||
|
{4, "\\204"}, {4, "\\205"}, {4, "\\206"}, {4, "\\207"},
|
||||||
|
{4, "\\210"}, {4, "\\211"}, {4, "\\212"}, {4, "\\213"},
|
||||||
|
{4, "\\214"}, {4, "\\215"}, {4, "\\216"}, {4, "\\217"},
|
||||||
|
{4, "\\220"}, {4, "\\221"}, {4, "\\222"}, {4, "\\223"},
|
||||||
|
{4, "\\224"}, {4, "\\225"}, {4, "\\226"}, {4, "\\227"},
|
||||||
|
{4, "\\230"}, {4, "\\231"}, {4, "\\232"}, {4, "\\233"},
|
||||||
|
{4, "\\234"}, {4, "\\235"}, {4, "\\236"}, {4, "\\237"},
|
||||||
|
{4, "\\240"}, {4, "\\241"}, {4, "\\242"}, {4, "\\243"},
|
||||||
|
{4, "\\244"}, {4, "\\245"}, {4, "\\246"}, {4, "\\247"},
|
||||||
|
{4, "\\250"}, {4, "\\251"}, {4, "\\252"}, {4, "\\253"},
|
||||||
|
{4, "\\254"}, {4, "\\255"}, {4, "\\256"}, {4, "\\257"},
|
||||||
|
{4, "\\260"}, {4, "\\261"}, {4, "\\262"}, {4, "\\263"},
|
||||||
|
{4, "\\264"}, {4, "\\265"}, {4, "\\266"}, {4, "\\267"},
|
||||||
|
{4, "\\270"}, {4, "\\271"}, {4, "\\272"}, {4, "\\273"},
|
||||||
|
{4, "\\274"}, {4, "\\275"}, {4, "\\276"}, {4, "\\277"},
|
||||||
|
{4, "\\300"}, {4, "\\301"}, {4, "\\302"}, {4, "\\303"},
|
||||||
|
{4, "\\304"}, {4, "\\305"}, {4, "\\306"}, {4, "\\307"},
|
||||||
|
{4, "\\310"}, {4, "\\311"}, {4, "\\312"}, {4, "\\313"},
|
||||||
|
{4, "\\314"}, {4, "\\315"}, {4, "\\316"}, {4, "\\317"},
|
||||||
|
{4, "\\320"}, {4, "\\321"}, {4, "\\322"}, {4, "\\323"},
|
||||||
|
{4, "\\324"}, {4, "\\325"}, {4, "\\326"}, {4, "\\327"},
|
||||||
|
{4, "\\330"}, {4, "\\331"}, {4, "\\332"}, {4, "\\333"},
|
||||||
|
{4, "\\334"}, {4, "\\335"}, {4, "\\336"}, {4, "\\337"},
|
||||||
|
{4, "\\340"}, {4, "\\341"}, {4, "\\342"}, {4, "\\343"},
|
||||||
|
{4, "\\344"}, {4, "\\345"}, {4, "\\346"}, {4, "\\347"},
|
||||||
|
{4, "\\350"}, {4, "\\351"}, {4, "\\352"}, {4, "\\353"},
|
||||||
|
{4, "\\354"}, {4, "\\355"}, {4, "\\356"}, {4, "\\357"},
|
||||||
|
{4, "\\360"}, {4, "\\361"}, {4, "\\362"}, {4, "\\363"},
|
||||||
|
{4, "\\364"}, {4, "\\365"}, {4, "\\366"}, {4, "\\367"},
|
||||||
|
{4, "\\370"}, {4, "\\371"}, {4, "\\372"}, {4, "\\373"},
|
||||||
|
{4, "\\374"}, {4, "\\375"}, {4, "\\376"}, {4, "\\377"}
|
||||||
|
};
|
||||||
|
|
||||||
|
#define FONTABSIZE 0x27
|
||||||
|
|
||||||
|
struct strtab fontname[FONTABSIZE] = {
|
||||||
|
{19, "LucidaSansUnicode00", 0},
|
||||||
|
{19, "LucidaSansUnicode01", 0},
|
||||||
|
{19, "LucidaSansUnicode02", 0},
|
||||||
|
{19, "LucidaSansUnicode03", 0},
|
||||||
|
{19, "LucidaSansUnicode04", 0},
|
||||||
|
{19, "LucidaSansUnicode05", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{19, "LucidaSansUnicode20", 0},
|
||||||
|
{19, "LucidaSansUnicode21", 0},
|
||||||
|
{19, "LucidaSansUnicode22", 0},
|
||||||
|
{0, "", 0},
|
||||||
|
{19, "LucidaSansUnicode24", 0},
|
||||||
|
{19, "LucidaSansUnicode25", 0},
|
||||||
|
{7, "Courier", 0}
|
||||||
|
};
|
||||||
|
|
||||||
|
/* This was taken from postprint */
|
||||||
|
|
||||||
|
int
|
||||||
|
cat(char *filename) {
|
||||||
|
Biobuf *bfile, *Bfile;
|
||||||
|
int n;
|
||||||
|
static char buf[Bsize];
|
||||||
|
|
||||||
|
bstdin = Bopen(filename, 0);
|
||||||
|
if (bstdin == 0) {
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
Bstdin = bstdin;
|
||||||
|
if ((bfile = Bopen(filename, OREAD)) == 0) {
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
Bfile = bfile;
|
||||||
|
while ((n=Bread(Bfile, buf, Bsize)) > 0) {
|
||||||
|
if (Bwrite(Bstdout, buf, n) != n) {
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (n != 0) {
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
prologues(void) {
|
||||||
|
char *ts;
|
||||||
|
int tabstop;
|
||||||
|
|
||||||
|
Bprint(Bstdout, "%s", CONFORMING);
|
||||||
|
Bprint(Bstdout, "%s %s\n", VERSION, PROGRAMVERSION);
|
||||||
|
Bprint(Bstdout, "%s %s\n", DOCUMENTFONTS, ATEND);
|
||||||
|
Bprint(Bstdout, "%s %s\n", PAGES, ATEND);
|
||||||
|
Bprint(Bstdout, "%s", ENDCOMMENTS);
|
||||||
|
|
||||||
|
if (cat(POSTPRINT)) {
|
||||||
|
Bprint(Bstderr, "can't read %s", POSTPRINT);
|
||||||
|
exits("prologue");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DOROUND)
|
||||||
|
cat(ROUNDPAGE);
|
||||||
|
|
||||||
|
tabstop = 0;
|
||||||
|
ts = getenv("tabstop");
|
||||||
|
if(ts != nil)
|
||||||
|
tabstop = strtol(ts, nil, 0);
|
||||||
|
if(tabstop == 0)
|
||||||
|
tabstop = 8;
|
||||||
|
Bprint(Bstdout, "/f {findfont pointsize scalefont setfont} bind def\n");
|
||||||
|
Bprint(Bstdout, "/tabwidth /Courier f (");
|
||||||
|
while(tabstop--)
|
||||||
|
Bputc(Bstdout, 'n');
|
||||||
|
Bprint(Bstdout, ") stringwidth pop def\n");
|
||||||
|
Bprint(Bstdout, "/tab {tabwidth 0 ne {currentpoint 3 1 roll exch tabwidth mul add tabwidth\n");
|
||||||
|
Bprint(Bstdout, "\tdiv truncate tabwidth mul exch moveto} if} bind def\n");
|
||||||
|
Bprint(Bstdout, "/spacewidth /%s f ( ) stringwidth pop def\n", fontname[0].str);
|
||||||
|
Bprint(Bstdout, "/sp {spacewidth mul 0 rmoveto} bind def\n");
|
||||||
|
Bprint(Bstdout, "%s", ENDPROLOG);
|
||||||
|
Bprint(Bstdout, "%s", BEGINSETUP);
|
||||||
|
Bprint(Bstdout, "mark\n");
|
||||||
|
|
||||||
|
if (formsperpage > 1) {
|
||||||
|
Bprint(Bstdout, "%s %d\n", FORMSPERPAGE, formsperpage);
|
||||||
|
Bprint(Bstdout, "/formsperpage %d def\n", formsperpage);
|
||||||
|
}
|
||||||
|
if (aspectratio != 1) Bprint(Bstdout, "/aspectratio %g def\n", aspectratio);
|
||||||
|
if (copies != 1) Bprint(Bstdout, "/#copies %d store\n", copies);
|
||||||
|
if (landscape) Bprint(Bstdout, "/landscape true def\n");
|
||||||
|
if (magnification != 1) Bprint(Bstdout, "/magnification %s def\n", magnification);
|
||||||
|
if (pointsize != 10) Bprint(Bstdout, "/pointsize %d def\n", pointsize);
|
||||||
|
if (xoffset != .25) Bprint(Bstdout, "/xoffset %g def\n", xoffset);
|
||||||
|
if (yoffset != .25) Bprint(Bstdout, "/yoffset %g def\n", yoffset);
|
||||||
|
cat(unsharp("#9/postscript/prologues/Latin1.enc"));
|
||||||
|
if (passthrough != 0) Bprint(Bstdout, "%s\n", passthrough);
|
||||||
|
Bprint(Bstdout, "setup\n");
|
||||||
|
if (formsperpage > 1) {
|
||||||
|
cat(FORMFILE);
|
||||||
|
Bprint(Bstdout, "%d setupforms \n", formsperpage);
|
||||||
|
}
|
||||||
|
if (cat(UNKNOWNCHAR))
|
||||||
|
Bprint(Bstderr, "cannot open %s\n", UNKNOWNCHAR);
|
||||||
|
Bprint(Bstdout, "%s", ENDSETUP);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
pageon(void) {
|
||||||
|
if (pplist == 0 && page_no != 0) return(1); /* no page list, print all pages */
|
||||||
|
if (page_no/8 < pplistmaxsize && (pplist[page_no/8] & 1<<(page_no%8)))
|
||||||
|
return(1);
|
||||||
|
else
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
startpage(void) {
|
||||||
|
++char_no;
|
||||||
|
++line_no;
|
||||||
|
++page_no;
|
||||||
|
if (pageon()) {
|
||||||
|
++pages_printed;
|
||||||
|
Bprint(Bstdout, "%s %d %d\n", PAGE, page_no, pages_printed);
|
||||||
|
Bprint(Bstdout, "/saveobj save def\n");
|
||||||
|
Bprint(Bstdout, "mark\n");
|
||||||
|
Bprint(Bstdout, "%d pagesetup\n", pages_printed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
endpage(void) {
|
||||||
|
line_no = 0;
|
||||||
|
char_no = 0;
|
||||||
|
if (pageon()) {
|
||||||
|
Bprint(Bstdout, "cleartomark\n");
|
||||||
|
Bprint(Bstdout, "showpage\n");
|
||||||
|
Bprint(Bstdout, "saveobj restore\n");
|
||||||
|
Bprint(Bstdout, "%s %d %d\n", ENDPAGE, page_no, pages_printed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
startstring(void) {
|
||||||
|
if (!in_string) {
|
||||||
|
if (pageon()) Bprint(Bstdout, "(");
|
||||||
|
in_string = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
endstring(void) {
|
||||||
|
if (in_string) {
|
||||||
|
if (pageon()) Bprint(Bstdout, ") show ");
|
||||||
|
in_string = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
prspace(void) {
|
||||||
|
if (spaces) {
|
||||||
|
endstring();
|
||||||
|
if (pageon()) Bprint(Bstdout, "%d sp ", spaces);
|
||||||
|
spaces = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
prtab(void) {
|
||||||
|
if (tabs) {
|
||||||
|
endstring();
|
||||||
|
if (pageon()) Bprint(Bstdout, "%d tab ", tabs);
|
||||||
|
tabs = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
txt2post(void) {
|
||||||
|
int lastfont = -1;
|
||||||
|
int lastchar = -1;
|
||||||
|
int thisfont, thischar;
|
||||||
|
long r;
|
||||||
|
|
||||||
|
in_string = 0;
|
||||||
|
char_no = 0;
|
||||||
|
line_no = 0;
|
||||||
|
page_no = 0;
|
||||||
|
spaces = 0;
|
||||||
|
fontname[0].used++;
|
||||||
|
while ((r=Bgetrune(Bstdin)) >= 0) {
|
||||||
|
thischar = r & 0xff;
|
||||||
|
thisfont = (r>>8) & 0xff;
|
||||||
|
|
||||||
|
if (line_no == 0 && char_no == 0)
|
||||||
|
startpage();
|
||||||
|
|
||||||
|
if (line_no == 1 && char_no == 1) {
|
||||||
|
if (pageon()) Bprint(Bstdout, " /%s f\n", fontname[thisfont].str);
|
||||||
|
lastfont = thisfont;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (r) {
|
||||||
|
case ' ':
|
||||||
|
prtab();
|
||||||
|
if (lastfont > 0) {
|
||||||
|
spaces++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '\n':
|
||||||
|
case '\f':
|
||||||
|
startstring();
|
||||||
|
if (pageon()) Bprint(Bstdout, ")l\n");
|
||||||
|
char_no = 1;
|
||||||
|
in_string = 0;
|
||||||
|
spaces = 0;
|
||||||
|
tabs = 0;
|
||||||
|
if (++line_no > linesperpage || r == '\f') {
|
||||||
|
endpage();
|
||||||
|
}
|
||||||
|
lastchar = -1;
|
||||||
|
continue;
|
||||||
|
case '\t':
|
||||||
|
prspace();
|
||||||
|
tabs++;
|
||||||
|
char_no++;
|
||||||
|
lastchar = -1;
|
||||||
|
continue;
|
||||||
|
case '\b':
|
||||||
|
/* just toss out backspaces for now */
|
||||||
|
if (lastchar != -1) {
|
||||||
|
endstring();
|
||||||
|
if (pageon()) Bprint(Bstdout, "(%s) stringwidth pop neg 0 rmoveto ", charcode[lastchar].str);
|
||||||
|
}
|
||||||
|
char_no++;
|
||||||
|
lastchar = -1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* do something if font is out of table range */
|
||||||
|
if (thisfont>=FONTABSIZE || fontname[thisfont].size == 0) {
|
||||||
|
prspace();
|
||||||
|
prtab();
|
||||||
|
endstring();
|
||||||
|
Bprint(Bstdout, "pw ");
|
||||||
|
char_no++;
|
||||||
|
lastchar = -1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (thisfont != lastfont) {
|
||||||
|
endstring();
|
||||||
|
if (pageon()) {
|
||||||
|
Bprint(Bstdout, "/%s f\n", fontname[thisfont].str);
|
||||||
|
}
|
||||||
|
fontname[thisfont].used++;
|
||||||
|
}
|
||||||
|
prspace();
|
||||||
|
prtab();
|
||||||
|
startstring();
|
||||||
|
if (pageon()) Bprint(Bstdout, "%s", charcode[thischar].str);
|
||||||
|
/* if (pageon()) Bprint(Bstdout, "%2.2x", thischar); /* try hex strings*/
|
||||||
|
char_no++;
|
||||||
|
lastchar = thischar;
|
||||||
|
lastfont = thisfont;
|
||||||
|
}
|
||||||
|
if (line_no != 0 || char_no != 0) {
|
||||||
|
if (char_no != 1) {
|
||||||
|
Bprint(Bstderr, "premature EOF: newline appended\n");
|
||||||
|
startstring();
|
||||||
|
if (pageon()) Bprint(Bstdout, ")l\n");
|
||||||
|
}
|
||||||
|
endpage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
pagelist(char *list) {
|
||||||
|
char c;
|
||||||
|
int n, m;
|
||||||
|
int state, start, end;
|
||||||
|
|
||||||
|
if (list == 0) return;
|
||||||
|
state = 1;
|
||||||
|
while ((c=*list) != '\0') {
|
||||||
|
n = 0;
|
||||||
|
while (isdigit(c)) {
|
||||||
|
n = n * 10 + c - '0';
|
||||||
|
c = *++list;
|
||||||
|
}
|
||||||
|
switch (state) {
|
||||||
|
case 1:
|
||||||
|
start = n;
|
||||||
|
case 2:
|
||||||
|
if (n/8+1 > pplistmaxsize) {
|
||||||
|
pplistmaxsize = n/8+1;
|
||||||
|
if ((pplist = realloc(pplist, n/8+1)) == 0) {
|
||||||
|
Bprint(Bstderr, "cannot allocate memory for page list\n");
|
||||||
|
exits("malloc");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (m=start; m<=n; m++)
|
||||||
|
pplist[m/8] |= 1<<(m%8);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch (c) {
|
||||||
|
case '-':
|
||||||
|
state = 2;
|
||||||
|
list++;
|
||||||
|
break;
|
||||||
|
case ',':
|
||||||
|
state = 1;
|
||||||
|
list++;
|
||||||
|
break;
|
||||||
|
case '\0':
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
finish(void) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
Bprint(Bstdout, "%s", TRAILER);
|
||||||
|
Bprint(Bstdout, "done\n");
|
||||||
|
Bprint(Bstdout, "%s", DOCUMENTFONTS);
|
||||||
|
|
||||||
|
for (i=0; i<FONTABSIZE; i++)
|
||||||
|
if (fontname[i].used)
|
||||||
|
Bprint(Bstdout, " %s", fontname[i].str);
|
||||||
|
Bprint(Bstdout, "\n");
|
||||||
|
|
||||||
|
Bprint(Bstdout, "%s %d\n", PAGES, pages_printed);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
main(int argc, char *argv[]) {
|
||||||
|
int i;
|
||||||
|
char *t;
|
||||||
|
Biobuf *input;
|
||||||
|
|
||||||
|
if ((bstderr = (Biobuf *)malloc(sizeof(Biobuf))) < (Biobuf *)0)
|
||||||
|
exits("malloc");
|
||||||
|
if (Binit(bstderr, 2, OWRITE) == Beof)
|
||||||
|
exits("Binit");
|
||||||
|
Bstderr = bstderr;
|
||||||
|
|
||||||
|
if ((bstdout = (Biobuf *)malloc(sizeof(Biobuf))) < (Biobuf *)0)
|
||||||
|
exits("malloc");
|
||||||
|
if (Binit(bstdout, 1, OWRITE) == Beof)
|
||||||
|
exits("Binit");
|
||||||
|
Bstdout = bstdout;
|
||||||
|
|
||||||
|
ARGBEGIN{
|
||||||
|
case 'a': /* aspect ratio */
|
||||||
|
aspectratio = atof(ARGF());
|
||||||
|
break;
|
||||||
|
case 'c': /* copies */
|
||||||
|
copies = atoi(ARGF());
|
||||||
|
break;
|
||||||
|
case 'f': /* primary font, for now */
|
||||||
|
t = ARGF();
|
||||||
|
fontname[0].str = malloc(strlen(t)+1);
|
||||||
|
strcpy(fontname[0].str, t);
|
||||||
|
break;
|
||||||
|
case 'l': /* lines per page */
|
||||||
|
linesperpage = atoi(ARGF());
|
||||||
|
break;
|
||||||
|
case 'm': /* magnification */
|
||||||
|
magnification = atof(ARGF());
|
||||||
|
break;
|
||||||
|
case 'n': /* forms per page */
|
||||||
|
formsperpage = atoi(ARGF());
|
||||||
|
break;
|
||||||
|
case 'o': /* output page list */
|
||||||
|
pagelist(ARGF());
|
||||||
|
break;
|
||||||
|
case 'p': /* landscape or portrait mode */
|
||||||
|
if ( ARGF()[0] == 'l' )
|
||||||
|
landscape = 1;
|
||||||
|
else
|
||||||
|
landscape = 0;
|
||||||
|
break;
|
||||||
|
case 's': /* point size */
|
||||||
|
pointsize = atoi(ARGF());
|
||||||
|
break;
|
||||||
|
case 'x': /* shift things horizontally */
|
||||||
|
xoffset = atof(ARGF());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'y': /* and vertically on the page */
|
||||||
|
yoffset = atof(ARGF());
|
||||||
|
break;
|
||||||
|
case 'P': /* PostScript pass through */
|
||||||
|
t = ARGF();
|
||||||
|
i = strlen(t) + 1;
|
||||||
|
passthrough = malloc(i);
|
||||||
|
if (passthrough == 0) {
|
||||||
|
Bprint(Bstderr, "cannot allocate memory for argument string\n");
|
||||||
|
exits("malloc");
|
||||||
|
}
|
||||||
|
strncpy(passthrough, t, i);
|
||||||
|
break;
|
||||||
|
default: /* don't know what to do for ch */
|
||||||
|
Bprint(Bstderr, "unknown option %C\n", ARGC());
|
||||||
|
break;
|
||||||
|
}ARGEND;
|
||||||
|
prologues();
|
||||||
|
if (argc <= 0) {
|
||||||
|
if ((bstdin = (Biobuf *)malloc(sizeof(Biobuf))) < (Biobuf *)0)
|
||||||
|
exits("malloc");
|
||||||
|
if (Binit(bstdin, 0, OREAD) == Beof) {
|
||||||
|
fprint(2, "cannot Binit stdin\n");
|
||||||
|
exits("Binit");
|
||||||
|
}
|
||||||
|
Bstdin = bstdin;
|
||||||
|
txt2post();
|
||||||
|
}
|
||||||
|
for (i=0; i<argc; i++) {
|
||||||
|
bstdin = Bopen(argv[i], 0);
|
||||||
|
if (bstdin == 0) {
|
||||||
|
fprint(2, "cannot open file %s\n", argv[i]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Bstdin = bstdin;
|
||||||
|
txt2post();
|
||||||
|
}
|
||||||
|
finish();
|
||||||
|
exits("");
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue