/[emacs]/emacs/lisp/language/indian.el
ViewVC logotype

Diff of /emacs/lisp/language/indian.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.14 by pj, Mon Jul 16 12:22:59 2001 UTC revision 1.15 by rms, Sun Nov 25 02:39:24 2001 UTC
# Line 1  Line 1 
1  ;;; indian.el --- support for Indian Languages -*- coding: iso-2022-7bit; -*-  ;;; indian.el --- Indian languages support -*- coding: iso-2022-7bit; -*-
2    
3  ;; Copyright (C) 1995 Free Software Foundation, Inc.  ;; Copyright (C) 1999, 2001 Free Software Foundation, Inc.
4    
5  ;; Author: KAWABATA, Taichi <kawabata@is.s.u-tokyo.ac.jp>  ;; Maintainer:  KAWABATA, Taichi <batta@beige.ocn.ne.jp>
6    ;; Keywords:    multilingual, Indian
 ;; Keywords: multilingual, Indian  
7    
8  ;; This file is part of GNU Emacs.  ;; This file is part of GNU Emacs.
9    
# Line 25  Line 24 
24    
25  ;;; Commentary:  ;;; Commentary:
26    
27  ;; History:  ;; This file defines in-is13194 coding system and relationship between
28  ;; 1996.10.18 written by KAWABATA, Taichi <kawabata@is.s.u-tokyo.ac.jp>  ;; indian-glyph character-set and various CDAC fonts.
   
 ;; For Indian, the character set IS 13194 is supported.  
 ;;  
 ;; IS 13194 does not specifically assign glyphs for each characters.  
 ;; Following code is not specific to each Indian language.  
 ;;  
 ;; Eventually, this code will support generic information about  
 ;; following scripts.  
 ;;  
 ;;    Devanagari  
 ;;    Bengali  
 ;;    Gurmukhi  
 ;;    Gujarati  
 ;;    Oriya  
 ;;    Tamil  
 ;;    Telgu  
 ;;    Kannada  
 ;;    Malayalam  
 ;;  
 ;; In this file, charsets other than charset-ascii and charset-indian-is13194  
 ;; should not be used except in the comment.  
