home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a013 / 1.ddi / SOURCE.EXE / F_ARREAD.PRG < prev    next >
Encoding:
Text File  |  1991-01-25  |  1.0 KB  |  39 lines

  1. *****************************************************************
  2. FUNCTION ARREAD (text_file)
  3. *****************************************************************
  4.  
  5. * Reads a text file into an array
  6.  
  7. * Copyright(c) 1991 -- James Occhiogrosso
  8.  
  9. # include "fileio.ch"
  10. # translate F_LEN(<n>)  => FSEEK(<n>, FS_SET, FS_END)
  11. # translate F_BOF(<n>)  => FSEEK(<n>, FS_SET)
  12. # translate F_MOVE(<n>) => FSEEK(handle, FS_SET, FS_RELATIVE)
  13.  
  14. LOCAL filelength := handle := pointer := 0, text_array := {}
  15.  
  16. * Open the file in read only mode
  17. IF (handle := FOPEN(text_file, FO_READ)) != -1
  18.  
  19.    * If successful, save its length and reset pointer
  20.    filelength := F_LEN(handle) ;  F_BOF(handle)
  21.  
  22.    DO WHILE pointer < filelength
  23.  
  24.         * Read next line and add to array.
  25.         AADD(text_array, FREADLINE(handle))
  26.  
  27.         * Update file pointer to current position
  28.          pointer := F_MOVE(handle)
  29.    ENDDO
  30.  
  31.    * Close file
  32.    FCLOSE(handle)
  33.  
  34. ENDIF
  35.  
  36. * Return text array. If any error, array length is zero
  37. RETURN text_array
  38.  
  39.