@@ -143,11 +151,8 @@ field formatted as a string.
Use in "%(otherrecord.RVAL)f";
to write the floating
point input value into the RVAL
field of
otherrecord
.
-
If no field is given for an other record .VAL is assumed.
When a record name conflicts with a field name use .VAL explicitly.
-
-
This feature is very useful when one line of input contains many values that should
@@ -158,7 +163,7 @@ attribute (see
target="ex">Record Reference Manual), the record will be processed.
It is your responsibility that the data type of the record field is
compatible to the the data type of the converter.
-STRING formats are compatible with arrays of CHAR or UCHAR.
+STRING formats are compatible with arrays of CHAR or UCHAR.
Note that using this syntax is by far not as efficient as using the
@@ -192,11 +197,11 @@ With the #
flag, output always contains a period character.
Input: All these formats are equivalent. Leading whitespaces are skipped.
-
+
With the #
flag additional whitespace between sign and number
is accepted.
-
+
When a maximum field width is given, leading whitespace only counts to the
field witdth when the space flag is used.
@@ -213,7 +218,7 @@ field witdth when the space flag is used.
With the #
flag, octal values are prefixed with 0
and hexadecimal values with 0x
or 0X
.
-
+
Unlike printf, %x
and %X
truncate the
output to the the given width (number of least significant half bytes).
@@ -228,14 +233,14 @@ Octal and hexadecimal values can optionally be prefixed.
hexadecimal notation.
Leading whitespaces are skipped.
-
+
With the -
negative octal and hexadecimal values are accepted.
-
+
With the #
flag additional whitespace between sign and number
is accepted.
-
+
When a maximum field width is given, leading whitespace only counts to the
field witdth when the space flag is used.
@@ -253,13 +258,11 @@ and %c
matches a sequence of not-null characters.
The maximum string length is given by width.
The default width is infinite for %s
and
1 for %c
.
-Leading whitespaces are skipped with %s
-
-except when the space flag is used
-but not with %c
.
+Leading whitespaces are skipped with %s
except when
+the space flag is used but not with %c
.
The empty string matches.
-
+
With the #
flag %s
matches a sequence of not-null
characters instead of non-whitespace characters.
@@ -290,18 +293,18 @@ The strings are separated by |
.
Example: %{OFF|STANDBY|ON}
mapps the string OFF
to the value 0, STANDBY
to 1 and ON
to 2.
-
+
When using the #
flag it is allowed to assign integer values
to the strings using =
.
Unassigned strings increment their values by 1 as usual.
-
+
If one string is the initial substing of another, the substing must come
later to ensure correct matching.
In particular if one string is the emptry string, it must be the last one.
Use #
and =
to renumber if necessary.
-
+
Use the assignment =?
for the last string to make it the
default value for output formats.
@@ -310,12 +313,12 @@ Example: %#{neg=-1|stop|pos|fast=10|rewind=-10}
.
If one of the strings contains |
or }
-(or =
if the #
flag is used)
+(or =
if the #
flag is used)
a \
must be used to escape the character.
Output: Depending on the value, one of the strings is printed,
-or the default if no value matches.
+or the default if no value matches.
Input: If any of the strings matches, the value is set accordingly.
@@ -463,62 +466,158 @@ In input, the next byte or bytes must match the checksum.
Implemented checksum functions
%<sum>
or %<sum8>
- - One byte. The sum of all characters modulo 28.
+ -
+ The sum of all characters modulo 28.
+
+ One byte. 123456789%<sum>
= 0xdd
+
%<sum16>
- - Two bytes. The sum of all characters modulo 216.
+ -
+ The sum of all characters modulo 216.
+
+ Two bytes. 123456789%<sum16>
= 0x01dd
+
%<sum32>
- - Four bytes. The sum of all characters modulo 232.
+ -
+ The sum of all characters modulo 232.
+
+ Four bytes. 123456789%<sum32>
= 0x000001dd
+
%<negsum>
, %<nsum>
, %<-sum>
, %<negsum8>
, %<nsum8>
, or %<-sum8>
- - One byte. The negative of the sum of all characters modulo 28.
+ -
+ The negative of the sum of all characters modulo 28.
+
+ One byte. 123456789%<-sum8>
= 0x23
+
%<negsum16>
, %<nsum16>
, or %<-sum16>
- - Two bytes. The negative of the sum of all characters modulo 216.
+ -
+ The negative of the sum of all characters modulo 216.
+
+ Two bytes. 123456789%<-sum16>
= 0xfe23
+
%<negsum32>
, %<nsum32>
, or %<-sum32>
- - Four bytes. The negative of the sum of all characters modulo 232.
+ -
+ The negative of the sum of all characters modulo 232.
+
+ Four bytes. 123456789%<-sum32>
= 0xfffffe23
+
%<notsum>
or %<~sum>
- - One byte. The bitwise inverse of the sum of all characters modulo 28.
- %<xor>
- - One byte. All characters xor'ed.
- %<xor7>
- - One byte. All characters xor'ed & 0x7F.
- %<crc8>
- - One byte. An often used 8 bit crc checksum
- (poly=0x07, init=0x00, xorout=0x00).
- %<ccitt8>
- - One byte. The CCITT standard 8 bit crc checksum
- (poly=0x31, init=0x00, xorout=0x00).
- %<crc16>
- - Two bytes. An often used 16 bit crc checksum
- (poly=0x8005, init=0x0000, xorout=0x0000).
- %<crc16r>
- - Two bytes. An often used reflected 16 bit crc checksum
- (poly=0x8005, init=0x0000, xorout=0x0000).
- %<ccitt16>
- - Two bytes. The usual (but wrong?)
- implementation of the CCITT standard 16 bit crc checksum
- (poly=0x1021, init=0xFFFF, xorout=0x0000).
- %<ccitt16a>
- - Two bytes. The unusual (but correct?)
- implementation of the CCITT standard 16 bit crc checksum with augment.
- (poly=0x1021, init=0x1D0F, xorout=0x0000).
- %<ccitt16x>
or %<crc16c>
or %<xmodem>
- - Two bytes. The XMODEM checksum.
- (poly=0x1021, init=0x0000, xorout=0x0000).
- %<crc32>
- - Four bytes. The standard 32 bit crc checksum.
- (poly=0x04C11DB7, init=0xFFFFFFFF, xorout=0xFFFFFFFF).
- %<crc32r>
- - Four bytes. The standard reflected 32 bit crc checksum.
- (poly=0x04C11DB7, init=0xFFFFFFFF, xorout=0xFFFFFFFF).
- %<jamcrc>
- - Four bytes. Another reflected 32 bit crc checksum.
- (poly=0x04C11DB7, init=0xFFFFFFFF, xorout=0x00000000).
- %<adler32>
- - Four bytes. The Adler32 checksum according to RFC 1950.
+ -
+ The bitwise inverse of the sum of all characters modulo 28.
+
+ One byte. 123456789%<~sum8>
= 0x22
+
+ %<notsum16>
or %<~sum16>
+ -
+ The bitwise inverse of the sum of all characters modulo 216.
+
+ Two bytes. 123456789%<~sum16>
= 0xfe22
+
+ %<notsum32>
or %<~sum32>
+ -
+ The bitwise inverse of the sum of all characters modulo 232.
+
+ Four bytes. 123456789%<~sum32>
= 0xfffffe22
+
%<hexsum8>
- - One byte. The sum of all hex digits. (Other characters are ignored.)
+ -
+ The sum of all hexadecimal digits. (Other characters are ignored.)
+
+ One byte. 123456789%<hexsum8>
= 0x2d
+
+ %<xor>
+ -
+ All characters xor'ed.
+
+ One byte. 123456789%<xor>
= 0x31
+
+ %<xor7>
+ -
+ All characters xor'ed modulo 27.
+
+ One byte. 123456789%<xor7>
= 0x31
+
+ %<crc8>
+ -
+ An often used 8 bit crc checksum
+ (poly=0x07, init=0x00, xorout=0x00).
+
+ One byte. 123456789%<crc8>
= 0x31
+
+ %<ccitt8>
+ -
+ The CCITT standard 8 bit crc checksum
+ (poly=0x31, init=0x00, xorout=0x00).
+
+ One byte. 123456789%<ccitt8>
= 0xf4
+
+ %<crc16>
+ -
+ An often used 16 bit crc checksum
+ (poly=0x8005, init=0x0000, xorout=0x0000).
+
+ Two bytes. 123456789%<crc16>
= 0xfee8
+
+ %<crc16r>
+ -
+ An often used reflected 16 bit crc checksum
+ (poly=0x8005, init=0x0000, xorout=0x0000).
+
+ Two bytes. 123456789%<crc16r>
= 0xbb3d
+
+ %<ccitt16>
+ -
+ The usual (but wrong?)
+ implementation of the CCITT standard 16 bit crc checksum
+ (poly=0x1021, init=0xFFFF, xorout=0x0000).
+
+ Two bytes. 123456789%<ccitt16>
= 0x29b1
+
+ %<ccitt16a>
+ -
+ The unusual (but correct?)
+ implementation of the CCITT standard 16 bit crc checksum with augment.
+ (poly=0x1021, init=0x1D0F, xorout=0x0000).
+
+ Two bytes. 123456789%<ccitt16a>
= 0xe5cc
+
+ %<ccitt16x>
or %<crc16c>
or %<xmodem>
+ -
+ The XMODEM checksum.
+ (poly=0x1021, init=0x0000, xorout=0x0000).
+
+ Two bytes. 123456789%<xmodem>
= 0x31c3
+
+ %<crc32>
+ -
+ The standard 32 bit crc checksum.
+ (poly=0x04C11DB7, init=0xFFFFFFFF, xorout=0xFFFFFFFF).
+
+ Four bytes. 123456789%<crc32>
= 0xfc891918
+
+ %<crc32r>
+ -
+ The standard reflected 32 bit crc checksum.
+ (poly=0x04C11DB7, init=0xFFFFFFFF, xorout=0xFFFFFFFF).
+
+ Four bytes. 123456789%<crc32r>
= 0xcbf43926
+
+ %<jamcrc>
+ -
+ Another reflected 32 bit crc checksum.
+ (poly=0x04C11DB7, init=0xFFFFFFFF, xorout=0x00000000).
+
+ Four bytes. 123456789%<jamcrc>
= 0x340bc6d9
+
+ %<adler32>
+ -
+ The Adler32 checksum according to RFC 1950.
+
+ Four bytes. 123456789%<adler32>
= 0x091e01de
+
@@ -584,7 +683,6 @@ Format flags +
, -
, and space are supported in
the usual way (always sign, left justified, space instead of + sign).
Flags #
and 0
are unsupported.
-
14. Timestamp DOUBLE converter (%T(timeformat)
)
@@ -637,7 +735,6 @@ Because of the complexity of the problem, locales are not supported.
Thus, only the English month names can be used (week day names are
ignored anyway).
-
Next: Record Processing
Dirk Zimoch, 2011
diff --git a/src/StreamCore.cc b/src/StreamCore.cc
index 19da960..e32fb50 100644
--- a/src/StreamCore.cc
+++ b/src/StreamCore.cc
@@ -1479,6 +1479,7 @@ scanValue(const StreamFormat& fmt, long& value)
}
else return -1;
}
+ if (fmt.flags & fix_width_flag && consumed != fmt.width) return -1;
if (consumed > inputLine.length()-consumedInput) return -1;
debug("StreamCore::scanValue(%s) scanned %li\n",
name(), value);
@@ -1510,6 +1511,7 @@ scanValue(const StreamFormat& fmt, double& value)
}
else return -1;
}
+ if (fmt.flags & fix_width_flag && (consumed != (fmt.width + fmt.prec + 1))) return -1;
if (consumed > inputLine.length()-consumedInput) return -1;
debug("StreamCore::scanValue(%s) scanned %#g\n",
name(), value);
@@ -1542,6 +1544,7 @@ scanValue(const StreamFormat& fmt, char* value, long maxlen)
}
else return -1;
}
+ if (fmt.flags & fix_width_flag && consumed != fmt.width) return -1;
if (consumed > inputLine.length()-consumedInput) return -1;
#ifndef NO_TEMPORARY
debug("StreamCore::scanValue(%s) scanned \"%s\"\n",
diff --git a/src/StreamFormat.h b/src/StreamFormat.h
index 79e22b9..a1b249c 100644
--- a/src/StreamFormat.h
+++ b/src/StreamFormat.h
@@ -30,7 +30,8 @@ typedef enum {
zero_flag = 0x10,
skip_flag = 0x20,
default_flag = 0x40,
- compare_flag = 0x80
+ compare_flag = 0x80,
+ fix_width_flag = 0x100,
} StreamFormatFlag;
typedef enum {
@@ -48,7 +49,7 @@ typedef struct StreamFormat
{
char conv;
StreamFormatType type;
- unsigned char flags;
+ unsigned short flags;
short prec;
unsigned short width;
unsigned short infolen;
diff --git a/src/StreamFormatConverter.cc b/src/StreamFormatConverter.cc
index d03f516..2b0c315 100644
--- a/src/StreamFormatConverter.cc
+++ b/src/StreamFormatConverter.cc
@@ -38,7 +38,7 @@ parseFormat(const char*& source, FormatType formatType, StreamFormat& streamForm
{
/*
source := [flags] [width] ['.' prec] conv [extra]
- flags := '-' | '+' | ' ' | '#' | '0' | '*' | '?' | '='
+ flags := '-' | '+' | ' ' | '#' | '0' | '*' | '?' | '=' | '!'
width := integer
prec := integer
conv := character
@@ -85,6 +85,15 @@ parseFormat(const char*& source, FormatType formatType, StreamFormat& streamForm
}
streamFormat.flags |= default_flag;
break;
+ case '!':
+ if (formatType != ScanFormat)
+ {
+ error("Use of fixed width modifier '!' "
+ "only allowed in input formats\n");
+ return false;
+ }
+ streamFormat.flags |= fix_width_flag;
+ break;
case '=':
if (formatType != ScanFormat)
{