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