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