head	1.3;
access;
symbols
	RELENG_2_2_8_RELEASE:1.2
	RELENG_2_2_7_RELEASE:1.2
	RELENG_2_2_6_RELEASE:1.2
	RELENG_2_2_5_RELEASE:1.2
	RELENG_2_2_2_RELEASE:1.2
	RELENG_2_2_1_RELEASE:1.2
	RELENG_2_2_0_RELEASE:1.2
	RELENG_2_1_7_RELEASE:1.2
	RELENG_2_1_6_1_RELEASE:1.2
	RELENG_2_1_6_RELEASE:1.2
	RELENG_2_2:1.2.0.6
	RELENG_2_2_BP:1.2
	RELENG_2_1_5_RELEASE:1.2
	RELENG_2_1_0_RELEASE:1.2
	RELENG_2_1_0:1.2.0.4
	RELENG_2_1_0_BP:1.2
	RELENG_2_0_5_RELEASE:1.2
	RELENG_2_0_5:1.2.0.2
	RELENG_2_0_5_BP:1.2
	RELENG_2_0_5_ALPHA:1.2;
locks; strict;
comment	@# @;


1.3
date	98.09.09.06.49.31;	author markm;	state dead;
branches;
next	1.2;

1.2
date	95.03.26.03.01.04;	author ache;	state Exp;
branches;
next	1.1;

1.1
date	95.03.24.04.33.53;	author jkh;	state Exp;
branches;
next	;


desc
@@


1.3
log
@Old Perl is leaving us. Goodbye, faithful friend.
@
text
@#!/usr/bin/curseperl

eval <<'EndOfMain';   $evaloffset = __LINE__;

    $SIG{'INT'} = 'endit';
    $| = 1;		# command buffering on stdout
    &initterm;
    &inithelp;
    &slurpfile && &pagearray;

EndOfMain

&endit;

################################################################################

sub initterm {

    &initscr; &cbreak; &noecho; &scrollok($stdscr, 1);
    &defbell unless defined &bell;

    $lines = $LINES; $lines1 = $lines - 1; $lines2 = $lines - 2;
    $cols = $COLS;   $cols1  = $cols  - 1; $cols2  = $cols  - 2;;

#   $dl = &getcap('dl');
#   $al = &getcap('al');
#   $ho = &getcap('ho');
#   $ce = &getcap('ce');
}

sub slurpfile {
    while (<>) {
	s/^(\t+)/'        ' x length($1)/e;
	&expand($_) if /\t/;
	if (length($_) < $cols) {
	    push(@@lines, $_);
	}
	else {
	    while ($_ && $_ ne "\n") {
		push(@@lines, substr($_,0,$cols));
		substr($_,0,$cols) = '';
	    }
	}
    }
    1;
}

sub drawscreen {
    &move(0,0);
    for ($line .. $line + $lines2) {
	&addstr($lines[$_]);
    }
    &clrtobot;
    &percent;
    &refresh;
}

sub expand {
    while (($off = index($_[0],"\t")) >= 0) {
	substr($_[0], $off, 1) = ' ' x (8 - $off % 8);
    }
}

sub pagearray {
    $line = 0;

    $| = 1;

    for (&drawscreen;;&drawscreen) {

	$ch = &getch;
	$ch = 'j' if $ch eq "\n";

	if ($ch eq ' ') {
	    last if $percent >= 100;
	    &move(0,0);
	    $line += $lines1;
	}
	elsif ($ch eq 'b') {
	    $line -= $lines1;
	    &move(0,0);
	    $line = 0 if $line < 0;
	}
	elsif ($ch eq 'j') {
	    next if $percent >= 100;
	    $line += 1;
#           if ($dl && $ho) {
#               print $ho, $dl;
#               &mvcur(0,0,$lines2,0);
#               print $ce,$lines[$line+$lines2],$ce;
#               &wmove($curscr,0,0);
#               &wdeleteln($curscr);
#               &wmove($curscr,$lines2,0);
#               &waddstr($curscr,$lines[$line+$lines2]);
#           }
	    &wmove($stdscr,0,0);
	    &wdeleteln($stdscr);
	    &wmove($stdscr,$lines2,0);
	    &waddstr($stdscr,$lines[$line+$lines2]);
	    &percent;
	    &refresh;
	    redo;
	}
	elsif ($ch eq 'k') {
	    next if $line <= 0;
	    $line -= 1;
#           if ($al && $ho && $ce) {
#               print $ho, $al, $ce, $lines[$line];
#               &wmove($curscr,0,0);
#               &winsertln($curscr);
#               &waddstr($curscr,$lines[$line]);
#           }
	    &wmove($stdscr,0,0);
	    &winsertln($stdscr);
	    &waddstr($stdscr,$lines[$line]);
	    &percent;
	    &refresh;
	    redo;
	}
	elsif ($ch eq "\f") {
	    &clear;
	}
	elsif ($ch eq 'q') {
	    last;
	}
	elsif ($ch eq 'h') {
	    &clear;
	    &help;
	    &clear;
	}
	else {
	    &bell;
	}
    }
}

sub defbell {
    eval q#
	sub bell {
	    print "\007";
	}
    #;
}

sub help {
    local(*lines) = *helplines;
    local($line);
    &pagearray;
}

sub inithelp {
    @@helplines = split(/\n/,<<'EOT');

  h              Display this help.
  q              Exit.

  SPACE          Forward  screen.
  b              Backward screen.
  j, CR          Forward  1 line.
  k              Backward 1 line.
  FF             Repaint screen.
EOT
    for (@@helplines) {
	s/$/\n/;
    }
}

sub percent {
    &standout;
      $percent = int(($line + $lines1) * 100 / @@lines);
      &move($lines1,0);
      &addstr("($percent%)");
    &standend;
    &clrtoeol;
}

sub endit {
    &move($lines1,0);
    &clrtoeol;
    &refresh;
    &endwin;

    if ($@@) {
	print "";				# force flush of stdout
	$@@ =~ s/\(eval\)/$0/ && $@@ =~ s/line (\d+)/'line ' . ($1 + $evaloffset)/e;
	die $@@;
    }

    exit;
}
@


1.2
log
@Comment out all perverted curses optimization
@
text
@@


1.1
log
@Bring back perl/usub as usub/, this time containing an updated curseperl
which is also installed by default (the reason for which should also be
plain shortly).
@
text
@d25 4
a28 4
    $dl = &getcap('dl');
    $al = &getcap('al');
    $ho = &getcap('ho');
    $ce = &getcap('ce');
d87 9
a95 9
	    if ($dl && $ho) {
		print $ho, $dl;
		&mvcur(0,0,$lines2,0);
		print $ce,$lines[$line+$lines2],$ce;
		&wmove($curscr,0,0);
		&wdeleteln($curscr);
		&wmove($curscr,$lines2,0);
		&waddstr($curscr,$lines[$line+$lines2]);
	    }
d107 6
a112 6
	    if ($al && $ho && $ce) {
		print $ho, $al, $ce, $lines[$line];
		&wmove($curscr,0,0);
		&winsertln($curscr);
		&waddstr($curscr,$lines[$line]);
	    }
@
