



          %SETEOF(bufnum)
          ==============
          The SETEOF command may  be used to "shrink" the  amount of  space
          taken up by a file, and  thus  free-up additional disk space. The
          syntax for the %SETEOF command is:
                 %SETEOF(n)
          where 'n' represents the buffer number used to  open the  file in
          question,  and  can  be  expressed as an  integer constant  or an
          integer expression.
          The %SETEOF command is used primarily  in conjunction with random
          files (R-mode). In some applications, a  random file may  contain
          unwanted records at the  end of  the file.  The  %SETEOF  command
          will furnish you with a way to  eliminate these unwanted records.
          The function it performs is to  reset the end of file  marker for
          the file in question  to a  value  less than the  current end  of
          file marker.  This will  cause all records whose  record  numbers
          are  greater than the new end of file marker value to be ignored,
          and  thus make these  records inaccessible. Also, the space taken
          up on the disk by  these  "eliminated" records  will be added  to
          the free space available, and thus may be reused.
          To use the SET  EOF command,  you must open the file  in question
          as  a  random file.  It  is highly  recommended that  the  record
          length  used to open the  file be the same as the  record  length
          used for normal access to the file.
          After the file has  been opened, perform  a GET of the record you
          wish to  be the last record in  the  file. You  may then  use the
          %SETEOF  command to reset the  end of file marker to the  current
          record  number, and thus eliminate all unwanted records (by doing
          a GET, the current record number will be changed to the  value of
          the record which was retrieved).
          Suppose  you have a  random file named XTRA/DAT  which  currently
          contains  100  records, and you  wish to eliminate  the  last  50
          records of the file (records 51-100). Assume also  that  the file
          has been opened  in the  random mode, using buffer number  3. The
          following   commands  may   be  used  to  accomplish  this  "file
          shrinkage".
                  GET3,50:%SETEOF(3)
          Here's  a more detailed example program illustrating an easy user
          command  designed to  set the EOF of  a random  access file.  The
          random file is  positioned to the last record desired by means of
          a  GET  on  that  record. Then  the SETEOF [of  course  coded  as
          %SETEOF(bufnum) since  EnhComp  requires  the  "%"  character  to
          indicate  a  user  command]  will  set  the  EOF  pointers to the
          current record pointers.












                  ALLOCATE 1
                  OPEN "R",1,"testfile/dat",32
                  FIELD 1,32 AS ARG$
                  FOR I = 1 TO 20
                  LSET ARG$="This is test "+STR$(I)
                  PUT 1,I: NEXT
                  CLOSE 1
                  SYSTEM"List testfile/dat (hex)"
                  OPEN "r",1,"TESTFILE/DAT",32
                  FIELD 1,32 AS ARG$
                  GET 1,10: PRINT ARG$
                  %SETEOF(1)
                  CLOSE 1
                  END"list testfile/dat (hex)"
                  *INCLUDE SETEOF/BAS
          N O T E
          =======
          Be  extremely  careful  when  using  the  SET  EOF command.  Once
          records  have  been eliminated  from a file using  this  command,
          they  might  not be  recoverable!! It is beyond the scope of this
          manual to discuss techniques used to recover lost  information in
          a file. The best prevention for such an occurrence is caution!
          Technical Note
          ==============
          The  %SETEOF(bufnum)   command  code   is  in  the   file   named
          "SETEOF/BAS".  This file  must  be included  with your program in
          order to be able to use the command. Here's the code:
                  COMMAND SETEOF(BUFNUM%)
                  IF NOT EOF(BUFNUM%)
                  Z80-MODE
                  LD HL,(&(BUFNUM%)):CALL @CALADR
                  LD A,(IX+16+5):LD (IX+16+8),A
                  LD A,(IX+16+10):LD (IX+16+12),A
                  LD A,(IX+16+11):LD (IX+16+13),A
                  HIGH-MODE
                  ENDIF
                  RETURN
                  ENDCOM
          If you care to examine that file,  you will see that it consists,
          in  part, of a Z80-MODE routine. "@CALADR" is a routine  from the
          EnhComp  SUPPORT/DAT  library which calculates  the  address of a
          bufnum's  file buffer allocation  (documented  on  page  5-2) and
          returns the value in  register IX. To be  fancy about it,  the CF
          would be set on return from  @CALADR  if the bufnum  referenced a
          file  which  was  not already open. Of course, under  that  case,
          nothing damaging would result as  the accessing of the FCB region
          would be of  unused  memory  addresses. Make  note  that  if  the
          bufnum exceeds  the value established  by ALLOCATE  (the  maximum
          number of open files), @CALADR would report a runtime error 104.






