157704Sbostic /*-
2*60663Sbostic * Copyright (c) 1992, 1993
3*60663Sbostic * The Regents of the University of California. All rights reserved.
457704Sbostic *
557704Sbostic * This code is derived from software contributed to Berkeley by
657704Sbostic * Rodney Ruddock of the University of Guelph.
757704Sbostic *
857704Sbostic * %sccs.include.redist.c%
957704Sbostic */
1057704Sbostic
1157704Sbostic #ifndef lint
12*60663Sbostic static char sccsid[] = "@(#)z.c 8.1 (Berkeley) 05/31/93";
1357704Sbostic #endif /* not lint */
1457704Sbostic
1557710Sbostic #include <sys/types.h>
1657710Sbostic
1757710Sbostic #include <regex.h>
1857710Sbostic #include <setjmp.h>
1957710Sbostic #include <stdio.h>
2057710Sbostic #include <string.h>
2157710Sbostic
2258315Sbostic #ifdef DBI
2358315Sbostic #include <db.h>
2458315Sbostic #endif
2558315Sbostic
2657704Sbostic #include "ed.h"
2757710Sbostic #include "extern.h"
2857704Sbostic
2957704Sbostic /*
3057704Sbostic * This prints out the next group of lines (as spec'd by the skicky
3157704Sbostic * number; 22 by default). It's really useful for scrolling in chunks
3257704Sbostic * through the buffer (better than l, n, or p). Shame on POSIX for
3357704Sbostic * not including it; yaaa! BSD for keeping it! :-)
3457704Sbostic */
3557704Sbostic void
z(inputt,errnum)3657704Sbostic z(inputt, errnum)
3757710Sbostic FILE *inputt;
3857710Sbostic int *errnum;
3957704Sbostic {
4057710Sbostic register int l_cnt;
4157704Sbostic
4257710Sbostic if (current == NULL) {
4357710Sbostic *errnum = -1;
4458315Sbostic strcpy(help_msg, "buffer empty");
4557710Sbostic return;
4657710Sbostic }
4757710Sbostic /* Set zsnum if need be here. */
4857710Sbostic ss = getc(inputt);
4957710Sbostic if ((ss > 48) && (ss < 57))
5057710Sbostic /* Default set in main. */
5157710Sbostic zsnum = dig_num_conv(inputt, errnum);
5257710Sbostic else
5357710Sbostic if ((ss != '\n') && (ss != EOF)) {
5457710Sbostic ungetc(ss, inputt);
5557710Sbostic if (rol(inputt, errnum))
5657710Sbostic return;
5757710Sbostic }
5858354Sbostic if (top == NULL) {
5958315Sbostic strcpy(help_msg, "buffer empty");
6058315Sbostic *errnum = -1;
6158315Sbostic ungetc('\n', inputt);
6258315Sbostic return;
6358315Sbostic }
6457710Sbostic if (End_default) {
6557710Sbostic if ((current->below) != NULL)
6658564Sralph Start = current->below;
6757710Sbostic else {
6857710Sbostic strcpy(help_msg, "at end of buffer");
6957710Sbostic *errnum = -1;
7057710Sbostic ungetc('\n', inputt);
7157710Sbostic return;
7257710Sbostic }
7357710Sbostic } else
7458564Sralph Start = End;
7558564Sralph if (Start == NULL) {
7658354Sbostic strcpy(help_msg, "bad address");
7758354Sbostic *errnum = -1;
7858354Sbostic ungetc('\n', inputt);
7958354Sbostic return;
8058354Sbostic }
8158564Sralph Start_default = End_default = 0;
8257704Sbostic
8358564Sralph current = Start;
8457710Sbostic l_cnt = 1; /* Yes, set to = 1. */
8557710Sbostic while (1) {
8657710Sbostic /* Scroll-out the next 'zsnum' of lines or until bottom. */
8757710Sbostic if (current == NULL)
8857710Sbostic break;
8958315Sbostic if (sigint_flag && (!sigspecial))
9058315Sbostic SIGINT_ACTION;
9157710Sbostic get_line(current->handle, current->len);
9257710Sbostic printf("%s\n", text);
9357710Sbostic if (current == bottom)
9457710Sbostic break;
9557710Sbostic l_cnt++;
9657710Sbostic if (zsnum < l_cnt)
9757710Sbostic break;
9857710Sbostic current = current->below;
9957710Sbostic }
10057710Sbostic *errnum = 1;
10157710Sbostic }
102