]>
src.bluestatic.org Git - isso.git/blob - docs/tools/convert_txt.php
4 define('ISSO', dirname(dirname(dirname(__FILE__
))));
5 require_once ISSO
. '/App.php';
6 require_once ISSO
. '/Functions.php';
10 echo 'Useage: convert_txt.php <file.txt>';
14 $data = @file_get_contents($argv[1]);
17 echo 'Unable to locate ' . $argv[1];
21 // ###################################################################
23 $data = BSFunctions
::convert_line_breaks($data);
24 $data = explode("\n", $data);
26 define('COLUMN_WIDTH', 80);
33 'sections' => array(), // array(header => X, items => array(list items))
36 // ###################################################################
39 if (!preg_match('/(\w+)\s+(.*)/i', $data[$line++
], $matches))
41 throw new Exception('No title line');
44 $TABLE['subject'] = $matches[1];
45 $TABLE['title'] = ucwords(strtolower($matches[2]));
47 if ($data[$line++
] != str_repeat('=', COLUMN_WIDTH
))
49 throw new Exception('No header separator');
53 while (trim($data[++
$line]) != '')
55 $TABLE['preface'] .= trim($data[$line]) . ' ';
57 $TABLE['preface'] = trim($TABLE['preface']);
60 for ($section = 0; $line < sizeof($data); $line++
)
62 // empty lines signal a new section
63 if (trim($data[$line]) == '')
68 // look for the heading
69 if (preg_match('/#{5,}/', $data[$line]))
71 $TABLE['sections'][$section]['header'] = ucwords(strtolower($data[$line - 1]));
73 // we've read the heading, start reading data
74 else if (isset($TABLE['sections'][$section]['header']))
76 if ($data[$line][0] == '-')
78 $TABLE['sections'][$section]['data'][] = trim(substr($data[$line], 1));
82 $TABLE['sections'][$section]['data'][sizeof($TABLE['sections'][$section]['data']) - 1] .= ' ' . trim($data[$line]);
87 // ###################################################################
90 foreach ($TABLE['sections'] as $section)
92 $sections .= "\n<h2>$section[header]</h2>\n";
94 if (is_array($section['data']))
96 $sections .= "<ul>\n";
97 foreach ($section['data'] as $item)
99 $sections .= "\t<li>$item</li>\n";
101 $sections .= "</ul>\n";
105 $sections .= "<p>$text</p>\n";
112 <title>$TABLE[subject] - $TABLE[title]</title>
116 <h1>$TABLE[title]</h1>
118 <p>$TABLE[preface]</p>