1 /*- 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. 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 8.1 (Berkeley) 05/31/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 * 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 */ 34 void 35 p(inputt, errnum, flag) 36 FILE *inputt; 37 int *errnum, flag; 38 { 39 int l_ln=0; 40 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; 47 48 if (Start == NULL) { 49 strcpy(help_msg, "buffer empty"); 50 *errnum = -1; 51 return; 52 } 53 if (rol(inputt, errnum)) /* For "command-suffix pairs". */ 54 return; 55 56 if (flag == 1) 57 l_ln = line_number(Start); 58 current = Start; 59 for (;;) { 60 /* Print out the lines. */ 61 if (current == NULL) 62 break; 63 get_line(current->handle, current->len); 64 if (sigint_flag && (!sigspecial)) 65 SIGINT_ACTION; 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 } 74 75 *errnum = 1; 76 } 77