Skip to content

Commit cce2b50

Browse files
committed
Fix translation modifier issue.
1 parent 053bbbb commit cce2b50

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

translator.c

+18-3
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ ctr_dict* ctr_translate_load_dictionary() {
296296
ctr_dict* previousEntry = NULL;
297297
ctr_dict* e;
298298
int qq = 0;
299+
char* modifier;
299300
while( fscanf( file, "%c \"%4999[^\"]\" \"%4999[^\"]\"\n", &translationType, word, translation) > 0 ) {
300301
if (translationType != 't' && translationType != 's' && translationType != 'd' && translationType != 'x') {
301302
printf("Invalid translation line: %d \n",qq);
@@ -304,8 +305,23 @@ ctr_dict* ctr_translate_load_dictionary() {
304305
entry = (ctr_dict*) calloc( sizeof(ctr_dict), 1 );
305306
entry->type = translationType;
306307
qq++;
307-
308308
entry->wordLength = strlen(word);
309+
// if a word contains a modifier (i.e. same word is used twice, don't continue)
310+
// translation stops, because it's a one-way dictionary.
311+
modifier = strchr(word, '#');
312+
if (modifier) {
313+
// modifiers are used to use the same translation
314+
// for different words, however this makes the translation
315+
// one-way, because translating back you cannot know what the
316+
// word means anymore - this is a feature, translation is not
317+
// a requirement, some code just runs locally only
318+
format = CTR_TERR_AMWORD;
319+
buffer = ctr_heap_allocate(600 * sizeof(char));
320+
snprintf( buffer, 600 * sizeof(char), format, modifier+1);
321+
ctr_print_error( buffer, 1 );
322+
}
323+
modifier = strchr(translation, '#');
324+
if (modifier) translation = modifier + 1;
309325
entry->translationLength = strlen(translation);
310326
if (entry->type != 's' && (entry->wordLength > CTR_TRANSLATE_MAX_WORD_LEN || entry->translationLength > CTR_TRANSLATE_MAX_WORD_LEN)) {
311327
ctr_print_error(CTR_TERR_ELONG, 1);
@@ -314,7 +330,6 @@ ctr_dict* ctr_translate_load_dictionary() {
314330
entry->translation = calloc( entry->translationLength, 1 );
315331
memcpy(entry->word, word, entry->wordLength);
316332
memcpy(entry->translation, translation, entry->translationLength);
317-
318333
if (translationType == 'd') {
319334
ctr_trans_d = entry;
320335
continue;
@@ -345,7 +360,7 @@ ctr_dict* ctr_translate_load_dictionary() {
345360
}
346361
}
347362
if ( e->translationLength == entry->translationLength ) {
348-
if ( strncmp( e->translation, entry->translation, entry->translationLength ) == 0 ) {
363+
if ( strncmp( e->translation, entry->translation, entry->translationLength ) == 0 && !modifier ) {
349364
format = CTR_TERR_AMTRANS;
350365
buffer = ctr_heap_allocate(600 * sizeof(char));
351366
snprintf( buffer, 600 * sizeof(char), format, translation);

0 commit comments

Comments
 (0)