gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master efe6013: Width correction in gal_blank_as_stri


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master efe6013: Width correction in gal_blank_as_string
Date: Sat, 6 May 2017 13:36:36 -0400 (EDT)

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

    Width correction in gal_blank_as_string
    
    After using the printf types of `inttypes.h', the `*' (to specify the width
    of the print) was put in the `printf' formatting string in any case (when a
    width was specified and when it wasn't). This is corrected with this
    commit. This only affected the integer types.
    
    The problem was actually found based on bad results from the checks in the
    Table program when printing text tables. So on the path to finding the
    cause (as described above), I also noticed that when setting the blank
    string for each column, we were not using `gal_blank_as_string' for
    strings! But now it supports strings also, so the extra
    `gal_checkset_allocate_copy' has been removed and the code of this part is
    much more cleaner now.
    
    A small correction was also made in the comments of
    `tests/buildprog/simpleio.c'.
---
 lib/blank.c                | 16 ++++++++--------
 lib/txt.c                  | 14 +++-----------
 tests/buildprog/simpleio.c |  2 +-
 3 files changed, 12 insertions(+), 20 deletions(-)

diff --git a/lib/blank.c b/lib/blank.c
index 3a21971..16153cb 100644
--- a/lib/blank.c
+++ b/lib/blank.c
@@ -390,49 +390,49 @@ gal_blank_as_string(uint8_t type, int width)
       break;
 
     case GAL_TYPE_UINT8:
-      fmt = width ? "%*"PRIu8 : "%*"PRIu8;
+      fmt = width ? "%*"PRIu8 : "%"PRIu8;
       if(width) asprintf(&blank, fmt, width, (uint8_t)GAL_BLANK_UINT8);
       else      asprintf(&blank, fmt,        (uint8_t)GAL_BLANK_UINT8);
       break;
 
     case GAL_TYPE_INT8:
-      fmt = width ? "%*"PRId8 : "%*"PRId8;
+      fmt = width ? "%*"PRId8 : "%"PRId8;
       if(width) asprintf(&blank, fmt, width, (int8_t)GAL_BLANK_INT8);
       else      asprintf(&blank, fmt,        (int8_t)GAL_BLANK_INT8);
       break;
 
     case GAL_TYPE_UINT16:
-      fmt = width ? "%*"PRIu16 : "%*"PRIu16;
+      fmt = width ? "%*"PRIu16 : "%"PRIu16;
       if(width) asprintf(&blank, fmt, width, (uint16_t)GAL_BLANK_UINT16);
       else      asprintf(&blank, fmt,        (uint16_t)GAL_BLANK_UINT16);
       break;
 
     case GAL_TYPE_INT16:
-      fmt = width ? "%*"PRId16 : "%*"PRId16;
+      fmt = width ? "%*"PRId16 : "%"PRId16;
       if(width) asprintf(&blank, fmt, width, (int16_t)GAL_BLANK_INT16);
       else      asprintf(&blank, fmt,        (int16_t)GAL_BLANK_INT16);
       break;
 
     case GAL_TYPE_UINT32:
-      fmt = width ? "%*"PRIu32 : "%*"PRIu32;
+      fmt = width ? "%*"PRIu32 : "%"PRIu32;
       if(width) asprintf(&blank, fmt, width, (uint32_t)GAL_BLANK_UINT32);
       else      asprintf(&blank, fmt,        (uint32_t)GAL_BLANK_UINT32);
       break;
 
     case GAL_TYPE_INT32:
-      fmt = width ? "%*"PRId32 : "%*"PRId32;
+      fmt = width ? "%*"PRId32 : "%"PRId32;
       if(width) asprintf(&blank, fmt, width, (int32_t)GAL_BLANK_INT32);
       else      asprintf(&blank, fmt,        (int32_t)GAL_BLANK_INT32);
       break;
 
     case GAL_TYPE_UINT64:
-      fmt = width ? "%*"PRIu64 : "%*"PRIu64;
+      fmt = width ? "%*"PRIu64 : "%"PRIu64;
       if(width) asprintf(&blank, fmt, width, (uint64_t)GAL_BLANK_UINT64);
       else      asprintf(&blank, fmt,        (uint64_t)GAL_BLANK_UINT64);
       break;
 
     case GAL_TYPE_INT64:
-      fmt = width ? "%*"PRId64 : "%*"PRId64;
+      fmt = width ? "%*"PRId64 : "%"PRId64;
       if(width) asprintf(&blank, fmt, width, (int64_t)GAL_BLANK_INT64);
       else      asprintf(&blank, fmt,        (int64_t)GAL_BLANK_INT64);
       break;
diff --git a/lib/txt.c b/lib/txt.c
index bd58174..880b2e3 100644
--- a/lib/txt.c
+++ b/lib/txt.c
@@ -1040,17 +1040,9 @@ make_fmts_for_printf(gal_data_t *datall, int leftadjust, 
size_t *len)
 
       /* If we have a blank value, get the blank value as a string and
          adjust the width */
-      if(gal_blank_present(data, 0)==0)
-        fmts[i*FMTS_COLS+2]=NULL;
-      else
-        {
-          /* Set the blank value. */
-          if(data->type==GAL_TYPE_STRING)
-            gal_checkset_allocate_copy(GAL_BLANK_STRING,
-                                       &fmts[i*FMTS_COLS+2]);
-          else
-            fmts[i*FMTS_COLS+2]=gal_blank_as_string(data->type, 0);
-        }
+      fmts[ i*FMTS_COLS+2 ] = ( gal_blank_present(data, 0)
+                                ? gal_blank_as_string(data->type, 0)
+                                : NULL );
 
 
       /* Fill in the printing paramters. */
diff --git a/tests/buildprog/simpleio.c b/tests/buildprog/simpleio.c
index 7e889d1..ac34d41 100644
--- a/tests/buildprog/simpleio.c
+++ b/tests/buildprog/simpleio.c
@@ -38,7 +38,7 @@ main(int argc, char *argv[])
       return EXIT_FAILURE;
     }
 
-  /* Read the image into memory as a float32 data type. */
+  /* Read the image into memory. */
   image=gal_fits_img_read(argv[1], argv[2], -1);
 
   /* Let the user know. */



reply via email to

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