; -*- coding: utf-8 -*-

;(shell-command "cd /opt/elbrus/pok/eo/kompleks;rm -f dict0.utf")
;(message "dumping KL with Lynx ...")
;(shell-command "dump-kl")
;

(defun faru-dict1 ()
  (require 'oc-unicode)
  (require 'un-tools)
  (find-file "/opt/elbrus/pok/eo/kompleks/dict0.utf" 1)
  (modify-coding-system-alist 'file "\\<utf\\>" 'utf-8)
  
  (goto-char (point-min))
  (while (re-search-forward "^ +$" nil t) (replace-match ""))
  
  (goto-char (point-max)) ; ??
  (while (re-search-backward
          "^ +\\(Sekv\\|Anta.\\)an pa.on\\>.* Indekson\\>.* Instrukcion.?*$"
          (point-min) t)
    (kill-line))
  
  (goto-char (point-max))
  (while (re-search-backward 
          "^ +_________________________________________________________________$"
          (point-min) t)
    (progn (kill-line)
           (delete-blank-lines)
           (insert-char 12 1)             ; form feed
    )
  )
  
  (while (search-forward "\14\14" nil t)
   (backward-delete-char 1))
  
  (goto-char (point-min))
  (while (re-search-forward "^Detaloj *\n\n" nil t)
    (progn (forward-line -2) (kill-line 2)))
  
  (goto-char (point-min))
  (while (re-search-forward "\\[DEL: *\n\\([^:]+[^ ]\\) *:DEL\\]" nil t)
    (replace-match "\n¿\\1?"))
  (goto-char (point-min))
  (while (re-search-forward "\\[DEL: *\\([^:]+[^ ]\\) *\n:DEL\\]" nil t)
    (replace-match "¿\\1?\n"))
  (goto-char (point-min))
  (while (re-search-forward "\\[DEL: *\\([^:]+[^ ]\\) *:DEL\\]" nil t)
    (replace-match "¿\\1?"))
  
  (let ((sort-fold-case t))
    (goto-char (point-min))             ; S^{*}
    (while (re-search-forward "\\^{\\([^a-z]\\)}" nil t)
      (replace-match "^\\1")))
  
  (goto-char (point-min))
  (while (re-search-forward "« +\\(\\w\\)" nil t)
    (replace-match "«\\1"))
  
  (goto-char (point-min))
  (kill-line 1)                             ; la komenca ff
  
  (insert (format-time-string "00-database-url
     http://www.esperanto.mv.ru/KompLeks/UTF8/
\14
00-database-short
     Komputada leksikono (Red. 24a)
\14
00-database-log
     Converted to dict on %Y-%m-%d.
\14
00-database-info
Komputada leksikono, red. 24 (C) de Sergio Pokrovskij.
\14\n"))
  
  (write-file "/opt/elbrus/pok/eo/kompleks/dict1.utf")
)