<commit_before># Copyright (C) 2003 Tresys Technology, LLC
# see file 'COPYING' for use and warranty information 

# TCL/TK GUI for SE Linux policy analysis
# Requires tcl and tk 8.3+, with BWidgets


##############################################################
# ::Apol_PolicyConf
#  
# The policy.conf Rules page
###############################################################
namespace eval Apol_PolicyConf {
	variable textbox_policyConf
	
	# wrap procs
	variable policy_conf_wrap_proc	"Apol_PolicyConf::wrap_proc_policy_conf"
	variable orig_cursor		""
	# used to indicate whether changes to policy conf box allowed
	variable mod_disabled		1
	variable lineno_tag		LINENO
	variable selected_tag		SELECTED

}

##################################################################
# ::wrap_proc_policy_conf
#  	- This overrides the default cmds
#		for text so we can track dirty bit
# NOTE: This proc MUST have same name as $policy_conf_wrap_proc var; it will
# be renamed in create
proc Apol_PolicyConf::wrap_proc_policy_conf { cmd args } {
	switch $cmd {
		insert	- 
		delete	{
			if { $Apol_PolicyConf::mod_disabled == 1 } {
				return 0
			}
		} 
		mark 	{	
			if { [string compare -length 10 $args "set insert"]  == 0 } {
				# in this case, go ahead and directly call the upleve cmd so that
				# the insertion mark is set, allowing us to determine its location.
				# Because we call uplevel, we MUST return from this case.
				uplevel "::${Apol_PolicyConf::textbox_policyConf}_" $cmd $args
				set lpos [$Apol_PolicyConf::textbox_policyConf index insert]
				Apol_PolicyConf::update_positionStatus $lpos
				return 
			}
		} 
	}
	# don't use a return after this!
	uplevel "::${Apol_PolicyConf::textbox_policyConf}_" $cmd $args
}

# ----------------------------------------------------------------------------------------
#  Command Apol_PolicyConf::set_Focus_to_Text
#
#  Description: 
# ----------------------------------------------------------------------------------------
proc Apol_PolicyConf::set_Focus_to_Text {} {
	focus $Apol_PolicyConf::textbox_policyConf
	set ApolTop::policyConf_lineno "Line [$Apol_PolicyConf::textbox_policyConf index insert]"
	
	return 0
}

############################################################################
# ::update_positionStatus
#  	- updates cursor position status infor
# 
proc Apol_PolicyConf::update_positionStatus { pos } { 
	if { [catch {scan $pos" %d.%d" line col} err ] } {
		puts stderr "update_positionStatus: Problem scanning position ($pos): $err"
		return -1
	}
	set ApolTop::policyConf_lineno "Line $line"
	return 0
}

############################################################################
# ::create
#  	- Create policy.conf tab
# 
proc Apol_PolicyConf::create {nb} {
	variable textbox_policyConf
	
	# Create tab for displaying the policy.conf file.
	set frame [$nb insert end $ApolTop::policy_conf_tab -text "policy.conf"]
	# policy.conf window
	set sw [ScrolledWindow $frame.sw -auto none]
	set textbox_policyConf [text [$sw getframe].text -bg white -wrap none]
	$sw setwidget $textbox_policyConf
	rename $textbox_policyConf "::${textbox_policyConf}_"
    	rename $Apol_PolicyConf::policy_conf_wrap_proc "::$textbox_policyConf"
	
    	pack $sw -side left -expand yes -fill both
	
	return 0
}

proc Apol_PolicyConf::open { file } {
	Apol_PolicyConf::display_policy_conf $file
			
	return 0
}

proc Apol_PolicyConf::close { } { 
	variable textbox_policyConf
	variable mod_disabled
	
	# Re-enable textbox and then delete it's contents
        set mod_disabled 0
        $textbox_policyConf delete 0.0 end
        set mod_disabled 1
        	      
	return 0
}

