home *** CD-ROM | disk | FTP | other *** search
-
- class sambaParser {
- inherit genericParser
-
- constructor { dirDef confDoc } {
- genericParser::constructor $dirDef $confDoc
- } {
- }
-
- method parseLine { text }
-
- method beginSection
-
-
- method processDirective
- method processStructure
- method loadValue
- method getElements
- method getElement
- method getDirectiveValue
- method getDirectiveName
- method isSpecialCase
- method processSpecialCase
- }
-
-
- body sambaParser::parseLine { data } {
-
- set data [string trim $data]
- if {[regexp "^ *;+" $data] ||\
- [regexp "^ *#+" $data] ||[regexp "^ *$" $data]} {
-
- return
- }
-
-
- if [regexp {^\[(.*)\]} $data match name] {
-
- beginSection $name share
- } else {
-
-
- processDirective $data
- }
- }
-
-
- body sambaParser::beginSection { value class } {
- set currentContainer \
- [$xmlConf addContainer $rootContainer $value $class]
- }
-
-
-
- body sambaParser::processDirective { text } {
-
-
- set dirName [string tolower [ getDirectiveName $text ]]
-
- if [ isSpecialCase $dirName ] {
-
-
- processSpecialCase $dirName $text
- return
- }
-
-
-
- if [llength [set dirObject \
- [$dirDefinition getDirectiveByName $dirName]]] {
-
-
- switch [$dirObject getXuiClass] {
- string - choice - boolean - number {
- if [llength [set existingDir \
- [$xmlConf getDirectiveByName \
- $currentContainer $dirName]]] {
- set xuiObj $existingDir
- } else {
- set xuiObj [$dirObject clone]
- $xmlConf addDirective $xuiObj $currentContainer
- }
-
- set value [getDirectiveValue $text]
-
- loadValue $xuiObj $value
- return
- } structure {
- set value {}
- regexp {([^ ]*) (.*)} $text dummy name value
- processStructure $xuiObj $value
- return
- }
- }
- } else {
-
- set xuiUnknown [ xuiString ::#auto ]
- $xuiUnknown setName $dirName
- $xuiUnknown setValue $text
- $xuiUnknown addClass unknownDirective
- $xmlConf addDirective $xuiUnknown $currentContainer
- return
- }
- error "Not recognized, not a special case $text"
- }
-
-
- body sambaParser::processStructure { xuiObj text } {
- set components [$xuiObj components]
-
- set structureComponents [ $this getElements $text]
- set idx 0
- foreach component $components {
- switch [$component getXuiClass] {
- string - choice - boolean - number {
- loadValue $component [lindex $structureComponents $idx]
- } default {
- error "Component in a structure of unrecognized class"
- }
- }
- incr idx
- }
- }
-
-
-
-
-
- body sambaParser::getDirectiveName { text } {
- return [lindex [::sambautils::getElements $text] 0]
-
- }
- body sambaParser::getDirectiveValue { text } {
- return [lindex [::sambautils::getElements $text] 1]
- }
-
- body sambaParser::isSpecialCase { dirName } {
- return [info exists specialCaseMapping($dirName)]
- }
-
- body sambaParser::processSpecialCase { dirName text } {
- $specialCaseMapping($dirName) parse $text $this\
- $dirDefinition $xmlConf $currentContainer
-
- }
- body sambaParser::loadValue { dirObject value } {
- switch [$dirObject getXuiClass] {
- string - number {
- $dirObject setValue [string trim $value]
- } choice {
- $dirObject selectItem [string trim $value]
- } boolean {
- switch [string tolower [string trim $value]] {
- on - yes - true - 1 {
- $dirObject setValue
- } off - false - no - 0 {
- $dirObject clearValue
- } default {
- error "Boolean with value different from on/off: [$dirObject getName] $value"
- }
- }
- }
- }
- }
-
-
-
-