source: trunk/tools/database/www/Odin32Changelog.php@ 5280

Last change on this file since 5280 was 4538, checked in by bird, 25 years ago

Changelog parser. Initial coding.
TODO: Select/Limit output.

File size: 10.8 KB
Line 
1<?php
2/* $Id: Odin32Changelog.php,v 1.1 2000-10-26 18:41:00 bird Exp $
3 *
4 * Change log parser/conveter.
5 *
6 * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
7 *
8 * Project Odin Software License can be found in LICENSE.TXT
9 *
10 */
11
12echo "<TABLE border=0 CELLSPACING=0 CELLPADDING=0 COLS=3 WIDTH=\"750\">\n".
13 "<TR><td>\n";
14$aChangeLog = ChangeLog_Read(file("d:/odin32/tree20001026/changelog"));
15//ChangeLog_Dump($aChangeLog);
16ChangeLog_MakeTable($aChangeLog);
17
18echo "</td></tr></table>\n";
19
20
21/**
22 * Reads, well really it pareses the file array passed into it.
23 * @returns Array structure of the changelog (see remarks)
24 * @param $aFile Array of the lines in the change log file to parse.
25 * @sketch
26 * @status
27 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
28 * @remark
29 *
30 * Return structure sketch:
31 * array $aChangeLog[]
32 * {
33 * int "cEntries";
34 * array //entry
35 * {
36 * _str "sDate";
37 * _str "sName";
38 * _str "sEmail";
39 * int "cModules";
40 * array "aModules"[]
41 * {
42 * array //entry
43 * {
44 * _str "sModule";
45 * int "cChanges";
46 * array "aChanges"[]
47 * {
48 * _str //change description
49 * };
50 * };
51 * };
52 * };
53 * }
54 */
55function ChangeLog_Read($aFile)
56{
57 $aChangeLog = array(); /* Empty change log array. */
58 $iChangeLog = -1; /* Current Entry in $aChangeLog*/
59 $fFirst = 1; /* Searching for the first line entry,
60 * ie. an ISO date. */
61 $fPre = 0; /* We're parsing preformatted text.
62 * Add newlines! */
63
64 reset($aFile);
65 while (list($sKey, $sLine) = each($aFile))
66 {
67 $sTrimmed = trim($sLine);
68
69 /* ISO date on this line? */
70 if ($sTrimmed[10] == ':' && isISODate(substr($sTrimmed, 0, 10)) )
71 {
72 $fFirst = 0;
73 /* example line:
74 * 2000-10-23: Sander van Leeuwen <sandervl@xs4all.nl>
75 * Locates the email address (which is enclosed within '<'-'>'.)
76 */
77 $iLeft = strpos($sTrimmed, "<");
78 $iRight = strrpos($sTrimmed, ">");
79 if ($iLeft >= $iRight)
80 {
81 echo "<!-- $iLeft >= $iRight; line $sKey -->";
82 $fFirst = 1; // skips this entry.
83 continue;
84 }
85 $sDate = substr($sTrimmed, 0, 10);
86 $sName = trim(substr($sTrimmed, 11, $iLeft - 11));
87 $sEmail = trim(substr($sTrimmed, $iLeft + 1, $iRight - $iLeft - 1));
88 //echo "<p>\r\n$sDate: $sName <$sEmail><br>\r\n";
89
90 $aChangeLog[++$iChangeLog] =
91 array("sDate" => $sDate,
92 "sName" => $sName,
93 "sEmail" => $sEmail,
94 "cModules" => 0,
95 "aModules" => array()
96 );
97 $iModule = -1;
98 }
99 else
100 {
101 /* example lines:
102 * - KERNEL32: o Add rename entry for winspool.drv to odin.ini. (if not present)
103 * o Check pointers in Read/WriteProcessMemory
104 * o Add OLE key during installation:<pre>
105 * [HKEY_LOCAL_MACHINE\Software\Microsoft\OLE]
106 * "EnableDCOM"="Y"
107 * "EnableRemoteConnect"="N"</pre>
108 *
109 * - WINSPOOL: o Removed changes. (now generates winspool.dll again)
110 */
111
112 /* Look for new module */
113 if ($sTrimmed[0] == '-'
114 && ($iColon = strpos($sTrimmed, ":")) > 1
115 && strlen($sModule = trim(substr($sTrimmed, 1, $iColon - 1))) > 0
116 && strlen($sModule) < 42
117 )
118 {
119 $sTrimmed = ltrim(substr($sTrimmed, $iColon+1));
120 $sLine = substr($sLine, strpos($sLine, ':')+1);
121
122 $aChangeLog[$iChangeLog]["cModules"] = ++$iModule + 1;
123 $aChangeLog[$iChangeLog]["aModules"][$iModule] =
124 array("sModule" => $sModule,
125 "cChanges" => 0,
126 "aChanges" => array()
127 );
128 $iChange = 0;
129
130 //echo "$sModule:\r\n";
131 }
132
133 /* Look for start of new point */
134 if ( $sTrimmed[0] == "ú"
135 || ($sTrimmed[0] == "o" && $sTrimmed[1] == " ")
136 )
137 {
138 if ($iChange > 0 ||
139 isset($aChangeLog[$iChangeLog]["aModules"][$iModule]["aChanges"][$iChange]))
140 ++$iChange;
141 $aChangeLog[$iChangeLog]["aModules"][$iModule]["cChanges"] = $iChange + 1;
142 $sTrimmed = ltrim(substr($sTrimmed, 1));
143
144 //echo " o ";
145 }
146
147 /* If not empty line, then add it to current change description */
148 if (strlen($sTrimmed) > 0)
149 {
150 if (isset($aChangeLog[$iChangeLog]["aModules"][$iModule]["aChanges"][$iChange]))
151 $aChangeLog[$iChangeLog]["aModules"][$iModule]["aChanges"][$iChange] .=
152 " ".$sTrimmed;
153 else
154 $aChangeLog[$iChangeLog]["aModules"][$iModule]["aChanges"][$iChange] =
155 $sTrimmed;
156
157 /* check for <pre> and </pre> */
158 $sTrimmed = strtolower($sTrimmed);
159 $iPre = strpos($sTrimmed, "<pre");
160 $iPre = ($iPre ? $iPre : -1);
161 $iEndPre = strpos($sTrimmed, "</pre");
162 $iEndPre = ($iEndPre ? $iEndPre : -1);
163 echo "<!--$iPre,$iEndPre-->\n";
164
165 if ($fPre && $iEndPre > $iPre)
166 $fPre = false;
167
168 if (!$fPre && $iPre > $iEndPre)
169 $fPre = true;
170
171 /* add newline if inside a <pre> */
172 if ($fPre)
173 $aChangeLog[$iChangeLog]["aModules"][$iModule]["aChanges"][$iChange] .=
174 "\n";
175 }
176
177 }
178 }
179 $aChangeLog["cEntries"] = $iChangeLog+1;
180
181 /* return array */
182 return $aChangeLog;
183}
184
185
186/**
187 * Dumps the array - debugging.
188 * @returns nothing.
189 * @param $aChangeLog Array returned by ChangeLog_Read.
190 * @status
191 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
192 * @remark
193 */
194function ChangeLog_Dump($aChangeLog)
195{
196 echo "<p><t1>Dump</t1>\r\n";
197
198 for ($iChangeLog = 0; $iChangeLog < $aChangeLog["cEntries"]; $iChangeLog++)
199 {
200 $aLogEntry = $aChangeLog[$iChangeLog];
201
202 echo $aLogEntry["sDate"].": ".$aLogEntry["sName"]." <".$aLogEntry["sEmail"]."> ".
203 $aLogEntry["cModules"]." modules\r\n";
204
205 $aModules = $aLogEntry["aModules"];
206 for ($iModule = 0; $iModule < $aLogEntry["cModules"]; $iModule++)
207 {
208 //$aModule = $aModules[$iModule];
209 $aModule = $aChangeLog[$iChangeLog]["aModules"][$iModule];
210 echo " - ".$aModule["sModule"]." ".$aModule["cChanges"]." changes\r\n";
211 if ($aModule["cChanges"] > 0)
212 {
213 for ($iChange = 0; $iChange < $aModule["cChanges"]; $iChange++)
214 echo " o ".$aModule["aChanges"][$iChange]."\r\n";
215 }
216 else
217 echo " ".$aModule["aChanges"][0]."\r\n";
218
219 }
220 } /* while */
221}
222
223
224/**
225 * Write the entrie change log to a table.
226 * @returns nothing.
227 * @param $aChangeLog Changelog array - output from ChangeLog_Read.
228 * @sketch
229 * @status
230 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
231 * @remark
232 */
233function ChangeLog_MakeTable($aChangeLog)
234{
235 echo "\n".
236 "<table>\n";
237
238 for ($iChangeLog = 0; $iChangeLog < $aChangeLog["cEntries"]; $iChangeLog++)
239 ChangeLog_MakeTableEntry($aChangeLog[$iChangeLog]);
240
241 echo "</table>\n";
242}
243
244
245/**
246 * Presents a single log entry ($aLogEntry).
247 * (It inserts a row into an existing table in the HTML output.)
248 * @returns nothing.
249 * @param $aLogEntry Log entry to present.
250 * @status
251 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
252 * @remark
253 */
254function ChangeLog_MakeTableEntry($aLogEntry)
255{
256 echo "<tr><td bgcolor=#d0dce0><font size=-1>".
257 $aLogEntry["sDate"].": ".
258 $aLogEntry["sName"].
259 /*" &lt;".$aLogEntry["sEmail"]."&gt;".*/"</td></tr>\r\n";
260
261 echo " <tr><td bgcolor=#f0f0f0>\n".
262 " <table>\n";
263
264 $aModules = $aLogEntry["aModules"];
265 for ($iModule = 0; $iModule < $aLogEntry["cModules"]; $iModule++)
266 {
267 $aModule = $aModules[$iModule];
268 $sModule = ChangeLog_CaseModuleName($aModule["sModule"]);
269
270 echo " <tr><td valign=top><font size=-1><b>".$sModule."</b>\n";
271
272 echo " <ul compact>\n";
273 if ($aModule["cChanges"] > 0)
274 {
275 for ($iChange = 0; $iChange < $aModule["cChanges"]; $iChange++)
276 echo " <li>".$aModule["aChanges"][$iChange]."\n";
277 }
278 else
279 echo " <li>".$aModule["aChanges"][0]."\r\n";
280 echo " </ul>\n".
281 " </td></tr>\n";
282 }
283
284 echo " </table></td>\n".
285 " </tr>\n";
286}
287
288
289/**
290 * This function cases the module name if it is a dll name or a directory name.
291 * If not a dll, nothing is done.
292 * @returns Modulename string to present.
293 * @param $sModule Modulename string.
294 * @sketch
295 * @status
296 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
297 * @remark
298 */
299function ChangeLog_CaseModuleName($sModule)
300{
301 $sModule = trim($sModule);
302 if ( strpos($sModule, ".") > 0
303 || strtoupper($sModule) != $sModule)
304 return $sModule;
305
306 $sResult = "";
307 $sModule = strtolower($sModule);
308 while (($i = strpos($sModule, "/")) > 0 || ($i = strpos($sModule, "\\")) > 0)
309 {
310 $sResult .= ucfirst(substr($sModule, 0, $i+1));
311 $sModule = substr($sModule, $i+1);
312 }
313 $sResult .= ucfirst($sModule);
314
315 return $sResult;
316}
317
318
319/**
320 * Checks if a date is a valid ISO date.
321 * @returns true/false according to the query.
322 *
323 * @param $sDate Possible ISO date.
324 * @status
325 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
326 * @remark
327 */
328function isISODate($sDate)
329{
330 /*YYYY-MM-DD*/
331 /*0123456789*/
332
333 if (strlen($sDate) != 10
334 ||
335 ($sDate[4] != '-' || $sDate[7] != '-')
336 )
337 return false;
338 $iYear = @(int)substr($sDate, 0, 4);
339 $iMonth = @(int)substr($sDate, 5, 2);
340 $iDay = @(int)substr($sDate, 8, 2);
341 if ( $iYear <= 0
342 || $iYear > 9999
343 || $iMonth <= 0
344 || $iMonth > 12
345 || $iDay <= 0
346 || $iDay > 31
347 )
348 return false;
349
350 return true;
351}
352
353
354
355
356?>
Note: See TracBrowser for help on using the repository browser.