1 /*
2  *
3 Copyright 1989, 1998  The Open Group
4 
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
24  */
25 
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <X11/Intrinsic.h>
29 #include <X11/StringDefs.h>
30 #include <X11/Xaw/Cardinals.h>
31 
32 #define THIS_IS_MAIN		/* Don't get extern definitions of global
33 				   variables. */
34 
35 #include "editresP.h"
36 
37 /*
38  * Global variables.
39  */
40 
41 /* array of toolkit dependent labels taken from the resource file */
42 String res_labels[NUM_RES_LABELS];
43 
44 /* decremented if the target client does not speak the current version */
45 int global_effective_protocol_version = CURRENT_PROTOCOL_VERSION;
46 
47 /* toolkit type of client whose "resources" we are currently editing */
48 char *global_effective_toolkit = "xt";
49 
50 int global_error_code;
51 unsigned long global_serial_num;
52 int (*global_old_error_handler)(Display *, XErrorEvent *);
53 
54 Boolean global_resource_box_up = FALSE;
55 TreeInfo *global_tree_info = NULL;
56 CurrentClient global_client;
57 ScreenData global_screen_data;
58 Widget global_tree_parent;
59 Widget global_paned = NULL;		/* named after toolkit */
60 Widget global_toplevel;
61 AppResources global_resources;
62 
63 
64 static void Syntax ( XtAppContext app_con, char *call ) _X_NORETURN;
65 
66 static String fallback_resources[] = {
67     NULL,
68 };
69 
70 #define Offset(field) (XtOffsetOf(AppResources, field))
71 
72 static XtResource editres_resources[] = {
73   {"debug", "Debug", XtRBoolean, sizeof(Boolean),
74      Offset(debug), XtRImmediate, (XtPointer) FALSE},
75   {"numFlashes", "NumFlashes", XtRInt, sizeof(int),
76      Offset(num_flashes), XtRImmediate, (XtPointer) NUM_FLASHES},
77   {"flashTime", "FlashTime", XtRInt, sizeof(int),
78      Offset(flash_time), XtRImmediate, (XtPointer) FLASH_TIME},
79   {"flashColor", XtCForeground, XtRPixel, sizeof(Pixel),
80      Offset(flash_color), XtRImmediate, (XtPointer) XtDefaultForeground},
81   {"saveResourceFile", "SaveResourcesFile", XtRString, sizeof(String),
82      Offset(save_resources_file), XtRString, (XtPointer) ""},
83 };
84 
85 Atom wm_delete_window;
86 
87 int
main(int argc,char ** argv)88 main(int argc, char **argv)
89 {
90     XtAppContext app_con;
91 
92     global_toplevel = XtAppInitialize(&app_con, "Editres", NULL, ZERO,
93 			       &argc, argv, fallback_resources,
94 			       NULL, ZERO);
95 
96     if (argc != 1)
97 	Syntax(app_con, argv[0]);
98 
99     SetApplicationActions(app_con);
100     XtGetApplicationResources(global_toplevel, (XtPointer) &global_resources,
101 			      editres_resources, XtNumber(editres_resources),
102 			      NULL, (Cardinal) 0);
103     global_resources.allocated_save_resources_file = FALSE;
104 
105     XtOverrideTranslations
106       (global_toplevel,
107        XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
108 
109     /* build tree for Xt intrinsics */
110     BuildWidgetTree(global_toplevel);
111 
112     SetMessage(global_screen_data.info_label,
113 	       res_labels[13]);
114 
115     global_screen_data.set_values_popup = NULL;
116 
117     InternAtoms(XtDisplay(global_toplevel));
118 
119     XtRealizeWidget(global_toplevel);
120 
121     wm_delete_window =
122       XInternAtom(XtDisplay(global_toplevel), "WM_DELETE_WINDOW",
123 				   False);
124     (void) XSetWMProtocols (XtDisplay(global_toplevel),
125 			    XtWindow(global_toplevel),
126                             &wm_delete_window, 1);
127     XtAppMainLoop(app_con);
128     exit(0);
129 }
130 
131 /*	Function Name: Syntax
132  *	Description: Prints a the calling syntax for this function to stdout.
133  *	Arguments: app_con - the application context.
134  *                 call - the name of the application.
135  *	Returns: none - exits tho.
136  */
137 
138 static void
Syntax(XtAppContext app_con,char * call)139 Syntax(XtAppContext app_con, char *call)
140 {
141     XtDestroyApplicationContext(app_con);
142     fprintf(stderr, "Usage: %s\n", call);
143     exit(1);
144 }
145