change all length agruments and return types to size_t or ssize_t

This commit is contained in:
2018-06-11 13:48:06 +02:00
parent b91f087736
commit 5a23b89087
26 changed files with 252 additions and 238 deletions

View File

@ -27,7 +27,7 @@ class BCDConverter : public StreamFormatConverter
{ {
int parse (const StreamFormat&, StreamBuffer&, const char*&, bool); int parse (const StreamFormat&, StreamBuffer&, const char*&, bool);
bool printLong(const StreamFormat&, StreamBuffer&, long); bool printLong(const StreamFormat&, StreamBuffer&, long);
long scanLong(const StreamFormat&, const char*, long&); ssize_t scanLong(const StreamFormat&, const char*, long&);
}; };
int BCDConverter:: int BCDConverter::
@ -41,7 +41,7 @@ printLong(const StreamFormat& fmt, StreamBuffer& output, long value)
{ {
unsigned char bcd; unsigned char bcd;
bool neg = false; bool neg = false;
long i; ssize_t i;
unsigned long prec = fmt.prec < 0 ? 2 * sizeof(value) : fmt.prec; // number of nibbles unsigned long prec = fmt.prec < 0 ? 2 * sizeof(value) : fmt.prec; // number of nibbles
unsigned long width = (prec + (fmt.flags & sign_flag ? 2 : 1)) / 2; unsigned long width = (prec + (fmt.flags & sign_flag ? 2 : 1)) / 2;
if (fmt.width > width) width = fmt.width; if (fmt.width > width) width = fmt.width;
@ -73,7 +73,7 @@ printLong(const StreamFormat& fmt, StreamBuffer& output, long value)
{ {
// most significant byte first (big endian) // most significant byte first (big endian)
output.append('\0', width); output.append('\0', width);
if (neg) output[-width] |= 0xf0; if (neg) output[-(long)width] |= 0xf0;
i = 0; i = 0;
while (width-- && prec) while (width-- && prec)
{ {
@ -91,10 +91,10 @@ printLong(const StreamFormat& fmt, StreamBuffer& output, long value)
return true; return true;
} }
long BCDConverter:: ssize_t BCDConverter::
scanLong(const StreamFormat& fmt, const char* input, long& value) scanLong(const StreamFormat& fmt, const char* input, long& value)
{ {
long length = 0; ssize_t consumed = 0;
long val = 0; long val = 0;
unsigned char bcd1, bcd10; unsigned char bcd1, bcd10;
long width = fmt.width; long width = fmt.width;
@ -105,7 +105,7 @@ scanLong(const StreamFormat& fmt, const char* input, long& value)
int shift = 1; int shift = 1;
while (width--) while (width--)
{ {
bcd1 = bcd10 = (unsigned char) input[length++]; bcd1 = bcd10 = input[consumed++];
bcd1 &= 0x0F; bcd1 &= 0x0F;
bcd10 >>= 4; bcd10 >>= 4;
if (bcd1 > 9 || shift * bcd1 < bcd1) break; if (bcd1 > 9 || shift * bcd1 < bcd1) break;
@ -128,10 +128,10 @@ scanLong(const StreamFormat& fmt, const char* input, long& value)
while (width--) while (width--)
{ {
long temp; long temp;
bcd1 = bcd10 = (unsigned char) input[length]; bcd1 = bcd10 = input[consumed];
bcd1 &= 0x0F; bcd1 &= 0x0F;
bcd10 >>= 4; bcd10 >>= 4;
if (length == 0 && fmt.flags & sign_flag && bcd10) if (consumed == 0 && fmt.flags & sign_flag && bcd10)
{ {
sign = -1; sign = -1;
bcd10 = 0; bcd10 = 0;
@ -140,17 +140,17 @@ scanLong(const StreamFormat& fmt, const char* input, long& value)
temp = val * 100 + (bcd1 + 10 * bcd10); temp = val * 100 + (bcd1 + 10 * bcd10);
if (temp < val) if (temp < val)
{ {
length = 0; consumed = 0;
break; break;
} }
val = temp; val = temp;
length++; consumed++;
} }
val *= sign; val *= sign;
} }
if (length == 0) return -1; if (consumed == 0) return -1;
value = val; value = val;
return length; return consumed;
} }
RegisterConverter (BCDConverter, "D"); RegisterConverter (BCDConverter, "D");

View File

@ -29,7 +29,7 @@ class BinaryConverter : public StreamFormatConverter
{ {
int parse(const StreamFormat&, StreamBuffer&, const char*&, bool); int parse(const StreamFormat&, StreamBuffer&, const char*&, bool);
bool printLong(const StreamFormat&, StreamBuffer&, long); bool printLong(const StreamFormat&, StreamBuffer&, long);
long scanLong(const StreamFormat&, const char*, long&); ssize_t scanLong(const StreamFormat&, const char*, long&);
}; };
int BinaryConverter:: int BinaryConverter::
@ -42,7 +42,7 @@ parse(const StreamFormat& fmt, StreamBuffer& info,
info.append("01"); info.append("01");
return unsigned_format; return unsigned_format;
} }
// user defined characters for %B (next 2 in source) // user defined characters for %B (next 2 in source)
if (*source) if (*source)
{ {
@ -70,7 +70,7 @@ printLong(const StreamFormat& fmt, StreamBuffer& output, long value)
prec = 32; prec = 32;
#if (LONG_BIT > 32) #if (LONG_BIT > 32)
if (x > 0xFFFFFFFF) { prec = 64; x >>=32; } if (x > 0xFFFFFFFF) { prec = 64; x >>=32; }
#endif #endif
if (x <= 0x0000FFFF) { prec -= 16; x <<=16; } if (x <= 0x0000FFFF) { prec -= 16; x <<=16; }
if (x <= 0x00FFFFFF) { prec -= 8; x <<=8; } if (x <= 0x00FFFFFF) { prec -= 8; x <<=8; }
if (x <= 0x0FFFFFFF) { prec -= 4; x <<=4; } if (x <= 0x0FFFFFFF) { prec -= 4; x <<=4; }
@ -132,39 +132,39 @@ printLong(const StreamFormat& fmt, StreamBuffer& output, long value)
return true; return true;
} }
long BinaryConverter:: ssize_t BinaryConverter::
scanLong(const StreamFormat& fmt, const char* input, long& value) scanLong(const StreamFormat& fmt, const char* input, long& value)
{ {
long val = 0; long val = 0;
long width = fmt.width; long width = fmt.width;
if (width == 0) width = -1; if (width == 0) width = -1;
long length = 0; size_t consumed = 0;
char zero = fmt.info[0]; char zero = fmt.info[0];
char one = fmt.info[1]; char one = fmt.info[1];
if (!isspace(zero) && !isspace(one)) if (!isspace(zero) && !isspace(one))
while (isspace(input[length])) length++; // skip whitespaces while (isspace(input[consumed])) consumed++; // skip whitespaces
if (input[length] != zero && input[length] != one) return -1; if (input[consumed] != zero && input[consumed] != one) return -1;
if (fmt.flags & alt_flag) if (fmt.flags & alt_flag)
{ {
// little endian (least significan bit first) // little endian (least significan bit first)
long mask = 1; long mask = 1;
while (width-- && (input[length] == zero || input[length] == one)) while (width-- && (input[consumed] == zero || input[consumed] == one))
{ {
if (input[length++] == one) val |= mask; if (input[consumed++] == one) val |= mask;
mask <<= 1; mask <<= 1;
} }
} }
else else
{ {
// big endian (most significan bit first) // big endian (most significan bit first)
while (width-- && (input[length] == zero || input[length] == one)) while (width-- && (input[consumed] == zero || input[consumed] == one))
{ {
val <<= 1; val <<= 1;
if (input[length++] == one) val |= 1; if (input[consumed++] == one) val |= 1;
} }
} }
value = val; value = val;
return length; return consumed;
} }
RegisterConverter (BinaryConverter, "bB"); RegisterConverter (BinaryConverter, "bB");

View File

@ -39,9 +39,9 @@ static int strncasecmp(const char *s1, const char *s2, size_t n)
#endif #endif
#endif #endif
typedef unsigned int (*checksumFunc)(const unsigned char* data, unsigned int len, unsigned int init); typedef unsigned int (*checksumFunc)(const unsigned char* data, size_t len, unsigned int init);
static unsigned int sum(const unsigned char* data, unsigned int len, unsigned int sum) static unsigned int sum(const unsigned char* data, size_t len, unsigned int sum)
{ {
while (len--) while (len--)
{ {
@ -50,7 +50,7 @@ static unsigned int sum(const unsigned char* data, unsigned int len, unsigned in
return sum; return sum;
} }
static unsigned int xor8(const unsigned char* data, unsigned int len, unsigned int sum) static unsigned int xor8(const unsigned char* data, size_t len, unsigned int sum)
{ {
while (len--) while (len--)
{ {
@ -59,12 +59,12 @@ static unsigned int xor8(const unsigned char* data, unsigned int len, unsigned i
return sum; return sum;
} }
static unsigned int xor7(const unsigned char* data, unsigned int len, unsigned int sum) static unsigned int xor7(const unsigned char* data, size_t len, unsigned int sum)
{ {
return xor8(data, len, sum) & 0x7F; return xor8(data, len, sum) & 0x7F;
} }
static unsigned int crc_0x07(const unsigned char* data, unsigned int len, unsigned int crc) static unsigned int crc_0x07(const unsigned char* data, size_t len, unsigned int crc)
{ {
// x^8 + x^2 + x^1 + x^0 (0x07) // x^8 + x^2 + x^1 + x^0 (0x07)
const static unsigned char table[256] = { const static unsigned char table[256] = {
@ -105,7 +105,7 @@ static unsigned int crc_0x07(const unsigned char* data, unsigned int len, unsign
return crc; return crc;
} }
static unsigned int crc_0x31(const unsigned char* data, unsigned int len, unsigned int crc) static unsigned int crc_0x31(const unsigned char* data, size_t len, unsigned int crc)
{ {
// x^8 + x^5 + x^4 + x^0 (0x31) // x^8 + x^5 + x^4 + x^0 (0x31)
const static unsigned char table[256] = { const static unsigned char table[256] = {
@ -146,7 +146,7 @@ static unsigned int crc_0x31(const unsigned char* data, unsigned int len, unsign
return crc; return crc;
} }
static unsigned int crc_0x8005(const unsigned char* data, unsigned int len, unsigned int crc) static unsigned int crc_0x8005(const unsigned char* data, size_t len, unsigned int crc)
{ {
// x^16 + x^15 + x^2 + x^0 (0x8005) // x^16 + x^15 + x^2 + x^0 (0x8005)
const static unsigned short table[256] = { const static unsigned short table[256] = {
@ -187,7 +187,7 @@ static unsigned int crc_0x8005(const unsigned char* data, unsigned int len, unsi
return crc; return crc;
} }
static unsigned int crc_0x8005_r(const unsigned char* data, unsigned int len, unsigned int crc) static unsigned int crc_0x8005_r(const unsigned char* data, size_t len, unsigned int crc)
{ {
// x^16 + x^15 + x^2 + x^0 (0x8005) // x^16 + x^15 + x^2 + x^0 (0x8005)
// reflected // reflected
@ -229,7 +229,7 @@ static unsigned int crc_0x8005_r(const unsigned char* data, unsigned int len, un
return crc; return crc;
} }
static unsigned int crc_0x1021(const unsigned char* data, unsigned int len, unsigned int crc) static unsigned int crc_0x1021(const unsigned char* data, size_t len, unsigned int crc)
{ {
// x^16 + x^12 + x^5 + x^0 (0x1021) // x^16 + x^12 + x^5 + x^0 (0x1021)
const static unsigned short table[256] = { const static unsigned short table[256] = {
@ -270,7 +270,7 @@ static unsigned int crc_0x1021(const unsigned char* data, unsigned int len, unsi
return crc; return crc;
} }
static unsigned int crc_0x04C11DB7(const unsigned char* data, unsigned int len, unsigned int crc) static unsigned int crc_0x04C11DB7(const unsigned char* data, size_t len, unsigned int crc)
{ {
// x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + // x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 +
// x^8 + x^7 + x^5 + x^4 + x^2 + x^1 + x^0 (0x04C11DB7) // x^8 + x^7 + x^5 + x^4 + x^2 + x^1 + x^0 (0x04C11DB7)
@ -344,7 +344,7 @@ static unsigned int crc_0x04C11DB7(const unsigned char* data, unsigned int len,
return crc; return crc;
} }
static unsigned int crc_0x04C11DB7_r(const unsigned char* data, unsigned int len, unsigned int crc) static unsigned int crc_0x04C11DB7_r(const unsigned char* data, size_t len, unsigned int crc)
{ {
// x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + // x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 +
// x^8 + x^7 + x^5 + x^4 + x^2 + x^1 + x^0 (0x04C11DB7) // x^8 + x^7 + x^5 + x^4 + x^2 + x^1 + x^0 (0x04C11DB7)
@ -419,13 +419,13 @@ static unsigned int crc_0x04C11DB7_r(const unsigned char* data, unsigned int len
return crc; return crc;
} }
static unsigned int adler32(const unsigned char* data, unsigned int len, unsigned int init) static unsigned int adler32(const unsigned char* data, size_t len, unsigned int init)
{ {
unsigned int a = init & 0xFFFF; unsigned int a = init & 0xFFFF;
unsigned int b = (init >> 16) & 0xFFFF; unsigned int b = (init >> 16) & 0xFFFF;
while (len) { while (len) {
unsigned int tlen = len > 5550 ? 5550 : len; size_t tlen = len > 5550 ? 5550 : len;
len -= tlen; len -= tlen;
do { do {
a += *data++; a += *data++;
@ -440,10 +440,10 @@ static unsigned int adler32(const unsigned char* data, unsigned int len, unsigne
return b << 16 | a; return b << 16 | a;
} }
static unsigned int hexsum(const unsigned char* data, unsigned int len, unsigned int sum) static unsigned int hexsum(const unsigned char* data, size_t len, unsigned int sum)
{ {
// Add all hex digits, ignore all other bytes. // Add all hex digits, ignore all other bytes.
unsigned int d; unsigned int d;
while (len--) while (len--)
{ {
d = toupper(*data++); d = toupper(*data++);
@ -500,7 +500,7 @@ class ChecksumConverter : public StreamFormatConverter
{ {
int parse (const StreamFormat&, StreamBuffer&, const char*&, bool); int parse (const StreamFormat&, StreamBuffer&, const char*&, bool);
bool printPseudo(const StreamFormat&, StreamBuffer&); bool printPseudo(const StreamFormat&, StreamBuffer&);
long scanPseudo(const StreamFormat&, StreamBuffer&, long& cursor); ssize_t scanPseudo(const StreamFormat&, StreamBuffer&, size_t& cursor);
}; };
int ChecksumConverter:: int ChecksumConverter::
@ -536,7 +536,7 @@ parse(const StreamFormat&, StreamBuffer& info, const char*& source, bool)
notflag = true; notflag = true;
} }
unsigned char fnum; unsigned char fnum;
int len = p-source; size_t len = p-source;
unsigned int init, xorout; unsigned int init, xorout;
for (fnum = 0; fnum < sizeof(checksumMap)/sizeof(checksum); fnum++) for (fnum = 0; fnum < sizeof(checksumMap)/sizeof(checksum); fnum++)
{ {
@ -575,13 +575,13 @@ printPseudo(const StreamFormat& format, StreamBuffer& output)
unsigned int xorout = extract<unsigned int>(info); unsigned int xorout = extract<unsigned int>(info);
unsigned char fnum = extract<unsigned char>(info); unsigned char fnum = extract<unsigned char>(info);
int start = format.width; size_t start = format.width;
int length = output.length()-format.width; size_t length = output.length()-format.width;
if (format.prec > 0) length -= format.prec; if (format.prec > 0) length -= format.prec;
debug("ChecksumConverter %s: output to check: \"%s\"\n", debug("ChecksumConverter %s: output to check: \"%s\"\n",
checksumMap[fnum].name, output.expand(start,length)()); checksumMap[fnum].name, output.expand(start,length)());
sum = (xorout ^ checksumMap[fnum].func( sum = (xorout ^ checksumMap[fnum].func(
reinterpret_cast<unsigned char*>(output(start)), length, init)) reinterpret_cast<unsigned char*>(output(start)), length, init))
& mask[checksumMap[fnum].bytes]; & mask[checksumMap[fnum].bytes];
@ -591,7 +591,7 @@ printPseudo(const StreamFormat& format, StreamBuffer& output)
int i; int i;
unsigned outchar; unsigned outchar;
if (format.flags & sign_flag) // decimal if (format.flags & sign_flag) // decimal
{ {
// get number of decimal digits from number of bytes: ceil(xbytes*2.5) // get number of decimal digits from number of bytes: ceil(xbytes*2.5)
@ -599,7 +599,7 @@ printPseudo(const StreamFormat& format, StreamBuffer& output)
output.print("%0*d", i, sum); output.print("%0*d", i, sum);
debug("ChecksumConverter %s: decimal appending %0*d\n", debug("ChecksumConverter %s: decimal appending %0*d\n",
checksumMap[fnum].name, i, sum); checksumMap[fnum].name, i, sum);
} }
else else
if (format.flags & alt_flag) // lsb first (little endian) if (format.flags & alt_flag) // lsb first (little endian)
{ {
@ -641,28 +641,28 @@ printPseudo(const StreamFormat& format, StreamBuffer& output)
return true; return true;
} }
long ChecksumConverter:: ssize_t ChecksumConverter::
scanPseudo(const StreamFormat& format, StreamBuffer& input, long& cursor) scanPseudo(const StreamFormat& format, StreamBuffer& input, size_t& cursor)
{ {
unsigned int sum; unsigned int sum;
const char* info = format.info; const char* info = format.info;
unsigned int init = extract<unsigned int>(info); unsigned int init = extract<unsigned int>(info);
unsigned int xorout = extract<unsigned int>(info); unsigned int xorout = extract<unsigned int>(info);
int start = format.width; size_t start = format.width;
unsigned char fnum = extract<unsigned char>(info); unsigned char fnum = extract<unsigned char>(info);
long length = cursor-format.width; size_t length = cursor-format.width;
if (format.prec > 0) length -= format.prec; if (format.prec > 0) length -= format.prec;
debug("ChecksumConverter %s: input to check: \"%s\n", debug("ChecksumConverter %s: input to check: \"%s\n",
checksumMap[fnum].name, input.expand(start,length)()); checksumMap[fnum].name, input.expand(start,length)());
int expectedLength = size_t expectedLength =
// get number of decimal digits from number of bytes: ceil(bytes*2.5) // get number of decimal digits from number of bytes: ceil(bytes*2.5)
format.flags & sign_flag ? (checksumMap[fnum].bytes + 1) * 25 / 10 - 2 : format.flags & sign_flag ? (checksumMap[fnum].bytes + 1) * 25 / 10 - 2 :
format.flags & (zero_flag|left_flag) ? 2 * checksumMap[fnum].bytes : format.flags & (zero_flag|left_flag) ? 2 * checksumMap[fnum].bytes :
checksumMap[fnum].bytes; checksumMap[fnum].bytes;
if (input.length() - cursor < expectedLength) if (input.length() - cursor < expectedLength)
{ {
debug("ChecksumConverter %s: Input '%s' too short for checksum\n", debug("ChecksumConverter %s: Input '%s' too short for checksum\n",
@ -671,15 +671,15 @@ scanPseudo(const StreamFormat& format, StreamBuffer& input, long& cursor)
} }
sum = (xorout ^ checksumMap[fnum].func( sum = (xorout ^ checksumMap[fnum].func(
reinterpret_cast<unsigned char*>(input(start)), length, init)) (unsigned char*)input(start), length, init))
& mask[checksumMap[fnum].bytes]; & mask[checksumMap[fnum].bytes];
debug("ChecksumConverter %s: input checksum is 0x%0*X\n", debug("ChecksumConverter %s: input checksum is 0x%0*X\n",
checksumMap[fnum].name, 2*checksumMap[fnum].bytes, sum); checksumMap[fnum].name, 2*checksumMap[fnum].bytes, sum);
int i, j; int i, j;
unsigned inchar; unsigned int inchar;
if (format.flags & sign_flag) // decimal if (format.flags & sign_flag) // decimal
{ {
unsigned int sumin = 0; unsigned int sumin = 0;
@ -691,12 +691,12 @@ scanPseudo(const StreamFormat& format, StreamBuffer& input, long& cursor)
} }
if (sumin != sum) if (sumin != sum)
{ {
debug("ChecksumConverter %s: Input %0*u does not match checksum %0*u\n", debug("ChecksumConverter %s: Input %0*u does not match checksum %0*u\n",
checksumMap[fnum].name, i, sumin, expectedLength, sum); checksumMap[fnum].name, i, sumin, expectedLength, sum);
return -1; return -1;
} }
} }
else else
if (format.flags & alt_flag) // lsb first (little endian) if (format.flags & alt_flag) // lsb first (little endian)
{ {
for (i = 0; i < checksumMap[fnum].bytes; i++) for (i = 0; i < checksumMap[fnum].bytes; i++)
@ -705,7 +705,7 @@ scanPseudo(const StreamFormat& format, StreamBuffer& input, long& cursor)
{ {
if (sscanf(input(cursor+2*i), "%2X", &inchar) != 1) if (sscanf(input(cursor+2*i), "%2X", &inchar) != 1)
{ {
debug("ChecksumConverter %s: Input byte '%s' is not a hex byte\n", debug("ChecksumConverter %s: Input byte '%s' is not a hex byte\n",
checksumMap[fnum].name, input.expand(cursor+2*i,2)()); checksumMap[fnum].name, input.expand(cursor+2*i,2)());
return -1; return -1;
} }
@ -715,13 +715,13 @@ scanPseudo(const StreamFormat& format, StreamBuffer& input, long& cursor)
{ {
if ((input[cursor+2*i] & 0xf0) != 0x30) if ((input[cursor+2*i] & 0xf0) != 0x30)
{ {
debug("ChecksumConverter %s: Input byte 0x%02X is not in range 0x30 - 0x3F\n", debug("ChecksumConverter %s: Input byte 0x%02X is not in range 0x30 - 0x3F\n",
checksumMap[fnum].name, input[cursor+2*i]); checksumMap[fnum].name, input[cursor+2*i]);
return -1; return -1;
} }
if ((input[cursor+2*i+1] & 0xf0) != 0x30) if ((input[cursor+2*i+1] & 0xf0) != 0x30)
{ {
debug("ChecksumConverter %s: Input byte 0x%02X is not in range 0x30 - 0x3F\n", debug("ChecksumConverter %s: Input byte 0x%02X is not in range 0x30 - 0x3F\n",
checksumMap[fnum].name, input[cursor+2*i+1]); checksumMap[fnum].name, input[cursor+2*i+1]);
return -1; return -1;
} }
@ -733,7 +733,7 @@ scanPseudo(const StreamFormat& format, StreamBuffer& input, long& cursor)
} }
if (inchar != ((sum >> 8*i) & 0xff)) if (inchar != ((sum >> 8*i) & 0xff))
{ {
debug("ChecksumConverter %s: Input byte 0x%02X does not match checksum 0x%0*X\n", debug("ChecksumConverter %s: Input byte 0x%02X does not match checksum 0x%0*X\n",
checksumMap[fnum].name, inchar, 2*checksumMap[fnum].bytes, sum); checksumMap[fnum].name, inchar, 2*checksumMap[fnum].bytes, sum);
return -1; return -1;
} }
@ -752,13 +752,13 @@ scanPseudo(const StreamFormat& format, StreamBuffer& input, long& cursor)
{ {
if ((input[cursor+2*i] & 0xf0) != 0x30) if ((input[cursor+2*i] & 0xf0) != 0x30)
{ {
debug("ChecksumConverter %s: Input byte 0x%02X is not in range 0x30 - 0x3F\n", debug("ChecksumConverter %s: Input byte 0x%02X is not in range 0x30 - 0x3F\n",
checksumMap[fnum].name, input[cursor+2*i]); checksumMap[fnum].name, input[cursor+2*i]);
return -1; return -1;
} }
if ((input[cursor+2*i+1] & 0xf0) != 0x30) if ((input[cursor+2*i+1] & 0xf0) != 0x30)
{ {
debug("ChecksumConverter %s: Input byte 0x%02X is not in range 0x30 - 0x3F\n", debug("ChecksumConverter %s: Input byte 0x%02X is not in range 0x30 - 0x3F\n",
checksumMap[fnum].name, input[cursor+2*i+1]); checksumMap[fnum].name, input[cursor+2*i+1]);
return -1; return -1;
} }

View File

@ -29,7 +29,7 @@ class EnumConverter : public StreamFormatConverter
{ {
int parse(const StreamFormat&, StreamBuffer&, const char*&, bool); int parse(const StreamFormat&, StreamBuffer&, const char*&, bool);
bool printLong(const StreamFormat&, StreamBuffer&, long); bool printLong(const StreamFormat&, StreamBuffer&, long);
long scanLong(const StreamFormat&, const char*, long&); ssize_t scanLong(const StreamFormat&, const char*, long&);
}; };
// info format: <numEnums><index><string>0<index><string>0... // info format: <numEnums><index><string>0<index><string>0...
@ -45,10 +45,10 @@ parse(const StreamFormat& fmt, StreamBuffer& info,
return false; return false;
} }
long numEnums = 0; long numEnums = 0;
int n = info.length(); // put numEnums here later size_t n = info.length(); // put numEnums here later
info.append(&numEnums, sizeof(numEnums)); info.append(&numEnums, sizeof(numEnums));
long index = 0; long index = 0;
int i = 0; size_t i = 0;
i = info.length(); // put index here later i = info.length(); // put index here later
info.append(&index, sizeof(index)); info.append(&index, sizeof(index));
while (*source) while (*source)
@ -56,7 +56,7 @@ parse(const StreamFormat& fmt, StreamBuffer& info,
if (*source == '=' && (fmt.flags & alt_flag)) if (*source == '=' && (fmt.flags & alt_flag))
{ {
char* p; char* p;
if (*++source == '?') if (*++source == '?')
{ {
// default choice // default choice
@ -78,7 +78,7 @@ parse(const StreamFormat& fmt, StreamBuffer& info,
-numEnums, info.expand()()); -numEnums, info.expand()());
return enum_format; return enum_format;
} }
index = strtol(source, &p, 0); index = strtol(source, &p, 0);
if (p == source || (*p != '|' && *p != '}')) if (p == source || (*p != '|' && *p != '}'))
{ {
@ -93,7 +93,7 @@ parse(const StreamFormat& fmt, StreamBuffer& info,
{ {
numEnums++; numEnums++;
info.append('\0'); info.append('\0');
if (*source++ == '}') if (*source++ == '}')
{ {
memcpy(info(n), &numEnums, sizeof(numEnums)); memcpy(info(n), &numEnums, sizeof(numEnums));
@ -101,7 +101,7 @@ parse(const StreamFormat& fmt, StreamBuffer& info,
numEnums, info.expand()()); numEnums, info.expand()());
return enum_format; return enum_format;
} }
index ++; index++;
i = info.length(); i = info.length();
info.append(&index, sizeof(index)); info.append(&index, sizeof(index));
} }
@ -123,8 +123,8 @@ printLong(const StreamFormat& fmt, StreamBuffer& output, long value)
long numEnums = extract<long>(s); long numEnums = extract<long>(s);
long index = extract<long>(s); long index = extract<long>(s);
bool noDefault = numEnums >= 0; bool noDefault = numEnums >= 0;
if (numEnums < 0) numEnums=-numEnums-1; if (numEnums < 0) numEnums=-numEnums-1;
while (numEnums-- && (value != index)) while (numEnums-- && (value != index))
{ {
while(*s) while(*s)
@ -148,7 +148,7 @@ printLong(const StreamFormat& fmt, StreamBuffer& output, long value)
return true; return true;
} }
long EnumConverter:: ssize_t EnumConverter::
scanLong(const StreamFormat& fmt, const char* input, long& value) scanLong(const StreamFormat& fmt, const char* input, long& value)
{ {
debug("EnumConverter::scanLong(%%%c, \"%s\")\n", debug("EnumConverter::scanLong(%%%c, \"%s\")\n",
@ -156,31 +156,31 @@ scanLong(const StreamFormat& fmt, const char* input, long& value)
const char* s = fmt.info; const char* s = fmt.info;
long numEnums = extract<long>(s); long numEnums = extract<long>(s);
long index; long index;
long length; ssize_t consumed;
bool match; bool match;
while (numEnums--) while (numEnums--)
{ {
index = extract<long>(s); index = extract<long>(s);
debug("EnumConverter::scanLong: check #%ld \"%s\"\n", index, s); debug("EnumConverter::scanLong: check #%ld \"%s\"\n", index, s);
length = 0; consumed = 0;
match = true; match = true;
while(*s) while(*s)
{ {
if (*s == StreamProtocolParser::skip) if (*s == StreamProtocolParser::skip)
{ {
s++; s++;
length++; consumed++;
continue; continue;
} }
if (*s == esc) s++; if (*s == esc) s++;
if (*s++ != input[length++]) match = false; if (*s++ != input[consumed++]) match = false;
} }
if (match) if (match)
{ {
debug("EnumConverter::scanLong: value %ld matches\n", index); debug("EnumConverter::scanLong: value %ld matches\n", index);
value = index; value = index;
return length; return consumed;
} }
s++; s++;
} }

View File

@ -3,7 +3,7 @@
* * * *
* (C) 2008 Dirk Zimoch (dirk.zimoch@psi.ch) * * (C) 2008 Dirk Zimoch (dirk.zimoch@psi.ch) *
* * * *
* This is a custom exponential format converter for * * This is a custom exponential format converter for *
* StreamDevice. * * StreamDevice. *
* The number is represented as two signed integers, mantissa * * The number is represented as two signed integers, mantissa *
* and exponent, like in +00011-01 * * and exponent, like in +00011-01 *
@ -39,7 +39,7 @@
class MantissaExponentConverter : public StreamFormatConverter class MantissaExponentConverter : public StreamFormatConverter
{ {
virtual int parse(const StreamFormat&, StreamBuffer&, const char*&, bool); virtual int parse(const StreamFormat&, StreamBuffer&, const char*&, bool);
virtual long scanDouble(const StreamFormat&, const char*, double&); virtual ssize_t scanDouble(const StreamFormat&, const char*, double&);
virtual bool printDouble(const StreamFormat&, StreamBuffer&, double); virtual bool printDouble(const StreamFormat&, StreamBuffer&, double);
}; };
@ -50,13 +50,13 @@ parse(const StreamFormat&, StreamBuffer&,
return double_format; return double_format;
} }
long MantissaExponentConverter:: ssize_t MantissaExponentConverter::
scanDouble(const StreamFormat& fmt, const char* input, double& value) scanDouble(const StreamFormat& fmt, const char* input, double& value)
{ {
int mantissa; int mantissa;
int exponent; int exponent;
int length = -1; int length = -1;
sscanf(input, "%d%d%n", &mantissa, &exponent, &length); sscanf(input, "%d%d%n", &mantissa, &exponent, &length);
if (fmt.flags & skip_flag) return length; if (fmt.flags & skip_flag) return length;
if (length == -1) return -1; if (length == -1) return -1;
@ -70,15 +70,15 @@ printDouble(const StreamFormat& fmt, StreamBuffer& output, double value)
// Have to divide value into mantissa and exponent // Have to divide value into mantissa and exponent
// precision field is number of characters in mantissa // precision field is number of characters in mantissa
// number of characters in exponent is at least 2 // number of characters in exponent is at least 2
int spaces; size_t spaces;
StreamBuffer buf; StreamBuffer buf;
int prec = fmt.prec; int prec = fmt.prec;
if (prec < 1) prec = 6; if (prec < 1) prec = 6;
buf.print("%.*e", prec-1, fabs(value)/pow(10.0, prec-1)); buf.print("%.*e", prec-1, fabs(value)/pow(10.0, prec-1));
buf.remove(1,1); buf.remove(1,1);
buf.remove(buf.find('e'),1); buf.remove(buf.find('e'),1);
spaces = fmt.width-buf.length(); spaces = fmt.width-buf.length();
if (fmt.flags & (space_flag|sign_flag) || value < 0.0) spaces--; if (fmt.flags & (space_flag|sign_flag) || value < 0.0) spaces--;
if (spaces < 0) spaces = 0; if (spaces < 0) spaces = 0;

View File

@ -27,7 +27,7 @@ class RawConverter : public StreamFormatConverter
{ {
int parse(const StreamFormat&, StreamBuffer&, const char*&, bool); int parse(const StreamFormat&, StreamBuffer&, const char*&, bool);
bool printLong(const StreamFormat&, StreamBuffer&, long); bool printLong(const StreamFormat&, StreamBuffer&, long);
long scanLong(const StreamFormat&, const char*, long&); ssize_t scanLong(const StreamFormat&, const char*, long&);
}; };
int RawConverter:: int RawConverter::
@ -44,7 +44,7 @@ printLong(const StreamFormat& fmt, StreamBuffer& output, long value)
unsigned long width = prec; // number of bytes in output unsigned long width = prec; // number of bytes in output
if (prec > sizeof(long)) prec=sizeof(long); if (prec > sizeof(long)) prec=sizeof(long);
if (fmt.width > width) width = fmt.width; if (fmt.width > width) width = fmt.width;
char byte = 0; char byte = 0;
if (fmt.flags & alt_flag) // little endian (lsb first) if (fmt.flags & alt_flag) // little endian (lsb first)
{ {
@ -95,10 +95,10 @@ printLong(const StreamFormat& fmt, StreamBuffer& output, long value)
return true; return true;
} }
long RawConverter:: ssize_t RawConverter::
scanLong(const StreamFormat& fmt, const char* input, long& value) scanLong(const StreamFormat& fmt, const char* input, long& value)
{ {
long length = 0; ssize_t consumed = 0;
long val = 0; long val = 0;
unsigned long width = fmt.width; unsigned long width = fmt.width;
if (width == 0) width = 1; // default: 1 byte if (width == 0) width = 1; // default: 1 byte
@ -112,7 +112,7 @@ scanLong(const StreamFormat& fmt, const char* input, long& value)
unsigned int shift = 0; unsigned int shift = 0;
while (--width && shift < sizeof(long)*8) while (--width && shift < sizeof(long)*8)
{ {
val |= ((unsigned char) input[length++]) << shift; val |= ((unsigned char)input[consumed++]) << shift;
shift += 8; shift += 8;
} }
if (width == 0) if (width == 0)
@ -120,15 +120,15 @@ scanLong(const StreamFormat& fmt, const char* input, long& value)
if (fmt.flags & zero_flag) if (fmt.flags & zero_flag)
{ {
// fill with zero // fill with zero
val |= ((unsigned char) input[length++]) << shift; val |= ((unsigned char)input[consumed++]) << shift;
} }
else else
{ {
// fill with sign // fill with sign
val |= ((signed char) input[length++]) << shift; val |= ((signed char)input[consumed++]) << shift;
} }
} }
length += width; // ignore upper bytes not fitting in long consumed += width; // ignore upper bytes not fitting in long
} }
else else
{ {
@ -136,21 +136,21 @@ scanLong(const StreamFormat& fmt, const char* input, long& value)
if (fmt.flags & zero_flag) if (fmt.flags & zero_flag)
{ {
// fill with zero // fill with zero
val = (unsigned char) input[length++]; val = (unsigned char)input[consumed++];
} }
else else
{ {
// fill with sign // fill with sign
val = (signed char) input[length++]; val = (signed char)input[consumed++];
} }
while (--width) while (--width)
{ {
val <<= 8; val <<= 8;
val |= (unsigned char) input[length++]; val |= (unsigned char)input[consumed++];
} }
} }
value = val; value = val;
return length; return consumed;
} }
RegisterConverter (RawConverter, "r"); RegisterConverter (RawConverter, "r");

View File

@ -29,7 +29,7 @@ class RawFloatConverter : public StreamFormatConverter
{ {
int parse(const StreamFormat&, StreamBuffer&, const char*&, bool); int parse(const StreamFormat&, StreamBuffer&, const char*&, bool);
bool printDouble(const StreamFormat&, StreamBuffer&, double); bool printDouble(const StreamFormat&, StreamBuffer&, double);
long scanDouble(const StreamFormat&, const char*, double&); ssize_t scanDouble(const StreamFormat&, const char*, double&);
}; };
int RawFloatConverter:: int RawFloatConverter::
@ -90,7 +90,7 @@ printDouble(const StreamFormat& format, StreamBuffer& output, double value)
return true; return true;
} }
long RawFloatConverter:: ssize_t RawFloatConverter::
scanDouble(const StreamFormat& format, const char* input, double& value) scanDouble(const StreamFormat& format, const char* input, double& value)
{ {
int nbOfBytes; int nbOfBytes;

View File

@ -136,8 +136,12 @@ append(const void* s, ssize_t size)
} }
ssize_t StreamBuffer:: ssize_t StreamBuffer::
find(const void* m, size_t size, ssize_t start) const find(const char* m, size_t size, ssize_t start) const
{ {
if (m && size == 0)
{
size = strlen(m);
}
if (start < 0) if (start < 0)
{ {
start += len; start += len;

View File

@ -28,7 +28,7 @@
#define __attribute__(x) #define __attribute__(x)
#endif #endif
#ifdef _WIN32 #if defined(_WIN32) && !defined(ssize_t)
#define ssize_t ptrdiff_t #define ssize_t ptrdiff_t
#endif #endif
@ -94,11 +94,11 @@ public:
{return len>0;} {return len>0;}
// length: get current data length // length: get current data length
ssize_t length() const size_t length() const
{return len;} {return len;}
// capacity: get current max data length (spare one byte for end) // capacity: get current max data length (spare one byte for end)
ssize_t capacity() const size_t capacity() const
{return cap-1;} {return cap-1;}
// end: get pointer to byte after last data byte // end: get pointer to byte after last data byte
@ -205,10 +205,7 @@ public:
c, start<0?-start:len-start)))? c, start<0?-start:len-start)))?
p-(buffer+offs) : -1;} p-(buffer+offs) : -1;}
ssize_t find(const void* s, size_t size, ssize_t start=0) const; ssize_t find(const char* s, size_t size=0, ssize_t start=0) const;
ssize_t find(const char* s, ssize_t start=0) const
{return find(s, s?strlen(s):0, start);}
ssize_t find(const StreamBuffer& s, ssize_t start=0) const ssize_t find(const StreamBuffer& s, ssize_t start=0) const
{return find(s.buffer+s.offs, s.len, start);} {return find(s.buffer+s.offs, s.len, start);}

View File

@ -196,7 +196,7 @@ parse(const char* filename, const char* _protocolname)
{ {
protocolname = _protocolname; protocolname = _protocolname;
// extract substitutions from protocolname "name(sub1,sub2)" // extract substitutions from protocolname "name(sub1,sub2)"
int i = protocolname.find('('); ssize_t i = protocolname.find('(');
if (i >= 0) if (i >= 0)
{ {
while (i >= 0) while (i >= 0)
@ -635,7 +635,7 @@ formatOutput()
char command; char command;
const char* fieldName = NULL; const char* fieldName = NULL;
const char* formatstring; const char* formatstring;
int formatstringlen; size_t formatstringlen;
outputLine.clear(); outputLine.clear();
while ((command = *commandIndex++) != StreamProtocolParser::eos) while ((command = *commandIndex++) != StreamProtocolParser::eos)
@ -1019,8 +1019,8 @@ readCallback(StreamIoStatus status,
// prepare to parse the input // prepare to parse the input
const char *commandStart = commandIndex; const char *commandStart = commandIndex;
long end = -1; ssize_t end = -1;
long termlen = 0; size_t termlen = 0;
if (inTerminator) if (inTerminator)
{ {
@ -1029,7 +1029,7 @@ readCallback(StreamIoStatus status,
// do not parse old chunks again or performance decreases to O(n^2) // do not parse old chunks again or performance decreases to O(n^2)
// but make sure to get all terminators in multi-line input // but make sure to get all terminators in multi-line input
long start; ssize_t start;
if (unparsedInput) if (unparsedInput)
{ {
// multi-line input sets 'unparsedInput' and removes the line // multi-line input sets 'unparsedInput' and removes the line
@ -1092,7 +1092,7 @@ readCallback(StreamIoStatus status,
name()); name());
flags |= AcceptInput; flags |= AcceptInput;
if (maxInput) if (maxInput)
return maxInput - inputBuffer.length(); return (long)(maxInput - inputBuffer.length());
else else
return -1; return -1;
} }
@ -1197,7 +1197,7 @@ matchInput()
{ {
fieldAddress.clear(); fieldAddress.clear();
normal_format: normal_format:
int consumed; ssize_t consumed;
// code layout: // code layout:
// formatstring <eos> StreamFormat [info] // formatstring <eos> StreamFormat [info]
formatstring.clear(); formatstring.clear();
@ -1215,7 +1215,7 @@ normal_format:
{ {
long ldummy; long ldummy;
double ddummy; double ddummy;
long unsigned size=0; size_t size=0;
switch (fmt.type) switch (fmt.type)
{ {
case unsigned_format: case unsigned_format:
@ -1388,7 +1388,7 @@ normal_format:
consumedInput++; consumedInput++;
} }
} }
long surplus = inputLine.length()-consumedInput; size_t surplus = inputLine.length()-consumedInput;
if (surplus > 0 && !(flags & IgnoreExtraInput)) if (surplus > 0 && !(flags & IgnoreExtraInput))
{ {
if (!(flags & AsyncMode) && onMismatch[0] != in_cmd) if (!(flags & AsyncMode) && onMismatch[0] != in_cmd)
@ -1430,8 +1430,8 @@ matchSeparator()
flags |= Separator; flags |= Separator;
return true; return true;
} }
long i; size_t i;
long j = consumedInput; size_t j = consumedInput;
for (i = 0; i < separator.length(); i++) for (i = 0; i < separator.length(); i++)
{ {
switch (separator[i]) switch (separator[i])
@ -1459,7 +1459,7 @@ matchSeparator()
return true; return true;
} }
long StreamCore:: ssize_t StreamCore::
scanValue(const StreamFormat& fmt, long& value) scanValue(const StreamFormat& fmt, long& value)
{ {
if (fmt.type != unsigned_format && fmt.type != signed_format && fmt.type != enum_format) if (fmt.type != unsigned_format && fmt.type != signed_format && fmt.type != enum_format)
@ -1470,7 +1470,7 @@ scanValue(const StreamFormat& fmt, long& value)
} }
flags |= ScanTried; flags |= ScanTried;
if (!matchSeparator()) return -1; if (!matchSeparator()) return -1;
long consumed = StreamFormatConverter::find(fmt.conv)-> ssize_t consumed = StreamFormatConverter::find(fmt.conv)->
scanLong(fmt, inputLine(consumedInput), value); scanLong(fmt, inputLine(consumedInput), value);
debug("StreamCore::scanValue(%s, format=%%%c, long) input=\"%s\"\n", debug("StreamCore::scanValue(%s, format=%%%c, long) input=\"%s\"\n",
name(), fmt.conv, inputLine.expand(consumedInput)()); name(), fmt.conv, inputLine.expand(consumedInput)());
@ -1484,14 +1484,14 @@ scanValue(const StreamFormat& fmt, long& value)
else return -1; else return -1;
} }
if (fmt.flags & fix_width_flag && (unsigned long)consumed != fmt.width) return -1; if (fmt.flags & fix_width_flag && (unsigned long)consumed != fmt.width) return -1;
if (consumed > inputLine.length()-consumedInput) return -1; if ((size_t)consumed > inputLine.length()-consumedInput) return -1;
debug("StreamCore::scanValue(%s) scanned %li\n", debug("StreamCore::scanValue(%s) scanned %li\n",
name(), value); name(), value);
flags |= GotValue; flags |= GotValue;
return consumed; return consumed;
} }
long StreamCore:: ssize_t StreamCore::
scanValue(const StreamFormat& fmt, double& value) scanValue(const StreamFormat& fmt, double& value)
{ {
if (fmt.type != double_format) if (fmt.type != double_format)
@ -1502,7 +1502,7 @@ scanValue(const StreamFormat& fmt, double& value)
} }
flags |= ScanTried; flags |= ScanTried;
if (!matchSeparator()) return -1; if (!matchSeparator()) return -1;
long consumed = StreamFormatConverter::find(fmt.conv)-> ssize_t consumed = StreamFormatConverter::find(fmt.conv)->
scanDouble(fmt, inputLine(consumedInput), value); scanDouble(fmt, inputLine(consumedInput), value);
debug("StreamCore::scanValue(%s, format=%%%c, double) input=\"%s\"\n", debug("StreamCore::scanValue(%s, format=%%%c, double) input=\"%s\"\n",
name(), fmt.conv, inputLine.expand(consumedInput, 20)()); name(), fmt.conv, inputLine.expand(consumedInput, 20)());
@ -1515,16 +1515,16 @@ scanValue(const StreamFormat& fmt, double& value)
} }
else return -1; else return -1;
} }
if (fmt.flags & fix_width_flag && ((unsigned long)consumed != (fmt.width + fmt.prec + 1))) return -1; if (fmt.flags & fix_width_flag && (consumed != (fmt.width + fmt.prec + 1))) return -1;
if (consumed > inputLine.length()-consumedInput) return -1; if ((size_t)consumed > inputLine.length()-consumedInput) return -1;
debug("StreamCore::scanValue(%s) scanned %#g\n", debug("StreamCore::scanValue(%s) scanned %#g\n",
name(), value); name(), value);
flags |= GotValue; flags |= GotValue;
return consumed; return consumed;
} }
long StreamCore:: ssize_t StreamCore::
scanValue(const StreamFormat& fmt, char* value, unsigned long& size) scanValue(const StreamFormat& fmt, char* value, size_t& size)
{ {
if (fmt.type != string_format) if (fmt.type != string_format)
{ {
@ -1534,7 +1534,7 @@ scanValue(const StreamFormat& fmt, char* value, unsigned long& size)
} }
flags |= ScanTried; flags |= ScanTried;
if (!matchSeparator()) return -1; if (!matchSeparator()) return -1;
long consumed = StreamFormatConverter::find(fmt.conv)-> ssize_t consumed = StreamFormatConverter::find(fmt.conv)->
scanString(fmt, inputLine(consumedInput), value, size); scanString(fmt, inputLine(consumedInput), value, size);
debug("StreamCore::scanValue(%s, format=%%%c, char*, size=%ld) input=\"%s\"\n", debug("StreamCore::scanValue(%s, format=%%%c, char*, size=%ld) input=\"%s\"\n",
name(), fmt.conv, size, inputLine.expand(consumedInput)()); name(), fmt.conv, size, inputLine.expand(consumedInput)());
@ -1548,7 +1548,7 @@ scanValue(const StreamFormat& fmt, char* value, unsigned long& size)
else return -1; else return -1;
} }
if (fmt.flags & fix_width_flag && (unsigned long)consumed != fmt.width) return -1; if (fmt.flags & fix_width_flag && (unsigned long)consumed != fmt.width) return -1;
if (consumed > inputLine.length()-consumedInput) return -1; if ((size_t)consumed > inputLine.length()-consumedInput) return -1;
#ifndef NO_TEMPORARY #ifndef NO_TEMPORARY
debug("StreamCore::scanValue(%s) scanned \"%s\"\n", debug("StreamCore::scanValue(%s) scanned \"%s\"\n",
name(), StreamBuffer(value, size).expand()()); name(), StreamBuffer(value, size).expand()());

View File

@ -135,10 +135,10 @@ protected:
bool printValue(const StreamFormat& format, long value); bool printValue(const StreamFormat& format, long value);
bool printValue(const StreamFormat& format, double value); bool printValue(const StreamFormat& format, double value);
bool printValue(const StreamFormat& format, char* value); bool printValue(const StreamFormat& format, char* value);
long scanValue(const StreamFormat& format, long& value); ssize_t scanValue(const StreamFormat& format, long& value);
long scanValue(const StreamFormat& format, double& value); ssize_t scanValue(const StreamFormat& format, double& value);
long scanValue(const StreamFormat& format, char* value, unsigned long& size); ssize_t scanValue(const StreamFormat& format, char* value, size_t& size);
long scanValue(const StreamFormat& format); ssize_t scanValue(const StreamFormat& format);
StreamBuffer protocolname; StreamBuffer protocolname;
unsigned long lockTimeout; unsigned long lockTimeout;
@ -163,7 +163,7 @@ protected:
StreamBuffer outputLine; StreamBuffer outputLine;
StreamBuffer inputBuffer; StreamBuffer inputBuffer;
StreamBuffer inputLine; StreamBuffer inputLine;
long consumedInput; size_t consumedInput;
ProtocolResult runningHandler; ProtocolResult runningHandler;
StreamBuffer fieldAddress; StreamBuffer fieldAddress;

View File

@ -116,7 +116,7 @@ class Stream : protected StreamCore
#endif #endif
int status; int status;
int convert; int convert;
long currentValueLength; ssize_t currentValueLength;
IOSCANPVT ioscanpvt; IOSCANPVT ioscanpvt;
CALLBACK commandCallback; CALLBACK commandCallback;
CALLBACK processCallback; CALLBACK processCallback;
@ -155,7 +155,7 @@ class Stream : protected StreamCore
long initRecord(const char* filename, const char* protocol, long initRecord(const char* filename, const char* protocol,
const char* busname, int addr, const char* busparam); const char* busname, int addr, const char* busparam);
bool print(format_t *format, va_list ap); bool print(format_t *format, va_list ap);
long scan(format_t *format, void* pvalue, size_t maxStringSize); ssize_t scan(format_t *format, void* pvalue, size_t maxStringSize);
bool process(); bool process();
// device support functions // device support functions
@ -165,7 +165,7 @@ class Stream : protected StreamCore
friend long streamGetIointInfo(int cmd, dbCommon *record, friend long streamGetIointInfo(int cmd, dbCommon *record,
IOSCANPVT *ppvt); IOSCANPVT *ppvt);
friend long streamPrintf(dbCommon *record, format_t *format, ...); friend long streamPrintf(dbCommon *record, format_t *format, ...);
friend long streamScanfN(dbCommon *record, format_t *format, friend ssize_t streamScanfN(dbCommon *record, format_t *format,
void*, size_t maxStringSize); void*, size_t maxStringSize);
friend long streamReload(const char* recordname); friend long streamReload(const char* recordname);
@ -282,9 +282,9 @@ struct drvet stream = {
epicsExportAddress(drvet, stream); epicsExportAddress(drvet, stream);
#ifdef EPICS_3_13 #ifdef EPICS_3_13
void streamEpicsPrintTimestamp(char* buffer, int size) void streamEpicsPrintTimestamp(char* buffer, size_t size)
{ {
int tlen; size_t tlen;
char* c; char* c;
TS_STAMP tm; TS_STAMP tm;
tsLocalTime (&tm); tsLocalTime (&tm);
@ -297,12 +297,12 @@ void streamEpicsPrintTimestamp(char* buffer, int size)
sprintf(buffer+tlen, " %.*s", size-tlen-2, taskName(0)); sprintf(buffer+tlen, " %.*s", size-tlen-2, taskName(0));
} }
#else // !EPICS_3_13 #else // !EPICS_3_13
void streamEpicsPrintTimestamp(char* buffer, int size) void streamEpicsPrintTimestamp(char* buffer, size_t size)
{ {
int tlen; size_t tlen;
epicsTime tm = epicsTime::getCurrent(); epicsTime tm = epicsTime::getCurrent();
tlen = tm.strftime(buffer, size, "%Y/%m/%d %H:%M:%S.%06f"); tlen = tm.strftime(buffer, size, "%Y/%m/%d %H:%M:%S.%06f");
sprintf(buffer+tlen, " %.*s", size-tlen-2, epicsThreadGetNameSelf()); sprintf(buffer+tlen, " %.*s", (int)(size-tlen-2), epicsThreadGetNameSelf());
} }
#endif // !EPICS_3_13 #endif // !EPICS_3_13
@ -540,10 +540,10 @@ long streamPrintf(dbCommon *record, format_t *format, ...)
return success ? OK : ERROR; return success ? OK : ERROR;
} }
long streamScanfN(dbCommon* record, format_t *format, ssize_t streamScanfN(dbCommon* record, format_t *format,
void* value, size_t maxStringSize) void* value, size_t maxStringSize)
{ {
long size; ssize_t size;
debug("streamScanfN(%s,format=%%%c,maxStringSize=%ld)\n", debug("streamScanfN(%s,format=%%%c,maxStringSize=%ld)\n",
record->name, format->priv->conv, (long)maxStringSize); record->name, format->priv->conv, (long)maxStringSize);
Stream* pstream = (Stream*)record->dpvt; Stream* pstream = (Stream*)record->dpvt;
@ -791,12 +791,12 @@ print(format_t *format, va_list ap)
return false; return false;
} }
long Stream:: ssize_t Stream::
scan(format_t *format, void* value, size_t maxStringSize) scan(format_t *format, void* value, size_t maxStringSize)
{ {
// called by streamScanfN // called by streamScanfN
unsigned long size = maxStringSize; size_t size = maxStringSize;
// first remove old value from inputLine (if we are scanning arrays) // first remove old value from inputLine (if we are scanning arrays)
consumedInput += currentValueLength; consumedInput += currentValueLength;
currentValueLength = 0; currentValueLength = 0;
@ -1145,14 +1145,14 @@ bool Stream::
matchValue(const StreamFormat& format, const void* fieldaddress) matchValue(const StreamFormat& format, const void* fieldaddress)
{ {
// this function must increase consumedInput // this function must increase consumedInput
long consumed = 0; ssize_t consumed = 0;
long lval; long lval;
double dval; double dval;
char* buffer; char* buffer;
int status; int status;
const char* putfunc; const char* putfunc;
format_s fmt; format_s fmt;
unsigned long stringsize = MAX_STRING_SIZE; size_t stringsize = MAX_STRING_SIZE;
fmt.type = dbfMapping[format.type]; fmt.type = dbfMapping[format.type];
fmt.priv = &format; fmt.priv = &format;
@ -1163,8 +1163,8 @@ matchValue(const StreamFormat& format, const void* fieldaddress)
StreamBuffer fieldBuffer; StreamBuffer fieldBuffer;
DBADDR* pdbaddr = (DBADDR*)fieldaddress; DBADDR* pdbaddr = (DBADDR*)fieldaddress;
size_t size; size_t size;
unsigned long nord; size_t nord;
unsigned long nelem = pdbaddr->no_elements; size_t nelem = pdbaddr->no_elements;
if (format.type == string_format && if (format.type == string_format &&
(pdbaddr->field_type == DBF_CHAR || pdbaddr->field_type == DBF_UCHAR)) (pdbaddr->field_type == DBF_CHAR || pdbaddr->field_type == DBF_UCHAR))
{ {
@ -1320,7 +1320,7 @@ matchValue(const StreamFormat& format, const void* fieldaddress)
// write into own record, thus don't process it // write into own record, thus don't process it
// in @init we must not process other record // in @init we must not process other record
putfunc = "dbPut"; putfunc = "dbPut";
status = dbPut(pdbaddr, fmt.type, buffer, nord); status = dbPut(pdbaddr, fmt.type, buffer, (long)nord);
if (INIT_RUN && pdbaddr->precord != record) if (INIT_RUN && pdbaddr->precord != record)
{ {
// clean error status of other record in @init // clean error status of other record in @init
@ -1334,7 +1334,7 @@ matchValue(const StreamFormat& format, const void* fieldaddress)
// write into other record, thus process it // write into other record, thus process it
putfunc = "dbPutField"; putfunc = "dbPutField";
status = dbPutField(pdbaddr, fmt.type, status = dbPutField(pdbaddr, fmt.type,
buffer, nord); buffer, (long)nord);
} }
debug("Stream::matchValue(%s): %s(%s.%s, %s, %s) status=0x%x\n", debug("Stream::matchValue(%s): %s(%s.%s, %s, %s) status=0x%x\n",
name(), putfunc, name(), putfunc,

View File

@ -41,20 +41,20 @@ FILE *StreamDebugFile = NULL;
by setting the StreamPrintTimestampFunction variable by setting the StreamPrintTimestampFunction variable
to your own function. to your own function.
*/ */
static void printTimestamp(char* buffer, int size) static void printTimestamp(char* buffer, size_t size)
{ {
time_t t; time_t t;
struct tm tm; struct tm tm;
time(&t); time(&t);
#ifdef _WIN32 #ifdef _WIN32
tm = *localtime(&t); tm = *localtime(&t);
#else #else
localtime_r(&t, &tm); localtime_r(&t, &tm);
#endif #endif
strftime(buffer, size, "%Y/%m/%d %H:%M:%S", &tm); strftime(buffer, size, "%Y/%m/%d %H:%M:%S", &tm);
} }
void (*StreamPrintTimestampFunction)(char* buffer, int size) = printTimestamp; void (*StreamPrintTimestampFunction)(char* buffer, size_t size) = printTimestamp;
void StreamError(const char* fmt, ...) void StreamError(const char* fmt, ...)
{ {

View File

@ -29,7 +29,7 @@
extern int streamDebug; extern int streamDebug;
extern int streamError; extern int streamError;
extern void (*StreamPrintTimestampFunction)(char* buffer, int size); extern void (*StreamPrintTimestampFunction)(char* buffer, size_t size);
void StreamError(int line, const char* file, const char* fmt, ...) void StreamError(int line, const char* file, const char* fmt, ...)
__attribute__((__format__(__printf__,3,4))); __attribute__((__format__(__printf__,3,4)));

View File

@ -205,7 +205,7 @@ printPseudo(const StreamFormat& fmt, StreamBuffer&)
return false; return false;
} }
long StreamFormatConverter:: ssize_t StreamFormatConverter::
scanLong(const StreamFormat& fmt, const char*, long&) scanLong(const StreamFormat& fmt, const char*, long&)
{ {
error("Unimplemented scanLong method for %%%c format\n", error("Unimplemented scanLong method for %%%c format\n",
@ -213,7 +213,7 @@ scanLong(const StreamFormat& fmt, const char*, long&)
return -1; return -1;
} }
long StreamFormatConverter:: ssize_t StreamFormatConverter::
scanDouble(const StreamFormat& fmt, const char*, double&) scanDouble(const StreamFormat& fmt, const char*, double&)
{ {
error("Unimplemented scanDouble method for %%%c format\n", error("Unimplemented scanDouble method for %%%c format\n",
@ -221,16 +221,16 @@ scanDouble(const StreamFormat& fmt, const char*, double&)
return -1; return -1;
} }
long StreamFormatConverter:: ssize_t StreamFormatConverter::
scanString(const StreamFormat& fmt, const char*, char*, unsigned long&) scanString(const StreamFormat& fmt, const char*, char*, size_t&)
{ {
error("Unimplemented scanString method for %%%c format\n", error("Unimplemented scanString method for %%%c format\n",
fmt.conv); fmt.conv);
return -1; return -1;
} }
long StreamFormatConverter:: ssize_t StreamFormatConverter::
scanPseudo(const StreamFormat& fmt, StreamBuffer&, long&) scanPseudo(const StreamFormat& fmt, StreamBuffer&, size_t&)
{ {
error("Unimplemented scanPseudo method for %%%c format\n", error("Unimplemented scanPseudo method for %%%c format\n",
fmt.conv); fmt.conv);
@ -255,15 +255,15 @@ static void copyFormatString(StreamBuffer& info, const char* source)
// Standard Long Converter for 'diouxX' // Standard Long Converter for 'diouxX'
static long prepareval(const StreamFormat& fmt, const char*& input, bool& neg) static size_t prepareval(const StreamFormat& fmt, const char*& input, bool& neg)
{ {
long consumed = 0; size_t consumed = 0;
neg = false; neg = false;
while (isspace(*input)) { input++; consumed++; } while (isspace(*input)) { input++; consumed++; }
if (fmt.width) if (fmt.width)
{ {
// take local copy because strto* don't have width parameter // take local copy because strto* don't have width parameter
int width = fmt.width; size_t width = fmt.width;
if (fmt.flags & space_flag) if (fmt.flags & space_flag)
{ {
// normally whitespace does not count to width // normally whitespace does not count to width
@ -297,7 +297,7 @@ class StdLongConverter : public StreamFormatConverter
{ {
int parse(const StreamFormat& fmt, StreamBuffer& output, const char*& value, bool scanFormat); int parse(const StreamFormat& fmt, StreamBuffer& output, const char*& value, bool scanFormat);
bool printLong(const StreamFormat& fmt, StreamBuffer& output, long value); bool printLong(const StreamFormat& fmt, StreamBuffer& output, long value);
long scanLong(const StreamFormat& fmt, const char* input, long& value); ssize_t scanLong(const StreamFormat& fmt, const char* input, long& value);
}; };
int StdLongConverter:: int StdLongConverter::
@ -334,11 +334,11 @@ printLong(const StreamFormat& fmt, StreamBuffer& output, long value)
return true; return true;
} }
long StdLongConverter:: ssize_t StdLongConverter::
scanLong(const StreamFormat& fmt, const char* input, long& value) scanLong(const StreamFormat& fmt, const char* input, long& value)
{ {
char* end; char* end;
long consumed; ssize_t consumed;
bool neg; bool neg;
int base; int base;
long v; long v;
@ -379,7 +379,7 @@ class StdDoubleConverter : public StreamFormatConverter
{ {
virtual int parse(const StreamFormat&, StreamBuffer&, const char*&, bool); virtual int parse(const StreamFormat&, StreamBuffer&, const char*&, bool);
virtual bool printDouble(const StreamFormat&, StreamBuffer&, double); virtual bool printDouble(const StreamFormat&, StreamBuffer&, double);
virtual long scanDouble(const StreamFormat&, const char*, double&); virtual ssize_t scanDouble(const StreamFormat&, const char*, double&);
}; };
int StdDoubleConverter:: int StdDoubleConverter::
@ -411,11 +411,11 @@ printDouble(const StreamFormat& fmt, StreamBuffer& output, double value)
return true; return true;
} }
long StdDoubleConverter:: ssize_t StdDoubleConverter::
scanDouble(const StreamFormat& fmt, const char* input, double& value) scanDouble(const StreamFormat& fmt, const char* input, double& value)
{ {
char* end; char* end;
long consumed; ssize_t consumed;
bool neg; bool neg;
consumed = prepareval(fmt, input, neg); consumed = prepareval(fmt, input, neg);
@ -435,7 +435,7 @@ class StdStringConverter : public StreamFormatConverter
{ {
virtual int parse(const StreamFormat&, StreamBuffer&, const char*&, bool); virtual int parse(const StreamFormat&, StreamBuffer&, const char*&, bool);
virtual bool printString(const StreamFormat&, StreamBuffer&, const char*); virtual bool printString(const StreamFormat&, StreamBuffer&, const char*);
virtual long scanString(const StreamFormat&, const char*, char*, unsigned long&); virtual ssize_t scanString(const StreamFormat&, const char*, char*, size_t&);
}; };
int StdStringConverter:: int StdStringConverter::
@ -483,13 +483,13 @@ printString(const StreamFormat& fmt, StreamBuffer& output, const char* value)
return true; return true;
} }
long StdStringConverter:: ssize_t StdStringConverter::
scanString(const StreamFormat& fmt, const char* input, scanString(const StreamFormat& fmt, const char* input,
char* value, unsigned long &size) char* value, size_t& size)
{ {
long consumed = 0; ssize_t consumed = 0;
long space_left = size; size_t space_left = size;
int width = fmt.width; ssize_t width = fmt.width;
if ((fmt.flags & skip_flag) || value == NULL) space_left = 0; if ((fmt.flags & skip_flag) || value == NULL) space_left = 0;
@ -547,7 +547,7 @@ class StdCharsConverter : public StreamFormatConverter
{ {
virtual int parse(const StreamFormat&, StreamBuffer&, const char*&, bool); virtual int parse(const StreamFormat&, StreamBuffer&, const char*&, bool);
virtual bool printLong(const StreamFormat&, StreamBuffer&, long); virtual bool printLong(const StreamFormat&, StreamBuffer&, long);
virtual long scanString(const StreamFormat&, const char*, char*, unsigned long&); virtual ssize_t scanString(const StreamFormat&, const char*, char*, size_t&);
}; };
int StdCharsConverter:: int StdCharsConverter::
@ -583,13 +583,13 @@ printLong(const StreamFormat& fmt, StreamBuffer& output, long value)
return true; return true;
} }
long StdCharsConverter:: ssize_t StdCharsConverter::
scanString(const StreamFormat& fmt, const char* input, scanString(const StreamFormat& fmt, const char* input,
char* value, unsigned long& size) char* value, size_t& size)
{ {
long consumed = 0; size_t consumed = 0;
long width = fmt.width; size_t width = fmt.width;
long space_left = size; size_t space_left = size;
if ((fmt.flags & skip_flag) || value == NULL) space_left = 0; if ((fmt.flags & skip_flag) || value == NULL) space_left = 0;
@ -623,7 +623,7 @@ RegisterConverter (StdCharsConverter, "c");
class StdCharsetConverter : public StreamFormatConverter class StdCharsetConverter : public StreamFormatConverter
{ {
virtual int parse(const StreamFormat&, StreamBuffer&, const char*&, bool); virtual int parse(const StreamFormat&, StreamBuffer&, const char*&, bool);
virtual long scanString(const StreamFormat&, const char*, char*, unsigned long&); virtual ssize_t scanString(const StreamFormat&, const char*, char*, size_t&);
// no print method, %[ is readonly // no print method, %[ is readonly
}; };
@ -702,13 +702,13 @@ parse(const StreamFormat& fmt, StreamBuffer& info,
return string_format; return string_format;
} }
long StdCharsetConverter:: ssize_t StdCharsetConverter::
scanString(const StreamFormat& fmt, const char* input, scanString(const StreamFormat& fmt, const char* input,
char* value, unsigned long& size) char* value, size_t& size)
{ {
long consumed = 0; ssize_t consumed = 0;
long width = fmt.width; ssize_t width = fmt.width;
long space_left = size; size_t space_left = size;
if ((fmt.flags & skip_flag) || value == NULL) space_left = 0; if ((fmt.flags & skip_flag) || value == NULL) space_left = 0;

View File

@ -56,14 +56,14 @@ public:
StreamBuffer& output, const char* value); StreamBuffer& output, const char* value);
virtual bool printPseudo(const StreamFormat& fmt, virtual bool printPseudo(const StreamFormat& fmt,
StreamBuffer& output); StreamBuffer& output);
virtual long scanLong(const StreamFormat& fmt, virtual ssize_t scanLong(const StreamFormat& fmt,
const char* input, long& value); const char* input, long& value);
virtual long scanDouble(const StreamFormat& fmt, virtual ssize_t scanDouble(const StreamFormat& fmt,
const char* input, double& value); const char* input, double& value);
virtual long scanString(const StreamFormat& fmt, virtual ssize_t scanString(const StreamFormat& fmt,
const char* input, char* value, unsigned long& size); const char* input, char* value, size_t& size);
virtual long scanPseudo(const StreamFormat& fmt, virtual ssize_t scanPseudo(const StreamFormat& fmt,
StreamBuffer& inputLine, long& cursor); StreamBuffer& inputLine, size_t& cursor);
}; };
inline StreamFormatConverter* StreamFormatConverter:: inline StreamFormatConverter* StreamFormatConverter::

View File

@ -446,7 +446,7 @@ terminated and the line number is stored for later use.
Each time newline is read, line is incremented. Each time newline is read, line is incremented.
*/ */
if (!specialchars) specialchars = specialChars; if (!specialchars) specialchars = specialChars;
long token = buffer.length(); size_t token = buffer.length();
int l = line; int l = line;
int c = readChar(); int c = readChar();
@ -580,7 +580,7 @@ parseAssignment(const char* name, Protocol& protocol)
bool StreamProtocolParser:: bool StreamProtocolParser::
parseValue(StreamBuffer& buffer, bool lazy) parseValue(StreamBuffer& buffer, bool lazy)
{ {
long token; size_t token;
int c; int c;
do c = readChar(); while (c == ' '); // skip leading spaces do c = readChar(); while (c == ' '); // skip leading spaces
@ -594,7 +594,7 @@ parseValue(StreamBuffer& buffer, bool lazy)
c = buffer[token]; c = buffer[token];
if (c == '$') // a variable if (c == '$') // a variable
{ {
long varname = token+1; size_t varname = token+1;
if (buffer[varname] == '"') varname++; // quoted variable if (buffer[varname] == '"') varname++; // quoted variable
if (lazy || (buffer[varname] >= '0' && buffer[varname] <= '9')) if (lazy || (buffer[varname] >= '0' && buffer[varname] <= '9'))
{ {
@ -1066,7 +1066,7 @@ compileString(StreamBuffer& buffer, const char*& source,
bool escaped = false; bool escaped = false;
int newline = 0; int newline = 0;
StreamBuffer formatbuffer; StreamBuffer formatbuffer;
int formatpos = buffer.length(); size_t formatpos = buffer.length();
line = getLineNumber(source); line = getLineNumber(source);
debug("StreamProtocolParser::Protocol::compileString " debug("StreamProtocolParser::Protocol::compileString "
@ -1116,7 +1116,7 @@ compileString(StreamBuffer& buffer, const char*& source,
formatbuffer()); formatbuffer());
return false; return false;
} }
int formatlen = p - buffer(formatpos); size_t formatlen = p - buffer(formatpos);
buffer.replace(formatpos, formatlen, formatbuffer); buffer.replace(formatpos, formatlen, formatbuffer);
debug("StreamProtocolParser::Protocol::compileString " debug("StreamProtocolParser::Protocol::compileString "
"replaced by: \"%s\"\n", buffer.expand(formatpos)()); "replaced by: \"%s\"\n", buffer.expand(formatpos)());
@ -1392,7 +1392,7 @@ compileFormat(StreamBuffer& buffer, const char*& formatstr,
*/ */
const char* source = formatstr; const char* source = formatstr;
StreamFormat streamFormat; StreamFormat streamFormat;
int fieldname = 0; size_t fieldname = 0;
// look for fieldname // look for fieldname
if (source[1] == '(') if (source[1] == '(')
{ {
@ -1432,12 +1432,12 @@ compileFormat(StreamBuffer& buffer, const char*& formatstr,
buffer.append(format); buffer.append(format);
} }
const char* formatstart = source + 1; const char* formatstart = source + 1;
// parse format and get info string // parse format and get info string
StreamBuffer infoString; StreamBuffer infoString;
int type = StreamFormatConverter::parseFormat(source, int type = StreamFormatConverter::parseFormat(source,
formatType, streamFormat, infoString); formatType, streamFormat, infoString);
if (!type) if (!type)
{ {
// parsing failed // parsing failed

View File

@ -29,10 +29,10 @@
/* timezone in UNIX contains the seconds between UTC and local time, /* timezone in UNIX contains the seconds between UTC and local time,
but not in Free-BSD! Here timezone() is a function delivering but not in Free-BSD! Here timezone() is a function delivering
the time zone abbreviation (e.g. CET). Alternatively, the timezone the time zone abbreviation (e.g. CET). Alternatively, the timezone
value can also be gained from tm_gmtoff of the tm-structure. value can also be gained from tm_gmtoff of the tm-structure.
HJK, 4.4.14 */ HJK, 4.4.14 */
/* The same seems to be true for other BSDs. DZ. */ /* The same seems to be true for other BSDs. DZ. */
#if defined(__FreeBSD__) || \ #if defined(__FreeBSD__) || \
defined(__NetBSD__) || \ defined(__NetBSD__) || \
defined(__OpenBSD__) || \ defined(__OpenBSD__) || \
@ -75,7 +75,7 @@ class TimestampConverter : public StreamFormatConverter
{ {
int parse(const StreamFormat&, StreamBuffer&, const char*&, bool); int parse(const StreamFormat&, StreamBuffer&, const char*&, bool);
bool printDouble(const StreamFormat&, StreamBuffer&, double); bool printDouble(const StreamFormat&, StreamBuffer&, double);
long scanDouble(const StreamFormat&, const char*, double&); ssize_t scanDouble(const StreamFormat&, const char*, double&);
}; };
int TimestampConverter:: int TimestampConverter::
@ -151,10 +151,10 @@ printDouble(const StreamFormat& format, StreamBuffer& output, double value)
struct tm brokenDownTime; struct tm brokenDownTime;
char buffer [40]; char buffer [40];
char fracbuffer [15]; char fracbuffer [15];
int length; size_t length;
time_t sec; time_t sec;
double frac; double frac;
int i, n; size_t i, n;
char* c; char* c;
char* p; char* p;
@ -172,7 +172,7 @@ printDouble(const StreamFormat& format, StreamBuffer& output, double value)
n = strtol(output(i+1), &c, 10); n = strtol(output(i+1), &c, 10);
if (*c++ != 'f') return false; if (*c++ != 'f') return false;
/* print fractional part */ /* print fractional part */
sprintf(fracbuffer, "%.*f", n, frac); sprintf(fracbuffer, "%.*f", (int)n, frac);
p = strchr(fracbuffer, '.')+1; p = strchr(fracbuffer, '.')+1;
output.replace(i, c-output(i), p); output.replace(i, c-output(i), p);
} }
@ -183,10 +183,10 @@ printDouble(const StreamFormat& format, StreamBuffer& output, double value)
all fields, e.g. %z. all fields, e.g. %z.
*/ */
static int strmatch(const char*& input, const char** strings, int minlen) static int strmatch(const char*& input, const char** strings, size_t minlen)
{ {
int i; int i;
int c; size_t c;
for (i=0; strings[i]; i++) { for (i=0; strings[i]; i++) {
for (c=0; ; c++) for (c=0; ; c++)
@ -516,7 +516,7 @@ startover:
return input; return input;
} }
long TimestampConverter:: ssize_t TimestampConverter::
scanDouble(const StreamFormat& format, const char* input, double& value) scanDouble(const StreamFormat& format, const char* input, double& value)
{ {
struct tm brokenDownTime; struct tm brokenDownTime;

View File

@ -55,6 +55,10 @@ extern "C" {
#include "dbAccess.h" #include "dbAccess.h"
#include <stdio.h> #include <stdio.h>
#if defined(_WIN32) && !defined(ssize_t)
#define ssize_t ptrdiff_t
#endif
#if defined(__cplusplus) && defined(EPICS_3_13) #if defined(__cplusplus) && defined(EPICS_3_13)
} }
#endif #endif
@ -74,16 +78,16 @@ extern const char StreamVersion [];
typedef long (*streamIoFunction) (dbCommon*, format_t*); typedef long (*streamIoFunction) (dbCommon*, format_t*);
epicsShareFunc long streamInit(int after); long streamInit(int after);
epicsShareFunc long streamInitRecord(dbCommon *record, long streamInitRecord(dbCommon *record,
const struct link *ioLink, const struct link *ioLink,
streamIoFunction readData, streamIoFunction writeData); streamIoFunction readData, streamIoFunction writeData);
epicsShareFunc long streamReport(int interest); long streamReport(int interest);
epicsShareFunc long streamReadWrite(dbCommon *record); long streamReadWrite(dbCommon *record);
epicsShareFunc long streamGetIointInfo(int cmd, long streamGetIointInfo(int cmd,
dbCommon *record, IOSCANPVT *ppvt); dbCommon *record, IOSCANPVT *ppvt);
epicsShareFunc long streamPrintf(dbCommon *record, format_t *format, ...); long streamPrintf(dbCommon *record, format_t *format, ...);
epicsShareFunc long streamScanfN(dbCommon *record, format_t *format, ssize_t streamScanfN(dbCommon *record, format_t *format,
void*, size_t maxStringSize); void*, size_t maxStringSize);
/* backward compatibility stuff */ /* backward compatibility stuff */

View File

@ -113,8 +113,10 @@ static long readData(dbCommon *record, format_t *format)
break; break;
case DBF_CHAR: case DBF_CHAR:
case DBF_UCHAR: case DBF_UCHAR:
{
ssize_t length;
aai->nord = 0; aai->nord = 0;
if ((lval = streamScanfN(record, format, if ((length = streamScanfN(record, format,
(char *)aai->bptr, aai->nelm)) == ERROR) (char *)aai->bptr, aai->nelm)) == ERROR)
{ {
memset(aai->bptr, 0, aai->nelm); memset(aai->bptr, 0, aai->nelm);
@ -129,8 +131,9 @@ static long readData(dbCommon *record, format_t *format)
{ {
((char*)aai->bptr)[aai->nelm-1] = 0; ((char*)aai->bptr)[aai->nelm-1] = 0;
} }
aai->nord = lval; aai->nord = (long)length;
return OK; return OK;
}
default: default:
errlogSevPrintf(errlogFatal, errlogSevPrintf(errlogFatal,
"readData %s: can't convert from string to %s\n", "readData %s: can't convert from string to %s\n",

View File

@ -113,14 +113,16 @@ static long readData(dbCommon *record, format_t *format)
break; break;
case DBF_CHAR: case DBF_CHAR:
case DBF_UCHAR: case DBF_UCHAR:
{
ssize_t length;
aao->nord = 0; aao->nord = 0;
if ((lval = streamScanfN(record, format, if ((length = streamScanfN(record, format,
(char *)aao->bptr, aao->nelm)) == ERROR) (char *)aao->bptr, aao->nelm)) == ERROR)
{ {
memset(aao->bptr, 0, aao->nelm); memset(aao->bptr, 0, aao->nelm);
return ERROR; return ERROR;
} }
if ((size_t)lval < aao->nelm) if ((size_t)length < aao->nelm)
{ {
memset(((char*)aao->bptr)+lval , 0, aao->nelm-lval); memset(((char*)aao->bptr)+lval , 0, aao->nelm-lval);
lval++; lval++;
@ -129,8 +131,9 @@ static long readData(dbCommon *record, format_t *format)
{ {
((char*)aao->bptr)[aao->nelm-1] = 0; ((char*)aao->bptr)[aao->nelm-1] = 0;
} }
aao->nord = lval; aao->nord = (long)length;
return OK; return OK;
}
default: default:
errlogSevPrintf(errlogFatal, errlogSevPrintf(errlogFatal,
"readData %s: can't convert from string to %s\n", "readData %s: can't convert from string to %s\n",

View File

@ -39,7 +39,7 @@ static long readData(dbCommon *record, format_t *format)
else else
{ {
/* No MASK, (NOBT = 0): use VAL field */ /* No MASK, (NOBT = 0): use VAL field */
mbbiD->val = val; mbbiD->val = val; /* no cast because we cannot be sure about type of VAL */
return DO_NOT_CONVERT; return DO_NOT_CONVERT;
} }
} }

View File

@ -41,17 +41,17 @@ static long readData(dbCommon *record, format_t *format)
if ((&mbbi->zrvl)[i]) if ((&mbbi->zrvl)[i])
{ {
if (mbbi->mask) val &= mbbi->mask; if (mbbi->mask) val &= mbbi->mask;
mbbi->rval = val; mbbi->rval = (epicsEnum16)val;
return OK; return OK;
} }
} }
mbbi->val = val; mbbi->val = (epicsEnum16)val;
return DO_NOT_CONVERT; return DO_NOT_CONVERT;
} }
case DBF_ENUM: case DBF_ENUM:
{ {
if (streamScanf(record, format, &val) == ERROR) return ERROR; if (streamScanf(record, format, &val) == ERROR) return ERROR;
mbbi->val = val; mbbi->val = (epicsEnum16)val;
return DO_NOT_CONVERT; return DO_NOT_CONVERT;
} }
case DBF_STRING: case DBF_STRING:
@ -63,7 +63,7 @@ static long readData(dbCommon *record, format_t *format)
{ {
if (strcmp ((&mbbi->zrst)[val], buffer) == 0) if (strcmp ((&mbbi->zrst)[val], buffer) == 0)
{ {
mbbi->val = val; mbbi->val = (epicsEnum16)val;
return DO_NOT_CONVERT; return DO_NOT_CONVERT;
} }
} }

View File

@ -41,7 +41,7 @@ static long readData(dbCommon *record, format_t *format)
else else
{ {
/* No MASK, (NOBT = 0): use VAL field */ /* No MASK, (NOBT = 0): use VAL field */
mbboD->val = val; mbboD->val = val; /* no cast because we cannot be sure about type of VAL */
return DO_NOT_CONVERT; return DO_NOT_CONVERT;
} }
} }

View File

@ -46,13 +46,13 @@ static long readData(dbCommon *record, format_t *format)
return OK; return OK;
} }
} }
mbbo->val = val; mbbo->val = (epicsEnum16)val;
return DO_NOT_CONVERT; return DO_NOT_CONVERT;
} }
case DBF_ENUM: case DBF_ENUM:
{ {
if (streamScanf(record, format, &val) == ERROR) return ERROR; if (streamScanf(record, format, &val) == ERROR) return ERROR;
mbbo->val = val; mbbo->val = (epicsEnum16)val;
return DO_NOT_CONVERT; return DO_NOT_CONVERT;
} }
case DBF_STRING: case DBF_STRING:
@ -64,7 +64,7 @@ static long readData(dbCommon *record, format_t *format)
{ {
if (strcmp ((&mbbo->zrst)[val], buffer) == 0) if (strcmp ((&mbbo->zrst)[val], buffer) == 0)
{ {
mbbo->val = val; mbbo->val = (epicsEnum16)val;
return DO_NOT_CONVERT; return DO_NOT_CONVERT;
} }
} }

View File

@ -113,14 +113,16 @@ static long readData(dbCommon *record, format_t *format)
break; break;
case DBF_CHAR: case DBF_CHAR:
case DBF_UCHAR: case DBF_UCHAR:
{
ssize_t length;
wf->nord = 0; wf->nord = 0;
if ((lval = streamScanfN(record, format, if ((length = streamScanfN(record, format,
(char *)wf->bptr, wf->nelm)) == ERROR) (char *)wf->bptr, wf->nelm)) == ERROR)
{ {
memset(wf->bptr, 0, wf->nelm); memset(wf->bptr, 0, wf->nelm);
return ERROR; return ERROR;
} }
if ((size_t)lval < wf->nelm) if (length < wf->nelm)
{ {
memset(((char*)wf->bptr)+lval , 0, wf->nelm-lval); memset(((char*)wf->bptr)+lval , 0, wf->nelm-lval);
lval++; lval++;
@ -129,8 +131,9 @@ static long readData(dbCommon *record, format_t *format)
{ {
((char*)wf->bptr)[wf->nelm-1] = 0; ((char*)wf->bptr)[wf->nelm-1] = 0;
} }
wf->nord = lval; wf->nord = (long)length;
return OK; return OK;
}
default: default:
errlogSevPrintf(errlogFatal, errlogSevPrintf(errlogFatal,
"readData %s: can't convert from string to %s\n", "readData %s: can't convert from string to %s\n",