diff --git a/src/BCDConverter.cc b/src/BCDConverter.cc index 1c51b8b..99c4ef5 100644 --- a/src/BCDConverter.cc +++ b/src/BCDConverter.cc @@ -31,9 +31,9 @@ class BCDConverter : public StreamFormatConverter }; int BCDConverter:: -parse(const StreamFormat&, StreamBuffer&, const char*&, bool) +parse(const StreamFormat& fmt, StreamBuffer&, const char*&, bool) { - return long_format; + return (fmt.flags & sign_flag) ? signed_format : unsigned_format; } bool BCDConverter:: diff --git a/src/BinaryConverter.cc b/src/BinaryConverter.cc index 7645ce9..188ee6f 100644 --- a/src/BinaryConverter.cc +++ b/src/BinaryConverter.cc @@ -19,6 +19,7 @@ ***************************************************************/ #include +#include #include "StreamFormatConverter.h" #include "StreamError.h" @@ -32,51 +33,59 @@ class BinaryConverter : public StreamFormatConverter }; int BinaryConverter:: -parse(const StreamFormat& format, StreamBuffer& info, +parse(const StreamFormat& fmt, StreamBuffer& info, const char*& source, bool) { - if (format.conv == 'B') + if (fmt.conv == 'b') { - // user defined characters for %B (next 2 in source) + // default characters 0 and 1 for %b + info.append("01"); + return unsigned_format; + } + + // user defined characters for %B (next 2 in source) + if (*source) + { + if (*source == esc) source++; + info.append(*source++); if (*source) { if (*source == esc) source++; info.append(*source++); - if (*source) - { - if (*source == esc) source++; - info.append(*source++); - return long_format; - } + return unsigned_format; } - error("Missing characters after %%B format conversion\n"); - return false; } - // default characters for %b - info.append("01"); - return long_format; + error("Missing characters after %%B format conversion\n"); + return false; } bool BinaryConverter:: -printLong(const StreamFormat& format, StreamBuffer& output, long value) +printLong(const StreamFormat& fmt, StreamBuffer& output, long value) { - int prec = format.prec; + int prec = fmt.prec; if (prec == -1) { - // find number of significant bits - prec = sizeof (value) * 8; - while (prec && (value & (1L << (prec - 1))) == 0) prec--; + // Find number of significant bits is nothing is specified. + unsigned long x = (unsigned long) value; + prec = 32; +#if (LONG_BIT > 32) + if (x > 0xFFFFFFFF) { prec = 64; x >>=32; } +#endif + if (x <= 0x0000FFFF) { prec -= 16; x <<=16; } + if (x <= 0x00FFFFFF) { prec -= 8; x <<=8; } + if (x <= 0x0FFFFFFF) { prec -= 4; x <<=4; } + if (x <= 0x3FFFFFFF) { prec -= 2; x <<=2; } + if (x <= 0x7FFFFFFF) { prec -= 1; } } - if (prec == 0) prec++; // print at least one bit int width = prec; - if (format.width > width) width = format.width; - char zero = format.info[0]; - char one = format.info[1]; - char fill = (format.flags & zero_flag) ? zero : ' '; - if (format.flags & alt_flag) + if (fmt.width > width) width = fmt.width; + char zero = fmt.info[0]; + char one = fmt.info[1]; + char fill = (fmt.flags & zero_flag) ? zero : ' '; + if (fmt.flags & alt_flag) { // little endian (least significant bit first) - if (!(format.flags & left_flag)) + if (!(fmt.flags & left_flag)) { // pad left while (width > prec) @@ -100,7 +109,7 @@ printLong(const StreamFormat& format, StreamBuffer& output, long value) else { // big endian (most significant bit first) - if (!(format.flags & left_flag)) + if (!(fmt.flags & left_flag)) { // pad left while (width > prec) @@ -124,18 +133,18 @@ printLong(const StreamFormat& format, StreamBuffer& output, long value) } int BinaryConverter:: -scanLong(const StreamFormat& format, const char* input, long& value) +scanLong(const StreamFormat& fmt, const char* input, long& value) { long val = 0; - int width = format.width; + int width = fmt.width; if (width == 0) width = -1; int length = 0; - char zero = format.info[0]; - char one = format.info[1]; + char zero = fmt.info[0]; + char one = fmt.info[1]; if (!isspace(zero) && !isspace(one)) while (isspace(input[length])) length++; // skip whitespaces if (input[length] != zero && input[length] != one) return -1; - if (format.flags & alt_flag) + if (fmt.flags & alt_flag) { // little endian (least significan bit first) long mask = 1; diff --git a/src/RawConverter.cc b/src/RawConverter.cc index 0eda514..f89abcb 100644 --- a/src/RawConverter.cc +++ b/src/RawConverter.cc @@ -31,23 +31,23 @@ class RawConverter : public StreamFormatConverter }; int RawConverter:: -parse(const StreamFormat&, StreamBuffer&, +parse(const StreamFormat& fmt, StreamBuffer&, const char*&, bool) { - return long_format; + return (fmt.flags & (sign_flag|zero_flag)) ? signed_format : unsigned_format; } bool RawConverter:: -printLong(const StreamFormat& format, StreamBuffer& output, long value) +printLong(const StreamFormat& fmt, StreamBuffer& output, long value) { - int prec = format.prec; // number of bytes from value + int prec = fmt.prec; // number of bytes from value if (prec == -1) prec = 1; // default: 1 byte int width = prec; // number of bytes in output if (prec > (int)sizeof(long)) prec=sizeof(long); - if (format.width > width) width = format.width; + if (fmt.width > width) width = fmt.width; char byte = 0; - if (format.flags & alt_flag) // little endian (lsb first) + if (fmt.flags & alt_flag) // little endian (lsb first) { while (prec--) { @@ -56,7 +56,7 @@ printLong(const StreamFormat& format, StreamBuffer& output, long value) value >>= 8; width--; } - if (format.flags & zero_flag) + if (fmt.flags & zero_flag) { // fill with zero byte = 0; @@ -73,7 +73,7 @@ printLong(const StreamFormat& format, StreamBuffer& output, long value) } else // big endian (msb first) { - if (format.flags & zero_flag) + if (fmt.flags & zero_flag) { // fill with zero byte = 0; @@ -97,17 +97,17 @@ printLong(const StreamFormat& format, StreamBuffer& output, long value) } int RawConverter:: -scanLong(const StreamFormat& format, const char* input, long& value) +scanLong(const StreamFormat& fmt, const char* input, long& value) { long length = 0; long val = 0; - int width = format.width; + int width = fmt.width; if (width == 0) width = 1; // default: 1 byte - if (format.flags & skip_flag) + if (fmt.flags & skip_flag) { return width; // just skip input } - if (format.flags & alt_flag) + if (fmt.flags & alt_flag) { // little endian (lsb first) unsigned int shift = 0; @@ -118,7 +118,7 @@ scanLong(const StreamFormat& format, const char* input, long& value) } if (width == 0) { - if (format.flags & zero_flag) + if (fmt.flags & zero_flag) { // fill with zero val |= ((unsigned char) input[length++]) << shift; @@ -134,7 +134,7 @@ scanLong(const StreamFormat& format, const char* input, long& value) else { // big endian (msb first) - if (format.flags & zero_flag) + if (fmt.flags & zero_flag) { // fill with zero val = (unsigned char) input[length++]; diff --git a/src/StreamCore.cc b/src/StreamCore.cc index ac8db8b..19da960 100644 --- a/src/StreamCore.cc +++ b/src/StreamCore.cc @@ -749,7 +749,7 @@ printSeparator() bool StreamCore:: printValue(const StreamFormat& fmt, long value) { - if (fmt.type != long_format && fmt.type != enum_format) + if (fmt.type != unsigned_format && fmt.type != signed_format && fmt.type != enum_format) { error("%s: printValue(long) called with %%%c format\n", name(), fmt.conv); @@ -1216,7 +1216,8 @@ normal_format: double ddummy; switch (fmt.type) { - case long_format: + case unsigned_format: + case signed_format: case enum_format: consumed = StreamFormatConverter::find(fmt.conv)-> scanLong(fmt, inputLine(consumedInput), ldummy); @@ -1457,7 +1458,7 @@ matchSeparator() long StreamCore:: scanValue(const StreamFormat& fmt, long& value) { - if (fmt.type != long_format && fmt.type != enum_format) + if (fmt.type != unsigned_format && fmt.type != signed_format && fmt.type != enum_format) { error("%s: scanValue(long&) called with %%%c format\n", name(), fmt.conv); diff --git a/src/StreamEpics.cc b/src/StreamEpics.cc index e874f49..7b45a4e 100644 --- a/src/StreamEpics.cc +++ b/src/StreamEpics.cc @@ -751,21 +751,16 @@ process() bool Stream:: print(format_t *format, va_list ap) { - long lval; - double dval; - char* sval; switch (format->type) { - case DBF_ENUM: + case DBF_ULONG: case DBF_LONG: - lval = va_arg(ap, long); - return printValue(*format->priv, lval); + case DBF_ENUM: + return printValue(*format->priv, va_arg(ap, long)); case DBF_DOUBLE: - dval = va_arg(ap, double); - return printValue(*format->priv, dval); + return printValue(*format->priv, va_arg(ap, double)); case DBF_STRING: - sval = va_arg(ap, char*); - return printValue(*format->priv, sval); + return printValue(*format->priv, va_arg(ap, char*)); } error("INTERNAL ERROR (%s): Illegal format type\n", name()); return false; @@ -775,27 +770,22 @@ bool Stream:: scan(format_t *format, void* value, size_t maxStringSize) { // called by streamScanfN - long* lptr; - double* dptr; - char* sptr; // first remove old value from inputLine (if we are scanning arrays) consumedInput += currentValueLength; currentValueLength = 0; switch (format->type) { + case DBF_ULONG: case DBF_LONG: case DBF_ENUM: - lptr = (long*)value; - currentValueLength = scanValue(*format->priv, *lptr); + currentValueLength = scanValue(*format->priv, *(long*)value); break; case DBF_DOUBLE: - dptr = (double*)value; - currentValueLength = scanValue(*format->priv, *dptr); + currentValueLength = scanValue(*format->priv, *(double*)value); break; case DBF_STRING: - sptr = (char*)value; - currentValueLength = scanValue(*format->priv, sptr, + currentValueLength = scanValue(*format->priv, (char*)value, maxStringSize); break; default: @@ -979,9 +969,9 @@ getFieldAddress(const char* fieldname, StreamBuffer& address) } static const unsigned char dbfMapping[] = - {0, DBF_LONG, DBF_ENUM, DBF_DOUBLE, DBF_STRING}; + {0, DBF_ULONG, DBF_LONG, DBF_ENUM, DBF_DOUBLE, DBF_STRING}; static const short typeSize[] = - {0, sizeof(epicsInt32), sizeof(epicsUInt16), + {0, sizeof(epicsUInt32), sizeof(epicsInt32), sizeof(epicsUInt16), sizeof(epicsFloat64), MAX_STRING_SIZE}; bool Stream:: @@ -1079,7 +1069,12 @@ formatValue(const StreamFormat& format, const void* fieldaddress) (long)((epicsUInt16*)buffer)[i])) return false; break; - case long_format: + case unsigned_format: + if (!printValue(format, + (long)((epicsUInt32*)buffer)[i])) + return false; + break; + case signed_format: if (!printValue(format, (long)((epicsInt32*)buffer)[i])) return false; @@ -1150,7 +1145,17 @@ matchValue(const StreamFormat& format, const void* fieldaddress) name(), fieldBuffer.expand()()); switch (format.type) { - case long_format: + case unsigned_format: + { + consumed = scanValue(format, lval); + if (consumed >= 0) ((epicsUInt32*)buffer)[nord] = lval; + debug("Stream::matchValue(%s): %s.%s[%li] = %lu\n", + name(), pdbaddr->precord->name, + ((dbFldDes*)pdbaddr->pfldDes)->name, + nord, lval); + break; + } + case signed_format: { consumed = scanValue(format, lval); if (consumed >= 0) ((epicsInt32*)buffer)[nord] = lval; @@ -1304,6 +1309,7 @@ matchValue(const StreamFormat& format, const void* fieldaddress) flags &= ~ScanTried; switch (fmt.type) { + case DBF_ULONG: case DBF_LONG: case DBF_ENUM: error("%s: %s(%s.%s, %s, %li) failed\n", diff --git a/src/StreamFormat.h b/src/StreamFormat.h index f144a77..79e22b9 100644 --- a/src/StreamFormat.h +++ b/src/StreamFormat.h @@ -34,11 +34,12 @@ typedef enum { } StreamFormatFlag; typedef enum { - long_format = 1, - enum_format = 2, - double_format = 3, - string_format = 4, - pseudo_format = 5 + unsigned_format = 1, + signed_format, + enum_format, + double_format, + string_format, + pseudo_format } StreamFormatType; extern const char* StreamFormatTypeStr[]; diff --git a/src/StreamFormatConverter.cc b/src/StreamFormatConverter.cc index aabbdba..d03f516 100644 --- a/src/StreamFormatConverter.cc +++ b/src/StreamFormatConverter.cc @@ -21,6 +21,7 @@ #include #include +#include #include "StreamFormatConverter.h" #include "StreamError.h" @@ -310,14 +311,16 @@ parse(const StreamFormat& fmt, StreamBuffer& info, info.append('l'); info.append(fmt.conv); } - return long_format; + if (fmt.conv == 'd' || fmt.conv == 'i') return signed_format; + return unsigned_format; } bool StdLongConverter:: printLong(const StreamFormat& fmt, StreamBuffer& output, long value) { - if (tolower(fmt.conv) == 'x' && fmt.width && fmt.width < 2*sizeof(long)) - value &= ~(-1L << (fmt.width<<2)); + // limits %x/%X formats to number of half bytes in width. + if (fmt.width && (fmt.conv == 'x' || fmt.conv == 'X') && fmt.width < 2*sizeof(long)) + value &= ~(-1L << (fmt.width*4)); output.print(fmt.info, value); return true; } @@ -329,6 +332,7 @@ scanLong(const StreamFormat& fmt, const char* input, long& value) int length; bool neg; int base; + long v; length = prepareval(fmt, input, neg); if (length < 0) return -1; @@ -338,14 +342,11 @@ scanLong(const StreamFormat& fmt, const char* input, long& value) base = 10; break; case 'o': - base = 8; - goto signcheck; case 'x': case 'X': - base = 16; -signcheck: - // allow negative hex and oct numbers with - flag + // allow negative hex and oct numbers with - flag if (neg && !(fmt.flags & left_flag)) return -1; + base = (fmt.conv == 'o') ? 8 : 16; break; case 'u': if (neg) return -1; @@ -354,10 +355,10 @@ signcheck: default: base = 0; } - value = strtoul(input, &end, base); - if (neg) value = -value; + v = strtoul(input, &end, base); if (end == input) return -1; length += end-input; + value = neg ? -v : v; return length; } @@ -545,7 +546,7 @@ parse(const StreamFormat& fmt, StreamBuffer& info, info.append("%n"); return string_format; } - return long_format; + return unsigned_format; } bool StdCharsConverter:: diff --git a/src/StreamProtocol.cc b/src/StreamProtocol.cc index 9c4c821..6f97db8 100644 --- a/src/StreamProtocol.cc +++ b/src/StreamProtocol.cc @@ -26,7 +26,8 @@ #include "StreamError.h" const char* StreamFormatTypeStr[] = { - "none", "long", "enum", "double", "string", "pseudo" + // must match the order in StreamFormat.h + "none", "unsigned", "signed", "enum", "double", "string", "pseudo" }; class StreamProtocolParser::Protocol::Variable @@ -1438,7 +1439,7 @@ compileFormat(StreamBuffer& buffer, const char*& formatstr, // parsing failed return false; } - if (type < long_format && type > pseudo_format) + if (type < 1 && type > pseudo_format) { error(line, filename(), "Illegal format type %d returned from '%%%c' converter\n", diff --git a/src/devaaiStream.c b/src/devaaiStream.c index 6ffb437..7f03e8a 100644 --- a/src/devaaiStream.c +++ b/src/devaaiStream.c @@ -20,9 +20,9 @@ #include #include -#include "devStream.h" -#include #include +#include +#include "devStream.h" #include static long readData (dbCommon *record, format_t *format) @@ -57,6 +57,7 @@ static long readData (dbCommon *record, format_t *format) } break; } + case DBF_ULONG: case DBF_LONG: case DBF_ENUM: { @@ -191,6 +192,7 @@ static long writeData (dbCommon *record, format_t *format) return ERROR; break; } + case DBF_ULONG: case DBF_LONG: case DBF_ENUM: { diff --git a/src/devaaoStream.c b/src/devaaoStream.c index 267f23f..0edb81b 100644 --- a/src/devaaoStream.c +++ b/src/devaaoStream.c @@ -20,9 +20,9 @@ #include #include -#include "devStream.h" -#include #include +#include +#include "devStream.h" #include static long readData (dbCommon *record, format_t *format) @@ -57,6 +57,7 @@ static long readData (dbCommon *record, format_t *format) } break; } + case DBF_ULONG: case DBF_LONG: case DBF_ENUM: { @@ -191,6 +192,7 @@ static long writeData (dbCommon *record, format_t *format) return ERROR; break; } + case DBF_ULONG: case DBF_LONG: case DBF_ENUM: { diff --git a/src/devaiStream.c b/src/devaiStream.c index c22887a..7fc92cc 100644 --- a/src/devaiStream.c +++ b/src/devaiStream.c @@ -18,11 +18,18 @@ * * ***************************************************************/ -#include "devStream.h" -#include +#include #include +#include +#include "devStream.h" #include +#ifdef vxWorks +#include +#define isinf(x) isInf(x) +#define isnan(x) isNan(x) +#endif + static long readData (dbCommon *record, format_t *format) { aiRecord *ai = (aiRecord *) record; @@ -33,25 +40,28 @@ static long readData (dbCommon *record, format_t *format) { double val; if (streamScanf (record, format, &val)) return ERROR; - if (ai->aslo != 0.0) val *= ai->aslo; + if (ai->aslo != 0.0 && ai->aslo != 1.0) val *= ai->aslo; val += ai->aoff; - if (!INIT_RUN && ai->smoo != 0.0) - { + if (!(ai->smoo == 0.0 || ai->init || ai->udf || isinf(ai->val) || isnan(ai->val))) val = ai->val * ai->smoo + val * (1.0 - ai->smoo); - } ai->val = val; return DO_NOT_CONVERT; } + case DBF_ULONG: case DBF_LONG: { long rval; if (streamScanf (record, format, &rval)) return ERROR; + ai->rval = rval; if (ai->linr == menuConvertNO_CONVERSION) { - ai->val = (double) rval; + /* allow more bits than 32 */ + if (format->type == DBF_ULONG) + ai->val = (unsigned long)rval; + else + ai->val = rval; return DO_NOT_CONVERT; } - ai->rval = rval; return OK; } } @@ -61,23 +71,32 @@ static long readData (dbCommon *record, format_t *format) static long writeData (dbCommon *record, format_t *format) { aiRecord *ai = (aiRecord *) record; - double val; switch (format->type) { case DBF_DOUBLE: { - val = ai->val - ai->aoff; - if (ai->aslo != 0) val /= ai->aslo; + double val = ai->val - ai->aoff; + if (ai->aslo != 0.0 && ai->aslo != 1.0) val /= ai->aslo; return streamPrintf (record, format, val); } + case DBF_ULONG: + { + if (ai->linr == menuConvertNO_CONVERSION) + { + /* allow more bits than 32 */ + return streamPrintf (record, format, (unsigned long)ai->val); + } + return streamPrintf (record, format, (unsigned long)ai->rval); + } case DBF_LONG: { if (ai->linr == menuConvertNO_CONVERSION) { - return streamPrintf (record, format, (long) ai->val); + /* allow more bits than 32 */ + return streamPrintf (record, format, (long)ai->val); } - return streamPrintf (record, format, (long) ai->rval); + return streamPrintf (record, format, (long)ai->rval); } } return ERROR; diff --git a/src/devaoStream.c b/src/devaoStream.c index fb643dc..36129eb 100644 --- a/src/devaoStream.c +++ b/src/devaoStream.c @@ -18,9 +18,9 @@ * * ***************************************************************/ -#include "devStream.h" -#include #include +#include +#include "devStream.h" #include static long readData (dbCommon *record, format_t *format) @@ -33,19 +33,24 @@ static long readData (dbCommon *record, format_t *format) { double val; if (streamScanf (record, format, &val)) return ERROR; - if (ao->aslo != 0) val *= ao->aslo; + if (ao->aslo != 0.0 && ao->aslo != 1.0) val *= ao->aslo; ao->val = val + ao->aoff; return DO_NOT_CONVERT; } + case DBF_ULONG: case DBF_LONG: { long rval; if (streamScanf (record, format, &rval)) return ERROR; ao->rbv = rval; - if (INIT_RUN) ao->rval = rval; + ao->rval = rval; if (ao->linr == menuConvertNO_CONVERSION) { - ao->val = (double) rval; + /* allow more bits than 32 */ + if (format->type == DBF_ULONG) + ao->val = (unsigned long)rval; + else + ao->val = rval; return DO_NOT_CONVERT; } return OK; @@ -62,23 +67,27 @@ static long writeData (dbCommon *record, format_t *format) { case DBF_DOUBLE: { - double val; - if (INIT_RUN) val = ao->val; - else val = ao->oval; - val -= ao->aoff; - if (ao->aslo != 0) val /= ao->aslo; + double val = (INIT_RUN ? ao->val : ao->oval) - ao->aoff; + if (ao->aslo != 0.0 && ao->aslo != 1.0) val /= ao->aslo; return streamPrintf (record, format, val); } + case DBF_ULONG: + { + if (ao->linr == menuConvertNO_CONVERSION) + { + /* allow more bits than 32 */ + return streamPrintf (record, format, (unsigned long)(INIT_RUN ? ao->val : ao->oval)); + } + return streamPrintf (record, format, (unsigned long)ao->rval); + } case DBF_LONG: { if (ao->linr == menuConvertNO_CONVERSION) { - long val; - if (INIT_RUN) val = (long) ao->val; - else val = (long) ao->oval; - return streamPrintf (record, format, val); + /* allow more bits than 32 */ + return streamPrintf (record, format, (long)(INIT_RUN ? ao->val : ao->oval)); } - return streamPrintf (record, format, (long) ao->rval); + return streamPrintf (record, format, (long)ao->rval); } } return ERROR; diff --git a/src/devbiStream.c b/src/devbiStream.c index 5d3c527..4a8bbbc 100644 --- a/src/devbiStream.c +++ b/src/devbiStream.c @@ -18,9 +18,9 @@ * * ***************************************************************/ -#include "devStream.h" -#include #include +#include +#include "devStream.h" #include static long readData (dbCommon *record, format_t *format) @@ -30,6 +30,7 @@ static long readData (dbCommon *record, format_t *format) switch (format->type) { + case DBF_ULONG: case DBF_LONG: { if (streamScanf (record, format, &val)) return ERROR; @@ -69,13 +70,14 @@ static long writeData (dbCommon *record, format_t *format) switch (format->type) { + case DBF_ULONG: case DBF_LONG: { return streamPrintf (record, format, bi->rval); } case DBF_ENUM: { - return streamPrintf (record, format, (long) bi->val); + return streamPrintf (record, format, (long)bi->val); } case DBF_STRING: { diff --git a/src/devboStream.c b/src/devboStream.c index 2fa2484..ebc0dc2 100644 --- a/src/devboStream.c +++ b/src/devboStream.c @@ -18,9 +18,9 @@ * * ***************************************************************/ -#include "devStream.h" -#include #include +#include +#include "devStream.h" #include static long readData (dbCommon *record, format_t *format) @@ -30,6 +30,7 @@ static long readData (dbCommon *record, format_t *format) switch (format->type) { + case DBF_ULONG: case DBF_LONG: { if (streamScanf (record, format, &val)) return ERROR; @@ -70,13 +71,14 @@ static long writeData (dbCommon *record, format_t *format) switch (format->type) { + case DBF_ULONG: case DBF_LONG: { return streamPrintf (record, format, bo->rval); } case DBF_ENUM: { - return streamPrintf (record, format, (long) bo->val); + return streamPrintf (record, format, (long)bo->val); } case DBF_STRING: { diff --git a/src/devcalcoutStream.c b/src/devcalcoutStream.c index b884675..8cee99e 100644 --- a/src/devcalcoutStream.c +++ b/src/devcalcoutStream.c @@ -17,9 +17,9 @@ * * ***************************************************************/ -#include "devStream.h" #include #include +#include "devStream.h" #include static long readData (dbCommon *record, format_t *format) @@ -32,13 +32,17 @@ static long readData (dbCommon *record, format_t *format) { return streamScanf (record, format, &co->val); } + case DBF_ULONG: case DBF_LONG: case DBF_ENUM: { long lval; if (streamScanf (record, format, &lval)) return ERROR; - co->val = lval; + if (format->type == DBF_LONG) + co->val = lval; + else + co->val = (unsigned long)lval; return OK; } } @@ -55,8 +59,12 @@ static long writeData (dbCommon *record, format_t *format) { return streamPrintf (record, format, co->oval); } - case DBF_LONG: + case DBF_ULONG: case DBF_ENUM: + { + return streamPrintf (record, format, (unsigned long)co->oval); + } + case DBF_LONG: { return streamPrintf (record, format, (long)co->oval); } diff --git a/src/devlonginStream.c b/src/devlonginStream.c index b542c44..9f714fa 100644 --- a/src/devlonginStream.c +++ b/src/devlonginStream.c @@ -18,20 +18,25 @@ * * ***************************************************************/ -#include "devStream.h" #include +#include "devStream.h" #include static long readData (dbCommon *record, format_t *format) { longinRecord *li = (longinRecord *) record; - if (format->type == DBF_LONG || format->type == DBF_ENUM) + switch (format->type) { - long val; - if (streamScanf (record, format, &val)) return ERROR; - li->val = val; - return OK; + case DBF_ULONG: + case DBF_LONG: + case DBF_ENUM: + { + long val; + if (streamScanf (record, format, &val)) return ERROR; + li->val = val; + return OK; + } } return ERROR; } @@ -40,9 +45,13 @@ static long writeData (dbCommon *record, format_t *format) { longinRecord *li = (longinRecord *) record; - if (format->type == DBF_LONG || format->type == DBF_ENUM) + switch (format->type) { - return streamPrintf (record, format, (long) li->val); + case DBF_ULONG: + case DBF_ENUM: + return streamPrintf (record, format, (unsigned long)li->val); + case DBF_LONG: + return streamPrintf (record, format, (long)li->val); } return ERROR; } diff --git a/src/devlongoutStream.c b/src/devlongoutStream.c index c7003b2..c2b21ee 100644 --- a/src/devlongoutStream.c +++ b/src/devlongoutStream.c @@ -19,20 +19,25 @@ * * ***************************************************************/ -#include "devStream.h" #include +#include "devStream.h" #include static long readData (dbCommon *record, format_t *format) { longoutRecord *lo = (longoutRecord *) record; - if (format->type == DBF_LONG || format->type == DBF_ENUM) + switch (format->type) { - long val; - if (streamScanf (record, format, &val)) return ERROR; - lo->val = val; - return OK; + case DBF_ULONG: + case DBF_LONG: + case DBF_ENUM: + { + long val; + if (streamScanf (record, format, &val)) return ERROR; + lo->val = val; + return OK; + } } return ERROR; } @@ -41,9 +46,13 @@ static long writeData (dbCommon *record, format_t *format) { longoutRecord *lo = (longoutRecord *) record; - if (format->type == DBF_LONG || format->type == DBF_ENUM) + switch (format->type) { - return streamPrintf (record, format, (long) lo->val); + case DBF_ULONG: + case DBF_ENUM: + return streamPrintf (record, format, (unsigned long)lo->val); + case DBF_LONG: + return streamPrintf (record, format, (long)lo->val); } return ERROR; } diff --git a/src/devmbbiDirectStream.c b/src/devmbbiDirectStream.c index f3f491f..34e634d 100644 --- a/src/devmbbiDirectStream.c +++ b/src/devmbbiDirectStream.c @@ -19,16 +19,16 @@ * * ***************************************************************/ -#include "devStream.h" #include +#include "devStream.h" #include static long readData (dbCommon *record, format_t *format) { mbbiDirectRecord *mbbiD = (mbbiDirectRecord *) record; - long val; + unsigned long val; - if (format->type == DBF_LONG) + if (format->type == DBF_ULONG || format->type == DBF_LONG) { if (streamScanf (record, format, &val)) return ERROR; if (mbbiD->mask) @@ -40,7 +40,7 @@ static long readData (dbCommon *record, format_t *format) else { /* No MASK, (NOBT = 0): use VAL field */ - mbbiD->val = (short)val; + mbbiD->val = (unsigned short)val; return DO_NOT_CONVERT; } } @@ -50,9 +50,9 @@ static long readData (dbCommon *record, format_t *format) static long writeData (dbCommon *record, format_t *format) { mbbiDirectRecord *mbbiD = (mbbiDirectRecord *) record; - long val; + unsigned long val; - if (format->type == DBF_LONG) + if (format->type == DBF_ULONG || format->type == DBF_LONG) { if (mbbiD->mask) val = mbbiD->rval & mbbiD->mask; else val = mbbiD->val; diff --git a/src/devmbbiStream.c b/src/devmbbiStream.c index 9c7b853..ad6fd04 100644 --- a/src/devmbbiStream.c +++ b/src/devmbbiStream.c @@ -19,19 +19,20 @@ * * ***************************************************************/ -#include "devStream.h" -#include #include +#include +#include "devStream.h" #include static long readData (dbCommon *record, format_t *format) { mbbiRecord *mbbi = (mbbiRecord *) record; - long val; + unsigned long val; int i; switch (format->type) { + case DBF_ULONG: case DBF_LONG: { if (streamScanf (record, format, &val)) return ERROR; diff --git a/src/devmbboDirectStream.c b/src/devmbboDirectStream.c index 5973093..3c8de96 100644 --- a/src/devmbboDirectStream.c +++ b/src/devmbboDirectStream.c @@ -19,16 +19,16 @@ * * ***************************************************************/ -#include "devStream.h" #include +#include "devStream.h" #include static long readData (dbCommon *record, format_t *format) { mbboDirectRecord *mbboD = (mbboDirectRecord *) record; - long val; + unsigned long val; - if (format->type == DBF_LONG) + if (format->type == DBF_ULONG || format->type == DBF_LONG) { if (streamScanf (record, format, &val)) return ERROR; if (mbboD->mask) @@ -53,7 +53,7 @@ static long writeData (dbCommon *record, format_t *format) mbboDirectRecord *mbboD = (mbboDirectRecord *) record; long val; - if (format->type == DBF_LONG) + if (format->type == DBF_ULONG || format->type == DBF_LONG) { if (mbboD->mask) val = mbboD->rval & mbboD->mask; else val = mbboD->val; diff --git a/src/devmbboStream.c b/src/devmbboStream.c index 174696f..c00508b 100644 --- a/src/devmbboStream.c +++ b/src/devmbboStream.c @@ -19,19 +19,20 @@ * * ***************************************************************/ -#include "devStream.h" -#include #include +#include +#include "devStream.h" #include static long readData (dbCommon *record, format_t *format) { mbboRecord *mbbo = (mbboRecord *) record; - long val; + unsigned long val; int i; switch (format->type) { + case DBF_ULONG: case DBF_LONG: { if (streamScanf (record, format, &val)) return ERROR; @@ -76,11 +77,12 @@ static long readData (dbCommon *record, format_t *format) static long writeData (dbCommon *record, format_t *format) { mbboRecord *mbbo = (mbboRecord *) record; - long val; + unsigned long val; int i; switch (format->type) { + case DBF_ULONG: case DBF_LONG: { /* print VAL or RVAL ? */ diff --git a/src/devstringinStream.c b/src/devstringinStream.c index 82e6618..5f02eeb 100644 --- a/src/devstringinStream.c +++ b/src/devstringinStream.c @@ -18,8 +18,8 @@ * * ***************************************************************/ -#include "devStream.h" #include +#include "devStream.h" #include static long readData (dbCommon *record, format_t *format) diff --git a/src/devstringoutStream.c b/src/devstringoutStream.c index 34c94ab..fcc2d6b 100644 --- a/src/devstringoutStream.c +++ b/src/devstringoutStream.c @@ -18,8 +18,8 @@ * * ***************************************************************/ -#include "devStream.h" #include +#include "devStream.h" #include static long readData (dbCommon *record, format_t *format) diff --git a/src/devwaveformStream.c b/src/devwaveformStream.c index 81edddb..b6fadae 100644 --- a/src/devwaveformStream.c +++ b/src/devwaveformStream.c @@ -18,10 +18,10 @@ * * ***************************************************************/ -#include "devStream.h" -#include #include #include +#include +#include "devStream.h" #include static long readData (dbCommon *record, format_t *format) @@ -57,6 +57,7 @@ static long readData (dbCommon *record, format_t *format) } break; } + case DBF_ULONG: case DBF_LONG: case DBF_ENUM: { diff --git a/streamApp/tests/testFormats b/streamApp/tests/testFormats index 7fc5f0d..9364e2f 100755 --- a/streamApp/tests/testFormats +++ b/streamApp/tests/testFormats @@ -70,11 +70,11 @@ ioccmd {dbpf DZ:lo -1} if {$tcl_platform(machine) == "x86_64"} { assure "-1 -1 -00001 ffffffffffffffff FFFFFF 11111111111111111111111111111111 11111111111111111111111111111111 111111 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" } else { -assure "-1 -1 -00001 ffffffff FFFFFFFF 11111111111111111111111111111111 11111111111111111111111111111111 111111 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" +assure "-1 -1 -00001 ffffffff FFFFFF 11111111111111111111111111111111 11111111111111111111111111111111 111111 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" } ioccmd {dbpf DZ:lo -1234} if {$tcl_platform(machine) == "x86_64"} { -assure "-1234 -1234 -01234 fffffffffffffb2e FFFB2E 1111111111111111111111111111111111111111111111111111101100101110 1111111111111111111111111111111111111111111111111111101100101110 101110 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.!!..!.!!!. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.!!..!.!!!.\n" +assure "-1234 -1234 -01234 fffffffffffffb2e FFFB2E 11111111111111111111101100101110 11111111111111111111101100101110 101110 !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!. !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!.\n" } else { assure "-1234 -1234 -01234 fffffb2e FFFB2E 11111111111111111111101100101110 11111111111111111111101100101110 101110 !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!. !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!.\n" }