File: ZIPCODE-MK

package info (click to toggle)
skkdic 20011121-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 12,436 kB
  • ctags: 16
  • sloc: asm: 3,307; makefile: 158; sh: 82; awk: 27
file content (512 lines) | stat: -rw-r--r-- 13,423 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
;; -*- mode: emacs-lisp -*-
;; ZIPCODE-MK -- $BM9JXHV9f<-=q:n@.MQ%W%m%0%i%`(B

(require 'cl)

(set-language-environment "Japanese")
(require 'japan-util)

(defvar TEMP_ZIPCODE nil)
(defvar TEMP_OFFICE nil)

(defvar KEN_ALL nil)
(defvar JIGYOSYO nil)

(let ((vars '(TEMP_ZIPCODE TEMP_OFFICE KEN_ALL JIGYOSYO))
      (args (nthcdr 4 command-line-args-left)))
  (when args
    (while (not (stringp (car args)))
      (setq args (cdr args)))
    (while vars
      (set (car vars) (car args))
      (setq args (cdr args))
      (setq vars (cdr vars)))))

;(save-excursion
;  (set-buffer (get-buffer-create " *arere*"))
;  (insert (format "%s %s %s %s %s" TEMP_ZIPCODE TEMP_OFFICE KEN_ALL JIGYOSYO
;		  command-line-args-left))
;  (write-region (point-min) (point-max) "00arere"))

;; $B0lHLM9JXHV9fMQ(B
(defun mkdic-zipcode ()
  (let (*addr3* *addr4*
	*stat*)
    (set-buffer (get-buffer-create " *dic *"))
    (erase-buffer)
    ;;
    (set-buffer (get-buffer-create " *csv *"))
    (erase-buffer)
    ;;
    (insert-file-contents (expand-file-name KEN_ALL))
    ;;
    (goto-char (point-min))
    ;;
    (while (not (looking-at "^[0-9]"))
      (forward-line))
    ;;
    (mkdic-get-line)
    (while (eq (forward-line) 0)
      (mkdic-get-line))
    ;;
    (set-buffer " *dic *")
    (set-buffer-file-coding-system 'euc-jp-unix)
    (set-buffer-modified-p t)
    (goto-char (point-min))
    (insert ";; okuri-ari entries.
;; okuri-nasi entries.
")
    (write-region (point-min)
		  (point-max)
		  (expand-file-name TEMP_ZIPCODE)
		  nil
		  nil
		  nil)))

(defun mkdic-get-line ()
  (let ((i 0)
	zip
	addr1 addr2 addr3
	stat)
    (while (< i 9)
      (cond
       ((= i 2)
	(forward-char 1)
	(setq zip (buffer-substring (point)
				    (+ 7 (point)))))
       ((= i 6)
	(forward-char 1)
	(setq addr1 (buffer-substring (point)
				      (1- (search-forward "\"")))))
       ((= i 7)
	(forward-char 1)
	(setq addr2 (buffer-substring (point)
				      (1- (search-forward "\"")))))
       ((= i 8)
	(forward-char 1)
	(setq addr3 (buffer-substring (point)
				      (1- (search-forward "\""))))
	(if (or (string= "$B0J2<$K7G:\$,$J$$>l9g(B"
			 addr3)
		(string-match ".*$B0l1_(B$"
			      addr3)
		(string-match ".*$B$N<!$KHVCO$,$/$k>l9g(B$"
			      addr3)
		(string-match "^[$B#0(B-$B#9(B].*[$B#0(B-$B#9(B]$"
			      addr3))
	    (setq addr3 ""))
	;;
	(when (string-match "$B!J(B" addr3)
	  (let ((start (match-beginning 0)))
	    (cond
	     ((string-match "$B3,(B" addr3 start)
	      (setq addr3 (concat (substring addr3
					     0
					     start)
				  (substring addr3
					     (1+ start)
					     (match-end 0)))))
	     ;;
	     ((and (string= addr1 "$B5~ETI\(B")
		   (string-match "^$B5~ET;T(B" addr2))
	      (setq *addr4* (substring addr3 0 start))
	      (setq *addr3* (substring addr3 start))
	      (if (string-match "$B!K(B$" *addr3*)
		  (progn
		    (setq addr3 (mkdic-process-kyoto *addr3*
						     *addr4*))
		    (setq *stat* nil)
		    (setq *addr4* nil))
		(setq addr3 nil)
		(setq *stat* t)))
	     ;;
	     ((and (string-match "$B!K(B" addr3)
		   (not (string-match
			 "$BCO3d(B\\|$B$r=|$/(B\\|$B$r4^$`(B\\|$BA40h(B\\|[$B%"(B-$B%s(B]$B!"(B[$B%"(B-$B%s(B]"
			 addr3)))
	      (setq *addr4* (substring addr3 0 start))
	      (setq *addr3* (substring addr3 start))
	      (when (string= *addr4* "$B9C!"25(B")
		(setq *addr4* ""))
	      (if (and (string-match ".+$B!K(B$" *addr3*)
		       (not (string-match "$B!V(B\\|$B!W(B\\|$B!A(B\\|[$B#0(B-$B#9(B]"
					  *addr3*)))
		  (progn
		    (setq addr3 (mkdic-process-kakkonai *addr3* *addr4*))
		    (setq *stat* nil)
		    (setq *addr4* nil))
		(setq *addr4* nil)
		(setq *addr3* nil)
		(setq addr3 (substring addr3 0 start))
		(setq *stat* t)))
	     ;;
	     (t
	      (setq addr3 (substring addr3 0 start))
	      (setq *addr3* nil)
	      (setq *stat* t)))))
	;;
	(when (and addr3
		   (string-match ".*$BCO3d(B$" addr3))
	  (cond
	   ((string-match "$B!"(B" addr3)
	    (let ((start (match-beginning 0)))
	      (setq addr3 (concat (substring addr3
					     0
					     start)
				  "/"
				  addr1
				  addr2
				  (substring addr3
					     (1+ start))))))
	   ((string-match "$B!A(B" addr3)
	    (let ((point (match-beginning 0))
		  fromstr tostr
		  from to
		  chimei
		  str
		  pt1 pt2)
	      (setq fromstr (japanese-hankaku (substring addr3
							 0
							 point)))
	      (setq tostr (japanese-hankaku (substring addr3
						       (1+ point))))
	      (setq chimei (substring fromstr
				      0
				      (string-match "[0-9]"
						    fromstr)))
	      (setq pt1 (match-beginning 0))
	      (if (string-match "$BCO3d(B$" fromstr)
		  (setq pt2 (match-beginning 0)))
	      (setq from (string-to-int (substring fromstr
						   pt1
						   pt2)))
	      ;;
	      (if (string-match "[0-9]" tostr)
		  (setq pt1 (match-beginning 0)))
	      (if (string-match "$BCO3d(B$" tostr)
		  (setq pt2 (match-beginning 0)))
	      (setq to (string-to-int (substring tostr
						 pt1
						 pt2)))
	      ;;
	      (let ((i from))
		(while (<= i to)
		  (cond
		   ((= i from)
		    (setq addr3 (concat chimei
					(japanese-zenkaku (format "%d" i))
					"$BCO3d(B")))
		   (t
		    (setq addr3 (concat addr3
					"/"
					addr1
					addr2
					chimei
					(japanese-zenkaku (format "%d" i))
					"$BCO3d(B"))))
		  (setq i (1+ i))))))))
	;;
	(when (and addr3
		   (string-match "$B!K(B$" addr3))
	  (cond
	   ((and *addr4* *addr3*)
	    (setq *addr3* (concat *addr3* addr3))
	    (setq addr3 (mkdic-process-kyoto *addr3* *addr4*))
	    (setq *stat* nil)
	    (setq *addr4* nil))
	   (t
	    (if (and *addr3*
		     (setq addr3 *addr3*))
		(setq *stat* nil)))))
	;;
	(cond
	 ((and *stat* *addr4* *addr3* addr3)
	  (setq *addr3* (concat *addr3* addr3))
	  (setq addr3 nil))
	 (addr3
	  (if (string-match "$B!"(B" addr3)
	      (if *stat*
		  (and *addr3* (setq addr3 *addr3*))
		(setq addr3 ""))))
	 (t nil)))
       (t nil))
      ;;
      (let ((search (search-forward "," nil t)))
	(if search
	    (setq i (1+ i))
	  (setq i 9))))
    ;;
    (if (and *stat* addr3)
	(setq *addr3* addr3)
      (if *addr4*
	  nil
	(setq *addr3* nil)))
    ;;
    (save-excursion
      (set-buffer " *dic *")
      (when (and zip addr1 addr2 addr3)
	(insert zip)
	(insert " /")
	(insert addr1)
	(insert addr2)
	(insert addr3)
	(insert "/\n")))))

