Index: Makefile ================================================================== --- Makefile +++ Makefile @@ -21,11 +21,14 @@ MTESTHASH=$(shell fossil info|grep checkout:| awk '{print $$2}') CSIPATH=$(shell which csi) CKPATH=$(shell dirname $(shell dirname $(CSIPATH))) -all : mtest dboard newdboard +all : mtest dboard newdboard txtdb + +refdb : txtdb/txtdb.scm + csc txtdb/txtdb.scm -o refdb mtest: $(OFILES) megatest.o csc $(CSCOPTS) $(OFILES) megatest.o -o mtest dboard : $(OFILES) $(GOFILES) dashboard.scm @@ -94,10 +97,14 @@ chmod a+x $@ $(PREFIX)/bin/nbfind : utils/nbfind $(INSTALL) $< $@ chmod a+x $@ + +$(PREFIX)/bin/refdb : refdb + $(INSTALL) $< $@ + chmod a+x $@ deploytarg/nbfake : utils/nbfake $(INSTALL) $< $@ chmod a+x $@ @@ -110,11 +117,11 @@ $(PREFIX)/bin/dboard : dboard $(FILES) $(INSTALL) dboard $(PREFIX)/bin/dboard utils/mk_wrapper $(PREFIX) dboard > $(PREFIX)/bin/dashboard chmod a+x $(PREFIX)/bin/dashboard -install : bin $(PREFIX)/bin/mtest $(PREFIX)/bin/megatest $(PREFIX)/bin/dboard $(PREFIX)/bin/dashboard $(HELPERS) $(PREFIX)/bin/nbfake $(PREFIX)/bin/nbfind $(PREFIX)/bin/newdboard +install : bin $(PREFIX)/bin/mtest $(PREFIX)/bin/megatest $(PREFIX)/bin/dboard $(PREFIX)/bin/dashboard $(HELPERS) $(PREFIX)/bin/nbfake $(PREFIX)/bin/nbfind $(PREFIX)/bin/newdboard $(PREFIX)/bin/refdb deploytarg/apropos.so : Makefile for i in apropos base64 canvas-draw csv-xml directory-utils dot-locking extras fmt format hostinfo http-client intarweb json md5 message-digest posix posix-extras readline regex regex-case s11n spiffy spiffy-request-vars sqlite3 srfi-1 srfi-18 srfi-69 tcp test uri-common check-errors synch matchable sql-null tcp-server rpc blob-utils string-utils variable-item defstruct uri-generic sendfile opensll openssl lookup-table list-utils stack; do \ chicken-install -prefix deploytarg -deploy $$i;done Index: txtdb/txtdb.scm ================================================================== --- txtdb/txtdb.scm +++ txtdb/txtdb.scm @@ -15,11 +15,11 @@ (use srfi-69) (use regex-case) (use posix) ;; Read a non-compressed gnumeric file -(define (txtdb:read-gnumeric-xml fname) +(define (refdb:read-gnumeric-xml fname) (with-input-from-file fname (lambda () (ssax:xml->sxml (current-input-port) '())))) (define (find-section dat section #!key (depth 0)) @@ -63,11 +63,11 @@ dat))) (define (string->safe-filename str) (string-substitute (regexp " ") "_" str #t)) -(define (sheet->txtdb dat targdir) +(define (sheet->refdb dat targdir) (let* ((sheet-name (car (find-section dat 'http://www.gnumeric.org/v10.dtd:Name))) ;; (safe-name (string->safe-filename sheet-name)) (cells (find-section dat 'http://www.gnumeric.org/v10.dtd:Cells)) (remaining (remove-section (remove-section dat 'http://www.gnumeric.org/v10.dtd:Name) 'http://www.gnumeric.org/v10.dtd:Cells)) @@ -133,20 +133,20 @@ (begin (print "ERROR: file " fname " is malformed for read") #f) (car res)))) -;; Write an sxml gnumeric workbook to a txtdb directory structure. +;; Write an sxml gnumeric workbook to a refdb directory structure. ;; -(define (extract-txtdb dat targdir) +(define (extract-refdb dat targdir) (create-directory (conc targdir "/sxml") #t) (let* ((wrkbk (find-section dat 'http://www.gnumeric.org/v10.dtd:Workbook)) (wrk-rem (remove-section dat 'http://www.gnumeric.org/v10.dtd:Workbook)) (sheets (find-section wrkbk 'http://www.gnumeric.org/v10.dtd:Sheets)) (sht-rem (remove-section wrkbk 'http://www.gnumeric.org/v10.dtd:Sheets)) (sheet-names (map (lambda (sheet) - (sheet->txtdb sheet targdir)) + (sheet->refdb sheet targdir)) sheets))) (sxml->file wrk-rem (conc targdir "/sxml/workbook.sxml")) (sxml->file sht-rem (conc targdir "/sxml/sheets.sxml")) (with-output-to-file (conc targdir "/sheet-names.cfg") (lambda () @@ -157,21 +157,21 @@ (begin (print "ERROR: Attempt to import gnumeric file with extention other than .gnumeric") (exit)) (let ((tmpf (create-temporary-file (pathname-strip-directory fname)))) (system (conc " gunzip > " tmpf " < " fname)) - (let ((res (txtdb:read-gnumeric-xml tmpf))) + (let ((res (refdb:read-gnumeric-xml tmpf))) (delete-file tmpf) res)))) (define (import-gnumeric-file fname targdir) - (extract-txtdb (read-gnumeric-file fname) targdir)) + (extract-refdb (read-gnumeric-file fname) targdir)) -;; Write a gnumeric compressed xml spreadsheet from a txtdb directory structure. +;; Write a gnumeric compressed xml spreadsheet from a refdb directory structure. ;; -(define (txtdb-export dbdir fname) - (let* ((sxml-dat (txtdb->sxml dbdir)) +(define (refdb-export dbdir fname) + (let* ((sxml-dat (refdb->sxml dbdir)) (tmpf (create-temporary-file (pathname-strip-directory fname))) (tmpgzf (conc tmpf ".gz"))) (with-output-to-file tmpf (lambda () (print (sxml-serializer#serialize-sxml sxml-dat ns-prefixes: (list (cons 'gnm "http://www.gnumeric.org/v10.dtd")))))) @@ -243,11 +243,11 @@ (list 'http://www.gnumeric.org/v10.dtd:Cell (list '@ val-type (list 'Row (conc row-num)) (list 'Col (conc col-num))) value))) (append rowdat coldat dat)))))) -(define (txtdb->sxml dbdir) +(define (refdb->sxml dbdir) (let* ((sht-names (read-file (conc dbdir "/sheet-names.cfg") read-line)) (wrk-rem (file->sxml (conc dbdir "/sxml/workbook.sxml"))) (sht-rem (file->sxml (conc dbdir "/sxml/sheets.sxml"))) (sheets (fold (lambda (sheetname res) (let* ((sheetdat (read-dat (conc dbdir "/" sheetname ".dat"))) @@ -302,21 +302,29 @@ new-colnames (if (> curr-rownum rownum) curr-rownum rownum) (if (> curr-colnum colnum) curr-colnum colnum) )))))) (define help - (conc "Usage: txtdb action params ... - -Note: txtdbdir is a path to the directory containg sheet-names.cfg - - import filename.gnumeric txtdbdir : Import a gnumeric file into a txt db directory - edit txtdbdir : Edit a txtdbdir using gnumeric. - lookup txtdbdir sheetname row col : Look up a value in the text db - json txtdbdir : Print the db as list of lists json data + (conc "Usage: refdb action params ... + +Note: refdbdir is a path to the directory containg sheet-names.cfg + + import filename.gnumeric refdbdir : Import a gnumeric file into a txt db directory + edit refdbdir : Edit a refdbdir using gnumeric. + lookup refdbdir sheetname row col : Look up a value in the text db + ls refdbdir : List the keys for specified level Part of the Megatest tool suite. Learn more at http://www.kiatoa.com/fossils/megatest")) +(define (list-sheets path) + ;; (cond + ;; ((and path (not sheet)(not row)(not col)) + (if (file-exists? path) + (read-file (conc path "/sheet-names.cfg") read-line) + '())) +;; ((and path sheet (not row)(not col)) + (define (lookup path sheet row col) (let ((fname (conc path "/" sheet ".dat"))) (if (file-exists? fname) (let ((dat (read-dat fname))) (if (null? dat) @@ -329,15 +337,15 @@ (if (null? tal) #f (loop (car tal)(cdr tal))))))) #f))) -(define (edit-txtdb path) +(define (edit-refdb path) (let* ((dbname (pathname-strip-directory path)) (tmpf (conc (create-temporary-file dbname) ".gnumeric"))) (if (file-exists? (conc path "/sheet-names.cfg")) - (txtdb-export path tmpf)) + (refdb-export path tmpf)) (let ((pid (process-run "gnumeric" (list tmpf)))) (process-wait pid) (import-gnumeric-file tmpf path)))) (define (process-action action-str . param) @@ -345,11 +353,13 @@ (action (string->symbol action-str))) (cond ((eq? num-params 1) (case action ((edit) - (edit-txtdb (car param))))) + (edit-refdb (car param))) + ((ls) + (map print (list-sheets (car param)))))) ((eq? num-params 2) (case action ((import) (let ((fname (car param)) (targname (cadr param))) @@ -375,11 +385,11 @@ (else (print help))))) (main) #| - (define x (txtdb:read-gnumeric-xml "testdata-stripped.xml")) + (define x (refdb:read-gnumeric-xml "testdata-stripped.xml")) ;; Write out sxml (with-output-to-file "testdata.sxml" (lambda()(pp x)))