Initial revision
[wmaker-crm.git] / util / wxpaste.c
blob086e80fb26b13d321cad0ca821404a1937d4b2ea
1 /* wxpaste.c- paste contents of cutbuffer to stdout
2 *
3 * Copyright (c) 1997 Alfredo K. Kojima
4 *
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.
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <X11/Xlib.h>
26 #define LINESIZE (4*1024)
28 void
29 help(char *progn)
31 printf("usage: %s [-cutbuffer number]\n", progn);
34 int
35 main(int argc, char **argv)
37 Display *dpy;
38 int i, l;
39 int buffer=0;
40 char *buf;
42 for (i=1; i<argc; i++) {
43 if (argv[i][0]=='-') {
44 if (argv[i][1]=='h') {
45 help(argv[0]);
46 exit(0);
47 } else if (strcmp(argv[i],"-cutbuffer")==0) {
48 if (i<argc-1) {
49 i++;
50 if (sscanf(argv[i],"%i", &buffer)!=1) {
51 printf("%s: could not convert \"%s\" to int\n",
52 argv[0], argv[i]);
53 exit(1);
55 if (buffer<0 || buffer > 7) {
56 printf("%s: invalid buffer number %i\n", argv[0],
57 buffer);
58 exit(1);
60 } else {
61 help(argv[0]);
62 exit(1);
65 } else {
66 help(argv[0]);
67 exit(1);
70 dpy = XOpenDisplay("");
71 if (!dpy) {
72 printf("%s: could not open display\n", argv[0]);
73 exit(1);
75 buf=XFetchBuffer(dpy, &l, buffer);
76 if (buf)
77 printf("%s", buf);
78 XCloseDisplay(dpy);
79 exit(1);