Revision: 616 Author: bertfrees@xxxxxxxxx Date: Mon May 14 05:12:03 2012Log: Fixed inputPos for situation where context and multipass opcodes are involved
http://code.google.com/p/liblouis/source/detail?r=616 Modified: /trunk/liblouis/compileTranslationTable.c /trunk/liblouis/lou_translateString.c /trunk/liblouis/louis.h /trunk/liblouis/transcommon.ci ======================================= --- /trunk/liblouis/compileTranslationTable.c Fri May 11 05:41:02 2012 +++ /trunk/liblouis/compileTranslationTable.c Mon May 14 05:12:03 2012 @@ -5041,7 +5041,9 @@ static widechar *passbuf2 = NULL; static int sizePassbuf2 = 0; static int *srcMapping = NULL; +static int *prevSrcMapping = NULL; static int sizeSrcMapping = 0; +static int sizePrevSrcMapping = 0; void * liblouis_allocMem (AllocBuf buffer, int srcmax, int destmax) { @@ -5103,6 +5105,22 @@ } } return srcMapping; + case alloc_prevSrcMapping: + { + int mapSize; + if (srcmax >= destmax) + mapSize = srcmax; + else + mapSize = destmax; + if (mapSize > sizePrevSrcMapping) + { + if (prevSrcMapping != NULL) + free (prevSrcMapping); + prevSrcMapping = malloc ((mapSize + 4) * sizeof (int)); + sizePrevSrcMapping = mapSize; + } + } + return prevSrcMapping; default: return NULL; } @@ -5146,7 +5164,11 @@ if (srcMapping != NULL) free (srcMapping); srcMapping = NULL; + if (prevSrcMapping != NULL) + free (prevSrcMapping); + prevSrcMapping = NULL; sizeSrcMapping = 0; + sizePrevSrcMapping = 0; opcodeLengths[0] = 0; } ======================================= --- /trunk/liblouis/lou_translateString.c Mon Apr 16 06:02:10 2012 +++ /trunk/liblouis/lou_translateString.c Mon May 14 05:12:03 2012 @@ -124,6 +124,8 @@ return 0;if (!(srcMapping = liblouis_allocMem (alloc_srcMapping, srcmax, destmax)))
return 0;+ if (!(prevSrcMapping = liblouis_allocMem (alloc_prevSrcMapping, srcmax, destmax)))
+ return 0; for (k = 0; k <= srcmax; k++) srcMapping[k] = k; srcMapping[srcmax] = srcmax; @@ -149,6 +151,7 @@ } while (currentPass <= table->numPasses && goodTrans) { + memcpy(prevSrcMapping, srcMapping, destmax * sizeof(int)); switch (currentPass) { case 0: @@ -210,6 +213,8 @@ } *inlen = srcMapping[realInlen]; *outlen = dest; + if (inputPositions != NULL) + memcpy(inputPositions, srcMapping, destmax * sizeof(int)); if (outputPos != NULL) { int lastpos = 0; @@ -344,7 +349,7 @@ for (k = 0; k < outLength; k++) { if (inputPositions != NULL) - inputPositions[dest + k] = srcMapping[src]; + srcMapping[dest + k] = prevSrcMapping[src]; if (outputPositions != NULL) outputPositions[srcMapping[src + k]] = dest; } @@ -357,13 +362,13 @@ for (k = 0; k < inLength; k++) { if (inputPositions != NULL) - inputPositions[dest + k] = srcMapping[src]; + srcMapping[dest + k] = prevSrcMapping[src]; if (outputPositions != NULL) outputPositions[srcMapping[src + k]] = dest; } for (k = inLength; k < outLength; k++) if (inputPositions != NULL) - inputPositions[dest + k] = srcMapping[src]; + srcMapping[dest + k] = prevSrcMapping[src]; } } dest += outLength; @@ -1450,7 +1455,7 @@ for (k = 0; k < strlen (display); k++) { if (inputPositions != NULL) - inputPositions[dest] = srcMapping[src]; + srcMapping[dest] = prevSrcMapping[src]; currentOutput[dest++] = getDotsForChar (display[k]); } return 1; ======================================= --- /trunk/liblouis/louis.h Fri May 4 11:03:27 2012 +++ /trunk/liblouis/louis.h Mon May 14 05:12:03 2012 @@ -474,7 +474,8 @@ alloc_destSpacing, alloc_passbuf1, alloc_passbuf2, - alloc_srcMapping + alloc_srcMapping, + alloc_prevSrcMapping } AllocBuf; /* The following function definitions are hooks into * compileTranslationTable.c. Some are used by other library modules. ======================================= --- /trunk/liblouis/transcommon.ci Tue Jan 31 05:49:30 2012 +++ /trunk/liblouis/transcommon.ci Mon May 14 05:12:03 2012 @@ -49,6 +49,7 @@ static widechar *passbuf1 = NULL; static widechar *passbuf2 = NULL; static widechar *currentOutput; +static int *prevSrcMapping = NULL; static int *srcMapping = NULL; static unsigned short *typebuf = NULL; static unsigned char *srcSpacing = NULL; @@ -240,7 +241,7 @@ case CTO_Always: if (dest >= destmax) goto failure; - srcMapping[dest] = srcMapping[src]; + srcMapping[dest] = prevSrcMapping[src]; currentOutput[dest++] = currentInput[src++]; break; case CTO_Correct: @@ -370,7 +371,7 @@ { if ((dest + 1) >= srcmax) return 0; - srcMapping[dest] = srcMapping[curSrc]; + srcMapping[dest] = prevSrcMapping[curSrc]; currentOutput[dest++] = replacements[curPos]; } else @@ -379,7 +380,7 @@ if ((dest + replacements[curPos] - 1) >= destmax) return 0; for (k = dest + replacements[curPos] - 1; k >= dest; --k) - srcMapping[k] = srcMapping[curSrc]; + srcMapping[k] = prevSrcMapping[curSrc]; memcpy (¤tOutput[dest], &replacements[curPos + 1], (replacements[curPos]) * CHARSIZE); dest += replacements[curPos] - 1; @@ -854,7 +855,7 @@ if ((dest + startReplace - startMatch) > destmax) return 0; if (transOpcode != CTO_Context) - memmove (&srcMapping[dest], &srcMapping[startMatch], + memmove (&srcMapping[dest], &prevSrcMapping[startMatch], (startReplace - startMatch) * sizeof (int)); for (k = startMatch; k < startReplace; k++) if (transOpcode == CTO_Context) @@ -872,7 +873,7 @@ if ((dest + passInstructions[passIC + 1]) > destmax) return 0; for (k = 0; k < passInstructions[passIC + 1]; ++k) - srcMapping[dest + k] = startMatch; + srcMapping[dest + k] = prevSrcMapping[startMatch]; memcpy (¤tOutput[dest], &passInstructions[passIC + 2], passInstructions[passIC + 1] * CHARSIZE); dest += passInstructions[passIC + 1]; @@ -897,7 +898,7 @@ ruleOffset = (passInstructions[passIC + 1] << 16) | passInstructions[passIC + 2]; rule = (TranslationTableRule *) & table->ruleArea[ruleOffset]; - srcMapping[dest] = startMatch; + srcMapping[dest] = prevSrcMapping[startMatch]; currentOutput[dest++] = rule->charsdots[2 * passCharDots]; passIC += 3; break; @@ -905,7 +906,7 @@ ruleOffset = (passInstructions[passIC + 1] << 16) | passInstructions[passIC + 2]; rule = (TranslationTableRule *) & table->ruleArea[ruleOffset]; - srcMapping[dest] = startMatch; + srcMapping[dest] = prevSrcMapping[startMatch]; currentOutput[dest++] = rule->charsdots[2 * passCharDots + 1]; passIC += 3; break; @@ -929,7 +930,7 @@ k = endReplace - startReplace; if ((dest + k) > destmax) return 0; - memmove (&srcMapping[dest], &srcMapping[startReplace], + memmove (&srcMapping[dest], &prevSrcMapping[startReplace], k * sizeof (int)); memcpy (¤tOutput[dest], ¤tInput[startReplace], k * CHARSIZE); @@ -1054,14 +1055,14 @@ case CTO_Always: if ((dest + 1) > destmax) goto failure; - srcMapping[dest] = srcMapping[src]; + srcMapping[dest] = prevSrcMapping[src]; currentOutput[dest++] = currentInput[src++]; break; default: goto failure; } } - srcMapping[dest] = srcMapping[src]; + srcMapping[dest] = prevSrcMapping[src]; failure:if (src < srcmax) { while (checkAttr (currentInput[src], CTC_Space, 1)) For a description of the software, to download it and links to project pages go to http://www.abilitiessoft.com