Sync usage with man page.
[netbsd-mini2440.git] / dist / nvi / motif_l / m_copypaste.c
blob787b90350c92b57e941371f8168736dde90bdb6f
1 /* $NetBSD$ */
3 /*-
4 * Copyright (c) 1996
5 * Rob Zimmermann. All rights reserved.
6 * Copyright (c) 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: m_copypaste.c,v 8.10 2003/11/05 17:09:59 skimo Exp (Berkeley) Date: 2003/11/05 17:09:59";
16 #endif /* not lint */
18 /* ICCCM Cut and paste Utilities: */
20 #include <sys/types.h>
21 #include <sys/queue.h>
23 #include <X11/X.h>
24 #include <X11/Intrinsic.h>
25 #include <X11/Xatom.h>
27 #include <bitstring.h>
28 #include <stdio.h>
30 #undef LOCK_SUCCESS
31 #include "../common/common.h"
32 #include "../ipc/ip.h"
33 #include "m_motif.h"
35 typedef int (*PFI)();
37 static PFI icccm_paste,
38 icccm_copy,
39 icccm_clear,
40 icccm_error;
43 * InitCopyPaste --
45 * PUBLIC: void __vi_InitCopyPaste
46 * PUBLIC: __P((int (*)(), int (*)(), int (*)(), int (*)()));
48 void
49 __vi_InitCopyPaste(PFI f_copy, PFI f_paste, PFI f_clear, PFI f_error)
51 icccm_paste = f_paste;
52 icccm_clear = f_clear;
53 icccm_copy = f_copy;
54 icccm_error = f_error;
58 #if defined(__STDC__)
59 static void peekProc( Widget widget,
60 void *data,
61 Atom *selection,
62 Atom *type,
63 void *value,
64 unsigned long *length,
65 int *format
67 #else
68 static void peekProc( widget, data, selection, type, value, length, format )
69 Widget widget;
70 void *data;
71 Atom *selection, *type;
72 void *value;
73 unsigned long *length;
74 int *format;
75 #endif
77 if ( *type == 0 )
78 (*icccm_error)( stderr, "Nothing in the primary selection buffer");
79 else if ( *type != XA_STRING )
80 (*icccm_error)( stderr, "Unknown type return from selection");
81 else
82 XtFree( value );
86 #if 0
87 #if defined(__STDC__)
88 void _vi_AcquireClipboard( Widget wid )
89 #else
90 void _vi_AcquireClipboard( wid )
91 Widget wid;
92 #endif
94 XtGetSelectionValue( wid,
95 XA_PRIMARY,
96 XA_STRING,
97 (XtSelectionCallbackProc) peekProc,
98 NULL,
99 XtLastTimestampProcessed( XtDisplay(wid) )
102 #endif
105 #if defined(__STDC__)
106 static void loseProc( Widget widget )
107 #else
108 static void loseProc( widget )
109 Widget widget;
110 #endif
112 /* we have lost ownership of the selection. clear it */
113 (*icccm_clear)( widget );
115 /* also participate in the protocols */
116 XtDisownSelection( widget,
117 XA_PRIMARY,
118 XtLastTimestampProcessed( XtDisplay(widget) )
123 #if defined(__STDC__)
124 static int convertProc( Widget widget,
125 Atom *selection,
126 Atom *target,
127 Atom *type,
128 void **value,
129 int *length,
130 int *format
132 #else
133 static int convertProc( widget, selection, target, type, value, length, format )
134 Widget widget;
135 Atom *selection, *target, *type;
136 void **value;
137 int *length;
138 int *format;
139 #endif
141 String buffer;
142 int len;
144 /* someone wants a copy of the selection. is there one? */
145 (*icccm_copy)( &buffer, &len );
146 if ( len == 0 ) return False;
148 /* do they want the string? */
149 if ( *target == XA_STRING ) {
150 *length = len;
151 *value = (void *) XtMalloc( len );
152 *type = XA_STRING;
153 *format = 8;
154 memcpy( (char *) *value, buffer, *length );
155 return True;
158 /* do they want the length? */
159 if ( *target == XInternAtom( XtDisplay(widget), "LENGTH", FALSE) ) {
160 *length = 1;
161 *value = (void *) XtMalloc( sizeof(int) );
162 *type = *target;
163 *format = 32;
164 * ((int *) *value) = len;
165 return True;
168 /* we lose */
169 return False;
173 * __vi_AcquirePrimary --
175 * PUBLIC: void __vi_AcquirePrimary __P((Widget));
177 void
178 __vi_AcquirePrimary(Widget widget)
180 /* assert we own the primary selection */
181 XtOwnSelection( widget,
182 XA_PRIMARY,
183 XtLastTimestampProcessed( XtDisplay(widget) ),
184 (XtConvertSelectionProc) convertProc,
185 (XtLoseSelectionProc) loseProc,
186 NULL
189 #if defined(OPENLOOK)
190 /* assert we also own the clipboard */
191 XtOwnSelection( widget,
192 XA_CLIPBOARD( XtDisplay(widget) ),
193 XtLastTimestampProcessed( XtDisplay(widget) ),
194 convertProc,
195 loseProc,
196 NULL
198 #endif
202 #if defined(__STDC__)
203 static void gotProc( Widget widget,
204 void *data,
205 Atom *selection,
206 Atom *type,
207 void *value,
208 unsigned long *length,
209 int *format
211 #else
212 static void gotProc( widget, data, selection, type, value, length, format )
213 Widget widget;
214 void *data;
215 Atom *selection, *type;
216 void *value;
217 unsigned long *length;
218 int *format;
219 #endif
221 if ( *type == 0 )
222 (*icccm_error)( stderr, "Nothing in the primary selection buffer");
223 else if ( *type != XA_STRING )
224 (*icccm_error)( stderr, "Unknown type return from selection");
225 else {
226 (*icccm_paste)( widget, value, *length );
227 XtFree( value );
232 * __vi_PasteFromClipboard --
234 * PUBLIC: void __vi_PasteFromClipboard __P((Widget));
236 void
237 __vi_PasteFromClipboard(Widget widget)
239 XtGetSelectionValue( widget,
240 XA_PRIMARY,
241 XA_STRING,
242 (XtSelectionCallbackProc) gotProc,
243 NULL,
244 XtLastTimestampProcessed( XtDisplay(widget) )