Skip to content

Commit

Permalink
treatment of filenames (ticket 125)
Browse files Browse the repository at this point in the history
 * string which represents filename does not expect to have
   "Japanese character" flag 0x100,
 * slow_print_filename and (rewrited) print_quoted both prints
   a string which represents filename.
    - slow_print_filename assumes that no kanji code conversion is required
    - print_quoted both prints assumes that code conversion should be performed
  • Loading branch information
h-kitagawa committed Oct 1, 2021
1 parent 9531158 commit 00b6c07
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 34 deletions.
18 changes: 18 additions & 0 deletions source/texk/ptexenc/ptexenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,24 @@ int multistrlen ## SUFF(TYPE *s, int len, int pos) \
DEFINE_MULTISTRLEN(,unsigned char);
DEFINE_MULTISTRLEN(short,unsigned short);

/* for outputting filename (*s) to the terminal */
int multistrlenfilename(unsigned short *s, int len, int pos)
{
s += pos; len -= pos;
if (terminal_enc == ENC_UTF8) {
int ret = UTF8Slengthshort(s, len);
if (ret < 0) return 1;
return ret;
}
if (len < 2) return 1;
if (terminal_enc == ENC_SJIS) {
if (isSJISkanji1(s[0]) && isSJISkanji2(s[1])) return 2;
} else { /* EUC */
if (isEUCkanji1(s[0]) && isEUCkanji2(s[1])) return 2;
}
return 1;
}

/* with not so strict range check */
int multibytelen (int first_byte)
{
Expand Down
3 changes: 3 additions & 0 deletions source/texk/ptexenc/ptexenc/ptexenc.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ extern PTENCDLL long fromBUFF(unsigned char *s, int len, int pos);
extern PTENCDLL long fromBUFFshort(unsigned short *s, int len, int pos);
extern PTENCDLL long toBUFF(long inter);

/* for outputting filename (*s) to the terminal */
extern PTENCDLL int multistrlenfilename(unsigned short *s, int len, int pos);

/* internal (EUC/SJIS/UPTEX) from/to DVI (JIS/UCS) code conversion */
extern PTENCDLL long toDVI (long kcode);
extern PTENCDLL long fromDVI (long kcode);
Expand Down
1 change: 1 addition & 0 deletions source/texk/web2c/eptexdir/eptex.defines
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@define function iskanji1 ();
@define function multistrlen ();
@define function multistrlenshort ();
@define function multistrlenfilename ();
@define function fromBUFF ();
@define function fromBUFFshort ();
@define function toBUFF ();
Expand Down
1 change: 1 addition & 0 deletions source/texk/web2c/euptexdir/euptex.defines
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

@define function multistrlen ();
@define function multistrlenshort ();
@define function multistrlenfilename ();
@define function fromBUFF ();
@define function fromBUFFshort ();
@define function toBUFF ();
Expand Down
14 changes: 12 additions & 2 deletions source/texk/web2c/lib/texmfmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3040,7 +3040,7 @@ maketexstring(const_string s)
}
#else /* ! XeTeX */
while (len-- > 0)
strpool[poolptr++] = *s++;
strpool[poolptr++] = 0xFF&(*s++);
#endif /* ! XeTeX */

