xref: /csrg-svn/contrib/ed/l.c (revision 57692)
1*57692Sbostic /*-
2*57692Sbostic  * Copyright (c) 1992 The Regents of the University of California.
3*57692Sbostic  * All rights reserved.
4*57692Sbostic  *
5*57692Sbostic  * This code is derived from software contributed to Berkeley by
6*57692Sbostic  * Rodney Ruddock of the University of Guelph.
7*57692Sbostic  *
8*57692Sbostic  * %sccs.include.redist.c%
9*57692Sbostic  */
10*57692Sbostic 
11*57692Sbostic #ifndef lint
12*57692Sbostic static char sccsid[] = "@(#)l.c	5.1 (Berkeley) 01/23/93";
13*57692Sbostic #endif /* not lint */
14*57692Sbostic 
15*57692Sbostic #include "ed.h"
16*57692Sbostic 
17*57692Sbostic /*
18*57692Sbostic  * This is the list command. It's not wrapped in with n and p because
19*57692Sbostic  * of the unambiguous printing needed.
20*57692Sbostic  */
21*57692Sbostic 
22*57692Sbostic void
23*57692Sbostic l(inputt, errnum)
24*57692Sbostic 
25*57692Sbostic FILE *inputt;
26*57692Sbostic int *errnum;
27*57692Sbostic 
28*57692Sbostic {
29*57692Sbostic   int l_cnt, l_len=1;
30*57692Sbostic 
31*57692Sbostic   if (start_default && End_default)
32*57692Sbostic     start = End = current;
33*57692Sbostic   else if (start_default)
34*57692Sbostic     start = End;
35*57692Sbostic 
36*57692Sbostic   if (start == NULL)
37*57692Sbostic     {
38*57692Sbostic       strcpy(help_msg, "bad address");
39*57692Sbostic       *errnum = -1;
40*57692Sbostic       return;
41*57692Sbostic     }
42*57692Sbostic   start_default = End_default = 0;
43*57692Sbostic 
44*57692Sbostic   if (rol(inputt, errnum))  /* for "command-suffix pairs" */
45*57692Sbostic     return;
46*57692Sbostic 
47*57692Sbostic   current = start;
48*57692Sbostic   while (1)
49*57692Sbostic        {
50*57692Sbostic          /* print out the line character-by-character and split the line
51*57692Sbostic           * when line length is at line_length.
52*57692Sbostic           */
53*57692Sbostic          if (sigint_flag)
54*57692Sbostic            SIGINT_ACTION;
55*57692Sbostic          if (current == NULL)
56*57692Sbostic            break;
57*57692Sbostic          get_line(current->handle, current->len);
58*57692Sbostic          for (l_cnt=0; l_cnt<current->len; l_cnt++)
59*57692Sbostic             {
60*57692Sbostic               /* check if line needs to be broken first */
61*57692Sbostic               if ((l_len)%line_length == 0)
62*57692Sbostic                 putchar('\n');
63*57692Sbostic               /* print out the next character */
64*57692Sbostic               if (text[l_cnt] == '\b') /* backspace (cntl-H) */
65*57692Sbostic                 fwrite("\\b", sizeof(char), 2, stdout);
66*57692Sbostic               else if (text[l_cnt] == '\t') /* horizontal tab */
67*57692Sbostic                 fwrite("\\t", sizeof(char), 2, stdout);
68*57692Sbostic               else if (text[l_cnt] == '\n') /* newline, not that there is one */
69*57692Sbostic                 fwrite("\\n", sizeof(char), 2, stdout);
70*57692Sbostic               else if (text[l_cnt] == '\v') /* vertical tab */
71*57692Sbostic                 fwrite("\\v", sizeof(char), 2, stdout);
72*57692Sbostic               else if (text[l_cnt] == '\f') /* form feed */
73*57692Sbostic                 fwrite("\\f", sizeof(char), 2, stdout);
74*57692Sbostic               else if (text[l_cnt] == '\r') /* return */
75*57692Sbostic                 fwrite("\\r", sizeof(char), 2, stdout);
76*57692Sbostic               else if ((text[l_cnt] < 32) || (text[l_cnt] > 126)) /* not printable */
77*57692Sbostic /* 127 is del */
78*57692Sbostic                 {
79*57692Sbostic                   putchar('\\');
80*57692Sbostic                   putchar(text[l_cnt]/64+'0');
81*57692Sbostic                   putchar(text[l_cnt]/8+'0');
82*57692Sbostic                   putchar(text[l_cnt]%8+'0');
83*57692Sbostic                   l_len += 2;
84*57692Sbostic                 }
85*57692Sbostic               else if (text[l_cnt] == '\\')
86*57692Sbostic                 fwrite("\\\\", sizeof(char), 2, stdout);
87*57692Sbostic               else
88*57692Sbostic                 {
89*57692Sbostic                   l_len--;
90*57692Sbostic                   putchar(text[l_cnt]);
91*57692Sbostic                 }
92*57692Sbostic               l_len += 2;
93*57692Sbostic             }
94*57692Sbostic          l_len = 1;
95*57692Sbostic          putchar('\n');
96*57692Sbostic          if (current == End)
97*57692Sbostic            break;
98*57692Sbostic          current = current->below;
99*57692Sbostic        } /* end-while */
100*57692Sbostic 
101*57692Sbostic   *errnum = 1;
102*57692Sbostic } /* end-l */
103