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