main: add '-c' option
This commit is contained in:
parent
7170066e69
commit
9571ee9871
2 changed files with 38 additions and 3 deletions
28
main.c
28
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';
|
||||
|
||||
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);
|
||||
|
|
11
test.sh
11
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
|
||||
|
|
Loading…
Reference in a new issue