-
Notifications
You must be signed in to change notification settings - Fork 45
/
adjscrol.c
95 lines (77 loc) · 2.06 KB
/
adjscrol.c
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
** ADJSCROL.C - Display lines to the screen, adjusting the scroll rate
**
** public domain demo by Bob Stout
*/
#include <stdio.h>
#include "more.h"
static int cols;
static long pause = 500; /* Default to 1/2 second */
/*
** adj_scroll() - Display a line, dynamically adjusting the scroll rate
**
** Parameters: 1 - Line to display
**
** Returns: Key_ESC ('\x1b') if ESC pressed, else 0
**
** Notes: Reads screen size from BIOS
** Handles long line wrapping
** Key_ESC to exit via calling function
** Key_PGUP to speed scrolling
** Key_PGDN to slow scrolling
*/
int adj_scroll(char *str)
{
char linebuf[256];
int ch;
if (!cols)
cols = SCREENCOLS;
if (strlen(str) == ((size_t)cols + 1) && LAST_CHAR(str) == '\n')
LAST_CHAR(str) = NUL;
while (strlen(str) > (size_t)cols)
{
strn1cpy(linebuf, str, cols);
linebuf[cols] = NUL;
adj_scroll(linebuf);
strMove(str, str + cols);
}
fputs(str, stderr);
delay((int)pause);
if (EOF != (ch = ext_inkey()))
{
switch (ch)
{
case Key_ESC:
return ch;
case Key_PGUP:
pause *= 3L; /* Reduce pause by 25% */
pause /= 4L;
break;
case Key_PGDN:
pause *= 125L; /* Increase pause by 25% */
pause /= 100L;
break;
}
}
return 0;
}
#ifdef TEST
#include "errors.h" /* For cant() */
main(int argc, char *argv[])
{
FILE *fp;
char buf[512];
while (--argc)
{
fp = cant(*++argv, "r");
while (!feof(fp))
{
if (NULL == fgets(buf, 512, fp))
break;
if (Key_ESC == adj_scroll(buf))
break;
}
}
return 0;
}
#endif /* TEST */