1 |
|
---|
2 | /***********************************************************************
|
---|
3 |
|
---|
4 | $Id: avl.c 287 2005-12-31 23:01:21Z root $
|
---|
5 |
|
---|
6 | archiver.bb2 search, load, save and date parse
|
---|
7 |
|
---|
8 | Copyright (c) 1993, 1998 M. Kimes
|
---|
9 | Copyright (c) 2004, 2005 Steven H.Levine
|
---|
10 |
|
---|
11 | 01 Aug 04 SHL Rework lstrip/rstrip usage
|
---|
12 | 13 Aug 05 SHL Beautify with indent
|
---|
13 | 13 Aug 05 SHL find_type: correct no sig exists bypass logic
|
---|
14 | 13 Aug 05 SHL SBoxDlgProc: avoid dereferencing NULL signature
|
---|
15 | 18 Aug 05 SHL Comments
|
---|
16 | 31 Dec 05 SHL indent -i2
|
---|
17 |
|
---|
18 | ***********************************************************************/
|
---|
19 |
|
---|
20 | #define INCL_WIN
|
---|
21 | #define INCL_DOS
|
---|
22 | #include <os2.h>
|
---|
23 |
|
---|
24 | #include <stdlib.h>
|
---|
25 | #include <stdio.h>
|
---|
26 | #include <string.h>
|
---|
27 | #include <share.h>
|
---|
28 | #include <ctype.h>
|
---|
29 |
|
---|
30 | #include "fm3dll.h"
|
---|
31 | #include "fm3dlg.h"
|
---|
32 | #include "fm3str.h"
|
---|
33 |
|
---|
34 | BOOL loadedarcs;
|
---|
35 |
|
---|
36 | #pragma alloc_text(MISC9,quick_find_type,find_type)
|
---|
37 |
|
---|
38 | ARC_TYPE *quick_find_type(CHAR * filespec, ARC_TYPE * topsig)
|
---|
39 | {
|
---|
40 | ARC_TYPE *info, *found = NULL;
|
---|
41 | CHAR *p;
|
---|
42 |
|
---|
43 | if (!loadedarcs)
|
---|
44 | load_archivers();
|
---|
45 | p = strrchr(filespec, '.');
|
---|
46 | if (p)
|
---|
47 | {
|
---|
48 | p++;
|
---|
49 | info = (topsig) ? topsig : arcsighead;
|
---|
50 | while (info)
|
---|
51 | {
|
---|
52 | if (info -> ext &&
|
---|
53 | *(info -> ext) &&
|
---|
54 | !stricmp(p, info -> ext))
|
---|
55 | {
|
---|
56 | found = find_type(filespec, topsig);
|
---|
57 | break;
|
---|
58 | }
|
---|
59 | info = info -> next;
|
---|
60 | }
|
---|
61 | }
|
---|
62 | return found;
|
---|
63 | }
|
---|
64 |
|
---|
65 | ARC_TYPE *find_type(CHAR * filespec, ARC_TYPE * topsig)
|
---|
66 | {
|
---|
67 | HFILE handle;
|
---|
68 | ULONG action;
|
---|
69 | ULONG len;
|
---|
70 | ULONG l;
|
---|
71 | ARC_TYPE *info;
|
---|
72 | CHAR *p;
|
---|
73 | CHAR buffer[80];
|
---|
74 |
|
---|
75 | if (!loadedarcs)
|
---|
76 | load_archivers();
|
---|
77 | if (!topsig)
|
---|
78 | topsig = arcsighead;
|
---|
79 | DosError(FERR_DISABLEHARDERR);
|
---|
80 | if (DosOpen(filespec,
|
---|
81 | &handle,
|
---|
82 | &action,
|
---|
83 | 0L,
|
---|
84 | 0L,
|
---|
85 | OPEN_ACTION_FAIL_IF_NEW |
|
---|
86 | OPEN_ACTION_OPEN_IF_EXISTS,
|
---|
87 | OPEN_FLAGS_FAIL_ON_ERROR |
|
---|
88 | OPEN_FLAGS_NOINHERIT |
|
---|
89 | OPEN_FLAGS_RANDOMSEQUENTIAL |
|
---|
90 | OPEN_SHARE_DENYNONE |
|
---|
91 | OPEN_ACCESS_READONLY,
|
---|
92 | 0L))
|
---|
93 | return NULL;
|
---|
94 | // Scan signatures
|
---|
95 | for (info = topsig; info; info = info -> next)
|
---|
96 | {
|
---|
97 | if (!info -> signature || !*info -> signature)
|
---|
98 | {
|
---|
99 | // No signature -- check extension
|
---|
100 | p = strrchr(filespec, '.');
|
---|
101 | if (p)
|
---|
102 | {
|
---|
103 | p++;
|
---|
104 | if (info -> ext &&
|
---|
105 | *(info -> ext) &&
|
---|
106 | !stricmp(p, info -> ext))
|
---|
107 | break; // Matched
|
---|
108 |
|
---|
109 | }
|
---|
110 | continue; // Next sig
|
---|
111 |
|
---|
112 | }
|
---|
113 | // Try signature match
|
---|
114 | l = strlen(info -> signature);
|
---|
115 | l = min(l, 79);
|
---|
116 | if (!DosChgFilePtr(handle,
|
---|
117 | abs(info -> file_offset),
|
---|
118 | (info -> file_offset >= 0L) ?
|
---|
119 | FILE_BEGIN :
|
---|
120 | FILE_END,
|
---|
121 | &len))
|
---|
122 | {
|
---|
123 | if (!DosRead(handle,
|
---|
124 | buffer,
|
---|
125 | l,
|
---|
126 | &len) &&
|
---|
127 | len == l)
|
---|
128 | {
|
---|
129 | if (!memcmp(info -> signature,
|
---|
130 | buffer,
|
---|
131 | l))
|
---|
132 | break; // Matched
|
---|
133 |
|
---|
134 | }
|
---|
135 | }
|
---|
136 | } // for
|
---|
137 |
|
---|
138 | DosClose(handle); /* Either way, we're done for now */
|
---|
139 | return info; /* Return signature, if any */
|
---|
140 | }
|
---|
141 |
|
---|
142 | #pragma alloc_text(AVL,load_archivers)
|
---|
143 |
|
---|
144 | INT load_archivers(VOID)
|
---|
145 | {
|
---|
146 | FILE *handle;
|
---|
147 | CHAR s[257];
|
---|
148 | CHAR *p;
|
---|
149 | ARC_TYPE *info = NULL;
|
---|
150 | ARC_TYPE *last = NULL;
|
---|
151 | INT numlines = NUMLINES;
|
---|
152 | INT x;
|
---|
153 |
|
---|
154 | loadedarcs = TRUE;
|
---|
155 | DosEnterCritSec();
|
---|
156 | p = searchpath(GetPString(IDS_ARCHIVERBB2));
|
---|
157 | if (!p || !*p)
|
---|
158 | {
|
---|
159 | DosExitCritSec();
|
---|
160 | return -1;
|
---|
161 | }
|
---|
162 | handle = _fsopen(p, "r", SH_DENYWR);
|
---|
163 | DosExitCritSec();
|
---|
164 | if (!handle)
|
---|
165 | return -2;
|
---|
166 | strcpy(archiverbb2, p);
|
---|
167 | // Get lines per record count
|
---|
168 | if (!fgets(s, 256, handle))
|
---|
169 | {
|
---|
170 | fclose(handle);
|
---|
171 | return -3;
|
---|
172 | }
|
---|
173 | p = strchr(s, ';');
|
---|
174 | if (p)
|
---|
175 | *p = 0; // Chop trailing comment
|
---|
176 |
|
---|
177 | bstripcr(s);
|
---|
178 | if (*s)
|
---|
179 | numlines = atoi(s);
|
---|
180 | if (!*s || numlines < NUMLINES)
|
---|
181 | return -3;
|
---|
182 | // Parse rest
|
---|
183 | while (!feof(handle))
|
---|
184 | {
|
---|
185 | if (!fgets(s, 256, handle))
|
---|
186 | break; // EOF
|
---|
187 |
|
---|
188 | p = strchr(s, ';');
|
---|
189 | if (p)
|
---|
190 | *p = 0; // Chop comment
|
---|
191 |
|
---|
192 | bstripcr(s);
|
---|
193 | // 1st non-blank line starts definition
|
---|
194 | // fixme to preserve comments
|
---|
195 | // fixme to avoid allocating empty fields
|
---|
196 | if (*s)
|
---|
197 | {
|
---|
198 | info = malloc(sizeof(ARC_TYPE));
|
---|
199 | if (!info)
|
---|
200 | break; // fixme to complain
|
---|
201 |
|
---|
202 | memset(info, 0, sizeof(ARC_TYPE));
|
---|
203 | if (*s)
|
---|
204 | info -> id = strdup(s);
|
---|
205 | else
|
---|
206 | info -> id = NULL;
|
---|
207 | if (!fgets(s, 256, handle))
|
---|
208 | break;
|
---|
209 | p = strchr(s, ';');
|
---|
210 | if (p)
|
---|
211 | *p = 0;
|
---|
212 | bstripcr(s);
|
---|
213 | if (*s)
|
---|
214 | info -> ext = strdup(s);
|
---|
215 | else
|
---|
216 | info -> ext = NULL;
|
---|
217 | if (!fgets(s, 256, handle))
|
---|
218 | break;
|
---|
219 | p = strchr(s, ';');
|
---|
220 | if (p)
|
---|
221 | *p = 0;
|
---|
222 | info -> file_offset = atol(s);
|
---|
223 | if (!fgets(s, 256, handle))
|
---|
224 | break;
|
---|
225 | p = strchr(s, ';');
|
---|
226 | if (p)
|
---|
227 | *p = 0;
|
---|
228 | bstripcr(s);
|
---|
229 | if (*s)
|
---|
230 | info -> list = strdup(s);
|
---|
231 | else
|
---|
232 | info -> list = NULL;
|
---|
233 | if (!info -> list)
|
---|
234 | break;
|
---|
235 | if (!fgets(s, 256, handle))
|
---|
236 | break;
|
---|
237 | p = strchr(s, ';');
|
---|
238 | if (p)
|
---|
239 | *p = 0;
|
---|
240 | bstripcr(s);
|
---|
241 | if (*s)
|
---|
242 | info -> extract = strdup(s);
|
---|
243 | else
|
---|
244 | info -> extract = NULL;
|
---|
245 | if (!fgets(s, 256, handle))
|
---|
246 | break;
|
---|
247 | p = strchr(s, ';');
|
---|
248 | if (p)
|
---|
249 | *p = 0;
|
---|
250 | bstripcr(s);
|
---|
251 | if (*s)
|
---|
252 | info -> exwdirs = strdup(s);
|
---|
253 | else
|
---|
254 | info -> exwdirs = NULL;
|
---|
255 | if (!fgets(s, 256, handle))
|
---|
256 | break;
|
---|
257 | p = strchr(s, ';');
|
---|
258 | if (p)
|
---|
259 | *p = 0;
|
---|
260 | bstripcr(s);
|
---|
261 | if (*s)
|
---|
262 | info -> test = strdup(s);
|
---|
263 | else
|
---|
264 | info -> test = NULL;
|
---|
265 | if (!fgets(s, 256, handle))
|
---|
266 | break;
|
---|
267 | p = strchr(s, ';');
|
---|
268 | if (p)
|
---|
269 | *p = 0;
|
---|
270 | bstripcr(s);
|
---|
271 | if (*s)
|
---|
272 | info -> create = strdup(s);
|
---|
273 | else
|
---|
274 | info -> create = NULL;
|
---|
275 | if (!fgets(s, 256, handle))
|
---|
276 | break;
|
---|
277 | p = strchr(s, ';');
|
---|
278 | if (p)
|
---|
279 | *p = 0; // Chop comment
|
---|
280 |
|
---|
281 | bstripcr(s);
|
---|
282 | if (*s)
|
---|
283 | info -> createwdirs = strdup(s);
|
---|
284 | else
|
---|
285 | info -> createwdirs = NULL;
|
---|
286 | if (!fgets(s, 256, handle))
|
---|
287 | break;
|
---|
288 | p = strchr(s, ';');
|
---|
289 | if (p)
|
---|
290 | *p = 0;
|
---|
291 | bstripcr(s);
|
---|
292 | if (*s)
|
---|
293 | info -> createrecurse = strdup(s);
|
---|
294 | else
|
---|
295 | info -> createrecurse = NULL;
|
---|
296 | if (!fgets(s, 256, handle))
|
---|
297 | break;
|
---|
298 | p = strchr(s, ';');
|
---|
299 | if (p)
|
---|
300 | *p = 0;
|
---|
301 | bstripcr(s);
|
---|
302 | if (*s)
|
---|
303 | info -> move = strdup(s);
|
---|
304 | else
|
---|
305 | info -> move = NULL;
|
---|
306 | if (!fgets(s, 256, handle))
|
---|
307 | break;
|
---|
308 | p = strchr(s, ';');
|
---|
309 | if (p)
|
---|
310 | *p = 0;
|
---|
311 | bstripcr(s);
|
---|
312 | if (*s)
|
---|
313 | info -> movewdirs = strdup(s);
|
---|
314 | else
|
---|
315 | info -> movewdirs = NULL;
|
---|
316 | if (!fgets(s, 256, handle))
|
---|
317 | break;
|
---|
318 | p = strchr(s, ';');
|
---|
319 | if (p)
|
---|
320 | *p = 0;
|
---|
321 | bstripcr(s);
|
---|
322 | info -> delete = strdup(s);
|
---|
323 | if (!fgets(s, 256, handle))
|
---|
324 | break;
|
---|
325 | stripcr(s);
|
---|
326 | literal(s);
|
---|
327 | if (*s)
|
---|
328 | {
|
---|
329 | info -> signature = strdup(s);
|
---|
330 | if (!info -> signature)
|
---|
331 | break;
|
---|
332 | }
|
---|
333 | else
|
---|
334 | info -> signature = NULL;
|
---|
335 | if (!fgets(s, 256, handle))
|
---|
336 | break;
|
---|
337 | stripcr(s);
|
---|
338 | info -> startlist = strdup(s);
|
---|
339 | if (!fgets(s, 256, handle))
|
---|
340 | break;
|
---|
341 | stripcr(s);
|
---|
342 | if (*s)
|
---|
343 | info -> endlist = strdup(s);
|
---|
344 | else
|
---|
345 | info -> endlist = NULL;
|
---|
346 | if (!fgets(s, 256, handle))
|
---|
347 | break;
|
---|
348 | p = strchr(s, ';');
|
---|
349 | if (p)
|
---|
350 | *p = 0;
|
---|
351 | info -> osizepos = atoi(s);
|
---|
352 | if (!fgets(s, 256, handle))
|
---|
353 | break;
|
---|
354 | p = strchr(s, ';');
|
---|
355 | if (p)
|
---|
356 | *p = 0;
|
---|
357 | info -> nsizepos = atoi(s);
|
---|
358 | if (!fgets(s, 256, handle))
|
---|
359 | break;
|
---|
360 | p = strchr(s, ';');
|
---|
361 | if (p)
|
---|
362 | *p = 0;
|
---|
363 | info -> fdpos = atoi(s);
|
---|
364 | p = strchr(s, ',');
|
---|
365 | if (p)
|
---|
366 | {
|
---|
367 | p++;
|
---|
368 | info -> datetype = atoi(p);
|
---|
369 | }
|
---|
370 | if (!fgets(s, 256, handle))
|
---|
371 | break;
|
---|
372 | p = strchr(s, ';');
|
---|
373 | if (p)
|
---|
374 | *p = 0;
|
---|
375 | info -> fdflds = atoi(s);
|
---|
376 | if (!fgets(s, 256, handle))
|
---|
377 | break;
|
---|
378 | p = strchr(s, ';');
|
---|
379 | if (p)
|
---|
380 | *p = 0;
|
---|
381 | info -> fnpos = atoi(s);
|
---|
382 | p = strchr(s, ',');
|
---|
383 | if (p)
|
---|
384 | {
|
---|
385 | p++;
|
---|
386 | info -> nameislast = (BOOL) (*p && atol(p) == 0) ? FALSE : TRUE;
|
---|
387 | p = strchr(p, ',');
|
---|
388 | if (p)
|
---|
389 | {
|
---|
390 | p++;
|
---|
391 | info -> nameisnext = (BOOL) (*p && atol(p) == 0) ? FALSE : TRUE;
|
---|
392 | p = strchr(p, ',');
|
---|
393 | if (p)
|
---|
394 | {
|
---|
395 | p++;
|
---|
396 | info -> nameisfirst = (BOOL) (*p && atol(p) == 0) ? FALSE : TRUE;
|
---|
397 | }
|
---|
398 | }
|
---|
399 | }
|
---|
400 | // Ignore unknown lines - must be newer file format
|
---|
401 | for (x = NUMLINES; x < numlines; x++)
|
---|
402 | {
|
---|
403 | if (!fgets(s, 256, handle))
|
---|
404 | break;
|
---|
405 | }
|
---|
406 |
|
---|
407 | info -> next = NULL;
|
---|
408 |
|
---|
409 | if (!arcsighead)
|
---|
410 | {
|
---|
411 | arcsighead = last = info;
|
---|
412 | info -> prev = NULL;
|
---|
413 | }
|
---|
414 | else
|
---|
415 | {
|
---|
416 | last -> next = info;
|
---|
417 | info -> prev = last;
|
---|
418 | last = info;
|
---|
419 | }
|
---|
420 | if (info -> extract && !*info -> extract)
|
---|
421 | {
|
---|
422 | free(info -> extract);
|
---|
423 | info -> extract = NULL;
|
---|
424 | }
|
---|
425 | } // if got definition
|
---|
426 |
|
---|
427 | info = NULL;
|
---|
428 | }
|
---|
429 | fclose(handle);
|
---|
430 | if (info)
|
---|
431 | {
|
---|
432 | // fixme to complain about partial definition
|
---|
433 | if (info -> id)
|
---|
434 | free(info -> id);
|
---|
435 | if (info -> ext)
|
---|
436 | free(info -> ext);
|
---|
437 | if (info -> list)
|
---|
438 | free(info -> list);
|
---|
439 | if (info -> extract)
|
---|
440 | free(info -> extract);
|
---|
441 | if (info -> create)
|
---|
442 | free(info -> create);
|
---|
443 | if (info -> move)
|
---|
444 | free(info -> move);
|
---|
445 | if (info -> delete)
|
---|
446 | free(info -> delete);
|
---|
447 | if (info -> signature)
|
---|
448 | free(info -> signature);
|
---|
449 | if (info -> startlist)
|
---|
450 | free(info -> startlist);
|
---|
451 | if (info -> endlist)
|
---|
452 | free(info -> endlist);
|
---|
453 | if (info -> exwdirs)
|
---|
454 | free(info -> exwdirs);
|
---|
455 | if (info -> test)
|
---|
456 | free(info -> test);
|
---|
457 | if (info -> createrecurse)
|
---|
458 | free(info -> createrecurse);
|
---|
459 | if (info -> createwdirs)
|
---|
460 | free(info -> createwdirs);
|
---|
461 | if (info -> movewdirs)
|
---|
462 | free(info -> movewdirs);
|
---|
463 | }
|
---|
464 | if (!arcsighead)
|
---|
465 | return -4;
|
---|
466 | return 0;
|
---|
467 | }
|
---|
468 |
|
---|
469 | #pragma alloc_text(FMARCHIVE,SBoxDlgProc)
|
---|
470 |
|
---|
471 | MRESULT EXPENTRY SBoxDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
472 | {
|
---|
473 | /* dlg proc that allows selecting an archiver entry */
|
---|
474 |
|
---|
475 | ARC_TYPE **info, *temp, *test;
|
---|
476 | SHORT sSelect, x;
|
---|
477 | CHAR text[256];
|
---|
478 |
|
---|
479 | switch (msg)
|
---|
480 | {
|
---|
481 | case WM_INITDLG:
|
---|
482 | if (!loadedarcs)
|
---|
483 | load_archivers();
|
---|
484 | if (!(ARC_TYPE **) mp2)
|
---|
485 | {
|
---|
486 | DosBeep(100, 100);
|
---|
487 | WinDismissDlg(hwnd, 0);
|
---|
488 | break;
|
---|
489 | }
|
---|
490 | info = (ARC_TYPE **) mp2;
|
---|
491 | if (*info)
|
---|
492 | *info = arcsighead;
|
---|
493 | WinSetWindowPtr(hwnd, 0L, (PVOID) info);
|
---|
494 | temp = arcsighead;
|
---|
495 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
|
---|
496 | /* this loop fills the listbox */
|
---|
497 | {
|
---|
498 | BOOL found = FALSE;
|
---|
499 |
|
---|
500 | while (temp)
|
---|
501 | {
|
---|
502 | /*
|
---|
503 | * this inner loop tests for a dupe signature entry and assures
|
---|
504 | * that only the entry at the top of the list gets used for
|
---|
505 | * conversion; editing any is okay
|
---|
506 | */
|
---|
507 | if (*info)
|
---|
508 | {
|
---|
509 | test = arcsighead;
|
---|
510 | while (test && test != temp)
|
---|
511 | {
|
---|
512 | if (test -> signature && temp -> signature &&
|
---|
513 | !strcmp(test -> signature, temp -> signature))
|
---|
514 | goto ContinueHere; // Got match
|
---|
515 |
|
---|
516 | test = test -> next;
|
---|
517 | }
|
---|
518 | }
|
---|
519 |
|
---|
520 | if (!*info || (temp -> id && temp -> extract && temp -> create))
|
---|
521 | {
|
---|
522 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_INSERTITEM,
|
---|
523 | MPFROM2SHORT(LIT_END, 0),
|
---|
524 | MPFROMP((temp -> id) ?
|
---|
525 | temp -> id : "?"));
|
---|
526 | if (!found && *szDefArc && temp -> id && !strcmp(szDefArc, temp -> id))
|
---|
527 | {
|
---|
528 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_SELECTITEM,
|
---|
529 | MPFROMSHORT(sSelect), MPFROMSHORT(TRUE));
|
---|
530 | found = TRUE;
|
---|
531 | }
|
---|
532 | }
|
---|
533 | else
|
---|
534 | {
|
---|
535 | if (!temp -> id || !*temp -> id)
|
---|
536 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_INSERTITEM,
|
---|
537 | MPFROM2SHORT(LIT_END, 0),
|
---|
538 | MPFROMP(GetPString(IDS_UNKNOWNUNUSABLETEXT)));
|
---|
539 | else
|
---|
540 | {
|
---|
541 | CHAR s[81];
|
---|
542 |
|
---|
543 | sprintf(s, "%0.12s %s",
|
---|
544 | temp -> id,
|
---|
545 | GetPString(IDS_UNUSABLETEXT));
|
---|
546 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_INSERTITEM,
|
---|
547 | MPFROM2SHORT(LIT_END, 0),
|
---|
548 | MPFROMP(s));
|
---|
549 | }
|
---|
550 | }
|
---|
551 |
|
---|
552 | ContinueHere:
|
---|
553 |
|
---|
554 | temp = temp -> next;
|
---|
555 | }
|
---|
556 | if (found)
|
---|
557 | PosOverOkay(hwnd);
|
---|
558 | }
|
---|
559 | break;
|
---|
560 |
|
---|
561 | case WM_COMMAND:
|
---|
562 | info = (ARC_TYPE **) WinQueryWindowPtr(hwnd, 0L);
|
---|
563 | switch (SHORT1FROMMP(mp1))
|
---|
564 | {
|
---|
565 | case DID_OK:
|
---|
566 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
|
---|
567 | ASEL_LISTBOX,
|
---|
568 | LM_QUERYSELECTION,
|
---|
569 | MPFROMSHORT(LIT_FIRST),
|
---|
570 | MPVOID);
|
---|
571 | if (sSelect >= 0)
|
---|
572 | {
|
---|
573 | temp = arcsighead;
|
---|
574 | if (*info)
|
---|
575 | {
|
---|
576 | *text = 0;
|
---|
577 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_QUERYITEMTEXT,
|
---|
578 | MPFROM2SHORT(sSelect, 255), MPFROMP(text));
|
---|
579 | if (*text)
|
---|
580 | {
|
---|
581 | while (temp)
|
---|
582 | {
|
---|
583 | if (temp -> id)
|
---|
584 | {
|
---|
585 | if (!strcmp(text, temp -> id))
|
---|
586 | break;
|
---|
587 | }
|
---|
588 | temp = temp -> next;
|
---|
589 | }
|
---|
590 | }
|
---|
591 | else
|
---|
592 | temp = NULL;
|
---|
593 | }
|
---|
594 | else
|
---|
595 | {
|
---|
596 | x = 0;
|
---|
597 | while (temp)
|
---|
598 | {
|
---|
599 | if (x >= sSelect)
|
---|
600 | break;
|
---|
601 | x++;
|
---|
602 | temp = temp -> next;
|
---|
603 | }
|
---|
604 | }
|
---|
605 | if (temp && (!*info || (temp -> id && temp -> extract &&
|
---|
606 | temp -> create)))
|
---|
607 | {
|
---|
608 | *info = temp;
|
---|
609 | }
|
---|
610 | else
|
---|
611 | {
|
---|
612 | WinSendDlgItemMsg(hwnd, ASEL_LISTBOX, LM_SELECTITEM,
|
---|
613 | MPFROMSHORT(LIT_NONE), FALSE);
|
---|
614 | DosBeep(100, 100);
|
---|
615 | temp = NULL;
|
---|
616 | return 0;
|
---|
617 | }
|
---|
618 | }
|
---|
619 | else
|
---|
620 | {
|
---|
621 | DosBeep(100, 100);
|
---|
622 | return 0;
|
---|
623 | }
|
---|
624 | WinDismissDlg(hwnd, TRUE);
|
---|
625 | return 0;
|
---|
626 |
|
---|
627 | case DID_CANCEL:
|
---|
628 | *info = NULL;
|
---|
629 | PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
|
---|
630 | break;
|
---|
631 |
|
---|
632 | default:
|
---|
633 | break;
|
---|
634 | }
|
---|
635 | return 0;
|
---|
636 |
|
---|
637 | case WM_CONTROL:
|
---|
638 | if (SHORT1FROMMP(mp1) == ASEL_LISTBOX && SHORT2FROMMP(mp1) == LN_ENTER)
|
---|
639 | PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
|
---|
640 | return 0;
|
---|
641 |
|
---|
642 | case WM_CLOSE:
|
---|
643 | WinDismissDlg(hwnd, FALSE);
|
---|
644 | return 0;
|
---|
645 |
|
---|
646 | default:
|
---|
647 | break;
|
---|
648 | }
|
---|
649 | return WinDefDlgProc(hwnd, msg, mp1, mp2);
|
---|
650 | }
|
---|
651 |
|
---|
652 | /*
|
---|
653 | 02-08-96 23:55 1
|
---|
654 | 8 Feb 96 23:55:32 2
|
---|
655 | 8 Feb 96 11:55p 3
|
---|
656 | 96-02-08 23:55:32 4
|
---|
657 | */
|
---|
658 |
|
---|
659 | #pragma alloc_text(ARCCNRS,ArcDateTime)
|
---|
660 |
|
---|
661 | BOOL ArcDateTime(CHAR * dt, INT type, CDATE * cdate, CTIME * ctime)
|
---|
662 | {
|
---|
663 | INT x;
|
---|
664 | BOOL ret = FALSE;
|
---|
665 | CHAR *p, *pp, *pd;
|
---|
666 |
|
---|
667 | if (dt && cdate && ctime)
|
---|
668 | {
|
---|
669 | memset(cdate, 0, sizeof(CDATE));
|
---|
670 | memset(ctime, 0, sizeof(CTIME));
|
---|
671 | if (type)
|
---|
672 | {
|
---|
673 | p = dt;
|
---|
674 | while (*p && *p == ' ')
|
---|
675 | p++;
|
---|
676 | pd = dt;
|
---|
677 | switch (type)
|
---|
678 | {
|
---|
679 | case 1:
|
---|
680 | cdate -> month = atoi(pd);
|
---|
681 | p = to_delim(pd, "-/.");
|
---|
682 | if (p)
|
---|
683 | {
|
---|
684 | p++;
|
---|
685 | cdate -> day = atoi(p);
|
---|
686 | pd = p;
|
---|
687 | p = to_delim(pd, "-/.");
|
---|
688 | if (p)
|
---|
689 | {
|
---|
690 | p++;
|
---|
691 | cdate -> year = atoi(p);
|
---|
692 | if (cdate -> year > 80 && cdate -> year < 1900)
|
---|
693 | cdate -> year += 1900;
|
---|
694 | else if (cdate -> year < 1900)
|
---|
695 | cdate -> year += 2000;
|
---|
696 | ret = TRUE;
|
---|
697 | p = strchr(p, ' ');
|
---|
698 | if (p)
|
---|
699 | {
|
---|
700 | while (*p && *p == ' ')
|
---|
701 | p++;
|
---|
702 | ctime -> hours = atoi(p);
|
---|
703 | p = to_delim(pd, ":.");
|
---|
704 | if (p)
|
---|
705 | {
|
---|
706 | p++;
|
---|
707 | ctime -> minutes = atoi(p);
|
---|
708 | p = to_delim(pd, ":.");
|
---|
709 | if (p)
|
---|
710 | {
|
---|
711 | p++;
|
---|
712 | ctime -> seconds = atoi(p);
|
---|
713 | }
|
---|
714 | }
|
---|
715 | }
|
---|
716 | }
|
---|
717 | }
|
---|
718 | break;
|
---|
719 |
|
---|
720 | case 2:
|
---|
721 | cdate -> day = atoi(p);
|
---|
722 | p = strchr(p, ' ');
|
---|
723 | if (p)
|
---|
724 | {
|
---|
725 | p++;
|
---|
726 | for (x = 0; x < 12; x++)
|
---|
727 | {
|
---|
728 | if (!strnicmp(p, GetPString(IDS_JANUARY + x), 3))
|
---|
729 | break;
|
---|
730 | }
|
---|
731 | if (x < 12)
|
---|
732 | {
|
---|
733 | cdate -> month = x;
|
---|
734 | p = strchr(p, ' ');
|
---|
735 | if (p)
|
---|
736 | {
|
---|
737 | p++;
|
---|
738 | cdate -> year = atoi(p);
|
---|
739 | if (cdate -> year > 80 && cdate -> year < 1900)
|
---|
740 | cdate -> year += 1900;
|
---|
741 | else if (cdate -> year < 1900)
|
---|
742 | cdate -> year += 2000;
|
---|
743 | ret = TRUE;
|
---|
744 | p = strchr(p, ' ');
|
---|
745 | if (p)
|
---|
746 | {
|
---|
747 | while (*p && *p == ' ')
|
---|
748 | p++;
|
---|
749 | ctime -> hours = atoi(p);
|
---|
750 | p = to_delim(pd, ":.");
|
---|
751 | if (p)
|
---|
752 | {
|
---|
753 | p++;
|
---|
754 | ctime -> minutes = atoi(p);
|
---|
755 | p = to_delim(pd, ":.");
|
---|
756 | if (p)
|
---|
757 | {
|
---|
758 | p++;
|
---|
759 | ctime -> seconds = atoi(p);
|
---|
760 | }
|
---|
761 | }
|
---|
762 | }
|
---|
763 | }
|
---|
764 | }
|
---|
765 | }
|
---|
766 | break;
|
---|
767 |
|
---|
768 | case 3:
|
---|
769 | cdate -> day = atoi(p);
|
---|
770 | p = strchr(p, ' ');
|
---|
771 | if (p)
|
---|
772 | {
|
---|
773 | p++;
|
---|
774 | for (x = 0; x < 12; x++)
|
---|
775 | {
|
---|
776 | if (!strnicmp(p, GetPString(IDS_JANUARY + x), 3))
|
---|
777 | break;
|
---|
778 | }
|
---|
779 | if (x < 12)
|
---|
780 | {
|
---|
781 | cdate -> month = x;
|
---|
782 | p = strchr(p, ' ');
|
---|
783 | if (p)
|
---|
784 | {
|
---|
785 | p++;
|
---|
786 | cdate -> year = atoi(p);
|
---|
787 | if (cdate -> year > 80 && cdate -> year < 1900)
|
---|
788 | cdate -> year += 1900;
|
---|
789 | else if (cdate -> year < 1900)
|
---|
790 | cdate -> year += 2000;
|
---|
791 | ret = TRUE;
|
---|
792 | p = strchr(p, ' ');
|
---|
793 | if (p)
|
---|
794 | {
|
---|
795 | while (*p && *p == ' ')
|
---|
796 | p++;
|
---|
797 | ctime -> hours = atoi(p);
|
---|
798 | p = to_delim(pd, ":.");
|
---|
799 | if (p)
|
---|
800 | {
|
---|
801 | p++;
|
---|
802 | pp = p;
|
---|
803 | ctime -> minutes = atoi(p);
|
---|
804 | p = to_delim(pd, ":.");
|
---|
805 | if (p)
|
---|
806 | {
|
---|
807 | p++;
|
---|
808 | ctime -> seconds = atoi(p);
|
---|
809 | p += 2;
|
---|
810 | if (toupper(*p) == 'P')
|
---|
811 | ctime -> hours += 12;
|
---|
812 | }
|
---|
813 | else
|
---|
814 | {
|
---|
815 | p = pp;
|
---|
816 | p += 2;
|
---|
817 | if (toupper(*p) == 'P')
|
---|
818 | ctime -> hours += 12;
|
---|
819 | }
|
---|
820 | }
|
---|
821 | }
|
---|
822 | }
|
---|
823 | }
|
---|
824 | }
|
---|
825 | break;
|
---|
826 |
|
---|
827 | case 4:
|
---|
828 | cdate -> year = atoi(p);
|
---|
829 | if (cdate -> year > 80 && cdate -> year < 1900)
|
---|
830 | cdate -> year += 1900;
|
---|
831 | else if (cdate -> year < 1900)
|
---|
832 | cdate -> year += 2000;
|
---|
833 | p = to_delim(pd, "-/.");
|
---|
834 | if (p)
|
---|
835 | {
|
---|
836 | p++;
|
---|
837 | cdate -> month = atoi(p);
|
---|
838 | pd = p;
|
---|
839 | p = to_delim(pd, "-/.");
|
---|
840 | if (p)
|
---|
841 | {
|
---|
842 | p++;
|
---|
843 | cdate -> day = atoi(p);
|
---|
844 | ret = TRUE;
|
---|
845 | p = strchr(p, ' ');
|
---|
846 | if (p)
|
---|
847 | {
|
---|
848 | while (*p && *p == ' ')
|
---|
849 | p++;
|
---|
850 | ctime -> hours = atoi(p);
|
---|
851 | p = to_delim(pd, ":.");
|
---|
852 | if (p)
|
---|
853 | {
|
---|
854 | p++;
|
---|
855 | ctime -> minutes = atoi(p);
|
---|
856 | p = to_delim(pd, ":.");
|
---|
857 | if (p)
|
---|
858 | {
|
---|
859 | p++;
|
---|
860 | ctime -> seconds = atoi(p);
|
---|
861 | }
|
---|
862 | }
|
---|
863 | }
|
---|
864 | }
|
---|
865 | }
|
---|
866 | break;
|
---|
867 |
|
---|
868 | case 5:
|
---|
869 | cdate -> day = atoi(pd);
|
---|
870 | p = to_delim(pd, "-/.");
|
---|
871 | if (p)
|
---|
872 | {
|
---|
873 | p++;
|
---|
874 | cdate -> month = atoi(p);
|
---|
875 | pd = p;
|
---|
876 | p = to_delim(pd, "-/.");
|
---|
877 | if (p)
|
---|
878 | {
|
---|
879 | p++;
|
---|
880 | cdate -> year = atoi(p);
|
---|
881 | if (cdate -> year > 80 && cdate -> year < 1900)
|
---|
882 | cdate -> year += 1900;
|
---|
883 | else if (cdate -> year < 1900)
|
---|
884 | cdate -> year += 2000;
|
---|
885 | ret = TRUE;
|
---|
886 | p = strchr(p, ' ');
|
---|
887 | if (p)
|
---|
888 | {
|
---|
889 | while (*p && *p == ' ')
|
---|
890 | p++;
|
---|
891 | ctime -> hours = atoi(p);
|
---|
892 | p = to_delim(pd, ":.");
|
---|
893 | if (p)
|
---|
894 | {
|
---|
895 | p++;
|
---|
896 | ctime -> minutes = atoi(p);
|
---|
897 | p = to_delim(pd, ":.");
|
---|
898 | if (p)
|
---|
899 | {
|
---|
900 | p++;
|
---|
901 | ctime -> seconds = atoi(p);
|
---|
902 | }
|
---|
903 | }
|
---|
904 | }
|
---|
905 | }
|
---|
906 | }
|
---|
907 | break;
|
---|
908 |
|
---|
909 | default:
|
---|
910 | break;
|
---|
911 | }
|
---|
912 | }
|
---|
913 | }
|
---|
914 | return ret;
|
---|
915 | }
|
---|