xref: /original-bsd/contrib/ed/p.c (revision 052d6878)
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[] = "@(#)p.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  * Both the n and p code are here because they're almost identical.
28  * Print out the line. If it's n print the line number, tab, and then
29  * the line.
30  */
31 void
32 p(inputt, errnum, flag)
33 	FILE *inputt;
34 	int *errnum, flag;
35 {
36 	int l_ln;
37 
38 	if (start_default && End_default)
39 		start = End = current;
40 	else
41 		if (start_default)
42 			start = End;
43 	start_default = End_default = 0;
44 
45 	if (start == NULL) {
46 		strcpy(help_msg, "bad address");
47 		*errnum = -1;
48 		return;
49 	}
50 	if (rol(inputt, errnum))	/* For "command-suffix pairs". */
51 		return;
52 
53 	if (flag == 1)
54 		l_ln = line_number(start);
55 	if (sigint_flag)
56 		SIGINT_ACTION;
57 	current = start;
58 	for (;;) {
59 		/* Print out the lines. */
60 		if (sigint_flag)
61 			SIGINT_ACTION;
62 		if (current == NULL)
63 			break;
64 		get_line(current->handle, current->len);
65 		if (flag == 1)		/* When 'n'. */
66 			printf("%d\t", l_ln++);
67 		fwrite(text, sizeof(char), current->len, stdout);
68 		putchar('\n');
69 		if (current == End)
70 			break;
71 		current = current->below;
72 	}
73 
74 	*errnum = 1;
75 }
76