* Makefile.am (SUBDIRS): Add LANGDATA.
[m17n/m17n-db.git] / LANGUAGE.awk
1 # LANGUAGE.awk -- awk script to generate LANGUAGE.tbl
2 # Copyright (C) 2007
3 #   National Institute of Advanced Industrial Science and Technology (AIST)
4 #   Registration Number H15PRO112
5
6 # This file is part of the m17n database; a sub-part of the m17n
7 # library.
8
9 # The m17n library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1 of
12 # the License, or (at your option) any later version.
13
14 # The m17n library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # Lesser General Public License for more details.
18
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with the m17n library; if not, write to the Free
21 # Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 # Boston, MA 02110-1301, USA.
23
24 BEGIN {
25     print ";; LANGUAGE.tbl -- ISO639 Language Code              -*- mode:lisp; coding:utf-8; -*-";
26     print ";; Copyright (C) 2007";
27     print ";;   National Institute of Advanced Industrial Science and Technology (AIST)";
28     print ";;   Registration Number H15PRO112";
29     print "";
30     print ";; This file is part of the m17n database; a sub-part of the m17n";
31     print ";; library.";
32     print "";
33     print ";; The m17n library is free software; you can redistribute it and/or";
34     print ";; modify it under the terms of the GNU Lesser General Public License";
35     print ";; as published by the Free Software Foundation; either version 2.1 of";
36     print ";; the License, or (at your option) any later version.";
37     print "";
38     print ";; The m17n library is distributed in the hope that it will be useful,";
39     print ";; but WITHOUT ANY WARRANTY; without even the implied warranty of";
40     print ";; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU";
41     print ";; Lesser General Public License for more details.";
42     print "";
43     print ";; You should have received a copy of the GNU Lesser General Public";
44     print ";; License along with the m17n library; if not, write to the Free";
45     print ";; Software Foundation, Inc., 51 Franklin Street, Fifth Floor,";
46     print ";; Boston, MA 02110-1301, USA.";
47     print ";;";
48     print ";; The file format is this:";
49     print ";;    (ISO639-2 ISO639-1 \"ENGLISH-NAME\" [ \"NATIVE-NAME\" [ \"EXTRA-CHARS\" ]]) ...";
50     print ";; ISO639-2: 3-letter language code of ISO639-2.";
51     print ";; ISO639-1: 2-letter language code of ISO639-1, or nil if it doesn't exist.";
52     print ";; ENGLISH-NAME: English name of the language.  The first name listed";
53     print ";;   in ISO639-2 with the following modifications:";
54     print ";;   'Greek, Modern (1453-)' is changed to 'Greek'";
55     print ";;   Tailing ' (Other)' is deleted.";
56     print ";;   Tailing ' languages' is deleted.";
57     print ";;   Tailing part specifying the date (e.g. ' (ca.450-1100)') is deleted.";
58     print ";;   Reorder, for instance, 'English, Old' to 'Old English'.";
59     while (getline < "LANGDATA/native.txt") {
60         if ($0 ~ /^[a-z]/) {
61             NATIVE[$1] = $2;
62             if ($3 != "")
63                 CHARS[$1] = $3;
64         } else if ($0 ~ /^;;/) {
65             print;
66         }
67     }
68 }
69
70 /^[a-z][a-z][a-z]\|/ {
71     native = NATIVE[$1];
72     chars = CHARS[$1];
73     two_letter = $3;
74     if (two_letter == "" || two_letter == "NULL")
75         two_letter = "nil";
76     name = $4;
77     if (name == "Greek, Modern (1453-)")
78         name = "Greek";
79     else {
80         gsub("; .*", "", name);
81         gsub(" \\(Other\\)$", "", name);
82         gsub(" languages$", "", name);
83         if (name ~ /\(.*[0-9].*\)$/)
84             gsub(" \\([^)]*\\)$", "", name);
85         if (name ~ ", ") {
86             split(name,array,", ");
87             name = array[2] " " array[1];
88         }
89     }
90     printf "(%s %-3s \"%s\"", $1, two_letter, name;
91     if (native != "")
92         printf " \"%s\"", native;
93     else if (chars != "")
94         printf " nil";
95     if (chars != "")
96         printf " \"%s\"", chars;
97     printf ")\n";
98 }