File: foo_module.tcl

package info (click to toggle)
setools 2.4-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 9,680 kB
  • ctags: 8,392
  • sloc: ansic: 96,778; tcl: 21,447; yacc: 4,341; makefile: 874; lex: 304; sh: 164
file content (274 lines) | stat: -rw-r--r-- 12,228 bytes parent folder | download
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#############################################################
#  foo_module.tcl  
# -----------------------------------------------------------
#  Copyright (C) 2003-2006 Tresys Technology, LLC
#  see file 'COPYING' for use and warranty information 
#
#  Requires tcl and tk 8.3+, with BWidgets
#  Author: <don.patterson@tresys.com, mayerf@tresys.com>
# -----------------------------------------------------------
#
##
## This module is not a real analysis, but a simple same that also 
## serves as a guide to what one must do when creating a module via
## embedded comments.  This file also serves as a template for when
## new analysis modules are created.  To include this module in apol,
## add the file name to the ANALYSIS-MODULES variable in the 
## Makefile.
#
# All this module does is display an entry box and echo the contents
# of that box.

##############################################################
# ::Apol_Analysis_foo module namespace
##############################################################

## The name space should following the convention of Apol_Analysis_XXX, where
## XXX is a 3-4 letter name for the analysis.
namespace eval Apol_Analysis_foo {
	# Display variables
    	variable entry_string_display	""
    	# State variables
    	variable entry_string_state	""
    	
    	# Global widgets
    	variable sEntry	""
    	variable descriptive_text "This is an analysis template dialog that simply displays the content of the \
		entry box.  The purpose of this analysis is to provide a template for new analyses."
    	
## Within the namespace command for the module, you must call Apol_Analysis::register_analysis_modules,
## the first argument is the namespace name of the module, and the second is the
## descriptive display name you want to be displayed in the GUI selection box.
    	Apol_Analysis::register_analysis_modules "Apol_Analysis_foo" "Analysis template example (foo)"
}

## Apol_Analysis_XXX::initialize is called when the tool first starts up.  The
## analysis has the oppertunity to do any additional initialization it must  do
## that wasn't done in the initial namespace eval command.
# ------------------------------------------------------------------------------
#  Command Apol_Analysis_foo::initialize
# ------------------------------------------------------------------------------
proc Apol_Analysis_foo::initialize { } {    
     	
     	return 0
}

## Command Apol_Analysis_XXX::do_analysis is the principal interface command.
## The GUI will call this when the module is to perform it's analysis.  The
## module should know how to get its own option information (the options
## are displayed via ::display_mod_options
# ------------------------------------------------------------------------------
#  Command Apol_Analysis_foo::do_analysis
# ------------------------------------------------------------------------------
proc Apol_Analysis_foo::do_analysis { results_frame } {  
	variable entry_string_display	
	if {$entry_string_display == "" } {
		return -code error "You must enter text in the entry box."
	}
     	set results_box [text $results_frame.results_box -bg white -wrap none -font {$ApolTop::text_font }]
     	pack $results_box -expand yes -fill both
     	$results_box insert 0.0 $entry_string_display
     	return 0
} 

## Apol_Analysis_XXX::close must exist; it is called when a policy is closed.
## Typically you should reset any context or option variables you have.
# ------------------------------------------------------------------------------
#  Command Apol_Analysis_foo::close
# ------------------------------------------------------------------------------
proc Apol_Analysis_foo::close { } {   
	Apol_Analysis_foo::clear_results
     	return 0
} 

## Apol_Analysis_XXX::open must exist; it is called when a policy is opened.
# ------------------------------------------------------------------------------
#  Command Apol_Analysis_foo::open
# ------------------------------------------------------------------------------
proc Apol_Analysis_foo::open { } {   	
     	return 0
} 

## Apol_Analysis_XXX::clear_results is called ????????
# ------------------------------------------------------------------------------
#  Command Apol_Analysis_foo::clear_results
# ------------------------------------------------------------------------------
proc Apol_Analysis_foo::clear_results { } {   
	Apol_Analysis_foo::reset_variables  	
     	return 0
} 

## Apol_Analysis_XXX::display_mod_options is called by the GUI to display the
## analysis options interface the analysis needs.  Each module must know how
## to display their own options, as well bind appropriate commands and variables
## with the options GUI.  opts_frame is the name of a frame in which the options
## GUI interface is to be packed.
# ------------------------------------------------------------------------------
#  Command Apol_Analysis_foo::display_mod_options
# ------------------------------------------------------------------------------
proc Apol_Analysis_foo::display_mod_options { opts_frame } {    
	Apol_Analysis_foo::reset_variables 	
     	Apol_Analysis_foo::create_options $opts_frame
     	return 0
} 

## Apol_Analysis_XXX::get_analysis_info is called by the GUI to retrieve
# descriptive text, which provides it's analysis information. Each module must
# return descriptive text.
# ------------------------------------------------------------------------------
#  Command Apol_Analysis_foo::get_analysis_info
# ------------------------------------------------------------------------------
proc Apol_Analysis_foo::get_analysis_info {} {
     	return $Apol_Analysis_foo::descriptive_text
} 

