home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 January / PCO0198.ISO / filesbbs / dos / maketic.exe / CRC32.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-11-08  |  4.8 KB  |  214 lines

  1. {$A+,B+,D+,E-,F-,G+,I-,L+,N-,O-,R-,S-,V-,X-}
  2. {$M 16384,0,300000}
  3. program CalcCRC32;
  4.  
  5. { A quick and dirty hack for the MAKETIC batch file }
  6. { SRC can be freely used.... if you have the same units :-((  }
  7.  
  8. uses dos, ansi_crc, tpdos, dosv2, netzwerk, utils;
  9.  
  10.    const MAGICFILE = 'MAGIC.DAT';
  11.          FILEIDDIZ = 'FILE_ID.DIZ';
  12.  
  13. var CRC      : PCrc;
  14.     lChk     : LongInt;
  15.     szFile   : String;
  16.     magic    : String;
  17.     replaces : String;
  18.     lZeit    : LongInt;
  19.  
  20. { ######################################################################### }
  21.  
  22. Procedure Fileid_Diz; { scanns the file_id.diz for entrys }
  23.  
  24. var hIn    : Text;
  25.     szLine : String;
  26.     bFirst : Boolean;
  27.  
  28. begin { Fileid_Diz }
  29.      if not exists(FILEIDDIZ) then exit;
  30.      assign(hIn, FILEIDDIZ);
  31.      if ioresult <> 0 then exit;
  32.      reset(hIn);
  33.      bFirst := FALSE;
  34.  
  35.      repeat
  36.            readln(hIn, szLine);
  37.            if not bFirst then
  38.            begin
  39.                 writeln('DESC ',szLine);
  40.                 bFirst := TRUE;
  41.            end;
  42.            writeln('LDESC ',szLine);
  43.      until eof(hIn);
  44.      close(hIn);
  45.  
  46. end; { Fileid_Diz }
  47.  
  48. { ----[ FileLength ]----------------------------------------------------- }
  49.  
  50. function FileLength(szFile: String) : LongInt;
  51.  
  52. var f : File;
  53.     l : LongInt;
  54.  
  55. begin
  56.      FileLength := 0;
  57.      l := 0;
  58.  
  59.      assign(f, szFile);
  60.      if ioresult <> 0 then exit;
  61.      reset(f,1);
  62.      if ioresult = 0 then l := FileSize(f);
  63.      close(f);
  64.  
  65.      FileLength := l;
  66.  
  67. end;
  68.  
  69. { ######################################################################### }
  70.  
  71. function GetMagic(szWhat: String) : String;
  72.  
  73. var szFile : String;
  74.     hIn    : Text;
  75.     szWork : String;
  76.     found  : String;
  77.     t      : Byte;
  78.  
  79. label breakit;
  80.  
  81. begin { GetMagic }
  82.  
  83.   GetMagic := '';
  84.   found    := '';
  85.  
  86.   if not existonpath(MAGICFILE, szFile) then goto breakit;
  87.  
  88.   assign(hIn, szFile);
  89.   reset(hIn);
  90.  
  91.   while not (eof(hIn)) do
  92.   begin
  93.       readln(hIn, szWork);
  94.       t := pos(' ', szWork);
  95.       if copy(szWork, 1, t-1) = szWhat
  96.          then found := copy(szWork, t+1, 255);
  97.   end;
  98.  
  99.   close(hIn);
  100.  
  101. breakit:
  102.   if found = '' then
  103.   begin
  104.        write('■ Enter MAGIC for ',szWhat,': ');
  105.        readln(found);
  106.        found := KillSpace(upper(found));
  107.        if found <> '' then
  108.        begin
  109.             assign(hIn, szFile);
  110.             append(hIn);
  111.             writeln(hIn, szWhat,' ', found);
  112.             close(hIn);
  113.        end;
  114.   end;
  115.  
  116.   GetMagic := found;
  117. end; { GetMagic }
  118.  
  119. { ######################################################################### }
  120.  
  121. function ReplaceMagic(filename: String; oldMagic: String) : String;
  122.  
  123. var szFile : String;
  124.     hIn    : Text;
  125.     szWork : String;
  126.     found  : String;
  127.     t      : Byte;
  128.  
  129. begin { ReplaceMagic }
  130.  
  131.   ReplaceMagic := '';
  132.   found    := '';
  133.  
  134.   if not existonpath(MAGICFILE, szFile) then exit;
  135.  
  136.   assign(hIn, szFile);
  137.   reset(hIn);
  138.  
  139.   while not (eof(hIn)) do
  140.   begin
  141.       readln(hIn, szWork);
  142.       t := pos(' ', szWork);
  143.       if (KillSpace(copy(szWork, t+1, 255)) = oldMagic)
  144.          and (copy(szWork, 1, t-1) <> filename)
  145.          then found := copy(szWork, 1, t-1);
  146.   end;
  147.  
  148.   close(hIn);
  149.  
  150.   ReplaceMagic := found;
  151.  
  152. end; { ReplaceMagic }
  153.  
  154. function todec(iTmp :integer) : String;
  155.  
  156. var szT : String;
  157.  
  158. begin
  159.      str(iTmp, szT);
  160.      if iTmp<10 then szT := '0'+szT;
  161.      todec := KillSpace(szT);
  162.  
  163. end;
  164.  
  165. { ######################################################################### }
  166.  
  167. begin { main }
  168.   if paramcount <> 1 then
  169.   begin
  170.     writeln('CRC32 Version 1.20, (C)0ded 1995-97 by R0$E Softwareentwicklung');
  171.     writeln;
  172.     writeln('Usage: CRC32 file');
  173.     halt;
  174.   end;
  175.  
  176.   szFile := Upper(paramstr(paramcount));
  177.   writeln('■ Proceeding file: ',szFile,'/',FileNameSplit(szFile));
  178.  
  179.   magic := GetMagic(FileNameSplit(szFile));
  180.   replaces := ReplaceMagic(FileNameSplit(szFile), Magic);
  181.  
  182.   if magic <> '' then
  183.       writeln('■ Magic: ',magic);
  184.   if replaces <> '' then
  185.       writeln('■ Replaces: ',replaces);
  186.  
  187.   crt2con;                              { redirect stdout }
  188.  
  189.   NEW(CRC, Init( CRCPOLY_Def ));        { Build Up Objekt }
  190.   lChk := Crc^.CheckSumme(szFile);
  191.   Dispose(crc, Done);                   { Speicher wieder freigeben }
  192.  
  193.   writeln('CRC ', hex(lChk,8));
  194.   writeln('FILE ', FileNameSplit(szFile));
  195.   if magic <> '' then
  196.   begin
  197.      writeln('MAGIC ', magic);
  198.   end;
  199.   if replaces <> '' then
  200.   begin
  201.      writeln('REPLACES ',replaces);
  202.   end;
  203.  
  204.   fileid_diz;
  205.   if magic <> '' then
  206.      Writeln('LDESC ■ Magic/Filename: ',magic,', ',FileNameSplit(szFile));
  207.   if replaces <> '' then
  208.      Writeln('LDESC ■ Replaces: ',replaces);
  209.  
  210.   write('LDESC ■ Size: ',Format(filelength(szFile)),' bytes, ');
  211.   lzeit := FileLength(szFile) div 2990 + 1;
  212.   writeln(todec(lZeit div 60),':',todec(lZeit mod 60),' min @ 28.8 KB');
  213. end.
  214.