1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
|
/*
* Copyright (c) 1999-2003 Smithsonian Astrophysical Observatory
*/
/*
*
* remote.c -- xpa access control list management
*
*/
#include <xpap.h>
/*
*----------------------------------------------------------------------------
*
*
* Private Routines
*
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static XPAClip
ClipBoardNew(XPA xpa, char *name)
#else
static XPAClip ClipBoardNew(xpa, name)
XPA xpa;
char *name;
#endif
{
XPAClip cur, xnew;
if( (xnew = (XPAClip)xcalloc(1, sizeof(XPAClipRec))) == NULL )
return(NULL);
/* fill in record structure */
xnew->name = xstrdup(name);
xnew->ip = xpa->comm->cmdip;
/* add to the end of list */
if( xpa->cliphead == NULL ){
xpa->cliphead = xnew;
}
else{
for(cur=xpa->cliphead; cur->next!=NULL; cur=cur->next){
;
}
cur->next = xnew;
}
return xnew;
}
#ifdef ANSI_FUNC
static XPAClip
ClipBoardLookup(XPA xpa, char *name)
#else
static XPAClip ClipBoardLookup(xpa, name)
XPA xpa;
char *name;
#endif
{
XPAClip cur;
/* look for reserved keywords that have callbacks */
for(cur=xpa->cliphead; cur!=NULL; cur=cur->next){
if( !strcmp(name, cur->name) && (xpa->comm->cmdip == cur->ip) ){
return(cur);
}
}
return NULL;
}
#ifdef ANSI_FUNC
static int
ClipBoardAdd(XPA xpa, char *name, char *paramlist, char *buf)
#else
static int
ClipBoardAdd(xpa, name, paramlist, buf)
XPA xpa;
char *name;
char *paramlist;
char *buf;
#endif
{
XPAClip cur;
if( !(cur = ClipBoardLookup(xpa, name)) )
cur = ClipBoardNew(xpa, name);
if( !cur )
return -1;
if( cur->value )
xfree(cur->value);
cur->value = xstrdup(buf);
return 0;
}
#ifdef ANSI_FUNC
static int
ClipBoardAppend(XPA xpa, char *name, char *paramlist, char *buf)
#else
static int
ClipBoardAppend(xpa, name, paramlist, buf)
XPA xpa;
char *name;
char *paramlist;
char *buf;
#endif
{
XPAClip cur;
if( !(cur = ClipBoardLookup(xpa, name)) )
cur = ClipBoardNew(xpa, name);
if( !cur )
return -1;
if( cur->value ){
if( (cur->value = (char *)xrealloc(cur->value,
strlen(cur->value)+strlen(buf)+1)) )
strcat(cur->value, buf);
else
return -1;
}
else{
cur->value = xstrdup(buf);
}
return 0;
}
#ifdef ANSI_FUNC
static int
ClipBoardDelete(XPA xpa, char *name, char *paramlist)
#else
static int
ClipBoardDelete(xpa, name, paramlist)
XPA xpa;
char *name;
char *paramlist;
#endif
{
XPAClip cur;
if( (cur = ClipBoardLookup(xpa, name)) ){
ClipBoardFree(xpa, cur);
return 0;
}
else
return -1;
}
/*
*----------------------------------------------------------------------------
*
*
* Semi-Public Routines (used by xpa.c and command.c)
*
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
int
ClipBoardFree(XPA xpa, XPAClip clip)
#else
int ClipBoardFree(xpa, clip)
XPA xpa;
XPAClip clip;
#endif
{
XPAClip cur;
if( !clip )
return 0;
/* remove from list */
if( xpa->cliphead ){
if( xpa->cliphead == clip ){
xpa->cliphead = clip->next;
}
else{
for(cur=xpa->cliphead; cur!=NULL; cur=cur->next){
if( cur->next == clip ){
cur->next = clip->next;
break;
}
}
}
}
if( clip->name ) xfree(clip->name);
if( clip->value ) xfree(clip->value);
xfree(clip);
return 1;
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPAReceiveClipboard
*
* Purpose: add a new clipboard entry
*
* Returns: xpa callback error codes
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
int
XPAReceiveClipboard (void *client_data, void *call_data, char *paramlist,
char *buf, size_t len)
#else
int XPAReceiveClipboard(client_data, call_data, paramlist, buf, len)
void *client_data;
void *call_data;
char *paramlist;
char *buf;
size_t len;
#endif
{
XPA xpa = (XPA)call_data;
char cmd[SZ_LINE];
char name[SZ_LINE];
char tbuf[SZ_LINE];
int lp=0;
int status = -1;
*cmd = '\0';
*name = '\0';
if( paramlist && *paramlist ){
if( !word(paramlist, cmd, &lp) || !word(paramlist, name, &lp) )
goto done;
/* lookup the command */
if( !strcmp(cmd, "add") ){
status = ClipBoardAdd(xpa, name, ¶mlist[lp], buf);
}
else if( !strncmp(cmd, "app", 3) ){
status = ClipBoardAppend(xpa, name, ¶mlist[lp], buf);
}
else if( !strncmp(cmd, "del", 3) ){
status = ClipBoardDelete(xpa, name, ¶mlist[lp]);
}
#ifdef LATER
else if( !strncmp(cmd, "loa", 3) ){
status = ClipBoardLoad(xpa, name, ¶mlist[lp], buf);
}
else if( !strncmp(cmd, "sav", 3) ){
status = ClipBoardSave(xpa, name, ¶mlist[lp]);
}
#endif
}
done:
if( status < 0 ){
if( !*cmd || !*name ){
XPAError(xpa, "XPA clipboard requires: add|append|delete name\n");
}
else{
snprintf(tbuf, SZ_LINE,
"XPA clipboard invalid cmd or name: %s %s\n", cmd, name);
XPAError(xpa, tbuf);
}
}
return(status);
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPASendClipboard
*
* Purpose: return clipboard information
*
* Returns: 0 for success, -1 for failure
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
int
XPASendClipboard (void *client_data, void *call_data, char *paramlist,
char **buf, size_t *len)
#else
int XPASendClipboard(client_data, call_data, paramlist, buf, len)
void *client_data;
void *call_data;
char *paramlist;
char **buf;
size_t *len;
#endif
{
XPA xpa = (XPA)call_data;
char name[SZ_LINE];
char tbuf[SZ_LINE];
int lp=0;
int status = -1;
XPAClip cur;
*name = '\0';
if( paramlist && *paramlist ){
if( !word(paramlist, name, &lp) )
goto done;
if( !(cur = ClipBoardLookup(xpa, name)) )
goto done;
if( cur->value ){
send(xpa_datafd(xpa), cur->value, strlen(cur->value), 0);
status = 0;
}
}
done:
if( status < 0 ){
if( !*name ){
XPAError(xpa, "XPA clipboard requires: name\n");
}
else{
snprintf(tbuf, SZ_LINE, "XPA clipboard invalid name: %s\n", name);
XPAError(xpa, tbuf);
}
}
return(status);
}
/*
*----------------------------------------------------------------------------
*
*
* Public Routines
*
*
*----------------------------------------------------------------------------
*/
|