@@ -1748,6 +1748,7 @@ static int decoderEngine(decodeRec *dec) {
17481748// WARNING - these alphabets have NOT yet been released as standard! use at your own risk! check www.mapcode.com for details.
17491749static UWORD asc2lan [MAPCODE_ALPHABETS_TOTAL ][36 ] = // A-Z equivalents for ascii characters A to Z, 0-9
17501750 {
1751+ // Character: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9
17511752 {0x0041 , 0x0042 , 0x0043 , 0x0044 , 0x0045 , 0x0046 , 0x0047 , 0x0048 , 0x0049 , 0x004a , 0x004b , 0x004c , 0x004d , 0x004e , 0x004f , 0x0050 , 0x0051 , 0x0052 , 0x0053 , 0x0054 , 0x0055 , 0x0056 , 0x0057 , 0x0058 , 0x0059 , 0x005a , 0x0030 , 0x0031 , 0x0032 , 0x0033 , 0x0034 , 0x0035 , 0x0036 , 0x0037 , 0x0038 , 0x0039 }, // roman
17521753 {0x0391 , 0x0392 , 0x039e , 0x0394 , 0x0388 , 0x0395 , 0x0393 , 0x0397 , 0x0399 , 0x03a0 , 0x039a , 0x039b , 0x039c , 0x039d , 0x039f , 0x03a1 , 0x0398 , 0x03a8 , 0x03a3 , 0x03a4 , 0x0389 , 0x03a6 , 0x03a9 , 0x03a7 , 0x03a5 , 0x0396 , 0x0030 , 0x0031 , 0x0032 , 0x0033 , 0x0034 , 0x0035 , 0x0036 , 0x0037 , 0x0038 , 0x0039 }, // greek
17531754 {0x0410 , 0x0412 , 0x0421 , 0x0414 , 0x0415 , 0x0416 , 0x0413 , 0x041d , 0x0418 , 0x041f , 0x041a , 0x041b , 0x041c , 0x0417 , 0x041e , 0x0420 , 0x0424 , 0x042f , 0x0426 , 0x0422 , 0x042d , 0x0427 , 0x0428 , 0x0425 , 0x0423 , 0x0411 , 0x0030 , 0x0031 , 0x0032 , 0x0033 , 0x0034 , 0x0035 , 0x0036 , 0x0037 , 0x0038 , 0x0039 }, // cyrillic
@@ -1907,15 +1908,35 @@ UWORD *convertToAlphabet(UWORD *unibuf, int maxlength, const char *mapcode, int
19071908 * unibuf = 0 ;
19081909 return startbuf ;
19091910 }
1910- * unibuf ++ = * mapcode ++ ;
1911+ * unibuf ++ = ( UWORD ) * mapcode ++ ;
19111912 }
19121913 }
19131914 }
19141915
1915- if (alphabet == 1 || alphabet == 3 || alphabet == 14 ) {
1916+ if (alphabet == 1 || alphabet == 3 || alphabet == 14 ) { // greek hebrew arabic
19161917 mapcode = convertToAbjad (u , mapcode , USIZE );
19171918 }
19181919
1920+ // re-pack E/U-voweled mapcodes when necessary:
1921+ if (alphabet == 1 ) { // alphabet has no letter E (greek!)
1922+ if (strchr (mapcode , 'E' ) || strchr (mapcode , 'U' ) ||
1923+ strchr (mapcode , 'e' ) || strchr (mapcode , 'u' )) {
1924+ // copy trimmed mapcode into temporary buffer u
1925+ int len = (int ) strlen (mapcode );
1926+ if (len < MAX_MAPCODE_RESULT_LEN ) {
1927+ while (len > 0 && mapcode [len - 1 ] > 0 && mapcode [len - 1 ] <= 32 ) {
1928+ len -- ;
1929+ }
1930+ memcpy (u , mapcode , len );
1931+ u [len ] = 0 ;
1932+ // re-pack into A-voweled mapcode
1933+ unpack_if_alldigits (u );
1934+ repack_if_alldigits (u , 1 );
1935+ mapcode = u ;
1936+ }
1937+ }
1938+ }
1939+
19191940 encode_utf16 (unibuf , 1 + (int ) (lastspot - unibuf ), mapcode , alphabet );
19201941 }
19211942 return startbuf ;
@@ -2134,29 +2155,27 @@ static int cmp_alphacode(const void *e1, const void *e2) {
21342155
21352156static int binfindmatch (const int parentcode , const char * str ) {
21362157 // build a 4-letter uppercase search term
2137- char tmp [5 ];
2158+ char alphaCode [5 ];
21382159 const char * r = str ;
21392160 int len = 0 ;
21402161
21412162 if (parentcode < 0 ) {
21422163 return -1 ;
21432164 }
21442165 if (parentcode > 0 ) {
2145- tmp [len ++ ] = (char ) ('0' + parentcode );
2166+ alphaCode [len ++ ] = (char ) ('0' + parentcode );
21462167 }
21472168 while ((len < 4 ) && (* r > 32 )) {
2148- tmp [len ++ ] = * r ++ ;
2169+ alphaCode [len ++ ] = * r ++ ;
21492170 }
21502171 if (* r > 32 ) {
21512172 return -1 ;
21522173 }
2153- tmp [len ] = 0 ;
2154- makeupper (tmp );
2174+ alphaCode [len ] = 0 ;
2175+ makeupper (alphaCode );
21552176 { // binary-search the result
21562177 const alphaRec * p ;
2157- alphaRec t ;
2158- t .alphaCode = tmp ;
2159- t .ccode = parentcode ;
2178+ alphaRec t = {alphaCode , parentcode };
21602179
21612180 p = (const alphaRec * ) bsearch (& t , alphaSearch , NRTERREC , sizeof (alphaRec ), cmp_alphacode );
21622181 if (p ) {
@@ -2605,7 +2624,7 @@ static void convertFromAbjad(char *s) {
26052624 }
26062625 repack_if_alldigits (s , 0 );
26072626 if (postfix ) {
2608- int len = (int ) strlen (s );
2627+ len = (int ) strlen (s );
26092628 * postfix = '-' ;
26102629 memmove (s + len , postfix , strlen (postfix ) + 1 );
26112630 }
0 commit comments