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

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

View file

@ -3,15 +3,12 @@ set -e
test_word()
{
transliterated=$(echo -n "$1" | ./iast $3 --)
output=$(echo -n "$1" | ./iast $3 --)
expected="$2"
if test "x$transliterated" = "x$expected"
then
echo "\033[32m$transliterated\033[0m = \033[32m$expected\033[0m"
else
echo "\033[31m$transliterated\033[0m != \033[31m$expected\033[0m"
fi
test "x$output" = "x$expected" &&
echo "\033[32m$output\033[0m = \033[32m$expected\033[0m" ||
echo "\033[31m$output\033[0m != \033[31m$expected\033[0m"
}
echo "Transliteration to IAST"
@ -34,3 +31,10 @@ test_word "सांख्य" "sánkhja" -c
test_word "महाभारतम्" "mahábhárata" -c
test_word "योगः" "jóga" -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