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