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