Maurus Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 1 | #!/usr/bin/php |
| 2 | <? |
| 3 | require_once("functions.php"); |
| 4 | |
| 5 | function get_group($text) |
| 6 | { |
| 7 | return str_replace(array(" ", "/"), "_", $text); |
| 8 | } |
| 9 | |
| 10 | $input = file_get_contents($argv[1]); |
| 11 | |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 12 | $mypath = $_SERVER['SCRIPT_FILENAME']; |
| 13 | $mypath = substr($mypath, 0, strrpos($mypath, "/"))."/"; |
| 14 | |
Maurus Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 15 | $inh = parse_documentation($input); |
| 16 | |
| 17 | @mkdir("output"); |
| 18 | |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 19 | $index_tpl = file_get_contents($mypath."index.tpl"); |
Maurus Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 20 | |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 21 | $group_data = array(); |
Maurus Cuelenaere | ae569c6 | 2008-10-09 09:57:21 +0000 | [diff] [blame] | 22 | $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 Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 24 | |
| 25 | foreach($inh as $group_name => $group) |
| 26 | { |
| 27 | if(strlen($group_name) > 0) |
| 28 | { |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 29 | $func_data = array(); |
Maurus Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 30 | foreach($group as $el_name => $el) |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 31 | $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 Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 34 | |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 35 | $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 Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 37 | } |
| 38 | } |
Maurus Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 39 | |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 40 | $index_tpl = ereg_replace("%GROUP_START%.*%GROUP_END%", implode("", $group_data), $index_tpl); |
| 41 | file_put_contents("output/index.html", $index_tpl); |
Maurus Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 42 | |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 43 | $menu_tpl = file_get_contents($mypath."menu.tpl"); |
Maurus Cuelenaere | ae569c6 | 2008-10-09 09:57:21 +0000 | [diff] [blame] | 44 | $group_tpl = get_tpl_part(array("%GROUP_START%", "%GROUP_END%"), $menu_tpl); |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 45 | |
| 46 | $menu = array(); |
Maurus Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 47 | foreach($inh as $group_name => $group) |
| 48 | { |
| 49 | if(strlen($group_name) > 0) |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 50 | $menu[strtolower($group_name)] = str_replace(array("%GROUP%", "%GROUP_NAME%"), |
| 51 | array(get_group($group_name), ucwords($group_name)), |
| 52 | $group_tpl); |
Maurus Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 53 | } |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 54 | ksort($menu); |
Maurus Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 55 | |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 56 | $menu = ereg_replace("%GROUP_START%.*%GROUP_END%", implode("", $menu), $menu_tpl); |
| 57 | |
| 58 | $section_tpl = file_get_contents($mypath."section.tpl"); |
| 59 | |
Maurus Cuelenaere | ae569c6 | 2008-10-09 09:57:21 +0000 | [diff] [blame] | 60 | $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 Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 67 | |
| 68 | foreach($inh as $group_name => $group) |
| 69 | { |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 70 | $section_data = str_replace(array("%MENU%", "%GROUP_NAME%"), array($menu, ucwords($group_name)), $section_tpl); |
| 71 | |
| 72 | $funcs_data = array(); |
Maurus Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 73 | foreach($group as $func_name => $func) |
| 74 | { |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 75 | $func_data = str_replace(array("%FUNCTION_NAME%", "%FUNCTION%"), array(get_func($func_name), $func_name), $func_tpl); |
Maurus Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 76 | |
| 77 | if(strlen($func["description"][0]) > 0) |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 78 | $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 Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 84 | if(isset($func["param"])) |
| 85 | { |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 86 | $params_data = array(); |
Maurus Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 87 | foreach($func["param"] as $param) |
| 88 | { |
| 89 | $param = trim($param); |
| 90 | $p1 = substr($param, 0, strpos($param, " ")); |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 91 | $p2 = do_markup(substr($param, strpos($param, " "))); |
| 92 | |
Maurus Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 93 | if(strlen($p1) > 0 && strlen($p2) > 0) |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 94 | $params_data[] = str_replace(array("%PARAM1%", "%PARAM2%"), array($p1, $p2), $parameters_tpl); |
Maurus Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 97 | |
| 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 Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 104 | } |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 105 | else |
| 106 | $func_data = ereg_replace("%PARAMETER_START%.*%PARAMETER_END%", "", $func_data); |
Maurus Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 107 | |
| 108 | if(isset($func["return"]) && strlen($func["return"][0]) > 0) |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 109 | $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 Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 114 | |
| 115 | if(isset($func["conditions"])) |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 116 | $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 Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 121 | |
| 122 | if(isset($func["see"])) |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 123 | $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 Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 130 | } |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 131 | $section_data = ereg_replace("%FUNCTION_START%.*%FUNCTION_END%", implode("", $funcs_data), $section_data); |
Maurus Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 132 | |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 133 | file_put_contents("output/".get_group($group_name).".html", $section_data); |
Maurus Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Maurus Cuelenaere | 8c0b661 | 2008-10-09 09:49:53 +0000 | [diff] [blame] | 136 | copy($mypath."layout.css", "output/layout.css"); |
Maurus Cuelenaere | 20fb47e | 2008-10-06 22:19:54 +0000 | [diff] [blame] | 137 | ?> |