Megatest

Diff
Login

Differences From Artifact [17b7d4ebc9]:

To Artifact [0fff6fff93]:


18
19
20
21
22
23
24

25
26
27
28
29
30
31

;;======================================================================

(declare (unit configfmod))
(declare (uses debugprint))
(declare (uses commonmod))
(declare (uses processmod))


(use regex regex-case)

(module configfmod
*	

(import scheme







>







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

;;======================================================================

(declare (unit configfmod))
(declare (uses debugprint))
(declare (uses commonmod))
(declare (uses processmod))
(declare (uses mtargs))

(use regex regex-case)

(module configfmod
*	

(import scheme
44
45
46
47
48
49
50
51


52
53
54
55
56
57
58
	regex
	regex-case
	
	)

(import debugprint
	commonmod
	processmod)



;; Run a shell command and return the output as a string
(define (shell cmd)
  (let* ((output (process:cmd-run->list cmd))
	 (res    (car output))
	 (status (cadr output)))
    (if (equal? status 0)







|
>
>







45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
	regex
	regex-case
	
	)

(import debugprint
	commonmod
	processmod
	(prefix mtargs args:)
	)

;; Run a shell command and return the output as a string
(define (shell cmd)
  (let* ((output (process:cmd-run->list cmd))
	 (res    (car output))
	 (status (cadr output)))
    (if (equal? status 0)
428
429
430
431
432
433
434

435



436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451


















452
453
454
455
      exn
    (begin
      (debug:print 0 *default-log-port* "read of alist " fname " failed. exn=" exn)
      #f)
    (configf:alist->config
     (with-input-from-file fname read))))


  



;; convert hierarchial list to ini format
;;
(define (configf:config->ini data)
  (map 
   (lambda (section)
     (let ((section-name (car section))
	   (section-dat  (cdr section)))
       (print "\n[" section-name "]")
       (map (lambda (dat-pair)
	      (let* ((var (car dat-pair))
		     (val (cadr dat-pair))
		     (fname (if (> (length dat-pair) 2)(caddr dat-pair) #f)))
		(if fname (print "# " var "=>" fname))
		(print var " " val)))
	    section-dat))) ;;       (print "section-dat: " section-dat))
   (hash-table->alist data)))




















)








>
|
>
>
>
















>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
      exn
    (begin
      (debug:print 0 *default-log-port* "read of alist " fname " failed. exn=" exn)
      #f)
    (configf:alist->config
     (with-input-from-file fname read))))

(define read-config (lambda ()(assert #f "FATAL: read-config proc not set!")))

(define (read-config-set! proc)
  (set! read-config proc))

;; convert hierarchial list to ini format
;;
(define (configf:config->ini data)
  (map 
   (lambda (section)
     (let ((section-name (car section))
	   (section-dat  (cdr section)))
       (print "\n[" section-name "]")
       (map (lambda (dat-pair)
	      (let* ((var (car dat-pair))
		     (val (cadr dat-pair))
		     (fname (if (> (length dat-pair) 2)(caddr dat-pair) #f)))
		(if fname (print "# " var "=>" fname))
		(print var " " val)))
	    section-dat))) ;;       (print "section-dat: " section-dat))
   (hash-table->alist data)))

;; pathenvvar will set the named var to the path of the config
(define (find-and-read-config fname #!key (environ-patt #f)(given-toppath #f)(pathenvvar #f))
  (let* ((curr-dir   (current-directory))
         (configinfo (find-config fname toppath: given-toppath))
	 (toppath    (car configinfo))
	 (configfile (cadr configinfo))
	 (set-fields (lambda (curr-section next-section ht path)
		       (let ((field-names (if ht (common:get-fields ht) '()))
			     (target      (or (getenv "MT_TARGET")(args:get-arg "-reqtarg")(args:get-arg "-target"))))
			 (debug:print-info 9 *default-log-port* "set-fields with field-names=" field-names " target=" target " curr-section=" curr-section " next-section=" next-section " path=" path " ht=" ht)
			 (if (not (null? field-names))(keys:target-set-args field-names target #f))))))
    (if toppath (change-directory toppath)) 
    (if (and toppath pathenvvar)(setenv pathenvvar toppath))
    (let ((configdat  (if configfile 
			  (read-config configfile #f #t environ-patt: environ-patt post-section-procs: (list (cons "^fields$" set-fields)) #f))))
      (if toppath (change-directory curr-dir))
      (list configdat toppath configfile fname))))


)