File: less-pipe

package info (click to toggle)
epic4 1%3A3.0-2.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,756 kB
  • sloc: ansic: 56,285; makefile: 631; sh: 161; perl: 30
file content (68 lines) | stat: -rw-r--r-- 1,018 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#
# Open up a pipe and then page the output.
# I wrote this in a race with Archon (hop, 1997)
#

#
# Usage: 
#  $0  - name of the pipe
#  $1- - stuff to run
#
alias less_pipe
{
	@ line = 0

	if ([$1])
	{
		^on ^exec "$0 *" {
			@ lessline[$line] = [$1-]
			@ line++
		}
		^on ^exec_error "$0 *" {
			echo *** Error on exec: $*
		}
		^on ^exec_exit "$0 *" {
			on exec -"$0 *"
			on exec_error -"$0 *"
			on exec_exit -"$0 *"
			less_array lessline 0 $line
		}
		exec -name $*
	}
}

/*
 * $0 is the array name to use
 * $1 is the starting line
 * $2 is the final line
 */
alias less_array
{
	local line $1
	local cr 0
	local rows $winsize()

	while ((line < [$2]) && (cr < rows))
	{
		echo $($0[$line])
		assign -$0[$line]
		@ line++, cr++
	}

	if (cr >= rows)
	{
		@ aaa.array_name = [$0]
		@ aaa.next_line = line
		@ aaa.final_line = [$2]

		input_char "Enter q to quit, or anything else to continue "
		{
			if ([$0] != [q])
			{
				^less_array $aaa.array_name $aaa.next_line $aaa.final_line
			}
		}
	}
}

#hop'97