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

Last change on this file since 10366 was 10027, checked in by bird, 22 years ago

Fixed warnings.

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