File: less

package info (click to toggle)
epic4 1%3A2.2-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,600 kB
  • ctags: 5,377
  • sloc: ansic: 55,723; makefile: 656; sh: 158; perl: 30
file content (69 lines) | stat: -rw-r--r-- 1,444 bytes parent folder | download | duplicates (10)
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
69
#
# A file pager.  A demonstration of how to do something useful in ircII.
# This cheesy rip-off was written by hop in 1996.
# My apologies in advance to archon.
# Modified on Jan 25, 1999 as an example of how to use arglists.
#
# Modified by howl on Des(1) 8, 2003, to honour numlines(), and close file
# on 'q'
#
# Modified by howl on Jan 14, 2004, to turn indent, and continue line off
# when paging a file. 
#
# (1: Des (Desember) is Dec (December) in Norwegian)

alias less (file default "-help")
{
	@ winnum = winnum()
	if (file == [-help]) {
		xecho -w $winnum Usage: /less <filename>
	} elsif (fexist($file) == 1) {
		less_file $open($file R) ${winsize() - 1} $winnum
	} else {
		xecho -w $winnum $file\: no such file.
	}
}


alias less_file (file, count, winnum default 0, void)
{
	^local line 0
	^local ugh
	^local width ${word(0 $geom())-1}
	
	stack push set indent
	stack push set continue_line
	^set indent off
	^set -continue_line
	while (!eof($file) && (line < count))
	{
		@ ugh = read($file)
		@ line +=  numlines($width $ugh)
		if (!eof($file)) {
			xecho -w $winnum $ugh
		}
	}
	stack pop set indent
	stack pop set continue_line
	if (!eof($file))
	{
		@ less.fd = file
		@ less.nl = count
		@ less.w  = winnum
		input_char "Enter q to quit, or anything else to continue "
		{
			if ([$0] != [q]) {
				less_file $less.fd $less.nl $less.w
			}
			{
				@ close($file)
			}
		}
	}
	{
		@ close($file)
	}
}

#hop'96,99
#howl'03