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