#!/bin/sh
: ; exec klone $0 "$@"
; The above line allows not to embed the exact path of the klone executable

;;Skeleton of a typical klone script

(setq args (getopts "USAGE: %0 [options] sfv-file
Fixes in place the sfv file"
    ("-v" () verbose "verbose operation")
;; --- Hidden Options ---
    ("-debug" () enter-debugger-on-error "enter klone debugger on error"
    :hidden t)
    ("-stackdump" () stackdump-on-error "verbose stack dump on error"
    :hidden t)
))

(if (not args) (getopts :usage))
file = (0 args)

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

(defun main (&aux
    fd
    (re-com (regcomp "^[ \t]*;"))
    (re-check (regcomp "^([^ ]+)[ \t]+([0-9a-fA-F]+)[ \t\r]*$"))
    (checks (list))
  )
  fd = (open  file)
  (doline (line fd)
    (if (re-com line) ()
      (re-check line) 
      (lappend checks (vector (re-check 1) (re-check 2)))
      (PF "*** WARNING: bad line: %r0\n" line)
  ))
  (close fd)
  (wait (system (list "mv" file (+ file ".back"))))
  fd = (open  file :direction :output :if-exists :supersede)
  (PF fd "; Generated by SFV32nix v1.2 on 1999-11-22 at 10:11.03\n;\n")
  (dolist (p checks)
    (PF fd "%0 %1\n" (0 p) (1 p))
  )
  (close fd)
)

(main)

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

