1 /* wxcopy.c- copy stdin or file into cutbuffer
3 * Copyright (c) 1997 Alfredo K. Kojima
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #define LINESIZE (4*1024)
27 #define MAXDATA (64*1024)
32 printf("usage: %s [-cutbuffer number] [filename]\n", progn
);
36 errorHandler(Display
*dpy
, XErrorEvent
*err
)
38 /* ignore all errors */
43 main(int argc
, char **argv
)
53 for (i
=1; i
<argc
; i
++) {
54 if (argv
[i
][0]=='-') {
55 if (argv
[i
][1]=='h') {
58 } else if (strcmp(argv
[i
],"-cutbuffer")==0) {
61 if (sscanf(argv
[i
],"%i", &buffer
)!=1) {
62 printf("%s: could not convert \"%s\" to int\n",
66 if (buffer
<0 || buffer
> 7) {
67 printf("%s: invalid buffer number %i\n", argv
[0],
84 file
= fopen(filename
, "r");
87 sprintf(line
, "%s: could not open \"%s\"", argv
[0], filename
);
93 dpy
= XOpenDisplay("");
94 XSetErrorHandler(errorHandler
);
96 printf("%s: could not open display\n", argv
[0]);
100 XRotateBuffers(dpy
, 1);
103 while (!feof(file
)) {
105 char tmp
[LINESIZE
+2];
108 if (!fgets(tmp
, LINESIZE
, file
)) {
113 nbuf
= malloc(l
+nl
+1);
115 nbuf
= realloc(buf
, l
+nl
+1);
117 printf("%s: out of memory\n", argv
[0]);
128 printf("%s: too much data in input\n", argv
[0]);
133 XStoreBuffer(dpy
, buf
, l
, buffer
);