From cb9ea5d47269896fbf4fde8b1cc7e2742105524f Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 21 Mar 2007 06:56:34 +0000 Subject: [PATCH] Updated class tree to combine multiple comments git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5842 594d385d-05f5-0310-b6e9-bd551577e9d8 --- include/sieve/class_My_Tree.inc | 34 ++++++++++++++++++++---- include/sieve/templates/element_size.tpl | 2 +- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/include/sieve/class_My_Tree.inc b/include/sieve/class_My_Tree.inc index 8525ee32d..c94d34cef 100644 --- a/include/sieve/class_My_Tree.inc +++ b/include/sieve/class_My_Tree.inc @@ -87,6 +87,14 @@ class My_Tree extends Tree /* Get node */ $node = $this->nodes_[$node_id]; + /* Get last element class */ + $last_class = ""; + if(count($this->mode_stack)){ + $key = key($this->mode_stack); + $tmp = array_reverse($this->mode_stack[$key]['ELEMENTS']); + $last_class = $tmp[key($tmp)]['class']; + } + /* This closes the last mode */ if($node['class'] == "block-start"){ $tmp = array_pop($this->mode_stack); @@ -107,14 +115,30 @@ class My_Tree extends Tree $this->handle_elements($tmp,$node_id); } - /* Handle comments */ - if($node['class'] == "comment"){ - $this->mode_stack[] = array("TYPE" => $node['class']); - $rewoke_last = TRUE; + + /* Comments require special attention. + * We do not want to create a single comment element + * foreach each "#comment" string found in the script. + * Sometimes comments are used like this + * # This is a comment + * # and it still is a comment + * # ... + * So we combine them to one single comment. + */ + if($last_class != "comment" && $node['class'] == "comment"){ + $tmp =array_pop($this->mode_stack); + $this->handle_elements($tmp,$node_id); + $this->mode_stack[] = array("TYPE" => $node['class']); + } + + if($last_class == "comment" && $node['class'] != "comment"){ + $tmp =array_pop($this->mode_stack); + $this->handle_elements($tmp,$node_id); } + /* Handle identifiers */ - $identifiers = array("else","if","elsif","end","reject","redirect","vacation","keep","discard","comment","fileinto","require","stop"); + $identifiers = array("else","if","elsif","end","reject","redirect","vacation","keep","discard","fileinto","require","stop"); if($node['class'] == "identifier" && in_array($node['text'],$identifiers)){ $this->mode_stack[] = array("TYPE" => $node['text']); } diff --git a/include/sieve/templates/element_size.tpl b/include/sieve/templates/element_size.tpl index a42d77243..fa6a92fbb 100644 --- a/include/sieve/templates/element_size.tpl +++ b/include/sieve/templates/element_size.tpl @@ -1,7 +1,7 @@
-{t}Size{/t} + {t}Size{/t} {if $LastError != ""} {$LastError}
-- 2.30.2