(defun mkdic-process-kyoto (nantaras cho)
  (let (addr)
    (cond
     ((string-match "\\($B!A(B\\|$B!JCzL\!K(B\\|$B$=$NB>(B\\|$BHVCO!K(B$\\)"
		    nantaras)
      (setq nantaras nil))
     ((string-match "$B!J(B[$B#0(B-$B#9(B]$BCzL\!K(B" nantaras)
      (setq cho (concat cho
			(substring nantaras
				   1
				   (1- (length nantaras)))))
      (setq nantaras nil))
     (t
      (setq nantaras (split-string (substring nantaras
					      1
					      (1- (length nantaras)))
				   "$B!"(B"))))
    (cond
     ((not nantaras)
      (setq addr cho))
     (t
      (setq addr (concat (car nantaras) cho))
      (mapc #'(lambda (nantara)
	       (setq addr (concat addr
				  "/"
				  addr1
				  addr2
				  nantara
				  cho)))
	    (cdr nantaras))
      addr))))

(defun mkdic-process-kakkonai (detail cho)
  (let (addr)
    (cond
     ((string-match "\\($B!A(B\\|$B!JCzL\!K(B\\|$BHVCO!K(B$\\)"
		    detail)
      (setq detail nil))
     ((string-match "$B!J(B[$B#0(B-$B#9(B]$BCzL\!K(B" detail)
      (setq cho (concat cho (substring detail 1 (1- (length detail)))))
      (setq detail nil))
     (t
      (setq detail (split-string (substring detail
					    1
					    (1- (length detail)))
				 "$B!"(B"))))
    (cond
     ((not detail)
      (setq addr cho))
     (t
      (unless (or (member "" detail)
		  (memq nil detail))
	(setq detail (cons "" detail)))
      (setq addr (concat cho (car detail)))
      (mapc #'(lambda (nantara)
		(unless (string-match "$B$=$NB>(B" nantara)
		  (setq addr (concat addr
				     "/"
				     addr1
				     addr2
				     cho
				     nantara))))
	    (cdr detail))
      addr))))

;; $B;v6H=jMQ(B
(defun mkdic-office ()
  (let (*addr3* *addr4*
		*stat*)
    (set-buffer (get-buffer-create " *dic *"))
    (erase-buffer)
    ;;
    (set-buffer (get-buffer-create " *csv *"))
    (erase-buffer)
    ;;
    (insert-file-contents (expand-file-name JIGYOSYO))
    ;;
    (goto-char (point-min))
    ;;
    (while (not (looking-at "^[0-9]"))
      (forward-line))
    ;;
    (mkdic-office-get-line)
    (while (eq (forward-line) 0)
      (mkdic-office-get-line))
    ;;
    (set-buffer " *dic *")
    (set-buffer-file-coding-system 'euc-jp-unix)
    (set-buffer-modified-p t)
    (goto-char (point-min))
    ;;
    (when (re-search-forward "^91086\"," nil t)
      (replace-match "9108630"))
    ;;
    (goto-char (point-min))
    (insert ";; okuri-ari entries.
;; okuri-nasi entries.
")
    (write-region (point-min)
		  (point-max)
		  (expand-file-name TEMP_OFFICE)
		  nil
		  nil
		  nil)))

(defun mkdic-office-get-line ()
  (let ((i 0)
	zip
	name
	addr1 addr2 addr3 addr4)
    (while (< i 9)
      (cond
       ((= i 7)
	(forward-char 1)
	(setq zip (buffer-substring (point)
				    (+ 7 (point)))))
       ((= i 2)
	(forward-char 1)
	(setq name (buffer-substring (point)
				     (1- (search-forward "\"")))))
       ((= i 3)
	(forward-char 1)
	(setq addr1 (buffer-substring (point)
				      (1- (search-forward "\"")))))
       ((= i 4)
	(forward-char 1)
	(setq addr2 (buffer-substring (point)
				      (1- (search-forward "\"")))))
       ((= i 5)
	(forward-char 1)
	(setq addr3 (buffer-substring (point)
				      (1- (search-forward "\"")))))
       ((= i 6)
	(forward-char 1)
	(setq addr4 (buffer-substring (point)
				      (1- (search-forward "\""))))))
      ;;
      (let ((search (search-forward "," nil t)))
	(if search
	    (setq i (1+ i))
	  (setq i 9))))
    ;;
    (save-excursion
      (set-buffer " *dic *")
      (when (and zip
		 name
		 addr1 addr2 addr3 addr4)
	(insert zip)
	(insert " /")
	(insert name)
	(insert " @ ")
	(insert addr1)
	(insert addr2)
	(insert addr3)
	(insert addr4)
	(insert "/\n")))))

(defun mkdic-words ()
  (let ((dics '("SKK-JISYO.office.zipcode"
		"SKK-JISYO.zipcode"))
	str)
    (set-buffer (get-buffer-create " *words *"))
    (erase-buffer)
    ;;
    (set-buffer (get-buffer-create " *dic *"))
    ;;
    (dolist (dic dics)
      (erase-buffer)
      (insert-file-contents dic)
      (goto-char (point-min))
      (while (re-search-forward "^[0-9][0-9][0-9][0-9][0-9][0-9][0-9] "
				nil
				t)
	(setq str (buffer-substring (match-beginning 0)
				    (1- (match-end 0))))
	(save-excursion
	  (set-buffer (get-buffer " *words *"))
	  (goto-char (point-max))
	  (insert (format "%s\n" str)))))
    ;;
    (set-buffer (get-buffer " *words *"))
    (sort-lines nil
		(point-min)
		(point-max))
    (write-region (point-min)
		  (point-max)
		  "words.zipcode"
		  nil
		  nil
		  nil)))

;;

(defun mkdic-zipcode-header ()
  (with-temp-buffer
    (insert "\
;; -*- mode: skk-jisyo-edit; coding: euc-jp -*-
;; 7-digit ZIP code dictionary for SKK system
;;
;; Copyright (C) 2000 Tetsuo Tsukamoto <czkmt@remus.dti.ne.jp>
;;
;; Maintainer: SKK Development Team <skk@ring.gr.jp>
;; Version: $Id: ZIPCODE-MK,v 1.7 2001/09/23 11:16:06 czkmt Exp $
;; Keywords: japanese
;; Last Modified: $Date: 2001/09/23 11:16:06 $
;;
;; This dictionary  is free software;  you can redistribute it and/or modify it
;; under the terms  of the GNU General Public License  as published by the Free
;; Software  Foundation;  either  versions 2,  or  (at your option)  any  later
;; version.
;;
;; This dictionary  is distributed  in  the hope  that  it will  be useful  but
;; WITHOUT ANY WARRANTY;  without even the implied warranty  of MERCHANTABILITY
;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
;; more details.
;;
;; You should have received a copy of the GNU General Public License along with
;; SKK,  see the file COPYING.  If not,  write  to the Free Software Foundation
;; Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;;
")
    (write-region (point-min)
		  (point-max)
		  "SKK-JISYO.zipcode")))

(defun mkdic-office-header ()
  (with-temp-buffer
    (insert "\
;; -*- mode: skk-jisyo-edit; coding: euc-jp -*-
;; 7-digit ZIP code (offices) dictionary for SKK system
;;
;; Copyright (C) 2000 Tetsuo Tsukamoto <czkmt@remus.dti.ne.jp>
;;
;; Maintainer: SKK Development Team <skk@ring.gr.jp>
;; Version: $Id: ZIPCODE-MK,v 1.7 2001/09/23 11:16:06 czkmt Exp $
;; Keywords: japanese
;; Last Modified: $Date: 2001/09/23 11:16:06 $
;;
;; This dictionary  is free software;  you can redistribute it and/or modify it
;; under the terms  of the GNU General Public License  as published by the Free
;; Software  Foundation;  either  versions 2,  or  (at your option)  any  later
;; version.
;;
;; This dictionary  is distributed  in  the hope  that  it will  be useful  but
;; WITHOUT ANY WARRANTY;  without even the implied warranty  of MERCHANTABILITY
;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
;; more details.
;;
;; You should have received a copy of the GNU General Public License along with
;; SKK,  see the file COPYING.  If not,  write  to the Free Software Foundation
;; Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;;
")
    (write-region (point-min)
		  (point-max)
		  "SKK-JISYO.office.zipcode")))

;; ZIPCODE-MK ends here