Module: nagvis Branch: nagvis-1.5 Commit: 786ecf0ab44f2fb88cb079d49d278a7a94a63140 URL: http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=commit;h=786ecf0ab44f2fb88cb079d49d278a7a94a63140
Author: Lars Michelsen <[email protected]> Date: Fri Dec 10 17:44:57 2010 +0100 Refactored map config parsing code to be better readable --- ChangeLog | 4 + share/server/core/classes/GlobalMapCfg.php | 118 ++++++++++++++++------------ 2 files changed, 72 insertions(+), 50 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6d5c7d8..10605b4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +1.5.7 +Core + * Refactored map configuration parsing code + 1.5.6 Core diff --git a/share/server/core/classes/GlobalMapCfg.php b/share/server/core/classes/GlobalMapCfg.php index bce7d61..dd20d13 100644 --- a/share/server/core/classes/GlobalMapCfg.php +++ b/share/server/core/classes/GlobalMapCfg.php @@ -1561,57 +1561,75 @@ class GlobalMapCfg { for($l = 0; $l < $iNumLines; $l++) { // Remove spaces, newlines, tabs, etc. (http://de.php.net/rtrim) $file[$l] = rtrim($file[$l]); + // Don't recognize empty lines - if($file[$l] != '') { - // Don't recognize comments and empty lines, do nothing with ending delimiters - $sFirstChar = substr(ltrim($file[$l]), 0, 1); - if($sFirstChar != ';' && $sFirstChar != '#' && $sFirstChar != '}') { - // Determine if this is a new object definition - if(strpos($file[$l], 'define') !== FALSE) { - // If only the global section should be read break the loop after the global section - if($onlyGlobal == 1 && $types['global'] == 1) { - break; - } - - $iDelimPos = strpos($file[$l], '{', 8); - $sObjType = substr($file[$l], 7, ($iDelimPos - 8)); - - if(isset($sObjType) && isset(self::$validConfig[$sObjType])) { - // This is a new definition and it's a valid one - - // Get the type index - $iObjTypeId = $types[$sObjType]; - - $this->mapConfig[$sObjType][$iObjTypeId] = Array( - 'type' => $sObjType, - 'object_id' => $iObjId - ); - - // increase type index - $types[$sObjType]++; - - // Increase the map object id to identify the object on the map - $iObjId++; - } else { - // unknown object type - new GlobalMessage('ERROR', $this->CORE->getLang()->getText('unknownObject',Array('TYPE' => $sObjType, 'MAPNAME' => $this->name))); - return FALSE; - } - } else { - // This is another attribute - $iDelimPos = strpos($file[$l], '='); - $sKey = trim(substr($file[$l],0,$iDelimPos)); - $sValue = trim(substr($file[$l],($iDelimPos+1))); - - if(!isset($ignoreKeys[$sKey])) { - if(isset($createArray[$sKey])) { - $this->mapConfig[$sObjType][$iObjTypeId][$sKey] = explode(',', $sValue); - } else { - $this->mapConfig[$sObjType][$iObjTypeId][$sKey] = $sValue; - } - } - } - } + if($file[$l] == '') + continue; + + // Don't recognize comments and empty lines, do nothing with ending delimiters + $sFirstChar = substr(ltrim($file[$l]), 0, 1); + if($sFirstChar == ';' || $sFirstChar == '#') + continue; + + // This is an object ending. Reset the object type and skip to next line + if($sFirstChar == '}') { + $sObjType = ''; + $iObjTypeId = 0; + + // If only the global section should be read break the loop after the global section + if($onlyGlobal == 1 && $types['global'] == 1) + break; + else + continue; + } + + // Determine if this is a new object definition + if(strpos($file[$l], 'define') !== FALSE) { + $sObjType = substr($file[$l], 7, (strpos($file[$l], '{', 8) - 8)); + if(!isset($sObjType) || !isset(self::$validConfig[$sObjType])) { + new GlobalMessage('ERROR', $this->CORE->getLang()->getText('unknownObject',Array('TYPE' => $sObjType, 'MAPNAME' => $this->name))); + return FALSE; + } + + // This is a new definition and it's a valid one + + // Get the type index + $iObjTypeId = $types[$sObjType]; + + $this->mapConfig[$sObjType][$iObjTypeId] = Array( + 'type' => $sObjType, + 'object_id' => $iObjId + ); + + // increase type index + $types[$sObjType]++; + + // Increase the map object id to identify the object on the map + $iObjId++; + + continue; + } + + // This is another attribute. But it is only ok to proceed here when + // there is an open object + if($sObjType === '') { + new GlobalMessage('ERROR', + $this->CORE->getLang()->getText('Attribute definition out of object. In map [MAPNAME] at line #[LINE].', + Array('MAPNAME' => $this->name, 'LINE' => $l+1))); + return FALSE; + } + + $iDelimPos = strpos($file[$l], '='); + $sKey = trim(substr($file[$l],0,$iDelimPos)); + $sValue = trim(substr($file[$l],($iDelimPos+1))); + + if(isset($ignoreKeys[$sKey])) + continue; + + if(isset($createArray[$sKey])) { + $this->mapConfig[$sObjType][$iObjTypeId][$sKey] = explode(',', $sValue); + } else { + $this->mapConfig[$sObjType][$iObjTypeId][$sKey] = $sValue; } } ------------------------------------------------------------------------------ Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL, new data types, scalar functions, improved concurrency, built-in packages, OCI, SQL*Plus, data movement tools, best practices and more. http://p.sf.net/sfu/oracle-sfdev2dev _______________________________________________ Nagvis-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nagvis-checkins
