| 1 | /* liblouis Braille Translation and Back-Translation Library |
| 2 | |
| 3 | Copyright (C) 2008 Eitan Isaacson <[email protected]> |
| 4 | Copyright (C) 2012 James Teh <[email protected]> |
| 5 | Copyright (C) 2012 Bert Frees <[email protected]> |
| 6 | Copyright (C) 2014 Mesar Hameed <[email protected]> |
| 7 | Copyright (C) 2015 Mike Gray <[email protected]> |
| 8 | Copyright (C) 2010-2017 Swiss Library for the Blind, Visually Impaired and Print |
| 9 | Disabled |
| 10 | Copyright (C) 2016-2017 Davy Kager <[email protected]> |
| 11 | |
| 12 | Copying and distribution of this file, with or without modification, |
| 13 | are permitted in any medium without royalty provided the copyright |
| 14 | notice and this notice are preserved. This file is offered as-is, |
| 15 | without any warranty. |
| 16 | */ |
| 17 | |
| 18 | /** |
| 19 | * @file |
| 20 | * @brief Test helper functions |
| 21 | */ |
| 22 | |
| 23 | #include <config.h>cxx . . $ `<file>/liblouis/config.h`/ |
| 24 | |
| 25 | #include <assert.h> |
| 26 | #include <stdio.h>cxx . . $ `<file>/tools/gnulib/stdio.h`/ |
| 27 | #include <stdlib.h>cxx . . $ `<file>/gnulib/stdlib.h`/ |
| 28 | #include <string.h>cxx . . $ `<file>/gnulib/string.h`/ |
| 29 | #include "liblouis.h"cxx . . $ `<file>/liblouis/liblouis.h`/ |
| 30 | #include "internal.h"cxx . . $ `<file>/liblouis/internal.h`/ |
| 31 | #include "brl_checks.h"cxx . . $ `<file>/tools/brl_checks.h`/ |
| 32 | #include "unistr.h"cxx . . $ `<file>/tools/gnulib/unistr.h`/ |
| 33 | |
| 34 | /* see http://stackoverflow.com/questions/5117393/utf-8-strings-length-in-linux-c */ |
| 35 | static int |
| 36 | my_strlen_utf8_ccxx . . $ my_strlen_utf8_c(1ef8e6ec083aabb9).(char *s) { |
| 37 | int i = 0, j = 0; |
| 38 | while (s[i]) { |
| 39 | if ((s[i] & 0xc0) != 0x80) j++; |
| 40 | i++; |
| 41 | } |
| 42 | return j; |
| 43 | } |
| 44 | |
| 45 | /* |
| 46 | * String parsing is also done later in check_base. At this point we |
| 47 | * only need it to compute the actual string length in order to be |
| 48 | * able to provide error messages when parsing typeform and position arrays. |
| 49 | */ |
| 50 | int |
| 51 | parsed_strlencxx . . $ parsed_strlen(1ef8e6ec083aabb9).(char *s) { |
| 52 | widecharcxx . . $ widechar# *buf; |
| 53 | int len, maxlen; |
| 54 | maxlen = my_strlen_utf8_ccxx . . $ my_strlen_utf8_c(1ef8e6ec083aabb9).(s); |
| 55 | buf = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(widecharcxx . . $ widechar#) * maxlen); |
| 56 | len = _lou_extParseCharscxx . . $ _lou_extParseChars(c9bce2f4bcd31d4).(s, buf); |
| 57 | freecxx . . $ free(5d22bdacc48458e8).(buf); |
| 58 | return len; |
| 59 | } |
| 60 | |
| 61 | static void |
| 62 | print_int_arraycxx . . $ print_int_array(b0c9ee718bb13ade).(const char *prefix, int *pos_list, int len) { |
| 63 | int i; |
| 64 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s ", prefix); |
| 65 | for (i = 0; i < len; i++) fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%d ", pos_list[i]); |
| 66 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\n"); |
| 67 | } |
| 68 | |
| 69 | static void |
| 70 | print_typeformcxx . . $ print_typeform(280060e335061cbc).(const formtypecxx . . $ formtype# *typeform, int len) { |
| 71 | int i; |
| 72 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Typeform: "); |
| 73 | for (i = 0; i < len; i++) fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%hi", typeform[i]); |
| 74 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\n"); |
| 75 | } |
| 76 | |
| 77 | static void |
| 78 | print_widecharscxx . . $ print_widechars(9ead97ff5579f406).(widecharcxx . . $ widechar# *buffer, int length) { |
| 79 | uint8_tcxx . . $ uint8_t# *result_buf; |
| 80 | size_tcxx . . $ size_t# result_len; |
| 81 | |
| 82 | #ifdef WIDECHARS_ARE_UCS4 |
| 83 | result_buf = u32_to_u8(buffer, length, NULL, &result_len); |
| 84 | #else |
| 85 | result_buf = u16_to_u8cxx . . $ u16_to_u8(e729bd8f99eea2d2).(buffer, length, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!, &result_len); |
| 86 | #endif |
| 87 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%.*s", (int)result_len, result_buf); |
| 88 | freecxx . . $ free(5d22bdacc48458e8).(result_buf); |
| 89 | } |
| 90 | |
| 91 | /* direction, 0=forward, 1=backwards. If diagnostics is 1 then print |
| 92 | * diagnostics in case where the translation is not as expected */ |
| 93 | |
| 94 | int |
| 95 | check_basecxx . . $ check_base(ac373b73bdec0de6).(const char *tableList, const char *input, const char *expected, |
| 96 | optional_test_paramscxx . . $ optional_test_params# in) { |
| 97 | |
| 98 | int i, retval = 0; |
| 99 | int direction = in.directioncxx . . $ $anonymous_type_be9fbadca6c15a59_0#direction.; |
| 100 | const int *expected_inputPos = in.expected_inputPoscxx . . $ $anonymous_type_be9fbadca6c15a59_0#expected_inputPos.; |
| 101 | const int *expected_outputPos = in.expected_outputPoscxx . . $ $anonymous_type_be9fbadca6c15a59_0#expected_outputPos.; |
| 102 | if (in.directioncxx . . $ $anonymous_type_be9fbadca6c15a59_0#direction. < 0 || in.directioncxx . . $ $anonymous_type_be9fbadca6c15a59_0#direction. > 1) { |
| 103 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Invalid direction.\n"); |
| 104 | return 1; |
| 105 | } |
| 106 | if (in.directioncxx . . $ $anonymous_type_be9fbadca6c15a59_0#direction. != 0 && in.typeformcxx . . $ $anonymous_type_be9fbadca6c15a59_0#typeform. != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 107 | // In backward translation, the typeform argument is for output only (emphasis |
| 108 | // detection). Use expected_typeform instead to verify backtranslation typeform. |
| 109 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, |
| 110 | "typeform (input) only supported with testmode 'forward'. " |
| 111 | "Use expected_typeform for backward translation.\n"); |
| 112 | return 1; |
| 113 | } |
| 114 | if (in.directioncxx . . $ $anonymous_type_be9fbadca6c15a59_0#direction. == 0 && in.expected_typeformcxx . . $ $anonymous_type_be9fbadca6c15a59_0#expected_typeform. != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 115 | // In forward translation, typeform is an input parameter. Use expected_typeform |
| 116 | // only for backward translation to verify emphasis detection output. |
| 117 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "expected_typeform only supported with testmode 'backward'\n"); |
| 118 | return 1; |
| 119 | } |
| 120 | if (in.directioncxx . . $ $anonymous_type_be9fbadca6c15a59_0#direction. == 2 && in.cursorPoscxx . . $ $anonymous_type_be9fbadca6c15a59_0#cursorPos. >= 0) { |
| 121 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "cursorPos not supported with testmode 'bothDirections'\n"); |
| 122 | return 1; |
| 123 | } |
| 124 | if (in.directioncxx . . $ $anonymous_type_be9fbadca6c15a59_0#direction. == 2 && in.max_outlencxx . . $ $anonymous_type_be9fbadca6c15a59_0#max_outlen. >= 0) { |
| 125 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "maxOutputLength not supported with testmode 'bothDirections'\n"); |
| 126 | return 1; |
| 127 | } |
| 128 | if (in.real_inlencxx . . $ $anonymous_type_be9fbadca6c15a59_0#real_inlen. >= 0 && in.max_outlencxx . . $ $anonymous_type_be9fbadca6c15a59_0#max_outlen. < 0) { |
| 129 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, |
| 130 | "realInputLength not supported when maxOutputLength is not specified\n"); |
| 131 | return 1; |
| 132 | } |
| 133 | widecharcxx . . $ widechar# *inbuf, *outbuf, *expectedbuf; |
| 134 | int inlen = parsed_strlencxx . . $ parsed_strlen(1ef8e6ec083aabb9).(input); |
| 135 | int actualInlen; |
| 136 | const int outlen_multiplier = 4 + sizeof(widecharcxx . . $ widechar#) * 2; |
| 137 | int outlen = inlen * outlen_multiplier; |
| 138 | int expectedlen = strlencxx . . $ strlen(751346f8406fd082).(expected); |
| 139 | int funcStatus = 0; |
| 140 | formtypecxx . . $ formtype# *typeformbuf = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 141 | int *inputPos = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 142 | int *outputPos = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 143 | int cursorPos = 0; |
| 144 | inbuf = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(widecharcxx . . $ widechar#) * inlen); |
| 145 | // + 1 : reserved for the '\0' terminator of C-format string argument used in |
| 146 | // `print_widechars` |
| 147 | outbuf = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(widecharcxx . . $ widechar#) * (outlen + 1)); |
| 148 | expectedbuf = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(widecharcxx . . $ widechar#) * expectedlen); |
| 149 | if (in.typeformcxx . . $ $anonymous_type_be9fbadca6c15a59_0#typeform. != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 150 | typeformbuf = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(outlen * sizeof(formtypecxx . . $ formtype#)); |
| 151 | memcpycxx . . $ memcpy(cc817cb175f282d).(typeformbuf, in.typeformcxx . . $ $anonymous_type_be9fbadca6c15a59_0#typeform., inlen * sizeof(formtypecxx . . $ formtype#)); |
| 152 | } else if (in.expected_typeformcxx . . $ $anonymous_type_be9fbadca6c15a59_0#expected_typeform. != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 153 | // Allocate typeform buffer to receive backtranslation emphasis output |
| 154 | typeformbuf = calloccxx . . $ calloc(63a7bf2941bfcd7a).(outlen, sizeof(formtypecxx . . $ formtype#)); |
| 155 | } |
| 156 | if (in.cursorPoscxx . . $ $anonymous_type_be9fbadca6c15a59_0#cursorPos. >= 0) { |
| 157 | cursorPos = in.cursorPoscxx . . $ $anonymous_type_be9fbadca6c15a59_0#cursorPos.; |
| 158 | } |
| 159 | if (in.max_outlencxx . . $ $anonymous_type_be9fbadca6c15a59_0#max_outlen. >= 0) { |
| 160 | outlen = in.max_outlencxx . . $ $anonymous_type_be9fbadca6c15a59_0#max_outlen.; |
| 161 | } |
| 162 | inlen = _lou_extParseCharscxx . . $ _lou_extParseChars(c9bce2f4bcd31d4).(input, inbuf); |
| 163 | if (!inlen) { |
| 164 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Cannot parse input string.\n"); |
| 165 | retval = 1; |
| 166 | goto fail; |
| 167 | } |
| 168 | if (in.real_inlencxx . . $ $anonymous_type_be9fbadca6c15a59_0#real_inlen. > inlen) { |
| 169 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, |
| 170 | "expected realInputLength (%d) may not exceed total input length " |
| 171 | "(%d)\n", |
| 172 | in.real_inlencxx . . $ $anonymous_type_be9fbadca6c15a59_0#real_inlen., inlen); |
| 173 | return 1; |
| 174 | } |
| 175 | if (expected_inputPos) { |
| 176 | inputPos = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(int) * outlen); |
| 177 | } |
| 178 | if (expected_outputPos) { |
| 179 | outputPos = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(int) * inlen); |
| 180 | } |
| 181 | actualInlen = inlen; |
| 182 | // Note that this loop is not strictly needed to make the current tests pass, but |
| 183 | // in the general case it is needed because it is theoretically possible that we |
| 184 | // provided a too short output buffer. |
| 185 | for (int k = 1; k <= 3; k++) { |
| 186 | if (direction == 1) { |
| 187 | funcStatus = _lou_backTranslatecxx . . $ _lou_backTranslate(5fc2ab337e0d897c).(tableList, in.display_tablecxx . . $ $anonymous_type_be9fbadca6c15a59_0#display_table., inbuf, |
| 188 | &actualInlen, outbuf, &outlen, typeformbuf, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!, outputPos, inputPos, |
| 189 | &cursorPos, in.modecxx . . $ $anonymous_type_be9fbadca6c15a59_0#mode., NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!); |
| 190 | } else { |
| 191 | funcStatus = _lou_translatecxx . . $ _lou_translate(5fc2ab337e0d897c).(tableList, in.display_tablecxx . . $ $anonymous_type_be9fbadca6c15a59_0#display_table., inbuf, &actualInlen, |
| 192 | outbuf, &outlen, typeformbuf, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!, outputPos, inputPos, &cursorPos, |
| 193 | in.modecxx . . $ $anonymous_type_be9fbadca6c15a59_0#mode., NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!); |
| 194 | } |
| 195 | if (!funcStatus) { |
| 196 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Translation failed.\n"); |
| 197 | retval = 1; |
| 198 | goto fail; |
| 199 | } |
| 200 | if (in.max_outlencxx . . $ $anonymous_type_be9fbadca6c15a59_0#max_outlen. >= 0 || inlen == actualInlen) { |
| 201 | break; |
| 202 | } else if (k < 3) { |
| 203 | // Hm, something is not quite right. Try again with a larger outbuf |
| 204 | freecxx . . $ free(5d22bdacc48458e8).(outbuf); |
| 205 | outlen = inlen * outlen_multiplier * (k + 1); |
| 206 | // + 1 : reserved for the '\0' terminator of C-format string argument used in |
| 207 | // `print_widechars` |
| 208 | outbuf = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(widecharcxx . . $ widechar#) * (outlen + 1)); |
| 209 | if (expected_inputPos) { |
| 210 | freecxx . . $ free(5d22bdacc48458e8).(inputPos); |
| 211 | inputPos = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(int) * outlen); |
| 212 | } |
| 213 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, |
| 214 | "Warning: For %s: returned inlen (%d) differs from passed inlen " |
| 215 | "(%d) " |
| 216 | "using outbuf of size %d. Trying again with bigger outbuf " |
| 217 | "(%d).\n", |
| 218 | input, actualInlen, inlen, inlen * outlen_multiplier * k, outlen); |
| 219 | actualInlen = inlen; |
| 220 | } |
| 221 | } |
| 222 | expectedlen = _lou_extParseCharscxx . . $ _lou_extParseChars(c9bce2f4bcd31d4).(expected, expectedbuf); |
| 223 | for (i = 0; i < outlen && i < expectedlen && expectedbuf[i] == outbuf[i]; i++); |
| 224 | if (i < outlen || i < expectedlen) { |
| 225 | retval = 1; |
| 226 | if (in.diagnosticscxx . . $ $anonymous_type_be9fbadca6c15a59_0#diagnostics.) { |
| 227 | outbuf[outlen] = 0; |
| 228 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Input: '%s'\n", input); |
| 229 | /* Print the original typeform not the typeformbuf, as the |
| 230 | * latter has been modified by the translation and contains some |
| 231 | * information about outbuf */ |
| 232 | if (in.typeformcxx . . $ $anonymous_type_be9fbadca6c15a59_0#typeform. != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) print_typeformcxx . . $ print_typeform(280060e335061cbc).(in.typeformcxx . . $ $anonymous_type_be9fbadca6c15a59_0#typeform., inlen); |
| 233 | if (in.cursorPoscxx . . $ $anonymous_type_be9fbadca6c15a59_0#cursorPos. >= 0) fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Cursor: %d\n", in.cursorPoscxx . . $ $anonymous_type_be9fbadca6c15a59_0#cursorPos.); |
| 234 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Expected: '%s' (length %d)\n", expected, expectedlen); |
| 235 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Received: '"); |
| 236 | print_widecharscxx . . $ print_widechars(9ead97ff5579f406).(outbuf, outlen); |
| 237 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "' (length %d)\n", outlen); |
| 238 | |
| 239 | uint8_tcxx . . $ uint8_t# *expected_utf8; |
| 240 | uint8_tcxx . . $ uint8_t# *out_utf8; |
| 241 | size_tcxx . . $ size_t# expected_utf8_len; |
| 242 | size_tcxx . . $ size_t# out_utf8_len; |
| 243 | #ifdef WIDECHARS_ARE_UCS4 |
| 244 | expected_utf8 = u32_to_u8(&expectedbuf[i], 1, NULL, &expected_utf8_len); |
| 245 | out_utf8 = u32_to_u8(&outbuf[i], 1, NULL, &out_utf8_len); |
| 246 | #else |
| 247 | expected_utf8 = u16_to_u8cxx . . $ u16_to_u8(e729bd8f99eea2d2).(&expectedbuf[i], 1, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!, &expected_utf8_len); |
| 248 | out_utf8 = u16_to_u8cxx . . $ u16_to_u8(e729bd8f99eea2d2).(&outbuf[i], 1, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!, &out_utf8_len); |
| 249 | #endif |
| 250 | |
| 251 | if (i < outlen && i < expectedlen) { |
| 252 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, |
| 253 | "Diff: Expected '%.*s' but received '%.*s' in index %d\n", |
| 254 | (int)expected_utf8_len, expected_utf8, (int)out_utf8_len, |
| 255 | out_utf8, i); |
| 256 | } else if (i < expectedlen) { |
| 257 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, |
| 258 | "Diff: Expected '%.*s' but received nothing in index " |
| 259 | "%d\n", |
| 260 | (int)expected_utf8_len, expected_utf8, i); |
| 261 | } else { |
| 262 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, |
| 263 | "Diff: Expected nothing but received '%.*s' in index " |
| 264 | "%d\n", |
| 265 | (int)out_utf8_len, out_utf8, i); |
| 266 | } |
| 267 | freecxx . . $ free(5d22bdacc48458e8).(expected_utf8); |
| 268 | freecxx . . $ free(5d22bdacc48458e8).(out_utf8); |
| 269 | } |
| 270 | } |
| 271 | if (expected_inputPos) { |
| 272 | int error_printed = 0; |
| 273 | // The expected_inputPos array may be shorter than the actual input length. |
| 274 | for (i = 0; i < outlen || i < expectedlen; i++) { |
| 275 | if (i < outlen && i < expectedlen && expected_inputPos[i] == inputPos[i]) |
| 276 | continue; |
| 277 | retval = 1; |
| 278 | if (in.diagnosticscxx . . $ $anonymous_type_be9fbadca6c15a59_0#diagnostics.) { |
| 279 | if (!error_printed) { // Print only once |
| 280 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Input position failure:\n"); |
| 281 | error_printed = 1; |
| 282 | } |
| 283 | if (i < outlen && i < expectedlen) { |
| 284 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Expected %d, received %d in index %d\n", |
| 285 | expected_inputPos[i], inputPos[i], i); |
| 286 | } else if (i < expectedlen) { |
| 287 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Expected %d, received nothing in index %d\n", |
| 288 | expected_inputPos[i], i); |
| 289 | } else { |
| 290 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Expected nothing, received %d in index %d\n", |
| 291 | inputPos[i], i); |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | if (expected_outputPos) { |
| 297 | int error_printed = 0; |
| 298 | for (i = 0; i < inlen; i++) { |
| 299 | if (expected_outputPos[i] != outputPos[i]) { |
| 300 | retval = 1; |
| 301 | if (in.diagnosticscxx . . $ $anonymous_type_be9fbadca6c15a59_0#diagnostics.) { |
| 302 | if (!error_printed) { // Print only once |
| 303 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Output position failure:\n"); |
| 304 | error_printed = 1; |
| 305 | } |
| 306 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Expected %d, received %d in index %d\n", |
| 307 | expected_outputPos[i], outputPos[i], i); |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | if ((in.expected_cursorPoscxx . . $ $anonymous_type_be9fbadca6c15a59_0#expected_cursorPos. >= 0) && (cursorPos != in.expected_cursorPoscxx . . $ $anonymous_type_be9fbadca6c15a59_0#expected_cursorPos.)) { |
| 313 | retval = 1; |
| 314 | if (in.diagnosticscxx . . $ $anonymous_type_be9fbadca6c15a59_0#diagnostics.) { |
| 315 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Cursor position failure:\n"); |
| 316 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Initial:%d Expected:%d Actual:%d \n", in.cursorPoscxx . . $ $anonymous_type_be9fbadca6c15a59_0#cursorPos., |
| 317 | in.expected_cursorPoscxx . . $ $anonymous_type_be9fbadca6c15a59_0#expected_cursorPos., cursorPos); |
| 318 | } |
| 319 | } |
| 320 | if (in.expected_typeformcxx . . $ $anonymous_type_be9fbadca6c15a59_0#expected_typeform. != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 321 | int error_printed = 0; |
| 322 | for (i = 0; i < outlen; i++) { |
| 323 | if (in.expected_typeformcxx . . $ $anonymous_type_be9fbadca6c15a59_0#expected_typeform.[i] != typeformbuf[i]) { |
| 324 | retval = 1; |
| 325 | if (in.diagnosticscxx . . $ $anonymous_type_be9fbadca6c15a59_0#diagnostics.) { |
| 326 | if (!error_printed) { |
| 327 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Typeform failure:\n"); |
| 328 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Expected: "); |
| 329 | print_typeformcxx . . $ print_typeform(280060e335061cbc).(in.expected_typeformcxx . . $ $anonymous_type_be9fbadca6c15a59_0#expected_typeform., outlen); |
| 330 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Received: "); |
| 331 | print_typeformcxx . . $ print_typeform(280060e335061cbc).(typeformbuf, outlen); |
| 332 | error_printed = 1; |
| 333 | } |
| 334 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Expected %d, received %d in index %d\n", |
| 335 | in.expected_typeformcxx . . $ $anonymous_type_be9fbadca6c15a59_0#expected_typeform.[i], typeformbuf[i], i); |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | if (in.max_outlencxx . . $ $anonymous_type_be9fbadca6c15a59_0#max_outlen. < 0 && inlen != actualInlen) { |
| 341 | retval = 1; |
| 342 | if (in.diagnosticscxx . . $ $anonymous_type_be9fbadca6c15a59_0#diagnostics.) { |
| 343 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, |
| 344 | "Unexpected error happened: input length is not the same before " |
| 345 | "as " |
| 346 | "after the translation:\n"); |
| 347 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Before: %d After: %d \n", inlen, actualInlen); |
| 348 | } |
| 349 | } else if (actualInlen > inlen) { |
| 350 | retval = 1; |
| 351 | if (in.diagnosticscxx . . $ $anonymous_type_be9fbadca6c15a59_0#diagnostics.) { |
| 352 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, |
| 353 | "Unexpected error happened: returned input length (%d) exceeds " |
| 354 | "total input length (%d)\n", |
| 355 | actualInlen, inlen); |
| 356 | } |
| 357 | } else if (in.real_inlencxx . . $ $anonymous_type_be9fbadca6c15a59_0#real_inlen. >= 0 && in.real_inlencxx . . $ $anonymous_type_be9fbadca6c15a59_0#real_inlen. != actualInlen) { |
| 358 | retval = 1; |
| 359 | if (in.diagnosticscxx . . $ $anonymous_type_be9fbadca6c15a59_0#diagnostics.) { |
| 360 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Real input length failure:\n"); |
| 361 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Expected: %d, received: %d\n", in.real_inlencxx . . $ $anonymous_type_be9fbadca6c15a59_0#real_inlen., actualInlen); |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | fail: |
| 366 | freecxx . . $ free(5d22bdacc48458e8).(inbuf); |
| 367 | freecxx . . $ free(5d22bdacc48458e8).(outbuf); |
| 368 | freecxx . . $ free(5d22bdacc48458e8).(expectedbuf); |
| 369 | freecxx . . $ free(5d22bdacc48458e8).(typeformbuf); |
| 370 | freecxx . . $ free(5d22bdacc48458e8).(inputPos); |
| 371 | freecxx . . $ free(5d22bdacc48458e8).(outputPos); |
| 372 | |
| 373 | return retval; |
| 374 | } |
| 375 | |
| 376 | /* Helper function to convert a typeform string of '0's, '1's, '2's etc. |
| 377 | * to the required format, which is an array of 0s, 1s, 2s, etc. |
| 378 | * For example, "0000011111000" is converted to {0,0,0,0,0,1,1,1,1,1,0,0,0} |
| 379 | * The caller is responsible for freeing the returned array. */ |
| 380 | formtypecxx . . $ formtype# * |
| 381 | convert_typeformcxx . . $ convert_typeform(66b0c00b809d082f).(const char *typeform_string) { |
| 382 | int len = strlencxx . . $ strlen(751346f8406fd082).(typeform_string); |
| 383 | formtypecxx . . $ formtype# *typeform = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(len * sizeof(formtypecxx . . $ formtype#)); |
| 384 | int i; |
| 385 | for (i = 0; i < len; i++) typeform[i] = typeform_string[i] - '0'; |
| 386 | return typeform; |
| 387 | } |
| 388 | |
| 389 | void |
| 390 | update_typeformcxx . . $ update_typeform(7f194a4a3ee1ceb8).(const char *typeform_string, formtypecxx . . $ formtype# *typeform, const typeformscxx . . $ typeforms# kind) { |
| 391 | int len = strlencxx . . $ strlen(751346f8406fd082).(typeform_string); |
| 392 | int i; |
| 393 | for (i = 0; i < len; i++) |
| 394 | if (typeform_string[i] != ' ') typeform[i] |= kind; |
| 395 | } |
| 396 | |
| 397 | int |
| 398 | check_cursor_poscxx . . $ check_cursor_pos(b84d5d24b2c4fe0b).(const char *tableList, const char *str, const int *expected_pos) { |
| 399 | widecharcxx . . $ widechar# *inbuf; |
| 400 | widecharcxx . . $ widechar# *outbuf; |
| 401 | int *inpos, *outpos; |
| 402 | int inlen = strlencxx . . $ strlen(751346f8406fd082).(str); |
| 403 | int outlen = inlen; |
| 404 | int cursor_pos; |
| 405 | int i, retval = 0; |
| 406 | |
| 407 | inbuf = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(widecharcxx . . $ widechar#) * inlen); |
| 408 | outbuf = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(widecharcxx . . $ widechar#) * inlen); |
| 409 | inpos = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(int) * inlen); |
| 410 | outpos = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(int) * inlen); |
| 411 | inlen = _lou_extParseCharscxx . . $ _lou_extParseChars(c9bce2f4bcd31d4).(str, inbuf); |
| 412 | |
| 413 | for (i = 0; i < inlen; i++) { |
| 414 | cursor_pos = i; |
| 415 | if (!lou_translatecxx . . $ lou_translate(62dc23c046bfbb96).(tableList, inbuf, &inlen, outbuf, &outlen, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!, |
| 416 | NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!, &cursor_pos, compbrlAtCursorcxx . . $ compbrlAtCursor.)) { |
| 417 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Translation failed.\n"); |
| 418 | retval = 1; |
| 419 | goto fail; |
| 420 | } |
| 421 | if (expected_pos[i] != cursor_pos) { |
| 422 | if (!retval) // Print only once |
| 423 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Cursorpos failure:\n"); |
| 424 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, |
| 425 | "string='%s' cursor=%d ('%c') expected=%d received=%d ('%c')\n", str, |
| 426 | i, str[i], expected_pos[i], cursor_pos, (char)outbuf[cursor_pos]); |
| 427 | retval = 1; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | fail: |
| 432 | freecxx . . $ free(5d22bdacc48458e8).(inbuf); |
| 433 | freecxx . . $ free(5d22bdacc48458e8).(outbuf); |
| 434 | freecxx . . $ free(5d22bdacc48458e8).(inpos); |
| 435 | freecxx . . $ free(5d22bdacc48458e8).(outpos); |
| 436 | return retval; |
| 437 | } |
| 438 | |
| 439 | /** Check if a display table maps characters to the right dots. |
| 440 | * |
| 441 | * The dots are read as Unicode braille. Multiple input characters are |
| 442 | * allowed to map to the same dot pattern. Virtual dots in the actual |
| 443 | * output are discarded. |
| 444 | * |
| 445 | * @return 0 if the result is as expected and 1 otherwise. |
| 446 | */ |
| 447 | int |
| 448 | check_displaycxx . . $ check_display(a8ee6f950d471de8).(const char *displayTableList, const char *input, const char *expected) { |
| 449 | widecharcxx . . $ widechar# *inbuf = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 450 | widecharcxx . . $ widechar# *outbuf = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 451 | widecharcxx . . $ widechar# *expectedbuf = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 452 | int retval = 0; |
| 453 | int inlen = strlencxx . . $ strlen(751346f8406fd082).(input); |
| 454 | inbuf = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(widecharcxx . . $ widechar#) * inlen); |
| 455 | inlen = _lou_extParseCharscxx . . $ _lou_extParseChars(c9bce2f4bcd31d4).(input, inbuf); |
| 456 | if (!inlen) { |
| 457 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Cannot parse input string.\n"); |
| 458 | retval = 1; |
| 459 | goto fail; |
| 460 | } |
| 461 | int expectedlen = strlencxx . . $ strlen(751346f8406fd082).(expected); |
| 462 | expectedbuf = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(widecharcxx . . $ widechar#) * expectedlen); |
| 463 | expectedlen = _lou_extParseCharscxx . . $ _lou_extParseChars(c9bce2f4bcd31d4).(expected, expectedbuf); |
| 464 | if (!expectedlen) { |
| 465 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Cannot parse output string.\n"); |
| 466 | retval = 1; |
| 467 | goto fail; |
| 468 | } |
| 469 | if (inlen != expectedlen) { |
| 470 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Input and output string must be the same length.\n"); |
| 471 | retval = 1; |
| 472 | goto fail; |
| 473 | } |
| 474 | for (int i = 0; i < expectedlen; i++) { |
| 475 | if ((expectedbuf[i] & 0xff00) != LOU_ROW_BRAILLEcxx . . $ LOU_ROW_BRAILLE.) { |
| 476 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Output string must be Unicode braille.\n"); |
| 477 | retval = 1; |
| 478 | goto fail; |
| 479 | } |
| 480 | } |
| 481 | outbuf = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(widecharcxx . . $ widechar#) * inlen); |
| 482 | if (!lou_charToDotscxx . . $ lou_charToDots(df909fc833338dc8).(displayTableList, inbuf, outbuf, inlen, ucBrlcxx . . $ ucBrl.)) { |
| 483 | // This should only happen if the table can not be compiled. |
| 484 | // If the table does not have a display rule for a character |
| 485 | // in the input, it will result in a blank dot pattern in the |
| 486 | // output. |
| 487 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Mapping to dots failed.\n"); |
| 488 | retval = 1; |
| 489 | goto fail; |
| 490 | } |
| 491 | for (int i = 0; i < inlen; i++) { |
| 492 | if (outbuf[i] != expectedbuf[i]) { |
| 493 | retval = 1; |
| 494 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Input: '%s'\n", input); |
| 495 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Expected: '%s'\n", expected); |
| 496 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Received: '"); |
| 497 | print_widecharscxx . . $ print_widechars(9ead97ff5579f406).(outbuf, inlen); |
| 498 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "'\n"); |
| 499 | uint8_tcxx . . $ uint8_t# *expected_utf8; |
| 500 | uint8_tcxx . . $ uint8_t# *out_utf8; |
| 501 | size_tcxx . . $ size_t# expected_utf8_len; |
| 502 | size_tcxx . . $ size_t# out_utf8_len; |
| 503 | #ifdef WIDECHARS_ARE_UCS4 |
| 504 | expected_utf8 = u32_to_u8(&expectedbuf[i], 1, NULL, &expected_utf8_len); |
| 505 | out_utf8 = u32_to_u8(&outbuf[i], 1, NULL, &out_utf8_len); |
| 506 | #else |
| 507 | expected_utf8 = u16_to_u8cxx . . $ u16_to_u8(e729bd8f99eea2d2).(&expectedbuf[i], 1, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!, &expected_utf8_len); |
| 508 | out_utf8 = u16_to_u8cxx . . $ u16_to_u8(e729bd8f99eea2d2).(&outbuf[i], 1, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!, &out_utf8_len); |
| 509 | #endif |
| 510 | expectedbuf[i] = (expectedbuf[i] & 0x00ff) | LOU_DOTScxx . . $ LOU_DOTS.; |
| 511 | outbuf[i] = (outbuf[i] & 0x00ff) | LOU_DOTScxx . . $ LOU_DOTS.; |
| 512 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Diff: Expected '%.*s' (dots %s)", (int)expected_utf8_len, |
| 513 | expected_utf8, _lou_showDotscxx . . $ _lou_showDots(dfd108baace36870).(&expectedbuf[i], 1)); |
| 514 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, " but received '%.*s' (dots %s) in index %d\n", |
| 515 | (int)out_utf8_len, out_utf8, _lou_showDotscxx . . $ _lou_showDots(dfd108baace36870).(&outbuf[i], 1), i); |
| 516 | freecxx . . $ free(5d22bdacc48458e8).(expected_utf8); |
| 517 | freecxx . . $ free(5d22bdacc48458e8).(out_utf8); |
| 518 | break; |
| 519 | } |
| 520 | } |
| 521 | fail: |
| 522 | freecxx . . $ free(5d22bdacc48458e8).(inbuf); |
| 523 | freecxx . . $ free(5d22bdacc48458e8).(outbuf); |
| 524 | freecxx . . $ free(5d22bdacc48458e8).(expectedbuf); |
| 525 | return retval; |
| 526 | } |
| 527 | |
| 528 | /* Check if a string is hyphenated as expected, by passing the |
| 529 | * expected hyphenation position array. |
| 530 | * |
| 531 | * @return 0 if the hyphenation is as expected and 1 otherwise. |
| 532 | */ |
| 533 | int |
| 534 | check_hyphenation_poscxx . . $ check_hyphenation_pos(a8ee6f950d471de8).(const char *tableList, const char *str, const char *expected) { |
| 535 | widecharcxx . . $ widechar# *inbuf; |
| 536 | char *hyphens = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 537 | int inlen = strlencxx . . $ strlen(751346f8406fd082).(str); |
| 538 | int retval = 0; |
| 539 | |
| 540 | inbuf = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(widecharcxx . . $ widechar#) * inlen); |
| 541 | inlen = _lou_extParseCharscxx . . $ _lou_extParseChars(c9bce2f4bcd31d4).(str, inbuf); |
| 542 | if (!inlen) { |
| 543 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Cannot parse input string.\n"); |
| 544 | retval = 1; |
| 545 | goto fail; |
| 546 | } |
| 547 | hyphens = calloccxx . . $ calloc(63a7bf2941bfcd7a).(inlen + 1, sizeof(char)); |
| 548 | |
| 549 | if (!lou_hyphenatecxx . . $ lou_hyphenate(c64cec7022e3b116).(tableList, inbuf, inlen, hyphens, 0)) { |
| 550 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Hyphenation failed.\n"); |
| 551 | retval = 1; |
| 552 | goto fail; |
| 553 | } |
| 554 | |
| 555 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(expected, hyphens)) { |
| 556 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Input: '%s'\n", str); |
| 557 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Expected: '%s'\n", expected); |
| 558 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Received: '%s'\n", hyphens); |
| 559 | retval = 1; |
| 560 | } |
| 561 | |
| 562 | fail: |
| 563 | freecxx . . $ free(5d22bdacc48458e8).(inbuf); |
| 564 | freecxx . . $ free(5d22bdacc48458e8).(hyphens); |
| 565 | return retval; |
| 566 | } |
| 567 | |
| 568 | /** Check if a string is hyphenated as expected. |
| 569 | * |
| 570 | * mode is '0' when input is text and '1' when input is braille |
| 571 | * |
| 572 | * @return 0 if the hyphenation is as expected and 1 otherwise. |
| 573 | */ |
| 574 | int |
| 575 | check_hyphenationcxx . . $ check_hyphenation(f37f69d9dd87ffca).( |
| 576 | const char *tableList, const char *str, const char *expected, int mode) { |
| 577 | widecharcxx . . $ widechar# *inbuf; |
| 578 | widecharcxx . . $ widechar# *hyphenatedbuf = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 579 | uint8_tcxx . . $ uint8_t# *hyphenated = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 580 | char *hyphens = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 581 | int inlen = strlencxx . . $ strlen(751346f8406fd082).(str); |
| 582 | size_tcxx . . $ size_t# hyphenatedlen = inlen * 2; |
| 583 | int retval = 0; |
| 584 | |
| 585 | inbuf = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(widecharcxx . . $ widechar#) * inlen); |
| 586 | inlen = _lou_extParseCharscxx . . $ _lou_extParseChars(c9bce2f4bcd31d4).(str, inbuf); |
| 587 | if (!inlen) { |
| 588 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Cannot parse input string.\n"); |
| 589 | retval = 1; |
| 590 | goto fail; |
| 591 | } |
| 592 | hyphens = calloccxx . . $ calloc(63a7bf2941bfcd7a).(inlen + 1, sizeof(char)); |
| 593 | |
| 594 | if (!lou_hyphenatecxx . . $ lou_hyphenate(c64cec7022e3b116).(tableList, inbuf, inlen, hyphens, mode)) { |
| 595 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Hyphenation failed.\n"); |
| 596 | retval = 1; |
| 597 | goto fail; |
| 598 | } |
| 599 | if (hyphens[0] != '0') { |
| 600 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Unexpected output from lou_hyphenate.\n"); |
| 601 | retval = 1; |
| 602 | goto fail; |
| 603 | } |
| 604 | |
| 605 | hyphenatedbuf = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(widecharcxx . . $ widechar#) * hyphenatedlen); |
| 606 | int i = 0; |
| 607 | int j = 0; |
| 608 | hyphenatedbuf[i++] = inbuf[j++]; |
| 609 | for (; j < inlen; j++) { |
| 610 | if (hyphens[j] == '2') |
| 611 | hyphenatedbuf[i++] = (widecharcxx . . $ widechar#)'|'; |
| 612 | else if (hyphens[j] != '0') |
| 613 | hyphenatedbuf[i++] = (widecharcxx . . $ widechar#)'-'; |
| 614 | hyphenatedbuf[i++] = inbuf[j]; |
| 615 | } |
| 616 | |
| 617 | #ifdef WIDECHARS_ARE_UCS4 |
| 618 | hyphenated = u32_to_u8(hyphenatedbuf, i, NULL, &hyphenatedlen); |
| 619 | #else |
| 620 | hyphenated = u16_to_u8cxx . . $ u16_to_u8(e729bd8f99eea2d2).(hyphenatedbuf, i, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!, &hyphenatedlen); |
| 621 | #endif |
| 622 | |
| 623 | if (!hyphenated) { |
| 624 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Unexpected error during UTF-8 encoding\n"); |
| 625 | freecxx . . $ free(5d22bdacc48458e8).(hyphenatedbuf); |
| 626 | retval = 2; |
| 627 | goto fail; |
| 628 | } |
| 629 | |
| 630 | if (strlencxx . . $ strlen(751346f8406fd082).(expected) != hyphenatedlen || |
| 631 | strncmpcxx . . $ strncmp(fd278af2f295fa2e).(expected, (const char *)hyphenated, hyphenatedlen)) { |
| 632 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Input: '%s'\n", str); |
| 633 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Expected: '%s'\n", expected); |
| 634 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Received: '%.*s'\n", (int)hyphenatedlen, hyphenated); |
| 635 | retval = 1; |
| 636 | } |
| 637 | |
| 638 | freecxx . . $ free(5d22bdacc48458e8).(hyphenatedbuf); |
| 639 | freecxx . . $ free(5d22bdacc48458e8).(hyphenated); |
| 640 | |
| 641 | fail: |
| 642 | freecxx . . $ free(5d22bdacc48458e8).(inbuf); |
| 643 | freecxx . . $ free(5d22bdacc48458e8).(hyphens); |
| 644 | return retval; |
| 645 | } |