]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
ptx: implement -t to change default width to 100
authorPádraig Brady <P@draigBrady.com>
Mon, 5 Jan 2026 21:56:38 +0000 (21:56 +0000)
committerPádraig Brady <P@draigBrady.com>
Mon, 5 Jan 2026 23:37:49 +0000 (23:37 +0000)
Align the -t implementation with the Heirloom project.

* src/ptx.c (usage): Describe -t, and also mention
the default width is 72 when not used.
* doc/coreutils.texi (ptx invocation): Likewise.
(main): Override the default width if -t is specified.
* tests/ptx/ptx.pl: Add test cases.
* NEWS: Mention the change in behavior.

NEWS
doc/coreutils.texi
src/ptx.c
tests/ptx/ptx.pl

diff --git a/NEWS b/NEWS
index ca13267b3c85898ca34cfd97dd4c7046339140c5..eb9c5e2c4d8e627b0550daa771d08c98f10b14a0 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -53,6 +53,8 @@ GNU coreutils NEWS                                    -*- outline -*-
 
 ** Changes in behavior
 
+  'ptx' -t is no longer a no-op, and now sets the default width to 100 columns.
+
   'timeout' now honors ignored signals and will not propagate them.  E.g.,
   timeout(1) in a shell backgrounded job, will not terminate upon receiving
   SIGINT or SIGQUIT, as these are ignored by default in shell background jobs.
index 1b0c0db91159859388716f0aa5f3abce1721b308..c42d75753dbbabf0b3613691ce791c831d833c3c 100644 (file)
@@ -5726,6 +5726,12 @@ Output format is further controlled by the following options.
 Select the size of the minimum white space gap between the fields on the
 output line.
 
+@optItem{ptx,-t,}
+@optItemx{ptx,--typeset-mode,}
+Prepare the output for a phototypesetter.
+I.e., change the default output width from 72 to 100 columns.
+This is equivalent to @option{--width=100}.
+
 @optItem{ptx,-w,@w{ }@var{number}}
 @optItemx{ptx,--width,=@var{number}}
 Select the maximum output width of each final line.  If references are
index 92f948d0c7ed13b9a234b659661f498b9daf94d8..040c9e837352aa980da0f4ea4a7f7640c79d95b7 100644 (file)
--- a/src/ptx.c
+++ b/src/ptx.c
@@ -76,7 +76,7 @@ static bool gnu_extensions = true;    /* trigger all GNU extensions */
 static bool auto_reference = false;    /* refs are 'file_name:line_number:' */
 static bool input_reference = false;   /* refs at beginning of input lines */
 static bool right_reference = false;   /* output refs after right context  */
-static idx_t line_width = 72;          /* output line width in characters */
+static idx_t line_width = -1;          /* output line width in characters */
 static idx_t gap_size = 3;     /* number of spaces between output fields */
 static char const *truncation_string = "/";
                                 /* string used to mark line truncations */
@@ -1710,7 +1710,7 @@ Output a permuted index, including context, of the words in the input files.\n\
 "), stdout);
       fputs (_("\
   -r, --references               first field of each line is a reference\n\
-  -t, --typeset-mode               - not implemented -\n\
+  -t, --typeset-mode             change the default width from 72 to 100\n\
   -w, --width=NUMBER             output width in columns, reference excluded\n\
 "), stdout);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
@@ -1820,7 +1820,8 @@ main (int argc, char **argv)
           break;
 
         case 't':
-          /* Yet to understand...  */
+          if (line_width < 0)
+            line_width = 100;
           break;
 
         case 'w':
@@ -1882,6 +1883,9 @@ main (int argc, char **argv)
         }
     }
 
+  if (line_width < 0)
+    line_width = 72;
+
   /* Process remaining arguments.  If GNU extensions are enabled, process
      all arguments as input parameters.  If disabled, accept at most two
      arguments, the second of which is an output parameter.  */
index 3ef86fe3d88d8a71a1bc6c9277de670e21f65f44..1561996ca6698f7d08e5ac767dc72df56d39d0fe 100755 (executable)
@@ -27,6 +27,13 @@ my @Tests =
 ["1tok", '-w10', {IN=>"bar\n"},     {OUT=>"        bar\n"}],
 ["2tok", '-w10', {IN=>"foo bar\n"}, {OUT=>"     /   bar\n        foo/\n"}],
 
+# Ensure -w overrides -t
+["width-1", '-t -w10', {IN=>"bar\n"},     {OUT=>" " x  8 . "bar\n"}],
+# Ensure default width is 72
+["width-3", '',        {IN=>"bar\n"},     {OUT=>" " x 39 . "bar\n"}],
+# Ensure default width is 100 with -t
+["width-2", '-t',      {IN=>"bar\n"},     {OUT=>" " x 53 . "bar\n"}],
+
 # with coreutils-6.12 and earlier, this would infloop with -wN, N < 10
 ["narrow", '-w2', {IN=>"qux\n"},    {OUT=>"      qux\n"}],
 ["narrow-g", '-g1 -w2', {IN=>"ta\n"}, {OUT=>"  ta\n"}],