blob: d85d5f86b4ebd08b0e9b392521f2aa5e36decd08 [file] [log] [blame]
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +00001#!/usr/bin/php
2<?
3require_once("functions.php");
4
5function get_group($text)
6{
7 return str_replace(array(" ", "/"), "_", $text);
8}
9
10$input = file_get_contents($argv[1]);
11
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +000012$mypath = $_SERVER['SCRIPT_FILENAME'];
13$mypath = substr($mypath, 0, strrpos($mypath, "/"))."/";
14
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +000015$inh = parse_documentation($input);
16
17@mkdir("output");
18
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +000019$index_tpl = file_get_contents($mypath."index.tpl");
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +000020
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +000021$group_data = array();
Maurus Cuelenaereae569c62008-10-09 09:57:21 +000022$group_tpl = get_tpl_part(array("%GROUP_START%", "%GROUP_END%"), $index_tpl);
23$func_tpl = get_tpl_part(array("%FUNCTION_START%", "%FUNCTION_END%"), $index_tpl);
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +000024
25foreach($inh as $group_name => $group)
26{
27 if(strlen($group_name) > 0)
28 {
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +000029 $func_data = array();
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +000030 foreach($group as $el_name => $el)
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +000031 $func_data[] = str_replace(array("%GROUP%", "%FUNCTION%", "%FUNCTION_NAME%"),
32 array(get_group($group_name), get_func($el_name), $el_name),
33 $func_tpl);
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +000034
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +000035 $tmp = str_replace("%GROUP_NAME%", ucwords($group_name), $group_tpl);
36 $group_data[] = ereg_replace("%FUNCTION_START%.*%FUNCTION_END%", implode("\n", $func_data), $tmp);
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +000037 }
38}
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +000039
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +000040$index_tpl = ereg_replace("%GROUP_START%.*%GROUP_END%", implode("", $group_data), $index_tpl);
41file_put_contents("output/index.html", $index_tpl);
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +000042
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +000043$menu_tpl = file_get_contents($mypath."menu.tpl");
Maurus Cuelenaereae569c62008-10-09 09:57:21 +000044$group_tpl = get_tpl_part(array("%GROUP_START%", "%GROUP_END%"), $menu_tpl);
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +000045
46$menu = array();
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +000047foreach($inh as $group_name => $group)
48{
49 if(strlen($group_name) > 0)
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +000050 $menu[strtolower($group_name)] = str_replace(array("%GROUP%", "%GROUP_NAME%"),
51 array(get_group($group_name), ucwords($group_name)),
52 $group_tpl);
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +000053}
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +000054ksort($menu);
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +000055
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +000056$menu = ereg_replace("%GROUP_START%.*%GROUP_END%", implode("", $menu), $menu_tpl);
57
58$section_tpl = file_get_contents($mypath."section.tpl");
59
Maurus Cuelenaereae569c62008-10-09 09:57:21 +000060$func_tpl = get_tpl_part(array("%FUNCTION_START%", "%FUNCTION_END%"), $section_tpl);
61$description_tpl = get_tpl_part(array("%DESCRIPTION_START%", "%DESCRIPTION_END%"), $section_tpl);
62$parameter_tpl = get_tpl_part(array("%PARAMETER_START%", "%PARAMETER_END%"), $section_tpl);
63$parameters_tpl = get_tpl_part(array("%PARAMETERS_START%", "%PARAMETERS_END%"), $section_tpl);
64$return_tpl = get_tpl_part(array("%RETURN_START%", "%RETURN_END%"), $section_tpl);
65$conditions_tpl = get_tpl_part(array("%CONDITIONS_START%", "%CONDITIONS_END%"), $section_tpl);
66$see_tpl = get_tpl_part(array("%SEE_START%", "%SEE_END%"), $section_tpl);
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +000067
68foreach($inh as $group_name => $group)
69{
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +000070 $section_data = str_replace(array("%MENU%", "%GROUP_NAME%"), array($menu, ucwords($group_name)), $section_tpl);
71
72 $funcs_data = array();
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +000073 foreach($group as $func_name => $func)
74 {
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +000075 $func_data = str_replace(array("%FUNCTION_NAME%", "%FUNCTION%"), array(get_func($func_name), $func_name), $func_tpl);
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +000076
77 if(strlen($func["description"][0]) > 0)
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +000078 $func_data = ereg_replace("%DESCRIPTION_START%.*%DESCRIPTION_END%",
79 str_replace("%FUNCTION_DESCRIPTION%", do_markup($func["description"][0]), $description_tpl),
80 $func_data);
81 else
82 $func_data = ereg_replace("%DESCRIPTION_START%.*%DESCRIPTION_END%", "", $func_data);
83
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +000084 if(isset($func["param"]))
85 {
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +000086 $params_data = array();
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +000087 foreach($func["param"] as $param)
88 {
89 $param = trim($param);
90 $p1 = substr($param, 0, strpos($param, " "));
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +000091 $p2 = do_markup(substr($param, strpos($param, " ")));
92
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +000093 if(strlen($p1) > 0 && strlen($p2) > 0)
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +000094 $params_data[] = str_replace(array("%PARAM1%", "%PARAM2%"), array($p1, $p2), $parameters_tpl);
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +000095 }
96
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +000097
98 if(count($params_data) > 0)
99 $func_data = ereg_replace("%PARAMETER_START%.*%PARAMETER_END%",
100 ereg_replace("%PARAMETERS_START%.*%PARAMETERS_END%", implode("\n", $params_data), $parameter_tpl),
101 $func_data);
102 else
103 $func_data = ereg_replace("%PARAMETER_START%.*%PARAMETER_END%", "", $func_data);
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +0000104 }
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +0000105 else
106 $func_data = ereg_replace("%PARAMETER_START%.*%PARAMETER_END%", "", $func_data);
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +0000107
108 if(isset($func["return"]) && strlen($func["return"][0]) > 0)
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +0000109 $func_data = ereg_replace("%RETURN_START%.*%RETURN_END%",
110 str_replace("%RETURN%", do_markup($func["return"][0]), $return_tpl),
111 $func_data);
112 else
113 $func_data = ereg_replace("%RETURN_START%.*%RETURN_END%", "", $func_data);
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +0000114
115 if(isset($func["conditions"]))
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +0000116 $func_data = ereg_replace("%CONDITIONS_START%.*%CONDITIONS_END%",
117 str_replace("%CONDITIONS%", $func["conditions"][0], $conditions_tpl),
118 $func_data);
119 else
120 $func_data = ereg_replace("%CONDITIONS_START%.*%CONDITIONS_END%", "", $func_data);
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +0000121
122 if(isset($func["see"]))
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +0000123 $func_data = ereg_replace("%SEE_START%.*%SEE_END%",
124 str_replace("%SEE%", do_see_markup(explode(" ", trim($func["see"][0]))), $see_tpl),
125 $func_data);
126 else
127 $func_data = ereg_replace("%SEE_START%.*%SEE_END%", "", $func_data);
128
129 $funcs_data[] = $func_data;
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +0000130 }
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +0000131 $section_data = ereg_replace("%FUNCTION_START%.*%FUNCTION_END%", implode("", $funcs_data), $section_data);
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +0000132
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +0000133 file_put_contents("output/".get_group($group_name).".html", $section_data);
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +0000134}
135
Maurus Cuelenaere8c0b6612008-10-09 09:49:53 +0000136copy($mypath."layout.css", "output/layout.css");
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +0000137?>