fix: allow encoding of data read from stdin

This commit is contained in:
Vlasta Vesely 2019-03-20 12:09:05 +01:00
parent 5d7fb6f8b4
commit 939c58db18
No known key found for this signature in database
GPG key ID: EB0E649DC0DFCC22
2 changed files with 23 additions and 18 deletions

19
main.c
View file

@ -119,15 +119,6 @@ int main(int argc, const char **argv)
} }
} }
if (flags & FLAG_ENCODE) {
for (i = 0; i < n; i++) {
output = encode_iast_punctation(queue[i]);
fprintf(stdout, "%s\n", output);
free(output);
}
return 0;
}
context = (flags & FLAG_CZECH) context = (flags & FLAG_CZECH)
? get_iast_czech_transliteration_context() ? get_iast_czech_transliteration_context()
: get_iast_transliteration_context(); : get_iast_transliteration_context();
@ -139,14 +130,24 @@ int main(int argc, const char **argv)
return -1; return -1;
} }
if (flags & FLAG_ENCODE) {
output = encode_iast_punctation(input);
} else {
output = transliterate_devanagari_to_latin(input, context); output = transliterate_devanagari_to_latin(input, context);
}
fprintf(stdout, "%s\n", output); fprintf(stdout, "%s\n", output);
free(output); free(output);
free(input); free(input);
} }
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if (flags & FLAG_ENCODE) {
output = encode_iast_punctation(queue[i]);
} else {
output = transliterate_devanagari_to_latin(queue[i], context); output = transliterate_devanagari_to_latin(queue[i], context);
}
fprintf(stdout, "%s\n", output); fprintf(stdout, "%s\n", output);
free(output); free(output);
} }

View file

@ -3,15 +3,12 @@ set -e
test_word() test_word()
{ {
transliterated=$(echo -n "$1" | ./iast $3 --) output=$(echo -n "$1" | ./iast $3 --)
expected="$2" expected="$2"
if test "x$transliterated" = "x$expected" test "x$output" = "x$expected" &&
then echo "\033[32m$output\033[0m = \033[32m$expected\033[0m" ||
echo "\033[32m$transliterated\033[0m = \033[32m$expected\033[0m" echo "\033[31m$output\033[0m != \033[31m$expected\033[0m"
else
echo "\033[31m$transliterated\033[0m != \033[31m$expected\033[0m"
fi
} }
echo "Transliteration to IAST" echo "Transliteration to IAST"
@ -34,3 +31,10 @@ test_word "सांख्य" "sánkhja" -c
test_word "महाभारतम्" "mahábhárata" -c test_word "महाभारतम्" "mahábhárata" -c
test_word "योगः" "jóga" -c test_word "योगः" "jóga" -c
test_word "भगवद्गीता" "bhagavadgíta" -c test_word "भगवद्गीता" "bhagavadgíta" -c
echo
echo "Encoding"
test_word "sam.skr.tam" "saṃskṛtam" -e
test_word "yogah." "yogaḥ" -e
test_word "tantras,a-stram" "tantraśāstram" -e
test_word "tantrašástram" "tantraśāstram" -e