From a0493a0d0cc48020047d06f6e637d65c8ae9e3a9 Mon Sep 17 00:00:00 2001 From: Robin Stuart Date: Tue, 22 Nov 2016 20:24:33 +0000 Subject: [PATCH] Force flush of last two C40 or Text values in buffer Relates to #38 --- backend/dmatrix.c | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/backend/dmatrix.c b/backend/dmatrix.c index 11560caf..dee968e0 100644 --- a/backend/dmatrix.c +++ b/backend/dmatrix.c @@ -987,35 +987,26 @@ static int dm200encode_remainder(unsigned char target[], int target_length, cons switch (last_mode) { case DM_C40: case DM_TEXT: - if (symbols_left == process_p) // No unlatch required! + if (process_p == 1) // 1 data character left to encode. { - if (process_p == 1) // 1 data character left to encode. - { - target[target_length] = source[inputlen - 1] + 1; - target_length++; - } - - if (process_p == 2) // 2 data characters left to encode. - { - // Pad with shift 1 value (0) and encode as double. - int intValue = (1600 * process_buffer[0]) + (40 * process_buffer[1]) + 1; // ie (0 + 1). - target[target_length] = (unsigned char) (intValue / 256); - target_length++; - target[target_length] = (unsigned char) (intValue % 256); - target_length++; + if (symbols_left > 1) { + target[target_length] = 254; + target_length++; // Unlatch and encode remaining data in ascii. } + target[target_length] = source[inputlen - 1] + 1; + target_length++; } - if (symbols_left > process_p) { - target[target_length] = (254); - target_length++; // Unlatch and encode remaining data in ascii. - if (process_p == 1) { - target[target_length] = source[inputlen - 1] + 1; - target_length++; - } else if (process_p == 2) { - target[target_length] = source[inputlen - 2] + 1; - target_length++; - target[target_length] = source[inputlen - 1] + 1; + if (process_p == 2) // 2 data characters left to encode. + { + // Pad with shift 1 value (0) and encode as double. + int intValue = (1600 * process_buffer[0]) + (40 * process_buffer[1]) + 1; // ie (0 + 1). + target[target_length] = (unsigned char) (intValue / 256); + target_length++; + target[target_length] = (unsigned char) (intValue % 256); + target_length++; + if (symbols_left > 2) { + target[target_length] = 254; // Unlatch target_length++; } }