Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 80 additions & 57 deletions skk-develop.el
Original file line number Diff line number Diff line change
Expand Up @@ -27,46 +27,55 @@
;;; Code:

(require 'skk)
(require 'tar-util)

(eval-when-compile
(require 'url)
(defvar skk-exserv-list))

(defvar skk-get-files '("SKK-JISYO.JIS2.gz"
"SKK-JISYO.JIS2004.gz"
"SKK-JISYO.JIS3_4.gz"
"SKK-JISYO.L.gz"
"SKK-JISYO.assoc.gz"
"SKK-JISYO.edict.tar.gz"
"SKK-JISYO.fullname.gz"
"SKK-JISYO.geo.gz"
"SKK-JISYO.itaiji.gz"
"SKK-JISYO.jinmei.gz"
"SKK-JISYO.law.gz"
"SKK-JISYO.lisp.gz"
"SKK-JISYO.mazegaki.gz"
"SKK-JISYO.okinawa.gz"
"SKK-JISYO.propernoun.gz"
"SKK-JISYO.pubdic+.gz"
"SKK-JISYO.station.gz"
"zipcode.tar.gz")
"")
(defvar skk-dict-collection
'(("SKK-JISYO.L.gz" . euc-jp-unix)
("SKK-JISYO.JIS2.gz" . euc-jp-unix)
("SKK-JISYO.JIS2004.gz" . euc-jisx0213-unix)
("SKK-JISYO.JIS3_4.gz" . euc-jisx0213-unix)
("SKK-JISYO.assoc.gz" . euc-jp-unix)
("SKK-JISYO.edict.tar.gz" . archive)
("SKK-JISYO.fullname.gz" . euc-jisx0213-unix)
("SKK-JISYO.geo.gz" . euc-jp-unix)
("SKK-JISYO.itaiji.gz" . euc-jp-unix)
("SKK-JISYO.jinmei.gz" . euc-jp-unix)
("SKK-JISYO.law.gz" . euc-jp-unix)
("SKK-JISYO.lisp.gz" . euc-jp-unix)
("SKK-JISYO.mazegaki.gz" . euc-jp-unix)
("SKK-JISYO.okinawa.gz" . euc-jp-unix)
("SKK-JISYO.propernoun.gz" . euc-jp-unix)
("SKK-JISYO.pubdic+.gz" . euc-jp-unix)
("SKK-JISYO.station.gz" . euc-jp-unix)
("zipcode.tar.gz" . archive))
"SKK $B<-=q$N%j%9%H!#(B
$BCM$,(B 'archive $B$J$i(B tar $B$GE83+!#(B
$B$=$l0J30$N%7%s%\%k$J$i!"$=$NJ8;z%3!<%I$GC10l%U%!%$%k$rE83+!#(B")

;; TODO:
;; SKK-JISYO.office.zipcode . euc-jisx0213-unix
;; SKK-JISYO.zipcode . euc-jisx0213-unix

(defun skk-get-delete-files (dir)
"DIR."
(let ((files (cons "edict_doc.txt" skk-get-files))
p)
(dolist (filename files)
(dolist (file (list filename
(replace-regexp-in-string ".gz" "" filename)
(replace-regexp-in-string ".tar.gz" "" filename)))
(setq p (expand-file-name file dir))
(when (file-exists-p p)
(cond ((null (car (file-attributes p)))
(delete-file p))
(t
(delete-directory p t))))))))
"DIR $BFb$N<-=q%U%!%$%k!J%"!<%+%$%V!"C10l%U%!%$%k!"%G%#%l%/%H%j!K$r0lA]$9$k!#(B"
(pcase-dolist (`(,f . ,_conf) skk-dict-collection)
(let ((targets (list f ; $B85$N(B .gz / .tar.gz
(replace-regexp-in-string "\\.tar\\.gz\\'" "" f) ; $BE83+8e(B(tar)
(replace-regexp-in-string "\\.gz\\'" "" f)))) ; $BE83+8e(B(gz)

;; SKK-JISYO.edict.tar.gz $B$KIU?o$9$kFC<l$J%I%-%e%a%s%H$bBP>]$K2C$($k(B
(when (string= f "SKK-JISYO.edict.tar.gz")
(push "edict_doc.txt" targets))

(dolist (file targets)
(let ((path (expand-file-name file dir)))
(when (file-exists-p path)
(if (file-directory-p path)
(delete-directory path t)
(delete-file path))))))))

(defun skk-get-mkdir (dir)
"DIR."
Expand All @@ -75,37 +84,51 @@
(make-directory dir t)))

(defun skk-get-download (dir)
"DIR."
(let ((url "https://skk-dev.github.io/dict/")
fn)
(dolist (f skk-get-files)
(setq fn (expand-file-name f dir))
(unless (file-exists-p fn)
(url-copy-file (format "%s%s" url f) fn)))))

(defun skk-get-expand-tar (dir)
"DIR."
;; (let (fn)
;; (dolist (f (directory-files dir t "tar"))
;; (setq fn (convert-standard-filename f))
;; (shell-command (format "tar -xf %s -C %s && rm %s"
;; fn dir fn))))
(let ((list '(("SKK-JISYO.edict.tar" . "SKK-JISYO.edict")
("zipcode.tar" . "SKK-JISYO.zipcode")
("zipcode.tar" . "SKK-JISYO.office.zipcode"))))
(dolist (c list)
(tar-salvage-file (expand-file-name (car c) dir)
(cdr c)
(expand-file-name (cdr c) dir)))))
"SKK$B<-=q$r%@%&%s%m!<%I$7!"(B`skk-dict-collection' $B$K4p$E$-E83+!&J]B8$9$k!#(B"
(let ((base-url "https://skk-dev.github.io/dict/"))
;; ($B%U%!%$%kL>(B . $B@_Dj(B) $B$rD>@\J,2r$7$F%k!<%W(B
(pcase-dolist (`(,f . ,conf) skk-dict-collection)
(let* ((dest-name (if (eq conf 'archive)
(replace-regexp-in-string "\\.tar\\.gz\\'" "" f)
(replace-regexp-in-string "\\.gz\\'" "" f)))
(dest-path (expand-file-name dest-name dir))
(url (concat base-url f))
(tmp-gz (expand-file-name f dir))) ; $B0l;~J]B8MQ%Q%9(B

(unless (file-exists-p dest-path)
(message "Downloading %s..." f)
;; unwind-protect $B$G%(%i!<;~$b0l;~%U%!%$%k$r3N<B$K>C5n(B
(unwind-protect
(progn
(url-copy-file url tmp-gz t)
(skk-unpack-entry tmp-gz dir conf))
(when (file-exists-p tmp-gz)
(delete-file tmp-gz))))))))

(defun skk-unpack-entry (file-path dest-dir config)
"CONFIG $B$K4p$E$-(B 'archive $B$+J8;z%3!<%I$+$rH=Dj$7$FE83+$9$k!#(B"
(let ((default-directory dest-dir)
(file-name (file-name-nondirectory file-path)))
(pcase config
('archive
(if (executable-find "tar") ; Windows 10 $B0J9_$G$OI8=`(B
(call-process "tar" nil nil nil "-xf" file-path)
(error "tar $B%3%^%s%I$,8+$D$+$j$^$;$s(B: %s" file-name)))

(coding
(let ((out-file (expand-file-name (replace-regexp-in-string "\\.gz\\'" "" file-name)
dest-dir))
(coding-system-for-write coding))
(with-temp-file out-file
(insert-file-contents file-path)))))))

;;;###autoload
(defun skk-get (dir)
"DIR."
(interactive (list (read-directory-name "skk-get directory: " (expand-file-name skk-get-jisyo-directory))))
(let ((jisyo-dir (expand-file-name dir)))
(skk-get-mkdir jisyo-dir)
(skk-get-download jisyo-dir)
(skk-get-expand-tar jisyo-dir))
(skk-get-download jisyo-dir))
(message "skk-get...done")
nil)

Expand Down
147 changes: 0 additions & 147 deletions tar-util.el

This file was deleted.

Loading