xref: /csrg-svn/contrib/ed/l.c (revision 60663)
157692Sbostic /*-
2*60663Sbostic  * Copyright (c) 1992, 1993
3*60663Sbostic  *	The Regents of the University of California.  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*60663Sbostic static char sccsid[] = "@(#)l.c	8.1 (Berkeley) 05/31/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
l(inputt,errnum)3457692Sbostic l(inputt, errnum)
3557710Sbostic 	FILE *inputt;
3657710Sbostic 	int *errnum;
3757692Sbostic {
3857710Sbostic 	int l_cnt, l_len = 1;
3957692Sbostic 
4058564Sralph 	if (Start_default && End_default)
4158564Sralph 		Start = End = current;
4257710Sbostic 	else
4358564Sralph 		if (Start_default)
4458564Sralph 			Start = End;
4557692Sbostic 
4658564Sralph 	if (Start == NULL) {
4758315Sbostic 		strcpy(help_msg, "empty buffer");
4857710Sbostic 		*errnum = -1;
4957710Sbostic 		return;
5057710Sbostic 	}
5158564Sralph 	Start_default = End_default = 0;
5257692Sbostic 
5357710Sbostic 	if (rol(inputt, errnum))	/* For "command-suffix pairs". */
5457710Sbostic 		return;
5557692Sbostic 
5658564Sralph 	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. */
6960656Sbostic 			if (l_len > line_length) {
7057710Sbostic 				putchar('\n');
7160656Sbostic 				l_len = 0;
7260656Sbostic 			}
7357710Sbostic 			else switch (text[l_cnt]) {
7457710Sbostic 			case '\b':	/* backspace (cntl-H) */
7557710Sbostic 				fwrite("\\b", sizeof(char), 2, stdout);
7657710Sbostic 				break;
7757710Sbostic 			case '\t':	/* horizontal tab */
7857710Sbostic 				fwrite("\\t", sizeof(char), 2, stdout);
7957710Sbostic 				break;
8057710Sbostic 			case '\n':	/* newline (not that there is one). */
8157710Sbostic 				fwrite("\\n", sizeof(char), 2, stdout);
8257710Sbostic 				break;
8357710Sbostic 			case '\v':	/* vertical tab */
8457710Sbostic 				fwrite("\\v", sizeof(char), 2, stdout);
8557710Sbostic 				break;
8657710Sbostic 			case '\f':	/* form feed */
8757710Sbostic 				fwrite("\\f", sizeof(char), 2, stdout);
8857710Sbostic 				break;
8957710Sbostic 			case '\r':	/* return */
9057710Sbostic 				fwrite("\\r", sizeof(char), 2, stdout);
9157710Sbostic 				break;
9257710Sbostic 			default:
9357710Sbostic 				if ((text[l_cnt] < 32) ||
9457710Sbostic 				    (text[l_cnt] > 126)) {
9557710Sbostic 					putchar('\\');
9660656Sbostic 					putchar(((text[l_cnt] & 0xC0) >> 6)
9760656Sbostic 					    + '0');
9860656Sbostic 					putchar(((text[l_cnt] & 0x38) >> 3)
9960656Sbostic 					    + '0');
10060656Sbostic 					putchar((text[l_cnt] & 0x07) + '0');
10157710Sbostic 					l_len += 2;
10257710Sbostic 				} else if (text[l_cnt] == '\\')
10357710Sbostic 					fwrite("\\\\", sizeof(char), 2, stdout);
10457710Sbostic 				else {
10557710Sbostic 					l_len--;
10657710Sbostic 					putchar(text[l_cnt]);
10757710Sbostic 				}
10857710Sbostic 				break;
10957710Sbostic 			}
11057710Sbostic 		}
11157710Sbostic 		l_len = 1;
11257710Sbostic 		putchar('\n');
11357710Sbostic 		if (current == End)
11457710Sbostic 			break;
11557710Sbostic 		current = current->below;
11657710Sbostic 	}
11757710Sbostic 	*errnum = 1;
11857710Sbostic }
119