From c3300623efba74c4e3dcb380bed77a673ae9581c Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 25 Oct 2005 12:35:09 +0000 Subject: [PATCH] Update for ppdManager. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@1688 594d385d-05f5-0310-b6e9-bd551577e9d8 --- include/class_ppdManager.inc | 137 +++++++++++++++++++++++++++++++++-- 1 file changed, 132 insertions(+), 5 deletions(-) diff --git a/include/class_ppdManager.inc b/include/class_ppdManager.inc index aa8cdcbd0..f93181951 100644 --- a/include/class_ppdManager.inc +++ b/include/class_ppdManager.inc @@ -43,6 +43,133 @@ class ppdManager } + function saveProperties($ppdFile, $properties) + { + echo "
";
+		print_r ($properties);
+		echo "
"; + } + + + function loadProperties($ppdFile) + { + $group= ""; + $option= ""; + $properties= array(); + + $fh= fopen ($ppdFile, 'r'); + while (!feof($fh)) { + + /* Read line */ + $line= fgets($fh, 256); + if (strlen($line) >= 256){ + trigger_error(_('Parsing PPD file %s failed - line too long. Trailing characters have been ignored'), E_USER_WARNING); + } + + /* Trigger for option groups */ + if (preg_match('/^\*OpenGroup:/i', $line)){ + + /* Sanity checks */ + if ($group != ""){ + trigger_error(_('Nested groups are not supported!'), E_USER_WARNING); + continue; + } + if (in_array($group, $properties)){ + trigger_error(_('Group name not unique!'), E_USER_WARNING); + continue; + } + + // TODO: Symbol values are not supported yet! + if (preg_match('/\^/', $line)){ + trigger_error(_('Symbol values are not supported yet!'), E_USER_WARNING); + } + $complete= preg_replace('@^\*OpenGroup:\s+(.*)$@i', '\1', $line); + $complete= trim($complete, '"'); + if (preg_match('@/@', $complete)){ + $group= trim(preg_replace('@^\*OpenGroup:\s+"?([^/]+)/.*$@i', '\1', $line)); + $name = preg_replace('@^\*OpenGroup:\s+"?[^/]+/([^/]+).*$@i', '\1', $line); + } else { + $group= $complete; + $name = $complete; + } + $properties[$group]= array('_name' => $name); + continue; + } + if (preg_match("/^\*CloseGroup:\s+\"?$group\"?/i", $line)){ + $group= ""; + continue; + } + + /* Trigger for options */ + if (preg_match('/^\*OpenUI\s+/i', $line)){ + + /* Sanity check */ + if ($option != ""){ + trigger_error(_('Nested options are not supported!'), E_USER_WARNING); + continue; + } + + // TODO: Symbol values are not supported yet! + if (preg_match('/\^/', $line)){ + trigger_error(_('Symbol values are not supported yet!'), E_USER_WARNING); + } + $complete= preg_replace('@^\*OpenUI\s+(.*)$@i', '\1', $line); + $complete= trim($complete, '"'); + if (preg_match('@/@', $complete)){ + $option= trim(preg_replace('@^\*OpenUI\s+([^/]+)/.*$@i', '\1', $line)); + $name = trim(preg_replace('@^\*OpenUI\s+[^/]+/([^/]+).*$@i', '\1', $line)); + } else { + $option= trim($complete); + $name = trim($complete); + } + + /* Extract option type */ + $type= trim(preg_replace('/^[^:]+:\s+/', '', $line)); + $name= preg_replace('/:.*$/', '', $name); + $option= preg_replace('/:.*$/', '', $option); + + // TODO: PickMany is not supported yet! + if (preg_match('/PickMany/i', $type)){ + trigger_error(_('PickMany is not supported yet!'), E_USER_WARNING); + } + + $properties[$group][$option]= array('_name' => $name, '_type' => $type); + continue; + } + /* Show interest for option parsing */ + if ($option != ""){ + + $eoption= preg_replace('@\*@', '', $option); + + /* Close section? */ + if (preg_match("@^\*CloseUI:\s+\*$eoption@i", $line)){ + $option= ""; + continue; + } + + /* Default value? */ + if (preg_match("@^\*Default$eoption:@", $line)){ + $c= preg_replace("@^\*Default$eoption:\s+@", "", $line); + $properties[$group][$option]['_default']= trim(trim($c, '"')); + continue; + } + + /* Possible value? */ + if (preg_match("@^\*$eoption\s+@", $line)){ + #*PageSize Letter/US Letter: "<>setpagedevice" + $c= preg_replace("@^\*$eoption\s+([^/]+).*$@", "$1", $line); + $d= preg_replace("@^\*$eoption\s+[^/]+/([^:]+).*$@", "$1", $line); + $properties[$group][$option][trim($c)]= trim($d); + continue; + } + } + + } + fclose ($fh); + + return ($properties); + } + function loadDescription($ppdFile) { $model= ""; @@ -52,17 +179,17 @@ class ppdManager while (!feof($fh)) { /* Read line */ - $line= fgets($fh, 4096); - if (strlen($line) >= 4095){ - trigger_error(_('Parsing PPD file %s faild - line too long. Trailing characters have been ignored'), E_USER_WARNING); + $line= fgets($fh, 256); + if (strlen($line) >= 256){ + trigger_error(_('Parsing PPD file %s failed - line too long. Trailing characters have been ignored'), E_USER_WARNING); } /* Extract interesting informations */ if (preg_match('/^\*Manufacturer:/i', $line)){ - $manufacturer= preg_replace('/^\*Manufacturer:\s+"([^"]+)".*$/i', '\1', $line); + $manufacturer= preg_replace('/^\*Manufacturer:\s+"?([^"]+)"?.*$/i', '\1', $line); } if (preg_match('/^\*ModelName:/i', $line)){ - $model= preg_replace('/^\*ModelName:\s+"([^"]+)".*$/i', '\1', $line); + $model= preg_replace('/^\*ModelName:\s+"?([^"]+)"?.*$/i', '\1', $line); } /* Got everything we need? Skip rest for speed reasons... */ -- 2.30.2