sanskrit-iast/iast.c

186 lines
4.4 KiB
C
Raw Normal View History

2018-04-25 19:30:49 +02:00
/* SPDX-License-Identifier: GPL-2.0 */
2018-04-25 18:11:56 +02:00
#include <stdlib.h>
2018-04-25 18:54:47 +02:00
#include <string.h>
2018-04-25 18:11:56 +02:00
#include "iast.h"
2018-04-25 19:14:57 +02:00
static inline void transliteration_modifier_apply(struct syllable *syllable,
const char *modified)
2018-04-25 18:54:47 +02:00
{
2018-04-25 19:14:57 +02:00
char buffer[10];
strcpy(buffer, syllable->data);
buffer[strlen(buffer) - 1] = 0;
strcat(buffer, modified);
2018-04-25 18:54:47 +02:00
free(syllable->data);
2018-04-25 19:14:57 +02:00
syllable->data = strdup(buffer);
}
static void transliteration_modifier_aa(struct syllable *syllable)
{
transliteration_modifier_apply(syllable, "ā");
}
static void transliteration_modifier_i(struct syllable *syllable)
{
transliteration_modifier_apply(syllable, "i");
}
static void transliteration_modifier_ii(struct syllable *syllable)
{
transliteration_modifier_apply(syllable, "ī");
}
static void transliteration_modifier_u(struct syllable *syllable)
{
transliteration_modifier_apply(syllable, "u");
}
static void transliteration_modifier_uu(struct syllable *syllable)
{
transliteration_modifier_apply(syllable, "ū");
}
static void transliteration_modifier_r(struct syllable *syllable)
{
transliteration_modifier_apply(syllable, "");
}
static void transliteration_modifier_rr(struct syllable *syllable)
{
transliteration_modifier_apply(syllable, "");
2018-04-25 18:54:47 +02:00
}
2018-04-26 13:01:50 +02:00
static void transliteration_modifier_l(struct syllable *syllable)
{
transliteration_modifier_apply(syllable, "");
}
static void transliteration_modifier_ll(struct syllable *syllable)
{
transliteration_modifier_apply(syllable, "");
}
2018-04-25 19:14:57 +02:00
static void transliteration_modifier_e(struct syllable *syllable)
{
transliteration_modifier_apply(syllable, "e");
}
2018-04-25 19:25:46 +02:00
static void transliteration_modifier_o(struct syllable *syllable)
{
transliteration_modifier_apply(syllable, "o");
}
2018-04-26 13:01:50 +02:00
static void transliteration_modifier_ai(struct syllable *syllable)
{
transliteration_modifier_apply(syllable, "ai");
}
2018-04-25 19:14:57 +02:00
static void transliteration_modifier_virama(struct syllable *syllable)
{
transliteration_modifier_apply(syllable, "");
}
2018-04-25 18:11:56 +02:00
static const struct transliteration_letter table_letters[] = {
/* Vowels */
{0x0905, "a"}, /* अ */
{0x0906, "ā"}, /* आ */
2018-04-25 18:35:28 +02:00
{0x0907, "i"}, /* इ */
{0x0908, "ī"}, /* ई */
{0x0909, "u"}, /* उ */
{0x090a, "ū"}, /* ऊ */
{0x090b, ""}, /* ऋ */
{0x0960, ""}, /* ॠ */
{0x090c, ""}, /* ऌ */
{0x0961, ""}, /* ॡ */
{0x090f, "e"}, /* ए */
{0x0910, "ai"}, /* ऐ */
{0x0913, "o"}, /* ओ */
{0x0914, "au"}, /* औ */
/* Consonants */
{0x0915, "ka"}, /* क */
{0x0916, "kha"}, /* ख */
{0x0917, "ga"}, /* ग */
{0x0918, "gha"}, /* घ */
{0x0919, "ṅa"}, /* ङ */
{0x0939, "ha"}, /* ह */
{0x091a, "ca"}, /* च */
{0x091b, "cha"}, /* छ */
{0x091c, "ja"}, /* ज */
{0x091d, "jha"}, /* झ */
{0x091e, "ña"}, /* ञ */
{0x092f, "ya"}, /* य */
{0x0936, "śa"}, /* श */
{0x091F, "ṭa"}, /* ट */
{0x0920, "ṭha"}, /* ठ */
{0x0921, "ḍa"}, /* ड */
{0x0922, "ḍha"}, /* ढ */
{0x0923, "ṇa"}, /* ण */
{0x0930, "ra"}, /* र */
{0x0937, "ṣa"}, /* श */
{0x0924, "ta"}, /* त */
{0x0925, "tha"}, /* थ */
{0x0926, "da"}, /* द */
{0x0927, "dha"}, /* ध */
{0x0928, "na"}, /* न */
{0x0932, "la"}, /* ल */
{0x0938, "sa"}, /* स */
{0x092a, "pa"}, /* प */
{0x092b, "pha"}, /* फ */
{0x092c, "ba"}, /* ब */
{0x092d, "bha"}, /* भ */
{0x092e, "ma"}, /* म */
{0x0935, "va"}, /* व */
/* Codas */
{0x0902, ""}, /* ं (anusvara) */
{0x0903, ""}, /* (visarga) */
{0x093d, "'"}, /* ऽ (avagrada) */
2018-04-25 18:11:56 +02:00
2018-04-27 13:21:36 +02:00
/* Numbers */
{0x0966, "0"},
{0x0967, "1"},
{0x0968, "2"},
{0x0969, "3"},
{0x096a, "4"},
{0x096b, "5"},
{0x096c, "6"},
{0x096d, "7"},
{0x096e, "8"},
{0x096f, "9"},
2018-04-25 18:11:56 +02:00
{0, NULL}
};
2018-04-25 18:54:47 +02:00
static const struct transliteration_modifier table_modifiers[] = {
2018-04-25 19:14:57 +02:00
{0x093e, transliteration_modifier_aa},
{0x093f, transliteration_modifier_i},
{0x0940, transliteration_modifier_ii},
{0x0941, transliteration_modifier_u},
{0x0942, transliteration_modifier_uu},
{0x0943, transliteration_modifier_r},
{0x0944, transliteration_modifier_rr},
2018-04-26 13:01:50 +02:00
{0x0962, transliteration_modifier_l},
{0x0963, transliteration_modifier_ll},
2018-04-25 19:14:57 +02:00
{0x0947, transliteration_modifier_e},
2018-04-25 19:25:46 +02:00
{0x094b, transliteration_modifier_o},
2018-04-26 13:01:50 +02:00
{0x0948, transliteration_modifier_ai},
2018-04-25 19:14:57 +02:00
{0x094d, transliteration_modifier_virama},
2018-04-25 18:54:47 +02:00
{0, NULL}
};
2018-04-25 18:11:56 +02:00
struct transliteration_context *transliteration_context_iast_alloc()
{
struct transliteration_context *context;
context = malloc(sizeof(*context));
context->table_letters = table_letters;
2018-04-25 18:54:47 +02:00
context->table_modifiers = table_modifiers;
2018-04-25 18:11:56 +02:00
return context;
}