typo
[unix-history] / usr / src / contrib / ed / l.c
CommitLineData
a4f91186
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
0be5e048 12static char sccsid[] = "@(#)l.c 5.4 (Berkeley) %G%";
a4f91186
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
a4f91186 26#include "ed.h"
ecbf4ad0 27#include "extern.h"
a4f91186
KB
28
29/*
30 * This is the list command. It's not wrapped in with n and p because
0be5e048 31 * of the unambiguous printing need.
a4f91186 32 */
a4f91186
KB
33void
34l(inputt, errnum)
ecbf4ad0
KB
35 FILE *inputt;
36 int *errnum;
a4f91186 37{
ecbf4ad0 38 int l_cnt, l_len = 1;
a4f91186 39
ecbf4ad0
KB
40 if (start_default && End_default)
41 start = End = current;
42 else
43 if (start_default)
44 start = End;
a4f91186 45
ecbf4ad0 46 if (start == NULL) {
e692f66f 47 strcpy(help_msg, "empty buffer");
ecbf4ad0
KB
48 *errnum = -1;
49 return;
50 }
51 start_default = End_default = 0;
a4f91186 52
ecbf4ad0
KB
53 if (rol(inputt, errnum)) /* For "command-suffix pairs". */
54 return;
a4f91186 55
ecbf4ad0
KB
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 */
ecbf4ad0
KB
62 if (current == NULL)
63 break;
64 get_line(current->handle, current->len);
e692f66f
KB
65 if (sigint_flag && (!sigspecial))
66 SIGINT_ACTION;
ecbf4ad0
KB
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 == 0)
70 putchar('\n');
71 else switch (text[l_cnt]) {
72 case '\b': /* backspace (cntl-H) */
73 fwrite("\\b", sizeof(char), 2, stdout);
74 break;
75 case '\t': /* horizontal tab */
76 fwrite("\\t", sizeof(char), 2, stdout);
77 break;
78 case '\n': /* newline (not that there is one). */
79 fwrite("\\n", sizeof(char), 2, stdout);
80 break;
81 case '\v': /* vertical tab */
82 fwrite("\\v", sizeof(char), 2, stdout);
83 break;
84 case '\f': /* form feed */
85 fwrite("\\f", sizeof(char), 2, stdout);
86 break;
87 case '\r': /* return */
88 fwrite("\\r", sizeof(char), 2, stdout);
89 break;
90 default:
91 if ((text[l_cnt] < 32) ||
92 (text[l_cnt] > 126)) {
93 putchar('\\');
94 putchar(text[l_cnt] / 64 + '0');
95 putchar(text[l_cnt] / 8 + '0');
96 putchar(text[l_cnt] % 8 + '0');
97 l_len += 2;
98 } else if (text[l_cnt] == '\\')
99 fwrite("\\\\", sizeof(char), 2, stdout);
100 else {
101 l_len--;
102 putchar(text[l_cnt]);
103 }
104 break;
105 }
106 }
107 l_len = 1;
108 putchar('\n');
109 if (current == End)
110 break;
111 current = current->below;
112 }
113 *errnum = 1;
114}