#!/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] file
prints the filesize in bytes of file, or 0 if file do not exists.
For output in K or M, the size is rounded up: a file of 1024 bytes is 
reported as 1 for -k, 1025 to 2048 as 2"
    ("-k" () in-k? "outputs the size in Kilobytes, not bytes")
    ("-m" () in-m? "outputs the size in Megabytes, not bytes")
    ("-e" () trigger-err? "if cannot read file, return an error, not 0")
))

(setq file (getn args 0))
(if (not file) (getopts :usage))

(defun main (&aux
    (size (get (file-stats file) 'size (if trigger-err? 
	  '(fatal-error 1 "File not found: %0\n" file)
	  0
    )))
  )
  (if in-m? (setq size (/ (+ size 1048575) 1048576))
    in-k? (setq size (/ (+ size 1023) 1024))
  )
  (? size "\n")
)

(main)

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

