#!/bin/sh
: ; exec klone $0 "$@"
; The above line finds the klone executable in the $PATH
;;Skeleton of a typical klone script

(setq args (getopts "USAGE: %0 [options] 
takes an IDRAW drawing (postscript) and outputs its strings on stdout"
    ("-l" () nl "add a newline between each paragraph")
    ("-c" () concat "concatenates lines of the same paragraph")
    ("-v" () verbose "verbose operation")
    ("-debug" () enter-debugger-on-error "enter klone debugger on error")
    ("-stackdump" () stackdump-on-error "verbose stack dump on error")
))

(if enter-debugger-on-error (kdb t))
(if stackdump-on-error (stack-dump-on-error t))


(defun filter-idraw-strings (in out &aux
    (res (regcomp "^[(](.*)[)]$"))
    (re-accents (regcomp "[\\][0-7][0-7][0-7]"))
    line
    (was-s t)
    tt
  )
  (catch 'EOF (while t (setq line (read-line in))
      (if (regexec res line) (progn
	  (setq line (regsub res 1))
	  (if (and (or nl concat) (not was-s)) (write-line "" out))
	  (if (and concat was-s) (write-string " " out))
	  (replace-string line re-accents 
	    [
	    "\\347" ""
	    "\\371" ""
	    "\\364" ""
	    "\\356" ""
	    "\\373" ""
	    "\\353" ""
	    "\\357" ""
	    "\\374" ""
	    "\\351" ""
	    "\\350" ""
	    "\\352" ""
	    "\\340" ""
	    "\\342" ""
	    ]
	    :all t :quote t
	  )
	  (write-string line out)
	  (if (not concat) (write-line "" out) (setq tt t))
	  (setq was-s t)
	)
	(setq was-s ())
  )))
  (if tt (write-line "" out))
)

(defun main (&aux
  )
  (filter-idraw-strings *standard-input* *standard-output*)
)

(main)

;;; EMACS MODES
;;; Local Variables: ***
;;; mode:lisp ***
;;; End: ***

