From 9571ee9871717cfb085a7120861d5a0ce775d8b7 Mon Sep 17 00:00:00 2001 From: Vlasta Vesely Date: Sat, 28 Apr 2018 14:03:30 +0200 Subject: [PATCH] main: add '-c' option --- main.c | 30 ++++++++++++++++++++++++++++-- test.sh | 11 ++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 25eb84c..98d0148 100644 --- a/main.c +++ b/main.c @@ -6,15 +6,37 @@ #include "transliteration.h" #include "iast.h" +#include "iast-czech.h" + +#define FLAG_CZECH 1 << 0 int main(int argc, const char **argv) { struct transliteration_context *context; unsigned int n, length = 0; - int retval = 0; + int i, retval = 0; char buffer[6]; char *text = malloc(0); char *out; + const char *arg; + unsigned int flags = 0; + + + for (i = 0; i < argc; i++) { + arg = argv[i]; + + if (*arg == '-') { + switch (arg[1]) { + case 'c': + flags |= FLAG_CZECH; + continue; + } + + fprintf(stderr, "error: unknown option '%s'\n", arg); + exit(1); + } + } + while ((n = read(STDIN_FILENO, buffer, sizeof(buffer))) > 0) { text = realloc(text, length + n + 1); @@ -28,7 +50,11 @@ int main(int argc, const char **argv) text[length] = '\0'; - context = transliteration_context_iast_alloc(); + if (flags & FLAG_CZECH) { + context = transliteration_context_iast_czech_alloc(); + } else { + context = transliteration_context_iast_alloc(); + } out = transliterate_devanagari_to_latin(text, context); printf("%s\n", out); diff --git a/test.sh b/test.sh index f03cc68..80ce809 100644 --- a/test.sh +++ b/test.sh @@ -3,7 +3,7 @@ set -e test_word() { - transliterated=$(echo -n "$1" | ./main) + transliterated=$(echo -n "$1" | ./main $3) expected="$2" if test "x$transliterated" = "x$expected" @@ -14,6 +14,7 @@ test_word() fi } +echo "Transliteration to IAST" test_word "संस्कृतम्" "saṃskṛtam" test_word "आर्यावर्त" "āryāvarta" test_word "तन्त्रशास्त्रम्" "tantraśāstram" @@ -25,3 +26,11 @@ test_word "देवनागरी" "devanāgarī" test_word "योगः" "yogaḥ" test_word "भगवद्गीता" "bhagavadgītā" test_word "सम्भोग" "sambhoga" + +echo +echo "Transliteration to czech" +test_word "तन्त्रशास्त्रम्" "tantrašástra" -c +test_word "सांख्य" "sánkhja" -c +test_word "महाभारतम्" "mahábhárata" -c +test_word "योगः" "jóga" -c +test_word "भगवद्गीता" "bhagavadgíta" -c