xref: /csrg-svn/contrib/ed/l.c (revision 57710)
157692Sbostic /*-
257692Sbostic  * Copyright (c) 1992 The Regents of the University of California.
357692Sbostic  * All rights reserved.
457692Sbostic  *
557692Sbostic  * This code is derived from software contributed to Berkeley by
657692Sbostic  * Rodney Ruddock of the University of Guelph.
757692Sbostic  *
857692Sbostic  * %sccs.include.redist.c%
957692Sbostic  */
1057692Sbostic 
1157692Sbostic #ifndef lint
12*57710Sbostic static char sccsid[] = "@(#)l.c	5.2 (Berkeley) 01/23/93";
1357692Sbostic #endif /* not lint */
1457692Sbostic 
15*57710Sbostic #include <sys/types.h>
16*57710Sbostic 
17*57710Sbostic #include <db.h>
18*57710Sbostic #include <regex.h>
19*57710Sbostic #include <setjmp.h>
20*57710Sbostic #include <stdio.h>
21*57710Sbostic #include <string.h>
22*57710Sbostic 
2357692Sbostic #include "ed.h"
24*57710Sbostic #include "extern.h"
2557692Sbostic 
2657692Sbostic /*
2757692Sbostic  * This is the list command. It's not wrapped in with n and p because
2857692Sbostic  * of the unambiguous printing needed.
2957692Sbostic  */
3057692Sbostic void
3157692Sbostic l(inputt, errnum)
32*57710Sbostic 	FILE *inputt;
33*57710Sbostic 	int *errnum;
3457692Sbostic {
35*57710Sbostic 	int l_cnt, l_len = 1;
3657692Sbostic 
37*57710Sbostic 	if (start_default && End_default)
38*57710Sbostic 		start = End = current;
39*57710Sbostic 	else
40*57710Sbostic 		if (start_default)
41*57710Sbostic 			start = End;
4257692Sbostic 
43*57710Sbostic 	if (start == NULL) {
44*57710Sbostic 		strcpy(help_msg, "bad address");
45*57710Sbostic 		*errnum = -1;
46*57710Sbostic 		return;
47*57710Sbostic 	}
48*57710Sbostic 	start_default = End_default = 0;
4957692Sbostic 
50*57710Sbostic 	if (rol(inputt, errnum))	/* For "command-suffix pairs". */
51*57710Sbostic 		return;
5257692Sbostic 
53*57710Sbostic 	current = start;
54*57710Sbostic 	for (;;) {
55*57710Sbostic 		/*
56*57710Sbostic 		 * Print out the line character-by-character and split the
57*57710Sbostic 		 * line when line length is at line_length.
58*57710Sbostic 		 */
59*57710Sbostic 		if (sigint_flag)
60*57710Sbostic 			SIGINT_ACTION;
61*57710Sbostic 		if (current == NULL)
62*57710Sbostic 			break;
63*57710Sbostic 		get_line(current->handle, current->len);
64*57710Sbostic 		for (l_cnt = 0; l_cnt < current->len; l_cnt++, l_len += 2) {
65*57710Sbostic 			/* Check if line needs to be broken first. */
66*57710Sbostic 			if ((l_len) % line_length == 0)
67*57710Sbostic 				putchar('\n');
68*57710Sbostic 			else switch (text[l_cnt]) {
69*57710Sbostic 			case '\b':	/* backspace (cntl-H) */
70*57710Sbostic 				fwrite("\\b", sizeof(char), 2, stdout);
71*57710Sbostic 				break;
72*57710Sbostic 			case '\t':	/* horizontal tab */
73*57710Sbostic 				fwrite("\\t", sizeof(char), 2, stdout);
74*57710Sbostic 				break;
75*57710Sbostic 			case '\n':	/* newline (not that there is one). */
76*57710Sbostic 				fwrite("\\n", sizeof(char), 2, stdout);
77*57710Sbostic 				break;
78*57710Sbostic 			case '\v':	/* vertical tab */
79*57710Sbostic 				fwrite("\\v", sizeof(char), 2, stdout);
80*57710Sbostic 				break;
81*57710Sbostic 			case '\f':	/* form feed */
82*57710Sbostic 				fwrite("\\f", sizeof(char), 2, stdout);
83*57710Sbostic 				break;
84*57710Sbostic 			case '\r':	/* return */
85*57710Sbostic 				fwrite("\\r", sizeof(char), 2, stdout);
86*57710Sbostic 				break;
87*57710Sbostic 			default:
88*57710Sbostic 				if ((text[l_cnt] < 32) ||
89*57710Sbostic 				    (text[l_cnt] > 126)) {
90*57710Sbostic 					putchar('\\');
91*57710Sbostic 					putchar(text[l_cnt] / 64 + '0');
92*57710Sbostic 					putchar(text[l_cnt] / 8 + '0');
93*57710Sbostic 					putchar(text[l_cnt] % 8 + '0');
94*57710Sbostic 					l_len += 2;
95*57710Sbostic 				} else if (text[l_cnt] == '\\')
96*57710Sbostic 					fwrite("\\\\", sizeof(char), 2, stdout);
97*57710Sbostic 				else {
98*57710Sbostic 					l_len--;
99*57710Sbostic 					putchar(text[l_cnt]);
100*57710Sbostic 				}
101*57710Sbostic 				break;
102*57710Sbostic 			}
103*57710Sbostic 		}
104*57710Sbostic 		l_len = 1;
105*57710Sbostic 		putchar('\n');
106*57710Sbostic 		if (current == End)
107*57710Sbostic 			break;
108*57710Sbostic 		current = current->below;
109*57710Sbostic 	}
110*57710Sbostic 	*errnum = 1;
111*57710Sbostic }
112