--- ray/src/util/cmatrix.c 2021/01/15 18:31:38 2.31 +++ ray/src/util/cmatrix.c 2022/04/27 01:31:56 2.35 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: cmatrix.c,v 2.31 2021/01/15 18:31:38 greg Exp $"; +static const char RCSid[] = "$Id: cmatrix.c,v 2.35 2022/04/27 01:31:56 greg Exp $"; #endif /* * Color matrix routines. @@ -15,6 +15,8 @@ static const char RCSid[] = "$Id: cmatrix.c,v 2.31 202 #include "paths.h" #include "resolu.h" +const char stdin_name[] = ""; + const char *cm_fmt_id[] = { "unknown", COLRFMT, CIEFMT, "float", "ascii", "double" @@ -212,14 +214,19 @@ CMATRIX * cm_load(const char *inspec, int nrows, int ncols, int dtype) { const int ROWINC = 2048; - FILE *fp = stdin; + int rowsOK = (dtype == DTascii) | (nrows > 0); int swap = 0; + FILE *fp; COLOR scale; CMATRIX *cm; if (!inspec) - inspec = ""; - else if (inspec[0] == '!') { + inspec = stdin_name; + else if (!*inspec) + return(NULL); + if (inspec == stdin_name) { /* reading from stdin? */ + fp = stdin; + } else if (inspec[0] == '!') { fp = popen(inspec+1, "r"); if (!fp) { sprintf(errmsg, "cannot start command '%s'", inspec); @@ -234,13 +241,14 @@ cm_load(const char *inspec, int nrows, int ncols, int #endif if (dtype != DTascii) SET_FILE_BINARY(fp); /* doesn't really work */ - if (!dtype | !ncols) { /* expecting header? */ + if (!dtype | !rowsOK | !ncols) { /* expecting header? */ char *err = cm_getheader(&dtype, &nrows, &ncols, &swap, scale, fp); if (err) error(USER, err); + rowsOK = (nrows > 0); } - if (ncols <= 0 && !fscnresolu(&ncols, &nrows, fp)) - error(USER, "unspecified number of columns"); + if (!rowsOK | !ncols && !fscnresolu(&ncols, &nrows, fp)) + error(USER, "unspecified matrix size"); switch (dtype) { case DTascii: case DTfloat: