]> git.mxchange.org Git - friendica.git/blob - util/createdoxygen.php
Some more small documentation stuff
[friendica.git] / util / createdoxygen.php
1 #!/usr/bin/php
2 <?php
3 if (count($_SERVER["argv"]) < 2)
4         die("usage: createdoxygen.php file\n");
5
6 $file = $_SERVER["argv"][1];
7 $data = file_get_contents($file);
8
9 $lines = explode("\n", $data);
10
11 $previous = "";
12
13 foreach ($lines AS $line) {
14         $line = rtrim(trim($line, "\r"));
15
16         if (strstr(strtolower($line), "function")) {
17                 $detect = strtolower(trim($line));
18                 $detect = implode(" ", explode(" ", $detect));
19
20                 $found = false;
21
22                 if (substr($detect, 0, 9) == "function ")
23                         $found = true;
24
25                 if (substr($detect, 0, 17) == "private function ")
26                         $found = true;
27
28                 if (substr($detect, 0, 23) == "public static function ")
29                         $found = true;
30
31                 if (substr($detect, 0, 10) == "function (")
32                         $found = false;
33
34                 if ($found and (trim($previous) == "*/"))
35                         $found = false;
36
37                 if ($found and !strstr($detect, "{"))
38                         $found = false;
39
40                 if ($found) {
41                         echo add_documentation($line);
42                 }
43         }
44         echo $line."\n";
45         $previous = $line;
46 }
47
48 function add_documentation($line) {
49
50         $trimmed = ltrim($line);
51         $length = strlen($line) - strlen($trimmed);
52         $space = substr($line, 0, $length);
53
54         $block = $space."/**\n".
55                 $space." * @brief \n".
56                 $space." *\n"; /**/
57
58
59         $left = strpos($line, "(");
60         $line = substr($line, $left + 1);
61
62         $right = strpos($line, ")");
63         $line = trim(substr($line, 0, $right));
64
65         if ($line != "") {
66                 $parameters = explode(",", $line);
67                 foreach ($parameters AS $parameter) {
68                         $parameter = trim($parameter);
69                         $splitted = explode("=", $parameter);
70
71                         $block .= $space." * @param ".trim($splitted[0], "& ")."\n";
72                 }
73                 if (count($parameters) > 0)
74                         $block .= $space." *\n";
75         }
76
77         $block .= $space." * @return \n".
78                 $space." */\n";
79
80         return $block;
81 }
82 ?>