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

  1. *****************************************************************
  2. FUNCTION FREADLINE (handle, line_len)
  3. *****************************************************************
  4.  
  5. * Read a line from a text file (from current pointer position)
  6.  
  7. * Copyright(c) 1991 -- James Occhiogrosso
  8.  
  9. # define MAXLINE   512
  10.  
  11. LOCAL buffer, line_end, num_bytes
  12.  
  13. * If line length not passed, default to MAXLINE
  14. IF VALTYPE(line_len) != 'N'
  15.     line_len = MAXLINE
  16. ENDIF
  17.  
  18. * Define temporary buffer to hold specified line length
  19. buffer = SPACE(line_len)
  20.  
  21. * Read from current position to specified line length
  22. num_bytes = FREAD(handle, @buffer, line_len)
  23.  
  24. * Find carriage return/line feed combination
  25. line_end = AT(CHR(13)+CHR(10), buffer)
  26.  
  27. IF line_end = 0
  28.     * No carriage return/line feed. Pointer is at the end of
  29.     * file, or line is too long. Rewind pointer and return
  30.     FSEEK(handle, 0)
  31.     RETURN('')
  32.  
  33. ELSE
  34.     * Move pointer to beginning of next line
  35.     FSEEK(handle, (num_bytes * -1) + line_end + 1, 1)
  36.     * And return current line
  37.     RETURN( SUBSTR(buffer, 1, line_end - 1) )
  38.  
  39. ENDIF
  40.  
  41.  
  42.