From 3e60c3fd9519be494abd6d85f2e368798cec88b1 Mon Sep 17 00:00:00 2001 From: Andreas Scherer Date: Sat, 15 Jun 2024 09:19:04 +0000 Subject: [PATCH] [WEB] Output '@x' with optional information. 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 --- texk/web2c/ChangeLog | 5 +++ texk/web2c/dvicopy.ch | 24 +++++----- texk/web2c/tests/fix-changefile-lines.py | 56 ++++++++++++++++++++---- 3 files changed, 65 insertions(+), 20 deletions(-) diff --git a/texk/web2c/ChangeLog b/texk/web2c/ChangeLog index 025a70eb69..543468fd74 100644 --- a/texk/web2c/ChangeLog +++ b/texk/web2c/ChangeLog @@ -1,3 +1,8 @@ +2024-06-15 Andreas Scherer + + * tests/fix-changefile-lines.py, + * dvicopy.ch: Output '@x' with optional information. + 2024-06-05 Andreas Scherer * tests/fix-changefile-lines.py, diff --git a/texk/web2c/dvicopy.ch b/texk/web2c/dvicopy.ch index 7ae1ecba2e..6e3a35fe69 100644 --- a/texk/web2c/dvicopy.ch +++ b/texk/web2c/dvicopy.ch @@ -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 @@ -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} @@ -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} @@ -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|} @@ -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 @@ -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); @@ -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 " +# 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) @@ -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]: