From 5685e839336a701a6d44356ec2792b06efa2352a Mon Sep 17 00:00:00 2001 From: Vlasta Vesely Date: Tue, 21 Dec 2021 13:45:46 +0100 Subject: [PATCH] =?UTF-8?q?add=20the=20=E2=80=98-d=E2=80=99=20option?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iast.1 | 8 ++++++++ main.c | 24 +++++++++++++++++++++--- tests/integration.c | 3 +++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/iast.1 b/iast.1 index 884f8c3..0c0ad0c 100644 --- a/iast.1 +++ b/iast.1 @@ -91,6 +91,14 @@ encoding rather than characters. .RE +.BR \-d , +.B \-\-devanagari +.RS 4 +When encoding, output Devanagari rather than +.I IAST +characters. +.RE + .BR \-h , .B \-\-help .RS 4 diff --git a/main.c b/main.c index caea188..f33781f 100644 --- a/main.c +++ b/main.c @@ -8,6 +8,7 @@ #define FLAG_VELTHUIS 1 << 1 #define FLAG_CZECH 1 << 2 #define FLAG_ASCII 1 << 3 +#define FLAG_DEVANAGARI 1 << 4 static const char *usage_str = PROGNAME ", a helper for Sanskrit transliteration.\n" @@ -19,6 +20,8 @@ static const char *usage_str = " -f, --file the input file for transliteration\n" " -r, --reverse reverse transliteration (from Latin to Devanagari)\n" " -e, --encode convert an ASCII text to IAST using the Velthuis scheme\n" + " -a, --ascii convert a Devanagari text to Velthuis text rather than to IAST\n" + " -d, --devanagari when encoding, output a Devanagari text rather than IAST\n" " -c, --czech transcript Devanagari to Czech language (experimental)\n" " -h, --help show this help and exit\n" " -v, --version show version number and exit\n" @@ -35,7 +38,7 @@ static const char *usage_str = "\n" " For more information see the iast(1) manual page.\n"; -static const char *short_opts = "f:reachv"; +static const char *short_opts = "f:readchv"; static const struct option long_opts[] = { {"file", required_argument, 0, 'f'}, @@ -43,6 +46,7 @@ static const struct option long_opts[] = { {"encode", no_argument, 0, 'e'}, {"velthuis", no_argument, 0, 'e'}, {"ascii", no_argument, 0, 'a'}, + {"devanagari", no_argument, 0, 'd'}, {"czech", no_argument, 0, 'c'}, {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'v'}, @@ -83,8 +87,19 @@ static int process_input(const char *input, char **out, unsigned int flags) } } - if (flags & FLAG_VELTHUIS) - return encode_velthuis_to_iast(input, out); + if (flags & FLAG_VELTHUIS) { + if (flags & FLAG_DEVANAGARI) { + ret = encode_velthuis_to_iast(input, &tmp); + if (ret != 0) + return ret; + + ret = transliterate_latin_to_devanagari(tmp, out); + free(tmp); + return ret; + } else { + return encode_velthuis_to_iast(input, out); + } + } if (flags & FLAG_CZECH) return transcript_devanagari_to_czech(input, out); @@ -204,6 +219,9 @@ int main(int argc, const char **argv) case 'a': flags |= FLAG_ASCII; break; + case 'd': + flags |= FLAG_DEVANAGARI; + break; case 'c': flags |= FLAG_CZECH; break; diff --git a/tests/integration.c b/tests/integration.c index 1572ccd..24ef97b 100644 --- a/tests/integration.c +++ b/tests/integration.c @@ -103,6 +103,9 @@ START_TEST(test_velthuis) /* reverse */ test_output("./iast \"ṛtaṃ ca satyam\" -er", ".rta.m ca satyam\n"); + + /* force Devanagari output */ + test_output("./iast \"agnii.h\" -ed", "अग्नीः\n"); } END_TEST