break;
}
- if (book->debug) {
- fprintf(stderr, "\n");
- for (size_t i = 0 ; i < field->bytes ; i++) {
- unsigned char byte = (unsigned char)data[i];
- fprintf(stderr, "%s -- Byte %zu = 0x%02X (%c)\n",
- field->name, i+1, byte, byte);
- }
- }
-
switch(field->type) {
case CBOOK_FMT_CHAR:
fwrite(data, 1, field->bytes, outfile);
case CBOOK_FMT_UDECIMAL:
;
cstring_t *str = new_cstring();
- int negative = 0;
+ int positive = 1;
int last = 0;
size_t dec_idx = ((field->size) - (field->decimals));
ss++;
int take_first = (ss % 2 == 0);
+ if (book->debug)
+ fprintf(stderr, "\n");
for (size_t i = 0 ; i < field->bytes ; i++) {
unsigned char byte = (unsigned char)data[i];
unsigned char x1 = (byte & 0xF0) >> 4;
last = 1;
if (last && field->type == CBOOK_FMT_DECIMAL) {
- if (x2 < 10) {
+ switch(x2) {
+ case 10: case 12: case 14: case 15:
+ positive = 1; break;
+ case 11: case 13:
+ positive = 0; break;
+ default:
+ positive = -1; break;
+ }
+
+ if (positive < 0) {
char bit[100];
sprintf(bit, "%zu", i+1);
char byte2[3];
sprintf(byte2, "%02X", byte);
cstring_t *tmp = new_cstring();
cstring_add(tmp,
- "Invalid DECIMAL value: ");
+ "Invalid DECIMAL sign value: ");
cstring_add(tmp, "Byte ");
cstring_add(tmp, bit);
cstring_add(tmp, " = 0x");
cstring_add(tmp, byte2);
book->err_mess = cstring_convert(tmp);
}
-
- if ((x2 == 11) || (x2 == 13))
- negative = 1;
}
if ((x1 > 9) || (!last && x2 > 9)) {
if (str->length == dec_idx)
cstring_add_car(str, '.');
}
+
+ if (book->debug) {
+ if ((x1 >= 0) && (x1 <= 9))
+ x1 = '0' + x1;
+ else
+ x1 = '?';
+ if ((x2 >= 0) && (x2 <= 9))
+ x2 = '0' + x2;
+ else
+ x2 = '?';
+ if (last && field->type == CBOOK_FMT_DECIMAL) {
+ if (positive == 1) x2 = '+';
+ else if(positive == 0) x2 = '-';
+ else x2 = '!';
+ }
+ fprintf(stderr, "%s -- Byte %zu = "
+ "0x%02X : %.3i (%c) -> (%c,%c)\n",
+ field->name, i+1, byte, byte,
+ (byte>=32 && byte<=126) ? byte : '?',
+ x1, x2
+ );
+ }
+
}
- if (negative)
+ if (!positive)
fwrite("-", 1, 1, outfile);
fwrite(str->string, 1, str->length, outfile);
break;
case CBOOK_FMT_PICTURE:
fwrite(data, 1, field->bytes, outfile);
+ if (book->debug) {
+ fprintf(stderr, "\n");
+ for (size_t i = 0 ; i < field->bytes ; i++) {
+ unsigned char byte = (unsigned char)data[i];
+ fprintf(stderr, "%s -- Byte %zu = "
+ "0x%02X : %.3i "
+ "(%c)\n",
+ field->name, i,
+ byte, byte,
+ (byte>=32 && byte<=126) ? byte : '?'
+ );
+ }
+ }
break;
//TODO: the rest
case CBOOK_FMT_UFIXED_BINARY:
default:
;
+ if (book->debug) {
+ fprintf(stderr, "\n");
+ for (size_t i = 0 ; i < field->bytes ; i++) {
+ unsigned char byte = (unsigned char)data[i];
+ fprintf(stderr, "%s -- Byte %zu = "
+ "0x%02X : %.3i "
+ "(%c)\n",
+ field->name, i,
+ byte, byte,
+ (byte>=32 && byte<=126) ? byte : '?'
+ );
+ }
+ }
cstring_t *tmp = new_cstring();
cstring_add(tmp, "FMT_");
cstring_add_car(tmp, '0' + field->type);