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

(if (not (file-stats "/usr/5bin/touch"))
  (progn
    (print-format *standard-error* "Sorry, you must be on a sun to run copy-0date\n")
    (exit 1)
))

(setq usage-text
  "USAGE: copy-date source-file dest-file
  setasthe date of dest-file to the date of source-file")

(with (*load-pathname* '("."))
  (if (or
      (/= 3 (length *arguments*))
      (not (find-file (setq source-file (get *arguments* 1))))
      (not (find-file (setq dest-file (get *arguments* 2))))
    )
    (progn
      (print-format *standard-error* usage-text)
      (exit 1)
)))


(defun itoa2 (n)
  (if (< n 10)
    (+ "0" (String n))
    (< n 100)
    (String n)
    (String (mod n 100))
))    

(setq file-date (seconds-to-date (getn (file-stats source-file) 'mtime)))
(if (not (and file-date
      (= 0 (wait (system (list "/usr/5bin/touch" "-cf"
	      ;; mmddhhmmyy
	      (+ "" (itoa2 (get file-date 1))
		(itoa2 (get file-date 2))
		(itoa2 (get file-date 3))
		(itoa2 (get file-date 4))
		(itoa2 (get file-date 0))
	      )
	      dest-file
  ))))))
  (print-format *standard-error* "Could not reset date of %0 to %1\n"
    dest-file
    (+ "" (itoa2 (get file-date 1))
      (itoa2 (get file-date 2))
      (itoa2 (get file-date 3))
      (itoa2 (get file-date 4))
      (itoa2 (get file-date 0))
    )
)))))
