(est-coded-charset-priority-list): Add `=ucs-itaiji-001'.
[chise/est.git] / cwiki-common.el
1 ;; -*- coding: utf-8-mcs-er -*-
2 (require 'char-db-util)
3
4 (setq file-name-coding-system 'utf-8-mcs-er)
5
6
7 (concord-assign-genre 'creator@ruimoku "/usr/local/var/ruimoku/db")
8 (concord-assign-genre 'person-name@ruimoku "/usr/local/var/ruimoku/db")
9
10 (concord-assign-genre 'journal-volume@ruimoku "/usr/local/var/ruimoku/db")
11 (concord-assign-genre 'article@ruimoku "/usr/local/var/ruimoku/db")
12 (concord-assign-genre 'book@ruimoku "/usr/local/var/ruimoku/db")
13
14 (concord-assign-genre 'classification@ruimoku "/usr/local/var/ruimoku/db")
15 (concord-assign-genre 'region@ruimoku "/usr/local/var/ruimoku/db")
16 (concord-assign-genre 'era@ruimoku "/usr/local/var/ruimoku/db")
17 (concord-assign-genre 'period@ruimoku "/usr/local/var/ruimoku/db")
18 (concord-assign-genre 'journal@ruimoku "/usr/local/var/ruimoku/db")
19 (concord-assign-genre 'journal-name@ruimoku "/usr/local/var/ruimoku/db")
20 (concord-assign-genre 'publisher@ruimoku "/usr/local/var/ruimoku/db")
21 (concord-assign-genre 'publisher-name@ruimoku "/usr/local/var/ruimoku/db")
22
23 (mount-char-attribute-table '*instance@ruimoku/bibliography/title)
24 ;; (mount-char-attribute-table '*instance@ruimoku/bibliography/content*note)
25
26 (concord-assign-genre 'entry@zh-classical "/usr/local/var/kanbun/db")
27 ;; (concord-assign-genre 'morpheme-entry@zh-classical "/usr/local/var/kanbun/db")
28 (concord-assign-genre 'word-class@zh-classical "/usr/local/var/kanbun/db")
29 (concord-assign-genre 'morpheme@zh-classical "/usr/local/var/kanbun/db")
30 (concord-assign-genre 'sentence@zh-classical "/usr/local/var/kanbun/db")
31 ;; (concord-assign-genre 'sentence-entry@zh-classical "/usr/local/var/kanbun/db")
32
33 (mount-char-attribute-table '*instance@morpheme-entry/zh-classical)
34
35
36 (mount-char-attribute-table '->HNG)
37 (mount-char-attribute-table '<-HNG)
38
39
40 (defvar est-hide-cgi-mode nil)
41 (defvar est-view-url-prefix "..")
42 (defvar chise-wiki-view-url "view.cgi")
43 (defvar chise-wiki-edit-url "edit.cgi")
44
45 (defvar chise-wiki-bitmap-glyphs-url
46   "http://www.chise.org/glyphs")
47
48 (defvar chise-wiki-hng-bitmap-glyphs-url
49   "http://hng.chise.org/glyphs/HNG")
50
51 (defvar chise-wiki-glyph-cgi-url
52   "http://www.chise.org/chisewiki/glyph.cgi")
53
54 (defvar chise-wiki-displayed-features nil)
55
56 (defvar est-coded-charset-priority-list
57   '(; =ucs
58     =cns11643-1 =cns11643-2 =cns11643-3
59     =cns11643-4 =cns11643-5 =cns11643-6 =cns11643-7
60     =gb2312 =gb12345
61     =jis-x0208 =jis-x0208@1990
62     =jis-x0213-2
63     =jis-x0212
64     =adobe-japan1
65     =cbeta =jef-china3
66     =jis-x0213-1@2000 =jis-x0213-1@2004
67     =jis-x0208@1983 =jis-x0208@1978
68     =zinbun-oracle =>zinbun-oracle
69     =daikanwa
70     =gt =gt-k
71     =>>>adobe-japan1
72     =>>>jis-x0208 =>>>jis-x0213-1 =>>>jis-x0213-2
73     =>>jis-x0208 =>>jis-x0213-1 =>>jis-x0213-2
74     =>>adobe-japan1
75     =+>jis-x0208 =+>jis-x0213-1 =+>jis-x0213-2
76     =+>jis-x0208@1978
77     =+>adobe-japan1
78     =>jis-x0208 =>jis-x0213-1
79     =>>gt
80     =>ucs@iso =>ucs@unicode
81     =>ucs@jis =>ucs@cns =>ucs@ks
82     =>>ucs@iso =>>ucs@unicode
83     =>>ucs@jis =>>ucs@cns =>>ucs@ks
84     =>>>ucs@iso =>>>ucs@unicode
85     =>>>ucs@jis =>>>ucs@cns =>>>ucs@ks
86     ===ucs@iso
87     =ruimoku-v6
88     =big5
89     =big5-cdp
90     =ucs-itaiji-001
91     =ucs-itaiji-002))
92
93 (defun decode-uri-string (string &optional coding-system)
94   (if (> (length string) 0)
95       (let ((i 0)
96             dest)
97         (setq string
98               (mapconcat (lambda (char)
99                            (if (eq char ?+)
100                                " "
101                              (char-to-string char)))
102                          string ""))
103         (while (string-match "%\\([0-9A-F][0-9A-F]\\)" string i)
104           (setq dest (concat dest
105                              (substring string i (match-beginning 0))
106                              (char-to-string
107                               (int-char
108                                (string-to-int (match-string 1 string) 16))))
109                 i (match-end 0)))
110         (decode-coding-string
111          (concat dest (substring string i))
112          coding-system))))
113
114 (defun www-feature-type (feature-name)
115   (or (char-feature-property feature-name 'type)
116       (let ((str (symbol-name feature-name)))
117         (cond
118          ((string-match "\\*note\\(@[^*]+\\)?$" str)
119           'stext)
120          ((string-match "\\*sources\\(@[^*]+\\)?$" str)
121           'domain-list)
122          ((string-match "\\*" str)
123           nil)
124          ((string-match "^\\(->\\|<-\\)" str)
125           'relation)
126          ((string-match "^ideographic-structure\\(@\\|$\\)" str)
127           'structure)
128          ))))
129
130 (defun www-feature-format (feature-name)
131   (or (char-feature-property feature-name 'presentation-format)
132       (char-feature-property feature-name 'format)
133       (let (fn parent ret)
134         (setq fn feature-name)
135         (while (and (setq parent (char-feature-name-parent fn))
136                     (null (setq ret
137                                 (char-feature-property
138                                  parent 'format))))
139           (setq fn parent))
140         ret)
141       '((name) " : " (value))))
142
143 (defun www-feature-value-format (feature-name)
144   (or (char-feature-property feature-name 'value-presentation-format)
145       (char-feature-property feature-name 'value-format)
146       (let (fn parent ret)
147         (setq fn feature-name)
148         (while (and (setq parent (char-feature-name-parent fn))
149                     (null (setq ret
150                                 (or (char-feature-property
151                                      parent 'value-presentation-format)
152                                     (char-feature-property
153                                      parent 'value-format)))))
154           (setq fn parent))
155         ret)
156       (let ((type (www-feature-type feature-name)))
157         (cond ((eq type 'relation)
158                'space-separated)
159               ((eq type 'structure)
160                'space-separated-ids)
161               ((eq type 'stext)
162                'wiki-text)
163               ))
164       (if (find-charset feature-name)
165           (if (and (= (charset-dimension feature-name) 2)
166                    (= (charset-chars feature-name) 94))
167               '("0x" (HEX)
168                 " (" (decimal) ") <" (ku-ten) "> " (prev-char) (next-char))
169             '("0x" (HEX) " (" (decimal) ") " (prev-char) (next-char))))
170       'space-separated))
171
172 (defun char-feature-name-at-domain (feature-name domain)
173   (if domain
174       (let ((name (symbol-name feature-name)))
175         (cond
176          ((string-match "@[^*]+$" name)
177           (intern (format "%s/%s" name domain))
178           )
179          (t
180           (intern (format "%s@%s" name domain))
181           )))
182     feature-name))
183
184 (defun char-feature-name-parent (feature-name)
185   (let ((name (symbol-name feature-name)))
186     (if (string-match "@[^@/*]+\\(/[^@/*]+\\)*$" name)
187         (intern (substring name 0 (car (last (match-data) 2)))))))
188
189 (defun char-feature-name-domain (feature-name)
190   (let ((name (symbol-name feature-name)))
191     (if (string-match "@[^@/*]+\\(/[^@/*]+\\)*$" name)
192         (intern (substring name (1+ (match-beginning 0)))))))
193
194 (defun char-feature-name-sans-versions (feature)
195   (let ((feature-name (symbol-name feature)))
196     (if (string-match "[@/]\\$rev=latest$" feature-name)
197         (intern (substring feature-name 0 (match-beginning 0)))
198       feature)))
199
200 (defun est-object-genre (object)
201   (if (characterp object)
202       'character
203     (concord-object-genre object)))
204
205 (defun www-get-feature-value (object feature)
206   (let ((latest-feature (char-feature-name-at-domain feature '$rev=latest)))
207     (cond
208      ((characterp object)
209       (mount-char-attribute-table latest-feature)
210       (or (char-feature object latest-feature)
211           (char-feature object feature))
212       )
213      (t
214       (or (condition-case nil
215               (concord-object-get object latest-feature)
216             (error nil))
217           (condition-case nil
218               (concord-object-get object feature)
219             (error nil)))
220       ))))
221
222 (defun get-previous-code-point (ccs code)
223   (let ((chars (charset-chars ccs))
224         (dim (charset-dimension ccs))
225         (i 0)
226         mask byte-min byte-max
227         bytes dest)
228     (cond
229      ((= chars 94)
230       (setq mask #x7F
231             byte-min 33
232             byte-max 126)
233       )
234      ((= chars 96)
235       (setq mask #x7F
236             byte-min 32
237             byte-max 127)
238       )
239      ((= chars 128)
240       (setq mask #x7F
241             byte-min 0
242             byte-max #xFF)
243       )
244      (t ; (= chars 256)
245       (setq mask #xFF
246             byte-min 0
247             byte-max #xFF)
248       ))
249     (setq bytes (make-vector dim 0))
250     (while (< i dim)
251       (aset bytes i (logand (lsh code (* i -8)) mask))
252       (setq i (1+ i)))
253     (setq i 0)
254     (while (and (< i dim)
255                 (progn
256                   (aset bytes i (1- (aref bytes i)))
257                   (< (aref bytes i) byte-min)))
258       (aset bytes i byte-max)
259       (setq i (1+ i)))
260     (when (< i dim)
261       (setq dest (aref bytes 0)
262             i 1)
263       (while (< i dim)
264         (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
265               i (1+ i)))
266       dest)))
267
268 (defun get-next-code-point (ccs code)
269   (let ((chars (charset-chars ccs))
270         (dim (charset-dimension ccs))
271         (i 0)
272         mask byte-min byte-max
273         bytes dest)
274     (cond
275      ((= chars 94)
276       (setq mask #x7F
277             byte-min 33
278             byte-max 126)
279       )
280      ((= chars 96)
281       (setq mask #x7F
282             byte-min 32
283             byte-max 127)
284       )
285      ((= chars 128)
286       (setq mask #x7F
287             byte-min 0
288             byte-max #xFF)
289       )
290      (t ; (= chars 256)
291       (setq mask #xFF
292             byte-min 0
293             byte-max #xFF)
294       ))
295     (setq bytes (make-vector dim 0))
296     (while (< i dim)
297       (aset bytes i (logand (lsh code (* i -8)) mask))
298       (setq i (1+ i)))
299     (setq i 0)
300     (while (and (< i dim)
301                 (progn
302                   (aset bytes i (1+ (aref bytes i)))
303                   (> (aref bytes i) byte-max)))
304       (aset bytes i byte-min)
305       (setq i (1+ i)))
306     (when (< i dim)
307       (setq dest (aref bytes 0)
308             i 1)
309       (while (< i dim)
310         (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
311               i (1+ i)))
312       dest)))
313
314 (defun find-previous-defined-code-point (ccs code)
315   (let ((i (get-previous-code-point ccs code))
316         char)
317     (cond
318      ((eq ccs '=jis-x0208)
319       (setq ccs '=jis-x0208@1990))
320      ((eq ccs '=jis-x0213-1)
321       (setq ccs '=jis-x0213-1@2004)))
322     (while (and i
323                 (>= i 0)
324                 (null (setq char (decode-char ccs i
325                                               (unless (eq ccs '=ucs)
326                                                 'defined-only)))))
327       (setq i (get-previous-code-point ccs i)))
328     char))
329
330 (defun find-next-defined-code-point (ccs code)
331   (let ((i (get-next-code-point ccs code))
332         max char)
333     (setq max (+ code 1000))
334     (cond
335      ((eq ccs '=jis-x0208)
336       (setq ccs '=jis-x0208@1990))
337      ((eq ccs '=jis-x0213-1)
338       (setq ccs '=jis-x0213-1@2004)))
339     (while (and i
340                 (<= i max)
341                 (null (setq char (decode-char ccs i
342                                               (unless (eq ccs '=ucs)
343                                                 'defined-only)))))
344       (setq i (get-next-code-point ccs i)))
345     char))
346
347
348 ;;; @ URI representation
349 ;;;
350
351 (defun est-uri-decode-feature-name-body (uri-feature)
352   (let ((len (length uri-feature))
353         (i 0)
354         ch dest)
355     (while (< i len)
356       (setq dest
357             (concat
358              dest
359              (if (eq (aref uri-feature i) ?\.)
360                  (if (and (< (+ i 2) len)
361                           (eq (aref uri-feature (+ i 2)) ?\.))
362                      (prog1
363                          (cond
364                           ((eq (setq ch (aref uri-feature (1+ i))) ?\.)
365                            "/")
366                           ((eq ch ?-)
367                            "*")
368                           (t
369                            (substring uri-feature i (+ i 3))
370                            ))
371                        (setq i (+ i 3)))
372                    (setq i (1+ i))
373                    ".")
374                (prog1
375                    (char-to-string (aref uri-feature i))
376                  (setq i (1+ i)))))))
377     dest))
378
379 (defun est-uri-encode-feature-name-body (feature)
380   (mapconcat (lambda (c)
381                (cond ((eq c ?*)
382                       ".-.")
383                      ((eq c ?/)
384                       "...")
385                      (t (char-to-string c))))
386              feature ""))
387
388 (defun www-uri-decode-feature-name (uri-feature)
389   (let (feature)
390     (setq uri-feature (decode-uri-string uri-feature 'utf-8-mcs-er))
391     (cond
392      ((string-match "^from\\." uri-feature)
393       (intern (format "<-%s"
394                       (est-uri-decode-feature-name-body
395                        (substring uri-feature (match-end 0)))))
396       )
397      ((string-match "^to\\." uri-feature)
398       (intern (format "->%s"
399                       (est-uri-decode-feature-name-body
400                        (substring uri-feature (match-end 0)))))
401       )
402      ((string-match "^rep\\." uri-feature)
403       (intern (format "=%s"
404                       (est-uri-decode-feature-name-body
405                        (substring uri-feature (match-end 0)))))
406       )
407      ((string-match "^rep[2i]\\." uri-feature)
408       (intern (format "===%s"
409                       (est-uri-decode-feature-name-body
410                        (substring uri-feature (match-end 0)))))
411       )
412      ((string-match "^g\\." uri-feature)
413       (intern (format "=>>%s"
414                       (est-uri-decode-feature-name-body
415                        (substring uri-feature (match-end 0)))))
416       )
417      ((string-match "^g[i2]\\." uri-feature)
418       (intern (format "==%s"
419                       (est-uri-decode-feature-name-body
420                        (substring uri-feature (match-end 0)))))
421       )
422      ((string-match "^gi\\([0-9]+\\)\\." uri-feature)
423       (intern (format "=>>%s%s"
424                       (make-string (string-to-int
425                                     (match-string 1 uri-feature))
426                                    ?>)
427                       (est-uri-decode-feature-name-body
428                        (substring uri-feature (match-end 0)))))
429       )
430      ((string-match "^o\\." uri-feature)
431       (intern (format "=+>%s"
432                       (est-uri-decode-feature-name-body
433                        (substring uri-feature (match-end 0)))))
434       )
435      ((string-match "^a\\." uri-feature)
436       (intern (format "=>%s"
437                       (est-uri-decode-feature-name-body
438                        (substring uri-feature (match-end 0)))))
439       )
440      ((string-match "^a\\([0-9]+\\)\\." uri-feature)
441       (intern (format "%s>%s"
442                       (make-string (string-to-int
443                                     (match-string 1 uri-feature))
444                                    ?=)
445                       (est-uri-decode-feature-name-body
446                        (substring uri-feature (match-end 0)))))
447       )
448      ((and (setq uri-feature (est-uri-decode-feature-name-body uri-feature))
449            (setq feature (intern (format "=>%s" uri-feature)))
450            (find-charset feature))
451       feature)
452      ((and (setq feature (intern (format "=>>%s" uri-feature)))
453            (find-charset feature))
454       feature)
455      ((and (setq feature (intern (format "=>>>%s" uri-feature)))
456            (find-charset feature))
457       feature)
458      ((and (setq feature (intern (format "=%s" uri-feature)))
459            (find-charset feature))
460       feature)
461      (t (intern uri-feature)))))
462
463 (defun www-uri-encode-feature-name (feature-name)
464   (setq feature-name (symbol-name feature-name))
465   (cond
466    ((string-match "^=\\+>\\([^=>]+\\)" feature-name)
467     (concat "o."
468             (est-uri-encode-feature-name-body
469              (substring feature-name (match-beginning 1))))
470     )
471    ((string-match "^=\\([^=>]+\\)" feature-name)
472     (concat "rep."
473             (est-uri-encode-feature-name-body
474              (substring feature-name (match-beginning 1))))
475     )
476    ((string-match "^==\\([^=>]+\\)" feature-name)
477     (concat "g2."
478             (est-uri-encode-feature-name-body
479              (substring feature-name (match-beginning 1))))
480     )
481    ((string-match "^===\\([^=>]+\\)" feature-name)
482     (concat "repi."
483             (est-uri-encode-feature-name-body
484              (substring feature-name (match-beginning 1))))
485     )
486    ((string-match "^=>>\\([^=>]+\\)" feature-name)
487     (concat "g."
488             (est-uri-encode-feature-name-body
489              (substring feature-name (match-beginning 1))))
490     )
491    ((string-match "^=>>>\\([^=>]+\\)" feature-name)
492     (concat "gi."
493             (est-uri-encode-feature-name-body
494              (substring feature-name (match-beginning 1))))
495     )
496    ((string-match "^=>>\\(>+\\)" feature-name)
497     (format "gi%d.%s"
498             (length (match-string 1 feature-name))
499             (est-uri-encode-feature-name-body
500              (substring feature-name (match-end 1))))
501     )
502    ((string-match "^=>\\([^=>]+\\)" feature-name)
503     (concat "a."
504             (est-uri-encode-feature-name-body
505              (substring feature-name (match-beginning 1))))
506     )
507    ((string-match "^\\(=+\\)>" feature-name)
508     (format "a%d.%s"
509             (length (match-string 1 feature-name))
510             (est-uri-encode-feature-name-body
511              (substring feature-name (match-end 0))))
512     )
513    ((string-match "^->" feature-name)
514     (concat "to."
515             (est-uri-encode-feature-name-body
516              (substring feature-name (match-end 0))))
517     )
518    ((string-match "^<-" feature-name)
519     (concat "from."
520             (est-uri-encode-feature-name-body
521              (substring feature-name (match-end 0))))
522     )
523    (t (est-uri-encode-feature-name-body feature-name))))
524
525 (defun www-uri-make-feature-name-url (uri-genre uri-feature-name uri-object)
526   (if est-hide-cgi-mode
527       (format "../feature/%s&%s/%s"
528               uri-feature-name uri-genre uri-object)
529     (format "%s?feature=%s&%s=%s"
530             chise-wiki-view-url uri-feature-name uri-genre uri-object)))
531
532 (defun www-uri-decode-object (genre char-rep)
533   (let (ccs cpos)
534     (cond
535      ((string-match (if est-hide-cgi-mode
536                         "\\(%3D\\|=\\|%3A\\|:\\)"
537                       "\\(%3A\\|:\\)") char-rep)
538       (setq ccs (substring char-rep 0 (match-beginning 0))
539             cpos (substring char-rep (match-end 0)))
540       (setq ccs (www-uri-decode-feature-name ccs))
541       (setq cpos (est-uri-decode-feature-name-body cpos))
542       (cond
543        ((string-match "^0x" cpos)
544         (setq cpos
545               (string-to-number (substring cpos (match-end 0)) 16))
546         )
547        (t
548         (setq cpos (car (read-from-string
549                          (decode-uri-string
550                           cpos file-name-coding-system))))
551         ))
552       (if (and (eq genre 'character)
553                (numberp cpos))
554           (decode-char ccs cpos)
555         (concord-decode-object ccs cpos genre))
556       )
557      (t
558       (setq char-rep (decode-uri-string char-rep 'utf-8-mcs-er))
559       (cond
560        ((eq genre 'character)
561         (when (= (length char-rep) 1)
562           (aref char-rep 0))
563         )
564        ((eq genre 'feature)
565         (concord-decode-object
566          '=id (www-uri-decode-feature-name char-rep) 'feature)
567         )
568        (t
569         (concord-decode-object
570          '=id (car (read-from-string char-rep)) genre)
571         ))))))
572
573 (defun www-uri-encode-object (object)
574   (if (characterp object)
575       (if (encode-char object '=ucs)
576           (mapconcat
577            (lambda (byte)
578              (format "%%%02X" byte))
579            (encode-coding-string (char-to-string object) 'utf-8-mcs-er)
580            "")
581         (let ((ccs-list est-coded-charset-priority-list)
582               ccs ret)
583           (while (and ccs-list
584                       (setq ccs (pop ccs-list))
585                       (not (setq ret (encode-char object ccs 'defined-only)))))
586           (cond (ret
587                  (format (if est-hide-cgi-mode
588                              "%s=0x%X"
589                            "%s:0x%X")
590                          (www-uri-encode-feature-name ccs)
591                          ret))
592                 ((and (setq ccs (car (split-char object)))
593                       (setq ret (encode-char object ccs)))
594                  (format (if est-hide-cgi-mode
595                              "%s=0x%X"
596                            "%s:0x%X")
597                          (www-uri-encode-feature-name ccs)
598                          ret))
599                 (t
600                  (format (if est-hide-cgi-mode
601                              "system-char-id=0x%X"
602                            "system-char-id:0x%X")
603                          (encode-char object 'system-char-id))
604                  ))))
605     (format (if est-hide-cgi-mode
606                 "rep.id=%s"
607               "rep.id:%s")
608             (est-uri-encode-feature-name-body
609              (format "%s" (concord-object-id object))))))
610
611 (defun est-format-object (object &optional readable)
612   (if (characterp object)
613       (char-to-string object)
614     (let ((ret (or (if readable
615                        (or (concord-object-get object 'name)
616                            (concord-object-get object '=name)
617                            (concord-object-get object 'title)))
618                    (concord-object-id object))))
619       (format "%s" ret))))
620
621 (defun www-uri-make-object-url (object &optional uri-object)
622   (if est-hide-cgi-mode
623       (format "%s/%s/%s"
624               est-view-url-prefix
625               (est-object-genre object)
626               (or uri-object
627                   (www-uri-encode-object object)))
628     (format "%s?%s=%s"
629             chise-wiki-view-url
630             (est-object-genre object)
631             (or uri-object
632                 (www-uri-encode-object object)))))
633
634
635 ;;; @ Feature name presentation
636 ;;;
637
638 (defun www-format-feature-name-default (feature-name)
639   (mapconcat
640    #'capitalize
641    (split-string
642     (symbol-name feature-name)
643     "-")
644    " "))
645
646 (defun www-format-feature-name-as-metadata (feature-name &optional lang)
647   (let ((str (symbol-name feature-name))
648         base meta)
649     (cond
650      ((string-match "\\*[^*]+$" str)
651       (setq base (substring str 0 (match-beginning 0))
652             meta (substring str (match-beginning 0)))
653       (concat (www-format-feature-name* (intern base) lang)
654               meta))
655      (t
656       (www-format-feature-name-default feature-name)
657       ))))
658
659 (defun www-format-feature-name-as-rel-to (feature-name)
660   (concat "\u2192" (substring (symbol-name feature-name) 2)))
661
662 (defun www-format-feature-name-as-rel-from (feature-name)
663   (concat "\u2190" (substring (symbol-name feature-name) 2)))
664
665 (defun www-format-feature-name-as-CCS (feature-name)
666   (let* ((rest
667           (split-string
668            (symbol-name feature-name)
669            "-"))
670          (dest (upcase (pop rest))))
671     (when (string-match "^=+>*" dest)
672       (setq dest (concat (substring dest 0 (match-end 0))
673                          " "
674                          (substring dest (match-end 0)))))
675     (cond
676      (rest
677       (while (cdr rest)
678         (setq dest (concat dest " " (upcase (pop rest)))))
679       (if (string-match "^[0-9]+$" (car rest))
680           (concat dest "-" (car rest))
681         (concat dest " " (upcase (car rest))))
682       )
683      (t dest))))
684
685 (defun www-format-feature-name* (feature-name &optional lang)
686   (let (name fn parent ret)
687     (cond
688      ((or (and lang
689                (char-feature-property
690                 feature-name
691                 (intern (format "name@%s" lang))))
692           (char-feature-property
693            feature-name 'name)))
694      ((and (setq name (symbol-name feature-name))
695            (string-match "\\*" name))
696       (www-format-feature-name-as-metadata feature-name lang))
697      (t
698       (setq fn feature-name)
699       (while (and (setq parent (char-feature-name-parent fn))
700                   (null (setq ret
701                               (or (and lang
702                                        (char-feature-property
703                                         parent
704                                         (intern (format "name@%s" lang))))
705                                   (char-feature-property
706                                    parent 'name)))))
707         (setq fn parent))
708       (cond
709        (ret
710         (concat ret (substring (symbol-name feature-name)
711                                (length (symbol-name parent)))))
712        ((find-charset feature-name)
713         (www-format-feature-name-as-CCS feature-name))
714        ((string-match "^\\(->\\)" name)
715         (www-format-feature-name-as-rel-to feature-name))
716        ((string-match "^\\(<-\\)" name)
717         (www-format-feature-name-as-rel-from feature-name))
718        (t
719         (www-format-feature-name-default feature-name)
720         ))
721       ))))
722
723 (defun www-format-feature-name (feature-name &optional lang)
724   (www-format-encode-string
725    (www-format-feature-name* feature-name lang)))
726
727
728 ;;; @ HTML generator
729 ;;;
730
731 (defvar www-format-char-img-style "vertical-align:bottom;")
732
733 (defun www-format-encode-string (string &optional without-tags as-body)
734   (with-temp-buffer
735     (insert string)
736     (let (plane code subcode start end char variants ret rret)
737       (when as-body
738         (goto-char (point-min))
739         (while (search-forward "&" nil t)
740           (replace-match "&amp;" nil t)))
741       (goto-char (point-min))
742       (while (search-forward "<" nil t)
743         (replace-match "&lt;" nil t))
744       (goto-char (point-min))
745       (while (search-forward ">" nil t)
746         (replace-match "&gt;" nil t))
747       (if without-tags
748           (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
749         (let ((coded-charset-entity-reference-alist
750                (list*
751                 '(=gt                   "GT-" 5 d)
752                 '(=hanyo-denshi/ja   "HD-JA-" 4 X)
753                 '(=hanyo-denshi/jb   "HD-JB-" 4 X)
754                 '(=hanyo-denshi/jc   "HD-JC-" 4 X)
755                 '(=hanyo-denshi/jd   "HD-JD-" 4 X)
756                 '(=hanyo-denshi/ft   "HD-FT-" 4 X)
757                 '(=hanyo-denshi/ia   "HD-IA-" 4 X)
758                 '(=hanyo-denshi/ib   "HD-IB-" 4 X)
759                 '(=hanyo-denshi/hg   "HD-HG-" 4 X)
760                 '(=hanyo-denshi/ip   "HD-IP-" 4 X)
761                 '(=hanyo-denshi/jt   "HD-JT-" 4 X)
762                 '(=hanyo-denshi/ks   "HD-KS-" 6 d)
763                 '(=>>hanyo-denshi/ja "G-HD-JA-" 4 X)
764                 '(=>>hanyo-denshi/jb "G-HD-JB-" 4 X)
765                 '(=>>hanyo-denshi/jc "G-HD-JC-" 4 X)
766                 '(=>>hanyo-denshi/jd "G-HD-JD-" 4 X)
767                 '(=>>hanyo-denshi/ft "G-HD-FT-" 4 X)
768                 '(=>>hanyo-denshi/ia "G-HD-IA-" 4 X)
769                 '(=>>hanyo-denshi/ib "G-HD-IB-" 4 X)
770                 '(=>>hanyo-denshi/hg "G-HD-HG-" 4 X)
771                 '(=>>hanyo-denshi/ip "G-HD-IP-" 4 X)
772                 '(=>>hanyo-denshi/jt "G-HD-JT-" 4 X)
773                 '(=>>hanyo-denshi/ks "G-HD-KS-" 6 d)
774                 '(==hanyo-denshi/ja "g2-HD-JA-" 4 X)
775                 '(==hanyo-denshi/jb "g2-HD-JB-" 4 X)
776                 '(==hanyo-denshi/jc "g2-HD-JC-" 4 X)
777                 '(==hanyo-denshi/jd "g2-HD-JD-" 4 X)
778                 '(==hanyo-denshi/ft "g2-HD-FT-" 4 X)
779                 '(==hanyo-denshi/ia "g2-HD-IA-" 4 X)
780                 '(==hanyo-denshi/ib "g2-HD-IB-" 4 X)
781                 '(==hanyo-denshi/hg "g2-HD-HG-" 4 X)
782                 '(==hanyo-denshi/ip "g2-HD-IP-" 4 X)
783                 '(==hanyo-denshi/jt "g2-HD-JT-" 4 X)
784                 '(==hanyo-denshi/ks "g2-HD-KS-" 6 d)
785                 '(=cns11643-1           "C1-" 4 X)
786                 '(=cns11643-2           "C2-" 4 X)
787                 '(=cns11643-3           "C3-" 4 X)
788                 '(=cns11643-4           "C4-" 4 X)
789                 '(=cns11643-5           "C5-" 4 X)
790                 '(=cns11643-6           "C6-" 4 X)
791                 '(=cns11643-7           "C7-" 4 X)
792                 '(=adobe-japan1-6       "AJ1-" 5 d)
793                 '(=big5-cdp             "CDP-" 4 X)
794                 '(=gb2312               "G0-" 4 X)
795                 '(=gb12345              "G1-" 4 X)
796                 '(=jis-x0208@1990       "J90-" 4 X)
797                 '(=jis-x0212            "JSP-" 4 X)
798                 '(=cbeta                "CB" 5 d)
799                 '(=jis-x0208@1997       "J97-" 4 X)
800                 '(=jis-x0208@1978       "J78-" 4 X)
801                 '(=jis-x0208@1983       "J83-" 4 X)
802                 '(=ruimoku-v6           "RUI6-" 4 X)
803                 '(=zinbun-oracle        "ZOB-" 4 d)
804                 '(=jef-china3           "JC3-" 4 X)
805                 '(=ucs@unicode          "UU+" 4 X)
806                 '(=ucs@JP/hanazono  "hanaJU+" 4 X)
807                 '(=daikanwa              "M-" 5 d)
808                 '(==cns11643-1        "R-C1-" 4 X)
809                 '(==cns11643-2        "R-C2-" 4 X)
810                 '(==cns11643-3        "R-C3-" 4 X)
811                 '(==cns11643-4        "R-C4-" 4 X)
812                 '(==cns11643-5        "R-C5-" 4 X)
813                 '(==cns11643-6        "R-C6-" 4 X)
814                 '(==cns11643-7        "R-C7-" 4 X)
815                 coded-charset-entity-reference-alist)))
816           (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
817
818           (goto-char (point-min))
819           (while (re-search-forward "&CB\\([0-9]+\\);" nil t)
820             (setq code (string-to-int (match-string 1)))
821             (replace-match
822              (format "<img alt=\"CB%05d\" src=\"%s/cb-gaiji/%02d/CB%05d.gif\"
823 style=\"%s\">"
824                      code
825                      chise-wiki-bitmap-glyphs-url
826                      (/ code 1000) code
827                      www-format-char-img-style)
828              t 'literal))
829
830           (goto-char (point-min))
831           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?J\\(78\\|83\\|90\\|97\\|SP\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
832             (setq plane (match-string 2)
833                   code (string-to-int (match-string 3) 16))
834             (replace-match
835              (format "<img alt=\"J%s-%04X\" src=\"%s/JIS-%s/%02d-%02d.gif\"
836 style=\"%s\">"
837                      plane code
838                      chise-wiki-bitmap-glyphs-url
839                      plane
840                      (- (lsh code -8) 32)
841                      (- (logand code 255) 32)
842                      www-format-char-img-style)
843              t 'literal))
844
845           (goto-char (point-min))
846           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?J0-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
847             (setq code (string-to-int (match-string 2) 16))
848             (replace-match
849              (format "<img alt=\"J0-%04X\" src=\"%s/JIS-90/%02d-%02d.gif\"
850 style=\"%s\">"
851                      code
852                      chise-wiki-bitmap-glyphs-url
853                      (- (lsh code -8) 32)
854                      (- (logand code 255) 32)
855                      www-format-char-img-style)
856              t 'literal))
857
858           (goto-char (point-min))
859           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?HD-\\(JA\\|JB\\|JC\\|JD\\|FT\\|IA\\|IB\\|HG\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
860             (setq plane (match-string 2)
861                   code (string-to-int (match-string 3) 16))
862             (replace-match
863              (format "<img alt=\"HD-%s-%04X\" src=\"%s/IVD/HanyoDenshi/%s%02d%02d.png\"
864 style=\"%s\">"
865                      plane code
866                      chise-wiki-bitmap-glyphs-url
867                      plane
868                      (- (lsh code -8) 32)
869                      (- (logand code 255) 32)
870                      www-format-char-img-style)
871              t 'literal))
872
873           (goto-char (point-min))
874           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?HD-\\(IP\\|JT\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
875             (setq plane (match-string 2)
876                   code (string-to-int (match-string 3) 16))
877             (replace-match
878              (format "<img alt=\"HD-%s-%04X\" src=\"%s/IVD/HanyoDenshi/%s%04X.png\"
879 style=\"%s\">"
880                      plane code
881                      chise-wiki-bitmap-glyphs-url
882                      plane code
883                      www-format-char-img-style)
884              t 'literal))
885
886           (goto-char (point-min))
887           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?HD-KS-\\([0-9]+\\);" nil t)
888             (setq code (string-to-int (match-string 2)))
889             (replace-match
890              (format "<img alt=\"HD-KS%06d\" src=\"%s/IVD/HanyoDenshi/KS%06d.png\"
891 style=\"vertical-align:middle\">"
892                      code
893                      chise-wiki-bitmap-glyphs-url
894                      code
895                      www-format-char-img-style)
896              t 'literal))
897
898           (goto-char (point-min))
899           (while (re-search-forward "&G\\([01]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
900             (setq plane (string-to-int (match-string 1))
901                   code (string-to-int (match-string 2) 16))
902             (replace-match
903              (format "<img alt=\"GB%d-%04X\" src=\"%s/GB%d/%02d-%02d.gif\"
904 style=\"%s\">"
905                      plane code
906                      chise-wiki-bitmap-glyphs-url
907                      plane
908                      (- (lsh code -8) 32)
909                      (- (logand code 255) 32)
910                      www-format-char-img-style)
911              t 'literal))
912
913           (goto-char (point-min))
914           (while (re-search-forward "&\\(R-\\)?C\\([1-7]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
915             (setq plane (string-to-int (match-string 2))
916                   code (string-to-int (match-string 3) 16))
917             (replace-match
918              (format "<img alt=\"CNS%d-%04X\" src=\"%s/CNS%d/%04X.gif\"
919 style=\"%s\">"
920                      plane code
921                      chise-wiki-bitmap-glyphs-url
922                      plane code
923                      www-format-char-img-style)
924              t 'literal))
925
926           (goto-char (point-min))
927           (while (re-search-forward "&\\(R-\\)?JC3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
928             (setq code (string-to-int (match-string 2) 16))
929             (replace-match
930              (format "<img alt=\"JC3-%04X\" src=\"http://kanji.zinbun.kyoto-u.ac.jp/db/CHINA3/Gaiji/%04x.gif\">"
931                      code code)
932              t 'literal))
933
934           (goto-char (point-min))
935           (while (re-search-forward "&\\(A-\\)?ZOB-\\([0-9]+\\);" nil t)
936             (setq code (string-to-int (match-string 2)))
937             (replace-match
938              (format "<img alt=\"ZOB-%04d\" src=\"%s/ZOB-1968/%04d.png\"
939 style=\"vertical-align:middle\">"
940                      code
941                      chise-wiki-bitmap-glyphs-url
942                      code
943                      www-format-char-img-style)
944              t 'literal))
945
946           (goto-char (point-min))
947           (while (re-search-forward "&HNG\\([0-9]+\\)-\\([0-9][0-9][0-9][0-9]\\)\\([0-9]\\);" nil t)
948             (setq plane (match-string 1)
949                   code (string-to-int (match-string 2))
950                   subcode (string-to-int (match-string 3)))
951             (setq subcode
952                   (if (eq subcode 0)
953                       ""
954                     (char-to-string (decode-char 'ascii (+ 96 subcode)))))
955             (replace-match
956              (format
957               "<img alt=\"HNG%s-%04d%s\" src=\"%s/%s/%04d%s.png\"
958 style=\"vertical-align:middle; width: 48px; height: 48px\">"
959               plane code subcode
960               chise-wiki-hng-bitmap-glyphs-url
961               plane code subcode
962               www-format-char-img-style)
963              t 'literal))
964
965           (goto-char (point-min))
966           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?AJ1-\\([0-9]+\\);" nil t)
967             (setq code (string-to-int (match-string 2)))
968             (replace-match
969              (format "<img alt=\"AJ1-%05d\" src=\"%s/IVD/AdobeJapan1/CID+%d.png\"
970 style=\"vertical-align:middle\">"
971                      code
972                      chise-wiki-bitmap-glyphs-url
973                      code
974                      www-format-char-img-style)
975              t 'literal))
976
977           (goto-char (point-min))
978           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?MJ\\([0-9]+\\);" nil t)
979             (setq code (string-to-int (match-string 2)))
980             (replace-match
981              (format "<img alt=\"MJ%06d\" src=\"http://mojikiban.ipa.go.jp/search/MJ%06d\"
982 style=\"vertical-align:middle; width: 48px; height: 48px\">"
983                      code
984                      code
985                      www-format-char-img-style)
986              t 'literal))
987
988           (goto-char (point-min))
989           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\)?IU-\\([0-9A-F]+\\);" nil t)
990             (setq code (string-to-int (match-string 2) 16))
991             (replace-match
992              (format "<img alt=\"u%04x\" src=\"http://glyphwiki.org/glyph/u%04x.100px.png\"
993 style=\"vertical-align:middle; width: 48px; height: 48px\">"
994                      code
995                      code
996                      www-format-char-img-style)
997              t 'literal))
998
999           (goto-char (point-min))
1000           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?U-i\\([0-9]+\\)\\+\\([0-9A-F]+\\);" nil t)
1001             (setq plane (string-to-int (match-string 2))
1002                   code (string-to-int (match-string 3) 16))
1003             (replace-match
1004              (format "<img alt=\"u%04x-itaiji-%03d\" src=\"http://glyphwiki.org/glyph/u%04x-itaiji-%03d.100px.png\"
1005 style=\"vertical-align:middle; width: 48px; height: 48px\">"
1006                      code
1007                      plane
1008                      code
1009                      plane
1010                      www-format-char-img-style)
1011              t 'literal))
1012
1013           (goto-char (point-min))
1014           (while (re-search-forward "&\\(G-\\|R-\\|g2-\\)?GT-\\([0-9]+\\);" nil t)
1015             (setq code (string-to-int (match-string 2)))
1016             (replace-match
1017              (format "<img alt=\"GT-%05d\" src=\"%s?char=GT-%05d\"
1018 style=\"%s\">"
1019                      code
1020                      chise-wiki-glyph-cgi-url
1021                      code
1022                      www-format-char-img-style)
1023              t 'literal))
1024
1025           (goto-char (point-min))
1026           (while (re-search-forward "&\\(G-\\)?GT-K\\([0-9]+\\);" nil t)
1027             (setq code (string-to-int (match-string 2)))
1028             (replace-match
1029              (format "<img alt=\"GT-K%05d\" src=\"%s?char=GT-K%05d\"
1030 style=\"%s\">"
1031                      code
1032                      chise-wiki-glyph-cgi-url
1033                      code
1034                      www-format-char-img-style)
1035              t 'literal))
1036
1037           (goto-char (point-min))
1038           (while (re-search-forward "&B-\\([0-9A-F]+\\);" nil t)
1039             (setq code (string-to-int (match-string 1) 16))
1040             (replace-match
1041              (format "<img alt=\"B-%04X\" src=\"%s?char=B-%04X\"
1042 style=\"%s\">"
1043                      code
1044                      chise-wiki-glyph-cgi-url
1045                      code
1046                      www-format-char-img-style)
1047              t 'literal))
1048
1049           (goto-char (point-min))
1050           (while (re-search-forward "&\\(G-\\|g2-\\|R-\\)?CDP-\\([0-9A-F]+\\);" nil t)
1051             (setq code (string-to-int (match-string 2) 16))
1052             (replace-match
1053              (format "<img alt=\"CDP-%04X\" src=\"%s?char=CDP-%04X\"
1054 style=\"%s\">"
1055                      code
1056                      chise-wiki-glyph-cgi-url
1057                      code
1058                      www-format-char-img-style)
1059              t 'literal))
1060
1061           (goto-char (point-min))
1062           (while (re-search-forward "&RUI6-\\([0-9A-F]+\\);" nil t)
1063             (setq code (string-to-int (match-string 1) 16))
1064             (replace-match
1065              (format "<img alt=\"RUI6-%04X\" src=\"%s?char=RUI6-%04X\"
1066 style=\"vertical-align:middle\">"
1067                      code
1068                      chise-wiki-glyph-cgi-url
1069                      code
1070                      www-format-char-img-style)
1071              t 'literal))
1072
1073           (goto-char (point-min))
1074           (while (re-search-forward "&hanaJU\\+\\([0-9A-F]+\\);" nil t)
1075             (setq code (string-to-int (match-string 1) 16))
1076             (replace-match
1077              (format "<img alt=\"hanaJU+%04X\" src=\"%s?char=hana-JU+%04X\"
1078 style=\"vertical-align:middle\">"
1079                      code
1080                      chise-wiki-glyph-cgi-url
1081                      code
1082                      www-format-char-img-style)
1083              t 'literal))
1084
1085           (goto-char (point-min))
1086           (while (re-search-forward "&\\(A-\\|G-\\|g2-\\|R-\\)?\\(UU\\+\\|U-\\)\\([0-9A-F]+\\);" nil t)
1087             (setq code (string-to-int (match-string 3) 16))
1088             (replace-match
1089              (format "<img alt=\"UU+%04X\" src=\"http://www.unicode.org/cgi-bin/refglyph?24-%04X\"
1090 style=\"vertical-align:middle\">"
1091                      code
1092                      code
1093                      www-format-char-img-style)
1094              t 'literal))
1095
1096           (goto-char (point-min))
1097           (while (re-search-forward "&MCS-\\([0-9A-F]+\\);" nil t)
1098             (setq code (string-to-int (match-string 1) 16))
1099             (setq start (match-beginning 0)
1100                   end (match-end 0))
1101             (setq char (decode-char 'system-char-id code))
1102             (cond
1103              ((and (setq variants
1104                          (or (www-get-feature-value char '->subsumptive)
1105                              (www-get-feature-value char '->denotational)))
1106                    (progn
1107                      (while (and variants
1108                                  (setq ret (www-format-encode-string
1109                                             (char-to-string (car variants))))
1110                                  (string-match "&MCS-\\([0-9A-F]+\\);" ret))
1111                        (setq variants (cdr variants)))
1112                      ret))
1113               (unless (string-match "&MCS-\\([0-9A-F]+\\);" ret)
1114                 (goto-char start)
1115                 (delete-region start end)
1116                 (insert ret))
1117               )
1118              ((setq ret (or (www-get-feature-value char 'ideographic-combination)
1119                             (www-get-feature-value char 'ideographic-structure)))
1120               (setq ret
1121                     (mapconcat
1122                      (lambda (ch)
1123                        (if (listp ch)
1124                            (if (characterp (setq rret (find-char ch)))
1125                                (setq ch rret)))
1126                        (if (characterp ch)
1127                            (www-format-encode-string
1128                             (char-to-string ch) without-tags)
1129                          (www-format-encode-string
1130                           (format "%S" ch) without-tags)))
1131                      ret ""))
1132               (when ret
1133                 (goto-char start)
1134                 (delete-region start end)
1135                 (insert ret))
1136               )))
1137           ))
1138       ;; (goto-char (point-min))
1139       ;; (while (search-forward "&GT-" nil t)
1140       ;;   (replace-match "&amp;GT-" t 'literal))
1141       (buffer-string))))
1142
1143 (defun www-html-display-text (text)
1144   (princ
1145    (with-temp-buffer
1146      (insert text)
1147      (goto-char (point-min))
1148      (while (search-forward "<" nil t)
1149        (replace-match "&lt;" nil t))
1150      (goto-char (point-min))
1151      (while (search-forward ">" nil t)
1152        (replace-match "&gt;" nil t))
1153      (goto-char (point-min))
1154      (while (re-search-forward "\\[\\[\\([^]|[]+\\)|\\([^][]+\\)\\]\\]" nil t)
1155        (replace-match
1156         (format "<a href=\"%s\">%s</a>"
1157                 (match-string 2)
1158                 (match-string 1))
1159         nil t))
1160      (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
1161      (goto-char (point-min))
1162      (while (search-forward "&GT-" nil t)
1163        (replace-match "&amp;GT-" nil t))
1164      (buffer-string))))
1165
1166 (defun www-html-display-paragraph (text)
1167   (princ "<p>")
1168   (www-html-display-text text)
1169   (princ "</p>\n"))
1170
1171
1172 ;;; @ for GlyphWiki
1173 ;;;
1174
1175 (defvar coded-charset-GlyphWiki-id-alist
1176   '((=ucs-var-001       "u"     4 x "-var-001")
1177     (=ucs-var-002       "u"     4 x "-var-002")
1178     (=ucs-var-003       "u"     4 x "-var-003")
1179     (=ucs-itaiji-001    "u"     4 x "-itaiji-001")
1180     (=ucs-itaiji-002    "u"     4 x "-itaiji-002")
1181     (=ucs-itaiji-084    "u"     4 x "-itaiji-084")
1182     (=ucs               "u"     4 x nil)
1183     (=adobe-japan1-0    "aj1-"  5 d nil)
1184     (=adobe-japan1-1    "aj1-"  5 d nil)
1185     (=adobe-japan1-2    "aj1-"  5 d nil)
1186     (=adobe-japan1-3    "aj1-"  5 d nil)
1187     (=adobe-japan1-4    "aj1-"  5 d nil)
1188     (=adobe-japan1-5    "aj1-"  5 d nil)
1189     (=adobe-japan1-6    "aj1-"  5 d nil)
1190     (==adobe-japan1-0   "aj1-"  5 d nil)
1191     (==adobe-japan1-1   "aj1-"  5 d nil)
1192     (==adobe-japan1-2   "aj1-"  5 d nil)
1193     (==adobe-japan1-3   "aj1-"  5 d nil)
1194     (==adobe-japan1-4   "aj1-"  5 d nil)
1195     (==adobe-japan1-5   "aj1-"  5 d nil)
1196     (==adobe-japan1-6   "aj1-"  5 d nil)
1197     (===adobe-japan1-0  "aj1-"  5 d nil)
1198     (===adobe-japan1-1  "aj1-"  5 d nil)
1199     (===adobe-japan1-2  "aj1-"  5 d nil)
1200     (===adobe-japan1-3  "aj1-"  5 d nil)
1201     (===adobe-japan1-4  "aj1-"  5 d nil)
1202     (===adobe-japan1-5  "aj1-"  5 d nil)
1203     (===adobe-japan1-6  "aj1-"  5 d nil)
1204     (=decomposition@cid)
1205     (=decomposition@hanyo-denshi)
1206     (=hanyo-denshi/ks   "koseki-" 6 d nil)
1207     (=>>hanyo-denshi/ks "koseki-" 6 d nil)
1208     (=ucs@jis           "u"     4 x nil)
1209     (==ucs@jis          "u"     4 x nil)
1210     (==ucs@iso          "u"     4 x nil)
1211     (===ucs@jis         "u"     4 x nil)
1212     (=ucs@cns           "u"     4 x "-t")
1213     (==ucs@cns          "u"     4 x "-t")
1214     (=jis-x0212         "jsp-"  4 x nil)
1215     (=jis-x0213-1@2000  "jx1-2000-" 4 x nil)
1216     (=jis-x0213-1@2004  "jx1-2004-" 4 x nil)
1217     (=jis-x0213-2       "jx2-"  4 x nil)
1218     (=gt                "gt-"   5 d nil)
1219     (=daikanwa          "dkw-"  5 d nil)
1220     (==daikanwa         "dkw-"  5 d nil)
1221     (===daikanwa        "dkw-"  5 d nil)
1222     (=gt-k              "gt-k"  5 d nil)
1223     (=jef-china3        "jc3-"  4 x nil)
1224     (=big5              "b-"    4 x nil)
1225     (=ucs@ks            "u"     4 x "-k")
1226     (==ucs@ks           "u"     4 x "-k")
1227     (===ucs@ks          "u"     4 x "-k")
1228     (=ks-x1001          "k0-"   4 x nil)
1229     (=jis-x0208@1978/1pr "j78-" 4 x nil)
1230     (=jis-x0208@1978/-4pr "j78-" 4 x nil)
1231     (=jis-x0208@1978    "j78-"  4 x nil)
1232     (=>>>jis-x0208@1978 "j78-"  4 x nil)
1233     (=>>jis-x0208@1978  "j78-"  4 x nil)
1234     (=+>jis-x0208@1978  "j78-"  4 x nil)
1235     (=ucs@JP            "u"     4 x nil)
1236     (=ucs@gb            "u"     4 x "-g")
1237     (=ucs@iso           "u"     4 x "-u")
1238     (=ucs@unicode       "u"     4 x "-us")
1239     (=big5-cdp          "cdp-"  4 x nil)
1240     (=>>big5-cdp        "cdp-"  4 x nil)
1241     (=cns11643-1        "c1-"   4 x nil)
1242     (=cns11643-2        "c2-"   4 x nil)
1243     (=cns11643-3        "c3-"   4 x nil)
1244     (=cns11643-4        "c4-"   4 x nil)
1245     (=cns11643-5        "c5-"   4 x nil)
1246     (=cns11643-6        "c6-"   4 x nil)
1247     (=cns11643-7        "c7-"   4 x nil)
1248     (=jis-x0208         "j90-"  4 x nil)
1249     (=>>>jis-x0208      "j90-"  4 x nil)
1250     (=>>jis-x0208       "j90-"  4 x nil)
1251     (=+>jis-x0208       "j90-"  4 x nil)
1252     (=jis-x0208@1990    "j90-"  4 x nil)
1253     (=>>>jis-x0208@1990 "j90-"  4 x nil)
1254     (=>>jis-x0208@1990  "j90-"  4 x nil)
1255     (=+>jis-x0208@1990  "j90-"  4 x nil)
1256     (=jis-x0208@1983    "j83-"  4 x nil)
1257     (=>>>jis-x0208@1983 "j83-"  4 x nil)
1258     (=>>jis-x0208@1983  "j83-"  4 x nil)
1259     (=+>jis-x0208@1983  "j83-"  4 x nil)
1260     (=cbeta             "cb"    5 d nil)
1261     (=>>daikanwa        "dkw-"  5 d nil)
1262     (=big5-cdp-var-3    "cdp-"  4 x "-var-3")
1263     (=big5-cdp-var-5    "cdp-"  4 x "-var-5")
1264     ))
1265
1266 (defun char-GlyphWiki-id (char)
1267   (let ((rest coded-charset-GlyphWiki-id-alist)
1268         spec ret code)
1269     (while (and rest
1270                 (setq spec (pop rest))
1271                 (null (setq ret (char-feature char (car spec))))))
1272     (when ret
1273       (or
1274        (and (listp ret)
1275             (mapconcat #'char-GlyphWiki-id ret "-"))
1276        (and (memq (car spec) '(=ucs@unicode '=ucs@iso))
1277             (cond
1278              ((and (or (encode-char char '=jis-x0208@1990)
1279                        (encode-char char '=jis-x0212)
1280                        (encode-char char '=jis-x0213-1)
1281                        (encode-char char '=jis-x0213-2))
1282                    (setq code (encode-char char '=ucs@jis)))
1283               (format "u%04x" code)
1284               )
1285              ((and (or (encode-char char '=gb2312)
1286                        (encode-char char '=gb12345))
1287                    (setq code (encode-char char '=ucs@gb)))
1288               (format "u%04x-g" code)
1289               )
1290              ((and (or (encode-char char '=cns11643-1)
1291                        (encode-char char '=cns11643-2)
1292                        (encode-char char '=cns11643-3)
1293                        (encode-char char '=cns11643-4)
1294                        (encode-char char '=cns11643-5)
1295                        (encode-char char '=cns11643-6)
1296                        (encode-char char '=cns11643-7))
1297                    (setq code (encode-char char '=ucs@cns)))
1298               (format "u%04x-t" code)
1299               )
1300              ((and (encode-char char '=ks-x1001)
1301                    (setq code (encode-char char '=ucs@ks)))
1302               (format "u%04x-k" code)
1303               )))
1304        (format (format "%s%%0%d%s%s"
1305                        (nth 1 spec)
1306                        (nth 2 spec)
1307                        (nth 3 spec)
1308                        (or (nth 4 spec) ""))
1309                ret)))))
1310
1311
1312 ;;; @ End.
1313 ;;;
1314
1315 (provide 'cwiki-common)
1316
1317 ;;; cwiki-common.el ends here