Skip to content

Commit

Permalink
uptex-{euc,sjis}: filename code conversion (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-tk committed Dec 16, 2022
1 parent ad87500 commit 028bb2b
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 1 deletion.
21 changes: 21 additions & 0 deletions source/texk/ptexenc/ptexenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,10 @@ void clear_infile_enc(FILE *fp)
{
infile_enc[fileno(fp)] = ENC_UNKNOWN;
}
long ptencconvfirstline(long pos, long last, unsigned char *buff, const long buffsize)
{
return last;
}
#else /* !WIN32 */
static const_string in_filter = NULL;
static FILE *piped_fp[NOFILE];
Expand Down Expand Up @@ -1361,4 +1365,21 @@ int ptenc_get_command_line_args(int *p_ac, char ***p_av)
return 0;
}

long ptencconvfirstline(long pos, long last, unsigned char *buff, const long buffsize)
/* return new last */
{
unsigned char *old, *new_buf; long new_last, i;
if (internal_enc==ENC_UPTEX) return last; /* no conversion needed */
old = xmalloc(last-pos+2);
if (old==NULL) return last;
strncpy(old, buff+pos, last-pos+1); old[last-pos+1]='\0';
new_buf = ptenc_from_utf8_string_to_internal_enc(old);
if (new_buf==NULL) { free(old); return last; }
new_last=pos+strlen(new_buf)-1;
if (new_last>=buffsize) new_last=buffsize-1;
for (i=0;i<strlen(new_buf); i++) buff[pos+i]=new_buf[i];
free(old); free(new_buf);
return new_last;
}

#endif /* !WIN32 */
1 change: 1 addition & 0 deletions source/texk/ptexenc/ptexenc/ptexenc.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,6 @@ extern PTENCDLL unsigned char *ptenc_from_utf8_string_to_internal_enc(const unsi
extern PTENCDLL unsigned char *ptenc_from_internal_enc_string_to_utf8(const unsigned char *is);
extern PTENCDLL int ptenc_get_command_line_args(int *p_ac, char ***p_av);
#endif
extern PTENCDLL long ptencconvfirstline(long pos, long limit, unsigned char *buff, const long buffsize);

#endif /* PTEXENC_PTEXENC_H */
1 change: 1 addition & 0 deletions source/texk/web2c/eptexdir/eptex.defines
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
@define function putc2 ();
@define function fputs2 ();
@define function inputline2 ();
@define function ptencconvfirstline ();

@define function setinfileenc ();
@define function setstdinenc ();
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 @@ -28,6 +28,7 @@
@define function putc2 ();
@define function fputs2 ();
@define function inputline2 ();
@define function ptencconvfirstline ();

@define function setinfileenc ();
@define function setstdinenc ();
Expand Down
33 changes: 32 additions & 1 deletion source/texk/web2c/lib/texmfmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -849,8 +849,10 @@ maininit (int ac, string *av)
enc = kpse_var_value("command_line_encoding");
get_command_line_args_utf8(enc, &argc, &argv);
#endif

#if IS_pTeX && !IS_upTeX && !defined(WIN32)
ptenc_get_command_line_args(&argc, &argv);
fprintf(stderr, "maininit: %d\n", get_internal_enc());
// ptenc_get_command_line_args(&argc, &argv);
#endif

/* If the user says --help or --version, we need to notice early. And
Expand Down Expand Up @@ -1016,7 +1018,14 @@ maininit (int ac, string *av)
/* If run like `tex \&foo', reasonable to guess "foo" as the fmt name. */
if (!main_input_file) {
if (argv[1] && *argv[1] == '&') {
#if IS_pTeX && !defined(WIN32)
string new_arg;
is_terminalUTF8(); /* To call get_terminal_enc(). return value is not used */
new_arg = ptenc_from_utf8_string_to_internal_enc(argv[1]);
dump_name = argv[1] + 1; argv[1] = new_arg;
#else
dump_name = argv[1] + 1;
#endif
}
}

Expand Down Expand Up @@ -1056,12 +1065,25 @@ maininit (int ac, string *av)
unsigned ext_len = strlen (DUMP_EXT);

/* Provide extension if not there already. */
#if IS_pTeX && !defined(WIN32)
string new_dump_name;
is_terminalUTF8(); /* To call get_terminal_enc(). return value is not used */
new_dump_name = ptenc_from_utf8_string_to_internal_enc(dump_name);
if (!new_dump_name) new_dump_name = (string)dump_name;
if (name_len > ext_len
&& FILESTRCASEEQ (dump_name + name_len - ext_len, DUMP_EXT)) {
with_ext = new_dump_name;
} else {
with_ext = concat(new_dump_name, DUMP_EXT);
}
#else
if (name_len > ext_len
&& FILESTRCASEEQ (dump_name + name_len - ext_len, DUMP_EXT)) {
with_ext = dump_name;
} else {
with_ext = concat (dump_name, DUMP_EXT);
}
#endif
DUMP_VAR = concat (" ", with_ext); /* adjust array for Pascal */
DUMP_LENGTH_VAR = strlen (DUMP_VAR + 1);
} else {
Expand Down Expand Up @@ -3095,7 +3117,16 @@ getjobname(strnumber name)
{
strnumber ret = name; int i, l, p;
if (c_job_name != NULL)
#if IS_pTeX && !defined(WIN32)
{
string new_job_name;
is_terminalUTF8();
new_job_name = ptenc_from_utf8_string_to_internal_enc(c_job_name);
ret = maketexstring(new_job_name? new_job_name : c_job_name);
}
#else
ret = maketexstring(c_job_name);
#endif
#if IS_pTeX
i = strstart[ret]; l = strstart[ret+1];
while (i<l)
Expand Down
15 changes: 15 additions & 0 deletions source/texk/web2c/ptexdir/ptex-base.ch
Original file line number Diff line number Diff line change
Expand Up @@ -6861,6 +6861,21 @@ undump_things(char_base[null_font], font_ptr+1-null_font);
font_info:=xmalloc_array (memory_word, font_mem_size);
@z
@x -- DEBUG!
fix_date_and_time;@/
@y
last:=ptenc_conv_first_line(loc, last, buffer, buf_size);
{ print_nl("debug 1st line "); print_int(loc); print(" ");
for k:=0 to last do begin
if k=loc then print(">");
if (buffer[k]<@"20)or(buffer[k]>@"7e) then
begin print("["); print_hex(buffer[k]); print("]"); end
else print(buffer[k]);
end;
print_nl(""); }
fix_date_and_time;@/
@z
@x [51.1337] l.25563 - pTeX:
font_check:=xmalloc_array(four_quarters, font_max);
@y
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 @@ -21,6 +21,7 @@
@define function putc2 ();
@define function fputs2 ();
@define function inputline2 ();
@define function ptencconvfirstline ();

@define function fromJIS ();
@define function fromEUC ();
Expand Down
1 change: 1 addition & 0 deletions source/texk/web2c/uptexdir/uptex.defines
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
@define function putc2 ();
@define function fputs2 ();
@define function inputline2 ();
@define function ptencconvfirstline ();

@define function fromJIS ();
@define function fromEUC ();
Expand Down

0 comments on commit 028bb2b

Please sign in to comment.