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[] = "@(#)l.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 * This is the list command. It's not wrapped in with n and p because 28 * of the unambiguous printing needed. 29 */ 30 void 31 l(inputt, errnum) 32 FILE *inputt; 33 int *errnum; 34 { 35 int l_cnt, l_len = 1; 36 37 if (start_default && End_default) 38 start = End = current; 39 else 40 if (start_default) 41 start = End; 42 43 if (start == NULL) { 44 strcpy(help_msg, "bad address"); 45 *errnum = -1; 46 return; 47 } 48 start_default = End_default = 0; 49 50 if (rol(inputt, errnum)) /* For "command-suffix pairs". */ 51 return; 52 53 current = start; 54 for (;;) { 55 /* 56 * Print out the line character-by-character and split the 57 * line when line length is at line_length. 58 */ 59 if (sigint_flag) 60 SIGINT_ACTION; 61 if (current == NULL) 62 break; 63 get_line(current->handle, current->len); 64 for (l_cnt = 0; l_cnt < current->len; l_cnt++, l_len += 2) { 65 /* Check if line needs to be broken first. */ 66 if ((l_len) % line_length == 0) 67 putchar('\n'); 68 else switch (text[l_cnt]) { 69 case '\b': /* backspace (cntl-H) */ 70 fwrite("\\b", sizeof(char), 2, stdout); 71 break; 72 case '\t': /* horizontal tab */ 73 fwrite("\\t", sizeof(char), 2, stdout); 74 break; 75 case '\n': /* newline (not that there is one). */ 76 fwrite("\\n", sizeof(char), 2, stdout); 77 break; 78 case '\v': /* vertical tab */ 79 fwrite("\\v", sizeof(char), 2, stdout); 80 break; 81 case '\f': /* form feed */ 82 fwrite("\\f", sizeof(char), 2, stdout); 83 break; 84 case '\r': /* return */ 85 fwrite("\\r", sizeof(char), 2, stdout); 86 break; 87 default: 88 if ((text[l_cnt] < 32) || 89 (text[l_cnt] > 126)) { 90 putchar('\\'); 91 putchar(text[l_cnt] / 64 + '0'); 92 putchar(text[l_cnt] / 8 + '0'); 93 putchar(text[l_cnt] % 8 + '0'); 94 l_len += 2; 95 } else if (text[l_cnt] == '\\') 96 fwrite("\\\\", sizeof(char), 2, stdout); 97 else { 98 l_len--; 99 putchar(text[l_cnt]); 100 } 101 break; 102 } 103 } 104 l_len = 1; 105 putchar('\n'); 106 if (current == End) 107 break; 108 current = current->below; 109 } 110 *errnum = 1; 111 } 112