Debian Codegraph @

texk/web2c/uptexdir/uppltotf.ch

raw
1 % This is a change file for PLtoTF
2 %
3 % (2024-04-27) TTK Support upTeX new encoding for combining characters
4 % (2023-09-17) HY Support more than 256 different glue/kern
5 % (2022-12-03) TTK Merge pPLtoTF source/binary into upPLtoTF
6 % (2018-01-27) HY pPLtoTF p2.0 - new JFM spec by texjporg
7 % (07/18/2006) ST PLtoTF p1.8 (3.5, Web2c 7.2)
8 % (11/13/2000) KN PLtoTF p1.4 (3.5, Web2c 7.2)
9 % (03/27/1998) KN PLtoTF p1.3 (3.5, Web2c 7.2)
10 %
11 @x [0] l.52 - pTeX:
12 \def\title{PL$\,$\lowercase{to}$\,$TF changes for C}
13 @y
14 \def\title{PL$\,$\lowercase{to}$\,$TF changes for C, and for KANJI}
15 @z
16
17 @x [2] l.69 - pTeX:
18 @d my_name=='pltotf'
19 @d banner=='This is PLtoTF, Version 3.6' {printed when the program starts}
20 @y
21 @d my_name=='uppltotf'
22 @d banner=='This is upPLtoTF, Version 3.6-p240427'
23 {printed when the program starts}
24 @z
25
26 @x
27 parse_arguments;
28 @y
29 init_kanji;
30 parse_arguments;
31 @z
32
33 @x [6] l.140 - pTeX:
34 print_ln (version_string);
35 @y
36 print_ln (version_string);
37 print_ln ('process kanji code is ', conststringcast(get_enc_string), '.');
38 @z
39
40 @x [18] l.495 - pTeX:
41 @!xord:array[char] of ASCII_code; {conversion table}
42 @y
43 @!xord:array[char] of ASCII_code; {conversion table}
44 @!xchr:array[char] of byte; {specifiles conversion of output character}
45 @z
46
47 @x [19] l.506 - pTeX:
48 for k:=first_ord to last_ord do xord[chr(k)]:=invalid_code;
49 @y
50 for k:=0 to @'37 do xchr[k]:='?';
51 for k:=@'40 to 255 do xchr[k]:=k;
52 for k:=first_ord to last_ord do xord[chr(k)]:=invalid_code;
53 @z
54
55 @x [28] l.619 - pTeX:
56 else begin while (limit<buf_size-2)and(not eoln(pl_file)) do
57 begin incr(limit); read(pl_file,buffer[limit]);
58 end;
59 @y
60 else begin limit:=input_line2(pl_file,ustringcast(buffer),limit+1,buf_size-1)-1;
61 @z
62
63 @x [36] l.754 - pTeX: May have to increase some numbers to fit new commands
64 @d max_name_index=88 {upper bound on the number of keywords}
65 @d max_letters=600 {upper bound on the total length of all keywords}
66 @y
67 @d max_name_index=97 {upper bound on the number of keywords}
68 @d max_letters=700 {upper bound on the total length of all keywords}
69 @z
70
71 @x [44] l.839 - pTeX: Add kanji related codes
72 @d character_code=12
73 @y
74 @d character_code=12
75 @d type_code=13 {|TYPE| property}
76 @d glue_kern_code=14 {|GLUEKERN| property}
77 @d chars_in_type_code=15 {|CHARSINTYPE| property}
78 @d dir_code=16 {|DIRECTION| property}
79 @z
80
81 @x [44] l.856 - pTeX:
82 @d lig_code=74
83 @y
84 @d lig_code=74
85 @d glue_code=75 {|GLUE| property}
86 @#
87 @d undefined=0 {not decided file format yet}
88 @d tfm_format=1 {\.{TFM} file format}
89 @d jfm_or_vfm=2 {Yoko or Tate \.{JFM} file format}
90 @d jfm_format=3 {Yoko-kumi \.{JFM} file format}
91 @d vfm_format=4 {Tate-kumi \.{JFM} file format}
92 @z
93
94 @x [84] l.1542 - pTeX: Change valid property code.
95 if cur_code=comment_code then skip_to_end_of_item
96 else if cur_code>character_code then
97 flush_error('This property name doesn''t belong on the outer level')
98 @.This property name doesn't belong...@>
99 @y
100 if cur_code=comment_code then skip_to_end_of_item
101 else if (cur_code>dir_code)or
102 ((file_format=tfm_format)and(cur_code>character_code)) then
103 flush_error('This property name doesn''t belong on the outer level')
104 @.This property name doesn't belong...@>
105 @z
106
107 @x [85] l.1565 - pTeX: Added some property codes.
108 character_code: read_char_info;
109 @y
110 character_code: read_char_info;
111 type_code: read_kanji_info;
112 glue_kern_code: read_glue_kern;
113 chars_in_type_code: read_chars_in_type;
114 dir_code: read_direction;
115 @z
116
117 @x [110] l.1915 - pTeX: there are no charlists in kanji format files.
118 @<Check for infinite ligature loops@>;
119 @<Doublecheck the lig/kern commands and the extensible recipes@>;
120 for c:=0 to 255 do
121 @<Make sure that |c| is not the largest element of a charlist cycle@>;
122 @y
123 if file_format=tfm_format then begin
124 @<Check for infinite ligature loops@>;
125 @<Doublecheck the lig/kern commands and the extensible recipes@>;
126 for c:=0 to 255 do
127 @<Make sure that |c| is not the largest element of a charlist cycle@>;
128 end;
129 @z
130
131 @x [120] l.2037 - pTeX: when checking glue_kern prog check glues as well
132 begin if lig_exam<>bchar then
133 check_existence(lig_exam)('LIG character examined by');
134 @.LIG character examined...@>
135 check_existence(lig_gen)('LIG character generated by');
136 @.LIG character generated...@>
137 if lig_gen>=128 then if(c<128)or(c=256) then
138 if(lig_exam<128)or(lig_exam=bchar) then seven_unsafe:=true;
139 end
140 @y
141 begin if file_format=tfm_format then
142 begin if lig_exam<>bchar then
143 check_existence(lig_exam)('LIG character examined by');
144 @.LIG character examined...@>
145 check_existence(lig_gen)('LIG character generated by');
146 @.LIG character generated...@>
147 if lig_gen>=128 then if(c<128)or(c=256) then
148 if(lig_exam<128)or(lig_exam=bchar) then seven_unsafe:=true;
149 end
150 else if lig_exam<>bchar then
151 check_existence(lig_exam)('GLUE character examined by');
152 @.GLUE character examined...@>
153 end
154 @z
155
156 @x [128] l.2207 - pTeX: Decide the |file_format|.
157 @<Do the output@>=
158 @y
159 @<Do the output@>=
160 case file_format of
161 tfm_format: do_nothing;
162 undefined,jfm_or_vfm: begin file_format:=jfm_format;
163 print_ln('Input file is in kanji YOKO-kumi format.');
164 end;
165 jfm_format: print_ln('Input file is in kanji YOKO-kumi format.');
166 vfm_format: print_ln('Input file is in kanji TATE-kumi format.');
167 end;
168 @z
169
170 @x [128] l.2211 - pTeX: Output kanji character
171 @<Output the character info@>;
172 @y
173 if file_format<>tfm_format then @<Output the kanji character type info@>;
174 @<Output the character info@>;
175 @z
176
177 @x [128] l.2213 - pTeX: Output glue/kern programs
178 @<Output the ligature/kern program@>;
179 @y
180 @<Output the ligature/kern program@>;
181 if (file_format<>tfm_format)and(ng>0) then
182 for krn_ptr:=0 to ng-1 do
183 begin out_scaled(glue[3*krn_ptr+0]);
184 out_scaled(glue[3*krn_ptr+1]);
185 out_scaled(glue[3*krn_ptr+2]);
186 end;
187 @z
188
189 @x [130] l.2238 - pTeX:
190 not_found:=true; bc:=0;
191 while not_found do
192 if (char_wd[bc]>0)or(bc=255) then not_found:=false
193 else incr(bc);
194 not_found:=true; ec:=255;
195 while not_found do
196 if (char_wd[ec]>0)or(ec=0) then not_found:=false
197 else decr(ec);
198 if bc>ec then bc:=1;
199 @y
200 if file_format<>tfm_format then
201 begin bc:=0; ec:=0; nt:=1;
202 for kanji_type_index:=0 to max_kanji do
203 begin if kanji_type[kanji_type_index]>0 then incr(nt);
204 if kanji_type[kanji_type_index]>ec then ec:=kanji_type[kanji_type_index];
205 end;
206 end
207 else begin not_found:=true; bc:=0;
208 while not_found do
209 if (char_wd[bc]>0)or(bc=255) then not_found:=false
210 else incr(bc);
211 not_found:=true; ec:=255;
212 while not_found do
213 if (char_wd[ec]>0)or(ec=0) then not_found:=false
214 else decr(ec);
215 if bc>ec then bc:=1;
216 end;
217 @z
218
219 @x [130] l.2250 - pTeX:
220 lf:=6+lh+(ec-bc+1)+memory[width]+memory[height]+memory[depth]+
221 memory[italic]+nl+lk_offset+nk+ne+np;
222 @y
223 if file_format<>tfm_format then
224 lf:=7+nt+lh+(ec-bc+1)+memory[width]+memory[height]+memory[depth]+
225 memory[italic]+nl+lk_offset+nk+3*ng+np
226 else
227 lf:=6+lh+(ec-bc+1)+memory[width]+memory[height]+memory[depth]+
228 memory[italic]+nl+lk_offset+nk+ne+np;
229 @z
230
231 @x [131] pTeX:
232 @ @d out_size(#)==out((#) div 256); out((#) mod 256)
233 @y
234 @ @d out_size(#)==out((#) div 256); out((#) mod 256)
235 @d out_kanji_code(#)==out_size((#) mod 65536); out((#) div 65536)
236 @z
237
238 @x [131] l.2256 - pTeX:
239 out_size(lf); out_size(lh); out_size(bc); out_size(ec);
240 out_size(memory[width]); out_size(memory[height]);
241 out_size(memory[depth]); out_size(memory[italic]);
242 out_size(nl+lk_offset); out_size(nk); out_size(ne); out_size(np);
243 @y
244 if file_format=jfm_format then
245 begin out_size(yoko_id_number); out_size(nt);
246 end
247 else if file_format=vfm_format then
248 begin out_size(tate_id_number); out_size(nt);
249 end;
250 out_size(lf); out_size(lh); out_size(bc); out_size(ec);
251 out_size(memory[width]); out_size(memory[height]);
252 out_size(memory[depth]); out_size(memory[italic]);
253 out_size(nl+lk_offset); out_size(nk);
254 if file_format<>tfm_format then begin out_size(ng*3)
255 end
256 else begin out_size(ne);
257 end;
258 out_size(np);
259 @z
260
261 @x [146] l.2476 - pTeX:
262 @p procedure param_enter;
263 @y
264 @p
265 @<Declare kanji scanning routines@>@/
266 procedure param_enter;
267 @z
268
269 @x [146] l.2488 - pTeX: LIGTABLE command can not be used in JPL.
270 begin @<Read ligature/kern list@>;
271 end;
272 @y
273 begin @<If is jfm or vfm then print error@>;
274 @<Read ligature/kern list@>;
275 end;
276 @z
277
278 @x [146] l.2493 - pTeX: CHARACTER command can not be used in JPL.
279 begin @<Read character info list@>;
280 end;
281 @y
282 begin @<If is jfm or vfm then print error@>;
283 @<Read character info list@>;
284 end;
285 @z
286
287 @x [146] l.2506 - pTeX:
288 begin @<Correct and check the information@>
289 end;
290 @y
291 begin @<Correct and check the information@>
292 end;
293 @#
294 procedure read_kanji_info; {TYPE command}
295 var @!c:byte; {the char}
296 begin @<If is tfm then print error@>;
297 @<Read Kanji character type list@>;
298 end;
299 @#
300 procedure read_glue_kern; {GLUEKERN command}
301 var krn_ptr:0..max_kerns; {an index into |kern|}
302 @!c:byte; {runs through all character codes}
303 begin @<If is tfm then print error@>;
304 @<Read glue/kern list@>;
305 end;
306 @#
307 procedure read_chars_in_type; {CHARSINTYPE command}
308 var @!type_num:byte; {kanji character type number}
309 @!jis_code:integer; {sixteen bits Kanji character code}
310 begin @<If is tfm then print error@>;
311 @<Read Kanji characters list in this type@>;
312 end;
313 @#
314 procedure read_direction; {DIRECTION command}
315 begin @<If is tfm then print error@>;
316 @<Read direction@>;
317 end;
318 @z
319
320 @x
321 const n_options = 3; {Pascal won't count array lengths for us.}
322 @y
323 const n_options = 5; {Pascal won't count array lengths for us.}
324 @z
325
326 @x
327 usage_help (PLTOTF_HELP, nil);
328 @y
329 usage_help (UPPLTOTF_HELP, 'issue@@texjp.org');
330 @z
331
332 @x
333 end; {Else it was a flag; |getopt| has already done the assignment.}
334 @y
335 end else if argument_is ('kanji') then begin
336 if (not set_enc_string(optarg,optarg)) then
337 print_ln('Bad kanji encoding "', stringcast(optarg), '".');
338
339 end; {Else it was a flag; |getopt| has already done the assignment.}
340 @z
341
342 @x
343 @ An element with all zeros always ends the list.
344 @y
345 @ Kanji option.
346 @.-kanji@>
347
348 @<Define the option...@> =
349 long_options[current_option].name := 'kanji';
350 long_options[current_option].has_arg := 1;
351 long_options[current_option].flag := 0;
352 long_options[current_option].val := 0;
353 incr(current_option);
354
355 @ An element with all zeros always ends the list.
356 @z
357
358 @x [148] l.2620 - pTeX:
359 @* Index.
360 @y
361 @* For Japanese Font Metric routines.
362 We need to include some routines for handling kanji characters.
363
364 @<Constants...@>=
365 max_kanji=@"2FFFFF; { maximam number of multibyte characters }
366 max_kanji_code=@"2FFFFF; { maximum ucs code }
367 yoko_id_number=11; { is identifier for YOKO-kumi font}
368 tate_id_number=9; { is identifier for TATE-kumi font}
369
370 @ @<Glob...@>=
371 file_format:undefined..vfm_format; {the format of the input file}
372 kanji_type:array[0..max_kanji] of -1..256; {the type of every kanji char }
373 kanji_type_index:0..max_kanji; { index into above }
374 nt:integer; {number of entries in character type table}
375 glue:array[0..15000] of fix_word; {the distinct glue amounts, equals 3 * |max_kerns|}
376 ng:integer; {number of 3-word entries in glue table}
377
378 @ @<Set init...@>=
379 file_format:=undefined;
380 for kanji_type_index:=0 to max_kanji do kanji_type[kanji_type_index]:=-1;
381 ng:=0;
382
383 @ @<If is jfm or vfm then print error@>=
384 if file_format>tfm_format then
385 err_print('This is an illegal command for kanji format files.')
386 else if file_format=undefined then file_format:=tfm_format
387
388 @ @<If is tfm then print error@>=
389 if file_format=tfm_format then
390 err_print('You can use this command only for kanji format files.')
391 else if file_format=undefined then file_format:=jfm_or_vfm
392
393 @ These are extended propaties for \.{JFM}.
394
395 @<Enter all of the names and ...@>=
396 load4("T")("Y")("P")("E")(type_code);@/
397 load8("G")("L")("U")("E")("K")("E")("R")("N")(glue_kern_code);@/
398 load11("C")("H")("A")("R")("S")("I")("N")("T")("Y")("P")("E")
399 (chars_in_type_code);@/
400 load9("D")("I")("R")("E")("C")("T")("I")("O")("N")(dir_code);@/
401 load4("G")("L")("U")("E")(glue_code);@/
402
403 @ @<Enter the parameter names@>=
404 load10("E")("X")("T")("R")("A")("S")("P")("A")("C")("E")(parameter_code+7);@/
405 load12("E")("X")("T")("R")("A")("S")("T")("R")("E")("T")("C")("H")
406 (parameter_code+8);@/
407 load11("E")("X")("T")("R")("A")("S")("H")("R")("I")("N")("K")
408 (parameter_code+9);@/
409
410
411 @ Here, we declare kanji related routines and package gluekern stuff.
412 There routines a bit similar reading ligature/kern programs.
413
414 @<Read glue/kern list@>=
415 begin lk_step_ended:=false;
416 while level=1 do
417 begin while cur_char=" " do get_next;
418 if cur_char="(" then @<Read a glue/kern command@>
419 else if cur_char=")" then skip_to_end_of_item
420 else junk_error;
421 end;
422 finish_inner_property_list;
423 end;
424
425 @ @<Read a glue/kern command@>=
426 begin get_name;
427 if cur_code=comment_code then skip_to_end_of_item
428 else begin case cur_code of
429 label_code:@<Read a glue label step@>;
430 stop_code:@<Read a stop step@>;
431 skip_code:@<Read a skip step@>;
432 krn_code:@<Read a (glue) kerning step@>;
433 glue_code:@<Read a glue step@>;
434 others:
435 flush_error('This property name doesn''t belong in a GLUEKERN list');
436 @.This property name doesn't belong...@>
437 end;
438 finish_the_property;
439 end;
440 end
441
442 @ When a character is about to be tagged, we call the following
443 procedure so that an error message is given in case of multiple tags.
444
445 @<Declare kanji scanning routines@>=
446 procedure check_tag_gluekern(c:byte); {print error if |c| already tagged}
447 begin case char_tag[c] of
448 no_tag: do_nothing;
449 lig_tag: err_print('This character already appeared in a GLUEKERN LABEL');
450 @.This character already...@>
451 list_tag: err_print('Impossible: a list tag in a kanji format file?');
452 ext_tag: err_print('Impossible: an extensible tag in a kanji format file?');
453 end;
454 end;
455
456 @ @<Read a glue label step@>=
457 begin while cur_char=" " do get_next;
458 if cur_char="B" then
459 begin bchar_label:=nl; skip_to_paren; {\.{LABEL BOUNDARYCHAR}}
460 end
461 else begin backup; c:=get_byte;
462 check_tag_gluekern(c); char_tag[c]:=lig_tag; char_remainder[c]:=nl;
463 end;
464 if min_nl<=nl then min_nl:=nl+1;
465 lk_step_ended:=false;
466 end
467
468 @ @<Read a (glue) kerning step@>=
469 begin lig_kern[nl].b0:=0; lig_kern[nl].b1:=get_byte;
470 kern[nk]:=get_fix; krn_ptr:=0;
471 while kern[krn_ptr]<>kern[nk] do incr(krn_ptr);
472 if krn_ptr=nk then
473 begin if nk<max_kerns then incr(nk)
474 else begin err_print('At most ',max_kerns,' different kerns are allowed');
475 @.At most 5000 different kerns...@>
476 decr(krn_ptr);
477 end;
478 end;
479 lig_kern[nl].b2:=kern_flag+(krn_ptr div 256);
480 lig_kern[nl].b3:=krn_ptr mod 256;
481 if nl>=max_lig_steps-1 then
482 err_print('GLUEKERN table should never exceed ',max_lig_steps,' GLUE/KRN commands')
483 @.GLUEKERN table should never...@>
484 else incr(nl);
485 lk_step_ended:=true;
486 end
487
488 @ @<Read a glue step@>=
489 begin lig_kern[nl].b0:=0; lig_kern[nl].b1:=get_byte;
490 glue[3*ng+0]:=get_fix; glue[3*ng+1]:=get_fix; glue[3*ng+2]:=get_fix;
491 krn_ptr:=0;
492 while (glue[3*krn_ptr+0]<>glue[3*ng+0])or
493 (glue[3*krn_ptr+1]<>glue[3*ng+1])or
494 (glue[3*krn_ptr+2]<>glue[3*ng+2]) do incr(krn_ptr);
495 if krn_ptr=ng then
496 begin if ng<max_kerns then incr(ng)
497 else begin err_print('At most ',max_kerns,' different glues are allowed');
498 decr(krn_ptr);
499 end;
500 end;
501 lig_kern[nl].b2:=krn_ptr div 256;
502 lig_kern[nl].b3:=krn_ptr mod 256;
503 if nl>=max_lig_steps-1 then
504 err_print('GLUEKERN table should never exceed ',max_lig_steps,' GLUE/KRN commands')
505 @.GLUEKERN table should never...@>
506 else incr(nl);
507 lk_step_ended:=true;
508 end
509
510 @ The |TYPE| command like |CHARACTER| command, but |TYPE| only use
511 |CHARWD|, |CHARHT|, |CHARDP| and |CHARIT|
512
513 @<Read Kanji character type list@>=
514 begin c:=get_byte; {read the character type that is begin specified}
515 if verbose then @<Print |c| in octal notation@>;
516 while level=1 do
517 begin while cur_char=" " do get_next;
518 if cur_char="(" then @<Read a kanji property@>
519 else if cur_char=")" then skip_to_end_of_item
520 else junk_error;
521 end;
522 if char_wd[c]=0 then char_wd[c]:=sort_in(width,0); {legitimatize c}
523 finish_inner_property_list;
524 end;
525
526 @ @<Read a kanji property@>=
527 begin get_name;
528 if cur_code=comment_code then skip_to_end_of_item
529 else if (cur_code<char_wd_code)or(cur_code>char_ic_code) then
530 flush_error('This property name doesn''t belong in a TYPE list')
531 else begin case cur_code of
532 char_wd_code: char_wd[c]:=sort_in(width,get_fix);
533 char_ht_code: char_ht[c]:=sort_in(height,get_fix);
534 char_dp_code: char_dp[c]:=sort_in(depth,get_fix);
535 char_ic_code: char_ic[c]:=sort_in(italic,get_fix);
536 end;@/
537 finish_the_property;
538 end;
539 end
540
541 @ Next codes used to get KANJI codes from \.{JPL} file.
542
543 @<Read Kanji characters list in this type@>=
544 begin type_num:=get_byte;
545 if type_num=0 then
546 skip_error('You cannot list the chars in type 0. It is the default type')
547 else begin repeat jis_code:=get_kanji;
548 if jis_code<0 then
549 err_print('Illegal characters. I was expecting a jis code or character')
550 else if jis_code=0 then { 0 signals |end_of_list| }
551 do_nothing
552 else if kanji_type[jis_to_index(jis_code)]>=0 then
553 err_print('jis code ', jis_code:1, ' is already in type ',
554 kanji_type[jis_to_index(jis_code)])
555 else
556 kanji_type[jis_to_index(jis_code)]:=type_num;
557 until jis_code=0;
558 skip_to_paren;
559 end
560 end
561
562 @ Next codes read and check direction. We can not decide |file_format| of
563 metric file whether for yoko-kumi or tate-kumi, until have scan |DIRECTION|
564 property (|dir_code| command).
565
566 @<Read direction@>=
567 begin while cur_char=" " do get_next;
568 if cur_char="T" then
569 begin if verbose then print_ln('This is tatekumi format');
570 file_format:=vfm_format;
571 end
572 else if cur_char="Y" then
573 begin if verbose then print_ln('This is yokokumi format');
574 file_format:=jfm_format;
575 end
576 else err_print('The dir value should be "TATE" or "YOKO"');
577 skip_to_paren;
578 end
579
580 @ Next codes used to write |kanji_type| to \.{JFM}.
581 In the original JFM spec by ASCII Corporation, |jis_code| and |char_type|
582 were packed into upper (2~bytes) and lower (2~bytes) halfword respectively.
583 However, |char_type| is allowed only 0..255,
584 so the upper byte of lower halfword was always 0.
585
586 In the new JFM spec by texjporg, |jis_code| ``XXyyzz'' is packed into
587 first 3~bytes in the form ``yy zz XX'', and |char_type| is packed into
588 remaining 1~byte. The new spec is effectively upper compatible with
589 the original, and it allows |jis_code| larger than 0x10000 (not really
590 useful for me \.{pPLtoTF} but necessary for \.{upPLtoTF}).
591
592 @<Output the kanji character type info@>=
593 begin out_size(0); out_size(0); { the default }
594 for kanji_type_index:=0 to max_kanji do
595 begin if kanji_type[kanji_type_index]>0 then
596 begin out_kanji_code(index_to_jis(kanji_type_index));
597 out(kanji_type[kanji_type_index]);
598 if verbose then begin
599 print('char index = ', kanji_type_index);
600 print(' (jis ');
601 print_jis_hex(index_to_jis(kanji_type_index));
602 print(') is type ');
603 print_octal(kanji_type[kanji_type_index]);
604 write_ln('');
605 end;
606 end;
607 end;
608 end;
609
610 @ We also need to define some routines which handling 2bytes characters.
611 These routine is called from only |read_chars_in_type| command.
612
613 The kanji jis code is taken from the |char_ext| and |char_code| values
614 set by the user. The index into the |kanji_type| array is based on the
615 kuten codes, with all unused codes removed and beginning at 0, not 0101.
616 The |jis_to_index| is called from |chars_in_type| command.
617
618 @<Declare kanji scanning routines@>=
619 function get_next_raw:byte; {get next rawdata in buffer}
620 begin while loc=limit do fill_buffer;
621 incr(loc); get_next_raw:=buffer[loc];
622 if multistrlen(ustringcast(buffer),loc+3,loc)>1 then cur_char:=" "
623 else cur_char:=xord[buffer[loc]];
624 end;
625 @#
626 function todig(@!ch:byte):byte; {convert character to number}
627 begin if (ch>="A")and(ch<="F") then todig:=ch-"A"+10
628 else if (ch>="0")and(ch<="9") then todig:=ch-"0"
629 else begin skip_error('This expression is out of JIS-code encoding.');
630 todig:=0;
631 end;
632 end;
633 @#
634 procedure print_jis_hex(jis_code:integer); {prints jiscode as four digits}
635 var dig:array[0..5] of byte; {holds jis hex codes}
636 i:byte; {index of array}
637 begin dig[0]:=(jis_code div 65536) div 16; dig[1]:=(jis_code div 65536) mod 16;
638 dig[2]:=(jis_code div 4096) mod 16; dig[3]:=(jis_code div 256) mod 16;
639 dig[4]:=(jis_code div 16) mod 16; dig[5]:=jis_code mod 16;
640 for i:=0 to 1 do
641 if (dig[i]<>0)or(dig[0]<>0) then begin { if dig[0]<>0, dig[1] should be always printed }
642 if dig[i]<10 then print(dig[i]) else
643 case dig[i] of
644 10: print('A'); 11: print('B'); 12: print('C');
645 13: print('D'); 14: print('E'); 15: print('F');
646 end;
647 end;
648 for i:=2 to 5 do
649 if dig[i]<10 then print(dig[i]) else
650 case dig[i] of
651 10: print('A'); 11: print('B'); 12: print('C');
652 13: print('D'); 14: print('E'); 15: print('F');
653 end;
654 end;
655 @#
656 function valid_jis_code(cx:integer):boolean;
657 begin valid_jis_code:=true;
658 if (cx>max_kanji)or(not is_char_kanji(fromDVI(cx)))
659 or(toDVI(fromDVI(cx))<>cx) then valid_jis_code:=false;
660 end;
661 @#
662 function jis_to_index(jis:integer):integer;
663 begin
664 jis_to_index:=jis;
665 end;
666 @#
667 function index_to_jis(ix:integer):integer;
668 begin
669 index_to_jis:=ix;
670 end;
671 @#
672 function get_kanji:integer; {get kanji character code}
673 var @!ch:byte;
674 @!cx,@!jis_code:integer; {sixteen bits kanji character code}
675 begin repeat ch:=get_next_raw; {|ch| is rawdata in buffer}
676 until ch<>' '; {skip the blanks before the kanji code}
677 if ch=')' then
678 begin decr(loc); jis_code:=0;
679 end
680 else if (ch='J')or(ch='j') then
681 begin repeat ch:=get_next_raw;
682 until ch<>' '; {skip the blanks after the type code}
683 @<Scan a Kanji hexadecimal code@>;
684 jis_code:=toDVI(fromJIS(cx)); cur_char:=ch;
685 if not valid_jis_code(jis_code) then
686 err_print('jis code ', jis_code:1, ' is invalid');
687 end
688 else if (ch='U')or(ch='u') then
689 begin repeat ch:=get_next_raw;
690 until ch<>' '; {skip the blanks after the type code}
691 @<Scan a Kanji hexadecimal code@>;
692 jis_code:=toDVI(fromUCS(cx)); cur_char:=ch;
693 if not valid_jis_code(jis_code) then
694 err_print('ucs code ', jis_code:1, ' is invalid');
695 end
696 else if multistrlen(ustringcast(buffer), loc+4, loc)>1 then
697 begin cur_char:=" ";
698 jis_code:=fromBUFF(ustringcast(buffer), loc+4, loc);
699 loc:=loc+multistrlen(ustringcast(buffer), loc+4, loc)-1;
700 if (isinternalUPTEX) then
701 begin
702 cx:=fromBUFF(ustringcast(buffer), loc+5, loc+1);
703 if (UVScombinecode(jis_code,cx)>0) then begin
704 jis_code:=UVScombinecode(jis_code,cx);
705 loc:=loc+multistrlen(ustringcast(buffer), loc+5, loc+1);
706 end;
707 end
708 else begin
709 jis_code:=toDVI(jis_code)
710 end;
711 if not valid_jis_code(jis_code) then
712 err_print('jis code ', jis_code:1, ' is invalid');
713 end
714 else jis_code:=-1;
715 get_kanji:=jis_code;
716 end;
717
718 @ @<Scan a Kanji hex...@>=
719 begin cx:=todig(xord[ch]);
720 incr(loc); ch:=xord[buffer[loc]];
721 while ((ch>="0")and(ch<="9"))or((ch>="A")and(ch<="F")) do
722 begin cx:=cx*16+todig(ch); {overflow might happen, but rare...}
723 incr(loc); ch:=xord[buffer[loc]];
724 end;
725 decr(loc); ch:=xord[buffer[loc]];
726 if cx>max_kanji_code then
727 begin skip_error('This value shouldn''t exceed jis code');
728 cx:=0; ch:=" ";
729 end;
730 end
731
732 @* Index.
733 @z