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.3 (Berkeley) 02/28/93"; 13 #endif /* not lint */ 14 15 #include <sys/types.h> 16 17 #include <regex.h> 18 #include <setjmp.h> 19 #include <stdio.h> 20 #include <string.h> 21 22 #ifdef DBI 23 #include <db.h> 24 #endif 25 26 #include "ed.h" 27 #include "extern.h" 28 29 /* 30 * This prints out the next group of lines (as spec'd by the skicky 31 * number; 22 by default). It's really useful for scrolling in chunks 32 * through the buffer (better than l, n, or p). Shame on POSIX for 33 * not including it; yaaa! BSD for keeping it! :-) 34 */ 35 void 36 z(inputt, errnum) 37 FILE *inputt; 38 int *errnum; 39 { 40 register int l_cnt; 41 42 if (current == NULL) { 43 *errnum = -1; 44 strcpy(help_msg, "buffer empty"); 45 return; 46 } 47 /* Set zsnum if need be here. */ 48 ss = getc(inputt); 49 if ((ss > 48) && (ss < 57)) 50 /* Default set in main. */ 51 zsnum = dig_num_conv(inputt, errnum); 52 else 53 if ((ss != '\n') && (ss != EOF)) { 54 ungetc(ss, inputt); 55 if (rol(inputt, errnum)) 56 return; 57 } 58 if (start == NULL) { 59 strcpy(help_msg, "buffer empty"); 60 *errnum = -1; 61 ungetc('\n', inputt); 62 return; 63 } 64 if (End_default) { 65 if ((current->below) != NULL) 66 start = current->below; 67 else { 68 strcpy(help_msg, "at end of buffer"); 69 *errnum = -1; 70 ungetc('\n', inputt); 71 return; 72 } 73 } else 74 start = End; 75 start_default = End_default = 0; 76 77 current = start; 78 l_cnt = 1; /* Yes, set to = 1. */ 79 while (1) { 80 /* Scroll-out the next 'zsnum' of lines or until bottom. */ 81 if (current == NULL) 82 break; 83 if (sigint_flag && (!sigspecial)) 84 SIGINT_ACTION; 85 get_line(current->handle, current->len); 86 printf("%s\n", text); 87 if (current == bottom) 88 break; 89 l_cnt++; 90 if (zsnum < l_cnt) 91 break; 92 current = current->below; 93 } 94 *errnum = 1; 95 } 96