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