Debian Codegraph @

texk/web2c/uptexdir/upbibtex.ch

raw
1 % Change file for BibTeX in C, originally by Howard Trickey.
2 %
3 % 05/28/84 Initial implementation, version 0.41 of BibTeX
4 % 07/01/84 Version 0.41a of BibTeX.
5 % 12/17/84 Version 0.97c of BibTeX.
6 % 02/12/85 Version 0.98c of BibTeX.
7 % 02/25/85 Newer version 0.98c of BibTeX.
8 % 03/25/85 Version 0.98f of BibTeX
9 % 05/23/85 Version 0.98i of BibTeX
10 % 02/11/88 Version 0.99b of BibTeX
11 % 04/04/88 Version 0.99c; converted for use with web2c (ETM).
12 % 11/30/89 Use FILENAMESIZE instead of 1024 (KB).
13 % 03/09/90 `int' is a bad variable name for C.
14 % (more recent changes in the ChangeLog)
15 %
16 % 5/ 2/89 Version 0.20 of JBiBTeX by Shouichi Matsui
17 % 12/25/90 Version 0.30 of JBibTeX by Shouichi Matsui
18 % 1/ 1/91 last update for JBibTeX 0.30 by Shouichi Matsui
19 % 10/30/92 last update for JBibTeX 0.31 for bug fix by Shouichi Matsui
20 % 11/02/94 Version 0.32 for use with web2c 6.1, by Takafumi Sakurai
21 %
22 % 2002 Version 0.33 add kanji option by ASCII Corporation
23 %
24 % 2009 pTeXenc, pbibtex N. Tsuchimura
25 % 2010 Version 0.99d of BibTeX for TeX Live
26 %
27 % 2022-02-08 Version 0.34 by H. Yamashita
28 % * Avoid breaking BBL lines at white space after a Japanese character, to
29 % preserve spacing within BIB entry for subsequent pTeX line-end operations.
30 % 2022-02-20 Still version 0.34 by H. Yamashita (-> TL'22 version)
31 % * Improve substring$ to truncate at least one character when trying to
32 % start counting from the middle byte of the first or last Japanese character.
33 % 2022-05-15 Version 0.35 by Takuji Tanaka
34 % * Accept multibyte characters by int.to.chr$ and chr.to.int$.
35 % 2022-12-03 Version 0.36 by Takuji Tanaka (-> TL'23 version)
36 % * Merge pBibTeX source/binary into upBibTeX.
37
38 @x [0] extended version information
39 \def\title{\BibTeX\ }
40 @y
41 \def\title{J\BibTeX\ 0.36 Changes for C Version \BibTeX\ }
42 @z
43
44 @x [0]
45 \centerline{\:\titlefont The {\:\ttitlefont \BibTeX} preprocessor}
46 \vskip 15pt \centerline{(Version 0.99e---\today)} \vfill}
47 @y
48 \centerline{\:\titlefont The {\:\ttitlefont J\BibTeX} preprocessor}
49 \vskip 15pt \centerline{(Version 0.99e-j0.36---\today)} \vfill}
50 @z
51
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 % [1] banner
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 @x [1]
56 @d my_name=='bibtex'
57 @d banner=='This is BibTeX, Version 0.99e' {printed when the program starts}
58 @y
59 @d my_name=='upbibtex'
60 @d banner=='This is upBibTeX, Version 0.99e-j0.36-u2.02'
61 {printed when the program starts}
62 @z
63
64 @x [10]
65 print (banner);
66 @y
67 print (banner);
68 print (' (', conststringcast(get_enc_string), ')');
69 @z
70
71 @x [27] Changes for JBibTeX by Shouichi Matsui
72 for i:=0 to @'37 do xchr[i]:=chr(i);
73 for i:=@'177 to @'377 do xchr[i]:=chr(i);
74 @y
75 for i:=1 to @'37 do xchr[i]:=' ';
76 xchr[tab]:=chr(tab);
77 for i:=@'200 to 255 do xchr[i]:=chr(i);
78 xchr[@'33]:=chr(@'33); {escape char}
79 @z
80
81 @x [28] Changes for JBibTeX by Shouichi Matsui
82 for i:=first_text_char to last_text_char do xord[xchr[i]]:=i;
83 @y
84 for i:=first_text_char to last_text_char do xord[i]:=invalid_code;
85 for i:=1 to @'176 do xord[i]:= i;
86 for i:=@'200 to 255 do xord[i]:=i;
87 @z
88
89
90 @x [29] Changes for JBibTeX by Shouichi Matsui for ver. 0.30
91 @d period = "." {these are three}
92 @d question_mark = "?" {string-ending characters}
93 @d exclamation_mark = "!" {of interest in \.{add.period\$}}
94 @y
95 @d period = "." {these are three}
96 @d question_mark = "?" {string-ending characters}
97 @d exclamation_mark = "!" {of interest in \.{add.period\$}}
98 @d e_ss3 = @"8F {single shift three in EUC}
99 @d e_pun_first = @"A1 {Zenkaku punctuation first byte; in EUC}
100 @d e_space = @"A1A1 {Zenkaku space; in EUC}
101 @d e_toten = @"A1A2 {Zenkaku kuten; in EUC}
102 @d e_kuten = @"A1A3 {Zenkaku toten; in EUC}
103 @d e_comma = @"A1A4 {Zenkaku comman; in EUC}
104 @d e_period = @"A1A5 {Zenkaku period; in EUC}
105 @d e_question = @"A1A9 {Zenkaku question mark; in EUC}
106 @d e_exclamation =@"A1AA {Zenkaku exclamation mark; in EUC}
107 @d u_pun_first1 = @"E3 {Zenkaku punctuation first byte(1); in UTF-8}
108 @d u_pun_first2 = @"EF {Zenkaku punctuation first byte(2); in UTF-8}
109 @d u_space = @"3000 {Zenkaku space; in UCS}
110 @d u_toten = @"3001 {Zenkaku toten; in UCS}
111 @d u_kuten = @"3002 {Zenkaku kuten; in UCS}
112 @d u_comma = @"FF0C {Zenkaku comman; in UCS}
113 @d u_period = @"FF0E {Zenkaku period; in UCS}
114 @d u_question = @"FF1F {Zenkaku question mark; in UCS}
115 @d u_exclamation = @"FF01 {Zenkaku exclamation mark; in UCS}
116 @d u_double_question = @"2047 {Zenkaku double question mark; in UCS}
117 @d u_double_exclam = @"203C {Zenkaku double exclamation mark; in UCS}
118 @d u_interrobang = @"203D {Zenkaku interrobang; in UCS}
119 @d u_question_exclam = @"2048 {Zenkaku question exclamation mark; in UCS}
120 @d u_exclam_question = @"2049 {Zenkaku exclamation question mark; in UCS}
121 @z
122
123 % [32] Make RET a `white_space' character, so we won't choke on DOS
124 % files, which use CR/LF for line endings.
125 @x [32] Changes for JBibTeX by Shouichi Matsui
126 @<Set initial values of key variables@>=
127 for i:=0 to @'177 do lex_class[i] := other_lex;
128 for i:=@'200 to @'377 do lex_class[i] := alpha;
129 for i:=0 to @'37 do lex_class[i] := illegal;
130 lex_class[invalid_code] := illegal;
131 lex_class[tab] := white_space;
132 lex_class[13] := white_space;
133 lex_class[space] := white_space;
134 lex_class[tie] := sep_char;
135 lex_class[hyphen] := sep_char;
136 for i:=@'60 to @'71 do lex_class[i] := numeric;
137 for i:=@'101 to @'132 do lex_class[i] := alpha;
138 for i:=@'141 to @'172 do lex_class[i] := alpha;
139 @y
140 @<Set initial values of key variables@>=
141 for i:=0 to @'377 do lex_class[i] := other_lex;
142 for i:=0 to @'37 do lex_class[i] := illegal;
143 lex_class[invalid_code] := illegal;
144 lex_class[tab] := white_space;
145 lex_class[13] := white_space;
146 lex_class[space] := white_space;
147 lex_class[tie] := sep_char;
148 lex_class[hyphen] := sep_char;
149 for i:=@'60 to @'71 do lex_class[i] := numeric;
150 for i:=@'101 to @'132 do lex_class[i] := alpha;
151 for i:=@'141 to @'172 do lex_class[i] := alpha;
152 @z
153
154 @x [33] Changes for JBibTeX by Shouichi Matsui
155 @<Set initial values of key variables@>=
156 for i:=0 to @'377 do id_class[i] := legal_id_char;
157 for i:=0 to @'37 do id_class[i] := illegal_id_char;
158 id_class[space] := illegal_id_char;
159 id_class[tab] := illegal_id_char;
160 id_class[double_quote] := illegal_id_char;
161 id_class[number_sign] := illegal_id_char;
162 id_class[comment] := illegal_id_char;
163 id_class[single_quote] := illegal_id_char;
164 id_class[left_paren] := illegal_id_char;
165 id_class[right_paren] := illegal_id_char;
166 id_class[comma] := illegal_id_char;
167 id_class[equals_sign] := illegal_id_char;
168 id_class[left_brace] := illegal_id_char;
169 id_class[right_brace] := illegal_id_char;
170 @y
171 @<Set initial values of key variables@>=
172 for i:=0 to @'377 do id_class[i] := legal_id_char;
173 for i:=0 to @'37 do id_class[i] := illegal_id_char;
174 id_class[@'33] := legal_id_char;
175 id_class[space] := illegal_id_char;
176 id_class[tab] := illegal_id_char;
177 id_class[double_quote] := illegal_id_char;
178 id_class[number_sign] := illegal_id_char;
179 id_class[comment] := illegal_id_char;
180 id_class[single_quote] := illegal_id_char;
181 id_class[left_paren] := illegal_id_char;
182 id_class[right_paren] := illegal_id_char;
183 id_class[comma] := illegal_id_char;
184 id_class[equals_sign] := illegal_id_char;
185 id_class[left_brace] := illegal_id_char;
186 id_class[right_brace] := illegal_id_char;
187 @z
188
189 @x [35] Changes for JBibTeX by Shouichi Matsui
190 char_width[@'167] := 722;
191 char_width[@'170] := 528;
192 char_width[@'171] := 528;
193 char_width[@'172] := 444;
194 char_width[@'173] := 500;
195 char_width[@'174] :=1000;
196 char_width[@'175] := 500;
197 char_width[@'176] := 500;
198 @y
199 char_width[@'167] := 722;
200 char_width[@'170] := 528;
201 char_width[@'171] := 528;
202 char_width[@'172] := 444;
203 char_width[@'173] := 500;
204 char_width[@'174] :=1000;
205 char_width[@'175] := 500;
206 char_width[@'176] := 500;
207 @z
208
209 @x [47] JBibTeX and dynamic buf_size.
210 label loop_exit;
211 @y
212 label loop_exit;
213 var i:c_int_type;
214 @z
215 @x [still 47] JBibTeX and dynamic buf_size.
216 while (not eoln(f)) do
217 begin
218 if (last >= buf_size) then
219 buffer_overflow;
220 buffer[last] := xord[getc (f)];
221 incr (last);
222 end;
223 vgetc (f); {skip the eol}
224 @y
225 last := input_line2(f,ustringcast(buffer),last,buf_size,address_of(i));
226 while (not eof(f)) and (last > 0) and (i <> 10) and (i <> 13) do
227 begin
228 buffer_overflow;
229 last := input_line2(f,ustringcast(buffer),last,buf_size,address_of(i));
230 end;
231 @z
232
233 @x [62] procedure lower_case
234 procedure lower_case (var buf:buf_type; @!bf_ptr,@!len:buf_pointer);
235 var i:buf_pointer;
236 begin
237 if (len > 0) then
238 for i := bf_ptr to bf_ptr+len-1 do
239 if ((buf[i]>="A") and (buf[i]<="Z")) then
240 buf[i] := buf[i] + case_difference;
241 @y
242 procedure lower_case (var buf:buf_type; @!bf_ptr,@!len:buf_pointer);
243 var i:buf_pointer;
244 @!ch:integer;
245 begin
246 if (len > 0) then
247 for i := bf_ptr to bf_ptr+len-1 do
248 if ((buf[i]>="A") and (buf[i]<="Z")) then begin
249 buf[i] := buf[i] + case_difference;
250 end
251 else if ((is_internalUPTEX) and (buf[i]>=@"C3) and (buf[i]<=@"D4)) then begin
252 ch := fromBUFF(buf,i+2,i);
253 if (((ch>=@"C0) and (ch<=@"DE) and (ch<>@"D7)) or
254 ((ch>=@"391) and (ch<=@"3AA) and (ch<>@"3A2)) or
255 ((ch>=@"410) and (ch<=@"42F))) then begin
256 ch := toBUFF(ch + case_difference);
257 buf[i] := BYTE3(ch);
258 buf[i+1] := BYTE4(ch);
259 end
260 else if (((ch>=@"100) and (ch<=@"137) and ((ch mod 2)=0)) or
261 ((ch>=@"139) and (ch<=@"148) and ((ch mod 2)=1)) or
262 ((ch>=@"14A) and (ch<=@"177) and ((ch mod 2)=0)) or
263 ((ch>=@"179) and (ch<=@"17E) and ((ch mod 2)=1)) or
264 ((ch>=@"370) and (ch<=@"373) and ((ch mod 2)=0)) or
265 ( ch=@"376 ) or
266 ((ch>=@"3D8) and (ch<=@"3EF) and ((ch mod 2)=0)) or
267 ( ch=@"3F7 ) or ( ch=@"3FA ) or
268 ((ch>=@"460) and (ch<=@"481) and ((ch mod 2)=0)) or
269 ((ch>=@"48A) and (ch<=@"4BF) and ((ch mod 2)=0)) or
270 ((ch>=@"4C1) and (ch<=@"4CE) and ((ch mod 2)=1)) or
271 ((ch>=@"4D0) and (ch<=@"52F) and ((ch mod 2)=0))) then begin
272 ch := toBUFF(ch + 1);
273 buf[i] := BYTE3(ch);
274 buf[i+1] := BYTE4(ch);
275 end
276 else if (ch=@"178) then begin
277 ch := toBUFF(@"FF);
278 buf[i] := BYTE3(ch);
279 buf[i+1] := BYTE4(ch);
280 end
281 else if ((ch>=@"400) and (ch<=@"40F)) then begin
282 ch := toBUFF(ch + @"50);
283 buf[i] := BYTE3(ch);
284 buf[i+1] := BYTE4(ch);
285 end
286 else if (ch=@"4C0) then begin
287 ch := toBUFF(@"4CF);
288 buf[i] := BYTE3(ch);
289 buf[i+1] := BYTE4(ch);
290 end
291 end
292 @z
293
294 @x [63] procedure upper_case
295 var i:buf_pointer;
296 begin
297 if (len > 0) then
298 for i := bf_ptr to bf_ptr+len-1 do
299 if ((buf[i]>="a") and (buf[i]<="z")) then
300 buf[i] := buf[i] - case_difference;
301 @y
302 var i:buf_pointer;
303 @!ch:integer;
304 begin
305 if (len > 0) then
306 for i := bf_ptr to bf_ptr+len-1 do
307 if ((buf[i]>="a") and (buf[i]<="z")) then begin
308 buf[i] := buf[i] - case_difference;
309 end
310 else if ((is_internalUPTEX) and (buf[i]>=@"C3) and (buf[i]<=@"D4)) then begin
311 ch := fromBUFF(buf,i+2,i);
312 if (((ch>=@"E0) and (ch<=@"FE) and (ch<>@"F7)) or
313 ((ch>=@"3B1) and (ch<=@"3CA) and (ch<>@"3C2)) or
314 ((ch>=@"430) and (ch<=@"44F))) then begin
315 ch := toBUFF(ch - case_difference);
316 buf[i] := BYTE3(ch);
317 buf[i+1] := BYTE4(ch);
318 end
319 else if (((ch>=@"100) and (ch<=@"137) and ((ch mod 2)=1)) or
320 ((ch>=@"139) and (ch<=@"148) and ((ch mod 2)=0)) or
321 ((ch>=@"14A) and (ch<=@"177) and ((ch mod 2)=1)) or
322 ((ch>=@"179) and (ch<=@"17E) and ((ch mod 2)=0)) or
323 ((ch>=@"370) and (ch<=@"373) and ((ch mod 2)=1)) or
324 ( ch=@"377 ) or
325 ((ch>=@"3D8) and (ch<=@"3EF) and ((ch mod 2)=1)) or
326 ( ch=@"3F8 ) or ( ch=@"3FB ) or
327 ((ch>=@"460) and (ch<=@"481) and ((ch mod 2)=1)) or
328 ((ch>=@"48A) and (ch<=@"4BF) and ((ch mod 2)=1)) or
329 ((ch>=@"4C1) and (ch<=@"4CE) and ((ch mod 2)=0)) or
330 ((ch>=@"4D0) and (ch<=@"52F) and ((ch mod 2)=1))) then begin
331 ch := toBUFF(ch - 1);
332 buf[i] := BYTE3(ch);
333 buf[i+1] := BYTE4(ch);
334 end
335 else if (ch=@"DF) then begin { Latin Small Letter Sharp S }
336 buf[i] := "S";
337 buf[i+1] := "S";
338 end
339 else if (ch=@"FF) then begin
340 ch := toBUFF(@"178);
341 buf[i] := BYTE3(ch);
342 buf[i+1] := BYTE4(ch);
343 end
344 else if ((ch>=@"450) and (ch<=@"45F)) then begin
345 ch := toBUFF(ch - @"50);
346 buf[i] := BYTE3(ch);
347 buf[i+1] := BYTE4(ch);
348 end
349 else if (ch=@"4CF) then begin
350 ch := toBUFF(@"4C0);
351 buf[i] := BYTE3(ch);
352 buf[i+1] := BYTE4(ch);
353 end
354 end
355 @z
356
357 @x [100]
358 @<Procedures and functions for the reading and processing of input files@>=
359 procedure get_the_top_level_aux_file_name;
360 label aux_found,@!aux_not_found;
361 begin
362 @y
363 @<Procedures and functions for the reading and processing of input files@>=
364 procedure get_the_top_level_aux_file_name;
365 label aux_found,@!aux_not_found;
366 var i:0..last_text_char; {this is the first one declared}
367 begin
368 @<Initialize variables depending on Kanji code@>
369 @z
370
371 @x [102]
372 parse_arguments;
373 @y
374 init_kanji;
375 parse_arguments;
376 @z
377
378 % pBibTeX: do not break at |white_space| after Japanese characters (2022-02-08 j0.34)
379 @x [323] "Break that line"
380 while ((lex_class[out_buf[out_buf_ptr]] <> white_space) and
381 (out_buf_ptr >= min_print_line)) do
382 decr(out_buf_ptr);
383 @y
384 while (((lex_class[out_buf[out_buf_ptr]] <> white_space) or
385 (out_buf[out_buf_ptr-1] > 127)) and (out_buf_ptr >= min_print_line)) do
386 decr(out_buf_ptr);
387 @z
388 @x [324] "Break that unbreakably long line"
389 if (lex_class[out_buf[out_buf_ptr]] <> white_space) then
390 incr(out_buf_ptr)
391 @y
392 if (lex_class[out_buf[out_buf_ptr]] <> white_space) or
393 (out_buf[out_buf_ptr-1] > 127) then
394 incr(out_buf_ptr)
395 @z
396
397 @x [331] Changes for JBibTeX by Shouichi Matsui
398 @!b_write : hash_loc; {\.{write\$}}
399 @!b_default : hash_loc; {either \.{skip\$} or \.{default.type}}
400 @y
401 @!b_write : hash_loc; {\.{write\$}}
402 @!b_is_kanji_str : hash_loc; {\.{is.kanji.str\$}}
403 @!b_default : hash_loc; {either \.{skip\$} or \.{default.type}}
404 @z
405
406 @x [333] Changes for JBibTeX by Shouichi Matsui
407 @d n_write = 36 {\.{write\$}}
408
409 @<Constants in the outer block@>=
410 @!num_blt_in_fns = 37; {one more than the previous number}
411 @y
412 @d n_write = 36 {\.{write\$}}
413 @d n_is_kanji_str = 37 {\.{is.kanji.str\$}}
414
415 @<Constants in the outer block@>=
416 @!num_blt_in_fns = 38; {one more than the previous number}
417 @z
418
419 @x [334] Changes for JBibTeX by Shouichi Matsui
420 build_in('write$ ',6,b_write,n_write);
421 @y
422 build_in('write$ ',6,b_write,n_write);
423 build_in('is.kanji.str$',13,b_is_kanji_str,n_is_kanji_str);
424 @z
425
426 @x [341] Changes for JBibTeX by Shouichi Matsui
427 n_write : x_write;
428 othercases confusion ('Unknown built-in function')
429 endcases;
430 end
431 @y
432 n_write : x_write;
433 n_is_kanji_str: x_is_kanji_str;
434 othercases confusion ('Unknown built-in function')
435 endcases;
436 end
437 @z
438
439 @x [342] Changes for JBibTeX by Shouichi Matsui
440 @<|execute_fn|({\.{write\$}})@>@;
441 @<|execute_fn| itself@>
442 @y
443 @<|execute_fn|({\.{write\$}})@>@;
444 @<|execute_fn|({\.{is.kanji.str\$}})@>@;
445 @<|execute_fn| itself@>
446 @z
447
448 @x [361] Changes for JBibTeX by Shouichi Matsui --- add.period$ for ver. 0.30
449 case (str_pool[sp_ptr]) of
450 period,
451 question_mark,
452 exclamation_mark :
453 repush_string;
454 othercases
455 @<Add the |period|\(t) (it's necessary) and push@>
456 @y
457 case (str_pool[sp_ptr]) of
458 period,
459 question_mark,
460 exclamation_mark :
461 repush_string;
462 othercases
463 begin
464 if (is_internalEUC) then
465 begin
466 case (fromBUFF(str_pool, sp_ptr+1, sp_ptr-1)) of
467 e_kuten,
468 e_period,
469 e_question,
470 e_exclamation:
471 if (str_pool[sp_ptr-2]<>e_ss3) then
472 repush_string
473 else
474 @<Add the |period|\(t) (it's necessary) and push@>;
475 othercases
476 @<Add the |period|\(t) (it's necessary) and push@>;
477 endcases;
478 end;
479 if (is_internalUPTEX) then
480 begin
481 case (fromBUFF(str_pool, sp_ptr+1, sp_ptr-2)) of
482 u_kuten,
483 u_period,
484 u_question,
485 u_exclamation,
486 u_double_question,
487 u_double_exclam,
488 u_interrobang,
489 u_question_exclam,
490 u_exclam_question:
491 repush_string;
492 othercases
493 @<Add the |period|\(t) (it's necessary) and push@>;
494 endcases;
495 end;
496 end;
497 @z
498
499 @x [377] x_chr_to_int
500 else if (length(pop_lit1) <> 1) then
501 begin
502 print ('"');
503 print_pool_str (pop_lit1);
504 bst_ex_warn ('" isn''t a single character');
505 push_lit_stk (0, stk_int);
506 end
507 else
508 push_lit_stk (str_pool[str_start[pop_lit1]], stk_int);
509 {push the (|ASCII_code|) integer}
510 @y
511 else if (length(pop_lit1) = multibytelen(str_pool[str_start[pop_lit1]])) then
512 begin
513 if (length(pop_lit1) = 1) then
514 push_lit_stk(str_pool[str_start[pop_lit1]],stk_int)
515 {push the (|ASCII_code|) integer}
516 else
517 push_lit_stk(toDVI(fromBUFF(str_pool, str_start[pop_lit1]+length(pop_lit1), str_start[pop_lit1])),stk_int)
518 { a KANJI char is |2..4|byte long }
519 end
520 else
521 begin
522 print ('"');
523 print_pool_str (pop_lit1);
524 bst_ex_warn ('" isn''t a single character');
525 push_lit_stk (0, stk_int);
526 end
527 @z
528
529 @x [383] by Shouichi Matsui for Zenkaku comma
530 if (ex_buf_ptr < ex_buf_length) then {remove the ``and''}
531 ex_buf_ptr := ex_buf_ptr - 4;
532 @y
533 if (ex_buf_ptr < ex_buf_length) then {remove the ``and'', or Zenkau comma}
534 begin
535 if (is_internalEUC) then
536 if((fromBUFF(ex_buf, ex_buf_length, ex_buf_ptr-2) = e_comma) or
537 (fromBUFF(ex_buf, ex_buf_length, ex_buf_ptr-2) = e_toten))
538 then ex_buf_ptr := ex_buf_ptr - 2
539 else ex_buf_ptr := ex_buf_ptr - 4;
540 if (is_internalUPTEX) then
541 if((fromBUFF(ex_buf, ex_buf_length, ex_buf_ptr-3) = u_comma) or
542 (fromBUFF(ex_buf, ex_buf_length, ex_buf_ptr-3) = u_toten))
543 then ex_buf_ptr := ex_buf_ptr - 3
544 else ex_buf_ptr := ex_buf_ptr - 4;
545 end;
546 @z
547
548 @x [384] Changes for JBibTeX by Shouichi Matsui for Zenkaku comma
549 "a", "A" :
550 begin
551 incr(ex_buf_ptr);
552 if (preceding_white) then
553 @<See if we have an ``and''@>; {if so, |and_found := true|}
554 preceding_white := false;
555 end;
556 @y
557 "a", "A" :
558 begin
559 incr(ex_buf_ptr);
560 if (preceding_white) then
561 @<See if we have an ``and''@>; {if so, |and_found := true|}
562 preceding_white := false;
563 end;
564 e_pun_first:
565 if (is_internalEUC) then
566 begin
567 if ((fromBUFF(ex_buf, ex_buf_length, ex_buf_ptr) = e_comma) or
568 (fromBUFF(ex_buf, ex_buf_length, ex_buf_ptr) = e_toten)) then
569 begin
570 preceding_white := false;
571 and_found := true
572 end
573 else if (fromBUFF(ex_buf,ex_buf_length,ex_buf_ptr) = e_space) then
574 begin
575 ex_buf[ex_buf_ptr] := space;
576 ex_buf[ex_buf_ptr+1] := space;
577 preceding_white := true;
578 end;
579 ex_buf_ptr := ex_buf_ptr + 2;
580 end else begin
581 ex_buf_ptr := ex_buf_ptr + multibytelen(ex_buf[ex_buf_ptr]);
582 preceding_white := false;
583 end;
584 u_pun_first1,
585 u_pun_first2:
586 if (is_internalUPTEX) then
587 begin
588 if ((fromBUFF(ex_buf, ex_buf_length, ex_buf_ptr) = u_comma) or
589 (fromBUFF(ex_buf, ex_buf_length, ex_buf_ptr) = u_toten)) then
590 begin
591 preceding_white := false;
592 and_found := true
593 end
594 else if (fromBUFF(ex_buf,ex_buf_length,ex_buf_ptr) = u_space) then
595 begin
596 ex_buf[ex_buf_ptr] := space;
597 ex_buf[ex_buf_ptr+1] := space;
598 ex_buf[ex_buf_ptr+2] := space;
599 preceding_white := true;
600 end;
601 ex_buf_ptr := ex_buf_ptr + 3;
602 end else begin
603 ex_buf_ptr := ex_buf_ptr + multibytelen(ex_buf[ex_buf_ptr]);
604 preceding_white := false;
605 end;
606 @z
607
608 @x [384] Changes for JBibTeX by Shouichi Matsui for Zenkaku comma
609 othercases
610 if (lex_class[ex_buf[ex_buf_ptr]] = white_space) then
611 begin
612 incr(ex_buf_ptr);
613 preceding_white := true;
614 end
615 else
616 begin
617 incr(ex_buf_ptr);
618 preceding_white := false;
619 end
620 endcases;
621 check_brace_level (pop_lit_var);
622 end;
623 @y
624 othercases
625 if (lex_class[ex_buf[ex_buf_ptr]] = white_space) then
626 begin
627 incr(ex_buf_ptr);
628 preceding_white := true;
629 end
630 else
631 begin
632 ex_buf_ptr := ex_buf_ptr + multibytelen(ex_buf[ex_buf_ptr]);
633 preceding_white := false;
634 end
635 endcases;
636 check_brace_level (pop_lit_var);
637 end;
638 @z
639
640 @x [415] Changes for JBibTeX by Shouichi Matsui
641 if (lex_class[name_buf[name_bf_ptr]] = alpha) then
642 begin
643 append_ex_buf_char_and_check (name_buf[name_bf_ptr]);
644 goto loop_exit;
645 end
646 else if ((name_buf[name_bf_ptr] = left_brace) and
647 @y
648 if (lex_class[name_buf[name_bf_ptr]] = alpha) then
649 begin
650 append_ex_buf_char_and_check (name_buf[name_bf_ptr]);
651 if multibytelen(name_buf[name_bf_ptr]) > 1 then
652 append_ex_buf_char_and_check (name_buf[name_bf_ptr+1]);
653 if multibytelen(name_buf[name_bf_ptr]) > 2 then
654 append_ex_buf_char_and_check (name_buf[name_bf_ptr+2]);
655 if multibytelen(name_buf[name_bf_ptr]) > 3 then
656 append_ex_buf_char_and_check (name_buf[name_bf_ptr+3]);
657 name_bf_ptr := name_bf_ptr + multibytelen(name_buf[name_bf_ptr])-1;
658 goto loop_exit;
659 end
660 else if ((name_buf[name_bf_ptr] = left_brace) and
661 @z
662
663 @x [422] x_int_to_chr
664 procedure x_int_to_chr;
665 begin
666 pop_lit_stk (pop_lit1,pop_typ1);
667 if (pop_typ1 <> stk_int) then
668 begin
669 print_wrong_stk_lit (pop_lit1,pop_typ1,stk_int);
670 push_lit_stk (s_null, stk_str);
671 end
672 else if ((pop_lit1 < 0) or (pop_lit1 > 127)) then
673 begin
674 bst_ex_warn (pop_lit1:0,' isn''t valid ASCII');
675 push_lit_stk (s_null, stk_str);
676 end
677 else
678 begin
679 str_room(1);
680 append_char (pop_lit1);
681 push_lit_stk (make_string, stk_str);
682 end;
683 end;
684 @y
685 procedure x_int_to_chr;
686 var k:integer;
687 begin
688 pop_lit_stk (pop_lit1,pop_typ1);
689 if (pop_typ1 <> stk_int) then
690 begin
691 print_wrong_stk_lit (pop_lit1,pop_typ1,stk_int);
692 push_lit_stk (s_null, stk_str);
693 end
694 else begin
695 k:=pop_lit1;
696 if (pop_lit1 > 127) then k:=fromDVI(pop_lit1);
697 if ((pop_lit1 < 0) or ((pop_lit1 > 127) and (k = 0))) then
698 begin
699 bst_ex_warn (pop_lit1:0,' isn''t valid character code');
700 push_lit_stk (s_null, stk_str);
701 end
702 else
703 begin
704 str_room(4);
705 k:=toBUFF(k);
706 if (BYTE1(k)>0) then
707 append_char (BYTE1(k));
708 if (BYTE2(k)>0) then
709 append_char (BYTE2(k));
710 if (BYTE3(k)>0) then
711 append_char (BYTE3(k));
712 { always }
713 append_char (BYTE4(k));
714 push_lit_stk (make_string, stk_str);
715 end;
716 end;
717 end;
718 @z
719
720 @x [437] Changes for JBibTeX by Shouichi Matsui
721 @<|execute_fn|({\.{substring\$}})@>=
722 procedure x_substring;
723 label exit;
724 begin
725 @y
726 @<|execute_fn|({\.{substring\$}})@>=
727 procedure x_substring;
728 label exit;
729 var tps,tpe:pool_pointer; {temporary pointer}
730 @!pop_lit2_saved,@!mbl_tpe: integer;
731 begin
732 @z
733
734 @x [438]
735 @<Form the appropriate substring@>=
736 begin
737 @y
738 @<Form the appropriate substring@>=
739 begin
740 pop_lit2_saved := pop_lit2; {save before negate}
741 @z
742
743 @x [438] 2023-04-08 texjporg/tex-jp-build#157
744 str_start[pop_lit3+1] := sp_end;
745 @y
746 { |2..4| bytes Kanji code break check }
747 tpe:=str_start[pop_lit3];
748 mbl_tpe:=0;
749 while tpe < str_start[pop_lit3+1] do begin
750 mbl_tpe := multibytelen(str_pool[tpe]);
751 if mbl_tpe<0 {just in case}
752 or (str_start[pop_lit3+1] < tpe+mbl_tpe) then
753 break;
754 tpe := tpe + mbl_tpe;
755 if sp_end<=tpe then break;
756 end;
757 str_start[pop_lit3+1] := tpe;
758 @z
759
760 @x [438] Changes for JBibTeX by Shouichi Matsui + fix (2022-02-20 j0.34)
761 str_room(sp_end - sp_ptr);
762 while (sp_ptr < sp_end) do {shift the substring}
763 begin
764 append_char (str_pool[sp_ptr]);
765 incr(sp_ptr);
766 end;
767 @y
768 { |2..4| bytes Kanji code break check }
769 tps:=str_start[pop_lit3];
770 tpe:=tps;
771 mbl_tpe:=0;
772 while tpe < str_start[pop_lit3+1] do begin
773 if multibytelen(str_pool[tpe])<0 {just in case}
774 or (str_start[pop_lit3+1] < tpe+multibytelen(str_pool[tpe])) then
775 break;
776 mbl_tpe := multibytelen(str_pool[tpe]);
777 tpe := tpe + mbl_tpe;
778 if tpe<=sp_ptr then
779 tps := tpe;
780 if sp_end<=tpe then break;
781 end;
782 if (pop_lit2_saved > 1) and (tps = str_start[pop_lit3]) then
783 if multibytelen(str_pool[tps])>=0 then {just in case}
784 tps := tps + multibytelen(str_pool[tps]); {truncate at least one}
785 if (pop_lit2_saved < -1) and (tpe = str_start[pop_lit3+1]) then
786 tpe := tpe - mbl_tpe; {truncate at least one}
787 if tps > tpe then tpe := tps;
788 sp_ptr := tps;
789 sp_end := tpe;
790
791 str_room(sp_end - sp_ptr);
792 while (sp_ptr < sp_end) do {shift the substring}
793 begin
794 append_char (str_pool[sp_ptr]);
795 incr(sp_ptr);
796 end;
797 @z
798
799 @x [445] Changes for JBibTeX by Shouichi Matsui
800 else if (str_pool[sp_xptr1-1] = right_brace) then
801 begin
802 if (sp_brace_level > 0) then
803 decr(sp_brace_level);
804 end
805 else
806 incr(num_text_chars);
807 end;
808 @y
809 else if (str_pool[sp_xptr1-1] = right_brace) then
810 begin
811 if (sp_brace_level > 0) then
812 decr(sp_brace_level);
813 end
814 else if (str_pool[sp_xptr1-1]>127) then
815 begin {kanji char}
816 num_text_chars := num_text_chars + multibytelen(str_pool[sp_xptr1-1]);
817 sp_xptr1 := sp_xptr1-1 + multibytelen(str_pool[sp_xptr1-1]);
818 end
819 else
820 incr(num_text_chars);
821 end;
822 @z
823
824 @x [467]
825 const n_options = 4; {Pascal won't count array lengths for us.}
826 @y
827 const n_options = 9; {Pascal won't count array lengths for us.}
828 @z
829
830 @x [467]
831 usage_help (BIBTEX_HELP, nil);
832 @y
833 usage_help (UPBIBTEX_HELP, 'issue@@texjp.org');
834 @z
835
836 @x [467]
837 end; {Else it was a flag; |getopt| has already done the assignment.}
838 @y
839 end else if argument_is ('kanji') then begin
840 if (not set_enc_string(optarg, nil)) then
841 write_ln('Bad kanji encoding "', stringcast(optarg), '".');
842
843 end else if argument_is ('guess-input-enc') then begin
844 enable_guess_file_enc;
845
846 end else if argument_is ('no-guess-input-enc') then begin
847 disable_guess_file_enc;
848
849 end else if argument_is ('kanji-internal') then begin
850 if (not (set_enc_string(nil,optarg) and
851 (is_internalEUC or is_internalUPTEX))) then
852 write_ln('Bad internal kanji encoding "', stringcast(optarg), '".');
853
854 end; {Else it was a flag; |getopt| has already done the assignment.}
855 @z
856
857 @x New sections [476] and [477]
858 @ An element with all zeros always ends the list.
859 @y
860 @ Kanji option.
861 @.-kanji@>
862
863 @<Define the option...@> =
864 long_options[current_option].name := 'kanji';
865 long_options[current_option].has_arg := 1;
866 long_options[current_option].flag := 0;
867 long_options[current_option].val := 0;
868 incr(current_option);
869 long_options[current_option].name := 'guess-input-enc';
870 long_options[current_option].has_arg := 0;
871 long_options[current_option].flag := 0;
872 long_options[current_option].val := 0;
873 incr(current_option);
874 long_options[current_option].name := 'no-guess-input-enc';
875 long_options[current_option].has_arg := 0;
876 long_options[current_option].flag := 0;
877 long_options[current_option].val := 0;
878 incr(current_option);
879
880 @ Kanji-internal option.
881 @.-kanji-internal@>
882
883 @<Define the option...@> =
884 long_options[current_option].name := 'kanji-internal';
885 long_options[current_option].has_arg := 1;
886 long_options[current_option].flag := 0;
887 long_options[current_option].val := 0;
888 incr(current_option);
889
890 @ An element with all zeros always ends the list.
891 @z
892
893 @x Shifted section [479]
894 begin kpse_set_program_name (argv[0], 'bibtex');
895 @y
896 begin kpse_set_program_name (argv[0], 'upbibtex');
897 @z
898
899 @x Shifted Index section [484]
900 @* Index.
901 @y
902 @ Modules for JBibTeX.
903
904 @<|execute_fn|({\.{is.kanji.str\$}})@>=
905 procedure x_is_kanji_str;
906 label exit;
907 var ctmp,clen:integer;
908 begin
909 pop_lit_stk(pop_lit1, pop_typ1);
910 if pop_typ1<> stk_str then
911 begin print_wrong_stk_lit(pop_lit1,pop_typ1,stk_str);
912 push_lit_stk(0,stk_int);
913 end else begin
914 sp_ptr := str_start[pop_lit1];
915 sp_end := str_start[pop_lit1+1];
916 while sp_ptr<sp_end do begin
917 clen := multibytelen(str_pool[sp_ptr]);
918 if sp_ptr+clen<=sp_end then
919 ctmp := fromBUFF(str_pool, sp_ptr+clen, sp_ptr)
920 else
921 ctmp := str_pool[sp_ptr];
922 if is_char_kanji_upbibtex(ctmp) then begin
923 push_lit_stk(1,stk_int);
924 return;
925 end else begin
926 if sp_ptr+clen<=sp_end then
927 sp_ptr := sp_ptr + clen
928 else
929 incr(sp_ptr);
930 end;
931 end;
932 push_lit_stk(0,stk_int);
933 end;
934 exit:end;
935
936 @ @<Procedures and functions for handling numbers, characters, and strings@>=
937 function is_char_kanji_upbibtex(@!c:integer):boolean;
938 label exit;
939 var k:integer;
940 begin
941 { based on upTeX-1.35 kcatcode status: 16,17,19->true / 15,18->false }
942 is_char_kanji_upbibtex := true;
943 if (is_internalUPTEX) then begin { should be in sync with |kcat_code| of uptex-m.ch }
944 k := kcatcodekey(c);
945 if k=@"25 then return { Hangul Jamo }
946 else if (k>=@"68)and(k<=@"69) then return { CJK Radicals Supplement, Kangxi Radicals }
947 else if (k>=@"6C)and(k<=@"6D) then return { Hiragana, Katakana }
948 else if k=@"6E then return { Bopomofo }
949 else if k=@"6F then return { Hangul Compatibility Jamo }
950 else if (k>=@"70)and(k<=@"72) then return { Kanbun .. CJK Strokes }
951 else if k=@"73 then return { Katakana Phonetic Extensions }
952 else if k=@"76 then return { CJK Unified Ideographs Extension A }
953 else if k=@"78 then return { CJK Unified Ideographs }
954 else if k=@"88 then return { Hangul Jamo Extended-A }
955 else if k=@"93 then return { Hangul Syllables }
956 else if k=@"94 then return { Hangul Jamo Extended-B }
957 else if k=@"99 then return { CJK Compatibility Ideographs }
958 else if (k>=@"11A)and(k<=@"11D) then return { Kana Extended-B .. Small Kana Extension }
959 else if (k>=@"14C)and(k<=@"156) then return { CJK Unified Ideographs Extension B .. J }
960 else if k=@"1FE then return { Fullwidth digit and latin alphabet }
961 else if k=@"1FF then return; { Halfwidth katakana }
962 end
963 else { |is_internalEUC| }
964 if is_char_kanji(c) then return;
965 is_char_kanji_upbibtex := false;
966 exit:end;
967
968 @ @<Initialize variables depending on Kanji code@>=
969 if (is_internalUPTEX) then
970 begin
971 for i:=@"80 to @"BF do lex_class[i] := alpha; { trail bytes }
972 for i:=@"C0 to @"C1 do lex_class[i] := illegal;
973 for i:=@"C2 to @"F4 do lex_class[i] := alpha; { lead bytes }
974 for i:=@"F5 to @"FF do lex_class[i] := illegal;
975 for i:=@"C0 to @"C1 do id_class[i] := illegal_id_char;
976 for i:=@"F5 to @"FF do id_class[i] := illegal_id_char;
977 for i:=@"80 to @"BF do char_width[i]:=257; { trail bytes }
978 for i:=@"C2 to @"DF do char_width[i]:=771; { lead bytes (2bytes) }
979 for i:=@"E0 to @"EF do char_width[i]:=514; { lead bytes (3bytes) }
980 for i:=@"F0 to @"F4 do char_width[i]:=257; { lead bytes (4bytes) }
981 end
982 else
983 begin { |is_internalEUC| }
984 for i:=@'200 to @'240 do lex_class[i] := illegal;
985 for i:=@'241 to 254 do lex_class[i] := alpha;
986 lex_class[255]:=illegal;
987 for i:=@'200 to @'240 do id_class[i] := illegal_id_char;
988 id_class[255]:=illegal_id_char;
989 lex_class[@'33]:=alpha;
990 lex_class[e_ss3]:=alpha;
991 for i:=@'241 to 254 do char_width[i]:=514;
992 char_width[e_ss3]:=0;
993 end;
994
995 @* Index.
996 @z