xref: /csrg-svn/contrib/ed/z.c (revision 57710)
1 /*-
2  * Copyright (c) 1992 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Rodney Ruddock of the University of Guelph.
7  *
8  * %sccs.include.redist.c%
9  */
10 
11 #ifndef lint
12 static char sccsid[] = "@(#)z.c	5.2 (Berkeley) 01/23/93";
13 #endif /* not lint */
14 
15 #include <sys/types.h>
16 
17 #include <db.h>
18 #include <regex.h>
19 #include <setjmp.h>
20 #include <stdio.h>
21 #include <string.h>
22 
23 #include "ed.h"
24 #include "extern.h"
25 
26 /*
27  * This prints out the next group of lines (as spec'd by the skicky
28  * number; 22 by default). It's really useful for scrolling in chunks
29  * through the buffer (better than l, n, or p). Shame on POSIX for
30  * not including it; yaaa! BSD for keeping it! :-)
31  */
32 void
33 z(inputt, errnum)
34 	FILE *inputt;
35 	int *errnum;
36 {
37 	register int l_cnt;
38 
39 	if (current == NULL) {
40 		*errnum = -1;
41 		strcpy(help_msg, "no lines in buffer");
42 		return;
43 	}
44 	/* Set zsnum if need be here. */
45 	ss = getc(inputt);
46 	if ((ss > 48) && (ss < 57))
47 		/* Default set in main. */
48 		zsnum = dig_num_conv(inputt, errnum);
49 	else
50 		if ((ss != '\n') && (ss != EOF)) {
51 			ungetc(ss, inputt);
52 			if (rol(inputt, errnum))
53 				return;
54 		}
55 	if (sigint_flag)
56 		SIGINT_ACTION;
57 	if (End_default) {
58 		if ((current->below) != NULL)
59 			start = current->below;
60 		else {
61 			strcpy(help_msg, "at end of buffer");
62 			*errnum = -1;
63 			ungetc('\n', inputt);
64 			return;
65 		}
66 	} else
67 		start = End;
68 	if (start == NULL) {
69 		strcpy(help_msg, "bad address");
70 		*errnum = -1;
71 		ungetc('\n', inputt);
72 		return;
73 	}
74 	start_default = End_default = 0;
75 
76 	current = start;
77 	l_cnt = 1;		/* Yes, set to = 1. */
78 	while (1) {
79 		/* Scroll-out the next 'zsnum' of lines or until bottom. */
80 		if (sigint_flag)
81 			SIGINT_ACTION;
82 		if (current == NULL)
83 			break;
84 		get_line(current->handle, current->len);
85 		printf("%s\n", text);
86 		if (current == bottom)
87 			break;
88 		l_cnt++;
89 		if (zsnum < l_cnt)
90 			break;
91 		current = current->below;
92 	}
93 	*errnum = 1;
94 }
95