Skip to content

Commit

Permalink
Merge pull request #223 from MikeGray-APH/aph_branch
Browse files Browse the repository at this point in the history
Aph branch
  • Loading branch information
egli committed Nov 24, 2016
2 parents 9649c64 + b00bd07 commit 8e160d1
Show file tree
Hide file tree
Showing 7 changed files with 705 additions and 670 deletions.
16 changes: 15 additions & 1 deletion liblouis/compileTranslationTable.c
Expand Up @@ -279,6 +279,8 @@ static const char *opcodeNames[CTO_None] = {
"before",
"noback",
"nofor",
"empmatchbefore",
"empmatchafter",
"swapcc",
"swapcd",
"swapdd",
Expand Down Expand Up @@ -3836,7 +3838,7 @@ compileRule (FileInfo * nested)
getCharacters(nested, &ptn_after);
getRuleDotsPattern(nested, &ruleDots);

if(!addRule(nested, opcode, &ruleChars, &ruleDots, 0, 0))
if(!addRule(nested, opcode, &ruleChars, &ruleDots, after, before))
ok = 0;

if(ptn_before.chars[0] == '-' && ptn_before.length == 1)
Expand Down Expand Up @@ -4689,6 +4691,18 @@ compileRule (FileInfo * nested)
goto doOpcode;
case CTO_NoFor:
nofor = 1;

case CTO_EmpMatchBefore:

before |= CTC_EmpMatch;
goto doOpcode;

case CTO_EmpMatchAfter:

after |= CTC_EmpMatch;
goto doOpcode;


goto doOpcode;
case CTO_SwapCc:
case CTO_SwapCd:
Expand Down
30 changes: 25 additions & 5 deletions liblouis/lou_translateString.c
Expand Up @@ -2070,7 +2070,7 @@ checkEmphasisChange(const int skip)
{
int i;
for(i = src + (skip + 1); i < src + transRule->charslen; i++)
if((emphasisBuffer[i] & ~CAPS_EMPHASIS) || transNoteBuffer[i])
if(emphasisBuffer[i] || transNoteBuffer[i])
return 1;
return 0;
}
Expand Down Expand Up @@ -2219,11 +2219,27 @@ for_selectRule ()
transCharslen = transRule->charslen;
if (tryThis == 1 || ((transCharslen <= length) && validMatch ()))
{
/* check before emphasis match */
if(transRule->before & CTC_EmpMatch)
{
if( emphasisBuffer[src]
|| transNoteBuffer[src])
break;
}

/* check after emphasis match */
if(transRule->after & CTC_EmpMatch)
{
if( emphasisBuffer[src + transCharslen]
|| transNoteBuffer[src + transCharslen])
break;
}

/* check this rule */
setAfter (transCharslen);
if ((!transRule->after || (beforeAttributes
if ((!(transRule->after & ~CTC_EmpMatch) || (beforeAttributes
& transRule->after)) &&
(!transRule->before || (afterAttributes
(!(transRule->before & ~CTC_EmpMatch) || (afterAttributes
& transRule->before)))
switch (transOpcode)
{ /*check validity of this Translation */
Expand Down Expand Up @@ -2806,6 +2822,10 @@ resolveEmphasisWords(
word_start = i;
word_whole = 0;
}

/* emphasis started on space */
if(!(wordBuffer[i] & WORD_CHAR))
word_start = -1;
}

/* check if at end of emphasis */
Expand Down Expand Up @@ -3529,7 +3549,7 @@ insertEmphasesAt(const int at)
EMPHASIS_END << (min * 4), EMPHASIS_WORD << (min * 4));
else
insertEmphasisEnd(
transNoteBuffer, at, emph6Rule + min,
transNoteBuffer, at, emph1Rule + min,
TRANSNOTE_END << (min * 4), TRANSNOTE_WORD << (min * 4));
}

Expand All @@ -3555,7 +3575,7 @@ insertEmphasesAt(const int at)
type_counts[max] = 0;
if (max >= 5)
insertEmphasisBegin(
transNoteBuffer, at, emph6Rule + max,
transNoteBuffer, at, emph1Rule + max,
TRANSNOTE_BEGIN << (max * 4), TRANSNOTE_END << (max * 4), TRANSNOTE_WORD << (max * 4));
else
insertEmphasisBegin(
Expand Down
5 changes: 4 additions & 1 deletion liblouis/louis.h
Expand Up @@ -110,7 +110,8 @@ typedef enum {
CTC_CapsMode = 0x1000000,
CTC_NumericMode = 0x2000000,
CTC_NumericNoContract = 0x4000000,
CTC_EndOfInput = 0x8000000 // used by pattern matcher
CTC_EndOfInput = 0x8000000, // only used by pattern matcher
CTC_EmpMatch = 0x10000000, // only used in TranslationTableRule->before and TranslationTableRule->after
} TranslationTableCharacterAttribute;

typedef enum {
Expand Down Expand Up @@ -261,6 +262,8 @@ typedef enum { /*Op codes */
CTO_Before, /*only match if before character in class 30 */
CTO_NoBack,
CTO_NoFor,
CTO_EmpMatchBefore,
CTO_EmpMatchAfter,
CTO_SwapCc,
CTO_SwapCd,
CTO_SwapDd,
Expand Down
2 changes: 1 addition & 1 deletion liblouis/pattern.c
Expand Up @@ -1380,7 +1380,7 @@ static int pattern_check_attrs(const widechar input_char, const widechar *expr_d
{
int attrs;

attrs = ((expr_data[0] << 16) | expr_data[1]) & ~CTC_EndOfInput;
attrs = ((expr_data[0] << 16) | expr_data[1]) & ~(CTC_EndOfInput | CTC_EmpMatch);
if(!checkAttr(input_char, attrs, 0))
return 0;
return 1;
Expand Down

0 comments on commit 8e160d1

Please sign in to comment.