return makestring();
Expand All @@ -3058,9 +3058,19 @@ makefullnamestring(void)
strnumber
getjobname(strnumber name)
{
strnumber ret = name;
strnumber ret = name; int i, l, p;
if (c_job_name != NULL)
ret = maketexstring(c_job_name);
#ifdef IS_pTeX
i = strstart[ret]; l = strstart[ret+1];
while (i<l)
{
p = multistrlenshort(strpool, l, i);
if (p>1)
for (int j=i+p; i<j; i++) strpool[i] = (0xFF&strpool[i])+0x100;
else i++;
}
#endif /* IS_pTeX */
return ret;
}
#endif
Expand Down
56 changes: 45 additions & 11 deletions source/texk/web2c/ptexdir/ptex-base.ch
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,40 @@ else begin j:=str_start[s];
end;
end;
end;
procedure slow_print_filename(@!s:integer);
{prints string |s| which represents filename, without code conversion}
var i,j,l:pool_pointer; p:integer;
begin if (s>=str_ptr) or (s<256) then print(s)
else begin i:=str_start[s]; l:=str_start[s+1];
while i<l do begin
p:=multistrlenfilename(str_pool, l, i);
if p<>1 then
begin for j:=i to i+p-1 do print_char(so(str_pool[j]));
i:=i+p; end
else begin print(so(str_pool[i])); incr(i); end;
end;
end;
end;
procedure print_quoted(@!s:integer);
{prints string |s| which represents filename,
omitting quotes and with code covversion}
var i,l:pool_pointer; j,p:integer;
begin if s<>0 then begin
i:=str_start[s]; l:=str_start[s+1];
while i<l do begin
p:=multistrlenshort(str_pool, l, i);
if p<>1 then begin
for j:=i to i+p-1 do print_char(@"100+so(str_pool[j]));
i:=i+p; end
else begin
if so(str_pool[i])<>"""" then print(so(str_pool[i]));
incr(i); end;
end;
end;
end;

@z

@x [5.61] l.1656 - pTeX:
Expand Down Expand Up @@ -2808,30 +2842,22 @@ else begin str_room(1); append_char(c); {contribute |c| to the current string}
end;
@z
@x [29.518] - print_quoted in pTeX: file name is always printed with code conversion
@x [29.518] - print_quoted in pTeX is already defined
@d print_quoted(#) == {print string |#|, omitting quotes}
if #<>0 then
for j:=str_start[#] to str_start[#+1]-1 do
if so(str_pool[j])<>"""" then
print(so(str_pool[j]))
@y
@d print_quoted(#) == {print string |#|, omitting quotes}
if #<>0 then
for j:=str_start[#] to str_start[#+1]-1 do
if so(str_pool[j])<>"""" then
begin
if so(str_pool[j])>=@"100 then print_char(so(str_pool[j]))
else print(so(str_pool[j])); end
@z
@x
@d append_to_name(#)==begin c:=#; if not (c="""") then begin incr(k);
if k<=file_name_size then name_of_file[k]:=xchr[c];
end end
@y
@d append_to_name(#)==begin if (#)>=@"100 then c:=(#)-256 else c:=#;
@d append_to_name(#)==begin if (#)>=@"100 then c:=(#)-@"100 else c:=#;
{ Since the type of |c| is |ASCII_code|, above if-statement might not be needed }
if not (c="""") then begin incr(k);
if k<=file_name_size then name_of_file[k]:=xchr[c];
Expand Down Expand Up @@ -2901,6 +2927,14 @@ else
wlog(')');
@z
@x [29.???] pTeX - start_input
print_char("("); incr(open_parens);
slow_print(full_source_filename_stack[in_open]); update_terminal;
@y
print_char("("); incr(open_parens);
slow_print_filename(full_source_filename_stack[in_open]); update_terminal;
@z
@x [30.560] l.10968 - pTeX:
This is called BigEndian order.
@!@^BigEndian order@>
Expand Down Expand Up @@ -7824,7 +7858,7 @@ are part of Japaense characters when the procedure is called.
@<Basic printing...@>=
procedure print_unread_buffer_with_ptenc(@!f, @!l: integer);
{ print |buffer[f..l-1]| with code conversion }
var @!i,@!j,@!p: integer;
var @!i,@!j: pool_pointer; @!p: integer;
begin
i:=f;
while i<l do begin
Expand Down
1 change: 1 addition & 0 deletions source/texk/web2c/ptexdir/ptex.defines
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@define function iskanji1 ();
@define function multistrlen ();
@define function multistrlenshort ();
@define function multistrlenfilename ();
@define function fromBUFF ();
@define function fromBUFFshort ();
@define function toBUFF ();
Expand Down
40 changes: 40 additions & 0 deletions source/texk/web2c/ptexdir/tests/filename_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
cat <<'EOF' > filename_日本語.tex
% UTF-8 encoding
\def\TEST#1{\ifx#1\relax\else\immediate\write16{[\meaning#1]}\expandafter\TEST\fi}
\expandafter\TEST\jobname\relax
\immediate\openout0=\jobname.txt
\immediate\write0{日本語}
\immediate\closeout0
\openin0=\jobname.txt
\ifeof0
\immediate\write16{File `\jobname.txt' not found.}
\else
\read0 to \TEXT
\immediate\write16{TEXT=\TEXT}
\fi
\closein0
\input \jobname.txt
\end
EOF

ln -s filename_日本語.tex "filename_日本a.tex"
eptex "\input {filename_日本a}"
euptex "\input {filename_日本a}"
ls "filename_日本a".*
rm "filename_日本a".*
ln -s filename_日本語.tex filename_日本ßſa.tex
euptex filename_日本ßſa
ls filename_日本ßſa.*
rm filename_日本ßſa.*

eptex "-jobname=漢ßſa" filename_日本語
ls 漢*; rm 漢*
euptex "-jobname=漢ßſa" filename_日本語
ls 漢*; rm 漢*
rm filename_日本語.tex
21 changes: 0 additions & 21 deletions source/texk/web2c/ptexdir/tests/filename_日本語.tex

This file was deleted.

1 change: 1 addition & 0 deletions source/texk/web2c/uptexdir/uptex.defines
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

@define function multistrlen ();
@define function multistrlenshort ();
@define function multistrlenfilename ();
@define function multibytelen ();
@define function fromBUFF ();
@define function fromBUFFshort ();
Expand Down

0 comments on commit 00b6c07

Please sign in to comment.