home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / packer / arc / arctool / dearc.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1988-09-29  |  10.4 KB  |  441 lines

  1. {
  2.                        F i l e    I n f o r m a t i o n
  3.  
  4. * DESCRIPTION
  5. Turbo Pascal 4.0 program to extract all files from an archive created by
  6. version 5.12 or earlier of the ARC utility.
  7.  
  8. * ASSOCIATED FILES
  9. DEARC.PAS
  10. DEARCABT.PAS
  11. DEARCGLB.PAS
  12. DEARCIO.PAS
  13. DEARCLZW.PAS
  14. DEARCUNP.PAS
  15. DEARCUSQ.PAS
  16. DEARC.TXT
  17.  
  18. }
  19. Program Dearc;
  20. (*
  21.  DEARC.PAS - Program to extract all files from an archive created by version
  22.              5.12 or earlier of the ARC utility.
  23.  
  24.              ARC is COPYRIGHT 1985-1988 by System Enhancement Associates.
  25.              PKARC/PKXARC are Copyright 1986-1988 by PKWARE, Inc.
  26.  
  27.  
  28.     This program requires Turbo Pascal Version 4.0 or higher.
  29.  
  30.  Usage:  DEARC arcname
  31.  
  32.     arcname is the path/file name of the archive file. All files contained
  33.     in the archive will be extracted into the current directory.
  34.  
  35.  HISTORY:
  36.  
  37.    *** ORIGINAL AUTHOR UNKNOWN ***
  38.  
  39.   Version 1.01 - 10/19/85. Changed end-of-file processing to, hopefully, be
  40.                            more compatible with CPM (whatever that is).
  41.  
  42.   Version 1.01A - 12/19/85 By Roy Collins
  43.                            Mail: TechMail BBS @ 703-430-2535
  44.                                  - or -
  45.                                  P.O.Box 1192, Leesburg, Va 22075
  46.                            Modified V1.01 to work with Turbo Pascal Version 2
  47.                            Added functions ARGC (argument count) and ARGV
  48.                            (argument value)
  49.                            Modified all references to "EXIT" command to be
  50.                            GOTO EXIT, with EXIT defined as a LABEL, at the
  51.                            end of the function/procedure involved.
  52.                            Will not accept path names - archives must be in
  53.                            the current directory.
  54.  
  55.   Version 2.00 - 6/11/86   By David W. Carroll
  56.                            Mail: High Sierra RBBS-PC @ 209/296-3534
  57.                            Now supports ARC version 5.12 files, compression
  58.                            types 7 and 8.
  59.  
  60.   Version 3.00 - 7/30/87   By Richard P. Byrne
  61.                            UN*X E-Mail:  ...!ihnp4!mduxf!rpb
  62.                            BBS Mail:     Software Society BBS @ (201) 729-7410
  63.                            Modified Version 2.00 to handle compression type
  64.                            9 (ie. Squashed ).
  65.  
  66.   Version 3.10 - 7/26/88   By Paul Roub
  67.                            BBS Mail: Society BBS (407)-773-2831
  68.                                      FIDONET Programming Echo
  69.                                      FIDONET C Echo
  70.                            Compuserve EasyPlex to [71131,157]
  71.                            Modified Version 3.00:
  72.                              Ported to Turbo Pascal v4.0
  73.                              Added Time/Date stamping of extracted files
  74.                              Removed all floating point
  75.                              Added confirmation when overwriting existing file
  76.                              Display type of decompression being done
  77.                              Updated docs
  78.                              Removed CP/M style end-of-file padding (do you
  79.                                really want a bunch of Control-Z's at the
  80.                                end of a .COM file?)
  81.                              By the way,  argc and argv are gone,  and of
  82.                                COURSE you can use pathnames...
  83. *)
  84.  
  85.  
  86. (*
  87.  *  other units involved
  88.  *)
  89. uses
  90.   dearcabt,                           (* abort() routine                    *)
  91.   dearcglb,                           (* global variables,  types           *)
  92.   dearcio,                            (* input/output routines              *)
  93.   dearcunp,                           (* unPacking stuff                    *)
  94.   dearcusq,                           (* unSqueezing routines               *)
  95.   dearclzw;                           (* LZW (unCrunching and unSquashing   *)
  96.  
  97.  
  98. (**
  99.  *
  100.  *  Name:         function fn_to_str
  101.  *  Description:  convert strings from C format (trailing 0) to Turbo Pascal
  102.  *                format (leading length byte).
  103.  *  Parameters:   var -
  104.  *                  fn : fntype : filename to convert
  105.  *  Returns:      converted filename
  106.  *
  107. **)
  108. function fn_to_str(var fn : fntype) : strtype;
  109. var
  110.   s : strtype;
  111.   i : integer;
  112. begin
  113.   s := '';
  114.   i := 0;
  115.  
  116.   while fn[i] <> #0 do
  117.     begin
  118.       s := s + fn[i];
  119.       i := i + 1
  120.     end;
  121.   fn_to_str := s
  122. end; (* func fn_to_str *)
  123.  
  124.  
  125. (**
  126.  *
  127.  *  Name:         procedure GetArcName
  128.  *  Description:  get the name of the archive file
  129.  *  Parameters:   none
  130.  *
  131. **)
  132. procedure GetArcName;
  133. var
  134.   i : integer;
  135. begin
  136.   if (ParamCount > 1) then
  137.     abort('Too many parameters');
  138.  
  139.   if (ParamCount = 1) then
  140.     arcname := ParamStr(1)
  141.   else
  142.     begin
  143.       write('Enter archive filename: ');
  144.       readln(arcname);
  145.       if arcname = '' then
  146.         abort('No file name entered');
  147.       writeln;
  148.       writeln;
  149.     end;
  150.  
  151.   for i := 1 to length(arcname) do
  152.     arcname[i] := UpCase(arcname[i]);
  153.  
  154.   if pos('.', arcname) = 0 then
  155.     arcname := arcname + '.ARC'
  156. end; (* proc GetArcName *)
  157.  
  158.  
  159. (**
  160.  *
  161.  *  Name:         function readhdr
  162.  *  Description:  read a file header from the archive file
  163.  *  Parameters:   var -
  164.  *                  hdr : heads - header to read
  165.  *  Returns:      FALSE : eof found
  166.  *                TRUE  : header found
  167.  *
  168. **)
  169. function readhdr(var hdr : heads) : boolean;
  170. label
  171.   exit;
  172. var
  173.   name : fntype;
  174.   try  : integer;
  175. begin
  176.   try := 10;
  177.  
  178.   if endfile then
  179.     begin
  180.       readhdr := FALSE;
  181.       goto exit               (******** was "exit" ************)
  182.     end;
  183.  
  184.   while get_arc <> arcmarc do
  185.     begin
  186.       if try = 0 then
  187.         abort(arcname + ' is not an archive');
  188.       try := try - 1;
  189.       writeln(arcname, ' is not an archive, or is out of sync');
  190.       if endfile then
  191.         abort('Archive length error')
  192.     end; (* while *)
  193.  
  194.   hdrver := get_arc;
  195.  
  196.   if hdrver < 0 then
  197.     abort('Invalid header in archive ' + arcname);
  198.  
  199.   if hdrver = 0 then         { special end of file marker }
  200.     begin
  201.       readhdr := FALSE;
  202.       goto exit               (******** was "exit" ************)
  203.     end;
  204.  
  205.   if hdrver = 1 then
  206.     begin
  207.       fread(hdr, sizeof(heads) - sizeof(longint));
  208.       hdrver := 2;
  209.       hdr.length := hdr.size
  210.     end
  211.   else
  212.     fread(hdr, sizeof(heads));
  213.  
  214.   readhdr := TRUE;
  215.  
  216. exit:
  217.  
  218. end; (* func readhdr *)
  219.  
  220.  
  221. (**
  222.  *
  223.  *  Name:         procedure unpack
  224.  *  Description:  unpack one file
  225.  *  Parameters:   var -
  226.  *                  hdr : heads - header of file to unpack
  227.  *
  228. **)
  229. procedure unpack(var hdr : heads);
  230. label
  231.   exit;
  232. var
  233.   c : integer;
  234. begin
  235.   crcval  := 0;
  236.   size    := hdr.size;
  237.   state   := NOHIST;
  238.   FirstCh := TRUE;
  239.  
  240.   case hdrver of
  241.     1, 2 :
  242.       begin
  243.         c := getc_unp;
  244.  
  245.         while c <> -1 do
  246.           begin
  247.             putc_unp(c);
  248.             c := getc_unp
  249.           end
  250.       end;
  251.  
  252.     3    :
  253.       begin
  254.         c := getc_unp;
  255.         while c <> -1 do
  256.           begin
  257.             putc_ncr(c);
  258.             c := getc_unp
  259.           end
  260.       end;
  261.  
  262.     4    :
  263.       begin
  264.         init_usq;
  265.         c := getc_usq;
  266.  
  267.         while c <> -1 do
  268.           begin
  269.             putc_ncr(c);
  270.             c := getc_usq
  271.           end
  272.       end;
  273.  
  274.     5    :
  275.       begin
  276.         init_ucr(0);
  277.         c := getc_ucr;
  278.  
  279.         while c <> -1 do
  280.           begin
  281.             putc_unp(c);
  282.             c := getc_ucr
  283.           end
  284.       end;
  285.  
  286.     6    :
  287.       begin
  288.         init_ucr(0);
  289.         c := getc_ucr;
  290.  
  291.         while c <> -1 do
  292.           begin
  293.             putc_ncr(c);
  294.             c := getc_ucr
  295.           end
  296.       end;
  297.  
  298.     7    :
  299.       begin
  300.         init_ucr(1);
  301.         c := getc_ucr;
  302.  
  303.         while c <> -1 do
  304.           begin
  305.             putc_ncr(c);
  306.             c := getc_ucr
  307.           end
  308.       end;
  309.  
  310.     8    :
  311.       decomp(0);
  312.  
  313.     9    :
  314.       decomp(1);
  315.  
  316.     else
  317.       begin
  318.         writeln('I dont know how to unpack file ', fn_to_str(hdr.name));
  319.         writeln('I think you need a newer version of DEARC');
  320.         fseek(hdr.size, 1);
  321.         goto exit                         (******** was "exit" ************)
  322.       end
  323.   end; (* case *)
  324.  
  325.   if crcval <> hdr.crc then
  326.     writeln('WARNING: File ', fn_to_str(hdr.name), ' fails CRC check');
  327.  
  328. exit:
  329.  
  330. end; (* proc unpack *)
  331.  
  332.  
  333. (**
  334.  *
  335.  *  Name:         procedure extract_file
  336.  *  Description:  extract one file from archive
  337.  *  Parameters:   var -
  338.  *                  hdr : heads - header for file to extract
  339.  *
  340. **)
  341. procedure extract_file(var hdr : heads);
  342. var
  343.   st : strtype;
  344.   ch : char;
  345.   fil : file;
  346. begin
  347.   extname := fn_to_str(hdr.name);
  348.  
  349.   assign(fil, extname);
  350.   {$I-}
  351.   reset(fil);
  352.   {$I+}
  353.  
  354.   if (ioresult = 0) then
  355.     begin
  356.       close(fil);
  357.  
  358.       repeat
  359.         write('  File ', extname, ' exists.  Overwrite (y/n)? ');
  360.         readln(st);
  361.         ch := upcase(st[1]);
  362.       until ((ch = 'Y') or (ch = 'N'));
  363.  
  364.       if (ch = 'N') then
  365.         begin
  366.           fseek(hdr.size, 1);
  367.           writeln('  ', extname, ' skipped.');
  368.           exit;
  369.         end;
  370.     end;
  371.  
  372.   case hdrver of
  373.     1, 2    : write('Extracting ');
  374.     3       : write('unPacking  ');
  375.     4       : write('unSqueezing');
  376.     5, 6, 7 : write('uncrunching');
  377.     8       : write('unCrunching');
  378.     9       : write('unSquashing');
  379.   end;
  380.  
  381.   writeln(' : ', extname);
  382.  
  383.   open_ext;
  384.   unpack(hdr);
  385.   close_ext(hdr);
  386. end; (* proc extract *)
  387.  
  388.  
  389. (**
  390.  *
  391.  *  Name:         procedure extarc
  392.  *  Description:  extract all files from an archive
  393.  *  Parameters:   none
  394.  *
  395. **)
  396. procedure extarc;
  397. var
  398.   hdr : heads;
  399. begin
  400.   open_arc;
  401.  
  402.   while readhdr(hdr) do
  403.     extract_file(hdr);
  404.  
  405.   close_arc;
  406. end; (* proc extarc *)
  407.  
  408.  
  409. (**
  410.  *
  411.  *  Name:         procedure PrintHeading
  412.  *  Description:  print DEARC header info
  413.  *  Parameters:   none
  414.  *
  415. **)
  416. procedure PrintHeading;
  417. begin
  418.   writeln;
  419.   writeln('Turbo Pascal DEARC Utility');
  420.   writeln('Version 3.1, 7/26/88');
  421.   writeln('Supports Phil Katz "squashed" files');
  422.   writeln;
  423. end; (* proc PrintHeading *)
  424.  
  425.  
  426. (**
  427.  *
  428.  *  Name:         (main routine)
  429.  *  Description:  print header information
  430.  *                get the archive file name
  431.  *                do the extraction
  432.  *
  433. **)
  434. begin
  435.   PrintHeading;
  436.   GetArcName;   { get the archive file name }
  437.   extarc        { extract all files from the archive }
  438. end.
  439.  
  440. 
  441.