home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a012 / 1.ddi / CHAP18.EXE / CHP1802.PRG < prev    next >
Encoding:
Text File  |  1991-04-30  |  927 b   |  31 lines

  1. /*
  2.    Listing 18.2  Protect()
  3.    Author: Joe Booth
  4.    Excerpted from "Clipper 5: A Developer's Guide"
  5.    Copyright (c) 1991 M&T Books
  6.                       501 Galveston Drive
  7.                       Redwood City, CA 94063-4728
  8.                       (415) 366-3600
  9. */
  10.  
  11.  
  12. #include "FILEIO.CH"
  13.  
  14. function protect(file_name)
  15. LOCAL handle,first_byte,buffer:=" "
  16. LOCAL fn:=trim(file_name)
  17. if (handle := Fopen(fn+".DBF",FO_READWRITE)) > -1
  18.    fread(handle,@buffer,1)         // Read first byte
  19.    first_byte := asc(buffer)
  20.    fseek(handle,0,0)               // Go to top of file
  21.    if first_byte = 131             // If memo file field
  22.       fwrite(handle,chr(27),1)     // write 27 as the first
  23.    else                            // byte, otherwise write
  24.       fwrite(handle,chr(26),1)     // a 26.
  25.    endif
  26.    fclose(handle)                  // Close the file
  27. endif
  28. return NIL
  29.  
  30. // end of file CHP1802.PRG
  31.