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