--- /dev/null
+#!/usr/bin/env php
+<?php
+
+define('ISSO', dirname(dirname(dirname(__FILE__))));
+require_once ISSO . '/App.php';
+require_once ISSO . '/Functions.php';
+
+if ($argc != 2)
+{
+ echo 'Useage: convert_txt.php <file.txt>';
+ exit;
+}
+
+$data = @file_get_contents($argv[1]);
+if ($data === false)
+{
+ echo 'Unable to locate ' . $argv[1];
+ exit;
+}
+
+// ###################################################################
+
+$data = BSFunctions::convert_line_breaks($data);
+$data = explode("\n", $data);
+
+define('COLUMN_WIDTH', 80);
+$line = 0;
+
+$TABLE = array(
+ 'subject' => null,
+ 'title' => null,
+ 'preface' => null,
+ 'sections' => array(), // array(header => X, items => array(list items))
+);
+
+// ###################################################################
+
+$matches = array();
+if (!preg_match('/(\w+)\s+(.*)/i', $data[$line++], $matches))
+{
+ throw new Exception('No title line');
+}
+
+$TABLE['subject'] = $matches[1];
+$TABLE['title'] = ucwords(strtolower($matches[2]));
+
+if ($data[$line++] != str_repeat('=', COLUMN_WIDTH))
+{
+ throw new Exception('No header separator');
+}
+
+// read the preface
+while (trim($data[++$line]) != '')
+{
+ $TABLE['preface'] .= trim($data[$line]) . ' ';
+}
+$TABLE['preface'] = trim($TABLE['preface']);
+
+// read the sections
+for ($section = 0; $line < sizeof($data); $line++)
+{
+ // empty lines signal a new section
+ if (trim($data[$line]) == '')
+ {
+ $section++;
+ }
+
+ // look for the heading
+ if (preg_match('/#{5,}/', $data[$line]))
+ {
+ $TABLE['sections'][$section]['header'] = ucwords(strtolower($data[$line - 1]));
+ }
+ // we've read the heading, start reading data
+ else if (isset($TABLE['sections'][$section]['header']))
+ {
+ if ($data[$line][0] == '-')
+ {
+ $TABLE['sections'][$section]['data'][] = trim(substr($data[$line], 1));
+ }
+ else
+ {
+ $TABLE['sections'][$section]['data'][sizeof($TABLE['sections'][$section]['data']) - 1] .= ' ' . trim($data[$line]);
+ }
+ }
+}
+
+// ###################################################################
+
+$sections = '';
+foreach ($TABLE['sections'] as $section)
+{
+ $sections .= "\n<h2>$section[header]</h2>\n";
+
+ if (is_array($section['data']))
+ {
+ $sections .= "<ul>\n";
+ foreach ($section['data'] as $item)
+ {
+ $sections .= "\t<li>$item</li>\n";
+ }
+ $sections .= "</ul>\n";
+ }
+ else
+ {
+ $sections .= "<p>$text</p>\n";
+ }
+}
+
+echo <<<HTML
+<html>
+<head>
+ <title>$TABLE[subject] - $TABLE[title]</title>
+</head>
+<body>
+
+<h1>$TABLE[title]</h1>
+
+<p>$TABLE[preface]</p>
+
+$sections
+
+</body>
+</html>
+
+HTML;
+
+?>
\ No newline at end of file