@@ -296,6 +296,7 @@ ctr_dict* ctr_translate_load_dictionary() {
296
296
ctr_dict * previousEntry = NULL ;
297
297
ctr_dict * e ;
298
298
int qq = 0 ;
299
+ char * modifier ;
299
300
while ( fscanf ( file , "%c \"%4999[^\"]\" \"%4999[^\"]\"\n" , & translationType , word , translation ) > 0 ) {
300
301
if (translationType != 't' && translationType != 's' && translationType != 'd' && translationType != 'x' ) {
301
302
printf ("Invalid translation line: %d \n" ,qq );
@@ -304,8 +305,23 @@ ctr_dict* ctr_translate_load_dictionary() {
304
305
entry = (ctr_dict * ) calloc ( sizeof (ctr_dict ), 1 );
305
306
entry -> type = translationType ;
306
307
qq ++ ;
307
-
308
308
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 ;
309
325
entry -> translationLength = strlen (translation );
310
326
if (entry -> type != 's' && (entry -> wordLength > CTR_TRANSLATE_MAX_WORD_LEN || entry -> translationLength > CTR_TRANSLATE_MAX_WORD_LEN )) {
311
327
ctr_print_error (CTR_TERR_ELONG , 1 );
@@ -314,7 +330,6 @@ ctr_dict* ctr_translate_load_dictionary() {
314
330
entry -> translation = calloc ( entry -> translationLength , 1 );
315
331
memcpy (entry -> word , word , entry -> wordLength );
316
332
memcpy (entry -> translation , translation , entry -> translationLength );
317
-
318
333
if (translationType == 'd' ) {
319
334
ctr_trans_d = entry ;
320
335
continue ;
@@ -345,7 +360,7 @@ ctr_dict* ctr_translate_load_dictionary() {
345
360
}
346
361
}
347
362
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 ) {
349
364
format = CTR_TERR_AMTRANS ;
350
365
buffer = ctr_heap_allocate (600 * sizeof (char ));
351
366
snprintf ( buffer , 600 * sizeof (char ), format , translation );
0 commit comments