-
Notifications
You must be signed in to change notification settings - Fork 0
/
t2p.c
205 lines (192 loc) · 4.52 KB
/
t2p.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
* a part of convert text to ps
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#define MAXLINE 66
#define MAXBUF 4096
#define ANK 1
#define UTF8 2
#define ANK_POINT "12"
#define KANJI_POINT "12"
#define ANK_XGAP "0"
#define ANK_YGAP "0"
#define KANJI_XGAP "2.4"
#define KANJI_YGAP "0"
int ShowUsage();
int main(argc, argv)
int argc;
char *argv[];
{
unsigned char buf[MAXBUF + 1], str[MAXBUF + 1];
int char_sw = 0 /* ANK */ ;
int line = 0, col, col_tmp, i, j, maxline = 0;
char ankpoint[5], kanjipoint[5];
char ank_xgap[5], ank_ygap[5];
char kanji_xgap[5], kanji_ygap[5];
if (argc == 2) {
if (strcmp(argv[1], "-h") == 0
|| strcmp(argv[1], "--help") == 0) {
ShowUsage();
exit(0);
}
}
if (argc == 3) {
if (strcmp(argv[1], "-l") == 0) {
if (argv[2] != NULL) {
maxline = atoi(argv[2]);
}
}
}
if (maxline == 0) {
maxline = MAXLINE;
}
if (getenv("PROV2_ANK_POINT") == (char *) NULL) {
strncpy(ankpoint, ANK_POINT, (sizeof ankpoint) - 1);
} else {
strncpy(ankpoint, getenv("PROV2_ANK_POINT"),
(sizeof ankpoint) - 1);
}
ankpoint[(sizeof ankpoint) - 1] = '\0';
if (getenv("PROV2_KANJI_POINT") == (char *) NULL) {
strncpy(kanjipoint, KANJI_POINT, (sizeof kanjipoint) - 1);
} else {
strncpy(kanjipoint, getenv("PROV2_KANJI_POINT"),
(sizeof kanjipoint) - 1);
}
kanjipoint[(sizeof kanjipoint) - 1] = '\0';
if (getenv("PROV2_ANK_XGAP") == (char *) NULL) {
strncpy(ank_xgap, ANK_XGAP, (sizeof ank_xgap) - 1);
} else {
strncpy(ank_xgap, getenv("PROV2_ANK_XGAP"),
(sizeof ank_xgap) - 1);
}
ank_xgap[(sizeof ank_xgap) - 1] = '\0';
if (getenv("PROV2_ANK_YGAP") == (char *) NULL) {
strncpy(ank_ygap, ANK_YGAP, (sizeof ank_ygap) - 1);
} else {
strncpy(ank_ygap, getenv("PROV2_ANK_YGAP"),
(sizeof ank_ygap) - 1);
}
ank_ygap[(sizeof ank_ygap) - 1] = '\0';
if (getenv("PROV2_KANJI_XGAP") == (char *) NULL) {
strncpy(kanji_xgap, KANJI_XGAP, (sizeof kanji_xgap) - 1);
} else {
strncpy(kanji_xgap, getenv("PROV2_KANJI_XGAP"),
(sizeof kanji_xgap) - 1);
}
kanji_xgap[(sizeof kanji_xgap) - 1] = '\0';
if (getenv("PROV2_KANJI_YGAP") == (char *) NULL) {
strncpy(kanji_ygap, KANJI_YGAP, (sizeof kanji_ygap) - 1);
} else {
strncpy(kanji_ygap, getenv("PROV2_KANJI_YGAP"),
(sizeof kanji_ygap) - 1);
}
kanji_ygap[(sizeof kanji_ygap) - 1] = '\0';
while (fgets(buf, MAXBUF, stdin) != (char *) NULL) {
col = 0;
for (i = 0; i <= strlen(buf); /* do nothing */ ) {
if (buf[i] == ' ') {
i++;
col++;
} else if (isprint(buf[i])) {
col_tmp = 0;
for (j = 0; isprint(buf[i]) && j < MAXBUF;
i++, j++) {
switch (buf[i]) {
case '\\':
str[j] = buf[i];
j++;
if (j < MAXBUF) {
str[j] = '\\';
}
break;
case '(':
case ')':
str[j] = '\\';
j++;
if (j < MAXBUF) {
str[j] = buf[i];
}
break;
default:
str[j] = buf[i];
break;
}
col_tmp++;
}
str[j] = '\0';
if (char_sw != ANK) {
printf("%s FONT_NORMAL setChar\n",
ankpoint);
printf
("/SYS_drawText_Xgap %s def\n",
ank_xgap);
printf
("/SYS_drawText_Ygap %s def\n",
ank_ygap);
char_sw = ANK;
}
printf("%d %d (%s) drawText\n", col, line,
str);
col += col_tmp;
} else if (buf[i] & 0x80) {
col_tmp = 0;
str[0] = '\0';
for (j = strlen(str); buf[i] & 0x80;
i++, j = strlen(str)) {
sprintf(str + j, "%2x", buf[i]);
if ((buf[i] & 0xc0) == 0xc0) {
col_tmp += 2;
}
}
if (char_sw != UTF8) {
printf
("%s KFONT_RYUMIN setKanjiChar\n",
kanjipoint);
printf
("/SYS_drawText_Xgap %s def\n",
kanji_xgap);
printf
("/SYS_drawText_Ygap %s def\n",
kanji_ygap);
char_sw = UTF8;
}
printf("%d %d <%s> drawText\n", col, line,
str);
col += col_tmp;
} else if (buf[i] == '\f') {
printf("showpage\n");
line = 0;
i++;
char_sw = 0;
} else {
i++;
}
}
line++;
if (line >= maxline) {
printf("showpage\n");
line = 0;
char_sw = 0;
}
}
if (line != 0) {
printf("showpage\n");
char_sw = 0;
}
}
int ShowUsage()
{
fprintf(stderr, "Usage: t2p [OPTION]\n");
fprintf(stderr, "\n");
fprintf(stderr, " -l maxline maxline per page\n");
fprintf(stderr, " -h show usage\n");
fprintf(stderr, "\n");
fprintf(stderr,
"a part of converting plain text to postscript from stdin\n");
fprintf(stderr, "and output to stdout\n");
return 0;
}