home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / fileutil / delnulls.arj / DELNULLS.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1991-08-07  |  1.9 KB  |  93 lines

  1. (*
  2.  * Program : DELNULLS.EXE
  3.  * Author  : Bill Mullen (ATTBS ->BIG5)
  4.  * Language: Turbo Pascal 6.0
  5.  *
  6.  * Syntax  : DELNULLS <filename.ext>
  7.  *
  8.  * Notes   : Hope it helps someone.  Kinda paying back for the help I've
  9.  *           received.
  10.  *)
  11.  
  12. {$m $400,0,0}
  13. program remove_nulls;
  14.  
  15. uses
  16.    dos;
  17.  
  18.  
  19. const
  20.    OldChar = #0;    (* Change this to any character you want converted       *)
  21.    NewChar = #32;   (* This character will replace all occurences of OLDCHAR *)
  22.  
  23.  
  24. type
  25.    Buffer   = Array [1..1024] of byte;
  26.  
  27.  
  28. var
  29.    FileName  : String;
  30.    FileHndl  : File;
  31.    Buf       : Buffer;
  32.    BufCntr   : Word;
  33.    NumRead   : Word;
  34.    CurrPos   : LongInt;
  35.    ExitSafe  : Pointer;
  36.    FileOpen  : Boolean;
  37.    SR        : SearchRec;
  38.  
  39.  
  40. {$f+}
  41. procedure SafeExit; Far;
  42. begin
  43.    ExitProc := ExitSafe;
  44.    if FileOpen then
  45.       Close(FileHndl);
  46. end;
  47.  
  48.  
  49.  
  50. begin
  51.    (* Set up exit routine *)
  52.    ExitSafe := ExitProc;
  53.    ExitProc := @SafeExit;
  54.    FileOpen := False;
  55.  
  56.    (* Was a file passed to the program *)
  57.    if ParamCount = 0 then
  58.       Halt(1);
  59.  
  60.    (* Save the parameter to a variable *)
  61.    FileName := paramstr(1);
  62.  
  63.    (* Now see if the file exist... *)
  64.    FindFirst(FileName,AnyFile,SR);
  65.    if DosError <> 0 then
  66.       halt(2);
  67.  
  68.    (* Open the file for READ/WRITE *)
  69.    Assign (FileHndl,FileName);
  70.    Reset  (FileHndl,1);
  71.    FileOpen := True;
  72.  
  73.    (*
  74.     * Read from the file 1 buffer at a time, replacing all OLDCHAR's with
  75.     * NEWCHAR's and write the buffer back to the file.
  76.     *)
  77.  
  78.     repeat
  79.        CurrPos := FilePos(FileHndl);
  80.        blockread(FileHndl,Buf,SizeOf(Buf),NumRead);
  81.        for BufCntr := 1 to NumRead do
  82.           if Buf[BufCntr] = ord(OldChar) then
  83.              Buf[BufCntr] := ord(NewChar);
  84.        Seek(FileHndl,Currpos);
  85.        BlockWrite(FileHndl,Buf,NumRead);
  86.     until (NumRead = 0);
  87.  
  88.     (* Close the file *)
  89.     Close(FileHndl);
  90.     FileOpen := False;
  91.     Halt(0);
  92. end.
  93.