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