xref: /csrg-svn/contrib/ed/l.c (revision 58564)
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*58564Sralph static char sccsid[] = "@(#)l.c	5.5 (Berkeley) 03/08/93";
1357692Sbostic #endif /* not lint */
1457692Sbostic 
1557710Sbostic #include <sys/types.h>
1657710Sbostic 
1757710Sbostic #include <regex.h>
1857710Sbostic #include <setjmp.h>
1957710Sbostic #include <stdio.h>
2057710Sbostic #include <string.h>
2157710Sbostic 
2258315Sbostic #ifdef DBI
2358315Sbostic #include <db.h>
2458315Sbostic #endif
2558315Sbostic 
2657692Sbostic #include "ed.h"
2757710Sbostic #include "extern.h"
2857692Sbostic 
2957692Sbostic /*
3057692Sbostic  * This is the list command. It's not wrapped in with n and p because
3158357Sbostic  * of the unambiguous printing need.
3257692Sbostic  */
3357692Sbostic void
3457692Sbostic l(inputt, errnum)
3557710Sbostic 	FILE *inputt;
3657710Sbostic 	int *errnum;
3757692Sbostic {
3857710Sbostic 	int l_cnt, l_len = 1;
3957692Sbostic 
40*58564Sralph 	if (Start_default && End_default)
41*58564Sralph 		Start = End = current;
4257710Sbostic 	else
43*58564Sralph 		if (Start_default)
44*58564Sralph 			Start = End;
4557692Sbostic 
46*58564Sralph 	if (Start == NULL) {
4758315Sbostic 		strcpy(help_msg, "empty buffer");
4857710Sbostic 		*errnum = -1;
4957710Sbostic 		return;
5057710Sbostic 	}
51*58564Sralph 	Start_default = End_default = 0;
5257692Sbostic 
5357710Sbostic 	if (rol(inputt, errnum))	/* For "command-suffix pairs". */
5457710Sbostic 		return;
5557692Sbostic 
56*58564Sralph 	current = Start;
5757710Sbostic 	for (;;) {
5857710Sbostic 		/*
5957710Sbostic 		 * Print out the line character-by-character and split the
6057710Sbostic 		 * line when line length is at line_length.
6157710Sbostic 		 */
6257710Sbostic 		if (current == NULL)
6357710Sbostic 			break;
6457710Sbostic 		get_line(current->handle, current->len);
6558315Sbostic 		if (sigint_flag && (!sigspecial))
6658315Sbostic 			SIGINT_ACTION;
6757710Sbostic 		for (l_cnt = 0; l_cnt < current->len; l_cnt++, l_len += 2) {
6857710Sbostic 			/* Check if line needs to be broken first. */
6957710Sbostic 			if ((l_len) % line_length == 0)
7057710Sbostic 				putchar('\n');
7157710Sbostic 			else switch (text[l_cnt]) {
7257710Sbostic 			case '\b':	/* backspace (cntl-H) */
7357710Sbostic 				fwrite("\\b", sizeof(char), 2, stdout);
7457710Sbostic 				break;
7557710Sbostic 			case '\t':	/* horizontal tab */
7657710Sbostic 				fwrite("\\t", sizeof(char), 2, stdout);
7757710Sbostic 				break;
7857710Sbostic 			case '\n':	/* newline (not that there is one). */
7957710Sbostic 				fwrite("\\n", sizeof(char), 2, stdout);
8057710Sbostic 				break;
8157710Sbostic 			case '\v':	/* vertical tab */
8257710Sbostic 				fwrite("\\v", sizeof(char), 2, stdout);
8357710Sbostic 				break;
8457710Sbostic 			case '\f':	/* form feed */
8557710Sbostic 				fwrite("\\f", sizeof(char), 2, stdout);
8657710Sbostic 				break;
8757710Sbostic 			case '\r':	/* return */
8857710Sbostic 				fwrite("\\r", sizeof(char), 2, stdout);
8957710Sbostic 				break;
9057710Sbostic 			default:
9157710Sbostic 				if ((text[l_cnt] < 32) ||
9257710Sbostic 				    (text[l_cnt] > 126)) {
9357710Sbostic 					putchar('\\');
9457710Sbostic 					putchar(text[l_cnt] / 64 + '0');
9557710Sbostic 					putchar(text[l_cnt] / 8 + '0');
9657710Sbostic 					putchar(text[l_cnt] % 8 + '0');
9757710Sbostic 					l_len += 2;
9857710Sbostic 				} else if (text[l_cnt] == '\\')
9957710Sbostic 					fwrite("\\\\", sizeof(char), 2, stdout);
10057710Sbostic 				else {
10157710Sbostic 					l_len--;
10257710Sbostic 					putchar(text[l_cnt]);
10357710Sbostic 				}
10457710Sbostic 				break;
10557710Sbostic 			}
10657710Sbostic 		}
10757710Sbostic 		l_len = 1;
10857710Sbostic 		putchar('\n');
10957710Sbostic 		if (current == End)
11057710Sbostic 			break;
11157710Sbostic 		current = current->below;
11257710Sbostic 	}
11357710Sbostic 	*errnum = 1;
11457710Sbostic }
115