Megatest

Check-in [d988af5391]
Login
Overview
Comment:Added support for comments in .dat files in refdb
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: d988af53918ffa567cb6b4dd605c28ed295f53b0
User & Date: matt on 2013-07-25 22:36:31
Other Links: branch diff | manifest | tags
Context
2013-07-25
22:49
Added support for blank lines check-in: f8e0755f5c user: matt tags: dev
22:36
Added support for comments in .dat files in refdb check-in: d988af5391 user: matt tags: dev
22:32
Fixed typo in cleanup-db check-in: e29acddac8 user: matt tags: dev
Changes

Modified txtdb/nada3/Second-sheet.dat from [897d8e51a6] to [2888a58afa].

1
2
3
4
5
6
7
8
9
10
11



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26



27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36











+
+
+















+
+
+




[2]
V2 X
V6 Y
V8 Z
V12 E
V15 B
V17 +

[A1]
V8 Z
V17 =
#
# Just a test really
#
V1 X
V3 X
V5 Y
V7 Y
V10 Z
V11 E
V13 E
V14 B
V16 B

[3]
V2 John,
V6 Tom
V8 Fred
V17 ~
#
# a deeply held belief is a danger to sanity
#
V4 X
row-11 Z
row-18 B

Modified txtdb/nada3/sxml/Second-sheet.sxml from [74cb91bdb6] to [4909e61f10].

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20












-
+







