2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
9 static char sccsid
[] = "$Id: ex_print.c,v 8.6 1993/11/02 18:46:49 bostic Exp $ (Berkeley) $Date: 1993/11/02 18:46:49 $";
12 #include <sys/types.h>
21 * ex_list -- :[line [,line]] l[ist] [count] [flags]
23 * Display the addressed lines such that the output is unambiguous.
32 &cmdp
->addr1
, &cmdp
->addr2
, cmdp
->flags
| E_F_LIST
))
34 sp
->lno
= cmdp
->addr2
.lno
;
35 sp
->cno
= cmdp
->addr2
.cno
;
40 * ex_number -- :[line [,line]] nu[mber] [count] [flags]
42 * Display the addressed lines with a leading line number.
45 ex_number(sp
, ep
, cmdp
)
51 &cmdp
->addr1
, &cmdp
->addr2
, cmdp
->flags
| E_F_HASH
))
53 sp
->lno
= cmdp
->addr2
.lno
;
54 sp
->cno
= cmdp
->addr2
.cno
;
59 * ex_pr -- :[line [,line]] p[rint] [count] [flags]
61 * Display the addressed lines.
69 if (ex_print(sp
, ep
, &cmdp
->addr1
, &cmdp
->addr2
, cmdp
->flags
))
71 sp
->lno
= cmdp
->addr2
.lno
;
72 sp
->cno
= cmdp
->addr2
.cno
;
78 * Print the selected lines.
81 ex_print(sp
, ep
, fp
, tp
, flags
)
87 register int ch
, col
, rlen
;
93 F_SET(sp
, S_INTERRUPTIBLE
);
94 for (from
= fp
->lno
, to
= tp
->lno
; from
<= to
; ++from
) {
95 /* Display the line number. */
96 if (LF_ISSET(E_F_HASH
))
97 col
= ex_printf(EXCOOKIE
, "%7ld ", from
);
102 * Display the line. The format for E_F_PRINT isn't very good,
103 * especially in handling end-of-line tabs, but they're almost
104 * backward compatible.
106 if ((p
= file_gline(sp
, ep
, from
, &len
)) == NULL
) {
107 GETLINE_ERR(sp
, from
);
111 #define WCHECK(ch) { \
112 if (col == sp->cols) { \
113 (void)ex_printf(EXCOOKIE, "\n"); \
116 (void)ex_printf(EXCOOKIE, "%c", ch); \
119 for (rlen
= len
; rlen
--;) {
121 if (LF_ISSET(E_F_LIST
))
122 if (ch
!= '\t' && isprint(ch
)) {
124 } else if (ch
& 0x80) {
126 sizeof(buf
), "\\%03o", ch
);
128 for (cnt
= 0; cnt
< len
; ++cnt
)
137 while (col
< sp
->cols
&&
138 ++col
% O_VAL(sp
, O_TABSTOP
))
139 (void)ex_printf(EXCOOKIE
, " ");
140 if (col
== sp
->cols
) {
142 (void)ex_printf(EXCOOKIE
, "\n");
144 } else if (isprint(ch
)) {
146 } else if (ch
== '\n') {
148 (void)ex_printf(EXCOOKIE
, "\n");
155 if (LF_ISSET(E_F_LIST
)) {
157 } else if (len
== 0) {
159 * If the line is empty, output a space
160 * to overwrite the colon prompt.
164 (void)ex_printf(EXCOOKIE
, "\n");
166 if (F_ISSET(sp
, S_INTERRUPTED
))