xref: /csrg-svn/contrib/ed/p.c (revision 60663)
157695Sbostic /*-
2*60663Sbostic  * Copyright (c) 1992, 1993
3*60663Sbostic  *	The Regents of the University of California.  All rights reserved.
457695Sbostic  *
557695Sbostic  * This code is derived from software contributed to Berkeley by
657695Sbostic  * Rodney Ruddock of the University of Guelph.
757695Sbostic  *
857695Sbostic  * %sccs.include.redist.c%
957695Sbostic  */
1057695Sbostic 
1157695Sbostic #ifndef lint
12*60663Sbostic static char sccsid[] = "@(#)p.c	8.1 (Berkeley) 05/31/93";
1357695Sbostic #endif /* not lint */
1457695Sbostic 
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 
2657695Sbostic #include "ed.h"
2757710Sbostic #include "extern.h"
2857695Sbostic 
2957695Sbostic /*
3057695Sbostic  * Both the n and p code are here because they're almost identical.
3157695Sbostic  * Print out the line. If it's n print the line number, tab, and then
3257695Sbostic  * the line.
3357695Sbostic  */
3457695Sbostic void
p(inputt,errnum,flag)3557695Sbostic p(inputt, errnum, flag)
3657710Sbostic 	FILE *inputt;
3757710Sbostic 	int *errnum, flag;
3857695Sbostic {
3958315Sbostic 	int l_ln=0;
4057695Sbostic 
4158564Sralph 	if (Start_default && End_default)
4258564Sralph 		Start = End = current;
4357710Sbostic 	else
4458564Sralph 		if (Start_default)
4558564Sralph 			Start = End;
4658564Sralph 	Start_default = End_default = 0;
4757695Sbostic 
4858564Sralph 	if (Start == NULL) {
4958315Sbostic 		strcpy(help_msg, "buffer empty");
5057710Sbostic 		*errnum = -1;
5157710Sbostic 		return;
5257710Sbostic 	}
5357710Sbostic 	if (rol(inputt, errnum))	/* For "command-suffix pairs". */
5457710Sbostic 		return;
5557695Sbostic 
5657710Sbostic 	if (flag == 1)
5758564Sralph 		l_ln = line_number(Start);
5858564Sralph 	current = Start;
5957710Sbostic 	for (;;) {
6057710Sbostic 		/* Print out the lines. */
6157710Sbostic 		if (current == NULL)
6257710Sbostic 			break;
6357710Sbostic 		get_line(current->handle, current->len);
6458315Sbostic 		if (sigint_flag && (!sigspecial))
6558315Sbostic 			SIGINT_ACTION;
6657710Sbostic 		if (flag == 1)		/* When 'n'. */
6757710Sbostic 			printf("%d\t", l_ln++);
6857710Sbostic 		fwrite(text, sizeof(char), current->len, stdout);
6957710Sbostic 		putchar('\n');
7057710Sbostic 		if (current == End)
7157710Sbostic 			break;
7257710Sbostic 		current = current->below;
7357710Sbostic 	}
7457695Sbostic 
7557710Sbostic 	*errnum = 1;
7657710Sbostic }
77