File: parsefile.php

package info (click to toggle)
dojo 1.10.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 97,980 kB
  • ctags: 10,348
  • sloc: php: 10,616; xml: 3,429; java: 3,098; sql: 928; sh: 484; pascal: 205; perl: 182; makefile: 77; python: 45; sed: 37; ruby: 10
file content (97 lines) | stat: -rw-r--r-- 2,123 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php

//	Simple single-file doc validation utility, using our php-based `jsdoc` parser. 
//	To be used as a post-commit hook?
// 
//	to use:
//		php -q parsefile.php dojox/data/AndOrReadStore.js
//
//	exits normally (status 0) if OK, with status 255 if failed, other values are from PHP untrapped.
//
//	add --debug to last argument to see output data, eg:
//
//		php -q parsefile.php dijit/_Widget.js --debug
//
//	scan all files prior to running generate/makeCix (considerably faster to detect fatal parser-breaking errors)
//
//		php -q parsefile.php --all

include_once('lib/parser2/dojo2.inc');
$allfiles = dojo_get_files();

function doc_passes($ns, $file, $debug){
	try{
		$ret = doc_test($ns, $file, $debug);
		return $ret;
	}catch (Exception $e){
		return false;
	}
}

function doc_test($ns, $file, $debug){
	// the testing of a single file. this is where the actual testing goes.
	
	try{
		$ret = true;
		$data = dojo_get_contents($ns, $file);
		// test other things. like we're expecting at the _very_ least a $data['#provides'] key?
		if(empty($data['#provides'])){
			if($debug){ 
				print "Warning: no provide() determined. [" . $ns . "/" . $file . "]\n"; 
			}
			$ret = false;	 
		}else{
			if(count($data['#provides']) > 1){
				if($debug){
					print "Warning: Multiple provides() found?\n";
					$ret = false;
				}
			}
		}
		
		if(count($data) == 0){
			if($debug){ print "Error: No data found. [" . $ns . "/" . $file . "]"; }
			$ret = false;
		}else{
		    
		}
		
		return $ret;
	}catch (Exception $e){
		print "Error: Exception trapped processing [" . $ns . "/" . $file . "]\nException:\n";
		print $e;
		return false;
	}
}

if($argc){
	
	$argfile = $argv[1];
	$debug = in_array("--debug", $argv);
	if($argfile == "--all"){

		$debug = true;
		$haserror = false;
		foreach($allfiles as $set){
			list($ns, $file) = $set;
			if(!doc_passes($ns, $file, $debug)){
				$haserror = true;
			}
		}

		if($haserror){
			die(255);
		}

	}else{

		$parts = explode("/", $argfile);
		$ns = array_shift($parts);
		$file = implode("/", $parts);
		if(!doc_passes($ns, $file, $debug)){
			die(255);
		}

	}

}