-> 1.03
[nvi.git] / vi / v_put.c
blob97187dd7a9b127627132446bbf832710b4c0dd47
1 /*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
6 */
8 #ifndef lint
9 static char sccsid[] = "$Id: v_put.c,v 8.6 1994/01/09 14:21:13 bostic Exp $ (Berkeley) $Date: 1994/01/09 14:21:13 $";
10 #endif /* not lint */
12 #include <sys/types.h>
14 #include "vi.h"
15 #include "vcmd.h"
17 static void inc_buf __P((SCR *, VICMDARG *));
20 * v_Put -- [buffer]P
21 * Insert the contents of the buffer before the cursor.
23 int
24 v_Put(sp, ep, vp, fm, tm, rp)
25 SCR *sp;
26 EXF *ep;
27 VICMDARG *vp;
28 MARK *fm, *tm, *rp;
30 if (F_ISSET(vp, VC_ISDOT))
31 inc_buf(sp, vp);
32 return (put(sp, ep,
33 NULL, F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL, fm, rp, 0));
37 * v_put -- [buffer]p
38 * Insert the contents of the buffer after the cursor.
40 int
41 v_put(sp, ep, vp, fm, tm, rp)
42 SCR *sp;
43 EXF *ep;
44 VICMDARG *vp;
45 MARK *fm, *tm, *rp;
47 if (F_ISSET(vp, VC_ISDOT))
48 inc_buf(sp, vp);
50 return (put(sp, ep,
51 NULL, F_ISSET(vp, VC_BUFFER) ? &vp->buffer : NULL, fm, rp, 1));
55 * Historical whackadoo. The dot command `puts' the numbered buffer
56 * after the last one put. For example, `"4p.' would put buffer #4
57 * and buffer #5. If the user continued to enter '.', the #9 buffer
58 * would be repeatedly output. This was not documented, and is a bit
59 * tricky to reconstruct. Historical versions of vi also dropped the
60 * contents of the default buffer after each put, so after `"4p' the
61 * default buffer would be empty. This makes no sense to me, so we
62 * don't bother. Don't assume sequential order of numeric characters.
64 * And, if that weren't exciting enough, failed commands don't normally
65 * set the dot command. Well, boys and girls, an exception is that
66 * the buffer increment gets done regardless of the success of the put.
68 static void
69 inc_buf(sp, vp)
70 SCR *sp;
71 VICMDARG *vp;
73 CHAR_T v;
75 switch (vp->buffer) {
76 case '1':
77 v = '2';
78 break;
79 case '2':
80 v = '3';
81 break;
82 case '3':
83 v = '4';
84 break;
85 case '4':
86 v = '5';
87 break;
88 case '5':
89 v = '6';
90 break;
91 case '6':
92 v = '7';
93 break;
94 case '7':
95 v = '8';
96 break;
97 case '8':
98 v = '9';
99 break;
100 default:
101 return;
103 VIP(sp)->sdot.buffer = vp->buffer = v;