main: implemented transliteration of stdin data
This commit is contained in:
parent
ba394e634c
commit
93179a934c
3 changed files with 38 additions and 1 deletions
32
main.c
32
main.c
|
@ -1,12 +1,42 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in a new issue