gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 57f3ce9: Table: properly reads column arithmet


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 57f3ce9: Table: properly reads column arithmetic when newline is commented
Date: Thu, 14 May 2020 20:44:06 -0400 (EDT)

branch: master
commit 57f3ce91a83b7556dc5e4586e6e0cfcb4be0bc06
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    Table: properly reads column arithmetic when newline is commented
    
    When using scripts and longer column arithmetic operations, it will often
    happen that the author may want to break the line by commenting the
    new-line character and going to the next, something like this:
    
      asttable table.fits --columns='arith $1 $2 + \
                                           $3 /'
    
    Until now, in such a call, Table would crash, complaining that there is no
    column called '\' (thinking that '\' is a column name). With this commit
    this bug is fixed by parsing all column values before any other
    operation. If a backslash is seen that is followed by a new-line, both
    characters are replaced with a single space each (which doesn't affect the
    interpretation).
    
    This fixes bug #58371.
---
 NEWS           |  1 +
 bin/table/ui.c | 10 +++++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index 8440c40..c820ea8 100644
--- a/NEWS
+++ b/NEWS
@@ -136,6 +136,7 @@ See the end of the file for license conditions.
   bug #57989: Warp not accounting for translation in pixel grid.
   bug #57995: Fits lib's date to second function affected by host's timezone.
   bug #58315: Some NaNs with sigma-clip operators in Arithmetic and one input.
+  bug #58371: Table crashes with a commented newline in the columns.
 
 
 
diff --git a/bin/table/ui.c b/bin/table/ui.c
index a2b9a91..ea9034f 100644
--- a/bin/table/ui.c
+++ b/bin/table/ui.c
@@ -547,7 +547,7 @@ ui_print_info_exit(struct tableparams *p)
 static void
 ui_columns_prepare(struct tableparams *p)
 {
-  char **strarr;
+  char *c, **strarr;
   gal_data_t *strs;
   size_t i, totcalled=0;
   struct column_pack *node, *last;
@@ -557,6 +557,14 @@ ui_columns_prepare(struct tableparams *p)
      one value separated by a comma. */
   for(tmp=p->columns;tmp!=NULL;tmp=tmp->next)
     {
+      /* Remove any possibly commented new-line where we have a backslash
+         followed by a new-line character (replace the two characters with
+         two single space characters). This can happen with the 'arith'
+         argument in a script, when it gets long (bug #58371). But to be
+         general in other cases too, we'll just correct it here. */
+      for(c=tmp->v;*c!='\0';++c)
+        if(*c=='\\' && *(c+1)=='\n') { *c=' '; *(++c)=' '; }
+
       /* Read the different comma-separated strings into an array (within a
          'gal_data_t'). */
       strs=gal_options_parse_csv_strings_raw(tmp->v, NULL, 0);



reply via email to

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