Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / nvi / vi / v_put.c
blob8bcc2be6901b1a0535b904b10751d51120d343d5
1 /* $NetBSD$ */
3 /*-
4 * Copyright (c) 1992, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (c) 1992, 1993, 1994, 1995, 1996
7 * Keith Bostic. All rights reserved.
9 * See the LICENSE file for redistribution information.
12 #include "config.h"
14 #ifndef lint
15 static const char sccsid[] = "Id: v_put.c,v 10.6 2001/06/25 15:19:34 skimo Exp (Berkeley) Date: 2001/06/25 15:19:34";
16 #endif /* not lint */
18 #include <sys/types.h>
19 #include <sys/queue.h>
20 #include <sys/time.h>
22 #include <bitstring.h>
23 #include <limits.h>
24 #include <stdio.h>
26 #include "../common/common.h"
27 #include "vi.h"
29 static void inc_buf __P((SCR *, VICMD *));
32 * v_Put -- [buffer]P
33 * Insert the contents of the buffer before the cursor.
35 * PUBLIC: int v_Put __P((SCR *, VICMD *));
37 int
38 v_Put(SCR *sp, VICMD *vp)
40 u_long cnt;
42 if (F_ISSET(vp, VC_ISDOT))
43 inc_buf(sp, vp);
46 * !!!
47 * Historic vi did not support a count with the 'p' and 'P'
48 * commands. It's useful, so we do.
50 for (cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt--;) {
51 if (put(sp, NULL,
52 F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
53 &vp->m_start, &vp->m_final, 0))
54 return (1);
55 vp->m_start = vp->m_final;
56 if (INTERRUPTED(sp))
57 return (1);
59 return (0);
63 * v_put -- [buffer]p
64 * Insert the contents of the buffer after the cursor.
66 * PUBLIC: int v_put __P((SCR *, VICMD *));
68 int
69 v_put(SCR *sp, VICMD *vp)
71 u_long cnt;
73 if (F_ISSET(vp, VC_ISDOT))
74 inc_buf(sp, vp);
77 * !!!
78 * Historic vi did not support a count with the 'p' and 'P'
79 * commands. It's useful, so we do.
81 for (cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1; cnt--;) {
82 if (put(sp, NULL,
83 F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL,
84 &vp->m_start, &vp->m_final, 1))
85 return (1);
86 vp->m_start = vp->m_final;
87 if (INTERRUPTED(sp))
88 return (1);
90 return (0);
94 * !!!
95 * Historical whackadoo. The dot command `puts' the numbered buffer
96 * after the last one put. For example, `"4p.' would put buffer #4
97 * and buffer #5. If the user continued to enter '.', the #9 buffer
98 * would be repeatedly output. This was not documented, and is a bit
99 * tricky to reconstruct. Historical versions of vi also dropped the
100 * contents of the default buffer after each put, so after `"4p' the
101 * default buffer would be empty. This makes no sense to me, so we
102 * don't bother. Don't assume sequential order of numeric characters.
104 * And, if that weren't exciting enough, failed commands don't normally
105 * set the dot command. Well, boys and girls, an exception is that
106 * the buffer increment gets done regardless of the success of the put.
108 static void
109 inc_buf(SCR *sp, VICMD *vp)
111 CHAR_T v;
113 switch (vp->buffer) {
114 case '1':
115 v = '2';
116 break;
117 case '2':
118 v = '3';
119 break;
120 case '3':
121 v = '4';
122 break;
123 case '4':
124 v = '5';
125 break;
126 case '5':
127 v = '6';
128 break;
129 case '6':
130 v = '7';
131 break;
132 case '7':
133 v = '8';
134 break;
135 case '8':
136 v = '9';
137 break;
138 default:
139 return;
141 VIP(sp)->sdot.buffer = vp->buffer = v;