add multiple access method code back in; signal fix
[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
ecbf4ad0 12static char sccsid[] = "@(#)l.c 5.2 (Berkeley) %G%";
a4f91186
KB
13#endif /* not lint */
14
ecbf4ad0
KB
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
a4f91186 23#include "ed.h"
ecbf4ad0 24#include "extern.h"
a4f91186
KB
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 */
a4f91186
KB
30void
31l(inputt, errnum)
ecbf4ad0
KB
32 FILE *inputt;
33 int *errnum;
a4f91186 34{
ecbf4ad0 35 int l_cnt, l_len = 1;
a4f91186 36
ecbf4ad0
KB
37 if (start_default && End_default)
38 start = End = current;
39 else
40 if (start_default)
41 start = End;
a4f91186 42
ecbf4ad0
KB
43 if (start == NULL) {
44 strcpy(help_msg, "bad address");
45 *errnum = -1;
46 return;
47 }
48 start_default = End_default = 0;
a4f91186 49
ecbf4ad0
KB
50 if (rol(inputt, errnum)) /* For "command-suffix pairs". */
51 return;
a4f91186 52
ecbf4ad0
KB
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}