Home | History | Annotate | Line # | Download | only in dist
      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 #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 */
     46 String res_labels[NUM_RES_LABELS];
     47 
     48 /* decremented if the target client does not speak the current version */
     49 int global_effective_protocol_version = CURRENT_PROTOCOL_VERSION;
     50 
     51 /* toolkit type of client whose "resources" we are currently editing */
     52 const char *global_effective_toolkit = "xt";
     53 
     54 int global_error_code;
     55 unsigned long global_serial_num;
     56 int (*global_old_error_handler)(Display *, XErrorEvent *);
     57 
     58 Boolean global_resource_box_up = FALSE;
     59 TreeInfo *global_tree_info = NULL;
     60 CurrentClient global_client;
     61 ScreenData global_screen_data;
     62 Widget global_tree_parent;
     63 Widget global_paned = NULL;		/* named after toolkit */
     64 Widget global_toplevel;
     65 AppResources global_resources;
     66 
     67 
     68 static void Syntax (XtAppContext, const char *, int) _X_NORETURN;
     69 
     70 static String fallback_resources[] = {
     71     NULL,
     72 };
     73 
     74 #define Offset(field) (XtOffsetOf(AppResources, field))
     75 
     76 static 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 
     89 Atom wm_delete_window;
     90 
     91 int
     92 main(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 
    164 static void
    165 Syntax(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