Commit | Line | Data |
---|---|---|
ade104e4 KB |
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 | |
e692f66f | 12 | static char sccsid[] = "@(#)p.c 5.3 (Berkeley) %G%"; |
ade104e4 KB |
13 | #endif /* not lint */ |
14 | ||
ecbf4ad0 KB |
15 | #include <sys/types.h> |
16 | ||
ecbf4ad0 KB |
17 | #include <regex.h> |
18 | #include <setjmp.h> | |
19 | #include <stdio.h> | |
20 | #include <string.h> | |
21 | ||
e692f66f KB |
22 | #ifdef DBI |
23 | #include <db.h> | |
24 | #endif | |
25 | ||
ade104e4 | 26 | #include "ed.h" |
ecbf4ad0 | 27 | #include "extern.h" |
ade104e4 KB |
28 | |
29 | /* | |
30 | * Both the n and p code are here because they're almost identical. | |
31 | * Print out the line. If it's n print the line number, tab, and then | |
32 | * the line. | |
33 | */ | |
ade104e4 KB |
34 | void |
35 | p(inputt, errnum, flag) | |
ecbf4ad0 KB |
36 | FILE *inputt; |
37 | int *errnum, flag; | |
ade104e4 | 38 | { |
e692f66f | 39 | int l_ln=0; |
ade104e4 | 40 | |
ecbf4ad0 KB |
41 | if (start_default && End_default) |
42 | start = End = current; | |
43 | else | |
44 | if (start_default) | |
45 | start = End; | |
46 | start_default = End_default = 0; | |
ade104e4 | 47 | |
ecbf4ad0 | 48 | if (start == NULL) { |
e692f66f | 49 | strcpy(help_msg, "buffer empty"); |
ecbf4ad0 KB |
50 | *errnum = -1; |
51 | return; | |
52 | } | |
53 | if (rol(inputt, errnum)) /* For "command-suffix pairs". */ | |
54 | return; | |
ade104e4 | 55 | |
ecbf4ad0 KB |
56 | if (flag == 1) |
57 | l_ln = line_number(start); | |
ecbf4ad0 KB |
58 | current = start; |
59 | for (;;) { | |
60 | /* Print out the lines. */ | |
ecbf4ad0 KB |
61 | if (current == NULL) |
62 | break; | |
63 | get_line(current->handle, current->len); | |
e692f66f KB |
64 | if (sigint_flag && (!sigspecial)) |
65 | SIGINT_ACTION; | |
ecbf4ad0 KB |
66 | if (flag == 1) /* When 'n'. */ |
67 | printf("%d\t", l_ln++); | |
68 | fwrite(text, sizeof(char), current->len, stdout); | |
69 | putchar('\n'); | |
70 | if (current == End) | |
71 | break; | |
72 | current = current->below; | |
73 | } | |
ade104e4 | 74 | |
ecbf4ad0 KB |
75 | *errnum = 1; |
76 | } |