From: Pádraig Brady
Date: Mon, 5 Jan 2026 21:56:38 +0000 (+0000) Subject: ptx: implement -t to change default width to 100 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7531d3a205346e3ef9d249194d44a7dcd1da6142;p=thirdparty%2Fcoreutils.git ptx: implement -t to change default width to 100 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. --- diff --git a/NEWS b/NEWS index ca13267b3c..eb9c5e2c4d 100644 --- 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. diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 1b0c0db911..c42d75753d 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -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 diff --git a/src/ptx.c b/src/ptx.c index 92f948d0c7..040c9e8373 100644 --- 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. */ diff --git a/tests/ptx/ptx.pl b/tests/ptx/ptx.pl index 3ef86fe3d8..1561996ca6 100755 --- a/tests/ptx/ptx.pl +++ b/tests/ptx/ptx.pl @@ -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"}],