[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 33bcd92 1/2: txt.h: optionally parse meta-data
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 33bcd92 1/2: txt.h: optionally parse meta-data without modifying the line |
Date: |
Wed, 15 May 2019 11:07:45 -0400 (EDT) |
branch: master
commit 33bcd923106f006689919d1d153d8d6265e00821
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>
txt.h: optionally parse meta-data without modifying the line
Until now, when there was a meta-data line (starting with `# Column N:'),
the `txt_info_from_comment' function would modify the contents of the line
(in partciular, it would put string-NULL characters in it for the different
components that it needs). As a result, a program like Match that would
need to parse these meta-data lines again wouldn't find any.
With this commit, an `inplace' argument has been added to this option, so
when it is zero, a separately allocated line is parsed and modified, not
the original one.
This fixes bug #56324.
---
NEWS | 1 +
bin/match/match.c | 2 +-
lib/txt.c | 22 +++++++++++++++++++---
3 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/NEWS b/NEWS
index e75ebe8..1f656bd 100644
--- a/NEWS
+++ b/NEWS
@@ -57,6 +57,7 @@ See the end of the file for license conditions.
bug #56256: Segmentation fault when reading plain text array/image.
bug #56257: ConvertType: Values not preserved when converting text to FITS.
bug #56299: cosmiccal fails at z=0.
+ bug #56324: Column metadata not usable when input is from pipe/stdin.
diff --git a/bin/match/match.c b/bin/match/match.c
index 7dca0ab..d60c39e 100644
--- a/bin/match/match.c
+++ b/bin/match/match.c
@@ -353,7 +353,7 @@ match_catalog(struct matchparams *p)
uint32_t *u, *uf;
gal_data_t *tmp, *mcols;
gal_data_t *a=NULL, *b=NULL;
- size_t nummatched, *acolmatch, *bcolmatch;
+ size_t nummatched, *acolmatch=NULL, *bcolmatch=NULL;
/* Find the matching coordinates. We are doing the processing in
place, */
diff --git a/lib/txt.c b/lib/txt.c
index 3ed8643..96d2027 100644
--- a/lib/txt.c
+++ b/lib/txt.c
@@ -153,16 +153,29 @@ txt_trim_space(char *str)
be before column 7.
*/
static void
-txt_info_from_comment(char *line, gal_data_t **datall, char *comm_start)
+txt_info_from_comment(char *in_line, gal_data_t **datall, char *comm_start,
+ int inplace)
{
- char *tailptr;
gal_data_t *tmp;
int index, strw=0;
+ char *line, *aline, *tailptr;
size_t len=strlen(comm_start);
int type=GAL_TYPE_FLOAT64; /* Default type. */
char *number=NULL, *name=NULL, *comment=NULL;
char *inbrackets=NULL, *unit=NULL, *typestr=NULL, *blank=NULL;
+ /* Make a copy of the input line if `inplace==0'. */
+ if(inplace) line=aline=in_line;
+ else
+ {
+ /* Because the `line' pointer will change, we need a pointer to the
+ start of the originally allocated lines. This is the purpose of
+ `aline' (allocated-line). */
+ gal_checkset_allocate_copy(in_line, &aline);
+ line=aline;
+ }
+
+
/* Only read this comment line if it follows the convention: */
if( !strncmp(line, comm_start, len) )
{
@@ -276,6 +289,9 @@ txt_info_from_comment(char *line, gal_data_t **datall, char
*comm_start)
final column, we are just collecting information now. */
gal_tableintern_read_blank(*datall, txt_trim_space(blank));
}
+
+ /* Clean up. */
+ if(in_line!=aline) free(aline);
}
@@ -539,7 +555,7 @@ txt_get_info_line(char *line, gal_data_t **datall, char
*comm_start,
{
/* Line is a comment, see if it has formatted information. */
case GAL_TXT_LINESTAT_COMMENT:
- txt_info_from_comment(line, datall, comm_start);
+ txt_info_from_comment(line, datall, comm_start, inplace);
break;
/* Line is actual data, use it to fill in the gaps. */