aboutsummaryrefslogtreecommitdiff
path: root/tcl_tests/getengine.tcl
blob: 49176c0c9f83a199b0ec16625d6d87f9b0fae1e9 (plain)
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
37
#!/usr/bin/tclsh
lappend auto_path .
package require ossltest

proc getConfigLine {var {section ""}} {
   global config
   if {[string length $section]} {
   		if {[regexp -indices "\n\\s*\\\[\\s*$section\\s*\\\]\\s*\n" $config start]} {
			set start [lindex $start 1]
		} else {
			return -code error "Section $section is not found"
		}	
	} else {
		set start 0
	}
	if {[regexp -indices "\n\\s*\\\[\[^\n\]+\\\]\\s*\n" [string range $config $start end] end]} {
		set end [expr $start+[lindex $end 0]]
	} else {
		set end end
	}
	if {![regexp "\n\\s*$var\\s*=\\s*(\\S\[^\n\]+?)\\s*\n" "\n[string range $config $start $end]" => value]} {
		return -code error "No variable $var in section $section"
	}	
	return $value
}

set config [getConfig] 

set openssl_def [getConfigLine openssl_conf]

set engine_section [getConfigLine {[^#]+}  [getConfigLine engines $openssl_def ]]

puts [getConfigLine engine_id $engine_section]