;; Define the ECI Software database

;; Define some enumerated types

;; "arch"

(define-enum-type 'arch 
	'("rs6000"			;IBM
	  "NeXT"			;NeXT
	  "sun3" "sun4"			;Sun
	  "mipsel"			;DECstation 5000
	  "r3000"			;SGI R3000
	  "r4000"			;SGI R4000
	  "mac"				;Macintosh
	  "any"				;any
	  ) nil)
;; "os"

(define-enum-type 'os
	'("AIX3.2" 
	  "NeXTOS2.0" "NeXTOS3.0" 
	  "SunOS4.0.3" "SunOS4.1.1" "SunOS4.1.2"
	  "Solaris2.0" "Solaris2.1" 
	  "Ultrix4.1" "Ultrix4.2" 
	  "IRIX4.1" "IRIX4.2"
	  "MacOS6.0.5" "MacOS7.0"
	  "any"				;any
	  ) nil)

;; "short-string": both a one-line-string and a string-or-nil.

(let ((ds (copy-displayspec (displaytype->displayspec 'one-line-string))))
  (displayspec-set-actual->display ds (function string-or-nil->string))
  (define-displaytype-from-displayspec 'short-string ds))
(let ((rs (copy-recordfieldspec (recordfieldtype->recordfieldspec 'one-line-string))))
  (recordfieldspec-set-type rs 'short-string)
  (recordfieldspec-set-order-fn rs (function string-or-nil-order-ci))
  (recordfieldspec-set-sort-fn rs (function string-or-nil-lessp-ci))
  (recordfieldspec-set-match-function rs (function string-or-nil-match-function))
  (define-recordfieldtype-from-recordfieldspec 'short-string rs))

;; Now define the database fields

(db-tagged-setup 
 '(((name	  . short-string)    "NM" "Name of software")
   ((desc	  . string-or-nil)   "SD" "Software description")
   ((version      . short-string)    "VR" "Version of software installed")
   ((arch         . arch)	     "MA" "Machine architecture of installation")
   ((os	          . os)		     "OS" "Operating System")
   ((restric      . string-or-nil)   "OR" "Operational restrictions (if any)")
   ((installdate  . date)	     "ID" "Date installed")
   ((installer    . short-string)    "IR" "Who installed it")
   ((installnotes . string-or-nil)   "IN" "Installation Notes")
   ((binpath      . short-string)    "BP" "Path to binaries")
   ((binlist      . string-or-nil)   "BL" "List of binaries (possibly linked)")
   ((libpath      . short-string)    "LP" "Path to libraries")
   ((liblist      . string-or-nil)   "LL" "List of libraries (eg: \"-lX11\")")
   ((manpath      . short-string)    "MP" "Path to \"man\" pages")
   ((infopath     . short-string)    "IP" "Path to GNU info file")
   ((helppath     . short-string)    "HP" "Path to file or command to help user with software")
   ((source       . short-string)    "SR" "Source location: FTP site, or local filesystem")
   ((updatedate   . date)	     "UD" "Last update date")
   ((updater      . short-string)    "UR" "Who did the last update")
   ((updatenotes  . string-or-nil)   "UN" "Notes on last update")
   ))

(database-set-print-name database "ECI Software Database")
(database-set-file database "ecisw.dat")
(dbf-set-summary-format
 "\\name,width=12 \\version,width=6 \\updatedate,date-mmddyy,width=8 \\arch,width=10 \\os,width=10")

(recordfieldspec-set-stored->actual (recordfieldtype->recordfieldspec 'date)
				    (function parse-date-string))

(database-set-local 'db-tagged-pre-tag-regexp      database "")
(database-set-local 'db-tagged-tag-chars           database "A-Z")
(database-set-local 'db-tagged-separator-regexp    database ":[ \t]*")
(database-set-local 'db-tagged-separator-output    database ":\t")
(database-set-local 'db-tagged-continuation-regexp database "^[ \t]+")
(database-set-local 'db-tagged-continuation-output database "\t")

(defun swdb-record-defaults (new-rec database)
  "Provide defaults for new records in the database."
  (let ((curdate (parse-date-string (current-date)))
	(curuser (concat (user-login-name) "@" (system-name)))
	)
    (record-set-field new-rec 'installdate curdate database)
    (record-set-field new-rec 'installer   curuser database)
    (record-set-field new-rec 'updatedate  curdate database)
    ))
(setq db-new-record-function 'swdb-record-defaults)
