source: trunk/dll/avl.c@ 2

Last change on this file since 2 was 2, checked in by root, 23 years ago

Initial revision

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