home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / tug__002 / dearc.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1988-08-08  |  12.0 KB  |  478 lines

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