ignore errors on making txt and html output
[nvi.git] / motif_l / m_copypaste.c
bloba42a1c0dfd46da1cf3baf4617d2b210ee72049b9
1 /*-
2 * Copyright (c) 1996
3 * Rob Zimmermann. All rights reserved.
4 * Copyright (c) 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 static const char sccsid[] = "$Id: m_copypaste.c,v 8.9 2001/06/25 15:19:26 skimo Exp $ (Berkeley) $Date: 2001/06/25 15:19:26 $";
14 #endif /* not lint */
16 /* ICCCM Cut and paste Utilities: */
18 #include <sys/types.h>
19 #include <sys/queue.h>
21 #include <X11/X.h>
22 #include <X11/Intrinsic.h>
23 #include <X11/Xatom.h>
25 #include <bitstring.h>
26 #include <stdio.h>
28 #include "../common/common.h"
29 #include "../ipc/ip.h"
30 #include "m_motif.h"
32 typedef int (*PFI)();
34 static PFI icccm_paste,
35 icccm_copy,
36 icccm_clear,
37 icccm_error;
40 * InitCopyPaste --
42 * PUBLIC: void __vi_InitCopyPaste
43 * PUBLIC: __P((int (*)(), int (*)(), int (*)(), int (*)()));
45 void
46 __vi_InitCopyPaste(PFI f_copy, PFI f_paste, PFI f_clear, PFI f_error)
48 icccm_paste = f_paste;
49 icccm_clear = f_clear;
50 icccm_copy = f_copy;
51 icccm_error = f_error;
55 #if defined(__STDC__)
56 static void peekProc( Widget widget,
57 void *data,
58 Atom *selection,
59 Atom *type,
60 void *value,
61 unsigned long *length,
62 int *format
64 #else
65 static void peekProc( widget, data, selection, type, value, length, format )
66 Widget widget;
67 void *data;
68 Atom *selection, *type;
69 void *value;
70 unsigned long *length;
71 int *format;
72 #endif
74 if ( *type == 0 )
75 (*icccm_error)( stderr, "Nothing in the primary selection buffer");
76 else if ( *type != XA_STRING )
77 (*icccm_error)( stderr, "Unknown type return from selection");
78 else
79 XtFree( value );
83 #if 0
84 #if defined(__STDC__)
85 void _vi_AcquireClipboard( Widget wid )
86 #else
87 void _vi_AcquireClipboard( wid )
88 Widget wid;
89 #endif
91 XtGetSelectionValue( wid,
92 XA_PRIMARY,
93 XA_STRING,
94 (XtSelectionCallbackProc) peekProc,
95 NULL,
96 XtLastTimestampProcessed( XtDisplay(wid) )
99 #endif
102 #if defined(__STDC__)
103 static void loseProc( Widget widget )
104 #else
105 static void loseProc( widget )
106 Widget widget;
107 #endif
109 /* we have lost ownership of the selection. clear it */
110 (*icccm_clear)( widget );
112 /* also participate in the protocols */
113 XtDisownSelection( widget,
114 XA_PRIMARY,
115 XtLastTimestampProcessed( XtDisplay(widget) )
120 #if defined(__STDC__)
121 static int convertProc( Widget widget,
122 Atom *selection,
123 Atom *target,
124 Atom *type,
125 void **value,
126 int *length,
127 int *format
129 #else
130 static int convertProc( widget, selection, target, type, value, length, format )
131 Widget widget;
132 Atom *selection, *target, *type;
133 void **value;
134 int *length;
135 int *format;
136 #endif
138 String buffer;
139 int len;
141 /* someone wants a copy of the selection. is there one? */
142 (*icccm_copy)( &buffer, &len );
143 if ( len == 0 ) return False;
145 /* do they want the string? */
146 if ( *target == XA_STRING ) {
147 *length = len;
148 *value = (void *) XtMalloc( len );
149 *type = XA_STRING;
150 *format = 8;
151 memcpy( (char *) *value, buffer, *length );
152 return True;
155 /* do they want the length? */
156 if ( *target == XInternAtom( XtDisplay(widget), "LENGTH", FALSE) ) {
157 *length = 1;
158 *value = (void *) XtMalloc( sizeof(int) );
159 *type = *target;
160 *format = 32;
161 * ((int *) *value) = len;
162 return True;
165 /* we lose */
166 return False;
170 * __vi_AcquirePrimary --
172 * PUBLIC: void __vi_AcquirePrimary __P((Widget));
174 void
175 __vi_AcquirePrimary(Widget widget)
177 /* assert we own the primary selection */
178 XtOwnSelection( widget,
179 XA_PRIMARY,
180 XtLastTimestampProcessed( XtDisplay(widget) ),
181 (XtConvertSelectionProc) convertProc,
182 (XtLoseSelectionProc) loseProc,
183 NULL
186 #if defined(OPENLOOK)
187 /* assert we also own the clipboard */
188 XtOwnSelection( widget,
189 XA_CLIPBOARD( XtDisplay(widget) ),
190 XtLastTimestampProcessed( XtDisplay(widget) ),
191 convertProc,
192 loseProc,
193 NULL
195 #endif
199 #if defined(__STDC__)
200 static void gotProc( Widget widget,
201 void *data,
202 Atom *selection,
203 Atom *type,
204 void *value,
205 unsigned long *length,
206 int *format
208 #else
209 static void gotProc( widget, data, selection, type, value, length, format )
210 Widget widget;
211 void *data;
212 Atom *selection, *type;
213 void *value;
214 unsigned long *length;
215 int *format;
216 #endif
218 if ( *type == 0 )
219 (*icccm_error)( stderr, "Nothing in the primary selection buffer");
220 else if ( *type != XA_STRING )
221 (*icccm_error)( stderr, "Unknown type return from selection");
222 else {
223 (*icccm_paste)( widget, value, *length );
224 XtFree( value );
229 * __vi_PasteFromClipboard --
231 * PUBLIC: void __vi_PasteFromClipboard __P((Widget));
233 void
234 __vi_PasteFromClipboard(Widget widget)
236 XtGetSelectionValue( widget,
237 XA_PRIMARY,
238 XA_STRING,
239 (XtSelectionCallbackProc) gotProc,
240 NULL,
241 XtLastTimestampProcessed( XtDisplay(widget) )