###################################################################
# Apol_PolicyConf::display_policy_conf
#  	- Display the policy.conf file
# 
proc Apol_PolicyConf::display_policy_conf { path } {
   	variable textbox_policyConf
   	variable mod_disabled
   
   	set mod_disabled 0
   	$textbox_policyConf delete 0.0 end
   	
	# Make sure the "policy.conf" file exists and is readable by the user.
	if { [file exists $path] } {
		if { [file readable $path] } {
			set file_channel [::open $path r]
			set data [read $file_channel]
			::close $file_channel
	
			$textbox_policyConf insert end $data 
		} else {
			$textbox_policyConf insert end "<policy.conf file exists but is not readable>"
		}<commit_msg>New proc for freeing call back procs. For now, it does nothing but return 0.<commit_after># Copyright (C) 2003 Tresys Technology, LLC
# see file 'COPYING' for use and warranty information 

# TCL/TK GUI for SE Linux policy analysis
# Requires tcl and tk 8.3+, with BWidgets


##############################################################
# ::Apol_PolicyConf
#  
# The policy.conf Rules page
###############################################################
namespace eval Apol_PolicyConf {
	variable textbox_policyConf
	
	# wrap procs
	variable policy_conf_wrap_proc	"Apol_PolicyConf::wrap_proc_policy_conf"
	variable orig_cursor		""
	# used to indicate whether changes to policy conf box allowed
	variable mod_disabled		1
	variable lineno_tag		LINENO
	variable selected_tag		SELECTED

}

##################################################################
# ::wrap_proc_policy_conf
#  	- This overrides the default cmds
#		for text so we can track dirty bit
# NOTE: This proc MUST have same name as $policy_conf_wrap_proc var; it will
# be renamed in create
proc Apol_PolicyConf::wrap_proc_policy_conf { cmd args } {
	switch $cmd {
		insert	- 
		delete	{
			if { $Apol_PolicyConf::mod_disabled == 1 } {
				return 0
			}
		} 
		mark 	{	
			if { [string compare -length 10 $args "set insert"]  == 0 } {
				# in this case, go ahead and directly call the upleve cmd so that
				# the insertion mark is set, allowing us to determine its location.
				# Because we call uplevel, we MUST return from this case.
				uplevel "::${Apol_PolicyConf::textbox_policyConf}_" $cmd $args
				set lpos [$Apol_PolicyConf::textbox_policyConf index insert]
				Apol_PolicyConf::update_positionStatus $lpos
				return 
			}
		} 
	}
	# don't use a return after this!
	uplevel "::${Apol_PolicyConf::textbox_policyConf}_" $cmd $args
}

# ----------------------------------------------------------------------------------------
#  Command Apol_PolicyConf::set_Focus_to_Text
#
#  Description: 
# ----------------------------------------------------------------------------------------
proc Apol_PolicyConf::set_Focus_to_Text {} {
	focus $Apol_PolicyConf::textbox_policyConf
	set ApolTop::policyConf_lineno "Line [$Apol_PolicyConf::textbox_policyConf index insert]"
	
	return 0
}

############################################################################
# ::update_positionStatus
#  	- updates cursor position status infor
# 
proc Apol_PolicyConf::update_positionStatus { pos } { 
	if { [catch {scan $pos" %d.%d" line col} err ] } {
		puts stderr "update_positionStatus: Problem scanning position ($pos): $err"
		return -1
	}
	set ApolTop::policyConf_lineno "Line $line"
	return 0
}

############################################################################
# ::create
#  	- Create policy.conf tab
# 
proc Apol_PolicyConf::create {nb} {
	variable textbox_policyConf
	
	# Create tab for displaying the policy.conf file.
	set frame [$nb insert end $ApolTop::policy_conf_tab -text "policy.conf"]
	# policy.conf window
	set sw [ScrolledWindow $frame.sw -auto none]
	set textbox_policyConf [text [$sw getframe].text -bg white -wrap none]
	$sw setwidget $textbox_policyConf
	rename $textbox_policyConf "::${textbox_policyConf}_"
    	rename $Apol_PolicyConf::policy_conf_wrap_proc "::$textbox_policyConf"
	
    	pack $sw -side left -expand yes -fill both
	
	return 0
}

proc Apol_PolicyConf::open { file } {
	Apol_PolicyConf::display_policy_conf $file
			
	return 0
}

proc Apol_PolicyConf::close { } { 
	variable textbox_policyConf
	variable mod_disabled
	
	# Re-enable textbox and then delete it's contents
        set mod_disabled 0
        $textbox_policyConf delete 0.0 end
        set mod_disabled 1
        	      
	return 0
}

proc Apol_PolicyConf::free_call_back_procs { } {
  
	return 0
}

###################################################################
# Apol_PolicyConf::display_policy_conf
#  	- Display the policy.conf file
# 
proc Apol_PolicyConf::display_policy_conf { path } {
   	variable textbox_policyConf
   	variable mod_disabled
   
   	set mod_disabled 0
   	$textbox_policyConf delete 0.0 end
   	
	# Make sure the "policy.conf" file exists and is readable by the user.
	if { [file exists $path] } {
		if { [file readable $path] } {
			set file_channel [::open $path r]
			set data [read $file_channel]
			::close $file_channel
	
			$textbox_policyConf insert end $data 
		} else {
			$textbox_policyConf insert end "<policy.conf file exists but is not readable>"
		}
{'fraction_non_alphanumeric': 0.2068769859282796, 'fraction_numerical': 0.005901044030866999, 'mean_word_length': 3.5948905109489053, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1957095', 'n_tokens_mistral': 2835, 'n_tokens_neox': 2585, 'n_words': 776}