-
Notifications
You must be signed in to change notification settings - Fork 0
/
tac180SE.pas
1598 lines (1309 loc) · 41 KB
/
tac180SE.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Program bored_stiff;
(*
Welcome to Therion's Archive Converter 1.80 Special Edition.
Legal stuff first:
Everything belonging to TAC, be it executables or source code, is
(C)opyright 1992-1996 Nocturnal Productions. You are allowed to
distribute the included archives as You wish, but You are NOT
allowed to distribute recompiled or modified versions of ANY of
the sources or programs related to TAC. You are allowed to modify
the source for Your own purposes as long as You keep the modified
sources and executables for Yourself.
** In other words: Spread hacks of my program and I'll get /really/ mad! **
Nevertheless, this program is the result of four years of
programming and testing, of which the last two has given the best
results. Many people have helped me testing it along those years,
so i hope that this release will spread TAC to a wider audience
than before.
My style is messy, so i have tried to clarify it by commenting
this and that here and there. Hope You'll understand whatever
went on in my head when i wrote /that/ particular routine.
Enjoy!
*)
{$IFDEF MSDOS}
{$M 8192,0,8192}
{$ELSE}
{$M 16384}
{$ENDIF}
Uses
{$IFDEF OS2}
use32, os2base,
{$ELSE}
crt,
{$ENDIF}
DOS;
(*
I certainly will not try to explain what all these constants and
variables are good for, although i'm certain that i use them all =) ..
*)
Const
arctypes: String [24] = 'ARCHPKARJLZHPAKTARUC2ZIP';
arctyps: String [8] = 'AHJLPTUZ';
dearctypes: String [144] = 'ARCHPKARJLZHPAKTARUC2ZIP' +
'GZ SITDWCMD LBRSQ SQZSH ' +
'CP HYPCHZLIMHAPHA GASZOO' +
'AR+RARAAFEX UUEXXEAR BIT' +
'HQXCPZCRUCPTPITSPLPP AIN' +
'MIMBLUCMTQ SHPSHKQIPBIN';
tempdir: String [13] = '$$TEMP$$.TAC';
tempfil: String [13] = '$$TEMP$$.FIL';
tempimg: String [13] = '$$TEMP$$.IMG';
redir: String [6] = ' >nul';
in_4DOS: Boolean = False;
in_OS2: Boolean = False;
batches: Boolean = False;
clobber: Boolean = False;
logging: Boolean = False;
delafter: Boolean = False;
striparc: Boolean = True;
inteldet: Boolean = False;
killfile: Boolean = False;
lowercase: Boolean = False;
quietmode: Boolean = False;
virusscan: Boolean = False;
recursion: Boolean = True;
timestamp: Boolean = True;
ExcludeEQ: Boolean = False;
floppymode: Boolean = False;
renameflag: Boolean = False;
keepsmallest: Boolean = False;
THANKSexe: String [10] = 'THANKS.EXE';
TACcfg: String [7] = 'TAC.CFG';
{$IFDEF MSDOS}
id: String [6] = 'TAC þ ';
bat1: String [8] = 'TAC1.BAT';
bat2: String [8] = 'TAC2.BAT';
bat3: String [8] = 'TAC3.BAT';
{$ELSE}
id: String [8] = 'TAC/2 þ ';
bat1: String [8] = 'TAC1.CMD';
bat2: String [8] = 'TAC2.CMD';
bat3: String [8] = 'TAC3.CMD';
{$ENDIF}
verstr: String [4] = '0180';
Type
archiver = Record
filename,
switches,
rswitch,
sswitch:
{$IFDEF OS2}
String;
{$ELSE}
String [32];
{$ENDIF}
End;
dearchiver = Record
filename,
switches,
rswitch:
{$IFDEF OS2}
String;
{$ELSE}
String [32];
{$ENDIF}
End;
virscan = Record
filename,
switches:
{$IFDEF OS2}
String;
{$ELSE}
String [32];
{$ENDIF}
End;
Label skip;
Var
Arc: Array [1..8] Of archiver;
dearc: Array [1..48] Of dearchiver;
vscan: virscan;
IMG_ext: dearchiver;
IMG_fil: dearchiver;
stripzip: String;
striparj: String;
logfile,
echostr: String;
THANKS_parm: String;
THANKS_sdir: String;
i,
o: File;
ci: Text;
lfile: Text;
b1,
b2: Byte;
{$IFDEF OS2}
OKey: KbdKeyInfo;
w1,
w2: LongInt;
{$ELSE}
w1,
w2: Word;
{$ENDIF}
s1,
s2,
s3,
ss1,
ss2,
ss3,
sss,
st2,
st3,
execstr: String;
src: String;
sourcetype: Byte;
desttype: Char;
seekptr: LongInt;
c1,
key: Char;
p: Pointer;
dirinfo: SearchRec;
buf: Array [1..4] Of Char;
bbuf: Array [1..4] Of Byte;
{$IFDEF MSDOS}
(*
Say "Cheese!" =) ..
*)
Procedure headermsg;
Begin
WriteLn;
WriteLn ('Therion''s Archive Converter 1.80SE, (c) 1992-1996 Nocturnal Productions.');
WriteLn;
End;
Procedure showsyntax;
Begin
WriteLn ('Usage: TAC [-|/]<To-format>[switches] <filemask>');
WriteLn;
WriteLn ('Type TAC ? ? for format and switch descriptions');
WriteLn;
End;
{$ELSE}
(*
Say "Cheese!" in 32 Bit =) ..
*)
Procedure headermsg;
Begin
WriteLn;
WriteLn ('Therion''s Archive Converter /2 1.80SE, (c) 1992-1996 Nocturnal Productions.');
WriteLn;
End;
Procedure showsyntax;
Begin
WriteLn ('Usage: TAC2 [-|/]<To-format>[switches] <filemask>');
WriteLn;
WriteLn ('Type TAC2 ? ? for format and switch descriptions');
WriteLn;
End;
{$ENDIF}
Procedure usage;
Begin
{$IFDEF MSDOS}
WriteLn ('Usage: TAC [-|/]<To-format>[switches] <filemask>');
{$ELSE}
WriteLn ('Usage: TAC2 [-|/]<To-format>[switches] <filemask>');
{$ENDIF}
WriteLn;
WriteLn ('To-format is one of the following (preceded with a / or -):');
WriteLn (' A (Arc), H (Hpack), J (Arj), L (Lha), P (Pak), T (Tar), U (UC2) or Z (Zip).');
WriteLn;
WriteLn ('Switches:');
WriteLn (' b to execute ' + bat1 + ' before, ' + bat2 + ' during and ' + bat3 + ' after repacking.');
WriteLn (' c to delete file with same filename as archive to be created.');
WriteLn (' d to delete old files after conversion.');
WriteLn (' e to inhibit use of StripAV and StripARJ.');
WriteLn (' f to treat all input files as Floppy Disk images.');
WriteLn (' i to use intelligent detection instead of file extensions.');
WriteLn (' k to invoke THANKS before re-archiving.');
{$IFDEF OS2}
WriteLn (' o to lowercase file extensions (relevant for HPFS only)');
{$ENDIF}
WriteLn (' q to keep (almost) quiet.');
WriteLn (' r to inhibit recursion.');
WriteLn (' s to inhibit timestamps being set to latest file in archive.');
WriteLn (' v to scan for viruses before creating new archive.');
WriteLn (' w to enable logging.');
WriteLn (' x to skip those archives already in the specified toformat.');
End;
(*
Routines to shut up if the user specified q, and to talk if the user
didn't specify c.
*)
Procedure nuloutput;
Begin
Assign (Output, 'NUL');
Rewrite (Output);
End;
Procedure stdoutput;
Begin
Assign (Output, '');
Rewrite (Output);
End;
(*
Checks for 4DOS to see if we can use redirection to STDERR and for OS/2
to disallow use of the AIN dearchiver, which thrashes the good 'ole WARP.
*)
{$IFDEF MSDOS}
Procedure Test4DOS;
Begin
Asm
MOV AX, 0D44DH
MOV BX, 0
Int 2Fh
CMP AX, 44DDh
JNE @No_fdos
mov BX, CX
mov Word Ptr [w1], BX
mov AH, 51h
mov AL, 0
Int 21h
mov Word Ptr [w2], BX
push DS
mov DS, Word Ptr [w2]
mov SI, 16h
lodsw
pop DS
mov BX, AX
mov Word Ptr [w2], BX
jmp @getout
@no_fdos:
mov Word Ptr [w1], 0
mov Word Ptr [w2], $ffff
@getout:
End;
If w1 = w2 Then in_4DOS := True Else in_4DOS := False;
End;
Function OS2_GetVersion: Word; Assembler;
Asm
MOV AH, 30h
Int 21h
MOV BH, AH
XOr AH, AH
MOV CL, 10
Div CL
MOV AH, BH
XCHG AH, AL
End;
{$ENDIF}
(*
Simple WriteLn() replacement that writes a line to both the screen and
optionally to the log file.
*)
Procedure lwrite (s: String);
Begin
WriteLn (s);
If logging Then WriteLn (lfile, s);
End;
(*
The error handler.
*)
Procedure help (X: Byte);
Begin
If quietmode Then stdoutput;
Case X Of
0: showsyntax;
1: lwrite ('Invalid parameter(s) in command line!');
2: lwrite ('Error reading from input file!');
3: lwrite ('Please set Your COMSPEC environment variable!');
5: lwrite ('Error changing directory!');
7: lwrite ('Parameter error: More than one format specified!');
8: lwrite ('Format not specified and virusscanner not defined!');
10: lwrite ('Error unpacking archive, exiting!');
11: lwrite ('Error packing archive, exiting!');
13: lwrite ('Error deleting old archive, exiting!');
15: lwrite ('Cannot find dearchiver, exiting!');
16: lwrite ('Cannot find archiver, exiting!');
23: lwrite ('Cannot find configuration file ' + s1 + ', exiting!');
24: lwrite ('Invalid configuration file - please run TACSETUP!');
30: lwrite ('Virus found inside archive! Take necessary precautions!');
40: lwrite ('Cannot find Image dearchiver!');
41: lwrite ('Cannot find Image filter!');
43: lwrite ('Error filtering image, exiting!');
44: lwrite ('Error unpacking image, exiting!');
211: usage;
End;
{$I-}
Close (lfile);
Halt (X);
End;
(*
KeyPressed() for OS/2 to avoid using CRT, which slows down screen output
drastically. Well, at least it did back then. Don't need CRT anyway.
*)
{$IFDEF OS2}
Function KeyPressed: Boolean;
Begin
KbdCharIn (OKey, io_NoWait, 0);
KeyPressed := (OKey. fbStatus And kbdtrf_Final_Char_In) <> 0;
End;
{$ENDIF}
(*
Simple batch-alike function.
*)
Function exist (filename: String): Boolean;
Var inf: SearchRec;
Begin
FindFirst (filename, AnyFile, inf);
exist := (DosError = 0);
{$IFDEF OS2}
FindClose (inf);
{$ENDIF}
End;
(*
Like FSearch(), but checks current directory as well. Could be smarter, i
guess.
*)
Function findfile (filename: String): Boolean;
Begin
If Not exist (filename) Then Begin
sss := FSearch (filename, GetEnv ('PATH') );
If sss = '' Then findfile := False Else findfile := True;
End
Else findfile := True;
End;
(*
VERY primitive KILLDIR / DELTREE-alike routine, but it works, and it's
fast enough for me.
*)
Procedure killdir (st1: String);
Var inf2: SearchRec;
Begin
st1 := FExpand (st1);
If exist (st1) Then Begin
GetDir (0, st3);
ChDir (st1);
Repeat
FindFirst ('*.*', $10, inf2);
Repeat
If (DosError = 0) And
(inf2.Name [1] <> '.') And
(inf2.Attr = $10)
Then Begin
ChDir (inf2.Name);
FindFirst ('*.*', $10, inf2);
End
Else FindNext (inf2);
Until DosError <> 0;
FindFirst ('*.*', $27, inf2);
While DosError = 0 Do Begin
Assign (o, inf2.Name);
SetFAttr (o, $20);
Erase (o);
FindNext (inf2);
End;
GetDir (0, st2);
ChDir ('..');
RmDir (st2);
GetDir (0, st2);
Until Length (st2) = Length (st3);
End;
End;
(*
Slave work; Read the configuration file.
*)
Procedure getcfg;
Begin
s1 := ParamStr (0);
While s1 [Length (s1) ] <> '\' Do Delete (s1, Length (s1), 1);
s1 := s1 + TACcfg;
Assign (ci, s1);
{$I-}
Reset (ci);
{$I+}
If IOResult <> 0 Then help (23)
Else Begin
ReadLn (ci, s2);
If s2 <> verstr Then help (24);
For b1 := 1 To 8 Do Begin
ReadLn (ci, Arc [b1].filename);
ReadLn (ci, Arc [b1].switches);
ReadLn (ci, Arc [b1].rswitch);
ReadLn (ci, Arc [b1].sswitch);
ReadLn (ci, dearc [b1].filename);
ReadLn (ci, dearc [b1].switches);
ReadLn (ci, dearc [b1].rswitch);
End;
For b1 := 9 To 48 Do Begin
ReadLn (ci, dearc [b1].filename);
ReadLn (ci, dearc [b1].switches);
ReadLn (ci, dearc [b1].rswitch);
End;
ReadLn (ci, vscan. filename);
ReadLn (ci, vscan. switches);
For b1 := 1 To 3 Do ReadLn (ci, stripzip);
ReadLn (ci, THANKS_parm);
ReadLn (ci, THANKS_sdir);
ReadLn (ci, stripzip);
ReadLn (ci, striparj);
ReadLn (ci, IMG_ext. filename);
ReadLn (ci, IMG_ext. switches);
ReadLn (ci, IMG_ext. rswitch);
ReadLn (ci, IMG_fil. filename);
ReadLn (ci, IMG_fil. rswitch);
ReadLn (ci, IMG_fil. switches);
ReadLn (ci, logfile);
Close (ci);
End;
End;
Procedure cleanup;
Begin
ChDir ('..');
killdir (tempdir);
End;
(*
This is where we execute the programs to remove AV information in ZIP
archives and Security Envelopes in ARJ archives.
*)
Procedure callstrip;
Begin
Case sourcetype Of
2: If findfile (striparj) Then Begin
lwrite (id + 'Stripping ARJ file ' + s2);
SwapVectors;
Exec (GetEnv ('COMSPEC'), '/C ' + striparj + ' ' + s2 + redir);
SwapVectors;
End;
8: If findfile (stripzip) Then Begin
lwrite (id + 'Stripping ZIP file ' + s2);
SwapVectors;
Exec (GetEnv ('COMSPEC'), '/C ' + stripzip + ' ' + s2 + redir);
SwapVectors;
End;
End;
End;
(*
Execute the Virus Scanner.
*)
Function scan: Byte;
Begin
lwrite (id + 'Scanning for viruses');
SwapVectors;
Exec (GetEnv ('COMSPEC'), '/C ' + vscan. filename + ' ' + vscan. switches + redir);
SwapVectors;
scan := DosExitCode;
End;
(*
Now the fun starts. This is where Floppy Disk Images are extracted. Both
the converter and the extracter are needed, otherwise we bum out.
TIFC is always executed on the images before extraction. If it cannot
recognize the image format, it does no harm.
*)
Function unimage (fn: String): Byte;
Var ifn: String;
Begin
If Not findfile (IMG_ext. filename) Then Begin
unimage := 40;
Exit;
End;
If Not findfile (IMG_fil. filename) Then Begin
unimage := 41;
Exit;
End;
If recursion Then ss2 := IMG_fil. rswitch
Else ss2 := IMG_fil. switches;
ss2 := ss2 + ' ' + fn + ' ' + tempimg;
lwrite (id + 'Filtering ' + s2);
execstr := '/c ' + IMG_fil. filename + ' ' + ss2 + redir;
SwapVectors;
Exec (GetEnv ('COMSPEC'), execstr);
SwapVectors;
If DosExitCode = 0 Then ifn := tempimg Else ifn := fn;
MkDir (tempdir);
If IOResult <> 0 Then;
{$I-}
ChDir (tempdir);
{$I+}
If IOResult <> 0 Then help (5);
If recursion Then ss2 := IMG_ext. rswitch
Else ss2 := IMG_ext. switches;
ss2 := ss2 + ' ' + '..\' + ifn;
lwrite (id + 'Extracting ' + s2);
execstr := '/c ' + IMG_ext. filename + ' ' + ss2 + redir;
SwapVectors;
Exec (GetEnv ('COMSPEC'), execstr);
SwapVectors;
If DosExitCode <> 0 Then Begin
cleanup;
help (44);
End;
If ifn = tempimg Then Begin
Assign (i, '..\' + tempimg);
{$I-}
Erase (i);
{$I+}
End;
sourcetype := 251;
End;
(*
Hey, wow!, now we're actually getting somewhere.
This is the extraction routine. It could have been so easy to write, but
i have added special handling to those formats who need it.
- HPack, DWC and HAP all requires the files to be called .HPK, .DWC and
.HAP, respectively.
- .Z and .gz are both deleted by the dearchiver after extraction, and
will be extracted to where the source archive is, no matter what.
- cpio requires the archive to be piped into it.
- PowerPacker requires a destination filename.
- HAP requires a filemask to extract from the archive.
- GZip, DWC, Squeeze and Comt all require the input file to be in the
current directory.
- The thing that is commented out is a leftover from my old StuffIt
extractor that required human intervention.
typ is obtained from Determine() (see later on) and fn is the filename to
extract from.
If Intelligent Detection is used, we tell the user what format we think
the file is.
Go go Gadget dearchiver! =) ..
*)
Function unpack (typ: Byte; fn: String): Byte;
Begin
Case sourcetype Of
2,
11,
21: renameflag := True;
End;
If typ <> 0 Then Begin
If (typ <> 9) And (typ <> 11) And (typ <> 14) Then Begin
If (Pos (':', fn) = 0) And (Pos ('\', fn) = 0) Then fn := '..\' + fn;
End;
ss1 := dearc [typ].filename;
If Not findfile (ss1) Then Begin
unpack := 255;
w2 := 55552;
Exit;
End;
If recursion Then ss2 := dearc [typ].rswitch
Else ss2 := dearc [typ].switches;
If sourcetype = 17 Then ss2 := ss2 + ' <';
ss2 := ss2 + ' ' + fn;
If sourcetype = 39 Then Begin
sss := fn;
While Pos (':', sss) > 0 Do Delete (sss, 1, 1);
While Pos ('\', sss) > 0 Do Delete (sss, 1, 1);
If Pos ('.', sss) > 0 Then Delete (sss, Pos ('.', sss), 3);
ss2 := ss2 + ' ' + sss;
End;
{$I-}
MkDir (tempdir);
If IOResult <> 0 Then;
ChDir (tempdir);
{$I+}
If IOResult <> 0 Then help (5);
echostr := id + 'Uncompressing ' + s2;
If inteldet Then Begin
echostr := echostr + ' (';
For b2 := 1 To 3 Do echostr := echostr + dearctypes [ ( (typ - 1) * 3) + b2];
echostr := echostr + ')';
End;
lwrite (echostr);
If (typ = 9) Or (typ = 11) Or (typ = 14) Or (typ = 43) Then Begin
Assign (i, '..\' + fn);
Reset (i, 1);
Assign (o, fn);
Rewrite (o, 1);
GetMem (p, 4096);
Repeat
BlockRead (i, p^, 4096, w1);
BlockWrite (o, p^, w1, w2);
Until (w1 = 0) Or (w2 <> w1);
FreeMem (p, 4096);
Close (o);
Close (i);
End;
If renameflag Then Begin
sss := fn;
Assign (i, fn);
If typ <> 11 Then Delete (fn, 1, 3);
{$IFDEF OS2}
For w2 := Length (fn) Downto 1 Do If fn [w2] = '.' Then Break;
Delete (fn, w2 + 1, Length (fn) - w2);
{$ELSE}
If Pos ('.', fn) > 1 Then Delete (fn, Pos ('.', fn) + 1, 3);
{$ENDIF}
w1 := ( (sourcetype - 1) * 3) + 1;
For w2 := w1 To w1 + 2 Do fn := fn + dearctypes [w2];
If typ <> 11 Then fn := '..\' + fn;
If sss <> fn Then Rename (i, fn);
Delete (ss2, Length (ss2) - Length (fn) + 1, Length (fn) + 1);
ss2 := ss2 + fn;
End;
If typ = 21 Then ss2 := ss2 + ' *.* ';
execstr := '/c ' + ss1 + ' ' + ss2;
(*
if typ<>10 then
*)
execstr := execstr + redir;
SwapVectors;
Exec (GetEnv ('COMSPEC'), execstr);
SwapVectors;
If (typ = 11) Or (typ = 14) Then Begin
Assign (i, fn);
Erase (i);
End;
unpack := DosExitCode;
End
Else unpack := 0;
End;
(*
Here we call our archiver of choice.
typ is the destination type, fn is the filename to create and the rest is
just slave work.
*)
Function pack (typ: Char; fn: String): Byte;
Begin
If sourcetype <> 0 Then Begin
While Pos (':', fn) > 0 Do Delete (fn, 1, 1);
While Pos ('\', fn) > 0 Do Delete (fn, 1, 1);
If Pos ('.', fn) > 1 Then While fn [Length (fn) ] <> '.' Do Delete (fn, Length (fn), 1);
If fn [Length (fn) ] <> '.' Then fn := fn + '.';
b1 := Pos (typ, arctyps);
For b2 := 1 To 3 Do fn := fn + arctypes [ ( (b1 - 1) * 3) + b2];
{$IFDEF OS2}
If Not lowercase Then For b2 := Length (fn) - 2 To Length (fn) Do fn [b2] := UpCase (fn [b2] )
Else For b2 := Length (fn) - 2 To Length (fn) Do Begin
If (fn [b2] >= 'A') And (fn [b2] <= 'Z') Then fn [b2] := Chr (Ord (fn [b2] ) + 32);
End;
While fn [Length (fn) ] = ' ' Do Delete (fn, Length (fn), 1);
{$ENDIF}
s3 := fn;
fn := '..\' + fn;
If exist (fn) Then Begin
If Not clobber Then Begin
ss1 := fn;
Delete (ss1, 1, 3);
If quietmode Then stdoutput;
Write (id + ss1 + ' already exists. Overwrite? ');
{$IFDEF MSDOS}
Repeat key := ReadKey Until Pos (UpCase (key), 'YN') > 0;
{$ELSE}
Repeat Until (KeyPressed) And (Pos (UpCase (OKey. chchar), 'YN') > 0);
key := OKey. chchar;
{$ENDIF}
WriteLn (key);
If quietmode Then nuloutput;
If UpCase (key) = 'Y' Then Begin
Assign (o, fn);
Rename (o, '..\' + tempfil);
End;
End
Else Begin
Assign (o, fn);
Rename (o, '..\' + tempfil);
End;
End;
If Not exist (fn) Then Begin
ss1 := Arc [b1].filename;
If Not findfile (ss1) Then Begin
pack := 255;
w2 := 55552;
Exit;
End;
If recursion Then ss2 := Arc [b1].rswitch Else ss2 := Arc [b1].switches;
If timestamp Then ss2 := ss2 + ' ' + Arc [b1].sswitch;
ss2 := ss2 + ' ' + fn + ' *';
{$IFDEF MSDOS}
If desttype <> 'H' Then ss2 := ss2 + '.*';
{$ENDIF}
echostr := id + 'Creating ';
For b1 := 4 To Length (fn) Do echostr := echostr + fn [b1];
lwrite (echostr);
SwapVectors;
Exec (GetEnv ('COMSPEC'), '/c ' + ss1 + ' ' + ss2 + redir);
SwapVectors;
pack := DosExitCode;
End
Else Begin
pack := 255;
w2 := 61613;
End;
End
Else pack := 0;
End;
(*
Whoa! Here's the routine to determine the archive formats.
*)
Procedure determine (fn: String);
(*
This routine scans for all the ASCii-based formats (well, some of them),
all in one go.
Stony Brook Pascal+ makes TAC die right here, as it does not like binary
files opened and read as text files. Don't ask me why, but it does.
*)
Procedure scantxt;
Var
sbuf,
swork: String;
bwork: Byte;
Begin
Assign (ci, fn);
Reset (ci);
While (Not EoF (ci) ) And (sourcetype = 0) Do Begin
ReadLn (ci, sbuf);
swork := sbuf;
While (swork [1] = ' ') And (Length (swork) > 0) Do Delete (swork, 1, 1);
While swork [Length (swork) ] = ' ' Do Delete (swork, Length (swork), 1);
If swork = 'FiLeStArTfIlEsTaRt' Then sourcetype := 48 Else Begin
For bwork := 1 To Length (swork) Do swork [bwork] := UpCase (swork [bwork] );
sbuf := swork;
Delete (sbuf, 6, Length (sbuf) - 5);
If swork = 'CONTENT-TRANSFER-ENCODING: BASE64' Then sourcetype := 41
Else If sbuf = 'SHIP ' Then sourcetype := 45
Else Begin
Delete (swork, 7, Length (swork) - 6);
If swork = 'BEGIN ' Then Begin
ReadLn (ci, sbuf);
If sbuf [1] = 'M' Then sourcetype := 29;
If sbuf [1] = 'h' Then sourcetype := 30;
End;
End;
End;
End;
Close (ci);
End;
(*
.. And here we go. First we just check for the file extensions. This
could probably be optimized, but .. erhm .. i had other things to do that
day =) ..
*)
Begin
renameflag := False;
ss1 := fn;
sourcetype := 0;
If Not inteldet Then Begin
While Pos ('.', ss1) <> 0 Do Begin
While (ss1 [1] <> '.') And
(Length (ss1) > 0)
Do Delete (ss1, 1, 1);
Delete (ss1, 1, 1);
End;
For b2 := 1 To Length (ss1) Do ss1 [b2] := UpCase (ss1 [b2] );
If ss1 = 'ARC' Then sourcetype := 1;
If ss1 = 'HPK' Then sourcetype := 2;
If ss1 = 'ARJ' Then sourcetype := 3;
If (ss1 = 'LHA') Or
(ss1 = 'LZH') Or
(ss1 = 'LZS') Or
(ss1 = 'ICE')
Then sourcetype := 4;
If ss1 = 'PAK' Then sourcetype := 5;
If ss1 = 'TAR' Then sourcetype := 6;
If ss1 = 'UC2' Then sourcetype := 7;
If ss1 = 'ZIP' Then sourcetype := 8;
If ss1 [Length (ss1) ] = 'Z' Then sourcetype := 9;
If ss1 = 'SIT' Then sourcetype := 10;
If ss1 = 'DWC' Then sourcetype := 11;
If (ss1 = 'MD') Or
(ss1 = 'CD')
Then sourcetype := 12;
If ss1 = 'LBR' Then sourcetype := 13;
If ss1 = 'SQZ' Then sourcetype := 15
Else If ss1 [2] = 'Q' Then sourcetype := 14;
If (ss1 [1] = 'S') And (ss1 [2] = 'H') Then sourcetype := 16;
If ss1 = 'CP' Then sourcetype := 17;
If ss1 = 'HYP' Then sourcetype := 18;
If ss1 = 'CHZ' Then sourcetype := 19;
If ss1 = 'LIM' Then sourcetype := 20;
If ss1 = 'HAP' Then sourcetype := 21;
If ss1 = 'HA' Then sourcetype := 22;
If ss1 = 'GAS' Then sourcetype := 23;
If ss1 = 'ZOO' Then sourcetype := 24;
If ss1 = 'ARP' Then sourcetype := 25;
If ss1 = 'RAR' Then sourcetype := 26;
If ss1 = 'AAF' Then sourcetype := 27;
If ss1 = 'EX' Then sourcetype := 28;
If (ss1 = 'UUE') Or
(ss1 = 'UU')
Then sourcetype := 29;
If (ss1 = 'XXE') Or
(ss1 = 'XX')
Then sourcetype := 30;
If ss1 = 'AR' Then sourcetype := 31;
If ss1 = 'BIT' Then sourcetype := 32;
If (ss1 = 'HQX') Or
(ss1 = 'HEX') Or
(ss1 = 'HCX')
Then sourcetype := 33;
If ss1 = 'CPZ' Then sourcetype := 34;
If ss1 = 'CRU' Then sourcetype := 35;
If ss1 = 'CPT' Then sourcetype := 36;
If ss1 = 'PIT' Then sourcetype := 37;
If ss1 = 'SPL' Then sourcetype := 38;
If ss1 = 'PP' Then sourcetype := 39;
If ss1 = 'AIN' Then sourcetype := 40;
If ss1 = 'MIM' Then sourcetype := 41;
If ss1 = 'BLU' Then sourcetype := 42;
If ss1 = 'CMT' Then sourcetype := 43;
If ss1 = 'Q' Then sourcetype := 44;
If ss1 = 'SHP' Then sourcetype := 45;
If ss1 = 'SHK' Then sourcetype := 46;
If ss1 = 'QIP' Then sourcetype := 47;
If ss1 = 'BIN' Then sourcetype := 48;
End
(*