Rev 735 | Rev 738 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
733 | daniel-mar | 1 | program OIDPLUS; |
2 | |||
3 | (************************************************) |
||
4 | (* OIDPLUS.PAS *) |
||
5 | (* Author: Daniel Marschall *) |
||
734 | daniel-mar | 6 | (* Revision: 2022-02-14 *) |
733 | daniel-mar | 7 | (* License: Apache 2.0 *) |
8 | (* This file contains: *) |
||
9 | (* - "OIDplus for DOS" program *) |
||
10 | (************************************************) |
||
11 | |||
12 | uses |
||
13 | Dos, Crt, StrList, VtsFuncs, VtsCui, OidFile, OidUtils; |
||
14 | |||
15 | const |
||
735 | daniel-mar | 16 | VERSIONINFO = 'Revision: 2022-02-14'; |
17 | DEFAULT_STATUSBAR = '(C)2020-2022 ViaThinkSoft. Licensed under the terms of the Apache 2.0 license.'; |
||
733 | daniel-mar | 18 | DISKIO_SOUND_DEBUGGING = false; |
735 | daniel-mar | 19 | DISKIO_SOUND_DELAY = 500; |
20 | ASNEDIT_LINES = 10; |
||
21 | DESCEDIT_LINES = 10; |
||
22 | DESCEDIT_PADDING = 3; |
||
23 | ACTIONMENU_SIZE = 5; |
||
24 | MAINMENU_WIDTH = 15; |
||
25 | MAINMENU_HEIGHT = 3; |
||
26 | MAINMENU_ALLOW_ESC = false; |
||
733 | daniel-mar | 27 | |
28 | procedure _WriteOidFile(filename: string; oid: POid); |
||
29 | begin |
||
30 | DrawStatusBar('Write file ' + filename + '...'); |
||
31 | WriteOidFile(filename, oid); |
||
32 | |||
33 | if DISKIO_SOUND_DEBUGGING then |
||
34 | begin |
||
35 | Sound(70); |
||
36 | Delay(DISKIO_SOUND_DELAY - 10); |
||
37 | NoSound; |
||
38 | Delay(10); |
||
39 | end; |
||
40 | |||
41 | DrawStatusBar(DEFAULT_STATUSBAR); |
||
42 | end; |
||
43 | |||
44 | procedure _ReadOidFile(filename: string; oid: POid); |
||
45 | begin |
||
46 | DrawStatusBar('Read file ' + filename + '...'); |
||
47 | ReadOidFile(filename, oid); |
||
48 | |||
49 | if DISKIO_SOUND_DEBUGGING then |
||
50 | begin |
||
51 | Sound(50); |
||
52 | Delay(DISKIO_SOUND_DELAY - 10); |
||
53 | NoSound; |
||
54 | Delay(10); |
||
55 | end; |
||
56 | |||
57 | DrawStatusBar(DEFAULT_STATUSBAR); |
||
58 | end; |
||
59 | |||
60 | procedure _Pause; |
||
61 | var |
||
62 | bakX, bakY: integer; |
||
63 | begin |
||
64 | bakX := WhereX; |
||
65 | bakY := WhereY; |
||
66 | DrawStatusBar('Press any key to continue'); |
||
67 | GoToXY(bakX, bakY); |
||
68 | ReadKey; |
||
69 | DrawStatusBar(DEFAULT_STATUSBAR); |
||
70 | end; |
||
71 | |||
72 | function _ShowASNIds(subfile: string): string; |
||
73 | var |
||
735 | daniel-mar | 74 | childOID: POID; |
733 | daniel-mar | 75 | j, jmax: integer; |
76 | sTmp: string; |
||
77 | begin |
||
78 | sTmp := ''; |
||
735 | daniel-mar | 79 | CreateOidDef(childOID); |
80 | _ReadOidFile(subfile, childOID); |
||
81 | jmax := ListCount(childOID^.ASNIds)-1; |
||
733 | daniel-mar | 82 | for j := 0 to jmax do |
83 | begin |
||
84 | if j = 0 then sTmp := sTmp + ' ('; |
||
735 | daniel-mar | 85 | sTmp := sTmp + ListGetElement(childOID^.ASNIds, j); |
733 | daniel-mar | 86 | if j = jmax then |
87 | sTmp := sTmp + ')' |
||
88 | else |
||
89 | sTmp := sTmp + ', '; |
||
90 | end; |
||
735 | daniel-mar | 91 | FreeOidDef(childOID); |
733 | daniel-mar | 92 | _ShowASNIds := sTmp; |
93 | end; |
||
94 | |||
95 | function AsnAlreadyExisting(oid: POID; asnid: string): boolean; |
||
96 | var |
||
97 | sTmp: string; |
||
98 | i: integer; |
||
99 | begin |
||
100 | for i := 0 to ListCount(oid^.AsnIds)-1 do |
||
101 | begin |
||
102 | sTmp := ListGetElement(oid^.AsnIds, i); |
||
103 | if sTmp = asnid then |
||
104 | begin |
||
105 | AsnAlreadyExisting := true; |
||
106 | exit; |
||
107 | end; |
||
108 | end; |
||
109 | AsnAlreadyExisting := false; |
||
110 | end; |
||
111 | |||
112 | function AsnEditor(oid: POID): boolean; |
||
113 | var |
||
114 | asnList: PStringList; |
||
115 | i: integer; |
||
116 | x, y, w, h: integer; |
||
117 | res: integer; |
||
118 | sInput: string; |
||
735 | daniel-mar | 119 | menuIdNew, menuIdSave, menuIdExit: integer; |
733 | daniel-mar | 120 | begin |
121 | AsnEditor := false; |
||
122 | |||
123 | repeat |
||
735 | daniel-mar | 124 | CreateList(asnList); |
733 | daniel-mar | 125 | |
126 | for i := 0 to ListCount(oid^.ASNIds)-1 do |
||
127 | begin |
||
128 | ListAppend(asnList, ListGetElement(oid^.ASNIDs, i)); |
||
129 | end; |
||
735 | daniel-mar | 130 | menuIdNew := ListAppend(asnList, '<NEW>'); |
131 | menuIdSave := ListAppend(asnList, '<SAVE>'); |
||
132 | menuIdExit := ListAppend(asnList, '<CANCEL>'); |
||
733 | daniel-mar | 133 | |
134 | DrawStatusBar(DEFAULT_STATUSBAR); |
||
135 | x := SINGLE_LINE_BOX_PADDING; |
||
136 | y := ScreenHeight div 2 - ASNEDIT_LINES div 2; |
||
137 | w := ScreenWidth - (SINGLE_LINE_BOX_PADDING-1)*2; |
||
138 | h := ASNEDIT_LINES; |
||
139 | res := DrawSelectionList(x, y, w, h, |
||
140 | asnList, true, |
||
141 | 'EDIT ASN.1 IDENTIFIERS', |
||
142 | 2); |
||
735 | daniel-mar | 143 | FreeList(asnList); |
733 | daniel-mar | 144 | |
145 | (* Change double-border to thin-border *) |
||
146 | DrawThinBorder(x-1, y-1, w+2, h+2); |
||
147 | GoToXY(x+1, y-1); |
||
148 | Write('EDIT ASN.1 IDENTIFIERS'); |
||
149 | |||
150 | if res = -1 then |
||
151 | begin |
||
152 | exit; |
||
153 | end |
||
735 | daniel-mar | 154 | else if res = menuIdNew then |
733 | daniel-mar | 155 | begin |
156 | (* "NEW" item was selected *) |
||
157 | sInput := ''; |
||
158 | repeat |
||
159 | if QueryVal(sInput, |
||
160 | SINGLE_LINE_BOX_PADDING_INNER, |
||
161 | ScreenHeight div 2, |
||
162 | ScreenWidth - (SINGLE_LINE_BOX_PADDING_INNER-1)*2, |
||
163 | 1, |
||
164 | 'ADD SINGLE ASN.1 ID', |
||
165 | 2) then |
||
166 | begin |
||
167 | if sInput = '' then continue; |
||
168 | if not ASN1IDValid(sInput) then |
||
169 | begin |
||
170 | ShowMessage('Invalid ASN1.ID! (Require -, a..z, A..Z, 0..9, begin with a-z)', 'ERROR', true); |
||
171 | _Pause; |
||
172 | end |
||
173 | else if AsnAlreadyExisting(oid, sInput) then |
||
174 | begin |
||
175 | ShowMessage('ASN.1 identifier is already existing on this arc', 'ERROR', true); |
||
176 | _Pause; |
||
177 | end |
||
178 | else |
||
179 | begin |
||
180 | ListAppend(oid^.ASNIDs, sInput); |
||
181 | break; |
||
182 | end; |
||
183 | end |
||
184 | else break; |
||
185 | until false; |
||
186 | end |
||
735 | daniel-mar | 187 | else if res = menuIdSave then |
733 | daniel-mar | 188 | begin |
189 | (* "SAVE" item was selected *) |
||
190 | AsnEditor := true; |
||
191 | Exit; |
||
192 | end |
||
735 | daniel-mar | 193 | else if res = menuIdExit then |
733 | daniel-mar | 194 | begin |
195 | (* "CANCEL" item was selected *) |
||
196 | AsnEditor := false; |
||
197 | Exit; |
||
198 | end |
||
199 | else |
||
200 | begin |
||
201 | DrawStatusBar('Note: Remove the text to delete the ASN.1 identifier'); |
||
202 | sInput := ListGetElement(oid^.ASNIDs, res); |
||
203 | repeat |
||
204 | if QueryVal(sInput, |
||
205 | SINGLE_LINE_BOX_PADDING_INNER, |
||
206 | ScreenHeight div 2, |
||
207 | ScreenWidth - (SINGLE_LINE_BOX_PADDING_INNER-1)*2, |
||
208 | 1, |
||
209 | 'EDIT SINGLE ASN.1 ID', |
||
210 | 2) then |
||
211 | begin |
||
212 | if sInput = '' then |
||
213 | begin |
||
214 | (* Empty input = Delete ASN.1 ID *) |
||
737 | daniel-mar | 215 | ListDeleteElementByIndex(oid^.ASNIDs, res); |
733 | daniel-mar | 216 | break; |
217 | end |
||
218 | else if not ASN1IDValid(sInput) then |
||
219 | begin |
||
220 | ShowMessage('Invalid ASN1.ID! (Require -, a..z, A..Z, 0..9, begin with a-z)', 'ERROR', true); |
||
221 | _Pause; |
||
222 | end |
||
223 | else if AsnAlreadyExisting(oid, sInput) and |
||
224 | not (ListGetElement(oid^.ASNIDs, res) = sInput) then |
||
225 | begin |
||
226 | ShowMessage('ASN.1 identifier is already existing on this arc', 'ERROR', true); |
||
227 | _Pause; |
||
228 | end |
||
229 | else |
||
230 | begin |
||
231 | ListSetElement(oid^.ASNIDs, res, sInput); |
||
232 | break; |
||
233 | end; |
||
234 | end |
||
235 | else break; |
||
236 | until false; |
||
237 | end; |
||
238 | until false; |
||
239 | end; |
||
240 | |||
241 | function DescEditor(oid: POID): boolean; |
||
242 | var |
||
243 | sInput: string; |
||
244 | begin |
||
245 | DescEditor := false; |
||
246 | |||
247 | DrawStatusBar('Note: Press Ctrl+Return for a line-break.'); |
||
248 | sInput := oid^.description; |
||
249 | if QueryVal(sInput, |
||
250 | DESCEDIT_PADDING, |
||
251 | ScreenHeight div 2 - DESCEDIT_LINES div 2, |
||
252 | ScreenWidth - (DESCEDIT_PADDING-1)*2, |
||
253 | DESCEDIT_LINES, |
||
254 | 'EDIT DESCRIPTION', |
||
255 | 2) then |
||
256 | begin |
||
257 | oid^.description := sInput; |
||
734 | daniel-mar | 258 | DescEditor := true; (* request caller to save @oid *) |
733 | daniel-mar | 259 | end; |
260 | end; |
||
261 | |||
262 | function NextPossibleFileID: string; |
||
263 | var |
||
264 | DirInfo: SearchRec; |
||
265 | list: PStringList; |
||
266 | iId: LongInt; |
||
267 | sId: string; |
||
268 | begin |
||
269 | (* Put all found files into a list *) |
||
735 | daniel-mar | 270 | CreateList(list); |
733 | daniel-mar | 271 | FindFirst('????????.OID', Archive, DirInfo); |
272 | while DosError = 0 do |
||
273 | begin |
||
274 | sId := Copy(DirInfo.Name, 1, 8); |
||
275 | ListAppend(list, sId); |
||
276 | FindNext(DirInfo); |
||
277 | end; |
||
278 | |||
279 | (* Search for the first non existing item in the list *) |
||
280 | sId := ''; |
||
281 | for iId := 0 to 99999999 do |
||
282 | begin |
||
283 | sId := ZeroPad(iId, 8); |
||
284 | if not ListContains(list, sId) then break; |
||
285 | end; |
||
286 | NextPossibleFileId := sId; |
||
287 | FreeList(list); |
||
288 | end; |
||
289 | |||
290 | function NumIdAlreadyExisting(parentOID: POID; sInput: string): boolean; |
||
291 | var |
||
292 | searchDotNotation: string; |
||
293 | sTmp: string; |
||
294 | i: integer; |
||
295 | begin |
||
296 | if parentOID^.DotNotation = '' then |
||
297 | searchDotNotation := sInput |
||
298 | else |
||
299 | searchDotNotation := parentOID^.DotNotation + '.' + sInput; |
||
300 | for i := 0 to ListCount(parentOID^.SubIds)-1 do |
||
301 | begin |
||
302 | sTmp := ListGetElement(parentOID^.SubIds, i); |
||
735 | daniel-mar | 303 | if DotNotationPart(sTmp) = searchDotNotation then |
733 | daniel-mar | 304 | begin |
305 | NumIdAlreadyExisting := true; |
||
306 | exit; |
||
307 | end; |
||
308 | end; |
||
309 | NumIdAlreadyExisting := false; |
||
310 | end; |
||
311 | |||
312 | function NumIdEditor(oid: POID; parentOID: POID): boolean; |
||
313 | var |
||
314 | sInput: string; |
||
315 | begin |
||
316 | NumIdEditor := false; |
||
317 | sInput := ''; |
||
318 | |||
319 | repeat |
||
320 | if QueryVal(sInput, |
||
321 | SINGLE_LINE_BOX_PADDING_INNER, |
||
322 | ScreenHeight div 2, |
||
323 | ScreenWidth - (SINGLE_LINE_BOX_PADDING_INNER-1)*2, |
||
324 | 1, |
||
325 | 'ENTER NUMERIC ID', |
||
326 | 2) then |
||
327 | begin |
||
328 | if sInput = '' then continue; |
||
329 | if not IsNumeric(sInput) then |
||
330 | begin |
||
331 | ShowMessage('Invalid numeric ID (must be a positive integer)', 'ERROR', true); |
||
332 | _Pause; |
||
333 | end |
||
334 | else if (parentOID^.DotNotation='') and (StrToInt(sInput) > 2) then |
||
335 | begin |
||
336 | ShowMessage('Invalid numeric ID (root arc can only be 0, 1, or 2)', 'ERROR', true); |
||
337 | _Pause; |
||
338 | end |
||
339 | else if ((parentOID^.DotNotation='0') or (parentOID^.DotNotation='1')) and (StrToInt(sInput) > 39) then |
||
340 | begin |
||
341 | ShowMessage('Invalid numeric ID (root 0 and 1 must have sub-arc of 0..39)', 'ERROR', true); |
||
342 | _Pause; |
||
343 | end |
||
344 | else if NumIdAlreadyExisting(parentOID, sInput) then |
||
345 | begin |
||
346 | ShowMessage('This numeric ID is already used in this arc', 'ERROR', true); |
||
347 | _Pause; |
||
348 | end |
||
349 | else |
||
350 | begin |
||
351 | if parentOID^.DotNotation = '' then |
||
352 | oid^.DotNotation := sInput |
||
353 | else |
||
354 | oid^.DotNotation := parentOID^.DotNotation + '.' + sInput; |
||
734 | daniel-mar | 355 | NumIdEditor := true; (* request caller to save @oid *) |
733 | daniel-mar | 356 | Exit; |
357 | end; |
||
358 | end |
||
359 | else |
||
360 | begin |
||
361 | Exit; |
||
362 | end; |
||
363 | until false; |
||
364 | end; |
||
365 | |||
366 | function NewOidEditor(oid: POID): boolean; |
||
367 | var |
||
368 | newfilename: string; |
||
735 | daniel-mar | 369 | newOID: POID; |
733 | daniel-mar | 370 | begin |
371 | NewOidEditor := false; |
||
372 | |||
735 | daniel-mar | 373 | CreateOidDef(newOID); |
374 | newOID^.FileId := NextPossibleFileID; |
||
375 | newOID^.Parent := oid^.FileId + oid^.DotNotation; |
||
376 | if NumIdEditor(newOID, oid) and |
||
377 | AsnEditor(newOID) and |
||
378 | DescEditor(newOID) then |
||
734 | daniel-mar | 379 | begin |
735 | daniel-mar | 380 | newfilename := newOID^.FileId + '.OID'; |
381 | _WriteOidFile(newfilename, newOID); |
||
733 | daniel-mar | 382 | |
734 | daniel-mar | 383 | (* Add link to original file and enable the saving of it *) |
735 | daniel-mar | 384 | ListAppend(oid^.SubIds, newOID^.FileId + newOID^.DotNotation); |
734 | daniel-mar | 385 | NewOidEditor := true; (* request caller to save @oid *) |
386 | end; |
||
735 | daniel-mar | 387 | FreeOidDef(newOID); |
733 | daniel-mar | 388 | end; |
389 | |||
390 | procedure DeleteChildrenRecursive(oid: POID); |
||
391 | var |
||
392 | i: integer; |
||
735 | daniel-mar | 393 | childOID: POID; |
733 | daniel-mar | 394 | filenameChild: string; |
395 | begin |
||
396 | for i := 0 to ListCount(oid^.SubIds)-1 do |
||
397 | begin |
||
735 | daniel-mar | 398 | filenameChild := FileIdPart(ListGetElement(oid^.SubIds, i)) + '.OID'; |
399 | CreateOidDef(childOID); |
||
400 | _ReadOidFile(filenameChild, childOID); |
||
401 | DeleteChildrenRecursive(childOID); |
||
402 | FreeOidDef(childOID); |
||
733 | daniel-mar | 403 | DeleteFile(filenameChild); |
404 | end; |
||
405 | ListClear(oid^.SubIds); |
||
406 | end; |
||
407 | |||
408 | procedure DeleteOidRecursive(selfOID: POID); |
||
409 | var |
||
410 | i: integer; |
||
735 | daniel-mar | 411 | parentOID: POID; |
733 | daniel-mar | 412 | filenameSelf, filenameParent: string; |
413 | begin |
||
414 | (* Remove all children and their files recursively *) |
||
415 | DeleteChildrenRecursive(selfOID); |
||
416 | |||
417 | (* Remove forward reference in parent OID *) |
||
735 | daniel-mar | 418 | filenameParent := FileIdPart(selfOID^.Parent) + '.OID'; |
419 | CreateOidDef(parentOID); |
||
420 | _ReadOidFile(filenameParent, parentOID); |
||
737 | daniel-mar | 421 | if ListDeleteElementByValue(parentOID^.SubIds, selfOID^.FileId + selfOID^.DotNotation) then |
733 | daniel-mar | 422 | begin |
737 | daniel-mar | 423 | _WriteOidFile(filenameParent, parentOID); |
733 | daniel-mar | 424 | end; |
735 | daniel-mar | 425 | FreeOidDef(parentOID); |
733 | daniel-mar | 426 | |
427 | (* Delete own file *) |
||
737 | daniel-mar | 428 | filenameSelf := selfOID^.FileId + '.OID'; |
733 | daniel-mar | 429 | DeleteFile(filenameSelf); |
430 | end; |
||
431 | |||
735 | daniel-mar | 432 | function _DeleteConfirmation: boolean; |
433 | var |
||
434 | sc: Char; |
||
435 | begin |
||
436 | repeat |
||
437 | ShowMessage('Are you sure you want to delete this OID? (Y/N)', 'DELETE OID', true); |
||
737 | daniel-mar | 438 | DrawStatusBar('Y=Yes, N=No'); |
735 | daniel-mar | 439 | |
440 | sc := ReadKey; |
||
441 | if sc = #0 then |
||
442 | begin |
||
443 | (* Extended key. Nothing we care about. *) |
||
444 | ReadKey; |
||
445 | continue; |
||
446 | end; |
||
447 | |||
448 | if UpCase(sc) = 'Y' then |
||
449 | begin |
||
450 | _DeleteConfirmation := true; |
||
451 | break; |
||
737 | daniel-mar | 452 | end |
453 | else if UpCase(sc) = 'N' then |
||
735 | daniel-mar | 454 | begin |
455 | _DeleteConfirmation := false; |
||
456 | break; |
||
457 | end; |
||
458 | until false; |
||
459 | end; |
||
460 | |||
737 | daniel-mar | 461 | procedure _DrawOidTitleBar(filename: string; oid: POID); |
462 | begin |
||
463 | if oid^.DotNotation = '' then |
||
464 | DrawTitleBar('OID ROOT') |
||
465 | else |
||
466 | DrawTitleBar('OID ' + oid^.DotNotation); |
||
467 | |||
468 | (* Put loaded filename into the title bar *) |
||
469 | GotoXY(ScreenWidth-Length(filename)+1,1); |
||
470 | TextBackground(White); |
||
471 | TextColor(Black); |
||
472 | WriteLn(filename); |
||
473 | TextBackground(Black); |
||
474 | TextColor(White); |
||
475 | end; |
||
476 | |||
733 | daniel-mar | 477 | procedure DisplayOIDFile(filename: string); |
478 | var |
||
479 | isRoot: boolean; |
||
735 | daniel-mar | 480 | oid: POID; |
733 | daniel-mar | 481 | i, menuX, menuY: integer; |
482 | linesLeft, linesRequired: integer; |
||
483 | sTmp, subfile: string; |
||
484 | subsel, subfiles: PStringList; |
||
485 | subselres: integer; |
||
735 | daniel-mar | 486 | exitRequest: boolean; |
487 | menuIdExit, menuIdAsnEdit, menuIdDescEdit, menuIdAdd, menuIdDelete: integer; |
||
733 | daniel-mar | 488 | begin |
735 | daniel-mar | 489 | exitRequest := false; |
733 | daniel-mar | 490 | repeat |
735 | daniel-mar | 491 | CreateOidDef(oid); |
492 | _ReadOidFile(filename, oid); |
||
733 | daniel-mar | 493 | |
494 | (* Print OID information *) |
||
495 | |||
496 | ClrScr; |
||
737 | daniel-mar | 497 | _DrawOidTitleBar(filename, oid); |
733 | daniel-mar | 498 | DrawStatusBar(DEFAULT_STATUSBAR); |
499 | GotoXY(1,2); |
||
500 | |||
735 | daniel-mar | 501 | if oid^.DotNotation <> '' then |
733 | daniel-mar | 502 | begin |
503 | WriteLn('Dot-Notation:'); |
||
735 | daniel-mar | 504 | WriteLn(oid^.DotNotation); |
733 | daniel-mar | 505 | WriteLn(''); |
506 | end; |
||
507 | |||
735 | daniel-mar | 508 | if Trim(oid^.Description) <> '' then |
733 | daniel-mar | 509 | begin |
510 | WriteLn('Description:'); |
||
735 | daniel-mar | 511 | WriteLn(oid^.Description); |
733 | daniel-mar | 512 | WriteLn(''); |
513 | end; |
||
514 | |||
515 | menuX := WhereX + 1; |
||
735 | daniel-mar | 516 | menuY := ScreenHeight - ACTIONMENU_SIZE - 1; |
733 | daniel-mar | 517 | |
735 | daniel-mar | 518 | if ListCount(oid^.ASNIDs) > 0 then |
733 | daniel-mar | 519 | begin |
520 | linesLeft := menuY - WhereY - 1; |
||
735 | daniel-mar | 521 | linesRequired := 1 + ListCount(oid^.ASNIds); |
733 | daniel-mar | 522 | |
523 | if LinesLeft < LinesRequired then |
||
524 | begin |
||
525 | (* Compact display of ASN.1 identifiers *) |
||
526 | Write('ASN.1-Identifiers: '); |
||
735 | daniel-mar | 527 | for i := 0 to ListCount(oid^.ASNIds)-1 do |
733 | daniel-mar | 528 | begin |
529 | if i > 0 then Write(', '); |
||
735 | daniel-mar | 530 | Write(ListGetElement(oid^.ASNIds, i)); |
733 | daniel-mar | 531 | end; |
532 | WriteLn(''); |
||
533 | end |
||
534 | else |
||
535 | begin |
||
536 | (* Long display of ASN.1 identifiers *) |
||
537 | WriteLn('ASN.1-Identifiers:'); |
||
735 | daniel-mar | 538 | for i := 0 to ListCount(oid^.ASNIds)-1 do |
733 | daniel-mar | 539 | begin |
735 | daniel-mar | 540 | WriteLn('- '+ListGetElement(oid^.ASNIds, i)); |
733 | daniel-mar | 541 | end; |
542 | WriteLn(''); |
||
543 | end; |
||
544 | end; |
||
545 | |||
546 | (* Now prepare the menu entries *) |
||
547 | |||
737 | daniel-mar | 548 | CreateList(subsel); (* Contains the human readable OID name *) |
549 | CreateList(subfiles); (* Contains the file name *) |
||
733 | daniel-mar | 550 | |
735 | daniel-mar | 551 | if oid^.Parent = '' then |
733 | daniel-mar | 552 | begin |
553 | isRoot := true; |
||
554 | end |
||
555 | else |
||
556 | begin |
||
735 | daniel-mar | 557 | isRoot := DotNotationPart(oid^.Parent) = oid^.DotNotation; |
733 | daniel-mar | 558 | end; |
559 | |||
735 | daniel-mar | 560 | if (oid^.Parent <> '') and not isRoot then |
733 | daniel-mar | 561 | begin |
735 | daniel-mar | 562 | sTmp := oid^.Parent; |
563 | subfile := FileIdPart(sTmp) + '.OID'; |
||
564 | ListAppend(subsel, 'Go to parent ' + DotNotationPart(sTmp) + _ShowASNIds(subfile)); |
||
733 | daniel-mar | 565 | ListAppend(subfiles, subfile); |
566 | end; |
||
567 | |||
568 | if isRoot then |
||
569 | begin |
||
735 | daniel-mar | 570 | menuIdExit := ListAppend(subsel, 'Back to main menu'); |
571 | ListAppend(subfiles, ''); |
||
572 | end |
||
573 | else menuIdExit := -99; |
||
733 | daniel-mar | 574 | |
735 | daniel-mar | 575 | for i := 0 to ListCount(oid^.SubIds)-1 do |
733 | daniel-mar | 576 | begin |
735 | daniel-mar | 577 | sTmp := ListGetElement(oid^.SubIds, i); |
578 | subfile := FileIdPart(sTmp) + '.OID'; |
||
579 | ListAppend(subsel, 'Go to child ' + DotNotationPart(sTmp) + _ShowASNIds(subfile)); |
||
733 | daniel-mar | 580 | ListAppend(subfiles, subfile); |
581 | end; |
||
582 | |||
735 | daniel-mar | 583 | if oid^.DotNotation <> '' then |
733 | daniel-mar | 584 | begin |
735 | daniel-mar | 585 | menuIdAsnEdit := ListAppend(subsel, 'Edit ASN.1 identifiers'); |
586 | ListAppend(subfiles, ''); |
||
587 | end |
||
588 | else menuIdAsnEdit := -99; |
||
733 | daniel-mar | 589 | |
735 | daniel-mar | 590 | menuIdDescEdit := ListAppend(subsel, 'Edit description'); |
591 | ListAppend(subfiles, ''); |
||
733 | daniel-mar | 592 | |
735 | daniel-mar | 593 | menuIdAdd := ListAppend(subsel, 'Add child'); |
594 | ListAppend(subfiles, ''); |
||
733 | daniel-mar | 595 | |
596 | if not isRoot then |
||
597 | begin |
||
735 | daniel-mar | 598 | menuIdDelete := ListAppend(subsel, 'Delete OID'); |
599 | ListAppend(subfiles, ''); |
||
600 | end |
||
601 | else menuIdDelete := -99; |
||
733 | daniel-mar | 602 | |
734 | daniel-mar | 603 | (* Show menu *) |
604 | |||
733 | daniel-mar | 605 | subselres := DrawSelectionList(menuX, menuY, |
606 | ScreenWidth-2, |
||
735 | daniel-mar | 607 | ACTIONMENU_SIZE, |
733 | daniel-mar | 608 | subsel, |
609 | true, |
||
610 | 'SELECT ACTION', |
||
611 | 1); |
||
734 | daniel-mar | 612 | |
613 | (* Process user selection *) |
||
614 | |||
733 | daniel-mar | 615 | if subselres = -1 then |
616 | begin |
||
735 | daniel-mar | 617 | exitRequest := true; |
733 | daniel-mar | 618 | end |
735 | daniel-mar | 619 | else if subselres = menuIdAsnEdit then |
733 | daniel-mar | 620 | begin |
735 | daniel-mar | 621 | if AsnEditor(oid) then |
622 | _WriteOidFile(filename, oid); |
||
623 | end |
||
624 | else if subselres = menuIdDescEdit then |
||
625 | begin |
||
626 | if DescEditor(oid) then |
||
627 | _WriteOidFile(filename, oid); |
||
628 | end |
||
629 | else if subselres = menuIdAdd then |
||
630 | begin |
||
631 | if NewOidEditor(oid) then |
||
632 | _WriteOidFile(filename, oid); |
||
633 | end |
||
634 | else if subselres = menuIdDelete then |
||
635 | begin |
||
636 | if _DeleteConfirmation then |
||
733 | daniel-mar | 637 | begin |
735 | daniel-mar | 638 | filename := FileIdPart(oid^.Parent) + '.OID'; |
639 | DeleteOidRecursive(oid); |
||
733 | daniel-mar | 640 | end; |
735 | daniel-mar | 641 | end |
642 | else if subselres = menuIdExit then |
||
643 | begin |
||
644 | exitRequest := true; |
||
645 | end |
||
646 | else |
||
647 | begin |
||
648 | (* Normal OID *) |
||
649 | filename := ListGetElement(subfiles, subselres); |
||
733 | daniel-mar | 650 | end; |
651 | FreeList(subsel); |
||
652 | FreeList(subfiles); |
||
653 | |||
735 | daniel-mar | 654 | FreeOidDef(oid); |
655 | until exitRequest; |
||
733 | daniel-mar | 656 | end; |
657 | |||
658 | procedure CreateInitOIDFile(filename: string); |
||
659 | var |
||
735 | daniel-mar | 660 | oid: POID; |
733 | daniel-mar | 661 | begin |
735 | daniel-mar | 662 | CreateOidDef(oid); |
663 | oid^.Description := 'This is the root of the OID tree.' +#13#10 + |
||
664 | #13#10 + |
||
665 | 'Valid subsequent arcs are per definition:' + #13#10 + |
||
666 | '- 0 (itu-t)' + #13#10 + |
||
667 | '- 1 (iso)' + #13#10 + |
||
668 | '- 2 (joint-iso-itu-t)'; |
||
737 | daniel-mar | 669 | oid^.FileId := ZeroPad(0, 8); |
735 | daniel-mar | 670 | oid^.DotNotation := ''; |
737 | daniel-mar | 671 | oid^.Parent := ZeroPad(0, 8); |
735 | daniel-mar | 672 | _WriteOidFile(filename, oid); |
673 | FreeOidDef(oid); |
||
733 | daniel-mar | 674 | end; |
675 | |||
676 | procedure OP_ManageOIDs; |
||
735 | daniel-mar | 677 | var |
678 | initFile: string; |
||
733 | daniel-mar | 679 | begin |
680 | ClrScr; |
||
681 | DrawTitleBar('Manage Object Identifiers'); |
||
682 | DrawStatusBar(''); |
||
683 | |||
735 | daniel-mar | 684 | initFile := ZeroPad(0, 8) + '.OID'; |
685 | if not FileExists(initFile) then |
||
733 | daniel-mar | 686 | begin |
735 | daniel-mar | 687 | CreateInitOIDFile(initFile); |
733 | daniel-mar | 688 | end; |
735 | daniel-mar | 689 | DisplayOIDFile(initFile); |
733 | daniel-mar | 690 | end; |
691 | |||
692 | procedure OP_ManageRAs; |
||
693 | begin |
||
694 | ClrScr; |
||
695 | DrawTitleBar('Manage Registration Authorities'); |
||
696 | DrawStatusBar(''); |
||
697 | |||
698 | (* TODO: Implement "Manage RAs" feature *) |
||
699 | end; |
||
700 | |||
701 | procedure OP_ReturnToMSDOS; |
||
702 | begin |
||
703 | ClrScr; |
||
704 | end; |
||
705 | |||
706 | procedure OP_MainMenu; |
||
707 | var |
||
708 | menu: PStringList; |
||
709 | menuRes, menuLeft, menuTop: integer; |
||
735 | daniel-mar | 710 | menuIdOID, menuIdRA, menuIdExit: integer; |
733 | daniel-mar | 711 | begin |
712 | repeat |
||
713 | ClrScr; |
||
714 | |||
715 | DrawTitleBar('Welcome to OIDplus for DOS'); |
||
716 | DrawStatusBar(DEFAULT_STATUSBAR); |
||
717 | GoToXY(ScreenWidth-Length(VERSIONINFO), ScreenHeight-1); |
||
718 | Write(VERSIONINFO); |
||
719 | |||
735 | daniel-mar | 720 | CreateList(menu); |
721 | |||
722 | menuIdOID := ListAppend(menu, 'Manage OIDs'); |
||
723 | menuIdRA := -99; (*ListAppend(menu, 'Manage RAs');*) |
||
724 | menuIdExit := ListAppend(menu, 'Return to DOS'); |
||
725 | |||
726 | menuLeft := round(ScreenWidth/2 -MAINMENU_WIDTH/2); |
||
727 | menuTop := round(ScreenHeight/2-MAINMENU_HEIGHT/2); |
||
728 | menuRes := DrawSelectionList(menuLeft, menuTop, |
||
729 | MAINMENU_WIDTH, MAINMENU_HEIGHT, |
||
730 | menu, true, 'MAIN MENU', 2); |
||
733 | daniel-mar | 731 | FreeList(menu); |
732 | |||
735 | daniel-mar | 733 | if menuRes = menuIdOID then |
733 | daniel-mar | 734 | begin |
735 | OP_ManageOIDs; |
||
735 | daniel-mar | 736 | end |
737 | else if menuRes = menuIdRA then |
||
733 | daniel-mar | 738 | begin |
739 | OP_ManageRAs; |
||
740 | end; |
||
735 | daniel-mar | 741 | until (menuRes = menuIdExit) or (MAINMENU_ALLOW_ESC and (menuRes = -1)); |
733 | daniel-mar | 742 | |
743 | OP_ReturnToMSDOS; |
||
744 | end; |
||
745 | |||
746 | begin |
||
747 | OP_MainMenu; |
||
748 | end. |