(http://www.gnumeric.org/v10.dtd:Sheet
  (@ (Visibility "GNM_SHEET_VISIBILITY_VISIBLE")
     (OutlineSymbolsRight "1")
     (OutlineSymbolsBelow "1")
     (HideZero "0")
     (HideRowHeader "0")
     (HideGrid "0")
     (HideColHeader "0")
     (GridColor "0:0:0")
     (DisplayOutlines "1")
     (DisplayFormulas "0"))
  (http://www.gnumeric.org/v10.dtd:MaxCol "3")
  (http://www.gnumeric.org/v10.dtd:MaxRow "19")
  (http://www.gnumeric.org/v10.dtd:MaxRow "21")
  (http://www.gnumeric.org/v10.dtd:Zoom "1")
  (http://www.gnumeric.org/v10.dtd:Names
    (http://www.gnumeric.org/v10.dtd:Name
      (http://www.gnumeric.org/v10.dtd:name "Print_Area")
      (http://www.gnumeric.org/v10.dtd:value "#REF!")
      (http://www.gnumeric.org/v10.dtd:position "A1"))
    (http://www.gnumeric.org/v10.dtd:Name
147
148
149
150
151
152
153
154

155
156
157
158
159
160
161
147
148
149
150
151
152
153

154
155
156
157
158
159
160
161







-
+







             (Underline "0")
             (StrikeThrough "0")
             (Script "0")
             (Italic "0")
             (Bold "0"))
          "Sans")))
    (http://www.gnumeric.org/v10.dtd:StyleRegion
      (@ (startRow "16") (startCol "3") (endRow "17") (endCol "3"))
      (@ (startRow "16") (startCol "3") (endRow "18") (endCol "3"))
      (http://www.gnumeric.org/v10.dtd:Style
        (@ (WrapText "0")
           (VAlign "2")
           (ShrinkToFit "0")
           (Shade "0")
           (Rotation "0")
           (PatternColor "0:0:0")
171
172
173
174
175
176
177
178

179
180
181
182
183
184
185
171
172
173
174
175
176
177

178
179
180
181
182
183
184
185







-
+







             (Underline "0")
             (StrikeThrough "0")
             (Script "0")
             (Italic "0")
             (Bold "0"))
          "Sans")))
    (http://www.gnumeric.org/v10.dtd:StyleRegion
      (@ (startRow "18") (startCol "3") (endRow "18") (endCol "3"))
      (@ (startRow "19") (startCol "3") (endRow "19") (endCol "3"))
      (http://www.gnumeric.org/v10.dtd:Style
        (@ (WrapText "0")
           (VAlign "2")
           (ShrinkToFit "0")
           (Shade "1")
           (Rotation "0")
           (PatternColor "FFFF:FFFF:0")
195
196
197
198
199
200
201
202

203
204
205
206
207
208
209
195
196
197
198
199
200
201

202
203
204
205
206
207
208
209







-
+







             (Underline "0")
             (StrikeThrough "0")
             (Script "0")
             (Italic "0")
             (Bold "0"))
          "Sans")))
    (http://www.gnumeric.org/v10.dtd:StyleRegion
      (@ (startRow "19") (startCol "3") (endRow "31") (endCol "3"))
      (@ (startRow "20") (startCol "3") (endRow "31") (endCol "3"))
      (http://www.gnumeric.org/v10.dtd:Style
        (@ (WrapText "0")
           (VAlign "2")
           (ShrinkToFit "0")
           (Shade "0")
           (Rotation "0")
           (PatternColor "0:0:0")
293
294
295
296
297
298
299

300
301



302
303
304
305


306
307

308
309

310
311
312
313
314
315
316
317
318
319
293
294
295
296
297
298
299
300
301

302
303
304
305
306
307

308
309
310

311
312

313
314
315
316
317
318
319
320
321
322
323







+

-
+
+
+



-
+
+

-
+

-
+










             (Script "0")
             (Italic "0")
             (Bold "0"))
          "Sans"))))
  (http://www.gnumeric.org/v10.dtd:Cols
    (@ (DefaultSizePts "48"))
    (http://www.gnumeric.org/v10.dtd:ColInfo (@ (Unit "64.01") (No "0")))
    (http://www.gnumeric.org/v10.dtd:ColInfo (@ (Unit "48") (No "1")))
    (http://www.gnumeric.org/v10.dtd:ColInfo
      (@ (Unit "48") (No "1") (Count "3"))))
      (@ (Unit "99") (No "2") (HardSize "1")))
    (http://www.gnumeric.org/v10.dtd:ColInfo
      (@ (Unit "227.2") (No "3") (HardSize "1"))))
  (http://www.gnumeric.org/v10.dtd:Rows
    (@ (DefaultSizePts "12.1"))
    (http://www.gnumeric.org/v10.dtd:RowInfo
      (@ (Unit "13.5") (No "0") (Count "20"))))
      (@ (Unit "13.5") (No "0") (Count "21")))
    (http://www.gnumeric.org/v10.dtd:RowInfo (@ (Unit "12.1") (No "21"))))
  (http://www.gnumeric.org/v10.dtd:Selections
    (@ (CursorRow "0") (CursorCol "0"))
    (@ (CursorRow "11") (CursorCol "3"))
    (http://www.gnumeric.org/v10.dtd:Selection
      (@ (startRow "0") (startCol "0") (endRow "0") (endCol "0"))))
      (@ (startRow "11") (startCol "3") (endRow "11") (endCol "3"))))
  (http://www.gnumeric.org/v10.dtd:SheetLayout (@ (TopLeft "A1")))
  (http://www.gnumeric.org/v10.dtd:Solver
    (@ (ProgramR "0")
       (ProblemType "0")
       (NonNeg "1")
       (ModelType "0")
       (MaxTime "60")
       (MaxIter "1000")
       (Discr "0")
       (AutoScale "0"))))

Modified txtdb/nada3/sxml/sheets.sxml from [af21813b45] to [b435b563f6].

24
25
26
27
28
29
30
31

32
33

34
35
36
37
38
39
40
24
25
26
27
28
29
30

31
32

33
34
35
36
37
38
39
40







-
+

-
+







   (http://www.gnumeric.org/v10.dtd:Attribute
     (http://www.gnumeric.org/v10.dtd:type "4")
     (http://www.gnumeric.org/v10.dtd:name "WorkbookView::is_protected")
     (http://www.gnumeric.org/v10.dtd:value "FALSE")))
 (urn:oasis:names:tc:opendocument:xmlns:office:1.0:document-meta
   (@ (urn:oasis:names:tc:opendocument:xmlns:office:1.0:version "1.2"))
   (urn:oasis:names:tc:opendocument:xmlns:office:1.0:meta
     (http://purl.org/dc/elements/1.1/:date "2013-07-19T05:53:19Z")
     (http://purl.org/dc/elements/1.1/:date "2013-07-26T04:34:47Z")
     (urn:oasis:names:tc:opendocument:xmlns:meta:1.0:creation-date
       "2013-07-19T05:52:56Z")))
       "2013-07-26T04:34:08Z")))
 (http://www.gnumeric.org/v10.dtd:Calculation
   (@ (MaxIterations "100")
      (ManualRecalc "0")
      (IterationTolerance "0.001")
      (FloatRadix "2")
      (FloatDigits "53")
      (EnableIteration "1")))
52
53
54
55
56
57
58
59

52
53
54
55
56
57
58

59







-
+
        (http://www.gnumeric.org/v10.dtd:Cols "256"))
     "RunsToDo")
   (http://www.gnumeric.org/v10.dtd:SheetName
     (@ (http://www.gnumeric.org/v10.dtd:Rows "65536")
        (http://www.gnumeric.org/v10.dtd:Cols "256"))
     "RunsToLock"))
 (http://www.gnumeric.org/v10.dtd:Geometry (@ (Width "1440") (Height "647")))
 (http://www.gnumeric.org/v10.dtd:UIData (@ (SelectedTab "2"))))
 (http://www.gnumeric.org/v10.dtd:UIData (@ (SelectedTab "1"))))

Modified txtdb/txtdb.scm from [17687f31ae] to [a0d9ce564b].

62
63
64
65
66
67
68

69

70
71
72
73
74
75
76
62
63
64
65
66
67
68
69

70
71
72
73
74
75
76
77







+
-
+







		     #f))
	       dat)))

(define (string->safe-filename str)
  (string-substitute (regexp " ") "_" str #t))

(define (sheet->refdb dat targdir)
  (let* ((comment-rx  (regexp "^#CMNT\\d+\\s*"))
  (let* ((sheet-name  (car (find-section dat 'http://www.gnumeric.org/v10.dtd:Name)))
	 (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))
	 (rownums     (make-hash-table))  ;; num -> name
	 (colnums     (make-hash-table))  ;; num -> name
	 (cols        (make-hash-table))) ;; name -> ( (name val) ... )
101
102
103
104
105
106
107

108




109
110
111
112
113
114
115
102
103
104
105
106
107
108
109

110
111
112
113
114
115
116
117
118
119
120







+
-
+
+
+
+







			      (list (cdr c)(car c)))
			    (hash-table->alist colnums))))
      (with-output-to-file (conc targdir "/" sheet-name ".dat")
	(lambda ()
	  (for-each (lambda (colname)
		      (print "[" colname "]")
		      (for-each (lambda (row)
				  (let ((key (car row))
				  (print (car row) " " (cadr row)))
					(val (cadr row)))
				    (if (string-search comment-rx key)
					(print val)
					(print key " " val))))
				(reverse (hash-table-ref cols colname)))
		      (print))
		    (sort (hash-table-keys cols)(lambda (a b)
						  (let ((colnum-a (assoc a ref-colnums))
							(colnum-b (assoc b ref-colnums)))
						    (if (and colnum-a colnum-b)
							(< (cadr colnum-a)(cadr colnum-b))
179
180
181
182
183
184
185
186
187
188
189
190






191
192
193
194
195
196
197
198
199


200



201
202
203
204
205
206
207
184
185
186
187
188
189
190





191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207

208
209
210
211
212
213
214
215
216
217







-
-
-
-
-
+
+
+
+
+
+









+
+
-
+
+
+







    (file-copy tmpgzf fname #t)
    (delete-file tmpgzf)))

(define (hash-table-reverse-lookup ht val)
  (hash-table-fold ht (lambda (k v res)(if (equal? v val) k res)) #f))

(define (read-dat fname)
  (let ((section-rx (regexp "^\\[(.*)\\]\\s*$"))
	(comment-rx (regexp "^#.*"))          ;; This means a cell name cannot start with #
	(cell-rx    (regexp "^(\\S+) (.*)$")) ;; One space only for the cellname content separator 
	(blank-rx   (regexp "^\\s*$"))
	(inp        (open-input-file fname)))
  (let ((section-rx  (regexp "^\\[(.*)\\]\\s*$"))
	(comment-rx  (regexp "^#.*"))          ;; This means a cell name cannot start with #
	(cell-rx     (regexp "^(\\S+) (.*)$")) ;; One space only for the cellname content separator 
	(blank-rx    (regexp "^\\s*$"))
	(inp         (open-input-file fname))
	(cmnt-indx   (make-hash-table)))
    (let loop ((inl     (read-line inp))
	       (section #f)
	       (res     '()))
      (if (eof-object? inl)
	  (begin
	    (close-input-port inp)
	    (reverse res))
	  (regex-case
	   inl 
	   (comment-rx _          (let ((curr-indx (+ 1 (hash-table-ref/default cmnt-indx section 0))))
				    (hash-table-set! cmnt-indx section curr-indx)
	   (comment-rx _          (loop (read-line inp) section res))
				    (loop (read-line inp)
					  section 
					  (cons (list (conc "#CMNT" curr-indx) section inl) res))))
	   (blank-rx   _          (loop (read-line inp) section res))
	   (section-rx (x sname)  (loop (read-line inp) 
					sname 
					res))
	   (cell-rx   (x k v)     (loop (read-line inp)
					section
					(cons (list k section v) res)))
340
341
342
343
344
345
346
347


348
349
350
351
352
353
354
355
356


357
358
359
360
361
362
363
364
365
366
367
368
369
370







371
372
373
374
375
376
377
350
351
352
353
354
355
356

357
358
359
360
361
362
363
364
365
366

367
368
369
370
371
372
373
374
375







376
377
378
379
380
381
382
383
384
385
386
387
388
389







-
+
+








-
+
+







-
-
-
-
-
-
-
+
+
+
+
+
+
+







			#f
			(loop (car tal)(cdr tal)))))))
	#f)))

;; call with proc = car to get row names
;; call with proc = cadr to get col names
(define (get-rowcol-names path sheet proc)
  (let ((fname (conc path "/" sheet ".dat")))
  (let ((fname (conc path "/" sheet ".dat"))
	(cmnt-rx (regexp "^#CMNT\\d+\\s*")))
    (if (file-exists? fname)
	(let ((dat (read-dat fname)))
	  (if (null? dat)
	      '()
	      (let loop ((hed (car dat))
			 (tal (cdr dat))
			 (res '()))
		(let* ((row-name (proc hed))
		       (newres (if (not (member row-name res))
		       (newres (if (and (not (member row-name res))
					(not (string-search cmnt-rx row-name)))
				   (cons row-name res)
				   res)))
		  (if (null? tal)
		      (reverse newres)
		      (loop (car tal)(cdr tal) newres))))))
	'())))

(define (get-col-names path sheet)
  (let ((fname (conc path "/" sheet ".dat")))
    (if (file-exists? fname)
	(let ((dat (read-dat fname)))
	  (if (null? dat)
	      #f
	      (map cadr dat))))))
;; (define (get-col-names path sheet)
;;   (let ((fname (conc path "/" sheet ".dat")))
;;     (if (file-exists? fname)
;; 	(let ((dat (read-dat fname)))
;; 	  (if (null? dat)
;; 	      #f
;; 	      (map cadr dat))))))

(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"))
	(refdb-export path tmpf))
    (let ((pid (process-run "gnumeric" (list tmpf))))