summaryrefslogtreecommitdiff
path: root/lib/lib/settings.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lib/settings.tcl')
-rw-r--r--[-rwxr-xr-x]lib/lib/settings.tcl35
1 files changed, 22 insertions, 13 deletions
diff --git a/lib/lib/settings.tcl b/lib/lib/settings.tcl
index 3c50466..8dd1c53 100755..100644
--- a/lib/lib/settings.tcl
+++ b/lib/lib/settings.tcl
@@ -2,7 +2,7 @@
# Part of MCU 8051 IDE ( http://mcu8051ide.sf.net )
############################################################################
-# Copyright (C) 2007-2009 by Martin Ošmera #
+# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin Ošmera #
# martin.osmera@gmail.com #
# #
# This program is free software; you can redistribute it and#or modify #
@@ -21,6 +21,11 @@
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
############################################################################
+# >>> File inclusion guard
+if { ! [ info exists _SETTINGS_TCL ] } {
+set _SETTINGS_TCL _
+# <<< File inclusion guard
+
# --------------------------------------------------------------------------
# DESCRIPTION
# Implements interface to program settings (which are stored in a file)
@@ -28,7 +33,7 @@
class Settings {
common dir_sep [file separator] ;# Directory separator (eg. '/')
- common count 0 ;# Counter of instances
+ common settings_count 0 ;# Counter of instances
private variable isEmpty 1 ;# Is settings array empty
private variable isReady 0 ;# Is interface ready
@@ -42,10 +47,10 @@ class Settings {
# @parm String configDir - Path to directory with settings file
# @parm String configFileName - Name of file with settings
constructor {configDir configFileName} {
- incr count ;# increment instance conter
+ incr settings_count ;# increment instance conter
# Incalize object variables
- set configArray "::Settings::S$count" ;# Array of settings
+ set configArray "::Settings::S${settings_count}" ;# Array of settings
set directory [string trimright $configDir "/\/"] ;# Path to directory with settings file
set filename [string trimleft $configFileName "/\/"] ;# Name of file with settings
set fileFullPath "${directory}${dir_sep}${filename}" ;# Full name of settings file
@@ -54,7 +59,7 @@ class Settings {
if {![file exists $fileFullPath]} {
if {[catch {
file mkdir $directory
- close [open $fileFullPath w 420]
+ close [open $fileFullPath w 0640]
}]} then {
return
} else {
@@ -65,7 +70,7 @@ class Settings {
} else {
if {$::MICROSOFT_WINDOWS || ([file readable $fileFullPath] && [file writable $fileFullPath])} {
set isReady 1
- } {
+ } else {
return
}
}
@@ -129,7 +134,7 @@ class Settings {
# Set variable isEmpty
if {[array size $configArray] != 0} {
set isEmpty 0
- } {
+ } else {
set isEmpty 1
}
@@ -147,7 +152,7 @@ class Settings {
}
# Local variables
- set configFile [open $fileFullPath w 420] ;# ID of config file chanel
+ set configFile [open $fileFullPath w 0640] ;# ID of config file chanel
set categories {general} ;# Name of current category
# Determinate list of categories
@@ -172,7 +177,7 @@ class Settings {
# Determinate key
regsub {^[^/]*/} $fullKey {} key
# Determinate value
- set value [subst "\$$configArray\(\$fullKey\)"]
+ set value [subst -nocommands "\$$configArray\(\$fullKey\)"]
regsub -all "\n" $value "\a" value
# Save key and value
puts $configFile "$key=\"$value\""
@@ -212,7 +217,7 @@ class Settings {
if {[i_contains $key]} {
unset "$configArray\($key\)"
return 1
- } {
+ } else {
return 0
}
}
@@ -233,7 +238,7 @@ class Settings {
private method i_contains {key} {
if {[array names $configArray -exact $key] == {}} {
return 0
- } {
+ } else {
return 1
}
}
@@ -258,8 +263,8 @@ class Settings {
# Check if the given key is defined
if {[i_contains $key]} {
- return [subst "\$$configArray\(\$key\)"]
- } {
+ return [subst -nocommands "\$$configArray\(\$key\)"]
+ } else {
return $default
}
}
@@ -291,3 +296,7 @@ class Settings {
return 1
}
}
+
+# >>> File inclusion guard
+}
+# <<< File inclusion guard