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