From:	CSBVAX::MRGATE!RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP 19-AUG-1988 11:44
To:	ARISIA::EVERHART
Subj:	TPU What_Line Procedure


Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Fri, 19 AUG 88 06:53:43 PDT
Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Fri, 19 Aug 88 06:36:00 PDT
Received: by ucbvax.Berkeley.EDU (5.59/1.30)
	id AA07715; Fri, 19 Aug 88 05:57:17 PDT
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 19 Aug 88 12:51:51 GMT
From: cookie.dec.com!chavez@decwrl.dec.com  (Dale - 522-2336 CXO-ESDP)
Organization: Digital Equipment Corporation
Subject: TPU What_Line Procedure
Message-Id: <8808191251.AA15605@decwrl.dec.com>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com


Here is a TPU procedure that returns the current line you're in.

Dale


! DJC$WHAT_LINE.TPU 		19-AUG-1988 06:48			Page 1

!++
!				Table of Contents 
!
!			        DJC$WHAT_LINE.TPU
!				19-AUG-1988 06:48
!
!	Procedure name			Page	Description
!	--------------			----	------------
!
!	djc$what_line 			   1	Display current line
!--
procedure djc$what_line		! Display current line

local this_position,		! marker - current position
      start_of_buffer,		! marker - beginning of current buffer
      this_line_position,	! marker - position at start of this_line
      total_lines,		! integer - total lines in buffer
      high_line,		! integer - high line limit for binary search
      low_line,			! integer - low line limit for binary search
      this_line,		! integer - line number of current guess
      percent;			! integer - percent of way through buffer

! Initialization

this_position := mark (none);
start_of_buffer := beginning_of (current_buffer);
total_lines := get_info (current_buffer, "record_count") + 1;
high_line := total_lines;
if this_position = end_of (current_buffer) then
    low_line := total_lines;
else
    low_line := 1;
endif;

! Binary search

loop
    exitif high_line - low_line <= 1;
    this_line := low_line + ((high_line - low_line) / 2);
    position (start_of_buffer);
    move_vertical (this_line - 1);
    if mark (none) > this_position then
	high_line := this_line;
    else
        low_line := this_line;
	if mark (none) = this_position then
	    high_line := this_line;
        endif;
    endif;
endloop;

! TPU truncates numbers on division; make it round instead

percent := (((low_line * 1000) / total_lines)+5)/10;

! Display message and return to original position

set (bell,broadcast,on);
message (fao ("You are on line !SL out of !SL (!SL%)",
	      low_line, total_lines, percent));
set (bell,broadcast,on);
position (this_position);

endprocedure;

