Skip to content

Commit

Permalink
[WEB] Output '@x' with optional information.
Browse files Browse the repository at this point in the history
E.g., 'fix-changefile-lines -hlp dvicopy.{wen,ch}' prints only
'@x [section] text' lines. ('[137/138]' was replaced with '[137]'.)

git-svn-id: svn://tug.org/texlive/trunk/Build/source@71530 c570f23f-e606-0410-a88d-b1316a301751
  • Loading branch information
Andreas Scherer committed Jun 15, 2024
1 parent 959a305 commit 3e60c3f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 20 deletions.
5 changes: 5 additions & 0 deletions texk/web2c/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2024-06-15 Andreas Scherer <https://ascherer.github.io>

* tests/fix-changefile-lines.py,
* dvicopy.ch: Output '@x' with optional information.

2024-06-05 Andreas Scherer <https://ascherer.github.io>

* tests/fix-changefile-lines.py,
Expand Down
24 changes: 12 additions & 12 deletions texk/web2c/dvicopy.ch
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ calls the `|jump_out|' procedure, which goes to the label |final_end|.
@y
calls the `|jump_out|' procedure.
@z
@x
@x [3]
label final_end;
@y
@z
Expand Down Expand Up @@ -85,7 +85,7 @@ procedure initialize; {this procedure gets things started properly}
% [7] Rename the integer types, as they collide with names used by C99.
% Rather than change the code all over the place, we use macros to do
% the renaming. This could also be done at C preprocessor level.
@x
@x [7]
@d int_32 == integer {signed 32~bit integers}
@y
@d int_32 == integer {signed 32~bit integers}
Expand All @@ -103,7 +103,7 @@ procedure initialize; {this procedure gets things started properly}
% [11] Redirect output, so it can go to either stdout or stderr,
% depending on where the output dvi file is going.
@x
@x [11]
@d print(#)==write(output,#)
@d print_ln(#)==write_ln(output,#)
@d new_line==write_ln(output) {start new line}
Expand All @@ -122,7 +122,7 @@ procedure initialize; {this procedure gets things started properly}
% [15] The text_char type is used as an array index into xord. The
% default type `char' produces signed integers, which are bad array
% indices in C.
@x
@x [15]
@d text_char == char {the data type of characters in text files}
@d first_text_char=0 {ordinal number of the smallest element of |text_char|}
@d last_text_char=127 {ordinal number of the largest element of |text_char|}
Expand All @@ -143,7 +143,7 @@ by a call on some system procedure that quietly terminates the program.
@y
so a procedure called |jump_out| has been introduced.
@z
@x
@x [23]
@d abort(#)==begin print_ln(' ',#,'.'); jump_out;
end

Expand Down Expand Up @@ -175,7 +175,7 @@ says |confusion(|indication of where we are|)|.
@y
says |confusion|(indication of where we are).
@z
@x
@x [24]
procedure confusion(@!p:pckt_pointer);
@y
noreturn procedure confusion(@!p:pckt_pointer);
Expand Down Expand Up @@ -229,24 +229,24 @@ to |make_font_name|.

% [67] No conversion of filenames in lower case, and initialize and
% terminate for C strings. Eliminate now unused variable.
@x
@x [67]
@!c:char; {a character to be appended to |cur_name|}
@y
@z

@x
@x [67]
cur_loc:=pckt_start[n]; cur_limit:=pckt_start[n+1];
@y
cur_name := xmalloc_array (char, pckt_length (n) + pckt_length (e));
cur_loc:=pckt_start[n]; cur_limit:=pckt_start[n+1];
@z

@x
@x [67]
if (b>="a")and(b<="z") then Decr(b)(("a"-"A")); {convert to upper case}
@y
@z

@x
@x [67]
cur_loc:=pckt_start[e]; cur_limit:=pckt_start[e+1];
while cur_loc<cur_limit do
begin pckt_extract(b); append_res_to_name(xchr[b]);
Expand Down Expand Up @@ -380,7 +380,7 @@ id3(".")("V")("F")(vf_ext); {file name extension for \.{VF} files}
id3(".")("v")("f")(vf_ext); {file name extension for \.{VF} files}
@z
@x [137/138] Set default directory name
@x [137] Set default directory name
@ If no font directory has been specified, \.{\title} is supposed to use
the default \.{VF} directory, which is a system-dependent place where
the \.{VF} files for standard fonts are kept.
Expand Down Expand Up @@ -488,7 +488,7 @@ end;
dialog; {get options}
@y
@z
@x
@x [241]
final_end:end.
@y
end.
Expand Down
56 changes: 48 additions & 8 deletions texk/web2c/tests/fix-changefile-lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,49 @@
potentially corrected part, section and line numbers.
Written by Tyge Tiessen, 2024. Public domain.
"""
import getopt
import re
import sys

USAGE = f"{sys.argv[0]} <web file> <change file>"

# Optional elements of "@x [{part}.{section}] l.{line} {-(hyphen)} {text}
part_b, section_b, line_b, hyphen_b, text_b = True, True, True, True, True


def main():
if len(sys.argv) != 3:
try:
opts, args = getopt.getopt(sys.argv[1:], "pslht",
["parts", "sections", "lines", "hyphens", "texts"])
except getopt.GetoptErr as err:
print(USAGE)
sys.exit(1)

global part_b, section_b, line_b, hyphen_b, text_b

for opt, _ in opts:
if opt in ("-p", "--parts"):
part_b = False
elif opt in ("-s", "--sections"):
section_b = False
elif opt in ("-l", "--lines"):
line_b = False
elif opt in ("-h", "--hyphens"):
hyphen_b = False
elif opt in ("-t", "--texts"):
text_b = False
else:
assert False, f"Unhandled option {opt}"

if len(args) != 2:
print(USAGE)
sys.exit(1)

# Read WEB file
web_reader = WebReader(sys.argv[1])
web_reader = WebReader(args[0])

# Read change file
ch_reader = ChangeReader(sys.argv[2])
ch_reader = ChangeReader(args[1])

# Run through the two files in parallel
ch_reader.traverse(web_reader)
Expand Down Expand Up @@ -189,11 +216,24 @@ def traverse(self, web_reader):
if re.match(pattern, text):
text = re.sub(pattern, "", text, 1).strip()

# Create line with standard tag.
new_line = f"@x [{part}.{section}] l.{line_number}"

if text:
new_line += f" - {text}"
# Create line with standard tag and optional information.
new_line = f"@x"
if part_b or section_b:
new_line += f" ["
if part_b:
new_line += f"{part}"
if part_b and section_b:
new_line += f"."
if section_b:
new_line += f"{section}"
new_line += f"]"
if line_b:
new_line += f" l.{line_number}"

if text_b and text:
if hyphen_b:
new_line += f" -"
new_line += f" {text}"

ch_line = self._lines[self._chunk_start]
if new_line[:10] != ch_line[:10]:
Expand Down

0 comments on commit 3e60c3f

Please sign in to comment.