From 93179a934ceb61523f39f717195f8963abb34100 Mon Sep 17 00:00:00 2001 From: Vlasta Vesely Date: Fri, 27 Apr 2018 11:59:32 +0200 Subject: [PATCH] main: implemented transliteration of stdin data --- main.c | 32 +++++++++++++++++++++++++++++++- transliteration.c | 5 +++++ transliteration.h | 2 ++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 5983ba3..25eb84c 100644 --- a/main.c +++ b/main.c @@ -1,12 +1,42 @@ #include #include #include +#include +#include +#include "transliteration.h" +#include "iast.h" int main(int argc, const char **argv) { + struct transliteration_context *context; + unsigned int n, length = 0; + int retval = 0; + char buffer[6]; + char *text = malloc(0); + char *out; + while ((n = read(STDIN_FILENO, buffer, sizeof(buffer))) > 0) { + text = realloc(text, length + n + 1); + strncpy(text + length, buffer, n); + length += n; + } + if (n == -1) { + retval = -errno; + goto out; + } + text[length] = '\0'; - return 0; + context = transliteration_context_iast_alloc(); + + out = transliterate_devanagari_to_latin(text, context); + printf("%s\n", out); + + transliteration_context_drop(context); + free(text); + free(out); + +out: + return retval; } diff --git a/transliteration.c b/transliteration.c index 74c5faa..22acb15 100644 --- a/transliteration.c +++ b/transliteration.c @@ -79,3 +79,8 @@ char *transliterate_devanagari_to_latin(const char *text, return syllable_chain_to_string(head); } + +void transliteration_context_drop(struct transliteration_context *context) +{ + free(context); +} diff --git a/transliteration.h b/transliteration.h index 940a4b4..71471b1 100644 --- a/transliteration.h +++ b/transliteration.h @@ -25,4 +25,6 @@ struct transliteration_context { char *transliterate_devanagari_to_latin(const char *text, struct transliteration_context *context); +void transliteration_context_drop(struct transliteration_context *context); + #endif /* __TRANSLITERATION_H */