List:Commits« Previous MessageNext Message »
From:jon Date:September 9 2008 1:06pm
Subject:svn commit - mysqldoc@docsrva: r11740 - trunk/dynamic-docs/command-optvars/ndb/errors
View as plain text  
Author: jstephens
Date: 2008-09-09 13:06:00 +0200 (Tue, 09 Sep 2008)
New Revision: 11740

Log:

NDB error extractor:
  Okay, now we can parse all the necessary rows and get them as:
                        lines of text - arrays - or XML <row>s

  Also cleaned out a bunch of dead/testing code + unnecessary comments



Modified:
   trunk/dynamic-docs/command-optvars/ndb/errors/write-errors.php


Modified: trunk/dynamic-docs/command-optvars/ndb/errors/write-errors.php
===================================================================
--- trunk/dynamic-docs/command-optvars/ndb/errors/write-errors.php	2008-09-09 02:22:36 UTC
(rev 11739)
+++ trunk/dynamic-docs/command-optvars/ndb/errors/write-errors.php	2008-09-09 11:06:00 UTC
(rev 11740)
Changed blocks: 4, Lines Added: 63, Lines Deleted: 86; 5697 bytes

@@ -48,59 +48,23 @@
     
     $temp = '';
     
-    while($i < $length)
+    foreach($inputs as $input)
     {        
-      #  Fetch the next line of input
-      $input = $inputs[$i];
-      
-      #  Did we reach the beginning of the error declaration yet?
-      #    yes: Did we reach the end yet? (qv. ->)
-      #    no: 
-      #      -  Does current line mark the beginning?
-      #      -  go on to the next line
-      
+      $line = preg_replace("/\/\*.*\*\//", '', $input);
+            
       if($begin)
       {
-      
-        #  Did we reach the end yet?
-        #    yes: break out; return array 
-        #    no:  Does current line mark the end?
-        #           yes: break out; return array
-        #           no:  process line
-        
         $end = $end || substr($input, -2, 2) == '};'; 
         
         if(!$end)
         {
-          #  This is where we get a complete line matching the pattern
-          #   /^\{\w+\,\s*\w+\,\s*\w+\,\s*\"w\+\"}\,?$/
-          #  and append it as the next element of the $outputs array
-          
-          #  Start by appending the current input line to the $temp line
-          #  (which is empty if we've just added an element to $outputs)
-          
-            $temp .= $input;
-            
-          #  Does the current input line end in '}' or '},'?
-          
-            if
-            (
-              substr($input, -2, 2) == '},'
-              ||
-              substr($input, -1) == '}'
-            )
-            
-          
-          #          yes: 
-          #            -  Append the $temp line to the $outputs array
-          #            -  Clear the $temp line
-          
-            {
-              $outputs []= preg_replace('/\/\*.*\*\//', '', $temp);
-              $temp = '';
-            }
-          
-                                
+          $temp .= $input;
+        
+          if(substr($temp, -2, 2) == '},' || substr($temp, -1) == '}')
+          {
+            $outputs []= preg_replace("/\/\*.*\*\//", '', $temp);
+            $temp = '';
+          }                     
         }  #  end if(!$end)
       }  
     # if($begin) ...

@@ -110,18 +74,17 @@
       }
       
       $i++;
-    }  #  end while
+    }  #  end foreach
   
     return $outputs;
   }  #  end function
-  
-  
-  
-  
-  /*
+
+
+  #  --!TESTED--
   function lineToXMLRowElement($line)
   {
     global $tags;
+    global $xmldoc;
     
     $matches = preg_grep('/\{\s*(.*)\, (.*)\, (.*)\, "(.*)"\s*\}\,?/', $line);
       

@@ -131,7 +94,7 @@
     {
       $entry = $xmldoc->createElement('entry');    
       $child = $xmldoc->createElement('error' . $tags[$i]);      
-      $text = $xmldoc->createTextNode(matches[$i]);
+      $text = $xmldoc->createTextNode($matches[$i]);
       
       $child->appendChild($text);
       $entry->appendChild($child);      

@@ -140,56 +103,70 @@
       
     return $row;
   }
-*/
 
   function lineToXMLRow($line)
   {
     global $tags;
     
-    $m = preg_match('/\{\s*(.*)\, (.*)\, (.*)\, "(.*)"\s*\}\,?/', $line);
+    preg_match('/\{\s*(.*)\, (.*)\, (.*)\,\s?"(.*)"\s*\}\,?/', $line, $m);
     
+    #  $line = preg_replace("/\{(.+)\}\,?/", "$1", $line);
+    
+    #  print_r($m);
+    
     $row = "
-            <row>
-              <entry><errorcode>{$m[1]}</errorcode></entry>
-              <entry><errorname>{$m[2]}</errorname></entry>
-              <entry><errortype>{$m[3]}</errortype></entry>
-              <entry><errortext>{$m[4]}</errortext></entry>
-            </row>";
+      <row>
+        <entry><errorname>{$m[1]}</errorcode></entry>
+        <entry><errorname>{$m[2]}</errorname></entry>
+        <entry><errortype>{$m[3]}</errortype></entry>
+        <entry><errortext>{$m[4]}</errortext></entry>
+      </row>
+            ";
+            
+    return $row;
   }
-
-  $lines = get_valid_lines(  array_map('trim', file($errorfile))  );
   
-  #  print_r($lines);
+  function lineToArray($line)
+  {
+    global $tags;
+    
+    preg_match('/\{\s*(.*)\, (.*)\, (.*)\,\s?"(.*)"\s*\}\,?/', $line, $m);
+    
+    $c = count($m);
+    
+    $output = array();
+    
+    for($i = 1; $i < $c; $i++)
+      $output[$tags[$i]] = $m[$i];
+    
+    return $output;
+  }
   
-  foreach($lines as $line)
-    echo "\n" . lineToXMLRow($line) . "\n";
-  
-  /*
-  $tgroup = $xmldoc->createElement('tgroup');  
-  $tgroup->setAttribute('cols', count($colwidths));
-  
-  foreach($colwidths as $colwidth)
+  function arrayToXMLRow($array)
   {
-    $colspec = $xmldoc->createElement('colspec');
-    $colspec->setAttribute('', "$colwidth*");
+    $output = "\n<row>";
     
-    $tgroup->appendChild($colspec);
+    foreach($array as $tag=>$value)
+      $output .=
"\n<entry><error$tag>$value</error$tag></entry>";
+      
+    return $output .= "\n</row>";
   }
+
+  $lines = get_valid_lines(  array_map('trim', file($errorfile))  );
   
-  $tbody = $xmldoc->createElement('tbody');
+  echo "\nTesting get_valid_lines()...\n";
+  print_r($lines);
   
-  #  !!!
+  $errors = array();
   
-  $rows = getErrorsByTypeAsXMLRows($xmldoc, $type, $lines);
+  echo "\nTesting lineToArray()...\n";
+  foreach($lines as $line)
+    $errors []= lineToArray($line);
   
-  foreach($rows as $row)
-    $tbody->appendChild($row);
+  print_r($errors);
   
-  $tgroup->appendChild($tbody);
-    
-  $table = $xmldoc->createElement('informaltable');
-  $table->appendChild($tgroup);
-  */
-  
+  echo "\nTesting arrayToXMLRow()...\n";
+  foreach($errors as $error)
+    echo arrayToXMLRow($error);
 ?>
 


Thread
svn commit - mysqldoc@docsrva: r11740 - trunk/dynamic-docs/command-optvars/ndb/errorsjon9 Sep