29    
30  ;;; Code:  ;;; Code:
31    
32  ;;  Followings are what you see when you refer to the Emacs  (make-coding-system
33  ;;  representations of IS 13194 charcters.  However, this is merely   'in-is13194 2 ?D
34  ;;  tentative apperance, and you must convert them by   "8-bit encoding for ASCII (MSB=0) and IS13194-Devanagari (MSB=1)"
35  ;;  indian-to-xxxxxx(specific script) function to use them.   '(ascii indian-is13194 nil nil
36  ;;  Devanagari is not an exception of this rule.     nil ascii-eol)
37     '((safe-charsets ascii indian-is13194)
38  ;;     0xa0 //(5!"#$%&'()*+,-./(B     (post-read-conversion . in-is13194-post-read-conversion)
39  ;;     0xb0 (50123456789:;<=>?(B     (pre-write-conversion . in-is13194-pre-write-conversion)))
40  ;;     0xc0 (5@ABCDEFGHIJKLMNO(B  
41  ;;     0xd0 (5PQRSTUVWXYZ[\]^_(B  (defvar indian-script-table
42  ;;     0xe0 (5`abcdefghijklmno(B    '[
43  ;;     0xf0 (5pqrstuvwxyz{|}~(B//      devanagari
44        sanskrit
45  ;; Note - In IS 13194, several symbols are obtained by special      bengali
46  ;; combination of several characters and Nukta sign.      tamil
47  ;;      telugu
48  ;;   Sanskrit Vowel R  -> (5*(B + (5i(B      assamese
49  ;;   Sanskrit Vowel L  -> (5&(B + (5i(B      oriya
50  ;;   Sanskrit Vowel LL -> (5'(B + (5i(B      kannada
51  ;;   Sanskrit Avagrah  -> (5j(B + (5i(B      malayalam
52  ;;   OM                -> (5!(B + (5i(B      gujarati
53  ;;      punjabi
54  ;; Note - IS 13194 defines ATR(0xEF) and EXT(0xF0), but they are      ]
55  ;; not used in Emacs.    "Vector of Indian script names.")
56  ;;  
57  ;; Note - the above characters DO NOT represent any script.  For  (let ((len (length indian-script-table))
58  ;; example, if you want to obtain Devanagari character, you must do        (i 0))
59  ;; something like the following.    (while (< i len)
60  ;;      (put (aref indian-script-table i) 'indian-glyph-code-offset (* 256 i))
61  ;;   (char-to-string (indian-to-devanagari ?(5$(B))      (setq i (1+ i))))
62  ;;   "$(5!$(B"  
63    (defvar indian-default-script 'devanagari
64  ;;; ITRANS    "Default script for Indian languages.
65  ;;  Each Indian language environment sets this value
66  ;; ITRANS is one of the most popular method to exchange indian scripts  to one of `indian-script-table' (which see).
67  ;; electronically.  Here is the table to convert between ITRANS code and  The default value is `devanagari'.")
68  ;; IS 13194 code.  
69    (defun indian-glyph-char (index &optional script)
70  (defvar indian-itrans-consonant-alist    "Return character of charset `indian-glyph' made from glyph index INDEX.
71    '(  The variable `indian-default-script' specifies the script of the glyph.
72      ("k" . "(53(B")  Optional argument SCRIPT, if non-nil, overrides `indian-default-script'.
73      ("kh" . "(54(B")  See also the function `indian-char-glyph'."
74      ("g" . "(55(B")    (or script
75      ("gh" . "(56(B")        (setq script indian-default-script))
76      ("N^" . "(57(B")    (let ((offset (get script 'indian-glyph-code-offset)))
77      ("ch" . "(58(B")      (or (integerp offset)
78      ("chh" . "(59(B")          (error "Invalid script name: %s" script))
79      ("j" . "(5:(B")      (or (and (>= index 0) (< index 256))
80      ("jh" . "(5;(B")          (error "Invalid glyph index: %d" index))
81      ("JN" . "(5<(B")      (setq index (+ offset index))
82      ("T" . "(5=(B")      (make-char 'indian-glyph (+ (/ index 96) 32) (+ (% index 96) 32))))
83      ("Th" . "(5>(B")  
84      ("D" . "(5?(B")  (defvar indian-glyph-max-char
85      ("Dh" . "(5@(B")    (indian-glyph-char
86      ("N" . "(5A(B")     255 (aref indian-script-table (1- (length indian-script-table))))
87      ("t" . "(5B(B")    "The maximum valid code of characters in the charset `indian-glyph'")
88      ("th" . "(5C(B")  
89      ("d" . "(5D(B")  (defun indian-char-glyph (char)
90      ("dh" . "(5E(B")    "Return information about the glphy code for CHAR of `indian-glyph' charset.
91      ("n" . "(5F(B")  The value is (INDEX . SCRIPT), where INDEX is the glyph index
92      ("nh" . "(5G(B")     ; For transcription of non-Devanagari Languages.  in the font that Indian script name SCRIPT specifies.
93      ("p" . "(5H(B")  See also the function `indian-glyph-char'."
94      ("ph" . "(5I(B")    (let ((split (split-char char))
95      ("b" . "(5J(B")          code)
96      ("bh" . "(5K(B")      (or (eq (car split) 'indian-glyph)
97      ("m" . "(5L(B")          (error "Charset of `%c' is not indian-glyph" char))
98      ("y" . "(5M(B")      (or (<= char indian-glyph-max-char)
99      ("yh" . "(5N(B")      ; For transcription of non-Devanagari Languages.          (error "Invalid indian-glyph char: %d" char))
100      ("r" . "(5O(B")      (setq code (+ (* (- (nth 1 split) 32) 96) (nth 2 split) -32))
101      ("rh" . "(5P(B")      ; For transcription of non-Devanagari Languages.      (cons (% code 256) (aref indian-script-table (/ code 256)))))
102      ("l" . "(5Q(B")  
103      ("v" . "(5T(B")  (define-ccl-program ccl-encode-indian-glyph-font
104      ("sh" . "(5U(B")    `(0
105      ("shh" . "(5V(B")      ;; Shorten (r1 = (((((r1 - 32) * 96) + r2) - 32) % 256))
106      ("s" . "(5W(B")      (r1 = ((((r1 * 96) + r2) - ,(+ (* 32 96) 32)) % 256))))
107      ("h" . "(5X(B")  
108      ("ld" . "(5R(B")  (setq font-ccl-encoder-alist
109      ("L" . "(5R(B")        (cons (cons "-CDAC" 'ccl-encode-indian-glyph-font)
110      ("ksh" . "$(5!3!h!V(B")              font-ccl-encoder-alist))
111      ("GY" . "***GY***")  ; Must check out later.  
112      ;; special consonants  (setq font-ccl-encoder-alist
113      ("q" . "(53i(B")        (cons '("ISO10646.*-1" . ccl-encode-unicode-font)
114      ("K" . "(54i(B")              font-ccl-encoder-alist))
     ("G" . "(55i(B")  
     ("z" . "(5:i(B")  
     ("f" . "(5Ii(B")  
     (".D" . "(5?i(B")  
     (".Dh" . "(5@i(B")  
   ))  
   
 (defvar indian-itrans-vowel-sign-alist  
   '(  
     ;; Special treatment unique to IS 13194 Transliteration  
     ("" . "(5h(B")  
     ("a" . "")  
     ;; Matra (Vowel Sign)  
     ("aa" . "(5Z(B")  
     ("A" . "(5Z(B")  
     ("i" . "(5[(B")  
     ("ii" . "(5\(B")  
     ("I" . "(5\(B")  
     ("u" . "(5](B")  
     ("uu" . "(5^(B")  
     ("U" . "(5^(B")  
     ("R^i" . "(5_(B")     ; These must be checked out later.  
     ("R^I" . "(5_i(B")  
     ("L^i" . "(5[i(B")  
     ("L^I" . "(5\i(B")  
     ("E" . "(5`(B")       ; For transcription of non-Devanangri Languages.  
     ("e" . "(5a(B")  
     ("ai" . "(5b(B")  
     ;; ("e.c" . "(5c(B")     ; Tentatively suppressed.  
     ("O" . "(5d(B")       ; For transcription of non-Devanagari Languages.  
     ("o" . "(5e(B")  
     ("au" . "(5f(B")  
     ;; ("o.c" . "(5g(B")     ; Tentatively suppressed.  
     ))  
   
 ;;  
 ;; Independent vowels and other signs.  
 ;;  
   
 (defvar indian-itrans-other-letters-alist  
   '(  
     ("a" . "(5$(B")  
     ("aa" . "(5%(B")  
     ("A" . "(5%(B")  
     ("i" . "(5&(B")  
     ("ii" . "(5'(B")  
     ("I" . "(5'(B")  
     ("u" . "(5((B")  
     ("uu" . "(5)(B")  
     ("U" . "(5)(B")  
     ("R^i" . "(5*(B")  
     ("R^I" . "(5*i(B")  
     ("L^i" . "(5&i(B")  
     ("L^I" . "(5'i(B")  
     ("E" . "(5+(B")   ; For transcription of non-Devanagari Languages.  
     ("e" . "(5,(B")  
     ("ai" . "(5-(B")  
     ;; ("e.c" . "(5.(B")      ; Candra E  
     ("O" . "(5/(B")   ; For transcription of non-Devanagari Languages.  
     ("o" . "(50(B")  
     ("au" . "(51(B")  
     ;; ("o.c" . "(52(B")      ; Candra O  
     ("M" . "(5$(B")  
     ("H" . "(5#(B")  
     ("AUM" . "(5!i(B")  
     ("OM" . "(5!i(B")  
     (".r" . "(5Oh(B")  
     (".n" . "(5"(B")  
     (".N" . "(5!(B")  
     (".h" . "(5h(B")        ; Halant  
     (".." . "(5j(B")  
     (".a" . "(5ji(B")      ; Avagrah  
     ("0" . "(5q(B")  
     ("1" . "(5r(B")  
     ("2" . "(5s(B")  
     ("3" . "(5t(B")  
     ("4" . "(5u(B")  
     ("5" . "(5v(B")  
     ("6" . "(5w(B")  
     ("7" . "(5x(B")  
     ("8" . "(5y(B")  
     ("9" . "(5z(B")  
     ))  
   
 ;; Regular expression matching single Indian character represented  
 ;; by ITRANS.  
   
 (defvar indian-itrans-regexp  
   (let ((consonant "\\([cs]hh?\\)\\|[kgjTDnpbyr]h?\\|\\(N\\^?\\)\\|\\(jN\\)\\|[mvqKGzfs]\\|\\(ld?\\)\\|\\(ksh\\)\\|\\(GY\\)\\|\\(\\.Dh?\\)")  
         (vowel "\\(a[aiu]\\)\\|\\(ii\\)\\|\\(uu\\)\\|\\([RL]\\^[iI]\\)\\|[AIEOeoaiu]")  
         (misc "[MH0-9]\\|\\(AUM\\)\\|\\(OM\\)\\|\\(\\.[rnNh\\.a]\\)")  
         (lpre "\\(") (rpre "\\)") (orre "\\|"))  
     (concat lpre misc rpre orre  
             lpre lpre consonant rpre "?" lpre vowel rpre rpre orre  
             lpre consonant rpre )))  
   
 ;;  
 ;; Regular expression matching single ITRANS unit for IS 13194 characters.  
 ;;  
   
 (defvar itrans-indian-regexp  
   (let ((vowel "[(5$(B-(52(B]")  
         (consonant "[(53(B-(5X(B]")  
         (matra "[(5Z(B-(5g(B]")  
         (misc "[(5q(B-(5z(B]")  
         (lpre "\\(") (rpre "\\)") (orre "\\|"))  
     (concat misc orre  
             lpre consonant matra "?" rpre orre  
             vowel)))  
   
 ;;  
 ;; IS13194 - ITRANS conversion table for string matching above regexp.  
 ;;  
   
 (defvar indian-itrans-alist  
   (let ((cl indian-itrans-consonant-alist)  
         (ml indian-itrans-other-letters-alist) rules)  
           (while cl  
             (let ((vl indian-itrans-vowel-sign-alist))  
               (while vl  
                 (setq rules  
                       (cons (cons (concat (car (car cl)) (car (car vl)))  
                                   (concat (cdr (car cl)) (cdr (car vl))))  
                             rules))  
                 (setq vl (cdr vl))))  
             (setq cl (cdr cl)))  
           (while ml  
             (setq rules (cons (cons (car (car ml))  
                                     (cdr (car ml)))  
                               rules))  
             (setq ml (cdr ml)))  
           rules))  
   
 ;;  
 ;; Utility program to convert from ITRANS to IS 13194 in specified region.  
 ;;  
   
 (defun indian-decode-itrans-region (from to)  
   "Convert `ITRANS' mnemonics of the current region to Indian characters.  
 When called from a program, expects two arguments,  
 positions (integers or markers) specifying the stretch of the region."  
   (interactive "r")  
   (save-restriction  
     (narrow-to-region from to)  
     (goto-char (point-min))  
     (while (re-search-forward indian-itrans-regexp nil t)  
       (let* ((itrans (buffer-substring (match-beginning 0) (match-end 0)))  
              (ch (cdr (assoc itrans indian-itrans-alist))))  
         (if ch  
             (progn  
               (delete-region (match-beginning 0) (match-end 0))  
               (insert ch)))))  
     (goto-char (point-min))  
     (while (re-search-forward "\\((5h(B\\)[^\\c0]" nil t)  
       (delete-region (match-beginning 1) (match-end 1)))))  
   
 ;;  
 ;; Utility program to convert from IS 13194 to ITRANS in specified region.  
 ;;  
   
 (defun indian-encode-itrans-region (from to)  
   "Convert indian region to ITRANS mnemonics."  
   (interactive "r")  
   (save-restriction  
     (narrow-to-region from to)  
     (goto-char (point-min))  
     (while (re-search-forward itrans-indian-regexp nil t)  
       (let* ((indian (buffer-substring (match-beginning 0) (match-end 0)))  
              (ch (car (rassoc indian indian-itrans-alist))))  
         (if ch  
             (progn  
               (delete-region (match-beginning 0) (match-end 0))  
               (insert ch)))))  
     (goto-char (point-min))))  
115    
116  (provide 'indian)  (provide 'indian)
117      
118  ;;; indian.el ends here  ;;; indian.el ends here

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26