sanskrit-iast/main.c

43 lines
782 B
C
Raw Normal View History

2018-04-25 14:29:11 +02:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
2018-04-25 14:29:11 +02:00
#include "transliteration.h"
#include "iast.h"
2018-04-25 14:29:11 +02:00
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;
2018-04-25 14:29:11 +02:00
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;
}
2018-04-25 14:29:11 +02:00
text[length] = '\0';
2018-04-25 14:29:11 +02:00
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;
2018-04-25 14:29:11 +02:00
}