Browse Source

* forgot to commit (part of r16923)

git-svn-id: trunk@16977 -
Jonas Maebe 14 years ago
parent
commit
9d033909df
2 changed files with 141 additions and 0 deletions
  1. 1 0
      .gitattributes
  2. 140 0
      packages/cocoaint/utils/source/docset.php

+ 1 - 0
.gitattributes

@@ -1586,6 +1586,7 @@ packages/cocoaint/utils/parser.php svneol=native#text/plain
 packages/cocoaint/utils/patches/cocoa-coredata-webkit.patch svneol=native#text/plain
 packages/cocoaint/utils/patches/uikit-3.2.patch svneol=native#text/plain
 packages/cocoaint/utils/patches/uikit-4.2.patch svneol=native#text/plain
+packages/cocoaint/utils/source/docset.php svneol=native#text/plain
 packages/cocoaint/utils/source/objp.php svneol=native#text/plain
 packages/cocoaint/utils/source/objp_base.php svneol=native#text/plain
 packages/cocoaint/utils/source/utilities.php svneol=native#text/plain

+ 140 - 0
packages/cocoaint/utils/source/docset.php

@@ -0,0 +1,140 @@
+<?
+
+// Returns an array of sub-directories for $directory
+function sub_directories ($directory, &$directories) {
+	
+	if (file_exists($directory)) {
+		$directories[] = $directory;
+	} else {
+		$directories = array();
+	}
+	
+	if ($handle = @opendir($directory)) {
+		while (($file = readdir($handle)) !== false) {
+			if (($file != '.') && ($file != '..') && ($file[0] != '.')) {
+				$path = "$directory/$file";
+				
+				if (is_dir($path)) sub_directories($path, $directories);
+			}
+		}
+		closedir($handle);
+	}
+}
+
+
+class DocSetParser {
+
+	var $docset;
+	var $methods = array();
+
+	// Parse a single reference file
+	private function parse ($path, $class) {
+		$method = null;
+		$methods = array();
+		
+		if ($lines = @file($path)) {
+			foreach ($lines as $line) {
+
+				// Parse instance method description
+				if ($method) {
+					if (preg_match("/<span.*data-abstract='(.*)'>/i", $line, $captures)) {
+						$methods[$method] = strip_tags($captures[1]);
+						$method = null;
+					}
+				}
+
+				// Found type definition tag
+				if (preg_match("/<h3 class=\"tight jump typeDef\">(\w+)<\/h3><p class=\"abstract\">(.*)<\/p>/i", $line, $captures)) {
+					
+					// Read until the end </p> because I can't get preg_match to do this
+					$text = substr($captures[2], 0, (stripos($captures[2], "</p>")));
+					if (!$text) $text = $captures[2];
+					
+					$methods[$captures[1]] = strip_tags($text);
+				}
+				
+				// Found constant tag
+				if (preg_match("/<code class=\"jump constantName\">(\w+)<\/code><\/dt><dd><p>(.*)<\/p>/i", $line, $captures)) {
+					//print_r($captures);
+					// Read until the end </p> because I can't get preg_match to do this
+					$text = substr($captures[2], 0, (stripos($captures[2], "</p>")));
+					if (!$text) $text = $captures[2];
+					
+					$methods[$captures[1]] = strip_tags($text);
+				}
+				
+				// Found instance method tag
+				if (preg_match("<a href=\"#//apple_ref/occ/(instm|intfm|intfp|clm)+/([a-zA-Z:_]+)/([a-zA-Z:_]+)\">", $line, $captures)) {
+					//print_r($captures);
+					if ($captures[2] == $class) {
+						$method = $captures[3];
+						continue;
+					}
+				}
+
+			}
+
+		} else {
+			print("* Warning: Can't find the docset at $path.\n");
+		}
+		
+		return $methods;
+	}
+	
+	// Parses the reference index.html file for the path to the reference html file
+	private function parse_reference_index ($path) {
+		$lines = file($path);
+		foreach ($lines as $line) {
+			if (preg_match("/<meta id=\"refresh\" http-equiv=\"refresh\" CONTENT=\"0; URL=(.*)\">/i", $line, $captures)) {
+				return $captures[1];
+			}
+		}
+	}
+	
+	public function parse_directory ($paths) {
+
+		foreach ($paths as $path) {
+			$path = $this->docset."/Contents/Resources/Documents/documentation".$path;
+			
+			if (file_exists($path)) {
+				sub_directories($path, $sub_directories);
+				foreach ($sub_directories as $directory) {
+					$name = basename($directory);
+					if (preg_match("/^(\w+)_(class|protocol)$/i", $name, $captures)) {
+						
+						$class = $captures[1];
+						$sub_path = $this->parse_reference_index("$directory/index.html");
+						
+						if ($methods = $this->parse("$directory/$sub_path", $class)) {
+							$this->methods[$class] = $methods;
+						}
+					}
+				}
+			} else {
+				print("* Warning: The docset at $path can't be found.\n");
+			}
+		}
+		
+		return true;
+	}
+		
+	function __construct ($docset) {
+		$this->docset = $docset;
+	}
+}
+
+
+// Cocoa
+//$path = "/Users/ryanjoseph/Desktop/com.apple.adc.documentation.AppleSnowLeopard.CoreReference.docset";
+//$folders = array("/Cocoa/Reference");
+
+// UIKIT
+// $path = "/Users/ryanjoseph/Desktop/com.apple.adc.documentation.AppleiOS4_2.iOSLibrary.docset";
+//$folders = array("/UIKit/Reference");
+
+//$parser = new DocSetParser($path);
+//$parser->parse_directory($folders);
+//print_r($parser->methods);
+
+
+?>