home *** CD-ROM | disk | FTP | other *** search
- FUNCTION bb_view
-
- PARAM t, l, b, r, fname
-
- PRIVATE s_line, save_scr, lkey
-
- * Save and set cursor
- * .
- * .
- * .
- SET CURSOR OFF
-
- IF bb_init(fname, t, l, b, r)
- s_line = 1 && Start line #
-
- save_scr = savescreen(t, l, b, r)
-
- * If we have at least one line, show it ...
- IF bb_show_win(s_line)
- * Now wait for page up, page down, or ESC
- lkey = inkey(0)
- DO WHILE lkey != ESC
- DO CASE
- CASE lkey = PG_UP
- * Move up by one page full
- IF s_line != 1
- s_line = s_line - bb_rows_win
- bb_show_win(s_line)
- ENDIF
-
- CASE lkey = PG_DOWN
- * Try and move down by one page full
- s_line = s_line + bb_rows_win
- IF !bb_show_win(s_line)
- * There were no more lines. Backtrack
- * and set last window pointer
- s_line = s_line - bb_rows_win
- bb_show_win(s_line)
- ENDIF
- ENDCASE
-
- * Now wait for page up, page down, or ESC
- lkey = inkey(0)
- ENDDO
- ENDIF && Show first window
-
- restscreen(t, l, b, r, save_scr)
- bb_end()
- ENDIF && bb_init ok
-
- * Restore cursor
- * .
- * .
- * .
- RETURN VOID
-
-
- * LOGICAL bb_init(fname, t, l, b, r)
- *
- * NUMERIC fname && Name of file to browse
- * NUMERIC t, l, b, r && Browse box coordinates
- *
- * Initialize the big browse class.
- * Returns .T. if successfully initialized, .F. otherwise
-
- FUNCTION bb_init
-
- PARAM fname, rows_win
-
- PRIVATE bb_init
-
- PUBLIC bb_fhandle && File handle of file being viewed
- PUBLIC bb_rows_win && The number of rows in the window
- PUBLIC bb_cols_win && The number of columns in the window
- PUBLIC bb_t && Window coordinates
- PUBLIC bb_l
- PUBLIC bb_b
- PUBLIC bb_r
- PUBLIC bb_f_ptrs && Character string containing pointers
- && into the browsed file, for each page
-
- bb_fhandle = fopen(fname, OPEN_RDWR)
- IF bb_fhandle > 0
- bb_t = t
- bb_l = l
- bb_b = b
- bb_r = r
- bb_rows_win = bb_b - bb_t + 1
- bb_cols_win = bb_r - bb_l + 1
-
- bb_f_ptrs = ""
- bb_mark(1)
- bb_init = .T.
- ELSE
- ? "Cannot open file ", fname
- RELEASE bb_fhandle, bb_rows_win, bb_cols_win, ;
- bb_t, bb_l, bb_b, bb_r, bb_f_ptrs
- bb_init = .F.
- ENDIF
-
- RETURN bb_init
-
-
- FUNCTION bb_end
-
- fclose(bb_fhandle)
- RELEASE bb_fhandle, bb_rows_win, bb_cols_win, ;
- bb_t, bb_l, bb_b, bb_r, bb_f_ptrs
-
- RETURN VOID
-
-
-
- * LOGICAL bb_show_win(s_line)
- *
- * NUMERIC s_line && Start line to browse from
- *
- * Show a window full from line s_line.
- * Return .T. if at least one line shown, .F. otherwise
-
- FUNCTION bb_show_win
-
- PARAM s_line
-
- PRIVATE line_num, more_lines, line
-
- * Clear window
- scroll(bb_t, bb_l, bb_b, bb_r, 0)
-
- line_num = s_line
- more_lines = bb_gotoln(s_line)
-
- DO WHILE line_num < s_line + bb_rows_win .AND. more_lines
- line = space(MAX_LINE_LEN)
- more_lines = readln(bb_fhandle, @line)
- IF more_lines
- @ bb_t + line_num - s_line, bb_l SAY pad(line, bb_cols_win)
- line_num = line_num + 1
- ENDIF
- ENDDO
-
- * if we read a complete window full, we can set next
- * window pointer ...
- IF more_lines
- bb_mark(line_num)
- ENDIF
-
- RETURN line_num > s_line
-
-
-
- FUNCTION readln
-
- PARAM f_handle, buffer_ptr
-
- PRIVATE where_crlf, num_read
-
- num_read = fread(f_handle, @buffer_ptr, len(buffer_ptr))
- IF num_read > 0
- where_crlf = at(CRLF, buffer_ptr)
- IF where_crlf != 0
- * Got crlf, position file pointer just after it
- fseek(f_handle, where_crlf - num_read + 1, SEEK_CUR)
- buffer_ptr = substr(buffer_ptr, 1, where_crlf - 1)
- ELSE
- buffer_ptr = trim(buffer_ptr)
- ENDIF
- ENDIF
-
- RETURN num_read > 0
-
-
-
- * VOID bb_mark(line_num)
- *
- * NUMERIC line_num && The line number where the file
- * && is currently positioned
- *
- * The file is currently positioned at line_num. Line_num is a multiple
- * of bb_rows_win. If this is the first time we have reached this point,
- * we store a pointer to it in the bb_f_ptrs string.
-
- FUNCTION bb_mark
-
- PARAM line_num
-
- PRIVATE lines_seen
-
- lines_seen = (len(bb_f_ptrs) / F_PTR_LEN) * bb_rows_win
- IF line_num > lines_seen
- bb_f_ptrs = bb_f_ptrs + str(FTELL(bb_fhandle), F_PTR_LEN)
- ENDIF
-
- RETURN VOID
-
-
-
- FUNCTION bb_gotoln
-
- PARAM line_num
-
- PRIVATE ret_val, lines_seen, win_num
-
- * If we have seen this line already, go to it, otherwise error
- lines_seen = (len(bb_f_ptrs) / F_PTR_LEN) * bb_rows_win
- ret_val = line_num <= lines_seen
- IF ret_val
- win_num = (line_num - 1) / bb_rows_win
- fseek(bb_fhandle, val(substr(bb_f_ptrs, ;
- win_num * F_PTR_LEN + 1, ;
- F_PTR_LEN)))
- ENDIF
-
- RETURN ret_val
-
-
-
-
- * bb.pre
- *
- * Big browse routines. Allow browsing of files of any size
-
- #include "keys.h"
- #include "system.h"
- #include "files.h"
-
- #define F_PTR_LEN 7 && length of file pointers
- #define MAX_LINE_LEN 255 && we split a line at this length
-
- #define CRLF chr(13) + chr(10)
-
- #define FTELL(f_handle) fseek(f_handle, 0, SEEK_CUR)
-
- * Sample driver, pass file name on comamnd line ...
-
- PARAM fname
-
- CLEAR
- bb_view(0, 0, 24, 79, fname)
-
-
- * VOID bb_view(t, l, b, r, fname)
- *
- * NUMERIC t, l, b, r && Window coordinates
- * CHARACTER fname && Name of file to browse
- *
- * Browse a file in the window. No restrictions on file size. Page up
- * and down scroll windows, Escape exits
-
- FUNCTION bb_view
-
- PARAM t, l, b, r, fname
-
- PRIVATE s_line, save_scr, lkey
-
- * start_last_win saves line number which start the last viewable
- * window. It is set when we determine we can no longer move,
- * and is used to optimize the viewing of the last window (if they
- * keep hitting page down, nothing happens). Initially set it to
- * invalid line # so we know it has not been set yet ...
-
- * Save and set cursor
- SET CURSOR OFF
- IF bb_init(fname, t, l, b, r)
- s_line = 1 && Start line #
-
- save_scr = savescreen(t, l, b, r)
-
- * If we have at least one line, show it ...
- IF bb_show_win(s_line)
- * Now wait for page up, page down, or ESC
- lkey = inkey(0)
- DO WHILE lkey != ESC
- DO CASE
- CASE lkey = PG_UP
- * Move up by one page full
- IF s_line != 1
- s_line = s_line - bb_rows_win
- bb_show_win(s_line)
- ENDIF
-
- CASE lkey = PG_DOWN
- * Try and move down by one page full
- s_line = s_line + bb_rows_win
- IF !bb_show_win(s_line)
- * There were no more lines. Backtrack
- * and set last window pointer
- s_line = s_line - bb_rows_win
- bb_show_win(s_line)
- ENDIF
- ENDCASE
-
- * Now wait for page up, page down, or ESC
- lkey = inkey(0)
- ENDDO
- ENDIF && Show first window
-
- restscreen(t, l, b, r, save_scr)
- bb_end()
- ENDIF && bb_init ok
-
- * Restore cursor
-
- RETURN VOID
-
-
- * LOGICAL bb_show_win(s_line)
- *
- * NUMERIC s_line && Start line to browse from
- *
- * Show a window full from line s_line.
- * Return .T. if at least one line shown, .F. otherwise
-
- FUNCTION bb_show_win
-
- PARAM s_line
-
- PRIVATE line_num, more_lines, line
-
- * Clear window
- scroll(bb_t, bb_l, bb_b, bb_r, 0)
-
- line_num = s_line
- more_lines = bb_gotoln(s_line)
-
- DO WHILE line_num < s_line + bb_rows_win .AND. more_lines
- line = space(MAX_LINE_LEN)
- more_lines = readln(bb_fhandle, @line)
- IF more_lines
- @ bb_t + line_num - s_line, bb_l SAY pad(line, bb_cols_win)
- line_num = line_num + 1
- ENDIF
- ENDDO
-
- * if we read a complete window full, we can set next
- * window pointer ...
- IF more_lines
- bb_mark(line_num)
- ENDIF
-
- RETURN line_num > s_line
-
-
- * LOGICAL bb_gotoln(line_num)
- *
- * NUMERIC line_num && Line number to go to
- *
- * Position file at start of line_num. Return .T. if ok, .F. otherwise
-
- FUNCTION bb_gotoln
-
- PARAM line_num
-
- PRIVATE ret_val, lines_seen, win_num
-
- * If we have seen this line already, go to it, otherwise error
- lines_seen = (len(bb_f_ptrs) / F_PTR_LEN) * bb_rows_win
- ret_val = line_num <= lines_seen
- IF ret_val
- win_num = (line_num - 1) / bb_rows_win
- fseek(bb_fhandle, val(substr(bb_f_ptrs, ;
- win_num * F_PTR_LEN + 1, ;
- F_PTR_LEN)))
- ENDIF
-
- RETURN ret_val
-
-
- * VOID bb_mark(line_num)
- *
- * NUMERIC line_num && The line number where the file
- * && is currently positioned
- *
- * The file is currently positioned at line_num. Line_num is a multiple
- * of bb_rows_win. If this is the first time we have reached this point,
- * we store a pointer to it in the bb_f_ptrs string.
-
- FUNCTION bb_mark
-
- PARAM line_num
-
- PRIVATE lines_seen
-
- lines_seen = (len(bb_f_ptrs) / F_PTR_LEN) * bb_rows_win
- IF line_num > lines_seen
- bb_f_ptrs = bb_f_ptrs + str(FTELL(bb_fhandle), F_PTR_LEN)
- ENDIF
-
- RETURN VOID
-
-
- * LOGICAL bb_init(fname, t, l, b, r)
- *
- * NUMERIC fname && Name of file to browse
- * NUMERIC t, l, b, r && Browse box coordinates
- *
- * Initialize the big browse class.
- * Returns .T. if successfully initialized, .F. otherwise
-
- FUNCTION bb_init
-
- PARAM fname, rows_win
-
- PRIVATE bb_init
-
- PUBLIC bb_fhandle && File handle of file being viewed
- PUBLIC bb_rows_win && The number of rows in the window
- PUBLIC bb_cols_win && The number of columns in the window
- PUBLIC bb_t && Window coordinates
- PUBLIC bb_l
- PUBLIC bb_b
- PUBLIC bb_r
- PUBLIC bb_f_ptrs && Character string containing pointers
- && into the browsed file, for each page
-
- bb_fhandle = fopen(fname, OPEN_RDONLY)
- IF bb_fhandle > 0
- bb_t = t
- bb_l = l
- bb_b = b
- bb_r = r
- bb_rows_win = bb_b - bb_t + 1
- bb_cols_win = bb_r - bb_l + 1
-
- bb_f_ptrs = ""
- bb_mark(1)
- bb_init = .T.
- ELSE
- ? "Cannot open file ", fname
- RELEASE bb_fhandle, bb_rows_win, bb_cols_win, ;
- bb_t, bb_l, bb_b, bb_r, bb_f_ptrs
- bb_init = .F.
- ENDIF
-
- RETURN bb_init
-
-
- FUNCTION bb_end
-
- fclose(bb_fhandle)
- RELEASE bb_fhandle, bb_rows_win, bb_cols_win, ;
- bb_t, bb_l, bb_b, bb_r, bb_f_ptrs
-
- RETURN VOID
-
-
- FUNCTION readln
-
- PARAM f_handle, buffer_ptr
-
- PRIVATE where_crlf, num_read
-
- num_read = fread(f_handle, @buffer_ptr, len(buffer_ptr))
- IF num_read > 0
- where_crlf = at(CRLF, buffer_ptr)
- IF where_crlf != 0
- * Got crlf, position file pointer just after it
- fseek(f_handle, where_crlf - num_read + 1, SEEK_CUR)
- buffer_ptr = substr(buffer_ptr, 1, where_crlf - 1)
- ELSE
- buffer_ptr = trim(buffer_ptr)
- ENDIF
- ENDIF
-
- RETURN num_read > 0
-
-
-
- FUNCTION bb_view
-
- PARAM t, l, b, r, fname
-
- PRIVATE s_line, save_scr, lkey, start_last_win
-
- * start_last_win saves line number which start the last viewable
- * window. It is set when we determine we can no longer move,
- * and is used to optimize the viewing of the last window (if they
- * keep hitting page down, nothing happens). Initially set it to
- * invalid line # so we know it has not been set yet ...
-
- start_last_win = -1
-
- * Save and set cursor
- SET CURSOR OFF
- IF bb_init(fname, t, l, b, r)
- s_line = 1 && Start line #
-
- save_scr = savescreen(t, l, b, r)
-
- * If we have at least one line, show it ...
- IF bb_show_win(s_line)
- * Now wait for page up, page down, or ESC
- lkey = inkey(0)
- DO WHILE lkey != ESC
- DO CASE
- CASE lkey = PG_UP
- * Move up by one page full
- IF s_line != 1
- s_line = s_line - bb_rows_win
- bb_show_win(s_line)
- ENDIF
-
- CASE lkey = PG_DOWN
- * OPTIMIZATION: If we have already determined
- * this is the last page, don't try and move
- IF s_line != start_last_win
- * Try and move down by one page full
- s_line = s_line + bb_rows_win
- IF !bb_show_win(s_line)
- * There were no more lines. Backtrack
- * and set last window pointer
- s_line = s_line - bb_rows_win
- start_last_win = s_line
- bb_show_win(s_line)
- ENDIF
- ENDIF
- ENDCASE
-
- * Now wait for page up, page down, or ESC
- lkey = inkey(0)
- ENDDO
- ENDIF && Show first window
-
- restscreen(t, l, b, r, save_scr)
- bb_end()
- ENDIF && bb_init ok
-
- * Restore cursor
-
- RETURN VOID
-
-
-
- * LOGICAL bb_init(fname, t, l, b, r)
- *
- * NUMERIC fname && Name of file to browse
- * NUMERIC t, l, b, r && Browse box coordinates
- *
- * Initialize the big browse class.
- * Returns .T. if successfully initialized, .F. otherwise
-
- FUNCTION bb_init
-
- PARAM fname, rows_win
-
- PRIVATE bb_init
-
- PUBLIC bb_fhandle && File handle of file being viewed
- PUBLIC bb_rows_win && The number of rows in the window
- PUBLIC bb_cols_win && The number of columns in the window
- PUBLIC bb_t && Window coordinates
- PUBLIC bb_l
- PUBLIC bb_b
- PUBLIC bb_r
- PUBLIC bb_fptr_handle && File handle of pointers file
-
- bb_fhandle = fopen(fname, OPEN_RDWR)
- IF bb_fhandle > 0
- bb_t = t
- bb_l = l
- bb_b = b
- bb_r = r
- bb_rows_win = bb_b - bb_t + 1
- bb_cols_win = bb_r - bb_l + 1
-
- bb_fptr_handle = fcreate("_fptrs")
- bb_mark(1)
- bb_init = .T.
- ELSE
- ? "Cannot open file ", fname
- RELEASE bb_fhandle, bb_rows_win, bb_cols_win, ;
- bb_t, bb_l, bb_b, bb_r, bb_fptr_handle
-
- bb_init = .F.
- ENDIF
-
- RETURN bb_init
-
-
-
- FUNCTION bb_end
-
- fclose(bb_fhandle)
- fclose(bb_fptr_handle)
- RELEASE bb_fhandle, bb_rows_win, bb_cols_win, bb_t, bb_l, ;
- bb_b, bb_r, bb_fptr_handle
-
- RETURN VOID
-
-
-
- * VOID bb_mark(line_num)
- *
- * NUMERIC line_num && The line number where the file
- * && is currently positioned
- *
- * The file is currently positioned at line_num. Line_num is a multiple
- * of bb_rows_win. If this is the first time we have reached this point,
- * we add a pointer to it at the end of the _fptrs file.
-
- FUNCTION bb_mark
-
- PARAM line_num
-
- PRIVATE lines_seen
-
- lines_seen = (file_len(bb_fptr_handle) / F_PTR_LEN) * bb_rows_win
- IF line_num > lines_seen
- fseek(bb_fptr_handle, 0, SEEK_EOF)
- fwrite(bb_fptr_handle, str(FTELL(bb_fhandle), F_PTR_LEN))
- ENDIF
-
- RETURN VOID
-
-
-
- FUNCTION file_len
-
- PARAM f_handle
- PRIVATE save_fpos, ret_val
-
- save_fpos = FTELL(f_handle)
- ret_val = fseek(f_handle, 0, SEEK_EOF)
- fseek(f_handle, save_fpos)
-
- RETURN ret_val
-
-
-
-
- * LOGICAL bb_gotoln(line_num)
- *
- * NUMERIC line_num && Line number to go to
- *
- * Position file at start of line_num. Return .T. if ok, .F. otherwise
-
- FUNCTION bb_gotoln
-
- PARAM line_num
-
- PRIVATE ret_val, lines_seen, win_num
-
- * If we have seen this line already, go to it, otherwise error
- lines_seen = (file_len(bb_fptr_handle) / F_PTR_LEN) * bb_rows_win
- ret_val = line_num <= lines_seen
- IF ret_val
- win_num = (line_num - 1) / bb_rows_win
- fseek(bb_fptr_handle, win_num * F_PTR_LEN + 1)
- fseek(bb_fhandle, val(freadstr(bb_fptr_handle, F_PTR_LEN)))
- ENDIF
-
- RETURN ret_val
-
-
-