Index: txtdb/nada3/Sheet3.dat ================================================================== --- txtdb/nada3/Sheet3.dat +++ txtdb/nada3/Sheet3.dat @@ -0,0 +1,8 @@ +[zeroth title] +row1name +row2name + +[col1title] +row1name row1value +row2nameNoValue +row3name row3value Index: txtdb/txtdb.scm ================================================================== --- txtdb/txtdb.scm +++ txtdb/txtdb.scm @@ -77,28 +77,34 @@ (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)) (rownums (make-hash-table)) ;; num -> name (colnums (make-hash-table)) ;; num -> name - (cols (make-hash-table))) ;; name -> ( (name val) ... ) + (cols (make-hash-table)) ;; name -> ( (name val) ... ) + (col0title "")) (for-each (lambda (cell) (let ((rownum (string->number (car (find-section cell 'Row)))) (colnum (string->number (car (find-section cell 'Col)))) (valtype (let ((res (find-section cell 'ValueType))) (if res (car res) #f))) (value (let ((res (cdr (filter (lambda (x)(not (list? x))) cell)))) (if (null? res) "" (car res))))) ;; If colnum is 0 Then this is a row name, if rownum is 0 then this is a col name (cond - ((eq? 0 colnum) ;; a blank in column zero is handled with the special name "row-N" + ((and (not (eq? 0 rownum)) + (eq? 0 colnum)) ;; a blank in column zero is handled with the special name "row-N" (hash-table-set! rownums rownum (if (equal? value "") (conc "row-" rownum) value))) - ((eq? 0 rownum) + ((and (not (eq? 0 colnum)) + (eq? 0 rownum)) (hash-table-set! colnums colnum (if (equal? value "") (conc "col-" colnum) value))) + ((and (eq? 0 rownum) + (eq? 0 colnum)) + (set! col0title value)) (else (let ((colname (hash-table-ref/default colnums colnum (conc "col-" colnum))) (rowname (hash-table-ref/default rownums rownum (conc "row-" rownum)))) (hash-table-set! cols colname (cons (list rowname value) (hash-table-ref/default cols colname '())))))))) @@ -106,10 +112,11 @@ (let ((ref-colnums (map (lambda (c) (list (cdr c)(car c))) (hash-table->alist colnums)))) (with-output-to-file (conc targdir "/" sheet-name ".dat") (lambda () + (print "[" col0title "]") (for-each (lambda (colname) (print "[" colname "]") (for-each (lambda (row) (let ((key (car row)) (val (cadr row))) @@ -215,18 +222,20 @@ (blank-rx (regexp "^\\s*$")) (continue-rx (regexp ".*\\\\$")) (var-no-val-rx (regexp "^(\\S+)\\s*$")) (inp (open-input-file fname)) (cmnt-indx (make-hash-table)) - (blnk-indx (make-hash-table))) + (blnk-indx (make-hash-table)) + (first-section #f)) ;; used for zeroth title (let loop ((inl (read-line inp)) (section ".............") (res '())) (if (eof-object? inl) (begin (close-input-port inp) - (reverse res)) + (cons (list first-section first-section first-section) + (reverse res))) (regex-case inl (continue-rx _ (loop (conc inl (read-line inp)) section res)) (comment-rx _ (let ((curr-indx (+ 1 (hash-table-ref/default cmnt-indx section 0)))) (hash-table-set! cmnt-indx section curr-indx) @@ -236,13 +245,16 @@ (blank-rx _ (let ((curr-indx (+ 1 (hash-table-ref/default blnk-indx section 0)))) (hash-table-set! blnk-indx section curr-indx) (loop (read-line inp) section (cons (list (conc "#BLNK" curr-indx) section " ") res)))) - (section-rx (x sname) (loop (read-line inp) - sname - res)) + (section-rx (x sname) (begin + (if (not first-section) + (set! first-section sname)) + (loop (read-line inp) + sname + res))) (cell-rx (x k v) (loop (read-line inp) section (cons (list k section v) res))) (var-no-val-rx (x k) (loop (read-line inp) section @@ -264,11 +276,11 @@ (hash-table-set! expressions val new-max) (list 'ExprID new-max))))) (else '(ValueType "60")))) (define (dat->cells dat) - (let* ((indx (common:sparse-list-generate-index dat)) + (let* ((indx (common:sparse-list-generate-index (cdr dat))) (row-indx (car indx)) (col-indx (cadr indx)) (rowdat (map (lambda (row)(list (car row) " " (car row))) row-indx)) (coldat (map (lambda (col)(list " " (car col) (car col))) col-indx)) (exprs (make-hash-table))) @@ -541,10 +553,13 @@ (let ((dotfile (conc (get-environment-variable "HOME") "/.txtdbrc"))) (if (file-exists? dotfile) (load dotfile))) +(let ((debugcontrolf (conc (get-environment-variable "HOME") "/.refdbrc"))) + (if (file-exists? debugcontrolf) + (load debugcontrolf))) (main) #| (define x (refdb:read-gnumeric-xml "testdata-stripped.xml"))