Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / osf / xmbind / xmbind.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* 
24  *  @OSF_COPYRIGHT@
25  *  COPYRIGHT NOTICE
26  *  Copyright (c) 1990, 1991, 1992, 1993 Open Software Foundation, Inc.
27  *  ALL RIGHTS RESERVED (MOTIF). See the file named COPYRIGHT.MOTIF for
28  *  the full copyright text.
29 */ 
30 /* 
31  * HISTORY
32 */ 
33 #ifdef REV_INFO
34 #ifndef lint
35 static char rcsid[] = "$TOG: xmbind.c /main/10 1997/06/18 17:34:48 samborn $"
36 #endif
37 #endif
38 #include <stdio.h>
39 #include <Xm/Xm.h>
40
41 /* Internal routines "borrowed" from libXm.  Don't try this at home! */
42 extern Boolean _XmVirtKeysLoadFileBindings(char *fileName, String *binding);
43 extern int _XmVirtKeysLoadFallbackBindings(Display *display, String *binding);
44
45 void main(argc, argv)
46     int argc;
47     char **argv;
48 {
49     enum { XA_MOTIF_DEFAULT_BINDINGS, XA_MOTIF_BINDINGS };
50     static char *atom_names[] = {
51       "_MOTIF_DEFAULT_BINDINGS", "_MOTIF_BINDINGS" };
52
53     Atom atoms[XtNumber(atom_names)];
54     XtAppContext  app_context;
55     Display *display;
56     String bindings = NULL;
57
58     XtToolkitInitialize();
59     app_context = XtCreateApplicationContext();
60     display = XtOpenDisplay(app_context, NULL, argv[0], "Xmbind",
61                         NULL, 0, &argc, argv);
62     
63     if (display == NULL) {
64         fprintf(stderr, "%s:  Can't open display\n", argv[0]);
65         exit(1);
66     }
67
68     XInternAtoms(display, atom_names, XtNumber(atom_names), False, atoms);
69     if (argc == 2) {
70         if (_XmVirtKeysLoadFileBindings (argv[1], &bindings) == True) {
71             XDeleteProperty (display, RootWindow (display, 0),
72                              atoms[XA_MOTIF_DEFAULT_BINDINGS]);
73             XChangeProperty (display, RootWindow(display, 0),
74                              atoms[XA_MOTIF_BINDINGS],
75                              XA_STRING, 8, PropModeReplace,
76                              (unsigned char *)bindings, strlen(bindings));
77             XFlush (display);
78             XtFree (bindings);
79             exit(0);
80         }
81         else {
82             fprintf(stderr, "%s:  Can't open %s\n", argv[0], argv[1]);
83             exit(1);
84         }
85     }
86
87     XDeleteProperty (display, RootWindow (display, 0),
88                      atoms[XA_MOTIF_BINDINGS]);
89     XDeleteProperty (display, RootWindow (display, 0),
90                      atoms[XA_MOTIF_DEFAULT_BINDINGS]);
91
92     _XmVirtKeysLoadFallbackBindings (display, &bindings);
93
94     XFlush (display);
95     XtFree (bindings);
96    
97     exit(0);
98 }
99