Mount `=hdic-syp-entry-id' and `hdic-syp-description'.
[chise/est.git] / cwiki-common.el
1 ;; -*- coding: utf-8-mcs-er -*-
2 (require 'char-db-util)
3 (require 'chiset-common)
4 ;; (require 'concord-images)
5
6 (setq file-name-coding-system 'utf-8-mcs-er)
7
8 (concord-assign-genre 'code-point "/usr/local/var/chise-ipld/db")
9 (concord-assign-genre 'coded-character "/usr/local/var/chise-ipld/db")
10 (concord-assign-genre 'glyph "/usr/local/var/chise-ipld/db")
11
12 (concord-assign-genre 'image-resource "/usr/local/var/photo/db")
13 (concord-assign-genre 'glyph-image "/usr/local/var/photo/db")
14
15 (concord-assign-genre 'creator@ruimoku "/usr/local/var/ruimoku/db")
16 (concord-assign-genre 'person-name@ruimoku "/usr/local/var/ruimoku/db")
17
18 (concord-assign-genre 'journal-volume@ruimoku "/usr/local/var/ruimoku/db")
19 (concord-assign-genre 'article@ruimoku "/usr/local/var/ruimoku/db")
20 (concord-assign-genre 'book@ruimoku "/usr/local/var/ruimoku/db")
21
22 (concord-assign-genre 'classification@ruimoku "/usr/local/var/ruimoku/db")
23 (concord-assign-genre 'region@ruimoku "/usr/local/var/ruimoku/db")
24 (concord-assign-genre 'era@ruimoku "/usr/local/var/ruimoku/db")
25 (concord-assign-genre 'period@ruimoku "/usr/local/var/ruimoku/db")
26 (concord-assign-genre 'journal@ruimoku "/usr/local/var/ruimoku/db")
27 (concord-assign-genre 'journal-name@ruimoku "/usr/local/var/ruimoku/db")
28 (concord-assign-genre 'publisher@ruimoku "/usr/local/var/ruimoku/db")
29 (concord-assign-genre 'publisher-name@ruimoku "/usr/local/var/ruimoku/db")
30
31 (mount-char-attribute-table '*instance@ruimoku/bibliography/title)
32 ;; (mount-char-attribute-table '*instance@ruimoku/bibliography/content*note)
33
34 (concord-assign-genre 'entry@zh-classical "/usr/local/var/kanbun/db")
35 ;; (concord-assign-genre 'morpheme-entry@zh-classical "/usr/local/var/kanbun/db")
36 (concord-assign-genre 'word-class@zh-classical "/usr/local/var/kanbun/db")
37 (concord-assign-genre 'morpheme@zh-classical "/usr/local/var/kanbun/db")
38 (concord-assign-genre 'sentence@zh-classical "/usr/local/var/kanbun/db")
39 ;; (concord-assign-genre 'sentence-entry@zh-classical "/usr/local/var/kanbun/db")
40
41 (mount-char-attribute-table '*instance@morpheme-entry/zh-classical)
42
43 (concord-assign-genre 'ud@zh-classical "/usr/local/var/kanbun/db")
44
45
46 (concord-assign-genre 'hng-card "/usr/local/var/hng-card/db")
47
48 (mount-char-attribute-table '->HNG)
49 (mount-char-attribute-table '<-HNG)
50 (mount-char-attribute-table '->HNG@CN/manuscript)
51 (mount-char-attribute-table '<-HNG@CN/manuscript)
52 (mount-char-attribute-table '->HNG@CN/printed)
53 (mount-char-attribute-table '<-HNG@CN/printed)
54 (mount-char-attribute-table '->HNG@JP/manuscript)
55 (mount-char-attribute-table '<-HNG@JP/manuscript)
56 (mount-char-attribute-table '->HNG@JP/printed)
57 (mount-char-attribute-table '<-HNG@JP/printed)
58 (mount-char-attribute-table '->HNG@KR)
59 (mount-char-attribute-table '<-HNG@KR)
60 (mount-char-attribute-table '->HNG@MISC)
61 (mount-char-attribute-table '<-HNG@MISC)
62
63 (mount-char-attribute-table 'abstract-glyph@iwds-1)
64 (mount-char-attribute-table 'abstract-glyph@iwds-1/confluented)
65
66 (mount-char-attribute-table '=hdic-tsj-entry-id)
67 (mount-char-attribute-table '=hdic-tsj-glyph-id)
68 (mount-char-attribute-table '=hdic-syp-entry-id)
69 (mount-char-attribute-table 'hdic-syp-description)
70
71 (defvar est-hide-cgi-mode nil)
72 (defvar est-view-url-prefix "..")
73 (defvar chise-wiki-view-url "view.cgi")
74 (defvar chise-wiki-edit-url "edit.cgi")
75
76 (defvar chise-wiki-bitmap-glyph-image-url
77   "https://image.chise.org/glyphs")
78
79 (defvar chise-wiki-legacy-bitmap-glyphs-url
80   "https://www.chise.org/glyphs")
81
82 (defvar chise-wiki-hng-bitmap-glyphs-url
83   "https://image.hng-data.org/glyphs/HNG")
84
85 (defvar chise-wiki-daijiten-bitmap-glyphs-url
86   "https://image.hng-data.org/glyphs/daijiten")
87
88 (defvar chise-wiki-glyphwiki-glyph-image-url
89   "https://glyphwiki.org/glyph")
90
91 (defvar chise-wiki-glyph-cgi-url
92   "https://www.chise.org/chisewiki/glyph.cgi")
93
94 (defvar chise-wiki-displayed-features nil)
95
96 (defvar est-coded-charset-priority-list
97   '(; =ucs
98     =cns11643-1 =cns11643-2 =cns11643-3
99     =cns11643-4 =cns11643-5 =cns11643-6 =cns11643-7
100     =gb2312 =gb12345
101     =jis-x0208 =jis-x0208@1990
102     =jis-x0213-2
103     =jis-x0212
104     =adobe-japan1
105     =cbeta =jef-china3
106     =jis-x0213-1@2000 =jis-x0213-1@2004
107     =jis-x0208@1983 =jis-x0208@1978
108     =zinbun-oracle =>zinbun-oracle
109     =daikanwa
110     =gt =gt-k
111     ==adobe-japan1
112     ==jis-x0208 ==jis-x0213-1 ==jis-x0213-2
113     =>>jis-x0208 =>>jis-x0213-1 =>>jis-x0213-2
114     =>>adobe-japan1
115     =+>jis-x0208 =+>jis-x0213-1 =+>jis-x0213-2
116     =+>jis-x0208@1978
117     =+>adobe-japan1
118     =>jis-x0208 =>jis-x0213-1
119     =>>gt
120     =>ucs@iso =>ucs@unicode
121     =>ucs@jis =>ucs@cns =>ucs@ks
122     =+>ucs@iso =+>ucs@unicode
123     =>>ucs@iso =>>ucs@unicode
124     =>>ucs@jis =>>ucs@cns =>>ucs@ks
125     ==ucs@iso ==ucs@unicode
126     ==ucs@jis ==ucs@cns ==ucs@ks
127     ===ucs@iso
128     =ruimoku-v6
129     =big5
130     =big5-cdp
131     =>cbeta
132     =mj
133     ==mj
134     ===mj
135     =ucs-itaiji-001
136     =ucs-itaiji-002
137     =ucs-itaiji-003
138     =ucs-itaiji-004
139     =ucs-itaiji-005
140     =ucs-itaiji-006
141     =ucs-itaiji-007
142     =ucs-itaiji-008
143     =ucs-itaiji-009
144     =ucs-itaiji-010
145     =ucs-itaiji-011
146     =ucs-itaiji-084
147     =ucs-var-001
148     =ucs-var-002
149     =ucs-var-003
150     =ucs-var-004
151     =ucs-var-010
152     =ucs@unicode
153     ==ucs@unicode
154     ===ucs@unicode
155     ==>daijiten
156     ==>ucs@bucs
157     ===daikanwa/+p
158     ===gt
159     =>ucs@iwds-1
160     =>ucs@component
161     =>ucs@cognate
162     =>ucs-itaiji-001
163     =>ucs-itaiji-002
164     =>ucs-itaiji-003
165     =>ucs-itaiji-004
166     =>ucs-itaiji-005
167     =>ucs-itaiji-006
168     =>ucs-itaiji-007
169     =>ucs-itaiji-008
170     ===adobe-japan1
171     ===cns11643-1 ===cns11643-2 ===cns11643-3
172     ===cns11643-4 ===cns11643-5 ===cns11643-6 ===cns11643-7
173     ))
174
175 (defvar est-coded-charset-entity-reference-alist
176   (list*
177    '(=gt                        "GT-"           5 d)
178    '(=mj                        "MJ"            6 d)
179    '(=hanyo-denshi/ja           "HD-JA-"        4 X)
180    '(=hanyo-denshi/jb           "HD-JB-"        4 X)
181    '(=hanyo-denshi/jc           "HD-JC-"        4 X)
182    '(=hanyo-denshi/jd           "HD-JD-"        4 X)
183    '(=hanyo-denshi/ft           "HD-FT-"        4 X)
184    '(=hanyo-denshi/ia           "HD-IA-"        4 X)
185    '(=hanyo-denshi/ib           "HD-IB-"        4 X)
186    '(=hanyo-denshi/hg           "HD-HG-"        4 X)
187    '(=hanyo-denshi/ip           "HD-IP-"        4 X)
188    '(=hanyo-denshi/jt           "HD-JT-"        4 X)
189    '(=hanyo-denshi/ks           "HD-KS-"        6 d)
190    '(=>>hanyo-denshi/ja       "G-HD-JA-"        4 X)
191    '(=>>hanyo-denshi/jb       "G-HD-JB-"        4 X)
192    '(=>>hanyo-denshi/jc       "G-HD-JC-"        4 X)
193    '(=>>hanyo-denshi/jd       "G-HD-JD-"        4 X)
194    '(=>>hanyo-denshi/ft       "G-HD-FT-"        4 X)
195    '(=>>hanyo-denshi/ia       "G-HD-IA-"        4 X)
196    '(=>>hanyo-denshi/ib       "G-HD-IB-"        4 X)
197    '(=>>hanyo-denshi/hg       "G-HD-HG-"        4 X)
198    '(=>>hanyo-denshi/ip       "G-HD-IP-"        4 X)
199    '(=>>hanyo-denshi/jt       "G-HD-JT-"        4 X)
200    '(=>>hanyo-denshi/ks       "G-HD-KS-"        6 d)
201    '(==mj                    "g2-MJ"            6 d)
202    '(==hanyo-denshi/ja       "g2-HD-JA-"        4 X)
203    '(==hanyo-denshi/jb       "g2-HD-JB-"        4 X)
204    '(==hanyo-denshi/jc       "g2-HD-JC-"        4 X)
205    '(==hanyo-denshi/jd       "g2-HD-JD-"        4 X)
206    '(==hanyo-denshi/ft       "g2-HD-FT-"        4 X)
207    '(==hanyo-denshi/ia       "g2-HD-IA-"        4 X)
208    '(==hanyo-denshi/ib       "g2-HD-IB-"        4 X)
209    '(==hanyo-denshi/hg       "g2-HD-HG-"        4 X)
210    '(==hanyo-denshi/ip       "g2-HD-IP-"        4 X)
211    '(==hanyo-denshi/jt       "g2-HD-JT-"        4 X)
212    '(==hanyo-denshi/ks       "g2-HD-KS-"        6 d)
213    '(==daijiten              "g2-DJT-"          5 d)
214    '(=cns11643-1                "C1-"           4 X)
215    '(=cns11643-2                "C2-"           4 X)
216    '(=cns11643-3                "C3-"           4 X)
217    '(=cns11643-4                "C4-"           4 X)
218    '(=cns11643-5                "C5-"           4 X)
219    '(=cns11643-6                "C6-"           4 X)
220    '(=cns11643-7                "C7-"           4 X)
221    '(=adobe-japan1-6           "AJ1-"           5 d)
222    '(=big5-cdp                 "CDP-"           4 X)
223    '(=>big5-cdp              "A-CDP-"           4 X)
224    '(=gb2312                   "G0-"            4 X)
225    '(=gb12345                  "G1-"            4 X)
226    '(=jis-x0208@1990           "J90-"           4 X)
227    '(=jis-x0212                "JSP-"           4 X)
228    '(=cbeta                    "CB"             5 d)
229    '(=jis-x0208@1997           "J97-"           4 X)
230    '(=jis-x0208@1978           "J78-"           4 X)
231    '(=jis-x0208@1983           "J83-"           4 X)
232    '(=ruimoku-v6               "RUI6-"          4 X)
233    '(=zinbun-oracle            "ZOB-"           4 d)
234    '(=daijiten                 "DJT-"           5 d)
235    '(=>ucs-itaiji-001        "A-U-i001+"        4 X)
236    '(=>ucs-itaiji-002        "A-U-i002+"        4 X)
237    '(=>ucs-itaiji-003        "A-U-i003+"        4 X)
238    '(=>ucs-itaiji-004        "A-U-i004+"        4 X)
239    '(=>ucs-itaiji-005        "A-U-i005+"        4 X)
240    '(=>ucs-itaiji-006        "A-U-i006+"        4 X)
241    '(=>ucs-itaiji-007        "A-U-i007+"        4 X)
242    '(=>ucs-itaiji-008        "A-U-i008+"        4 X)
243    '(=>ucs-itaiji-009        "A-U-i009+"        4 X)
244    '(=>ucs-itaiji-010        "A-U-i010+"        4 X)
245    '(=>ucs-itaiji-011        "A-U-i011+"        4 X)
246    '(=>ucs-itaiji-001@iwds-1 "A-IWDSU-i001+"    4 X)
247    '(=>ucs-itaiji-002@iwds-1 "A-IWDSU-i002+"    4 X)
248    '(=>ucs-itaiji-003@iwds-1 "A-IWDSU-i003+"    4 X)
249    '(=>ucs-itaiji-006@iwds-1 "A-IWDSU-i006+"    4 X)
250    '(=jef-china3               "JC3-"           4 X)
251    '(=ucs@unicode              "UU+"            4 X)
252    '(=ucs@JP/hanazono          "hanaJU+"        4 X)
253    '(==cns11643-1            "R-C1-"            4 X)
254    '(==cns11643-2            "R-C2-"            4 X)
255    '(==cns11643-3            "R-C3-"            4 X)
256    '(==cns11643-4            "R-C4-"            4 X)
257    '(==cns11643-5            "R-C5-"            4 X)
258    '(==cns11643-6            "R-C6-"            4 X)
259    '(==cns11643-7            "R-C7-"            4 X)
260    '(=hanziku-1                "HZK01-"         4 X)
261    '(=hanziku-2                "HZK02-"         4 X)
262    '(=hanziku-3                "HZK03-"         4 X)
263    '(=hanziku-4                "HZK04-"         4 X)
264    '(=hanziku-5                "HZK05-"         4 X)
265    '(=hanziku-6                "HZK06-"         4 X)
266    '(=hanziku-7                "HZK07-"         4 X)
267    '(=hanziku-8                "HZK08-"         4 X)
268    '(=hanziku-9                "HZK09-"         4 X)
269    '(=hanziku-10               "HZK10-"         4 X)
270    '(=hanziku-11               "HZK11-"         4 X)
271    '(=hanziku-12               "HZK12-"         4 X)
272    '(==>daijiten            "A2-DJT-"           5 d)
273    '(==cbeta                   "CB"             5 d)
274    '(=big5                     "B-"             4 X)
275    '(=daikanwa                 "M-"             5 d)
276    '(=>>daikanwa             "G-M-"             5 d)
277    '(===ucs@ks               "R-KU+"            4 X)
278    coded-charset-entity-reference-alist))
279
280 (defun decode-uri-string (string &optional coding-system)
281   (if (> (length string) 0)
282       (let ((i 0)
283             dest)
284         (setq string
285               (mapconcat (lambda (char)
286                            (if (eq char ?+)
287                                " "
288                              (char-to-string char)))
289                          string ""))
290         (while (string-match "%\\([0-9A-F][0-9A-F]\\)" string i)
291           (setq dest (concat dest
292                              (substring string i (match-beginning 0))
293                              (char-to-string
294                               (int-char
295                                (string-to-int (match-string 1 string) 16))))
296                 i (match-end 0)))
297         (decode-coding-string
298          (concat dest (substring string i))
299          coding-system))))
300
301 (defun www-feature-type (feature-name)
302   (or (char-feature-property feature-name 'type)
303       (let ((str (symbol-name feature-name)))
304         (cond
305          ((string-match "\\*note\\(@[^*]+\\)?$" str)
306           'stext)
307          ((string-match "\\*sources\\(@[^*]+\\)?$" str)
308           'domain-list)
309          ((string-match "\\*" str)
310           nil)
311          ((string-match "^\\(->\\|<-\\)" str)
312           'relation)
313          ((string-match "^ideographic-structure\\(@\\|$\\)" str)
314           'structure)
315          ))))
316
317 (defun www-feature-format (feature-name)
318   (or (char-feature-property feature-name 'presentation-format)
319       (char-feature-property feature-name 'format)
320       (let (fn parent ret)
321         (setq fn feature-name)
322         (while (and (setq parent (char-feature-name-parent fn))
323                     (null (setq ret
324                                 (char-feature-property
325                                  parent 'format))))
326           (setq fn parent))
327         ret)
328       '((name) " : " (value))))
329
330 (defun www-feature-value-format (feature-name)
331   (or (char-feature-property feature-name 'value-presentation-format)
332       (char-feature-property feature-name 'value-format)
333       (let (fn parent ret)
334         (setq fn feature-name)
335         (while (and (setq parent (char-feature-name-parent fn))
336                     (null (setq ret
337                                 (or (char-feature-property
338                                      parent 'value-presentation-format)
339                                     (char-feature-property
340                                      parent 'value-format)))))
341           (setq fn parent))
342         ret)
343       (let ((type (www-feature-type feature-name)))
344         (cond ((eq type 'relation)
345                'space-separated)
346               ((eq type 'structure)
347                'space-separated-ids)
348               ((eq type 'stext)
349                'wiki-text)
350               ))
351       (if (find-charset feature-name)
352           (if (and (= (charset-dimension feature-name) 2)
353                    (= (charset-chars feature-name) 94))
354               '("0x" (HEX)
355                 " (" (decimal) ") <" (ku-ten) "> " (prev-char) (next-char))
356             '("0x" (HEX) " (" (decimal) ") " (prev-char) (next-char))))
357       'space-separated))
358
359 (defun char-feature-name-at-domain (feature-name domain)
360   (if domain
361       (let ((name (symbol-name feature-name)))
362         (cond
363          ((string-match "@[^*]+$" name)
364           (intern (format "%s/%s" name domain))
365           )
366          (t
367           (intern (format "%s@%s" name domain))
368           )))
369     feature-name))
370
371 (defun char-feature-name-parent (feature-name)
372   (let ((name (symbol-name feature-name)))
373     (if (string-match "@[^@/*]+\\(/[^@/*]+\\)*$" name)
374         (intern (substring name 0 (car (last (match-data) 2)))))))
375
376 (defun char-feature-name-domain (feature-name)
377   (let ((name (symbol-name feature-name)))
378     (if (string-match "@[^@/*]+\\(/[^@/*]+\\)*$" name)
379         (intern (substring name (1+ (match-beginning 0)))))))
380
381 (defun char-feature-name-sans-versions (feature)
382   (let ((feature-name (symbol-name feature)))
383     (if (string-match "[@/]\\$rev=latest$" feature-name)
384         (intern (substring feature-name 0 (match-beginning 0)))
385       feature)))
386
387 (defun est-object-genre (object)
388   (if (characterp object)
389       'character
390     (concord-object-genre object)))
391
392 (defun www-get-feature-value (object feature)
393   (let ((latest-feature (char-feature-name-at-domain feature '$rev=latest)))
394     (cond
395      ((characterp object)
396       (mount-char-attribute-table latest-feature)
397       (or (char-feature object latest-feature)
398           (char-feature object feature))
399       )
400      (t
401       (or (condition-case nil
402               (concord-object-get object latest-feature)
403             (error nil))
404           (condition-case nil
405               (concord-object-get object feature)
406             (error nil)))
407       ))))
408
409 (defun get-previous-code-point (ccs code)
410   (let ((chars (charset-chars ccs))
411         (dim (charset-dimension ccs))
412         (i 0)
413         mask byte-min byte-max
414         bytes dest)
415     (cond
416      ((= chars 94)
417       (setq mask #x7F
418             byte-min 33
419             byte-max 126)
420       )
421      ((= chars 96)
422       (setq mask #x7F
423             byte-min 32
424             byte-max 127)
425       )
426      ((= chars 128)
427       (setq mask #x7F
428             byte-min 0
429             byte-max #xFF)
430       )
431      (t ; (= chars 256)
432       (setq mask #xFF
433             byte-min 0
434             byte-max #xFF)
435       ))
436     (setq bytes (make-vector dim 0))
437     (while (< i dim)
438       (aset bytes i (logand (lsh code (* i -8)) mask))
439       (setq i (1+ i)))
440     (setq i 0)
441     (while (and (< i dim)
442                 (progn
443                   (aset bytes i (1- (aref bytes i)))
444                   (< (aref bytes i) byte-min)))
445       (aset bytes i byte-max)
446       (setq i (1+ i)))
447     (when (< i dim)
448       (setq dest (aref bytes 0)
449             i 1)
450       (while (< i dim)
451         (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
452               i (1+ i)))
453       dest)))
454
455 (defun get-next-code-point (ccs code)
456   (let ((chars (charset-chars ccs))
457         (dim (charset-dimension ccs))
458         (i 0)
459         mask byte-min byte-max
460         bytes dest)
461     (cond
462      ((= chars 94)
463       (setq mask #x7F
464             byte-min 33
465             byte-max 126)
466       )
467      ((= chars 96)
468       (setq mask #x7F
469             byte-min 32
470             byte-max 127)
471       )
472      ((= chars 128)
473       (setq mask #x7F
474             byte-min 0
475             byte-max #xFF)
476       )
477      (t ; (= chars 256)
478       (setq mask #xFF
479             byte-min 0
480             byte-max #xFF)
481       ))
482     (setq bytes (make-vector dim 0))
483     (while (< i dim)
484       (aset bytes i (logand (lsh code (* i -8)) mask))
485       (setq i (1+ i)))
486     (setq i 0)
487     (while (and (< i dim)
488                 (progn
489                   (aset bytes i (1+ (aref bytes i)))
490                   (> (aref bytes i) byte-max)))
491       (aset bytes i byte-min)
492       (setq i (1+ i)))
493     (when (< i dim)
494       (setq dest (aref bytes 0)
495             i 1)
496       (while (< i dim)
497         (setq dest (logior dest (lsh (aref bytes i) (* i 8)))
498               i (1+ i)))
499       dest)))
500
501 (defun find-previous-defined-code-point (ccs code)
502   (let ((i (get-previous-code-point ccs code))
503         char)
504     (cond
505      ((eq ccs '=jis-x0208)
506       (setq ccs '=jis-x0208@1990))
507      ((eq ccs '=jis-x0213-1)
508       (setq ccs '=jis-x0213-1@2004)))
509     (while (and i
510                 (>= i 0)
511                 (null (setq char (decode-char ccs i
512                                               (unless (eq ccs '=ucs)
513                                                 'defined-only)))))
514       (setq i (get-previous-code-point ccs i)))
515     char))
516
517 (defun find-next-defined-code-point (ccs code)
518   (let ((i (get-next-code-point ccs code))
519         max char)
520     (setq max (+ code 1000))
521     (cond
522      ((eq ccs '=jis-x0208)
523       (setq ccs '=jis-x0208@1990))
524      ((eq ccs '=jis-x0213-1)
525       (setq ccs '=jis-x0213-1@2004)))
526     (while (and i
527                 (<= i max)
528                 (null (setq char (decode-char ccs i
529                                               (unless (eq ccs '=ucs)
530                                                 'defined-only)))))
531       (setq i (get-next-code-point ccs i)))
532     char))
533
534
535 ;;; @ URI representation
536 ;;;
537
538 ;; (defun est-uri-decode-feature-name-body (uri-feature)
539 ;;   (let ((len (length uri-feature))
540 ;;         (i 0)
541 ;;         ch dest)
542 ;;     (while (< i len)
543 ;;       (setq dest
544 ;;             (concat
545 ;;              dest
546 ;;              (if (eq (aref uri-feature i) ?\.)
547 ;;                  (if (and (< (+ i 2) len)
548 ;;                           (eq (aref uri-feature (+ i 2)) ?\.))
549 ;;                      (prog1
550 ;;                          (cond
551 ;;                           ((eq (setq ch (aref uri-feature (1+ i))) ?\.)
552 ;;                            "/")
553 ;;                           ((eq ch ?-)
554 ;;                            "*")
555 ;;                           ((eq ch ?_)
556 ;;                            "+")
557 ;;                           (t
558 ;;                            (substring uri-feature i (+ i 3))
559 ;;                            ))
560 ;;                        (setq i (+ i 3)))
561 ;;                    (setq i (1+ i))
562 ;;                    ".")
563 ;;                (prog1
564 ;;                    (char-to-string (aref uri-feature i))
565 ;;                  (setq i (1+ i)))))))
566 ;;     dest))
567
568 ;; (defun est-uri-encode-feature-name-body (feature)
569 ;;   (mapconcat (lambda (c)
570 ;;                (cond ((eq c ?*)
571 ;;                       ".-.")
572 ;;                      ((eq c ?/)
573 ;;                       "...")
574 ;;                      ((eq c ?+)
575 ;;                       "._.")
576 ;;                      (t (char-to-string c))))
577 ;;              feature ""))
578
579 ;; (defun www-uri-decode-feature-name (uri-feature)
580 ;;   (let (feature)
581 ;;     (setq uri-feature (decode-uri-string uri-feature 'utf-8-mcs-er))
582 ;;     (cond
583 ;;      ((string-match "^from\\." uri-feature)
584 ;;       (intern (format "<-%s"
585 ;;                       (est-uri-decode-feature-name-body
586 ;;                        (substring uri-feature (match-end 0)))))
587 ;;       )
588 ;;      ((string-match "^to\\." uri-feature)
589 ;;       (intern (format "->%s"
590 ;;                       (est-uri-decode-feature-name-body
591 ;;                        (substring uri-feature (match-end 0)))))
592 ;;       )
593 ;;      ((string-match "^rep\\." uri-feature)
594 ;;       (intern (format "=%s"
595 ;;                       (est-uri-decode-feature-name-body
596 ;;                        (substring uri-feature (match-end 0)))))
597 ;;       )
598 ;;      ((string-match "^rep[2i]\\." uri-feature)
599 ;;       (intern (format "===%s"
600 ;;                       (est-uri-decode-feature-name-body
601 ;;                        (substring uri-feature (match-end 0)))))
602 ;;       )
603 ;;      ((string-match "^g\\." uri-feature)
604 ;;       (intern (format "=>>%s"
605 ;;                       (est-uri-decode-feature-name-body
606 ;;                        (substring uri-feature (match-end 0)))))
607 ;;       )
608 ;;      ((string-match "^g[i2]\\." uri-feature)
609 ;;       (intern (format "==%s"
610 ;;                       (est-uri-decode-feature-name-body
611 ;;                        (substring uri-feature (match-end 0)))))
612 ;;       )
613 ;;      ((string-match "^gi\\([0-9]+\\)\\." uri-feature)
614 ;;       (intern (format "=>>%s%s"
615 ;;                       (make-string (string-to-int
616 ;;                                     (match-string 1 uri-feature))
617 ;;                                    ?>)
618 ;;                       (est-uri-decode-feature-name-body
619 ;;                        (substring uri-feature (match-end 0)))))
620 ;;       )
621 ;;      ((string-match "^o\\." uri-feature)
622 ;;       (intern (format "=+>%s"
623 ;;                       (est-uri-decode-feature-name-body
624 ;;                        (substring uri-feature (match-end 0)))))
625 ;;       )
626 ;;      ((string-match "^a\\." uri-feature)
627 ;;       (intern (format "=>%s"
628 ;;                       (est-uri-decode-feature-name-body
629 ;;                        (substring uri-feature (match-end 0)))))
630 ;;       )
631 ;;      ((string-match "^a\\([0-9]+\\)\\." uri-feature)
632 ;;       (intern (format "%s>%s"
633 ;;                       (make-string (string-to-int
634 ;;                                     (match-string 1 uri-feature))
635 ;;                                    ?=)
636 ;;                       (est-uri-decode-feature-name-body
637 ;;                        (substring uri-feature (match-end 0)))))
638 ;;       )
639 ;;      ((and (setq uri-feature (est-uri-decode-feature-name-body uri-feature))
640 ;;            (setq feature (intern (format "=>%s" uri-feature)))
641 ;;            (find-charset feature))
642 ;;       feature)
643 ;;      ((and (setq feature (intern (format "=>>%s" uri-feature)))
644 ;;            (find-charset feature))
645 ;;       feature)
646 ;;      ((and (setq feature (intern (format "=>>>%s" uri-feature)))
647 ;;            (find-charset feature))
648 ;;       feature)
649 ;;      ((and (setq feature (intern (format "=%s" uri-feature)))
650 ;;            (find-charset feature))
651 ;;       feature)
652 ;;      (t (intern uri-feature)))))
653
654 ;; (defun www-uri-encode-feature-name (feature-name)
655 ;;   (setq feature-name (symbol-name feature-name))
656 ;;   (cond
657 ;;    ((string-match "^=\\+>\\([^=>]+\\)" feature-name)
658 ;;     (concat "o."
659 ;;             (est-uri-encode-feature-name-body
660 ;;              (substring feature-name (match-beginning 1))))
661 ;;     )
662 ;;    ((string-match "^=\\([^=>]+\\)" feature-name)
663 ;;     (concat "rep."
664 ;;             (est-uri-encode-feature-name-body
665 ;;              (substring feature-name (match-beginning 1))))
666 ;;     )
667 ;;    ((string-match "^==\\([^=>]+\\)" feature-name)
668 ;;     (concat "g2."
669 ;;             (est-uri-encode-feature-name-body
670 ;;              (substring feature-name (match-beginning 1))))
671 ;;     )
672 ;;    ((string-match "^===\\([^=>]+\\)" feature-name)
673 ;;     (concat "repi."
674 ;;             (est-uri-encode-feature-name-body
675 ;;              (substring feature-name (match-beginning 1))))
676 ;;     )
677 ;;    ((string-match "^=>>\\([^=>]+\\)" feature-name)
678 ;;     (concat "g."
679 ;;             (est-uri-encode-feature-name-body
680 ;;              (substring feature-name (match-beginning 1))))
681 ;;     )
682 ;;    ((string-match "^=>>>\\([^=>]+\\)" feature-name)
683 ;;     (concat "gi."
684 ;;             (est-uri-encode-feature-name-body
685 ;;              (substring feature-name (match-beginning 1))))
686 ;;     )
687 ;;    ((string-match "^=>>\\(>+\\)" feature-name)
688 ;;     (format "gi%d.%s"
689 ;;             (length (match-string 1 feature-name))
690 ;;             (est-uri-encode-feature-name-body
691 ;;              (substring feature-name (match-end 1))))
692 ;;     )
693 ;;    ((string-match "^=>\\([^=>]+\\)" feature-name)
694 ;;     (concat "a."
695 ;;             (est-uri-encode-feature-name-body
696 ;;              (substring feature-name (match-beginning 1))))
697 ;;     )
698 ;;    ((string-match "^\\(=+\\)>" feature-name)
699 ;;     (format "a%d.%s"
700 ;;             (length (match-string 1 feature-name))
701 ;;             (est-uri-encode-feature-name-body
702 ;;              (substring feature-name (match-end 0))))
703 ;;     )
704 ;;    ((string-match "^->" feature-name)
705 ;;     (concat "to."
706 ;;             (est-uri-encode-feature-name-body
707 ;;              (substring feature-name (match-end 0))))
708 ;;     )
709 ;;    ((string-match "^<-" feature-name)
710 ;;     (concat "from."
711 ;;             (est-uri-encode-feature-name-body
712 ;;              (substring feature-name (match-end 0))))
713 ;;     )
714 ;;    (t (est-uri-encode-feature-name-body feature-name))))
715
716 (defun www-uri-make-feature-name-url (uri-genre uri-feature-name uri-object)
717   (if est-hide-cgi-mode
718       (format "../feature/%s&%s/%s"
719               uri-feature-name uri-genre uri-object)
720     (format "%s?feature=%s&%s=%s"
721             chise-wiki-view-url uri-feature-name uri-genre uri-object)))
722
723 (defun www-uri-decode-object (genre char-rep)
724   (let (ccs cpos)
725     (cond
726      ((string-match (if est-hide-cgi-mode
727                         "\\(%3D\\|=\\|%3A\\|:\\)"
728                       "\\(%3A\\|:\\)") char-rep)
729       (setq ccs (substring char-rep 0 (match-beginning 0))
730             cpos (substring char-rep (match-end 0)))
731       (setq ccs (www-uri-decode-feature-name ccs))
732       (setq cpos (est-uri-decode-feature-name-body cpos))
733       (cond
734        ((string-match "^0x" cpos)
735         (setq cpos
736               (string-to-number (substring cpos (match-end 0)) 16))
737         )
738        (t
739         (setq cpos (car (read-from-string
740                          (decode-uri-string
741                           cpos file-name-coding-system))))
742         ))
743       (if (and (eq genre 'character)
744                (numberp cpos))
745           (decode-char ccs cpos)
746         (concord-decode-object ccs cpos genre))
747       )
748      (t
749       (setq char-rep (decode-uri-string char-rep 'utf-8-mcs-er))
750       (cond
751        ((eq genre 'character)
752         (when (= (length char-rep) 1)
753           (aref char-rep 0))
754         )
755        ((eq genre 'feature)
756         (concord-decode-object
757          '=id (www-uri-decode-feature-name char-rep) 'feature)
758         )
759        (t
760         (concord-decode-object
761          '=id (car (read-from-string char-rep)) genre)
762         ))))))
763
764 (defun www-uri-encode-object (object)
765   (if (characterp object)
766       (if (encode-char object '=ucs)
767           (mapconcat
768            (lambda (byte)
769              (format "%%%02X" byte))
770            (encode-coding-string (char-to-string object) 'utf-8-mcs-er)
771            "")
772         (let ((ccs-list est-coded-charset-priority-list)
773               ccs ret)
774           (while (and ccs-list
775                       (setq ccs (pop ccs-list))
776                       (not (setq ret (encode-char object ccs 'defined-only)))))
777           (cond (ret
778                  (format (if est-hide-cgi-mode
779                              "%s=0x%X"
780                            "%s:0x%X")
781                          (www-uri-encode-feature-name ccs)
782                          ret))
783                 ((and (setq ccs (car (split-char object)))
784                       (setq ret (encode-char object ccs)))
785                  (format (if est-hide-cgi-mode
786                              "%s=0x%X"
787                            "%s:0x%X")
788                          (www-uri-encode-feature-name ccs)
789                          ret))
790                 (t
791                  (format (if est-hide-cgi-mode
792                              "system-char-id=0x%X"
793                            "system-char-id:0x%X")
794                          (encode-char object 'system-char-id))
795                  ))))
796     (format (if est-hide-cgi-mode
797                 "rep.id=%s"
798               "rep.id:%s")
799             (www-uri-encode-feature-name
800              (concord-object-id object)))))
801
802 (defun est-format-object (object &optional readable)
803   (if (characterp object)
804       (char-to-string object)
805     (let ((ret (or (if readable
806                        (or (concord-object-get object 'name)
807                            (concord-object-get object '=name)
808                            (concord-object-get object 'title)))
809                    (concord-object-id object))))
810       (format "%s" ret))))
811
812 (defun www-uri-make-object-url (object &optional uri-object)
813   (if est-hide-cgi-mode
814       (format "%s/%s/%s"
815               est-view-url-prefix
816               (est-object-genre object)
817               (or uri-object
818                   (www-uri-encode-object object)))
819     (format "%s?%s=%s"
820             chise-wiki-view-url
821             (est-object-genre object)
822             (or uri-object
823                 (www-uri-encode-object object)))))
824
825
826 ;;; @ Feature name presentation
827 ;;;
828
829 (defun www-format-feature-name-default (feature-name)
830   (mapconcat
831    #'capitalize
832    (split-string
833     (symbol-name feature-name)
834     "-")
835    " "))
836
837 (defun www-format-feature-name-as-metadata (feature-name &optional lang)
838   (let ((str (symbol-name feature-name))
839         base meta)
840     (cond
841      ((string-match "\\*[^*]+$" str)
842       (setq base (substring str 0 (match-beginning 0))
843             meta (substring str (match-beginning 0)))
844       (concat (www-format-feature-name* (intern base) lang)
845               meta))
846      (t
847       (www-format-feature-name-default feature-name)
848       ))))
849
850 (defun www-format-feature-name-as-rel-to (feature-name)
851   (concat "\u2192" (substring (symbol-name feature-name) 2)))
852
853 (defun www-format-feature-name-as-rel-from (feature-name)
854   (concat "\u2190" (substring (symbol-name feature-name) 2)))
855
856 (defun www-format-feature-name-as-CCS (feature-name)
857   (let* ((rest
858           (split-string
859            (symbol-name feature-name)
860            "-"))
861          (dest (upcase (pop rest))))
862     (when (string-match "^=+>*" dest)
863       (setq dest (concat (substring dest 0 (match-end 0))
864                          " "
865                          (substring dest (match-end 0)))))
866     (cond
867      (rest
868       (while (cdr rest)
869         (setq dest (concat dest " " (upcase (pop rest)))))
870       (if (string-match "^[0-9]+$" (car rest))
871           (concat dest "-" (car rest))
872         (concat dest " " (upcase (car rest))))
873       )
874      (t dest))))
875
876 (defun www-format-feature-name* (feature-name &optional lang)
877   (let (name fn parent ret)
878     (cond
879      ((or (and lang
880                (char-feature-property
881                 feature-name
882                 (intern (format "name@%s" lang))))
883           (char-feature-property
884            feature-name 'name)))
885      ((and (setq name (symbol-name feature-name))
886            (string-match "\\*" name))
887       (www-format-feature-name-as-metadata feature-name lang))
888      (t
889       (setq fn feature-name)
890       (while (and (setq parent (char-feature-name-parent fn))
891                   (null (setq ret
892                               (or (and lang
893                                        (char-feature-property
894                                         parent
895                                         (intern (format "name@%s" lang))))
896                                   (char-feature-property
897                                    parent 'name)))))
898         (setq fn parent))
899       (cond
900        (ret
901         (concat ret (substring (symbol-name feature-name)
902                                (length (symbol-name parent)))))
903        ((find-charset feature-name)
904         (www-format-feature-name-as-CCS feature-name))
905        ((string-match "^\\(->\\)" name)
906         (www-format-feature-name-as-rel-to feature-name))
907        ((string-match "^\\(<-\\)" name)
908         (www-format-feature-name-as-rel-from feature-name))
909        (t
910         (www-format-feature-name-default feature-name)
911         ))
912       ))))
913
914 (defun www-format-feature-name (feature-name &optional lang)
915   (www-format-encode-string
916    (www-format-feature-name* feature-name lang)))
917
918
919 ;;; @ HTML generator
920 ;;;
921
922 (defvar www-format-char-img-style "vertical-align:bottom;")
923
924 (defun www-format-encode-string (string &optional without-tags as-body)
925   (with-temp-buffer
926     (insert string)
927     (let (plane code subcode start end char variants ret rret)
928       (when as-body
929         (goto-char (point-min))
930         (while (search-forward "&" nil t)
931           (replace-match "&amp;" nil t)))
932       (goto-char (point-min))
933       (while (search-forward "<" nil t)
934         (replace-match "&lt;" nil t))
935       (goto-char (point-min))
936       (while (search-forward ">" nil t)
937         (replace-match "&gt;" nil t))
938       (if without-tags
939           (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
940         (let ((coded-charset-entity-reference-alist
941                est-coded-charset-entity-reference-alist))
942           (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
943
944           (goto-char (point-min))
945           (while (re-search-forward "&\\(A-\\|G-\\|g2-\\|R-\\)?CB\\([0-9]+\\);" nil t)
946             (setq code (string-to-int (match-string 2)))
947             (replace-match
948              (format "<img alt=\"CB%05d\" src=\"%s/cb-gaiji/%02d/CB%05d.gif\"
949 style=\"%s\">"
950                      code
951                      chise-wiki-legacy-bitmap-glyphs-url
952                      (/ code 1000) code
953                      www-format-char-img-style)
954              t 'literal))
955
956           (goto-char (point-min))
957           (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)
958             (setq plane (match-string 2)
959                   code (string-to-int (match-string 3) 16))
960             (replace-match
961              (format "<img alt=\"J%s-%04X\" src=\"%s/JIS-%s/%02d-%02d.gif\"
962 style=\"%s\">"
963                      plane code
964                      chise-wiki-legacy-bitmap-glyphs-url
965                      plane
966                      (- (lsh code -8) 32)
967                      (- (logand code 255) 32)
968                      www-format-char-img-style)
969              t 'literal))
970
971           (goto-char (point-min))
972           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?J0-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
973             (setq code (string-to-int (match-string 2) 16))
974             (replace-match
975              (format "<img alt=\"J0-%04X\" src=\"%s/JIS-90/%02d-%02d.gif\"
976 style=\"%s\">"
977                      code
978                      chise-wiki-legacy-bitmap-glyphs-url
979                      (- (lsh code -8) 32)
980                      (- (logand code 255) 32)
981                      www-format-char-img-style)
982              t 'literal))
983
984           (goto-char (point-min))
985           (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)
986             (setq plane (match-string 2)
987                   code (string-to-int (match-string 3) 16))
988             (replace-match
989              (format "<img alt=\"HD-%s-%04X\" src=\"%s/IVD/HanyoDenshi/%s%02d%02d.png\"
990 style=\"%s\">"
991                      plane code
992                      chise-wiki-legacy-bitmap-glyphs-url
993                      plane
994                      (- (lsh code -8) 32)
995                      (- (logand code 255) 32)
996                      www-format-char-img-style)
997              t 'literal))
998
999           (goto-char (point-min))
1000           (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)
1001             (setq plane (match-string 2)
1002                   code (string-to-int (match-string 3) 16))
1003             (replace-match
1004              (format "<img alt=\"HD-%s-%04X\" src=\"%s/IVD/HanyoDenshi/%s%04X.png\"
1005 style=\"%s\">"
1006                      plane code
1007                      chise-wiki-legacy-bitmap-glyphs-url
1008                      plane code
1009                      www-format-char-img-style)
1010              t 'literal))
1011
1012           (goto-char (point-min))
1013           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?HD-KS-\\([0-9]+\\);" nil t)
1014             (setq code (string-to-int (match-string 2)))
1015             (replace-match
1016              (format "<img alt=\"HD-KS%06d\" src=\"%s/IVD/HanyoDenshi/KS%06d.png\"
1017 style=\"vertical-align:middle\">"
1018                      code
1019                      chise-wiki-legacy-bitmap-glyphs-url
1020                      code
1021                      www-format-char-img-style)
1022              t 'literal))
1023
1024           (goto-char (point-min))
1025           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?HD-TK-\\([0-9]+\\);" nil t)
1026             (setq code (string-to-int (match-string 2)))
1027             (replace-match
1028              (format "<img alt=\"HD-KS%06d\" src=\"%s/IVD/HanyoDenshi/TK%08d.png\"
1029 style=\"vertical-align:middle\">"
1030                      code
1031                      chise-wiki-legacy-bitmap-glyphs-url
1032                      code
1033                      www-format-char-img-style)
1034              t 'literal))
1035
1036           (goto-char (point-min))
1037           (while (re-search-forward "&G\\([01]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
1038             (setq plane (string-to-int (match-string 1))
1039                   code (string-to-int (match-string 2) 16))
1040             (replace-match
1041              (format "<img alt=\"GB%d-%04X\" src=\"%s/GB%d/%02d-%02d.gif\"
1042 style=\"%s\">"
1043                      plane code
1044                      chise-wiki-legacy-bitmap-glyphs-url
1045                      plane
1046                      (- (lsh code -8) 32)
1047                      (- (logand code 255) 32)
1048                      www-format-char-img-style)
1049              t 'literal))
1050
1051           (goto-char (point-min))
1052           (while (re-search-forward "&\\(R-\\)?C\\([1-7]\\)-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
1053             (setq plane (string-to-int (match-string 2))
1054                   code (string-to-int (match-string 3) 16))
1055             (replace-match
1056              (format "<img alt=\"CNS%d-%04X\" src=\"%s/CNS%d/%04X.gif\"
1057 style=\"%s\">"
1058                      plane code
1059                      chise-wiki-legacy-bitmap-glyphs-url
1060                      plane code
1061                      www-format-char-img-style)
1062              t 'literal))
1063
1064           (goto-char (point-min))
1065           (while (re-search-forward "&\\(R-\\)?JC3-\\([0-9A-F][0-9A-F][0-9A-F][0-9A-F]\\);" nil t)
1066             (setq code (string-to-int (match-string 2) 16))
1067             (replace-match
1068              (format "<img alt=\"JC3-%04X\" src=\"%s/JEF-CHINA3/%04X.png\">"
1069                      code chise-wiki-bitmap-glyph-image-url code)
1070              t 'literal))
1071
1072           (goto-char (point-min))
1073           (while (re-search-forward "&\\(A-\\)?ZOB-\\([0-9]+\\);" nil t)
1074             (setq code (string-to-int (match-string 2)))
1075             (replace-match
1076              (format "<img alt=\"ZOB-%04d\" src=\"%s/ZOB-1968/%04d.png\"
1077 style=\"vertical-align:middle\">"
1078                      code
1079                      chise-wiki-legacy-bitmap-glyphs-url
1080                      code
1081                      www-format-char-img-style)
1082              t 'literal))
1083
1084           (goto-char (point-min))
1085           (while (re-search-forward "&\\(A2-\\|g2-\\|R-\\)?DJT-\\([0-9]+\\);" nil t)
1086             (setq code (string-to-int (match-string 2)))
1087             (replace-match
1088              (format "<img alt=\"DJT-%05d\" src=\"%s/%05d.png\"
1089 style=\"vertical-align:middle; width: auto; max-height: 60px\">"
1090                      code
1091                      chise-wiki-daijiten-bitmap-glyphs-url
1092                      code
1093                      www-format-char-img-style)
1094              t 'literal))
1095
1096           (goto-char (point-min))
1097           (while (re-search-forward "&SW-JIGUGE\\([45]?\\)-\\([0-9]+\\);" nil t)
1098             (setq subcode (match-string 1)
1099                   code (string-to-int (match-string 2)))
1100             (setq plane
1101                   (if (string= subcode "")
1102                       "5"
1103                     subcode))
1104             (replace-match
1105              (format "<div class=\"tooltip\"><img alt=\"SW-JIGUGE%s-%05d\" src=\"%s/ShuoWen/Jiguge%s/%05d.png\"
1106 style=\"vertical-align:middle; width: auto; max-height: 80px\"><span
1107 class=\"tooltiptext\">%s</span></div>"
1108                      plane code
1109                      chise-wiki-legacy-bitmap-glyphs-url
1110                      plane code
1111                      (charset-description
1112                       (if (string= subcode "")
1113                           '=shuowen-jiguge
1114                         (intern (format "===shuowen-jiguge%s" subcode)))))
1115              t 'literal))
1116
1117           (goto-char (point-min))
1118           (while (re-search-forward "&HNG\\([0-9]+\\)-\\([0-9][0-9][0-9][0-9]\\)\\([0-9]\\);" nil t)
1119             (setq plane (match-string 1)
1120                   code (string-to-int (match-string 2))
1121                   subcode (string-to-int (match-string 3)))
1122             (setq subcode
1123                   (if (eq subcode 0)
1124                       ""
1125                     (char-to-string (decode-char 'ascii (+ 96 subcode)))))
1126             (replace-match
1127              (format
1128               "<div class=\"tooltip\"><img alt=\"HNG%s-%04d%s\" src=\"%s/%s/%04d%s.png\" style=\"
1129 vertical-align:middle; width: auto; max-height: 60px\"><span
1130 class=\"tooltiptext\">%s</span></div>"
1131               plane code subcode
1132               chise-wiki-hng-bitmap-glyphs-url
1133               plane code subcode
1134               (charset-description
1135                (car (find (format "HNG%s-" plane)
1136                           coded-charset-entity-reference-alist
1137                           :test (lambda (key cell)
1138                                   (string= key (nth 1 cell))))))
1139               )
1140              t 'literal))
1141
1142           (goto-char (point-min))
1143           (while (re-search-forward "&\\(R-\\)?CHISE-HDIC-TSJ\\([0-9A-F]+\\);" nil t)
1144             (setq code (string-to-int (match-string 2) 16))
1145             (setq char (decode-char '===chise-hdic-tsj code))
1146             (when (setq ret (get-char-attribute char '=hdic-tsj-glyph-id))
1147               (replace-match
1148                (format
1149                 "<div class=\"tooltip\"><img alt=\"HDIC-TSJ-%s\" src=\"https://viewer.hdic.jp/img/tsj/%s.jpg\" style=\"
1150 vertical-align:middle; width: auto; max-height: 60px\"><span
1151 class=\"tooltiptext\">%s</span></div>"
1152                 ret ret
1153                 (charset-description '===chise-hdic-tsj))
1154                t 'literal)))
1155
1156           (goto-char (point-min))
1157           (while (re-search-forward "&\\(R-\\)?CHISE-HDIC-SYP\\([0-9A-F]+\\);" nil t)
1158             (setq code (string-to-int (match-string 2) 16))
1159             (setq char (decode-char '===chise-hdic-syp code))
1160             (when (setq ret (get-char-attribute char '=hdic-syp-entry-id))
1161               (replace-match
1162                (format
1163                 "<div class=\"tooltip\"><img alt=\"HDIC-SYP-%s\" src=\"https://viewer.hdic.jp/img/syp/%s\" style=\"
1164 vertical-align:middle; width: auto; max-height: 60px\"><span
1165 class=\"tooltiptext\">%s</span></div>"
1166                 ret ret
1167                 (charset-description '===chise-hdic-syp))
1168                t 'literal)))
1169
1170           (goto-char (point-min))
1171           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?AJ1-\\([0-9]+\\);" nil t)
1172             (setq code (string-to-int (match-string 2)))
1173             (replace-match
1174              (format "<img alt=\"AJ1-%05d\" src=\"%s/IVD/AdobeJapan1/CID+%d.png\"
1175 style=\"vertical-align:middle\">"
1176                      code
1177                      chise-wiki-legacy-bitmap-glyphs-url
1178                      code
1179                      www-format-char-img-style)
1180              t 'literal))
1181
1182           (goto-char (point-min))
1183           (while (re-search-forward "&\\(A-\\|o-\\|G-\\|g2-\\|R-\\)?MJ\\([0-9]+\\);" nil t)
1184             (setq code (string-to-int (match-string 2)))
1185             (replace-match
1186              (format "<img alt=\"MJ%06d\" src=\"https://moji.or.jp/mojikibansearch/img/MJ/MJ%06d.png\"
1187 style=\"vertical-align:middle; width: 48px; height: 48px\">"
1188                      code
1189                      code
1190                      www-format-char-img-style)
1191              t 'literal))
1192
1193           (goto-char (point-min))
1194           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\)?IU[+-]\\([0-9A-F]+\\);" nil t)
1195             (setq code (string-to-int (match-string 2) 16))
1196             (replace-match
1197              (format "<img alt=\"u%04x\" src=\"%s/u%04x.svg\"
1198 style=\"vertical-align:middle; width: 48px; height: 48px\">"
1199                      code
1200                      chise-wiki-glyphwiki-glyph-image-url
1201                      code
1202                      www-format-char-img-style)
1203              t 'literal))
1204
1205           (goto-char (point-min))
1206           (while (re-search-forward "&\\(o-\\|G-\\|g2-\\|R-\\)?KU[+-]\\([0-9A-F]+\\);" nil t)
1207             (setq code (string-to-int (match-string 2) 16))
1208             (replace-match
1209              (format "<img alt=\"u%04x-k\" src=\"%s/u%04x-k.svg\"
1210 style=\"vertical-align:middle; width: 48px; height: 48px\">"
1211                      code
1212                      chise-wiki-glyphwiki-glyph-image-url
1213                      code
1214                      www-format-char-img-style)
1215              t 'literal))
1216
1217           (goto-char (point-min))
1218           (while (re-search-forward "&A-\\(comp\\|cgn\\)U[+-]\\([0-9A-F]+\\);" nil t)
1219             (setq code (string-to-int (match-string 2) 16))
1220             (replace-match
1221              (format "<img alt=\"u%04x\" src=\"%s/u%04x.svg\"
1222 style=\"vertical-align:middle; width: 48px; height: 48px\">"
1223                      code
1224                      chise-wiki-glyphwiki-glyph-image-url
1225                      code
1226                      www-format-char-img-style)
1227              t 'literal))
1228
1229           (goto-char (point-min))
1230           (while (re-search-forward
1231                   "&\\(A-\\|g2-\\)?\\(IWDS\\)?U-i\\([0-9]+\\)\\+\\([0-9A-F]+\\);"
1232                   nil t)
1233             (setq plane (string-to-int (match-string 3))
1234                   code (string-to-int (match-string 4) 16))
1235             (replace-match
1236              (format "<img alt=\"u%04x-itaiji-%03d\" src=\"%s/u%04x-itaiji-%03d.svg\"
1237 style=\"vertical-align:middle; width: 48px; height: 48px\">"
1238                      code
1239                      plane
1240                      chise-wiki-glyphwiki-glyph-image-url
1241                      code
1242                      plane
1243                      www-format-char-img-style)
1244              t 'literal))
1245
1246           (goto-char (point-min))
1247           (while (re-search-forward "&A-IWDSU\\+\\([0-9A-F]+\\);" nil t)
1248             (setq code (string-to-int (match-string 1) 16))
1249             (replace-match
1250              (format "<img alt=\"A-IWDSU+%04x\" src=\"%s/u%04x.svg\"
1251 style=\"vertical-align:middle; width: 48px; height: 48px\">"
1252                      code
1253                      chise-wiki-glyphwiki-glyph-image-url
1254                      code
1255                      www-format-char-img-style)
1256              t 'literal))
1257
1258           (goto-char (point-min))
1259           (while (re-search-forward
1260                   "&\\(A-\\)?CDP-i\\([0-9]+\\)-\\([0-9A-F]+\\);"
1261                   nil t)
1262             (setq plane (string-to-int (match-string 2))
1263                   code (string-to-int (match-string 3) 16))
1264             (replace-match
1265              (format "<img alt=\"cdp-%04x-itaiji-%03d\" src=\"%s/cdp-%04x-itaiji-%03d.svg\"
1266 style=\"vertical-align:middle; width: 48px; height: 48px\">"
1267                      code
1268                      plane
1269                      chise-wiki-glyphwiki-glyph-image-url
1270                      code
1271                      plane
1272                      www-format-char-img-style)
1273              t 'literal))
1274
1275           (goto-char (point-min))
1276           (while (re-search-forward
1277                   "&\\(A-\\)?CDP-v\\([0-9]+\\)-\\([0-9A-F]+\\);"
1278                   nil t)
1279             (setq plane (string-to-int (match-string 2))
1280                   code (string-to-int (match-string 3) 16))
1281             (replace-match
1282              (format "<img alt=\"cdp-%04x-var-%03d\" src=\"%s/cdp-%04x-var-%03d.svg\"
1283 style=\"vertical-align:middle; width: 48px; height: 48px\">"
1284                      code
1285                      plane
1286                      chise-wiki-glyphwiki-glyph-image-url
1287                      code
1288                      plane
1289                      www-format-char-img-style)
1290              t 'literal))
1291
1292           (goto-char (point-min))
1293           (while (re-search-forward
1294                   "&\\(A-\\|G-\\|g2-\\|R-\\)?M-\\([0-9]+\\);"
1295                   nil t)
1296             (setq code (string-to-int (match-string 2)))
1297             (replace-match
1298              (format "<img alt=\"dkw-%05d\" src=\"%s/dkw-%05d.svg\"
1299 style=\"vertical-align:middle; width: 48px; height: 48px\">"
1300                      code
1301                      chise-wiki-glyphwiki-glyph-image-url
1302                      code
1303                      www-format-char-img-style)
1304              t 'literal))
1305
1306           (goto-char (point-min))
1307           (while (re-search-forward "&\\(g2-\\)?U-v\\([0-9]+\\)\\+\\([0-9A-F]+\\);" nil t)
1308             (setq plane (string-to-int (match-string 2))
1309                   code (string-to-int (match-string 3) 16))
1310             (replace-match
1311              (format "<img alt=\"u%04x-var-%03d\" src=\"%s/u%04x-var-%03d.svg\"
1312 style=\"vertical-align:middle; width: 48px; height: 48px\">"
1313                      code
1314                      plane
1315                      chise-wiki-glyphwiki-glyph-image-url
1316                      code
1317                      plane
1318                      www-format-char-img-style)
1319              t 'literal))
1320
1321           (goto-char (point-min))
1322           (while (re-search-forward "&\\(A-\\|G-\\|R-\\|g2-\\)?GT-\\([0-9]+\\);" nil t)
1323             (setq code (string-to-int (match-string 2)))
1324             (replace-match
1325              (format "<img alt=\"GT-%05d\" src=\"%s?char=GT-%05d\"
1326 style=\"%s\">"
1327                      code
1328                      chise-wiki-glyph-cgi-url
1329                      code
1330                      www-format-char-img-style)
1331              t 'literal))
1332
1333           (goto-char (point-min))
1334           (while (re-search-forward "&\\(A-\\|G-\\|g2-\\)?GT-K\\([0-9]+\\);" nil t)
1335             (setq code (string-to-int (match-string 2)))
1336             (replace-match
1337              (format "<img alt=\"GT-K%05d\" src=\"%s?char=GT-K%05d\"
1338 style=\"%s\">"
1339                      code
1340                      chise-wiki-glyph-cgi-url
1341                      code
1342                      www-format-char-img-style)
1343              t 'literal))
1344
1345           (goto-char (point-min))
1346           (while (re-search-forward "&B-\\([0-9A-F]+\\);" nil t)
1347             (setq code (string-to-int (match-string 1) 16))
1348             (replace-match
1349              (format "<img alt=\"B-%04X\" src=\"%s?char=B-%04X\"
1350 style=\"%s\">"
1351                      code
1352                      chise-wiki-glyph-cgi-url
1353                      code
1354                      www-format-char-img-style)
1355              t 'literal))
1356
1357           (goto-char (point-min))
1358           (while (re-search-forward
1359                   "&\\(A-\\|G-\\|g2-\\|R-\\)?CDP-\\([0-9A-F]+\\);" nil t)
1360             (setq code (string-to-int (match-string 2) 16))
1361             (replace-match
1362              (format "<img alt=\"CDP-%04X\" src=\"%s?char=CDP-%04X\"
1363 style=\"%s\">"
1364                      code
1365                      chise-wiki-glyph-cgi-url
1366                      code
1367                      www-format-char-img-style)
1368              t 'literal))
1369
1370           (goto-char (point-min))
1371           (while (re-search-forward
1372                   "&\\(I-\\)?HZK\\(0[1-9]\\|1[0-2]\\)-\\([0-9A-F]+\\);" nil t)
1373             (setq plane (match-string 2)
1374                   code (string-to-int (match-string 3) 16))
1375             (replace-match
1376              (format "<img alt=\"HZK%s-%04X\" src=\"%s?char=HZK%s-%04X\"
1377 style=\"%s\">"
1378                      plane
1379                      code
1380                      chise-wiki-glyph-cgi-url
1381                      plane
1382                      code
1383                      www-format-char-img-style)
1384              t 'literal))
1385
1386           (goto-char (point-min))
1387           (while (re-search-forward "&\\(A-\\|G-\\|g2-\\|R-\\)?RUI6-\\([0-9A-F]+\\);" nil t)
1388             (setq code (string-to-int (match-string 2) 16))
1389             (replace-match
1390              (format "<img alt=\"RUI6-%04X\" src=\"%s?char=RUI6-%04X\"
1391 style=\"vertical-align:middle\">"
1392                      code
1393                      chise-wiki-glyph-cgi-url
1394                      code
1395                      www-format-char-img-style)
1396              t 'literal))
1397
1398           (goto-char (point-min))
1399           (while (re-search-forward "&hanaJU\\+\\([0-9A-F]+\\);" nil t)
1400             (setq code (string-to-int (match-string 1) 16))
1401             (replace-match
1402              (format "<img alt=\"hanaJU+%04X\" src=\"%s?char=hana-JU+%04X\"
1403 style=\"vertical-align:middle\">"
1404                      code
1405                      chise-wiki-glyph-cgi-url
1406                      code
1407                      www-format-char-img-style)
1408              t 'literal))
1409
1410           (goto-char (point-min))
1411           (while (re-search-forward "&\\(A-\\|G-\\|g2-\\|R-\\)?\\(UU\\+\\|U-\\)\\([0-9A-F]+\\);" nil t)
1412             (setq code (string-to-int (match-string 3) 16))
1413             (replace-match
1414              (format "<img alt=\"UU+%04X\" src=\"https://www.unicode.org/cgi-bin/refglyph?24-%04X\"
1415 style=\"vertical-align:middle\">"
1416                      code
1417                      code
1418                      www-format-char-img-style)
1419              t 'literal))
1420
1421           (goto-char (point-min))
1422           (while (re-search-forward "&MCS-\\([0-9A-F]+\\);" nil t)
1423             (setq code (string-to-int (match-string 1) 16))
1424             (setq start (match-beginning 0)
1425                   end (match-end 0))
1426             (setq char (decode-char 'system-char-id code))
1427             (cond
1428              ((and (setq variants
1429                          (or (www-get-feature-value char '->subsumptive)
1430                              (www-get-feature-value char '->denotational)))
1431                    (progn
1432                      (if (characterp variants)
1433                          (setq variants (list variants)))
1434                      (while (and variants
1435                                  (setq ret (www-format-encode-string
1436                                             (char-to-string (car variants))))
1437                                  (string-match "&MCS-\\([0-9A-F]+\\);" ret))
1438                        (setq variants (cdr variants)))
1439                      ret))
1440               (unless (string-match "&MCS-\\([0-9A-F]+\\);" ret)
1441                 (goto-char start)
1442                 (delete-region start end)
1443                 (insert ret))
1444               )
1445              ((setq ret (or (www-get-feature-value char 'ideographic-combination)
1446                             (www-get-feature-value char 'ideographic-structure)))
1447               (setq ret
1448                     (mapconcat
1449                      (lambda (ch)
1450                        (if (listp ch)
1451                            (if (characterp (setq rret (find-char ch)))
1452                                (setq ch rret)))
1453                        (if (characterp ch)
1454                            (www-format-encode-string
1455                             (char-to-string ch) without-tags)
1456                          (www-format-encode-string
1457                           (format "%S" ch) without-tags)))
1458                      ret ""))
1459               (when ret
1460                 (goto-char start)
1461                 (delete-region start end)
1462                 (insert ret))
1463               )))
1464           ))
1465       ;; (goto-char (point-min))
1466       ;; (while (search-forward "&GT-" nil t)
1467       ;;   (replace-match "&amp;GT-" t 'literal))
1468       (buffer-string))))
1469
1470 (defun www-html-display-text (text)
1471   (princ
1472    (with-temp-buffer
1473      (insert text)
1474      (goto-char (point-min))
1475      (while (search-forward "<" nil t)
1476        (replace-match "&lt;" nil t))
1477      (goto-char (point-min))
1478      (while (search-forward ">" nil t)
1479        (replace-match "&gt;" nil t))
1480      (goto-char (point-min))
1481      (while (re-search-forward "\\[\\[\\([^]|[]+\\)|\\([^][]+\\)\\]\\]" nil t)
1482        (replace-match
1483         (format "<a href=\"%s\">%s</a>"
1484                 (match-string 2)
1485                 (match-string 1))
1486         nil t))
1487      (encode-coding-region (point-min)(point-max) 'utf-8-mcs-er)
1488      (goto-char (point-min))
1489      (while (search-forward "&GT-" nil t)
1490        (replace-match "&amp;GT-" nil t))
1491      (buffer-string))))
1492
1493 (defun www-html-display-paragraph (text)
1494   (princ "<p>")
1495   (www-html-display-text text)
1496   (princ "</p>\n"))
1497
1498
1499 ;;; @ for GlyphWiki
1500 ;;;
1501
1502 (defvar coded-charset-GlyphWiki-id-alist
1503   '((===adobe-japan1-0  "aj1-"  5 d nil)
1504     (===adobe-japan1-1  "aj1-"  5 d nil)
1505     (===adobe-japan1-2  "aj1-"  5 d nil)
1506     (===adobe-japan1-3  "aj1-"  5 d nil)
1507     (===adobe-japan1-4  "aj1-"  5 d nil)
1508     (===adobe-japan1-5  "aj1-"  5 d nil)
1509     (===adobe-japan1-6  "aj1-"  5 d nil)
1510     (===mj              "jmj-"  6 d nil)
1511     (===ucs@jis         "u"     4 x "-j")
1512     (===daikanwa        "dkw-"  5 d nil)
1513     (===ucs@ks          "u"     4 x "-k")
1514     (===jis-x0208@1978  "j78-"  4 x nil)
1515     (==ucs-itaiji-005   "u"     4 x "-itaiji-005")
1516     (=ucs-var-001       "u"     4 x "-var-001")
1517     (=ucs-var-002       "u"     4 x "-var-002")
1518     (=ucs-var-003       "u"     4 x "-var-003")
1519     (=ucs-var-004       "u"     4 x "-var-004")
1520     (=ucs-var-006       "u"     4 x "-var-006")
1521     (=ucs-var-010       "u"     4 x "-var-010")
1522     (=ucs-itaiji-001    "u"     4 x "-itaiji-001")
1523     (=ucs-itaiji-002    "u"     4 x "-itaiji-002")
1524     (=ucs-itaiji-003    "u"     4 x "-itaiji-003")
1525     (=ucs-itaiji-004    "u"     4 x "-itaiji-004")
1526     (=ucs-itaiji-005    "u"     4 x "-itaiji-005")
1527     (=ucs-itaiji-006    "u"     4 x "-itaiji-006")
1528     (=ucs-itaiji-007    "u"     4 x "-itaiji-007")
1529     (=ucs-itaiji-008    "u"     4 x "-itaiji-008")
1530     (=ucs-itaiji-084    "u"     4 x "-itaiji-084")
1531     (=>ucs-itaiji-001   "u"     4 x "-itaiji-001")
1532     (=>ucs-itaiji-002   "u"     4 x "-itaiji-002")
1533     (=>ucs-itaiji-003   "u"     4 x "-itaiji-003")
1534     (=>ucs-itaiji-004   "u"     4 x "-itaiji-004")
1535     (=>ucs-itaiji-005   "u"     4 x "-itaiji-005")
1536     (=>ucs-itaiji-006   "u"     4 x "-itaiji-006")
1537     (=>ucs-itaiji-007   "u"     4 x "-itaiji-007")
1538     (=>ucs-itaiji-008   "u"     4 x "-itaiji-008")
1539     (==adobe-japan1-0   "aj1-"  5 d nil)
1540     (==adobe-japan1-1   "aj1-"  5 d nil)
1541     (==adobe-japan1-2   "aj1-"  5 d nil)
1542     (==adobe-japan1-3   "aj1-"  5 d nil)
1543     (==adobe-japan1-4   "aj1-"  5 d nil)
1544     (==adobe-japan1-5   "aj1-"  5 d nil)
1545     (==adobe-japan1-6   "aj1-"  5 d nil)
1546     (==mj               "jmj-"  6 d nil)
1547     (==ucs@jis          "u"     4 x "-j")
1548     (==ucs@iso          "u"     4 x nil)
1549     ;; (==ucs@cns          "u"     4 x "-t")
1550     (==ucs@unicode      "u"     4 x "-us")
1551     (==ucs@JP/hanazono  "u"     4 x "-jv")
1552     (==gt               "gt-"   5 d nil)
1553     (==gt-k             "gt-k"  5 d nil)
1554     (==daikanwa         "dkw-"  5 d nil)
1555     (==ucs@ks           "u"     4 x "-k")
1556     (==jis-x0208@1978   "j78-"  4 x nil)
1557     (==jis-x0208        "j90-"  4 x nil)
1558     (==jis-x0208@1990   "j90-"  4 x nil)
1559     (==jis-x0208@1983   "j83-"  4 x nil)
1560     (==cbeta           "cbeta-" 5 d nil)
1561     (=>>hanyo-denshi/ks "koseki-" 6 d nil)
1562     (=>>jis-x0208@1978  "j78-"  4 x nil)
1563     (=>>big5-cdp        "cdp-"  4 x nil)
1564     (=>>adobe-japan1-0  "aj1-"  5 d nil)
1565     (=>>adobe-japan1-1  "aj1-"  5 d nil)
1566     (=>>adobe-japan1-2  "aj1-"  5 d nil)
1567     (=>>adobe-japan1-3  "aj1-"  5 d nil)
1568     (=>>adobe-japan1-4  "aj1-"  5 d nil)
1569     (=>>adobe-japan1-5  "aj1-"  5 d nil)
1570     (=>>adobe-japan1-6  "aj1-"  5 d nil)
1571     (=>>jis-x0208       "j90-"  4 x nil)
1572     (=>>jis-x0208@1990  "j90-"  4 x nil)
1573     (=>>jis-x0208@1983  "j83-"  4 x nil)
1574     (=>>daikanwa        "dkw-"  5 d nil)
1575     (=adobe-japan1-0    "aj1-"  5 d nil)
1576     (=adobe-japan1-1    "aj1-"  5 d nil)
1577     (=adobe-japan1-2    "aj1-"  5 d nil)
1578     (=adobe-japan1-3    "aj1-"  5 d nil)
1579     (=adobe-japan1-4    "aj1-"  5 d nil)
1580     (=adobe-japan1-5    "aj1-"  5 d nil)
1581     (=adobe-japan1-6    "aj1-"  5 d nil)
1582     (=hanyo-denshi/ks   "koseki-" 6 d nil)
1583     (=mj                "jmj-"  6 d nil)
1584     (=decomposition@cid)
1585     (=decomposition@hanyo-denshi)
1586     (=koseki            "koseki-" 6 d nil)
1587     (=hanyo-denshi/tk   "toki-"   8 d nil)
1588     (=ucs@jis           "u"     4 x "-j")
1589     ;; (=ucs@cns           "u"     4 x "-t")
1590     (=ucs@ks            "u"     4 x "-k")
1591     (=ucs@JP            "u"     4 x "-jv")
1592     (=ucs@JP/hanazono   "u"     4 x "-jv")
1593     (=ucs@gb            "u"     4 x "-g")
1594     (=big5-cdp          "cdp-"  4 x nil)
1595     (=>big5-cdp         "cdp-"  4 x nil)
1596     (=+>big5-cdp        "cdp-"  4 x nil)
1597     (=>big5-cdp@iwds-1  "cdp-"  4 x nil)
1598     (=cbeta            "cbeta-" 5 d nil)
1599     (=>cbeta           "cbeta-" 5 d nil)
1600     (=big5-cdp-var-001  "cdp-"  4 x "-var-001")
1601     (=big5-cdp-var-003  "cdp-"  4 x "-var-003")
1602     (=big5-cdp-var-005  "cdp-"  4 x "-var-005")
1603     (=big5-cdp-itaiji-001 "cdp-" 4 x "-itaiji-001")
1604     (=big5-cdp-itaiji-002 "cdp-" 4 x "-itaiji-002")
1605     (=big5-cdp-itaiji-003 "cdp-" 4 x "-itaiji-003")
1606     (=>big5-cdp-itaiji-001 "cdp-" 4 x "-itaiji-001")
1607     (=>big5-cdp-itaiji-002 "cdp-" 4 x "-itaiji-002")
1608     (=>big5-cdp-itaiji-003 "cdp-" 4 x "-itaiji-003")
1609     (=jef-china3        "jc3-"  4 x nil)
1610     (=jis-x0212         "jsp-"  4 x nil)
1611     (=jis-x0213-1@2000  "jx1-2000-" 4 x nil)
1612     (=jis-x0213-1@2004  "jx1-2004-" 4 x nil)
1613     (=jis-x0213-2       "jx2-"  4 x nil)
1614     (=gt                "gt-"   5 d nil)
1615     (=gt-k              "gt-k"  5 d nil)
1616     (=>gt-k             "gt-k"  5 d nil)
1617     (=daikanwa          "dkw-"  5 d nil)
1618     (=ruimoku-v6        "rui6-" 4 x nil)
1619     (=>ruimoku-v6       "rui6-" 4 x nil)
1620     (=ucs@iso           "u"     4 x "-u")
1621     (=ucs@unicode       "u"     4 x "-us")
1622     (=jis-x0208@1978/1pr "j78-" 4 x nil)
1623     (=jis-x0208@1978/-4pr "j78-" 4 x nil)
1624     (=jis-x0208@1978    "j78-"  4 x nil)
1625     (=+>jis-x0208@1978  "j78-"  4 x nil)
1626     (=+>jis-x0208       "j90-"  4 x nil)
1627     (=+>jis-x0208@1990  "j90-"  4 x nil)
1628     (=+>jis-x0208@1983  "j83-"  4 x nil)
1629     (=ucs               "u"     4 x nil)
1630     (=big5              "b-"    4 x nil)
1631     (=ks-x1001          "k0-"   4 x nil)
1632     ;; (=cns11643-1        "c1-"   4 x nil)
1633     ;; (=cns11643-2        "c2-"   4 x nil)
1634     ;; (=cns11643-3        "c3-"   4 x nil)
1635     ;; (=cns11643-4        "c4-"   4 x nil)
1636     ;; (=cns11643-5        "c5-"   4 x nil)
1637     ;; (=cns11643-6        "c6-"   4 x nil)
1638     ;; (=cns11643-7        "c7-"   4 x nil)
1639     (=jis-x0208         "j90-"  4 x nil)
1640     (=jis-x0208@1990    "j90-"  4 x nil)
1641     (=jis-x0208@1983    "j83-"  4 x nil)
1642     ))
1643
1644 (defun char-GlyphWiki-id (char)
1645   (let ((rest coded-charset-GlyphWiki-id-alist)
1646         spec ret code)
1647     (while (and rest
1648                 (setq spec (pop rest))
1649                 (null (setq ret (get-char-attribute char (car spec))))))
1650     (when ret
1651       (or
1652        (and (listp ret)
1653             (mapconcat #'char-GlyphWiki-id ret "-"))
1654        (and (memq (car spec) '(=ucs@unicode '=ucs@iso))
1655             (cond
1656              ((and (or (encode-char char '=jis-x0208@1990)
1657                        (encode-char char '=jis-x0212)
1658                        (encode-char char '=jis-x0213-1)
1659                        (encode-char char '=jis-x0213-2))
1660                    (setq code (encode-char char '=ucs@jis)))
1661               (format "u%04x-j" code)
1662               )
1663              ((and (or (encode-char char '=gb2312)
1664                        (encode-char char '=gb12345))
1665                    (setq code (encode-char char '=ucs@gb)))
1666               (format "u%04x-g" code)
1667               )
1668              ;; ((and (or (encode-char char '=cns11643-1)
1669              ;;           (encode-char char '=cns11643-2)
1670              ;;           (encode-char char '=cns11643-3)
1671              ;;           (encode-char char '=cns11643-4)
1672              ;;           (encode-char char '=cns11643-5)
1673              ;;           (encode-char char '=cns11643-6)
1674              ;;           (encode-char char '=cns11643-7))
1675              ;;       (setq code (encode-char char '=ucs@cns)))
1676              ;;  (format "u%04x-t" code)
1677              ;;  )
1678              ((and (encode-char char '=ks-x1001)
1679                    (setq code (encode-char char '=ucs@ks)))
1680               (format "u%04x-k" code)
1681               )))
1682        (format (format "%s%%0%d%s%s"
1683                        (nth 1 spec)
1684                        (nth 2 spec)
1685                        (nth 3 spec)
1686                        (or (nth 4 spec) ""))
1687                ret)))))
1688
1689
1690 ;;; @ End.
1691 ;;;
1692
1693 (provide 'cwiki-common)
1694
1695 ;;; cwiki-common.el ends here