texlive[71613] Build/source/texk/web2c: Simplify

commits+ascherer at tug.org commits+ascherer at tug.org
Mon Jun 24 10:15:10 CEST 2024


Revision: 71613
          https://tug.org/svn/texlive?view=revision&revision=71613
Author:   ascherer
Date:     2024-06-24 10:15:10 +0200 (Mon, 24 Jun 2024)
Log Message:
-----------
Simplify 'fix-changefile-lines.py' script.

"In every large program there's a small one struggling to get out."

Back to basics (Thanks, Tyge!), with just enough flexibility. In this
reduced form, 'f-c-l' handles 'tex.ch', 'ctie-k.ch', 'tie-w2c.ch',
'weave.ch' and the whole slew of CWEB's '*-w2c.ch' monsters correctly.

Plus it corrects a few tags in 'bibtex.ch' just for fun.

Modified Paths:
--------------
    trunk/Build/source/texk/web2c/ChangeLog
    trunk/Build/source/texk/web2c/bibtex.ch
    trunk/Build/source/texk/web2c/tests/fix-changefile-lines.py

Modified: trunk/Build/source/texk/web2c/ChangeLog
===================================================================
--- trunk/Build/source/texk/web2c/ChangeLog	2024-06-24 07:30:49 UTC (rev 71612)
+++ trunk/Build/source/texk/web2c/ChangeLog	2024-06-24 08:15:10 UTC (rev 71613)
@@ -1,3 +1,8 @@
+2024-06-24  Andreas Scherer  <https://ascherer.github.io>
+
+	* tests/fix-changefile-lines.py,
+	* bibtex.ch: Update a few tags.
+
 2024-06-15  Andreas Scherer  <https://ascherer.github.io>
 
 	* tests/fix-changefile-lines.py,

Modified: trunk/Build/source/texk/web2c/bibtex.ch
===================================================================
--- trunk/Build/source/texk/web2c/bibtex.ch	2024-06-24 07:30:49 UTC (rev 71612)
+++ trunk/Build/source/texk/web2c/bibtex.ch	2024-06-24 08:15:10 UTC (rev 71613)
@@ -1054,7 +1054,7 @@
 % [141] Don't pad with blanks, terminate with null.
 % Don't use a path to search for subsidiary aux files,
 % but do check the directory of the main .aux file.
-% 
+%
 % This last is useful, for example, when --output-dir is used with TeX and the
 % .aux file has an \@input directive resulting from a LaTeX \include;
 % see bibtex-auxinclude.test. It's necessary because BibTeX itself does
@@ -1065,7 +1065,7 @@
 % changing the add_extension function to look for those overrides to the
 % aux file dirname, so that when we call kpse_*_name_ok below, we're
 % calling it on the actual file that will be used.
-% 
+%
 % And we need to call kpse_*_name_ok because bibtex is included in the
 % shell_escape_commands list that can be invoked by TeX in restricted mode.
 %
@@ -1299,7 +1299,7 @@
 @!cite_info : ^str_number; {extra |cite_list| info}
 @z
 
- at x [224] Be silent unless verbose.
+ at x [223] Be silent unless verbose.
     print ('Database file #',bib_ptr+1:0,': ');
     print_bib_name;@/
 @y
@@ -1445,7 +1445,7 @@
     x_entry_strs(str_ent_ptr)(0) := end_of_string;
 @z
 
- at x [291] Dynamic lit_stk_size.
+ at x [290] Dynamic lit_stk_size.
 @!lit_stack : array[lit_stk_loc] of integer;    {the literal function stack}
 @!lit_stk_type : array[lit_stk_loc] of stk_type; {their corresponding types}
 @y
@@ -1478,7 +1478,7 @@
     end;
 @z
 
- at x [320] Dynamic buf_size.
+ at x [322] Dynamic buf_size.
 if (out_buf_length+(p_ptr2-p_ptr1) > buf_size) then
     overflow('output buffer size ',buf_size);
 @y
@@ -1494,7 +1494,7 @@
         confusion ('field_info index is out of range');
 @z
 
- at x [330] Macroize entry_strs[][]
+ at x [329] Macroize entry_strs[][]
     while (entry_strs[str_ent_ptr][ex_buf_ptr] <> end_of_string) do
                                         {copy characters into the buffer}
         append_ex_buf_char (entry_strs[str_ent_ptr][ex_buf_ptr]);
@@ -1622,7 +1622,7 @@
 @z
 
 % emacs-page
- at x [468] System-dependent changes.
+ at x [467] System-dependent changes.
 This section should be replaced, if necessary, by changes to the program
 that are necessary to make \BibTeX\ work at a particular installation.
 It is usually best to design your change file so that all changes to

