main: update handling -e and -c
This commit is contained in:
parent
9c3db8ebb8
commit
1a9a55ee41
2 changed files with 36 additions and 22 deletions
4
compat.h
4
compat.h
|
@ -1,7 +1,11 @@
|
||||||
#ifndef __COMPAT_H
|
#ifndef __COMPAT_H
|
||||||
#define __COMPAT_H
|
#define __COMPAT_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#endif /* __COMPAT_H */
|
#endif /* __COMPAT_H */
|
||||||
|
|
54
main.c
54
main.c
|
@ -1,19 +1,15 @@
|
||||||
#include <stdio.h>
|
#include "compat.h"
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include "transliteration.h"
|
#include "transliteration.h"
|
||||||
|
#include "transcription.h"
|
||||||
#include "encoder.h"
|
#include "encoder.h"
|
||||||
|
|
||||||
#define PROGNAME "iast"
|
#define PROGNAME "iast"
|
||||||
#define VERSION "0.1"
|
#define VERSION "1.0"
|
||||||
|
|
||||||
#define FLAG_STDIN 1 << 0
|
#define FLAG_STDIN 1 << 0
|
||||||
#define FLAG_CZECH 1 << 1
|
#define FLAG_REVERSE 1 << 1
|
||||||
#define FLAG_ENCODE 1 << 2
|
#define FLAG_ENCODE 1 << 2
|
||||||
|
#define FLAG_CZECH 1 << 3
|
||||||
|
|
||||||
|
|
||||||
static const char *usage_str =
|
static const char *usage_str =
|
||||||
|
@ -25,8 +21,9 @@ static const char *usage_str =
|
||||||
"options:\n"
|
"options:\n"
|
||||||
" -h shows this help and exits\n"
|
" -h shows this help and exits\n"
|
||||||
" -v shows version number and exits\n"
|
" -v shows version number and exits\n"
|
||||||
" -c transliterate to Czech language\n"
|
" -r reverse transliteration (from Latin to Devanagari)\n"
|
||||||
" -e convert symbolic ASCII text to IAST representation\n"
|
" -e convert symbolic ASCII text to IAST representation\n"
|
||||||
|
" -c transcript Devanagari to Czech language\n"
|
||||||
" -- read data from the standard input\n"
|
" -- read data from the standard input\n"
|
||||||
"\n"
|
"\n"
|
||||||
" By default, `" PROGNAME "` takes all input arguments written in Devanagari\n"
|
" By default, `" PROGNAME "` takes all input arguments written in Devanagari\n"
|
||||||
|
@ -79,6 +76,19 @@ static char *stdin_read()
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *process_input(const char *input, unsigned int flags)
|
||||||
|
{
|
||||||
|
if (flags & FLAG_ENCODE) {
|
||||||
|
return encode_iast_punctation(input);
|
||||||
|
} else if (flags & FLAG_REVERSE) {
|
||||||
|
return transliterate_latin_to_devanagari(input);
|
||||||
|
} else if (flags & FLAG_CZECH) {
|
||||||
|
return transcript_devanagari_to_czech(input);
|
||||||
|
} else {
|
||||||
|
return transliterate_devanagari_to_latin(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, const char **argv)
|
int main(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -87,6 +97,11 @@ int main(int argc, const char **argv)
|
||||||
const char *queue[argc];
|
const char *queue[argc];
|
||||||
char *input, *output;
|
char *input, *output;
|
||||||
|
|
||||||
|
if (argc == 1) {
|
||||||
|
print_usage();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
arg = argv[i];
|
arg = argv[i];
|
||||||
|
|
||||||
|
@ -95,12 +110,15 @@ int main(int argc, const char **argv)
|
||||||
case '-':
|
case '-':
|
||||||
flags |= FLAG_STDIN;
|
flags |= FLAG_STDIN;
|
||||||
continue;
|
continue;
|
||||||
case 'c':
|
case 'r':
|
||||||
flags |= FLAG_CZECH;
|
flags |= FLAG_REVERSE;
|
||||||
continue;
|
continue;
|
||||||
case 'e':
|
case 'e':
|
||||||
flags |= FLAG_ENCODE;
|
flags |= FLAG_ENCODE;
|
||||||
continue;
|
continue;
|
||||||
|
case 'c':
|
||||||
|
flags |= FLAG_CZECH;
|
||||||
|
continue;
|
||||||
case 'h':
|
case 'h':
|
||||||
print_usage();
|
print_usage();
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -123,11 +141,7 @@ int main(int argc, const char **argv)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & FLAG_ENCODE) {
|
output = process_input(input, flags);
|
||||||
output = encode_iast_punctation(input);
|
|
||||||
} else {
|
|
||||||
output = transliterate_devanagari_to_latin(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(stdout, "%s\n", output);
|
fprintf(stdout, "%s\n", output);
|
||||||
free(output);
|
free(output);
|
||||||
|
@ -135,11 +149,7 @@ int main(int argc, const char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
if (flags & FLAG_ENCODE) {
|
output = process_input(queue[i], flags);
|
||||||
output = encode_iast_punctation(queue[i]);
|
|
||||||
} else {
|
|
||||||
output = transliterate_devanagari_to_latin(queue[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(stdout, "%s\n", output);
|
fprintf(stdout, "%s\n", output);
|
||||||
free(output);
|
free(output);
|
||||||
|
|
Loading…
Add table
Reference in a new issue