Please find attached patches for the test cases listed in the discussion
of bug #429210 and #773719
In fact the test cases in the discussion are based on more than one bug
in the code.
By and large it makes the impression that the code in libdmtx is of
better quality, but iec16022 is used for package "glabels".
diff -c -r y/iec16022-0.2.4/iec16022ecc200.c fixedifact/iec16022-0.2.4/iec16022ecc200.c
*** y/iec16022-0.2.4/iec16022ecc200.c 2008-11-30 01:22:32.000000000 +0100
--- fixedifact/iec16022-0.2.4/iec16022ecc200.c 2014-12-22 15:09:05.000000000 +0100
***************
*** 357,364 ****
{
unsigned char out[4], p = 0;
if (enc != newenc) { // can only be from C40/Text/X12
! t[tp++] = 254;
! enc = 'a';
}
while (sp < sl && tolower(encoding[sp]) == 'e'
&& p < 4)
--- 357,364 ----
{
unsigned char out[4], p = 0;
if (enc != newenc) { // can only be from C40/Text/X12
! t[tp++] = 240;
! enc = 'e';
}
while (sp < sl && tolower(encoding[sp]) == 'e'
&& p < 4)
***************
*** 367,381 ****
out[p++] = 0x1F;
enc = 'a';
} // termination
! t[tp] = ((s[0] & 0x3F) << 2);
! t[tp++] |= ((s[1] & 0x30) >> 4);
! t[tp] = ((s[1] & 0x0F) << 4);
if (p == 2)
tp++;
else {
! t[tp++] |= ((s[2] & 0x3C) >> 2);
! t[tp] = ((s[2] & 0x03) << 6);
! t[tp++] |= (s[3] & 0x3F);
}
}
break;
--- 367,381 ----
out[p++] = 0x1F;
enc = 'a';
} // termination
! t[tp] = ((out[0] & 0x3F) << 2);
! t[tp++] |= ((out[1] & 0x30) >> 4);
! t[tp] = ((out[1] & 0x0F) << 4);
if (p == 2)
tp++;
else {
! t[tp++] |= ((out[2] & 0x3C) >> 2);
! t[tp] = ((out[2] & 0x03) << 6);
! t[tp++] |= (out[3] & 0x3F);
}
}
break;
diff -c -r y/iec16022-0.2.4/iec16022ecc200.c fixedifactend/iec16022-0.2.4/iec16022ecc200.c
*** y/iec16022-0.2.4/iec16022ecc200.c 2014-12-23 09:46:10.000000000 +0100
--- fixedifactend/iec16022-0.2.4/iec16022ecc200.c 2014-12-23 10:49:46.000000000 +0100
***************
*** 245,251 ****
while (sp < sl && tp < tl) {
char newenc = enc; // suggest new encoding
if (tl - tp <= 1 && (enc == 'c' || enc == 't') || tl - tp <= 2
! && enc == 'x')
enc = 'a'; // auto revert to ASCII
newenc = tolower(encoding[sp]);
switch (newenc) { // encode character
--- 245,251 ----
while (sp < sl && tp < tl) {
char newenc = enc; // suggest new encoding
if (tl - tp <= 1 && (enc == 'c' || enc == 't') || tl - tp <= 2
! && (enc == 'x' || enc == 'e') )
enc = 'a'; // auto revert to ASCII
newenc = tolower(encoding[sp]);
switch (newenc) { // encode character
diff -c -r y/iec16022-0.2.4/iec16022ecc200.c fixedunderscore/iec16022-0.2.4/iec16022ecc200.c
*** y/iec16022-0.2.4/iec16022ecc200.c 2014-12-23 08:21:57.000000000 +0100
--- fixedunderscore/iec16022-0.2.4/iec16022ecc200.c 2014-12-23 08:19:46.000000000 +0100
***************
*** 255,261 ****
{
char out[6], p = 0;
const char *e,
! *s2 = "!\"#$%&'()*+,-./:;<=>?@[\\]_",
*s3 = 0;
if (newenc == 'c') {
e = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
--- 255,261 ----
{
char out[6], p = 0;
const char *e,
! *s2 = "!\"#$%&'()*+,-./:;<=>?@[\\]^_",
*s3 = 0;
if (newenc == 'c') {
e = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
diff -c -r y/iec16022-0.2.4/iec16022ecc200.c fixlength/iec16022-0.2.4/iec16022ecc200.c
*** y/iec16022-0.2.4/iec16022ecc200.c 2014-12-23 09:46:10.000000000 +0100
--- fixlength/iec16022-0.2.4/iec16022ecc200.c 2014-12-23 09:47:30.000000000 +0100
***************
*** 321,327 ****
}
}
}
! if (p == 2 && tp + 2 == tl && sp == sl)
out[p++] = 0; // shift 1 pad at end
while (p >= 3) {
int v =
--- 321,327 ----
}
}
}
! while (p < 3 && sp == sl)
out[p++] = 0; // shift 1 pad at end
while (p >= 3) {
int v =