home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / cx201 / cxf.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-03-01  |  4.9 KB  |  169 lines

  1. {
  2.    Cx, CXSUB example program.
  3.    Copyright (c) 1990-1994 Eugene Nelson, Four Lakes Computing.
  4. }
  5.  
  6. program  Cxf; uses cx, cxsub, crt;
  7.  
  8. {$F+}    {Required, do not change}
  9.  
  10.  
  11. type ARECORD = record
  12.    quiet       :boolean;
  13.    interrupted :boolean
  14. end;
  15.  
  16. var   j        :integer;
  17.       method   :CXINT;
  18.       bsize    :CXINT;
  19.       tsize    :CXINT;
  20.       ret      :CXINT;
  21.       test     :boolean;
  22.       extract  :boolean;
  23.       s        :string[200];
  24.       iname    :string[200];
  25.       oname    :string[200];
  26.       rec      :ARECORD;
  27.  
  28. {-------------------------------------------------------------------------}
  29. procedure USAGE;
  30. begin
  31.    writeln('usage: cxf [options] infile [outfile]');
  32.    writeln('   -1    compress infile to outfile using CX_METHOD1');
  33.    writeln('   -2    compress infile to outfile using CX_METHOD2');
  34.    writeln('   -3    compress infile to outfile using CX_METHOD3');
  35.    writeln('   -c    compress infile to outfile using CX_METHODC');
  36.    writeln('   -d    compress infile to outfile using CX_METHODD');
  37.    writeln('   -x    decompress (extract) infile to outfile');
  38.    writeln('   -i    test integrity of infile');
  39.    writeln('   -b[n] buffer size (in K) when compressing (default CX_MAX_BUFFER)');
  40.    writeln('   -t[n] temporary size (in K) when compressing (default CX_C_MAXTEMP)');
  41.    writeln('   -q    quiet, no progress information');
  42.    writeln('');
  43.    writeln('   Examples:');
  44.    writeln('      cxf -1 -b63 -t63 cx.doc cfile.dat');
  45.    writeln('      cxf -i cfile.dat');
  46.    writeln('      cxf -x cfile.dat dfile.dat');
  47.    Halt;
  48. end;
  49.  
  50.  
  51. {-------------------------------------------------------------------------}
  52. function callback(p: pointer): integer;
  53. type pARECORD = ^ARECORD;
  54. var   rec:  pARECORD;
  55. begin
  56.    rec:= pARECORD(p);
  57.  
  58.    if not rec^.quiet
  59.       then write('.');
  60.  
  61.    if KeyPressed
  62.    then begin
  63.       rec^.interrupted:= True;
  64.       callback:= -1;    {any non-zero return will work}
  65.    end
  66.    else
  67.       callback:= 0;
  68. end;
  69.  
  70. {The following is a dummy callback which may be used instead of callback}
  71. {-------------------------------------------------------------------------}
  72. function dcallback(p: pointer): integer;
  73. begin
  74.    dcallback:= 0;
  75. end;
  76.  
  77. {-------------------------------------------------------------------------}
  78. begin
  79.    method:= 0;
  80.    test:= False;
  81.    extract:= False;
  82.    iname:= '';
  83.    oname:= '';
  84.    bsize:= CX_MAX_BUFFER;
  85.    tsize:= CX_C_MAXTEMP;
  86.    rec.quiet:= False;
  87.    rec.interrupted:= False;
  88.  
  89.    writeln('Cx Test Program, Copyright (c) 1990-1994 Four Lakes Computing');
  90.    writeln('   ┌────────────────────────────────────────────────────────────────┐');
  91.    writeln('   │The evaluation object code runs MUCH slower than the object code│');
  92.    writeln('   │that may be purchased.  Run TEST.EXE for EXACT speed and size   │');
  93.    writeln('   │measurements.                                                   │');
  94.    writeln('   └────────────────────────────────────────────────────────────────┘');
  95.  
  96.    for j:= 1 to ParamCount
  97.    do begin
  98.       s:= ParamStr(j);
  99.       if (s[1] = '-') and (Length(s) >= 2)
  100.       then begin
  101.          case s[2] of
  102.             '1': method:= CX_METHOD1;
  103.             '2': method:= CX_METHOD2;
  104.             '3': method:= CX_METHOD3;
  105.             'c', 'C': method:= CX_METHODC;
  106.             'd', 'D': method:= CX_METHODD;
  107.             'q', 'Q': rec.quiet:= TRUE;
  108.             'i': test:= True;
  109.             'x': extract:= True;
  110.  
  111.             't', 'T':
  112.             begin
  113.                val(Copy(s, 3, 200), tsize, ret);
  114.                if tsize < 1 then tsize:= 1;
  115.                if tsize > 63 then tsize:= 63;
  116.                tsize:= tsize * 1024;
  117.             end;
  118.  
  119.             'b', 'B':
  120.             begin
  121.                val(Copy(s, 3, 200), bsize, ret);
  122.                if bsize < 1 then bsize:= 1;
  123.                if bsize > 63 then bsize:= 63;
  124.                bsize:= bsize * 1024;
  125.             end;
  126.  
  127.             else USAGE;
  128.          end;
  129.       end
  130.       else begin
  131.          if Length(iname) = 0
  132.             then iname:= s
  133.             else oname:= s;
  134.       end;
  135.    end;
  136.  
  137.    if Length(iname) = 0
  138.       then USAGE;
  139.  
  140.    if (method <> 0) and (Length(oname) = 0)
  141.       then USAGE;
  142.       
  143.    if extract and (Length(oname) = 0)
  144.       then USAGE;
  145.  
  146.    if not test and not extract and (method = 0)
  147.       then USAGE;
  148.  
  149.    writeln('Press any key to stop.');
  150.  
  151.    if test
  152.       then ret:= cx_decompress_file('', iname, callback, @rec)
  153.    else if (extract)
  154.       then ret:= cx_decompress_file(oname, iname, callback, @rec)
  155.    else if method <> 0
  156.       then ret:= cx_compress_file(oname, iname, method, bsize, tsize, callback, @rec);
  157.  
  158.    writeln('');
  159.  
  160.    if rec.interrupted
  161.       then writeln('Interrupted.')
  162.       else if ret = 0
  163.          then writeln('Ok.')
  164.          else begin
  165.             write('ERROR: ');
  166.             writeln(cx_error_message(ret));
  167.          end;
  168. end.
  169.