gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master 5c7c0b78: ConvertType: standard input only rea


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 5c7c0b78: ConvertType: standard input only read when no file specified
Date: Wed, 14 Feb 2024 20:41:00 -0500 (EST)

branch: master
commit 5c7c0b784a289cd100506e5761a0310266e31773
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    ConvertType: standard input only read when no file specified
    
    Until now, ConvertType would always read the standard input; even when the
    three or four color channels had been given as files on the command-line!
    This is contrary to normal expection on the command-line (for example AWK
    or SED only check the standard input when no file is given as an
    argument). Therefore it could cause un-expected bugs in situations where
    ConvertType was being called within a loop that was parsing the standard
    input (see [1]).
    
    With this commit, ConvertType now only reads the standard input when no
    input file is specified.
    
    This issue was reported by Jesús Vega and Raul Infante-Sainz and solved
    with the help of Greg Wooledge and Dennis Williamson.
---
 NEWS                         | 17 ++++++++++++++++-
 bin/convertt/ui.c            | 19 ++++++-------------
 doc/announce-acknowledge.txt |  3 +++
 doc/gnuastro.texi            |  3 ++-
 4 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/NEWS b/NEWS
index 958595e3..861555bb 100644
--- a/NEWS
+++ b/NEWS
@@ -48,7 +48,7 @@ See the end of the file for license conditions.
     instead of '$HOME/.local/etc/'. See the description of system
     configuration files above for more.
 
-*** Arithmetic:
+*** Arithmetic
 
   - The following operators will output two operands: the main statistic
     and the number of inputs used in each pixel: 'sigclip-mean',
@@ -71,6 +71,21 @@ See the end of the file for license conditions.
       as many other useful scenarios.
 
 
+*** ConvertType
+
+  - Standard input (stdin) is only checked when no input file has been
+    specified. Until now, the 'stdin' would be checked all the time, and if
+    anything was present there, it would be taken as the first color
+    channel. But this could cause problems in shell loops that parse the
+    standard input (for example, see
+    https://lists.gnu.org/archive/html/help-bash/2024-02/msg00074.html). Also,
+    it would rarely happen that when the three RGB color channels are
+    necessary, the first would be from the standard input, and the other
+    two as files. The new behavior is much more similar to the behavior of
+    other command-line programs like AWK or SED. This issue was reported by
+    Jesús Vega and Raul Infante-Sainz and solved with the help of Greg
+    Wooledge and Dennis Williamson.
+
 *** astscript-fits-view
   - The short format of the '--ds9geometry' option is '-G' (until now it
     was '-g'). This was necessary to allow the '-g' of this script to have
diff --git a/bin/convertt/ui.c b/bin/convertt/ui.c
index 4d7a267a..9da2724e 100644
--- a/bin/convertt/ui.c
+++ b/bin/convertt/ui.c
@@ -703,11 +703,8 @@ ui_make_channels_ll(struct converttparams *p)
   /* Initialize the counting of channels. */
   p->numch=0;
 
-  /* If any standard input is provided, we want to process that first. Note
-     that since other input arguments are also allowed (as other channels),
-     we'll need to process the standard input independently first, then go
-     onto the possible list of other files.*/
-  lines=gal_txt_stdin_read(p->cp.stdintimeout);
+  /* If no input files are specified, check the standard input. */
+  lines=p->inputnames?NULL:gal_txt_stdin_read(p->cp.stdintimeout);
   if(lines)
     {
       data=gal_txt_image_read(NULL, lines, p->cp.minmapsize,
@@ -953,14 +950,10 @@ ui_prepare_input_channels(struct converttparams *p)
     error(EXIT_FAILURE, 0, "the number of input color channels has to "
           "be 1 (for non image data, grayscale or only K channel in "
           "CMYK), 3 (for RGB) and 4 (for CMYK). You have given %zu "
-          "color channels. Note 1: some file formats (for example "
-          "JPEG in RGB mode) can contain more than one color channel, "
-          "if such a file is given all its channels are read, so "
-          "separate them first. Note 2: if your first input channel "
-          "was given through the standard input (piped from another "
-          "program) you can fix this error by giving a larger value "
-          "to the '--stdintimeout' option (currently %ld "
-          "micro-seconds)", p->numch, p->cp.stdintimeout);
+          "color channels. Note that some file formats (for example "
+          "JPEG in RGB mode) can contain more than one color channel. "
+          "If such a file is given all its channels are read, so "
+          "separate them first", p->numch);
 
 
   /* If there are multiple color channels, then ignore the monotocolor
diff --git a/doc/announce-acknowledge.txt b/doc/announce-acknowledge.txt
index 2deecce4..4d933524 100644
--- a/doc/announce-acknowledge.txt
+++ b/doc/announce-acknowledge.txt
@@ -1,10 +1,13 @@
 Alphabetically ordered list to acknowledge in the next release.
 
+Dennis Williamson
+Greg Wooledge
 Hamed Altafi
 Jesús Vega
 Juan Castillo Ramírez
 Phil Wyett
 Rahna Payyasseri Thanduparackal
+Raul Infante-Sainz
 
 
 
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index d382312b..f52eccdc 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -17700,7 +17700,8 @@ The common options are not repeated here.
 
 @cindex Standard input
 At most four input files (one for each color channel for formats that allow 
it) are allowed in ConvertType.
-The first input dataset can either be a file, or come from Standard input (see 
@ref{Standard input} and @ref{Recognized file formats}).
+When there is only one input channel (grayscale), the input can either be 
given as a file name (as an argument on the command-line) or through 
@ref{Standard input} (a pipe for example: only when no input file is specified).
+Therefore, if an input file is given, the standard input will not be checked.
 
 The order of multiple input files is important.
 After reading the input file(s) the number of color channels in all the inputs 
will be used to define which color space to use for the outputs and how each 
color channel is interpreted: 1 (for grayscale), 3 (for RGB) and 4 (for CMYK) 
input channels.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]