Modified: trunk/Build/source/texk/web2c/tests/fix-changefile-lines.py
===================================================================
--- trunk/Build/source/texk/web2c/tests/fix-changefile-lines.py	2024-06-24 07:30:49 UTC (rev 71612)
+++ trunk/Build/source/texk/web2c/tests/fix-changefile-lines.py	2024-06-24 08:15:10 UTC (rev 71613)
@@ -11,17 +11,13 @@
 import getopt, os, re, sys
 
 USAGE = f"""
-Usage: {os.path.basename(sys.argv[0])} [options] <web file> <change file>
+Usage: {os.path.basename(sys.argv[0])} [-i|--init] <web file> <change file>
 
 Reads a WEB file and a change file and writes a change file to stdout with
 potentially corrected part, section and line numbers.
 
-Options influence the '@x [part.section] l.line - text' format:
-    -p, --parts     Suppress the 'part' (starred section) number
-    -s, --sections  Suppress the (unstarred) 'section' number
-    -l, --lines     Suppress the 'l.line' number
-    -h, --hyphens   Suppress the '-'
-    -t, --texts     Suppress the 'text'
+The option '-i' ('--init') forces a '[part.section] l.line' tag after each
+'@x'; this is useful for untagged change files.
 
 Written by Tyge Tiessen, 2024. Public domain.
 """.strip()
@@ -180,41 +176,33 @@
                 # CWEB @qcomments@> are ignored; see ctwill-w2c.ch
                 if repl_start != "@q":
                     break
-            if match_start == "@ ":
-                if repl_start in ["@ ", "@*"]:
+            if match_start == "@ " or match_start == "@":
+                if repl_start in ["@ ", "@*", "@"]:
                     section += 1
             elif match_start == "@*":
                 if repl_start == "@*":
                     part += 1
                     section += 1
-                elif repl_start == "@ ":
+                elif repl_start in ["@ ", "@"]:
                     section += 1
 
-            # Create line with standard tag and optional information.
-            old_line = self._lines[self._chunk_start][2:].strip()
-            new_line = "@x"
+            # Replace '@x' line with updated information.
+            new_line = self._lines[self._chunk_start]
 
-            if opt_handler.part_b or opt_handler.section_b:
-                old_line = re.sub("\\[\\d+(\\.\\d+)?\\]", "", old_line, 1).strip()
-                new_line += " ["
-                if opt_handler.part_b:
-                    new_line += f"{part}"
-                if opt_handler.part_b and opt_handler.section_b:
-                    new_line += "."
-                if opt_handler.section_b:
-                    new_line += f"{section}"
-                new_line += "]"
+            new_line = re.sub(
+                    "\\[\\d+\\.\\d+\\]", f"[{part}.{section}]", new_line, 1)
+            new_line = re.sub(
+                    "^@x \\[\\d+\\]", f"@x [{section}]", new_line, 1)
+            new_line = re.sub(
+                    "l\\.\\d+", f"l.{line_number}", new_line, 1)
 
-            if opt_handler.line_b:
-                old_line = re.sub("l\\.\\d+", "", old_line, 1).strip()
-                new_line += f" l.{line_number}"
+            # Force '[part.section] l.line' tag after '@x'; useful for untagged
+            # change files, e.g., CWEB's '*-w2c.ch' monsters.
+            if opt_handler.init_b:
+                new_line = re.sub(
+                        "^@x", f"@x [{part}.{section}] l.{line_number}",
+                        new_line, 1)
 
-            if opt_handler.text_b and old_line:
-                if opt_handler.hyphen_b:
-                    old_line = re.sub("-+", "", old_line, 1).strip()
-                    new_line += " -"
-                new_line += f" {old_line}"
-
             ch_line = self._lines[self._chunk_start]
             if new_line[:10] != ch_line[:10]:
                 eprint("Old:")
@@ -237,15 +225,10 @@
     def __init__(self):
         # Optional elements of the output format
         # '@x [{part}.{section}] l.{line} {-(hyphen)} {text}'
-        self.part_b = True
-        self.section_b = True
-        self.line_b = True
-        self.hyphen_b = True
-        self.text_b = True
+        self.init_b = False
 
         try:
-            opts, self.args = getopt.getopt(sys.argv[1:], "pslht",
-                ["parts", "sections", "lines", "hyphens", "texts"])
+            opts, self.args = getopt.getopt(sys.argv[1:], "i", ["init"])
         except getopt.GetoptError as err:
             eprint(f"\n{os.path.basename(sys.argv[0])}: {err}!\n")
             print(USAGE)
@@ -252,16 +235,8 @@
             sys.exit(1)
 
         for opt, _ in opts:
-            if opt in ("-p", "--parts"):
-                self.part_b = False
-            elif opt in ("-s", "--sections"):
-                self.section_b = False
-            elif opt in ("-l", "--lines"):
-                self.line_b = False
-            elif opt in ("-h", "--hyphens"):
-                self.hyphen_b = False
-            elif opt in ("-t", "--texts"):
-                self.text_b = False
+            if opt in ("-i", "--init"):
+                self.init_b = True
             else:
                 assert False, f"Unhandled option {opt}"
 



More information about the tex-live-commits mailing list.