## Apol_Analysis_XXX::load_query_options is called by the GUI to 
## set the query options in the GUI with the given query options. 
# ------------------------------------------------------------------------------
#  Command Apol_Analysis_foo::load_query_options
# ------------------------------------------------------------------------------
proc Apol_Analysis_foo::load_query_options { file_channel parentDlg } {   
	variable entry_string_state
     	
     	set query_options ""
        while {[eof $file_channel] != 1} {
		gets $file_channel line
		set tline [string trim $line]
		# Skip empty lines and comments
		if {$tline == "" || [string compare -length 1 $tline "#"] == 0} {
			continue
		}
		set query_options [lappend query_options $tline]
	}
	if {$query_options == ""} {
		return -code error "No query parameters were found."
	}
	# Re-format the query options list into a string where all elements are seperated
	# by a single space. Then split this string into a list using the space as the delimeter.	
	set query_options [split [join $query_options " "]]
	
     	if {[lindex $query_options 0] != "\{\}"} {
     		set entry_string_state [lindex $query_options 0]
     	}
     	Apol_Analysis_foo::update_display_variables
     	# After updating any display variables, must configure widgets accordingly
	return 0
} 

## Apol_Analysis_XXX::save_query_options is called by the GUI to save
## the analysis's current result query parameters to a file on disk. 
# ------------------------------------------------------------------------------
#  Command Apol_Analysis_foo::save_query_options
#	- module_name - name of the analysis module
#	- file_channel - file channel identifier of the query file to write to.
#	- file_name - name of the query file
# ------------------------------------------------------------------------------
proc Apol_Analysis_foo::save_query_options {module_name file_channel file_name} {  
	variable entry_string_display 
	   	
     	set options [list $entry_string_display]
     
     	puts $file_channel "$module_name"
	puts $file_channel "$options"
     	return 0
} 

## Apol_Analysis_XXX::get_current_results_state is called by the GUI to get
## the analysis's current result query parameters. The GUI calls this when it plans to
## switch views and wants to restore the current query options displayed.
## This proc should return a list containing whatever context the analysis
## wants to store so that it can restore the options when asked to.  The
## GUI will treat the returned list as opaque and will not attempt to 
## interpret the list.
# ------------------------------------------------------------------------------
#  Command Apol_Analysis_foo::get_current_results_state
# ------------------------------------------------------------------------------
proc Apol_Analysis_foo::get_current_results_state { } {  
	variable entry_string_display 
	variable sEntry    	
     	return [list $sEntry $entry_string_display]
} 

## Apol_Analysis_XXX::set_display_to_results_state is called to reset the options
## or any other context that analysis needs when the GUI switches back to an
## existing analysis.  options is a list that we created in a previous 
## get_current_results_state() call.
# ------------------------------------------------------------------------------
#  Command Apol_Analysis_foo::set_display_to_results_state
# ------------------------------------------------------------------------------
proc Apol_Analysis_foo::set_display_to_results_state { query_options } {     	
     	variable entry_string_state
     	variable sEntry 
     	
     	# results tab widget variables
     	set sEntry [lindex $query_options 0]
     	# query options variables
     	set entry_string_state [lindex $query_options 1]
     	Apol_Analysis_foo::update_display_variables
     	# After updating any display variables, must configure widgets accordingly
     	return 0
} 

## Apol_Analysis_foo::free_results_data is called to destroy subwidgets 
#  under a results frame as well as free any data associated with them.
#  query_options is a list that we created in a previous get_current_results_state() call,
#  from which we extract the subwidget pathnames for the results frame.
# ------------------------------------------------------------------------------
#  Command Apol_Analysis_foo::free_results_data
# ------------------------------------------------------------------------------
proc Apol_Analysis_foo::free_results_data {query_options} {  
	set sEntry [lindex $query_options 1]
	
	if {[winfo exists $sEntry]} {
		set Apol_Analysis_foo::entry_string_display ""
		destroy $sEntry
	}
	return 0
}

#################################################################################
#################################################################################
##
## The rest of these procs are not interface procedures, but rather internal
## functions to this analysis.
##
#################################################################################
#################################################################################

# ------------------------------------------------------------------------------
#  Command Apol_Analysis_foo::reset_variables
# ------------------------------------------------------------------------------
proc Apol_Analysis_foo::reset_variables { } {   
	set Apol_Analysis_foo::entry_string_display	"" 
	set Apol_Analysis_foo::entry_string_state	""
	set sEntry ""
     	return 0
} 
 
# ------------------------------------------------------------------------------
#  Command Apol_Analysis_foo::update_display_variables
# ------------------------------------------------------------------------------
proc Apol_Analysis_foo::update_display_variables {  } {
	variable entry_string_display
	set entry_string_display $Apol_Analysis_foo::entry_string_state
	return 0
}

# ------------------------------------------------------------------------------
#  Command Apol_Analysis_foo::create_options
# ------------------------------------------------------------------------------
proc Apol_Analysis_foo::create_options { options_frame } {
	variable sEntry
	
	set entry_frame [frame $options_frame.entry_frame]
	set sLabel [Label $entry_frame.sLabel -text "Enter Text:"]
    	set sEntry [Entry $entry_frame.sEntry -textvariable Apol_Analysis_foo::entry_string_display -width 25 -background white]
        	
	pack $entry_frame -side left -fill y -padx 10
	pack $sLabel $sEntry -side top -anchor nw
	return 0	
}

proc Apol_Analysis_foo::get_short_name {} {
    return "Foo"
}