# HG changeset patch # User jwe # Date 776925149 0 # Node ID 5acc6db54c8f92be5429ad6cb09cc6e125d72578 # Parent 9ced66fce8a34e874ad84d4a33d724bafce8b89e [project @ 1994-08-15 04:32:29 by jwe] diff --git a/src/load-save.cc b/src/load-save.cc --- a/src/load-save.cc +++ b/src/load-save.cc @@ -88,12 +88,17 @@ LS_UNKNOWN_FLT_FMT, }; +// Not all of the following are currently used. + enum save_type { LS_U_CHAR, LS_U_SHORT, + LS_U_INT, + LS_CHAR, LS_SHORT, LS_INT, + LS_FLOAT, LS_DOUBLE, }; @@ -464,6 +469,14 @@ LS_DO_WRITE (unsigned TWO_BYTE_INT, data, 2, len, os); break; + case LS_U_INT: + LS_DO_WRITE (unsigned FOUR_BYTE_INT, data, 4, len, os); + break; + + case LS_CHAR: + LS_DO_WRITE (signed char, data, 1, len, os); + break; + case LS_SHORT: LS_DO_WRITE (TWO_BYTE_INT, data, 2, len, os); break; @@ -1390,6 +1403,39 @@ return -1; } +// We don't just use a cast here, because we need to be able to detect +// possible errors. + +static floating_point_format +get_floating_point_format (int mach) +{ + switch (mach) + { + case 0: + flt_fmt = LS_IEEE_LITTLE; + break; + + case 1: + flt_fmt = LS_IEEE_BIG; + break; + + case 2: + flt_fmt = LS_VAX_D; + break; + + case 3: + flt_fmt = LS_VAX_G; + break; + + case 4: + flt_fmt = LS_CRAY; + break; + + default: + flt_fmt = LS_UNKOWN_FLT_FMT; + break; + } +} // Extract one value (scalar, matrix, string, etc.) from stream IS and // place it in TC, returning the name of the variable. // @@ -1430,14 +1476,9 @@ mopt /= 100; // Skip unused third digit too. mach = mopt % 10; // IEEE, VAX, etc. - switch (mach) + flt_fmt = get_floating_point_format (mach); + if (flt_fmt == LS_UNKNOWN_FLT_FMT) { - case 0: flt_fmt = LS_IEEE_LITTLE; break; - case 1: flt_fmt = LS_IEEE_BIG; break; - case 2: flt_fmt = LS_VAX_D; break; - case 3: flt_fmt = LS_VAX_G; break; - case 4: flt_fmt = LS_CRAY; break; - default: error ("load: unrecognized binary format!"); return 0; } @@ -1553,14 +1594,9 @@ char tmp = 0; is.read (&tmp, 1); - switch (tmp) + flt_fmt = get_floating_point_format (tmp); + if (flt_fmt == LS_UNKNOWN_FLT_FMT) { - case 0: flt_fmt = LS_IEEE_LITTLE; break; - case 1: flt_fmt = LS_IEEE_BIG; break; - case 2: flt_fmt = LS_VAX_D; break; - case 3: flt_fmt = LS_VAX_G; break; - case 4: flt_fmt = LS_CRAY; break; - default: if (! quiet) error ("load: unrecognized binary format!"); return -1;