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