changeset 80:2f1ecc1c5f72

Huge cleanup -- move some global variables into a struct.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 26 Sep 2011 17:39:49 +0300
parents 0602d9bf474a
children 7ed31bc85504
files GNUmakefile src/cfgfile.cc src/checks.cc src/colour4.cc src/dialog.cc src/dialog.h src/drawmap.cc src/edisplay.cc src/editgrid.cc src/editlev.cc src/editloop.cc src/editobj.cc src/editsave.cc src/editzoom.cc src/entry.cc src/entry2.cc src/gcolour1.cc src/gfx.cc src/gfx.h src/gotoobj.cc src/help2.cc src/img.cc src/imgspect.cc src/infobar.cc src/input.cc src/l_align.cc src/levels.cc src/lists.cc src/locate.cc src/menu.cc src/menubar.cc src/mkpalette.cc src/objects.cc src/palview.cc src/pic2img.cc src/prefer.cc src/r_images.cc src/s_door.cc src/s_lift.cc src/s_misc.cc src/spritdir.h src/sticker.cc src/textures.cc src/trace.cc src/trace.h src/v_merge.cc src/verbmsg.cc src/wadres.cc src/wads.cc src/wads2.cc src/x_hover.cc src/yadex.cc src/yadex.h
diffstat 53 files changed, 789 insertions(+), 1252 deletions(-) [+]
line wrap: on
line diff
--- a/GNUmakefile	Mon Sep 26 17:14:54 2011 +0300
+++ b/GNUmakefile	Mon Sep 26 17:39:49 2011 +0300
@@ -152,7 +152,7 @@
 	l_misc		l_prop		l_unlink	l_vertices	\
 	levels		lists		locate		lumpdir		\
 	macro		memory		menubar		menu		\
-	mkpalette	names		nop		\
+	mkpalette	names		\
 	objects		objinfo		oldmenus	palview		\
 	patchdir	pic2img		prefer		s_centre	\
 	s_door		s_lift		s_linedefs	s_merge		\
@@ -161,7 +161,7 @@
 	selbox		selectn		selpath		selrect		\
 	serialnum	spritdir	sticker		r_render	r_images	\
 	t_centre	t_flags		t_prop		t_spin		\
-	textures	things		trace		v_centre	\
+	textures	things		v_centre	\
 	v_merge		v_polyg		vectext		verbmsg		\
 	version		wadfile		wadlist		wadnamec	\
 	wadres		wads		wads2		warn		\
--- a/src/cfgfile.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/cfgfile.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -36,7 +36,6 @@
 #include "help1.h"
 #include "levels.h"
 #include "locate.h"
-#include "trace.h"
 #include "windim.h"
 
 
@@ -96,13 +95,13 @@
 
     // End of the options description
     OPT_END
-} opt_type_t;
+} OptionType;
 
 typedef struct
 {
     const char *long_name;        // Command line arg. or keyword
     const char *short_name;        // Abbreviated command line argument
-    opt_type_t opt_type;        // Type of this option
+    OptionType type;        // Type of this option
     const char *flags;                // Flags for this option :
     // "1" = process only on pass 1 of
     //       parse_command_line_options()
@@ -110,438 +109,75 @@
     // "x" = X only (ignored ifndef Y_X11)
     const char *desc;                // Description of the option
     void *data_ptr;                // Pointer to the data
-} opt_desc_t;
+} OptionDesc;
 
 /* The first option has neither long name nor short name.
    It is used for "lonely" arguments (i.e. file names). */
-opt_desc_t options[] =                // Description of the command line options
-{
-    {0,
-     0,
-     OPT_STRINGPTRACC,
-     0,
-     "Patch wad file",
-     &PatchWads},
-
-    {"autoscroll",
-     0,
-     OPT_BOOLEAN,
-     0,
-     "Enable autoscrolling",
-     &autoscroll},
-
-    {"autoscroll_amp",
-     0,
-     OPT_UNSIGNED,
-     0,
-     "Amp. of scrolling (% of screen size)",
-     &autoscroll_amp},
-
-    {"autoscroll_edge",
-     0,
-     OPT_UNSIGNED,
-     0,
-     "Max. dist. to edge (pixels)",
-     &autoscroll_edge},
-
-    {0,
-     "b",
-     OPT_STRINGPTR,
-     0,
-     "Run benchmark and exit successfully",
-     &bench},
-
-    {"blindly_swap_sidedefs",
-     0,
-     OPT_BOOLEAN,
-     0,
-     "Blindly swap sidedefs on a linedef",
-     &blindly_swap_sidedefs},
-
-    {"config_file",
-     "f",
-     OPT_STRINGPTR,
-     "1",
-     "Config file",
-     &config_file},
-
-    {"copy_linedef_reuse_sidedefs",
-     0,
-     OPT_BOOLEAN,
-     0,
-     "Use same sidedefs as original linedef",
-     &copy_linedef_reuse_sidedefs},
-
-    {"debug",
-     "d",
-     OPT_BOOLEAN,
-     0,
-     "Debug mode",
-     &Debug},
-
-    {"default_ceiling_height",
-     0,
-     OPT_INTEGER,
-     0,
-     "Default ceiling height",
-     &default_ceiling_height},
-
-    {"default_ceiling_texture",
-     0,
-     OPT_STRINGBUF8,
-     0,
-     "Default ceiling texture",
-     default_ceiling_texture},
-
-    {"default_floor_height",
-     0,
-     OPT_INTEGER,
-     0,
-     "Default floor height",
-     &default_floor_height},
-
-    {"default_floor_texture",
-     0,
-     OPT_STRINGBUF8,
-     0,
-     "Default floor texture",
-     default_floor_texture},
-
-    {"default_light_level",
-     0,
-     OPT_INTEGER,
-     0,
-     "Default light level",
-     &default_light_level},
+OptionDesc options[] = {
+    {NULL,                        NULL, OPT_STRINGPTRACC,  NULL, "Patch wad file", &cfg.PatchWads },
+    {"autoscroll",                NULL, OPT_BOOLEAN,       NULL, "Enable autoscrolling", &cfg.autoscroll },
+    {"autoscroll_amp",            NULL, OPT_UNSIGNED,      NULL, "Amp. of scrolling (% of screen size)", &cfg.autoscroll_amp},
+    {"autoscroll_edge",           NULL, OPT_UNSIGNED,      NULL, "Max. dist. to edge (pixels)", &cfg.autoscroll_edge},
+    {NULL,                        "b",  OPT_STRINGPTR,     NULL, "Run benchmark and exit successfully",     &cfg.bench},
+    {"blindly_swap_sidedefs",     NULL, OPT_BOOLEAN,       NULL, "Blindly swap sidedefs on a linedef",     &cfg.blindly_swap_sidedefs},
+    {"config_file",               "f",  OPT_STRINGPTR,     "1",  "Config file",     &cfg.config_file},
+    {"copy_linedef_reuse_sidedefs",NULL,OPT_BOOLEAN,       NULL, "Use same sidedefs as original linedef",     &cfg.copy_linedef_reuse_sidedefs},
+    {"debug",                     "d",  OPT_BOOLEAN,       NULL, "Debug mode",     &cfg.Debug},
 
-    {"default_lower_texture",
-     0,
-     OPT_STRINGBUF8,
-     0,
-     "Default lower texture",
-     default_lower_texture},
-
-    {"default_middle_texture",
-     0,
-     OPT_STRINGBUF8,
-     0,
-     "Default middle texture",
-     default_middle_texture},
-
-    {"default_thing",
-     0,
-     OPT_INTEGER,
-     0,
-     "Default thing number",
-     &default_thing},
-
-    {"default_upper_texture",
-     0,
-     OPT_STRINGBUF8,
-     0,
-     "Default upper texture",
-     default_upper_texture},
-
-    {"digit_zoom_base",
-     0,
-     OPT_INTEGER,
-     0,
-     "[0]-[9]: base zoom factor (in %)",
-     &digit_zoom_base},
-
-    {"digit_zoom_step",
-     0,
-     OPT_INTEGER,
-     0,
-     "[0]-[9]: step between factors (in %)",
-     &digit_zoom_step},
-
-    {"double_click_timeout",
-     0,
-     OPT_INTEGER,
-     0,
-     "Max delay in ms between clicks",
-     &double_click_timeout},
-
-    {"expert",
-     0,
-     OPT_BOOLEAN,
-     0,
-     "Expert mode",
-     &Expert},
-
-    {"file",
-     0,
-     OPT_STRINGPTRLIST,
-     0,
-     "Patch wad file",
-     &PatchWads},
-
-    {"font",
-     "fn",
-     OPT_STRINGPTR,
-     0,
-     "(X11 only) Font name",
-     &font_name},
-
-    {"game",
-     "g",
-     OPT_STRINGPTR,
-     0,
-     "Game",
-     &Game},
-
-    {"grid_max",
-     0,
-     OPT_INTEGER,
-     0,
-     "Max grid step (map units)",
-     &GridMax},
-
-    {"grid_min",
-     0,
-     OPT_INTEGER,
-     0,
-     "Min grid step (map units)",
-     &GridMin},
-
-    {"grid_pixels_min",
-     0,
-     OPT_INTEGER,
-     0,
-     "Min grid step (pixels)",
-     &grid_pixels_min},
-
-    {"height",
-     "h",
-     OPT_WINDIM,
-     "x",
-     "(X11 only) Initial window height",
-     &initial_window_height},
-
-    {"help",
-     "?",
-     OPT_BOOLEAN,
-     "1",
-     "Show usage summary",
-     &show_help},
+    {"default_ceiling_height",    NULL, OPT_INTEGER,       NULL, "Default ceiling height",     &cfg.def.ceiling_height},
+    {"default_ceiling_texture",   NULL, OPT_STRINGBUF8,    NULL, "Default ceiling texture",     cfg.def.ceiling_texture},
+    {"default_floor_height",      NULL, OPT_INTEGER,       NULL, "Default floor height",     &cfg.def.floor_height},
+    {"default_floor_texture",     NULL, OPT_STRINGBUF8,    NULL, "Default floor texture",     cfg.def.floor_texture},
+    {"default_light_level",       NULL, OPT_INTEGER,       NULL, "Default light level",     &cfg.def.light_level},
+    {"cfg.def.lower_texture",     NULL, OPT_STRINGBUF8,    NULL, "Default lower texture",     cfg.def.lower_texture},
+    {"default_middle_texture",    NULL, OPT_STRINGBUF8,    NULL, "Default middle texture",     cfg.def.middle_texture},
+    {"default_thing",             NULL, OPT_INTEGER,       NULL, "Default thing number",     &cfg.def.thing},
 
-    {"idle_sleep_ms",
-     0,
-     OPT_INTEGER,
-     0,
-     "ms to sleep before XPending()",
-     &idle_sleep_ms},
-
-    {"info_bar",
-     0,
-     OPT_BOOLEAN,
-     0,
-     "Show the info bar",
-     &InfoShown},
-
-    {"insert_vertex_split_linedef",
-     0,
-     OPT_CONFIRM,
-     0,
-     "Split ld after ins. vertex",
-     &insert_vertex_split_linedef},
-
-    {"insert_vertex_merge_vertices",
-     0,
-     OPT_CONFIRM,
-     0,
-     "Merge vertices after ins. vertex",
-     &insert_vertex_merge_vertices},
-
-    {"iwad1",
-     "i1",
-     OPT_STRINGPTR,
-     0,
-     "The name of the Doom/Ultimate D. iwad",
-     &Iwad1},
-
-    {"iwad2",
-     "i2",
-     OPT_STRINGPTR,
-     0,
-     "The name of the Doom II/Final D. iwad",
-     &Iwad2},
-
-    {"iwad3",
-     "i3",
-     OPT_STRINGPTR,
-     0,
-     "The name of the Heretic iwad",
-     &Iwad3},
-
-    {"iwad4",
-     "i4",
-     OPT_STRINGPTR,
-     0,
-     "The name of the Hexen iwad",
-     &Iwad4},
-
-    {"iwad5",
-     "i5",
-     OPT_STRINGPTR,
-     0,
-     "The name of the Strife iwad",
-     &Iwad5},
-
-    {"iwad6",
-     "i6",
-     OPT_STRINGPTR,
-     0,
-     "The name of the Doom alpha 0.2 iwad",
-     &Iwad6},
-
-    {"iwad7",
-     "i7",
-     OPT_STRINGPTR,
-     0,
-     "The name of the Doom alpha 0.4 iwad",
-     &Iwad7},
-
-    {"iwad8",
-     "i8",
-     OPT_STRINGPTR,
-     0,
-     "The name of the Doom alpha 0.5 iwad",
-     &Iwad8},
-
-    {"iwad9",
-     "i9",
-     OPT_STRINGPTR,
-     0,
-     "The name of the Doom press rel. iwad",
-     &Iwad9},
-
-    {"iwad10",
-     "i10",
-     OPT_STRINGPTR,
-     0,
-     "The name of the Strife 1.0 iwad",
-     &Iwad10},
-
-    {"no_pixmap",
-     "P",
-     OPT_BOOLEAN,
-     0,
-     "(X11 only) Use no pixmap",
-     &no_pixmap},
+    {"cfg.def.upper_texture",     NULL, OPT_STRINGBUF8,    NULL, "Default upper texture",     cfg.def.upper_texture},
+    {"digit_zoom_base",           NULL, OPT_INTEGER,       NULL, "[0]-[9]: base zoom factor (in %)",     &cfg.digit_zoom_base},
+    {"digit_zoom_step",           NULL, OPT_INTEGER,       NULL, "[0]-[9]: step between factors (in %)",     &cfg.digit_zoom_step},
+    {"double_click_timeout",      NULL, OPT_INTEGER,       NULL, "Max delay in ms between clicks",     &cfg.double_click_timeout},
+    {"expert",                    NULL, OPT_BOOLEAN,       NULL, "Expert mode",     &cfg.Expert},
+    {"file",                      NULL, OPT_STRINGPTRLIST, NULL, "Patch wad file",     &cfg.PatchWads},
+    {"font",                      "fn", OPT_STRINGPTR,     NULL, "(X11 only) Font name",     &font_name},
+    {"game",                      "g",  OPT_STRINGPTR,     NULL, "Game",     &cfg.Game},
+    {"grid_max",                  NULL, OPT_INTEGER,       NULL, "Max grid step (map units)",     &cfg.GridMax},
+    {"grid_min",                  NULL, OPT_INTEGER,       NULL, "Min grid step (map units)",     &cfg.GridMin},
+    {"grid_pixels_min",           NULL, OPT_INTEGER,       NULL, "Min grid step (pixels)",     &cfg.grid_pixels_min},
+    {"height",                    "h",  OPT_WINDIM,        "x",  "(X11 only) Initial window height",     &initial_window_height},
+    {"help",                      "?",  OPT_BOOLEAN,       "1",  "Show usage summary",     &cfg.show_help},
+    {"idle_sleep_ms",             NULL, OPT_INTEGER,       NULL, "ms to sleep before XPending()",     &cfg.idle_sleep_ms},
+    {"info_bar",                  NULL, OPT_BOOLEAN,       NULL, "Show the info bar",     &cfg.InfoShown},
+    {"insert_vertex_split_linedef",NULL,OPT_CONFIRM,       NULL, "Split ld after ins. vertex",     &cfg.insert_vertex_split_linedef},
+    {"insert_vertex_merge_vertices",NULL,OPT_CONFIRM,      NULL, "Merge vertices after ins. vertex",     &cfg.insert_vertex_merge_vertices},
+    {"iwad1",                     "i1", OPT_STRINGPTR,     NULL, "The name of the Doom/Ultimate D. iwad",    &cfg.Iwad[0]},
+    {"iwad2",                     "i2", OPT_STRINGPTR,     NULL, "The name of the Doom II/Final D. iwad",    &cfg.Iwad[1]},
+    {"iwad3",                     "i3", OPT_STRINGPTR,     NULL, "The name of the Heretic iwad",             &cfg.Iwad[2]},
+    {"iwad4",                     "i4", OPT_STRINGPTR,     NULL, "The name of the Hexen iwad",               &cfg.Iwad[3]},
+    {"iwad5",                     "i5", OPT_STRINGPTR,     NULL, "The name of the Strife iwad",              &cfg.Iwad[4]},
+    {"iwad6",                     "i6", OPT_STRINGPTR,     NULL, "The name of the Doom alpha 0.2 iwad",      &cfg.Iwad[5]},
+    {"iwad7",                     "i7", OPT_STRINGPTR,     NULL, "The name of the Doom alpha 0.4 iwad",      &cfg.Iwad[6]},
+    {"iwad8",                     "i8", OPT_STRINGPTR,     NULL, "The name of the Doom alpha 0.5 iwad",      &cfg.Iwad[7]},
+    {"iwad9",                     "i9", OPT_STRINGPTR,     NULL, "The name of the Doom press rel. iwad",     &cfg.Iwad[8]},
+    {"iwad10",                    "i10",OPT_STRINGPTR,     NULL, "The name of the Strife 1.0 iwad",          &cfg.Iwad[9]},
+    {"no_pixmap",                 "P",  OPT_BOOLEAN,       NULL, "(X11 only) Use no pixmap",     &cfg.no_pixmap},
+    {"pwad",                      "pw", OPT_STRINGPTRACC,  NULL, "Pwad file to load",     &cfg.PatchWads},
+    {"quiet",                     "q",  OPT_BOOLEAN,       NULL, "Quiet mode",     &cfg.Quiet},
+    {"quieter",                   "qq", OPT_BOOLEAN,       NULL, "Quieter mode",     &cfg.Quieter},
+    {"scroll_less",               NULL, OPT_UNSIGNED,      NULL, "Amp. of scrolling (% of screen size)",     &cfg.scroll_less},
+    {"scroll_more",               NULL, OPT_UNSIGNED,      NULL, "Amp. of scrolling (% of screen size)",     &cfg.scroll_more},
+    {"select0",                   "s0", OPT_BOOLEAN,       NULL, "Automatic selection of 0th object",     &cfg.Select0},
+    {"sprite_scale",              NULL, OPT_INTEGER,       NULL, "Relative scale of sprites",     &cfg.sprite_scale},
+    {"swap_buttons",              "sb", OPT_BOOLEAN,       NULL, "Swap mouse buttons",     &cfg.SwapButtons},
+    {"text_dot",                  "td", OPT_BOOLEAN,       NULL, "DrawScreenText debug flag",     &cfg.text_dot},
+    {"verbose",                   "v",  OPT_BOOLEAN,       "1",  "Verbose mode",     &cfg.verbose},
+    {"welcome_message",           NULL, OPT_BOOLEAN,       NULL, "Print welcome message",     &cfg.welcome_message},
+    {"width",                     "w",  OPT_WINDIM,        "x",  "(X11 only) Initial window width",     &initial_window_width},
+    {"zoom_default",              "z",  OPT_INTEGER,       NULL, "Initial zoom factor",     &cfg.zoom_default},
+    {"zoom_step",                 NULL, OPT_INTEGER,       NULL, "Step between zoom factors (in %)",     &cfg.zoom_step},
+    {"error_resiliency",          "e",  OPT_UNSIGNED,      NULL, "Error resiliency of the WAD/map loader (0-4). See yadex.cfg for more info.",     &cfg.error_res},
 
-    {"pwad",
-     "pw",
-     OPT_STRINGPTRACC,
-     0,
-     "Pwad file to load",
-     &PatchWads},
-
-    {"quiet",
-     "q",
-     OPT_BOOLEAN,
-     0,
-     "Quiet mode",
-     &Quiet},
-
-    {"quieter",
-     "qq",
-     OPT_BOOLEAN,
-     0,
-     "Quieter mode",
-     &Quieter},
-
-    {"scroll_less",
-     0,
-     OPT_UNSIGNED,
-     0,
-     "Amp. of scrolling (% of screen size)",
-     &scroll_less},
-
-    {"scroll_more",
-     0,
-     OPT_UNSIGNED,
-     0,
-     "Amp. of scrolling (% of screen size)",
-     &scroll_more},
-
-    {"select0",
-     "s0",
-     OPT_BOOLEAN,
-     0,
-     "Automatic selection of 0th object",
-     &Select0},
-
-    {"sprite_scale",
-     0,
-     OPT_INTEGER,
-     0,
-     "Relative scale of sprites",
-     &sprite_scale},
-
-    {"swap_buttons",
-     "sb",
-     OPT_BOOLEAN,
-     0,
-     "Swap mouse buttons",
-     &SwapButtons},
-
-    {"text_dot",
-     "td",
-     OPT_BOOLEAN,
-     0,
-     "DrawScreenText debug flag",
-     &text_dot},
-
-    {"verbose",
-     "v",
-     OPT_BOOLEAN,
-     "1",
-     "Verbose mode",
-     &verbose},
-
-    {"welcome_message",
-     0,
-     OPT_BOOLEAN,
-     0,
-     "Print welcome message",
-     &welcome_message},
-
-    {"width",
-     "w",
-     OPT_WINDIM,
-     "x",
-     "(X11 only) Initial window width",
-     &initial_window_width},
-
-    {"zoom_default",
-     "z",
-     OPT_INTEGER,
-     0,
-     "Initial zoom factor",
-     &zoom_default},
-
-    {"zoom_step",
-     0,
-     OPT_INTEGER,
-     0,
-     "Step between zoom factors (in %)",
-     &zoom_step},
-
-    {"error_resiliency",
-     "e",
-     OPT_UNSIGNED,
-     0,
-     "Error resiliency of the WAD/map loader (0-4). See yadex.cfg for more info.",
-     &error_res},
-
-    {0,
-     0,
-     OPT_END,
-     0,
-     0,
-     0}
+    {NULL,                        NULL, OPT_END,           NULL, NULL,  NULL}
 };
 
 
@@ -552,12 +188,12 @@
     CFG_PARSE_MAGIC_WARN = 0x02,
     CFG_PARSE_ANAL_NAME = 0x04,
     CFG_PARSE_ANAL_SYNTAX = 0x08
-} cfg_parse_flags_t;
+} ConfigParseFlags;
 
 
 static void append_item_to_list(const char ***list, const char *item);
 static int parse_config_file(const char *filename,
-                             cfg_parse_flags_t flags = CFG_PARSE_);
+                             ConfigParseFlags flags = CFG_PARSE_);
 static confirm_t confirm_e2i(const char *external);
 static const char *confirm_i2e(confirm_t internal);
 
@@ -640,7 +276,7 @@
  *        Return 0 on success, <>0 on failure.
  */
 #define RETURN_FAILURE do { rc = 1; goto byebye; } while (0)
-static int parse_config_file(const char *filename, cfg_parse_flags_t flags)
+static int parse_config_file(const char *filename, ConfigParseFlags flags)
 {
     int rc = 0;
     FILE *cfgfile;
@@ -769,9 +405,9 @@
             *p2 = '\0';
         }
 
-        for (const opt_desc_t * o = options + 1;; o++)
+        for (const OptionDesc * o = options + 1;; o++)
         {
-            if (o->opt_type == OPT_END)
+            if (o->type == OPT_END)
             {
                 if (flags & CFG_PARSE_ANAL_NAME)
                 {
@@ -795,7 +431,7 @@
             if (o->flags != NULL && strchr(o->flags, 'x'))
                 break;
 #endif
-            switch (o->opt_type)
+            switch (o->type)
             {
             case OPT_BOOLEAN:
                 if (!strcmp(value, "yes") || !strcmp(value, "true")
@@ -918,7 +554,7 @@
             default:
                 {
                     nf_bug("%s(%u): unknown option type %d",
-                           filename, lnum, (int) o->opt_type);
+                           filename, lnum, (int) o->type);
                     RETURN_FAILURE;
                 }
             }
@@ -944,7 +580,7 @@
  */
 int parse_command_line_options(int argc, const char *const *argv, int pass)
 {
-    const opt_desc_t *o;
+    const OptionDesc *o;
 
     while (argc > 0)
     {
@@ -960,7 +596,7 @@
         else
             for (o = options + 1;; o++)
             {
-                if (o->opt_type == OPT_END)
+                if (o->type == OPT_END)
                 {
                     err("invalid option: \"%s\"", argv[0]);
                     return 1;
@@ -974,7 +610,7 @@
         // or it doesn't but pass is 1, ignore it.
         ignore = (o->flags != NULL && strchr(o->flags, '1')) != (pass == 1);
 
-        switch (o->opt_type)
+        switch (o->type)
         {
         case OPT_BOOLEAN:
             if (argv[0][0] == '-')
@@ -1130,7 +766,7 @@
 
         default:
             {
-                nf_bug("unknown option type (%d)", (int) o->opt_type);
+                nf_bug("unknown option type (%d)", (int) o->type);
                 return 1;
             }
         }
@@ -1147,11 +783,11 @@
  */
 void dump_parameters(FILE * fp)
 {
-    const opt_desc_t *o;
+    const OptionDesc *o;
     int desc_maxlen = 0;
     int name_maxlen = 0;
 
-    for (o = options + 1; o->opt_type != OPT_END; o++)
+    for (o = options + 1; o->type != OPT_END; o++)
     {
         int len = strlen(o->desc);
         desc_maxlen = al_amax(desc_maxlen, len);
@@ -1162,38 +798,38 @@
         }
     }
 
-    for (o = options + 1; o->opt_type != OPT_END; o++)
+    for (o = options + 1; o->type != OPT_END; o++)
     {
         if (!o->long_name)
             continue;
         fprintf(fp, "%-*s  %-*s  ", name_maxlen, o->long_name, desc_maxlen,
                 o->desc);
-        if (o->opt_type == OPT_BOOLEAN)
+        if (o->type == OPT_BOOLEAN)
             fprintf(fp, "%s",
                     *((bool *) o->data_ptr) ? "enabled" : "disabled");
-        else if (o->opt_type == OPT_CONFIRM)
+        else if (o->type == OPT_CONFIRM)
             fputs(confirm_i2e(*((confirm_t *) o->data_ptr)), fp);
-        else if (o->opt_type == OPT_STRINGBUF8)
+        else if (o->type == OPT_STRINGBUF8)
             fprintf(fp, "\"%s\"", (char *) o->data_ptr);
-        else if (o->opt_type == OPT_STRINGPTR)
+        else if (o->type == OPT_STRINGPTR)
         {
             if (o->data_ptr)
                 fprintf(fp, "\"%s\"", *((char **) o->data_ptr));
             else
                 fprintf(fp, "--none--");
         }
-        else if (o->opt_type == OPT_INTEGER)
+        else if (o->type == OPT_INTEGER)
             fprintf(fp, "%d", *((int *) o->data_ptr));
-        else if (o->opt_type == OPT_UNSIGNED)
+        else if (o->type == OPT_UNSIGNED)
             fprintf(fp, "%lu", *((unsigned long *) o->data_ptr));
-        else if (o->opt_type == OPT_WINDIM)
+        else if (o->type == OPT_WINDIM)
         {
             char buf[50];        // Much slack
             ((Win_dim *) (o->data_ptr))->string(buf, sizeof buf);
             fputs(buf, fp);
         }
-        else if (o->opt_type == OPT_STRINGPTRACC
-                 || o->opt_type == OPT_STRINGPTRLIST)
+        else if (o->type == OPT_STRINGPTRACC
+                 || o->type == OPT_STRINGPTRLIST)
         {
             if (o->data_ptr)
             {
@@ -1217,11 +853,11 @@
  */
 void dump_command_line_options(FILE * fd)
 {
-    const opt_desc_t *o;
+    const OptionDesc *o;
     int desc_maxlen = 0;
     int name_maxlen = 0;
 
-    for (o = options + 1; o->opt_type != OPT_END; o++)
+    for (o = options + 1; o->type != OPT_END; o++)
     {
         int len;
         if (!o->short_name)
@@ -1235,7 +871,7 @@
         }
     }
 
-    for (o = options; o->opt_type != OPT_END; o++)
+    for (o = options; o->type != OPT_END; o++)
     {
         if (!o->short_name)
             continue;
@@ -1251,7 +887,7 @@
             fprintf(fd, "-%-*s ", name_maxlen, o->long_name);
         else
             fprintf(fd, "%*s", name_maxlen + 2, "");
-        switch (o->opt_type)
+        switch (o->type)
         {
         case OPT_BOOLEAN:
             fprintf(fd, "            ");
--- a/src/checks.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/checks.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -60,10 +60,10 @@
 {
     const char *line5 = 0;
 
-    if (Registered)
+    if (cfg.Registered)
     {
         /* Commented out AYM 19971130 - wouldn't work with Doom 2
-           if (! FindMasterDir (MasterDir, "TEXTURE2"))
+           if (! FindMasterDir (cfg.MasterDir, "TEXTURE2"))
            NumVertexes--;
            else
          */
@@ -110,8 +110,8 @@
 
     width = 2 * BOX_BORDER + 2 * WIDE_HSPACING + 33 * FONTW;
     height = 2 * BOX_BORDER + 2 * WIDE_VSPACING + 9 * FONTH;
-    out_x0 = (ScrMaxX + 1 - width) / 2;
-    out_y0 = (ScrMaxY + 1 - height) / 2;
+    out_x0 = (cfg.ScrMaxX + 1 - width) / 2;
+    out_y0 = (cfg.ScrMaxY + 1 - height) / 2;
     text_x0 = out_x0 + BOX_BORDER + WIDE_HSPACING;
     text_y0 = out_y0 + BOX_BORDER + WIDE_VSPACING;
     DrawScreenBox3D(out_x0, out_y0, out_x0 + width - 1, out_y0 + height - 1);
@@ -189,9 +189,9 @@
     int height =
         2 * BOX_BORDER + 2 * WIDE_VSPACING + FONTH * (prompt2 ? 6 : 5);
     if (x0 < 0)
-        x0 = (ScrMaxX - width) / 2;
+        x0 = (cfg.ScrMaxX - width) / 2;
     if (y0 < 0)
-        y0 = (ScrMaxY - height) / 2;
+        y0 = (cfg.ScrMaxY - height) / 2;
     int text_x0 = x0 + BOX_BORDER + WIDE_HSPACING;
     int text_y0 = y0 + BOX_BORDER + WIDE_VSPACING;
     int cur_y = text_y0;
@@ -443,7 +443,7 @@
             }
     }
     if (cur
-        && (Expert
+        && (cfg.Expert
             || Confirm(-1, -1,
                        "There are multiple linedefs between the same vertices",
                        "Do you want to delete the redundant linedefs?")))
@@ -456,7 +456,7 @@
     for (n = 0; n < NumLineDefs; n++)
         if ((LineDefs[n].flags & 0x01) == 0 && LineDefs[n].sidedef2 < 0)
             SelectObject(&cur, n);
-    if (cur && (Expert
+    if (cur && (cfg.Expert
                 || Confirm(-1, -1,
                            "Some linedefs have only one side but their I flag is"
                            " not set",
@@ -476,7 +476,7 @@
         if ((LineDefs[n].flags & 0x04) != 0 && LineDefs[n].sidedef2 < 0)
             SelectObject(&cur, n);
     if (cur
-        && (Expert
+        && (cfg.Expert
             || Confirm(-1, -1,
                        "Some linedefs have only one side but their 2 flag"
                        " is set",
@@ -497,7 +497,7 @@
         if ((LineDefs[n].flags & 0x04) == 0 && LineDefs[n].sidedef2 >= 0)
             SelectObject(&cur, n);
     if (cur
-        && (Expert
+        && (cfg.Expert
             || Confirm(-1, -1,
                        "Some linedefs have two sides but their 2S bit is not set",
                        "Do you want to set the 'two-sided' flag?")))
@@ -528,7 +528,7 @@
     }
 /* check if there are any Vertices left */
     if (cur
-        && (Expert
+        && (cfg.Expert
             || Confirm(-1, -1, "Some vertices are not bound to any linedef",
                        "Do you want to delete these unused Vertices?")))
     {
@@ -554,7 +554,7 @@
     }
 /* check if there are any SideDefs left */
     if (cur
-        && (Expert
+        && (cfg.Expert
             || Confirm(-1, -1, "Some sidedefs are not bound to any linedef",
                        "Do you want to delete these unused sidedefs?")))
         DeleteObjects(OBJ_SIDEDEFS, &cur);
@@ -578,7 +578,7 @@
     }
 /* check if there are any Sectors left */
     if (cur
-        && (Expert
+        && (cfg.Expert
             || Confirm(-1, -1, "Some sectors are not bound to any sidedef",
                        "Do you want to delete these unused sectors?")))
         DeleteObjects(OBJ_SECTORS, &cur);
@@ -661,13 +661,13 @@
                 sprintf(msg1, "Error in one-sided linedef #%d:"
                         " sidedef #%d has no middle texture", n, sd1);
                 sprintf(msg2, "Do you want to set the texture to \"%s\""
-                        " and continue?", default_middle_texture);
+                        " and continue?", cfg.def.middle_texture);
                 if (CheckFailed(-1, -1, msg1, msg2, 0, first_time))
                 {
                     GoToObject(Objid(OBJ_LINEDEFS, n));
                     return;
                 }
-                strncpy(SideDefs[sd1].tex3, default_middle_texture,
+                strncpy(SideDefs[sd1].tex3, cfg.def.middle_texture,
                         WAD_TEX_NAME);
                 MadeChanges = 1;
                 CheckingObjects();
@@ -682,13 +682,13 @@
                 sprintf(msg1, "Error in first sidedef of linedef #%d:"
                         " sidedef #%d has no upper texture", n, sd1);
                 sprintf(msg2, "Do you want to set the texture to \"%s\""
-                        " and continue?", default_upper_texture);
+                        " and continue?", cfg.def.upper_texture);
                 if (CheckFailed(-1, -1, msg1, msg2, 0, first_time))
                 {
                     GoToObject(Objid(OBJ_LINEDEFS, n));
                     return;
                 }
-                strncpy(SideDefs[sd1].tex1, default_upper_texture,
+                strncpy(SideDefs[sd1].tex1, cfg.def.upper_texture,
                         WAD_TEX_NAME);
                 MadeChanges = 1;
                 CheckingObjects();
@@ -703,13 +703,13 @@
                 sprintf(msg1, "Error in first sidedef of linedef #%d:"
                         " sidedef #%d has no lower texture", n, sd1);
                 sprintf(msg2, "Do you want to set the texture to \"%s\""
-                        " and continue?", default_lower_texture);
+                        " and continue?", cfg.def.lower_texture);
                 if (CheckFailed(-1, -1, msg1, msg2, 0, first_time))
                 {
                     GoToObject(Objid(OBJ_LINEDEFS, n));
                     return;
                 }
-                strncpy(SideDefs[sd1].tex2, default_lower_texture,
+                strncpy(SideDefs[sd1].tex2, cfg.def.lower_texture,
                         WAD_TEX_NAME);
                 MadeChanges = 1;
                 CheckingObjects();
@@ -724,13 +724,13 @@
                 sprintf(msg1, "Error in second sidedef of linedef #%d:"
                         " sidedef #%d has no upper texture", n, sd2);
                 sprintf(msg2, "Do you want to set the texture to \"%s\""
-                        " and continue?", default_upper_texture);
+                        " and continue?", cfg.def.upper_texture);
                 if (CheckFailed(-1, -1, msg1, msg2, 0, first_time))
                 {
                     GoToObject(Objid(OBJ_LINEDEFS, n));
                     return;
                 }
-                strncpy(SideDefs[sd2].tex1, default_upper_texture,
+                strncpy(SideDefs[sd2].tex1, cfg.def.upper_texture,
                         WAD_TEX_NAME);
                 MadeChanges = 1;
                 CheckingObjects();
@@ -745,13 +745,13 @@
                 sprintf(msg1, "Error in second sidedef of linedef #%d:"
                         " sidedef #%d has no lower texture", n, sd2);
                 sprintf(msg2, "Do you want to set the texture to \"%s\""
-                        " and continue?", default_lower_texture);
+                        " and continue?", cfg.def.lower_texture);
                 if (CheckFailed(-1, -1, msg1, msg2, 0, first_time))
                 {
                     GoToObject(Objid(OBJ_LINEDEFS, n));
                     return;
                 }
-                strncpy(SideDefs[sd2].tex2, default_lower_texture,
+                strncpy(SideDefs[sd2].tex2, cfg.def.lower_texture,
                         WAD_TEX_NAME);
                 MadeChanges = 1;
                 CheckingObjects();
@@ -791,7 +791,7 @@
     LogMessage("\nVerifying texture names...\n");
 
 // AYM 2000-07-24: could someone explain this one ?
-    if (!FindMasterDir(MasterDir, "F2_START"))
+    if (!FindMasterDir(cfg.MasterDir, "F2_START"))
         NumThings--;
 
     for (n = 0; n < NumSectors; n++)
@@ -901,7 +901,7 @@
         else
             return true;        // No point in doing further checking !
     }
-    if (Expert)
+    if (cfg.Expert)
         return true;
     if (!p2 || !p3 || !p4)
     {
--- a/src/colour4.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/colour4.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -156,7 +156,7 @@
 void free_colours(pcolour_t * pcn_table, size_t count)
 {
     verbmsg("colours: free_colours: count %d\n", count);
-    if (verbose)
+    if (cfg.verbose)
         dump_pcolours();
 
     if (pcn_table == NULL)        // Sanity
--- a/src/dialog.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/dialog.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -66,9 +66,9 @@
     height =
         2 * BOX_BORDER + 2 * WIDE_VSPACING + (int) (n_lines_of_text * FONTH);
     if (x0 < 0)
-        x0 = (ScrMaxX - width) / 2;
+        x0 = (cfg.ScrMaxX - width) / 2;
     if (y0 < 0)
-        y0 = (ScrMaxY - height) / 2;
+        y0 = (cfg.ScrMaxY - height) / 2;
     text_x0 = x0 + BOX_BORDER + WIDE_HSPACING;
     text_x1 = text_x0 + maxlen * FONTW - 1;
     x1 = text_x1 + WIDE_HSPACING + BOX_BORDER;
@@ -155,9 +155,9 @@
     height =
         2 * BOX_BORDER + 2 * WIDE_VSPACING + (int) (n_lines_of_text * FONTH);
     if (x0 < 0)
-        x0 = (ScrMaxX - width) / 2;
+        x0 = (cfg.ScrMaxX - width) / 2;
     if (y0 < 0)
-        y0 = (ScrMaxY - height) / 2;
+        y0 = (cfg.ScrMaxY - height) / 2;
     text_x0 = x0 + BOX_BORDER + WIDE_HSPACING;
     text_x1 = text_x0 + maxlen * FONTW - 1;
     x1 = text_x1 + WIDE_HSPACING + BOX_BORDER;
@@ -188,9 +188,9 @@
     int width = 2 * BOX_BORDER + 2 * WIDE_HSPACING + FONTW * strlen(prompt);
     int height = 2 * BOX_BORDER + 2 * WIDE_VSPACING + FONTH;
     if (x0 < 0)
-        x0 = (ScrMaxX - width) / 2;
+        x0 = (cfg.ScrMaxX - width) / 2;
     if (y0 < 0)
-        y0 = (ScrMaxY - height) / 2;
+        y0 = (cfg.ScrMaxY - height) / 2;
     DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1);
     push_colour(WINFG);
     DrawScreenText(x0 + BOX_BORDER + WIDE_HSPACING,
--- a/src/dialog.h	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/dialog.h	Mon Sep 26 17:39:49 2011 +0300
@@ -9,6 +9,5 @@
 int Confirm2(int x0, int y0, confirm_t * confirm_flag,
              const char *prompt1, const char *prompt2);
 void Notify(int, int, const char *, const char *);
-void debmes(const char *fmt, ...);
 void DisplayMessage(int, int, const char *, ...);
 void NotImplemented(void);
--- a/src/drawmap.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/drawmap.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -112,8 +112,8 @@
 void draw_map(edit_t * e)        /* SWAP! */
 {
     int mapx0 = MAPX(0);
-    int mapx9 = MAPX(ScrMaxX);
-    int mapy0 = MAPY(ScrMaxY);
+    int mapx9 = MAPX(cfg.ScrMaxX);
+    int mapy0 = MAPY(cfg.ScrMaxY);
     int mapy9 = MAPY(0);
     int n;
 
@@ -191,8 +191,8 @@
         return;
 
     int mapx0 = MAPX(0);
-    int mapx1 = MAPX(ScrMaxX);
-    int mapy0 = MAPY(ScrMaxY);
+    int mapx1 = MAPX(cfg.ScrMaxX);
+    int mapy0 = MAPY(cfg.ScrMaxY);
     int mapy1 = MAPY(0);
 
     int grid_step_1 = e->grid_step;        // Map units between dots
@@ -316,10 +316,10 @@
 static void draw_vertices(edit_t * e)
 {
     int mapx0 = MAPX(0);
-    int mapx9 = MAPX(ScrMaxX);
-    int mapy0 = MAPY(ScrMaxY);
+    int mapx9 = MAPX(cfg.ScrMaxX);
+    int mapy0 = MAPY(cfg.ScrMaxY);
     int mapy9 = MAPY(0);
-    const int r = vertex_radius(Scale);
+    const int r = vertex_radius(cfg.Scale);
 
     push_colour(LIGHTGREEN);
     for (int n = 0; n < NumVertices; n++)
@@ -358,8 +358,8 @@
  */
 static int ld_check(VPtr v1, VPtr v2)
 {
-    const int mapx0 = MAPX(0), mapx9 = MAPX(ScrMaxX),
-              mapy0 = MAPY(ScrMaxY), mapy9 = MAPY(0);
+    const int mapx0 = MAPX(0), mapx9 = MAPX(cfg.ScrMaxX),
+              mapy0 = MAPY(cfg.ScrMaxY), mapy9 = MAPY(0);
 
     return ((v1->x < mapx0 && v2->x < mapx0) || (v1->x > mapx9 && v2->x > mapx9) ||
             (v1->y < mapy0 && v2->y < mapy0) || (v1->y > mapy9 && v2->y > mapy9));
@@ -532,8 +532,8 @@
        if its centre is more than <max_radius> units
        beyond the edge of the screen. */
     int mapx0 = MAPX(0) - max_radius;
-    int mapx9 = MAPX(ScrMaxX) + max_radius;
-    int mapy0 = MAPY(ScrMaxY) - max_radius;
+    int mapx9 = MAPX(cfg.ScrMaxX) + max_radius;
+    int mapy0 = MAPY(cfg.ScrMaxY) - max_radius;
     int mapy9 = MAPY(0) + max_radius;
 
     push_colour(THING_REM);
@@ -700,16 +700,16 @@
 
 #ifdef NO_RENDER
     static double last_scale = 0;
-    if (last_scale != Scale)
+    if (last_scale != cfg.Scale)
     {
         Lump_loc loc;
         wad_res.sprites.loc_by_root("PLAY", loc);
         Img img;
         LoadPicture(img, "PLAYA0", loc, 0, 0);
         Img img_scaled;
-        scale_img(img, Scale * sprite_scale / 100, img_scaled);
+        scale_img(img, cfg.Scale * cfg.sprite_scale / 100, img_scaled);
         sprite.load(img_scaled, false);
-        last_scale = Scale;
+        last_scale = cfg.Scale;
     }
 #endif
     push_colour(CYAN);
@@ -725,15 +725,15 @@
             {
                 set_dim = true;
                 mapx0 = MAPX(0) - max_width / 2;
-                mapx9 = MAPX(ScrMaxX) + max_width / 2;
-                mapy0 = MAPY(ScrMaxY) - max_height / 2;
+                mapx9 = MAPX(cfg.ScrMaxX) + max_width / 2;
+                mapy0 = MAPY(cfg.ScrMaxY) - max_height / 2;
                 mapy9 = MAPY(0) + max_height / 2;
             }
             else
             {
                 mapx0 = MAPX(0) - dim->second.width / 2;
-                mapx9 = MAPX(ScrMaxX) + dim->second.width / 2;
-                mapy0 = MAPY(ScrMaxY) - dim->second.height / 2;
+                mapx9 = MAPX(cfg.ScrMaxX) + dim->second.width / 2;
+                mapy0 = MAPY(cfg.ScrMaxY) - dim->second.height / 2;
                 mapy9 = MAPY(0) + dim->second.height / 2;
             }
         }
@@ -766,7 +766,7 @@
                             sprite_dim_t(img_raw.width(), img_raw.height());
                         set_dim = false;
                     }
-                    scale_img(img_raw, Scale * sprite_scale / 100,
+                    scale_img(img_raw, cfg.Scale * cfg.sprite_scale / 100,
                               img_scaled);
                     if (get_thing_flags(t.type) & THINGDEF_SPECTRAL)
                         spectrify_img(img_scaled);
@@ -780,7 +780,7 @@
 
         // Display it
         if (sticker.is_clear())
-            draw_vint(t.type, SCREENX(mapx), SCREENY(mapy), Scale);
+            draw_vint(t.type, SCREENX(mapx), SCREENY(mapy), cfg.Scale);
         else
             sticker.draw(drw, 'c', SCREENX(mapx), SCREENY(mapy));
     }
--- a/src/edisplay.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/edisplay.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -120,11 +120,11 @@
     int redraw_from_scratch;
 
     // The poor hacker's geometry manager (FIXME: this needs work!)
-    infobar->set_x1(ScrMaxX);
-    infobar->set_y1(ScrMaxY);
+    infobar->set_x1(cfg.ScrMaxX);
+    infobar->set_y1(cfg.ScrMaxY);
     infobar->set_x0(0);
-    infobar->set_y0(ScrMaxY - (infobar->req_height() - 1));
-    objinfo->set_y1(e->infobar_shown ? infobar->get_y0() - 1 : ScrMaxY);
+    infobar->set_y0(cfg.ScrMaxY - (infobar->req_height() - 1));
+    objinfo->set_y1(e->infobar_shown ? infobar->get_y0() - 1 : cfg.ScrMaxY);
 
     /* Extract the interesting data from the edit_c object
        and feed it to the widgets. */
@@ -135,7 +135,7 @@
     infobar->set_changes(MadeMapChanges ? 2 : (MadeChanges ? 1 : 0));
     infobar->set_grid_snap(e->grid_snap);
     infobar->set_grid_step_locked(e->grid_step_locked);
-    infobar->set_scale(Scale);
+    infobar->set_scale(cfg.Scale);
     infobar->set_grid_step(e->grid_step);
     if (e->pointer_in_window)
         infobar->set_pointer(e->pointer_x, e->pointer_y);
--- a/src/editgrid.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/editgrid.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -36,6 +36,6 @@
 {
     if (!e->grid_step_locked)
         for (e->grid_step = e->grid_step_max;
-             e->grid_step * Scale / 2 >= grid_pixels_min; e->grid_step /= 2)
+             e->grid_step * cfg.Scale / 2 >= cfg.grid_pixels_min; e->grid_step /= 2)
             ;
 }
--- a/src/editlev.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/editlev.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -54,7 +54,7 @@
 {
     ReadWTextureNames();
     ReadFTextureNames();
-    patch_dir.refresh(MasterDir);
+    patch_dir.refresh(cfg.MasterDir);
     if (InitGfx())
         return;
 /* Call init_input_status() as shortly as possible after the creation
@@ -82,7 +82,7 @@
     {
 #if 0
         if (levelname == 0 || !levelname2levelno(levelname)
-            || !FindMasterDir(MasterDir, levelname))
+            || !FindMasterDir(cfg.MasterDir, levelname))
             levelname = SelectLevel(atoi(levelname));        /* returns "" on Esc */
         if (levelname2levelno(levelname))
         {
@@ -143,7 +143,7 @@
     }
   done:
     TermGfx();
-    if (!Registered)
+    if (!cfg.Registered)
         printf("Please register the game"
                " if you want to be able to save your changes.\n");
 
--- a/src/editloop.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/editloop.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -73,7 +73,6 @@
 
 
 static int zoom_fit(edit_t &);
-extern bool InfoShown;                /* should we display the info bar? */
 static int menubar_out_y1;        /* FIXME */
 
 
@@ -104,7 +103,7 @@
     int n = 0;                        /* number of levels in the dir. that match */
 
   get_levels_that_match:
-    for (dir = MasterDir; dir; dir = dir->next)
+    for (dir = cfg.MasterDir; dir; dir = dir->next)
     {
         if (levelname2levelno(dir->dir.name) > 0
             && (levelno == 0
@@ -230,12 +229,12 @@
     e.global = false;
     e.tool = TOOL_NORMAL;
     e.grid_step = 128;
-    e.grid_step_min = GridMin;
-    e.grid_step_max = GridMax;
+    e.grid_step_min = cfg.GridMin;
+    e.grid_step_max = cfg.GridMax;
     e.grid_step_locked = 0;
     e.grid_shown = 1;
     e.grid_snap = 1;
-    e.infobar_shown = (bool) InfoShown;
+    e.infobar_shown = cfg.InfoShown;
     e.objinfo_shown = true;
     e.show_object_numbers = false;
     e.show_things_squares = false;
@@ -260,19 +259,19 @@
     MadeMapChanges = 0;
 
 // Sane defaults
-    Scale = 1.0;
-    OrigX = 0;
-    OrigY = 0;
+    cfg.Scale = 1.0;
+    cfg.OrigX = 0;
+    cfg.OrigY = 0;
 
     edit_zoom_init();
 
-    if (zoom_default == 0)
+    if (cfg.zoom_default == 0)
     {
         zoom_fit(e);
     }
     else
     {
-        int r = edit_set_zoom(&e, zoom_default / 100.0);
+        int r = edit_set_zoom(&e, cfg.zoom_default / 100.0);
         if (r == 0)
             CenterMapAroundCoords((MapMinX + MapMaxX) / 2,
                                   (MapMinY + MapMaxY) / 2);
@@ -281,7 +280,7 @@
 
 /* Create the menu bar */
     {
-        e.menubar->compute_menubar_coords(0, 0, ScrMaxX, ScrMaxY);
+        e.menubar->compute_menubar_coords(0, 0, cfg.ScrMaxX, cfg.ScrMaxY);
 
         e.mb_menu[MBM_FILE] = new Menu(NULL,
                                        "~Save", YK_F2, 0,
@@ -862,7 +861,7 @@
         else if (is.key == YE_RESIZE)
         {
             SetWindowSize(is.width, is.height);
-            e.menubar->compute_menubar_coords(0, 0, ScrMaxX, ScrMaxY);
+            e.menubar->compute_menubar_coords(0, 0, cfg.ScrMaxX, cfg.ScrMaxY);
             RedrawMap = 1;
             goto done2;
         }
@@ -882,8 +881,8 @@
 
             if (deltaX != 0 || deltaY != 0)
             {
-                OrigX += (deltaX / Scale);
-                OrigY -= (deltaY / Scale);
+                cfg.OrigX += (deltaX / cfg.Scale);
+                cfg.OrigY -= (deltaY / cfg.Scale);
                 RedrawMap = 1;
                 DragMapMoveX = is.x;
                 DragMapMoveY = is.y;
@@ -974,7 +973,7 @@
                  && IsSelected(e.Selected, object.num)
                  && object == e.clicked
                  && is.time - e.click_time <=
-                 (unsigned long) double_click_timeout)
+                 (unsigned long) cfg.double_click_timeout)
         {
             // Very important! If you don't do that, the release of the
             // click that closed the properties menu will drag the object.
@@ -1210,7 +1209,7 @@
             else if (is.key == YK_F1 + YK_SHIFT)
             {
                 Rgbbmp b;
-                window_to_rgbbmp(0, 0, (int) ScrMaxX + 1, (int) ScrMaxY + 1,
+                window_to_rgbbmp(0, 0, (int) cfg.ScrMaxX + 1, (int) cfg.ScrMaxY + 1,
                                  b);
                 rgbbmp_to_rawppm(b, "yadex.ppm");
                 //ScreenShot ();
@@ -1235,7 +1234,7 @@
 
             /* [F2] save level into pwad, prompt for the file name
                every time but keep the same level name. */
-            else if (is.key == YK_F2 && Registered)
+            else if (is.key == YK_F2 && cfg.Registered)
             {
                 if (!CheckStartingPos())
                     goto cancel_save;
@@ -1255,14 +1254,14 @@
                 SaveLevelData(outfile, newlevelname);
                 levelname = newlevelname;
                 // Sigh. Shouldn't have to do that. Level must die !
-                Level = FindMasterDir(MasterDir, levelname);
+                Level = FindMasterDir(cfg.MasterDir, levelname);
               cancel_save:
                 RedrawMap = 1;
             }
 
             /* [F3] save level into pwad, prompt for the file name and
                level name. */
-            else if (is.key == YK_F3 && Registered)
+            else if (is.key == YK_F3 && cfg.Registered)
             {
                 char *outfile;
                 const char *newlevelname;
@@ -1277,7 +1276,7 @@
                 {
                     /* horrible but it works... */
                     // Horrible indeed -- AYM 1999-07-30
-                    newLevel = FindMasterDir(MasterDir, newlevelname);
+                    newLevel = FindMasterDir(cfg.MasterDir, newlevelname);
                     if (!newLevel)
                         nf_bug("newLevel is NULL");        // Debatable ! -- AYM 2001-05-29
                     if (Level)        // If new level ("create" command), Level is NULL
@@ -1450,58 +1449,58 @@
 
 
             // [Left], [Right], [Up], [Down]:
-            // scroll <scroll_less> percents of a screenful.
-            else if (is.key == YK_LEFT && MAPX(ScrCenterX) > -20000)
+            // scroll <cfg.scroll_less> percents of a screenful.
+            else if (is.key == YK_LEFT && MAPX(cfg.ScrCenterX) > -20000)
             {
-                OrigX -= (int) ((double) ScrMaxX * scroll_less / 100 / Scale);
+                cfg.OrigX -= (int) ((double) cfg.ScrMaxX * cfg.scroll_less / 100 / cfg.Scale);
                 RedrawMap = 1;
             }
-            else if (is.key == YK_RIGHT && MAPX(ScrCenterX) < 20000)
+            else if (is.key == YK_RIGHT && MAPX(cfg.ScrCenterX) < 20000)
             {
-                OrigX += (int) ((double) ScrMaxX * scroll_less / 100 / Scale);
+                cfg.OrigX += (int) ((double) cfg.ScrMaxX * cfg.scroll_less / 100 / cfg.Scale);
                 RedrawMap = 1;
             }
-            else if (is.key == YK_UP && MAPY(ScrCenterY) < 20000)
+            else if (is.key == YK_UP && MAPY(cfg.ScrCenterY) < 20000)
             {
-                OrigY += (int) ((double) ScrMaxY * scroll_less / 100 / Scale);
+                cfg.OrigY += (int) ((double) cfg.ScrMaxY * cfg.scroll_less / 100 / cfg.Scale);
                 RedrawMap = 1;
             }
-            else if (is.key == YK_DOWN && MAPY(ScrCenterY) > -20000)
+            else if (is.key == YK_DOWN && MAPY(cfg.ScrCenterY) > -20000)
             {
-                OrigY -= (int) ((double) ScrMaxY * scroll_less / 100 / Scale);
+                cfg.OrigY -= (int) ((double) cfg.ScrMaxY * cfg.scroll_less / 100 / cfg.Scale);
                 RedrawMap = 1;
             }
 
             // [Pgup], [Pgdn], [Home], [End]:
-            // scroll <scroll_more> percents of a screenful.
-            else if (is.key == YK_PU && MAPY(ScrCenterY) < /*MapMaxY */ 20000)
+            // scroll <cfg.scroll_more> percents of a screenful.
+            else if (is.key == YK_PU && MAPY(cfg.ScrCenterY) < /*MapMaxY */ 20000)
             {
-                OrigY += (int) ((double) ScrMaxY * scroll_more / 100 / Scale);
+                cfg.OrigY += (int) ((double) cfg.ScrMaxY * cfg.scroll_more / 100 / cfg.Scale);
                 RedrawMap = 1;
             }
             else if (is.key == YK_PD
-                     && MAPY(ScrCenterY) > /*MapMinY */ -20000)
+                     && MAPY(cfg.ScrCenterY) > /*MapMinY */ -20000)
             {
-                OrigY -= (int) ((double) ScrMaxY * scroll_more / 100 / Scale);
+                cfg.OrigY -= (int) ((double) cfg.ScrMaxY * cfg.scroll_more / 100 / cfg.Scale);
                 RedrawMap = 1;
             }
             else if (is.key == YK_HOME
-                     && MAPX(ScrCenterX) > /*MapMinX */ -20000)
+                     && MAPX(cfg.ScrCenterX) > /*MapMinX */ -20000)
             {
-                OrigX -= (int) ((double) ScrMaxX * scroll_more / 100 / Scale);
+                cfg.OrigX -= (int) ((double) cfg.ScrMaxX * cfg.scroll_more / 100 / cfg.Scale);
                 RedrawMap = 1;
             }
             else if (is.key == YK_END
-                     && MAPX(ScrCenterX) < /*MapMaxX */ 20000)
+                     && MAPX(cfg.ScrCenterX) < /*MapMaxX */ 20000)
             {
-                OrigX += (int) ((double) ScrMaxX * scroll_more / 100 / Scale);
+                cfg.OrigX += (int) ((double) cfg.ScrMaxX * cfg.scroll_more / 100 / cfg.Scale);
                 RedrawMap = 1;
             }
 
             else if (is.key == ' ')
             {
                 e.extra_zoom = !e.extra_zoom;
-                edit_set_zoom(&e, Scale * (e.extra_zoom ? 4 : 0.25));
+                edit_set_zoom(&e, cfg.Scale * (e.extra_zoom ? 4 : 0.25));
                 RedrawMap = 1;
             }
 
@@ -1639,7 +1638,7 @@
                     else
                         ForgetSelection(&e.Selected);
                 }
-                if (GetMaxObjectNum(e.obj_type) >= 0 && Select0 && !e.global)
+                if (GetMaxObjectNum(e.obj_type) >= 0 && cfg.Select0 && !e.global)
                 {
                     e.highlighted.type = e.obj_type;
                     e.highlighted.num = 0;
@@ -2066,7 +2065,7 @@
             else if (is.key == YK_DEL && (e.Selected || e.highlighted()))        /* 'Del' */
             {
                 if (e.obj_type == OBJ_THINGS
-                    || Expert
+                    || cfg.Expert
                     || Confirm(-1, -1,
                                (e.Selected && e.Selected->next ?
                                 "Do you really want to delete these objects?"
@@ -2444,45 +2443,43 @@
         // through the menus.
 
         if (is.in_window
-            && autoscroll && !is.scroll_lock && e.menubar->pulled_down() < 0)
+            && cfg.autoscroll && !is.scroll_lock && e.menubar->pulled_down() < 0)
         {
             unsigned distance;        // In pixels
 
 #define actual_move(total,dist) \
-   ((int) (((total * autoscroll_amp / 100)\
-   * ((double) (autoscroll_edge - dist) / autoscroll_edge))\
-   / Scale))
+   ((int) (((total * cfg.autoscroll_amp / 100) * ((double) (cfg.autoscroll_edge - dist) / cfg.autoscroll_edge)) / cfg.Scale))
 
             distance = is.y;
             // The reason for the second member of the condition
             // is that we don't want to scroll when the user is
             // simply reaching for a menu...
-            if (distance <= autoscroll_edge
+            if (distance <= cfg.autoscroll_edge
                 && e.menubar->is_under_menubar_item(is.x) < 0)
             {
-                if (MAPY(ScrCenterY) < /*MapMaxY */ 20000)
+                if (MAPY(cfg.ScrCenterY) < /*MapMaxY */ 20000)
                 {
-                    OrigY += actual_move(ScrMaxY, distance);
+                    cfg.OrigY += actual_move(cfg.ScrMaxY, distance);
                     RedrawMap = 1;
                 }
             }
 
-            distance = ScrMaxY - is.y;
-            if (distance <= autoscroll_edge)
+            distance = cfg.ScrMaxY - is.y;
+            if (distance <= cfg.autoscroll_edge)
             {
-                if (MAPY(ScrCenterY) > /*MapMinY */ -20000)
+                if (MAPY(cfg.ScrCenterY) > /*MapMinY */ -20000)
                 {
-                    OrigY -= actual_move(ScrMaxY, distance);
+                    cfg.OrigY -= actual_move(cfg.ScrMaxY, distance);
                     RedrawMap = 1;
                 }
             }
 
             distance = is.x;
-            if (distance <= autoscroll_edge)
+            if (distance <= cfg.autoscroll_edge)
             {
-                if (MAPX(ScrCenterX) > /*MapMinX */ -20000)
+                if (MAPX(cfg.ScrCenterX) > /*MapMinX */ -20000)
                 {
-                    OrigX -= actual_move(ScrMaxX, distance);
+                    cfg.OrigX -= actual_move(cfg.ScrMaxX, distance);
                     RedrawMap = 1;
                 }
             }
@@ -2492,12 +2489,12 @@
             // simply reaching for the "Help" menu...
             // Note: the ordinate "3 * FONTH" is of course not
             // critical. It's just a rough approximation.
-            distance = ScrMaxX - is.x;
-            if (distance <= autoscroll_edge && (unsigned) is.y >= 3 * FONTH)
+            distance = cfg.ScrMaxX - is.x;
+            if (distance <= cfg.autoscroll_edge && (unsigned) is.y >= 3 * FONTH)
             {
-                if (MAPX(ScrCenterX) < /*MapMaxX */ 20000)
+                if (MAPX(cfg.ScrCenterX) < /*MapMaxX */ 20000)
                 {
-                    OrigX += actual_move(ScrMaxX, distance);
+                    cfg.OrigX += actual_move(cfg.ScrMaxX, distance);
                     RedrawMap = 1;
                 }
             }
@@ -2548,8 +2545,8 @@
     int MapSizeX = MapMaxX - MapMinX,
         MapSizeY = MapMaxY - MapMinY;
 
-    double xzoom = MapSizeX ? (0.95f * ScrMaxX / (double) MapSizeX) : 1,
-           yzoom = MapSizeY ? (0.9f * ScrMaxY / (double) MapSizeY) : 1;
+    double xzoom = MapSizeX ? (0.95f * cfg.ScrMaxX / (double) MapSizeX) : 1,
+           yzoom = MapSizeY ? (0.9f * cfg.ScrMaxY / (double) MapSizeY) : 1;
 
     int r = edit_set_zoom(&e, y_min(xzoom, yzoom));
     if (r != 0)
--- a/src/editobj.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/editobj.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -61,9 +61,9 @@
     sprintf(prompt, "Enter a %s number between 0 and %d:",
             GetObjectTypeName(objtype), GetMaxObjectNum(objtype));
     if (x0 < 0)
-        x0 = (ScrMaxX - 25 - 8 * strlen(prompt)) / 2;
+        x0 = (cfg.ScrMaxX - 25 - 8 * strlen(prompt)) / 2;
     if (y0 < 0)
-        y0 = (ScrMaxY - 55) / 2;
+        y0 = (cfg.ScrMaxY - 55) / 2;
     DrawScreenBox3D(x0, y0, x0 + 25 + 8 * strlen(prompt), y0 + 55);
     set_colour(WHITE);
     DrawScreenText(x0 + 10, y0 + 8, prompt);
@@ -92,9 +92,9 @@
     sprintf(prompt, "Enter a %s number between 0 and %d:",
             GetObjectTypeName(init.type), GetMaxObjectNum(init.type));
     if (x0 < 0)
-        x0 = (ScrMaxX - 25 - 8 * strlen(prompt)) / 2;
+        x0 = (cfg.ScrMaxX - 25 - 8 * strlen(prompt)) / 2;
     if (y0 < 0)
-        y0 = (ScrMaxY - 55) / 2;
+        y0 = (cfg.ScrMaxY - 55) / 2;
     DrawScreenBox3D(x0, y0, x0 + 25 + 8 * strlen(prompt), y0 + 55);
     set_colour(WHITE);
     DrawScreenText(x0 + 10, y0 + 8, prompt);
@@ -163,9 +163,9 @@
 
 // Position
     if (x0 < 0)
-        x0 = (ScrMaxX - width) / 2;
+        x0 = (cfg.ScrMaxX - width) / 2;
     if (y0 < 0)
-        y0 = (ScrMaxY - height) / 2;
+        y0 = (cfg.ScrMaxY - height) / 2;
 
     DrawScreenBox3D(x0, y0, x0 + width, y0 + height);
     set_colour(WHITE);
@@ -217,9 +217,9 @@
     else
         maxlen = strlen(prompt2);
     if (x0 < 0)
-        x0 = (ScrMaxX - 25 - 8 * maxlen) / 2;
+        x0 = (cfg.ScrMaxX - 25 - 8 * maxlen) / 2;
     if (y0 < 0)
-        y0 = (ScrMaxY - 75) / 2;
+        y0 = (cfg.ScrMaxY - 75) / 2;
     text_x0 = x0 + BOX_BORDER + WIDE_HSPACING;
     text_y0 = y0 + BOX_BORDER + WIDE_VSPACING;
     entry1_x0 = text_x0 + 13 * FONTW;
@@ -424,9 +424,9 @@
     }
 
     if (x0 < 0)
-        x0 = (ScrMaxX - window_x1) / 2;
+        x0 = (cfg.ScrMaxX - window_x1) / 2;
     if (y0 < 0)
-        y0 = (ScrMaxY - window_y1) / 2;
+        y0 = (cfg.ScrMaxY - window_y1) / 2;
 
     DrawScreenBox3D(x0, y0, x0 + window_x1, y0 + window_y1);
     set_colour(WHITE);
@@ -937,8 +937,8 @@
         // Linedefs -> Swap sidedefs
         if (objtype == OBJ_LINEDEFS)
         {
-            if (Expert
-                || blindly_swap_sidedefs
+            if (cfg.Expert
+                || cfg.blindly_swap_sidedefs
                 || Confirm(-1, -1,
                            "Warning: the sector references are also swapped",
                            "You may get strange results if you don't know what you are doing..."))
@@ -1000,7 +1000,7 @@
                     struct SideDef *s = SideDefs + l->sidedef1;
                     strcpy(s->tex1, "-");
                     strcpy(s->tex2, "-");
-                    strcpy(s->tex3, default_middle_texture);
+                    strcpy(s->tex3, cfg.def.middle_texture);
                 }
                 /* Don't delete the 2nd sidedef, it could be used
                    by another linedef. And if it isn't, the next
--- a/src/editsave.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/editsave.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -118,7 +118,7 @@
   try_again:
 
     // If necessary, prompt for new level name and file name
-    if (prompt || !fncmp(level_name, MainWad))
+    if (prompt || !fncmp(level_name, cfg.MainWad))
     {
         int r = e.loop();
         if (!r)                        // Cancelled by user
@@ -190,7 +190,7 @@
     }
 
     if (!Level
-        || !Level->wadfile || !fncmp(Level->wadfile->filename, MainWad))
+        || !Level->wadfile || !fncmp(Level->wadfile->filename, cfg.MainWad))
     {
         al_scpslower(outfile, levelname, BUFSZ);
         al_saps(outfile, ".wad", BUFSZ);
@@ -199,7 +199,7 @@
         strcpy(outfile, Level->wadfile->filename);
     do
         InputFileName(-1, -1, "Name of the new wad file:", BUFSZ, outfile);
-    while (!fncmp(outfile, MainWad));
+    while (!fncmp(outfile, cfg.MainWad));
     /* escape */
     if (outfile[0] == '\0')
     {
--- a/src/editzoom.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/editzoom.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -41,9 +41,8 @@
 
 void edit_zoom_init()
 {
-    double factor = digit_zoom_base / 100.0;
-    double step = digit_zoom_step != 0 ? (digit_zoom_step + 100.0) / 100
-        : pow(2, -.5);
+    double factor = cfg.digit_zoom_base / 100.0;
+    double step = cfg.digit_zoom_step != 0 ? (cfg.digit_zoom_step + 100.0) / 100 : pow(2, -.5);
     for (int i = 1; i <= 10; i++, factor *= step)
         digit_zoom_factors[i % 10] = factor;
 }
@@ -53,14 +52,14 @@
 {
     if (!e)
         return 1;                // Prevent compiler warning about unused .p.
-    double step = zoom_step != 0 ? (zoom_step + 100.0) / 100 : sqrt(2);
-    if (Scale * step > 10.0)
+    double step = cfg.zoom_step != 0 ? (cfg.zoom_step + 100.0) / 100 : sqrt(2);
+    if (cfg.Scale * step > 10.0)
         return 1;
-    OrigX += (int) ((is.x - ScrCenterX) / Scale);
-    OrigY += (int) ((ScrCenterY - is.y) / Scale);
-    Scale *= step;
-    OrigX -= (int) ((is.x - ScrCenterX) / Scale);
-    OrigY -= (int) ((ScrCenterY - is.y) / Scale);
+    cfg.OrigX += (int) ((is.x - cfg.ScrCenterX) / cfg.Scale);
+    cfg.OrigY += (int) ((cfg.ScrCenterY - is.y) / cfg.Scale);
+    cfg.Scale *= step;
+    cfg.OrigX -= (int) ((is.x - cfg.ScrCenterX) / cfg.Scale);
+    cfg.OrigY -= (int) ((cfg.ScrCenterY - is.y) / cfg.Scale);
     send_event(YE_ZOOM_CHANGED);
     return 0;
 }
@@ -70,14 +69,14 @@
 {
     if (!e)
         return 1;                // Prevent compiler warning about unused .p.
-    double step = zoom_step != 0 ? (zoom_step + 100.0) / 100 : sqrt(2);
-    if (Scale / step < 0.05)
+    double step = cfg.zoom_step != 0 ? (cfg.zoom_step + 100.0) / 100 : sqrt(2);
+    if (cfg.Scale / step < 0.05)
         return 1;
-    OrigX += (int) ((is.x - ScrCenterX) / Scale);
-    OrigY += (int) ((ScrCenterY - is.y) / Scale);
-    Scale /= step;
-    OrigX -= (int) ((is.x - ScrCenterX) / Scale);
-    OrigY -= (int) ((ScrCenterY - is.y) / Scale);
+    cfg.OrigX += (int) ((is.x - cfg.ScrCenterX) / cfg.Scale);
+    cfg.OrigY += (int) ((cfg.ScrCenterY - is.y) / cfg.Scale);
+    cfg.Scale /= step;
+    cfg.OrigX -= (int) ((is.x - cfg.ScrCenterX) / cfg.Scale);
+    cfg.OrigY -= (int) ((cfg.ScrCenterY - is.y) / cfg.Scale);
     send_event(YE_ZOOM_CHANGED);
     return 0;
 }
@@ -91,11 +90,11 @@
         zoom_factor = 0.05;
     if (zoom_factor > 10.0)
         zoom_factor = 10.0;
-    OrigX += (int) ((is.x - ScrCenterX) / Scale);
-    OrigY += (int) ((ScrCenterY - is.y) / Scale);
-    Scale = zoom_factor;
-    OrigX -= (int) ((is.x - ScrCenterX) / Scale);
-    OrigY -= (int) ((ScrCenterY - is.y) / Scale);
+    cfg.OrigX += (int) ((is.x - cfg.ScrCenterX) / cfg.Scale);
+    cfg.OrigY += (int) ((cfg.ScrCenterY - is.y) / cfg.Scale);
+    cfg.Scale = zoom_factor;
+    cfg.OrigX -= (int) ((is.x - cfg.ScrCenterX) / cfg.Scale);
+    cfg.OrigY -= (int) ((cfg.ScrCenterY - is.y) / cfg.Scale);
     send_event(YE_ZOOM_CHANGED);
     return 0;
 }
--- a/src/entry.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/entry.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -143,9 +143,9 @@
     y_snprintf(prompt, sizeof prompt,
                "Enter a number between %d and %d:", minv, maxv);
     if (x0 < 0)
-        x0 = (ScrMaxX - 25 - FONTW * strlen(prompt)) / 2;
+        x0 = (cfg.ScrMaxX - 25 - FONTW * strlen(prompt)) / 2;
     if (y0 < 0)
-        y0 = (ScrMaxY - 55) / 2;
+        y0 = (cfg.ScrMaxY - 55) / 2;
     DrawScreenBox3D(x0, y0, x0 + 25 + FONTW * strlen(prompt), y0 + 55);
     set_colour(WHITE);
     DrawScreenText(x0 + 10, y0 + 8, prompt);
@@ -198,9 +198,9 @@
     width += 2 * BOX_BORDER + 2 * WIDE_HSPACING;
 
     if (x0 < 0)
-        x0 = (ScrMaxX - width) / 2;
+        x0 = (cfg.ScrMaxX - width) / 2;
     if (y0 < 0)
-        y0 = (ScrMaxY - 2 * BOX_BORDER
+        y0 = (cfg.ScrMaxY - 2 * BOX_BORDER
               - 2 * WIDE_VSPACING
               - (int) (2.5 * FONTH)
               - 2 * HOLLOW_BORDER - 2 * NARROW_VSPACING) / 2;
--- a/src/entry2.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/entry2.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -631,9 +631,9 @@
 
     // Compute the absolute coordinates
     if (win_x0 < 0)
-        win_x0 = (ScrMaxX - outer_width) / 2;
+        win_x0 = (cfg.ScrMaxX - outer_width) / 2;
     if (win_y0 < 0)
-        win_y0 = (ScrMaxY - outer_height) / 2;
+        win_y0 = (cfg.ScrMaxY - outer_height) / 2;
     win_x1 = win_x0 + outer_width - 1;
     win_y1 = win_y0 + outer_height - 1;
     title_x0 = win_x0 + win_hofs;
--- a/src/gcolour1.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/gcolour1.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -59,7 +59,7 @@
     u8 *dpal;
     pcolour_t *game_colours = 0;
 
-    dir = FindMasterDir(MasterDir, "PLAYPAL");
+    dir = FindMasterDir(cfg.MasterDir, "PLAYPAL");
     if (dir == NULL)
     {
         warn("PLAYPAL lump not found.\n");
--- a/src/gfx.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/gfx.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -51,20 +51,11 @@
 const char *font_name = NULL;        // X: the name of the font to load
 Win_dim initial_window_width("90%");        // X: the name says it all
 Win_dim initial_window_height("90%");        // X: the name says it all
-int no_pixmap;                        // X: use no pixmap -- direct window output
-int VideoMode = 2;                // BGI: default video mode for VESA cards
 
 /* Global variables */
 int GfxMode = 0;                // graphics mode number, or 0 for text
                         // 1 = 320x200, 2 = 640x480, 3 = 800x600, 4 = 1kx768
                         // positive = 16 colors, negative = 256 colors
-int OrigX;                        // Map X-coord of centre of screen/window
-int OrigY;                        // Map Y-coord of centre of screen/window
-float Scale;                        // the scale value
-int ScrMaxX;                        // Maximum display X-coord of screen/window
-int ScrMaxY;                        // Maximum display Y-coord of screen/window
-int ScrCenterX;                        // Display X-coord of centre of screen/window
-int ScrCenterY;                        // Display Y-coord of centre of screen/window
 unsigned FONTH;
 unsigned FONTW;
 int font_xofs;
@@ -105,7 +96,6 @@
 static pcolour_t *app_colour = 0;        // Pixel values for the app. colours
 static int DrawingMode = 0;        // 0 = copy, 1 = xor
 static int LineThickness = 0;        // 0 = thin, 1 = thick
-int text_dot = 0;                // DrawScreenText() debug flag
 
 static acolour_t colour_stack[4];
 static int colour_stack_pointer = 0;
@@ -151,7 +141,7 @@
             verbmsg("unknown\n");
             warn("don't understand X server's endianness code %d\n", r);
             warn("assuming same endianness as CPU.\n");
-            x_server_big_endian = cpu_big_endian;
+            x_server_big_endian = cfg.cpu_big_endian;
         }
     }
     int screen_width = DisplayWidth(dpy, scn);
@@ -442,7 +432,7 @@
     XMapWindow(dpy, win);
 
     // Unless no_pixmap is set, create the pixmap and its own pet GC.
-    if (no_pixmap)
+    if (cfg.no_pixmap)
         drw = win;
     else
     {
@@ -457,7 +447,7 @@
         drw_mods = 0;                // Force display the first time
     }
     XSync(dpy, False);
-    GfxMode = -VideoMode;
+    GfxMode = -2;
 
     SetWindowSize(width, height);
     return 0;
@@ -474,7 +464,7 @@
     {
         int r;
 
-        if (!no_pixmap)
+        if (!cfg.no_pixmap)
         {
             XFreePixmap(dpy, pixmap);
             XFreeGC(dpy, pixmap_gc);
@@ -511,16 +501,16 @@
 void SetWindowSize(int width, int height)
 {
     // Am I called uselessly ?
-    if (width == ScrMaxX + 1 && height == ScrMaxY + 1)
+    if (width == cfg.ScrMaxX + 1 && height == cfg.ScrMaxY + 1)
         return;
 
-    ScrMaxX = width - 1;
-    ScrMaxY = height - 1;
-    ScrCenterX = ScrMaxX / 2;
-    ScrCenterY = ScrMaxY / 2;
+    cfg.ScrMaxX = width - 1;
+    cfg.ScrMaxY = height - 1;
+    cfg.ScrCenterX = cfg.ScrMaxX / 2;
+    cfg.ScrCenterY = cfg.ScrMaxY / 2;
 
     // Replace the old pixmap by another of the new size
-    if (!no_pixmap)
+    if (!cfg.no_pixmap)
     {
         XFreePixmap(dpy, pixmap);
         pixmap = XCreatePixmap(dpy, win, width, height, win_depth);
@@ -534,12 +524,12 @@
  */
 void ClearScreen()
 {
-    if (no_pixmap)
+    if (cfg.no_pixmap)
         XClearWindow(dpy, win);
     else
     {
-        XFillRectangle(dpy, pixmap, pixmap_gc, 0, 0, ScrMaxX + 1,
-                       ScrMaxY + 1);
+        XFillRectangle(dpy, pixmap, pixmap_gc, 0, 0, cfg.ScrMaxX + 1,
+                       cfg.ScrMaxY + 1);
         drw = pixmap;                // Redisplaying from scratch so let's use the pixmap
     }
 }
@@ -563,10 +553,10 @@
     //   return;
     //printf (" [");
     //fflush (stdout);
-    if (!no_pixmap && drw == pixmap)
+    if (!cfg.no_pixmap && drw == pixmap)
     {
         //putchar ('*');
-        XCopyArea(dpy, pixmap, win, pixmap_gc, 0, 0, ScrMaxX + 1, ScrMaxY + 1,
+        XCopyArea(dpy, pixmap, win, pixmap_gc, 0, 0, cfg.ScrMaxX + 1, cfg.ScrMaxY + 1,
                   0, 0);
     }
     XFlush(dpy);
@@ -743,8 +733,8 @@
 {
     XDrawArc(dpy, drw, gc, SCREENX(mapx - mapradius),
              SCREENY(mapy + mapradius),
-             (unsigned int) (2 * mapradius * Scale),
-             (unsigned int) (2 * mapradius * Scale), 0, 360 * 64);
+             (unsigned int) (2 * mapradius * cfg.Scale),
+             (unsigned int) (2 * mapradius * cfg.Scale), 0, 360 * 64);
     drw_mods++;
 }
 
@@ -765,17 +755,17 @@
     /* AYM 19980216 to avoid getting huge arrowheads when zooming in */
     int scrXoff =
         (r >=
-         1.0) ? (int) ((scrx1 - scrx2) * 8.0 / r * (Scale <
-                                                    1 ? Scale : 1)) : 0;
+         1.0) ? (int) ((scrx1 - scrx2) * 8.0 / r * (cfg.Scale <
+                                                    1 ? cfg.Scale : 1)) : 0;
     int scrYoff =
         (r >=
-         1.0) ? (int) ((scry1 - scry2) * 8.0 / r * (Scale <
-                                                    1 ? Scale : 1)) : 0;
+         1.0) ? (int) ((scry1 - scry2) * 8.0 / r * (cfg.Scale <
+                                                    1 ? cfg.Scale : 1)) : 0;
 #else
     int scrXoff =
-        (r >= 1.0) ? (int) ((scrx1 - scrx2) * 8.0 / r * (Scale / 2)) : 0;
+        (r >= 1.0) ? (int) ((scrx1 - scrx2) * 8.0 / r * (cfg.Scale / 2)) : 0;
     int scrYoff =
-        (r >= 1.0) ? (int) ((scry1 - scry2) * 8.0 / r * (Scale / 2)) : 0;
+        (r >= 1.0) ? (int) ((scry1 - scry2) * 8.0 / r * (cfg.Scale / 2)) : 0;
 #endif
 
     XDrawLine(dpy, drw, gc, scrx1, scry1, scrx2, scry2);
@@ -802,17 +792,17 @@
 #if 0
     int scrXoff =
         (r >=
-         1.0) ? (int) ((scrx1 - scrx2) * 8.0 / r * (Scale <
-                                                    1 ? Scale : 1)) : 0;
+         1.0) ? (int) ((scrx1 - scrx2) * 8.0 / r * (cfg.Scale <
+                                                    1 ? cfg.Scale : 1)) : 0;
     int scrYoff =
         (r >=
-         1.0) ? (int) ((scry1 - scry2) * 8.0 / r * (Scale <
-                                                    1 ? Scale : 1)) : 0;
+         1.0) ? (int) ((scry1 - scry2) * 8.0 / r * (cfg.Scale <
+                                                    1 ? cfg.Scale : 1)) : 0;
 #else
     int scrXoff =
-        (r >= 1.0) ? (int) ((scrx1 - scrx2) * 8.0 / r * (Scale / 2)) : 0;
+        (r >= 1.0) ? (int) ((scrx1 - scrx2) * 8.0 / r * (cfg.Scale / 2)) : 0;
     int scrYoff =
-        (r >= 1.0) ? (int) ((scry1 - scry2) * 8.0 / r * (Scale / 2)) : 0;
+        (r >= 1.0) ? (int) ((scry1 - scry2) * 8.0 / r * (cfg.Scale / 2)) : 0;
 #endif
 
     XDrawLine(dpy, drw, gc, scrx1, scry1, scrx2, scry2);
@@ -1180,7 +1170,7 @@
         }
         set_colour(save);
     }
-    if (text_dot)
+    if (cfg.text_dot)
         XDrawPoint(dpy, drw, gc, x, y);
     drw_mods++;
 
@@ -1202,7 +1192,7 @@
 void DrawScreenChar(int x, int y, char c)
 {
     XDrawString(dpy, drw, gc, x - font_xofs, y + font_yofs, &c, 1);
-    if (text_dot)
+    if (cfg.text_dot)
         XDrawPoint(dpy, drw, gc, x, y);
     drw_mods++;
 }
--- a/src/gfx.h	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/gfx.h	Mon Sep 26 17:39:49 2011 +0300
@@ -48,15 +48,9 @@
                                 // (if NULL, use the default)
 extern Win_dim initial_window_width;        // X: the name says it all
 extern Win_dim initial_window_height;        // X: the name says it all
-extern int no_pixmap;                // X: use no pixmap -- direct window output
-extern int VideoMode;                // BGI: default video mode for VESA cards
 
 /* Global variables */
 extern int GfxMode;
-extern int OrigX;                // Map X-coord of centre of screen/window
-extern int OrigY;                // Map Y-coord of centre of screen/window
-extern int ScrCenterX;                // Display X-coord of center of screen/window
-extern int ScrCenterY;                // Display Y-coord of center of screen/window
 typedef unsigned long xpv_t;        // The type of a pixel value in X's opinion
 #ifdef X_PROTOCOL
 extern Display *dpy;
@@ -72,7 +66,6 @@
 extern int ximage_bpp;                // Number of bytes per pixels in XImages
 extern int ximage_quantum;        // Pad XImage lines to a mult of that many B.
 #endif // ifdef X_PROTOCOL
-extern int text_dot;                // DrawScreenText()/DrawScreenString() debug flag
 
 /* gfx.cc */
 int InitGfx(void);
--- a/src/gotoobj.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/gotoobj.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -43,14 +43,14 @@
  */
 void CenterMapAroundCoords(int xpos, int ypos)
 {
-    OrigX = xpos;
-    OrigY = ypos;
+    cfg.OrigX = xpos;
+    cfg.OrigY = ypos;
 /* AYM 1998-09-20 This is a DOS-ism. IIRC, the ICCCM says an
    application program should generally not mess with the
    pointer. */
 #if 0
-    is.x = ScrCenterX;
-    is.y = ScrCenterY;
+    is.x = cfg.ScrCenterX;
+    is.y = cfg.ScrCenterY;
 #endif
 }
 
@@ -62,8 +62,8 @@
  */
 void focus_on_map_coords(int x, int y)
 {
-    OrigX = x - (MAPX(is.x) - OrigX);
-    OrigY = y - (MAPY(is.y) - OrigY);
+    cfg.OrigX = x - (MAPX(is.x) - cfg.OrigX);
+    cfg.OrigY = y - (MAPY(is.y) - cfg.OrigY);
 }
 
 
@@ -92,7 +92,7 @@
 
     GetObjectCoords(objid.type, objid.num, &xpos, &ypos);
     focus_on_map_coords(xpos, ypos);
-    oldscale = Scale;
+    oldscale = cfg.Scale;
 
 /* I ifdef'd out this block because the only thing it really
    does is (uselessly) messing the zoom factor up when there are
@@ -100,13 +100,13 @@
    highest-numbered (and therefore hidden) one. AYM 1999-07-26 */
 #if 0
 /* zoom in until the object can be selected */
-    while (Scale < 8.0
+    while (cfg.Scale < 8.0
            && GetCurObject(objid.type, MAPX(is.x), MAPY(is.y)) != objid.num)
     {
-        if (Scale < 1.0)
-            Scale = 1.0 / ((1.0 / Scale) - 1.0);
+        if (cfg.Scale < 1.0)
+            cfg.Scale = 1.0 / ((1.0 / cfg.Scale) - 1.0);
         else
-            Scale = Scale * 2.0;
+            cfg.Scale *= 2.0;
     }
 #endif
 
@@ -124,7 +124,7 @@
     if (objid.type == OBJ_SECTORS && sector_under_pointer() != objid.num)
     {
         /* restore the Scale */
-        Scale = oldscale;
+        cfg.Scale = oldscale;
         for (int n = 0; n < NumLineDefs; n++)
         {
             sd1 = LineDefs[n].sidedef1;
--- a/src/help2.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/help2.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -95,8 +95,8 @@
     }
     width = (maxlen + 4) * FONTW + 2 * BOX_BORDER;
     height = lines * FONTH + 2 * BOX_BORDER;
-    x0 = (ScrMaxX + 1 - width) / 2;
-    y0 = (ScrMaxY + 1 - height) / 2;
+    x0 = (cfg.ScrMaxX + 1 - width) / 2;
+    y0 = (cfg.ScrMaxY + 1 - height) / 2;
     /* put in the instructions */
     DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1);
     set_colour(LIGHTCYAN);
@@ -129,8 +129,8 @@
     }
     int width = 2 * BOX_BORDER + 2 * WIDE_HSPACING + widthc * FONTW;
     int height = 2 * BOX_BORDER + 2 * WIDE_VSPACING + heightc * FONTH;
-    int x0 = (ScrMaxX + 1 - width) / 2;
-    int y0 = (ScrMaxY + 1 - height) / 2;
+    int x0 = (cfg.ScrMaxX + 1 - width) / 2;
+    int y0 = (cfg.ScrMaxY + 1 - height) / 2;
 
     DrawScreenBox3D(x0, y0, x0 + width - 1, y0 + height - 1);
     push_colour(WINFG);
--- a/src/img.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/img.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -211,7 +211,7 @@
     FILE *fp = 0;
 
     // Load palette 0 from PLAYPAL
-    MDirPtr dir = FindMasterDir(MasterDir, "PLAYPAL");
+    MDirPtr dir = FindMasterDir(cfg.MasterDir, "PLAYPAL");
     if (dir == 0)
     {
         errno = ECHILD;
--- a/src/imgspect.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/imgspect.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -41,9 +41,9 @@
     u8 grey;
 
 // FIXME this is gross
-    if (!strncmp(Game, "doom", 4))
+    if (!strncmp(cfg.Game, "doom", 4))
         grey = 104;
-    else if (!strcmp(Game, "heretic"))
+    else if (!strcmp(cfg.Game, "heretic"))
         grey = 8;
     else
     {
--- a/src/infobar.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/infobar.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -100,7 +100,7 @@
 
     if (redraw_from_scratch)
     {
-        DrawScreenBox3D(0, out_y0, ScrMaxX, ScrMaxY);
+        DrawScreenBox3D(0, out_y0, cfg.ScrMaxX, cfg.ScrMaxY);
         visible_disp = 1;
         flags &= ~pointer_disp_set;
     }
@@ -171,13 +171,13 @@
     if (redraw_from_scratch || scale_disp != scale)
     {
 #ifdef OLD
-        if (Scale < 1.0)
+        if (cfg.Scale < 1.0)
             DrawScreenText(x, text_y0, "Scale: 1/%d",
-                           (int) (1.0 / Scale + 0.5));
+                           (int) (1.0 / cfg.Scale + 0.5));
         else
-            DrawScreenText(x, text_y0, "Scale: %d/1", (int) Scale);
+            DrawScreenText(x, text_y0, "Scale: %d/1", (int) cfg.Scale);
 #else
-        DrawScreenText(x, text_y0, "Scale: %d%%", (int) (Scale * 100));
+        DrawScreenText(x, text_y0, "Scale: %d%%", (int) (cfg.Scale * 100));
 #endif
         scale_disp = scale;
     }
--- a/src/input.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/input.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -131,11 +131,11 @@
     {
         // No event ? Wait for <idle_sleep_ms> ms before polling again.
 #if defined Y_NANOSLEEP
-        struct timespec treq = { 0, 1000000ul * idle_sleep_ms };
+        struct timespec treq = { 0, 1000000ul * cfg.idle_sleep_ms };
         struct timespec trem;
         nanosleep(&treq, &trem);
 #elif defined Y_USLEEP
-        usleep(1000ul * idle_sleep_ms);
+        usleep(1000ul * cfg.idle_sleep_ms);
 #else
         // Neither nanosleep() no usleep() so be a CPU hog.
         // FIXME: if autoscroll is turned off, could as well
--- a/src/l_align.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/l_align.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -228,8 +228,8 @@
 
         sprintf(prompt, "Enter initial offset between 0 and %d:", texlength);
 
-        x0 = (ScrMaxX - 25 - 8 * strlen(prompt)) / 2;
-        y0 = (ScrMaxY - 55) / 2;
+        x0 = (cfg.ScrMaxX - 25 - 8 * strlen(prompt)) / 2;
+        y0 = (cfg.ScrMaxY - 55) / 2;
 
         DrawScreenBox3D(x0, y0, x0 + 25 + 8 * strlen(prompt), y0 + 55);
         set_colour(WHITE);
--- a/src/levels.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/levels.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -41,11 +41,6 @@
 #include "wads.h"
 #include "wads2.h"
 
-/* Error resiliency of during loading of WAD / map data, 0 - 4
- * 0 = Bail on all errors.
- * 4 = Ignore almost anything.
- */
-int error_res = 0;
 
 /*
          FIXME
@@ -155,7 +150,7 @@
 
 /* Find the various level information from the master directory */
     DisplayMessage(-1, -1, "Reading data for level %s...", levelname);
-    Level = FindMasterDir(MasterDir, levelname);
+    Level = FindMasterDir(cfg.MasterDir, levelname);
     if (!Level)
         fatal_error("level data not found");
 
@@ -200,7 +195,7 @@
         {
             offset = dir->dir.start;
             length = dir->dir.size;
-            if (MainWad == Iwad4)        // Hexen mode
+            if (cfg.MainWad == cfg.Iwad[IWAD_HEXEN])        // Hexen mode
             {
                 NumThings = (int) (length / WAD_HEXEN_THING_BYTES);
                 if ((i32) (NumThings * WAD_HEXEN_THING_BYTES) != length)
@@ -234,9 +229,9 @@
             {
                 err("%s: seek error", lump_name);
                 rc = 1;
-                if (error_res <= 3) goto byebye;
+                if (cfg.error_res <= 3) goto byebye;
             }
-            if (MainWad == Iwad4)        // Hexen mode
+            if (cfg.MainWad == cfg.Iwad[IWAD_HEXEN])        // Hexen mode
                 for (long n = 0; n < NumThings; n++)
                 {
                     u8 dummy2[6];
@@ -252,7 +247,7 @@
                     {
                         err("%s: error reading thing #%ld", lump_name, n);
                         rc = 1;
-                        if (error_res <= 3) goto byebye;
+                        if (cfg.error_res <= 3) goto byebye;
                     }
                 }
             else                // Doom/Heretic/Strife mode
@@ -269,7 +264,7 @@
                     {
                         err("%s: error reading thing #%ld", lump_name, n);
                         rc = 1;
-                        if (error_res <= 3) goto byebye;
+                        if (cfg.error_res <= 3) goto byebye;
                     }
                 }
         }
@@ -285,7 +280,7 @@
             NumLineDefs = 0;
         else
         {
-            if (MainWad == Iwad4)        // Hexen mode
+            if (cfg.MainWad == cfg.Iwad[IWAD_HEXEN])        // Hexen mode
             {
                 NumLineDefs = (int) (dir->dir.size / WAD_HEXEN_LINEDEF_BYTES);
                 if ((i32) (NumLineDefs * WAD_HEXEN_LINEDEF_BYTES) !=
@@ -311,9 +306,9 @@
             {
                 err("%s: seek error", lump_name);
                 rc = 1;
-                if (error_res <= 3) goto byebye;
+                if (cfg.error_res <= 3) goto byebye;
             }
-            if (MainWad == Iwad4)        // Hexen mode
+            if (cfg.MainWad == cfg.Iwad[IWAD_HEXEN])        // Hexen mode
                 for (long n = 0; n < NumLineDefs; n++)
                 {
                     u8 dummy[6];
@@ -329,7 +324,7 @@
                     {
                         err("%s: error reading linedef #%ld", lump_name, n);
                         rc = 1;
-                        if (error_res <= 3) goto byebye;
+                        if (cfg.error_res <= 3) goto byebye;
                     }
                 }
             else                // Doom/Heretic/Strife mode
@@ -346,7 +341,7 @@
                     {
                         err("%s: error reading linedef #%ld", lump_name, n);
                         rc = 1;
-                        if (error_res <= 3) goto byebye;
+                        if (cfg.error_res <= 3) goto byebye;
                     }
                 }
         }
@@ -376,7 +371,7 @@
             {
                 err("%s: seek error", lump_name);
                 rc = 1;
-                if (error_res <= 3) goto byebye;
+                if (cfg.error_res <= 3) goto byebye;
             }
             for (long n = 0; n < NumSideDefs; n++)
             {
@@ -390,7 +385,7 @@
                 {
                     err("%s: error reading sidedef #%ld", lump_name, n);
                     rc = 1;
-                    if (error_res <= 3) goto byebye;
+                    if (cfg.error_res <= 3) goto byebye;
                 }
             }
         }
@@ -407,7 +402,7 @@
             err("linedef %ld has bad 1st sidedef number %d, giving up",
                 n, LineDefs[n].sidedef1);
             rc = 1;
-            if (error_res <= 2) goto byebye;
+            if (cfg.error_res <= 2) goto byebye;
             LineDefs[n].sidedef1 = 0;
         }
         if (LineDefs[n].sidedef2 != -1
@@ -416,7 +411,7 @@
             err("linedef %ld has bad 2nd sidedef number %d, giving up",
                 n, LineDefs[n].sidedef2);
             rc = 1;
-            if (error_res <= 2) goto byebye;
+            if (cfg.error_res <= 2) goto byebye;
             LineDefs[n].sidedef2 = 0;
         }
         if (outside(LineDefs[n].start, 0, OldNumVertices - 1))
@@ -424,7 +419,7 @@
             err("linedef %ld has bad 1st vertex number %d, giving up",
                 n, LineDefs[n].start);
             rc = 1;
-            if (error_res <= 2) goto byebye;
+            if (cfg.error_res <= 2) goto byebye;
             LineDefs[n].start = 0;
         }
         if (outside(LineDefs[n].end, 0, OldNumVertices - 1))
@@ -432,7 +427,7 @@
             err("linedef %ld has bad 2nd vertex number %d, giving up",
                 n, LineDefs[n].end);
             rc = 1;
-            if (error_res <= 2) goto byebye;
+            if (cfg.error_res <= 2) goto byebye;
             LineDefs[n].end = 0;
         }
     }
@@ -461,7 +456,7 @@
                 bool success = false;
                 ntex = 0;
                 i32 *offset_table = 0;
-                MDirPtr d = FindMasterDir(MasterDir, lump_name);
+                MDirPtr d = FindMasterDir(cfg.MasterDir, lump_name);
                 if (!d)
                 {
                     warn("%s: lump not found in directory\n", lump_name);
@@ -532,7 +527,7 @@
             {
                 err("%s: seek error", lump_name);
                 rc = 1;
-                if (error_res <= 3) goto byebye;
+                if (cfg.error_res <= 3) goto byebye;
             }
             size_t s = 0;
             for (size_t n = 0; n < nlines; n++)
@@ -588,7 +583,7 @@
                 {
                     err("%s: error reading line #%d", lump_name, int (n));
                     rc = 1;
-                    if (error_res <= 3) goto byebye;
+                    if (cfg.error_res <= 3) goto byebye;
                 }
             }
             // (size_t) to silence GCC warning
@@ -695,7 +690,7 @@
                 {
                     err("%s: seek error", lump_name);
                     rc = 1;
-                    if (error_res <= 3) goto byebye;
+                    if (cfg.error_res <= 3) goto byebye;
                 }
                 MapMaxX = -32767;
                 MapMaxY = -32767;
@@ -720,7 +715,7 @@
                     {
                         err("%s: error reading vertex #%ld", lump_name, n);
                         rc = 1;
-                        if (error_res <= 3) goto byebye;
+                        if (cfg.error_res <= 3) goto byebye;
                     }
                 }
             }
@@ -757,7 +752,7 @@
                 {
                     err("%s: seek error", lump_name);
                     rc = 1;
-                    if (error_res <= 3) goto byebye;
+                    if (cfg.error_res <= 3) goto byebye;
                 }
                 for (long n = 0; n < NumSectors; n++)
                 {
@@ -772,7 +767,7 @@
                     {
                         err("%s: error reading sector #%ld", lump_name, n);
                         rc = 1;
-                        if (error_res <= 3) goto byebye;
+                        if (cfg.error_res <= 3) goto byebye;
                     }
                 }
             }
@@ -795,14 +790,14 @@
                 {
                     err("%s: seek error", lump_name);
                     rc = 1;
-                    if (error_res <= 3) goto byebye;
+                    if (cfg.error_res <= 3) goto byebye;
                 }
                 wf->read_i32(&nsectors);
                 if (wf->error())
                 {
                     err("%s: error reading sector count", lump_name);
                     rc = 1;
-                    if (error_res <= 3) goto byebye;
+                    if (cfg.error_res <= 3) goto byebye;
                 }
                 if (nsectors < 0)
                 {
@@ -920,7 +915,7 @@
                 delete[]offset_table;
             if (flatnames != 0)
                 delete[]flatnames;
-            if (rc != 0 && error_res <= 3) goto byebye;
+            if (rc != 0 && cfg.error_res <= 3) goto byebye;
         }
     }
 
@@ -949,7 +944,7 @@
     if (rc != 0)
         err("%s: errors found, giving up", levelname);
 
-    return (error_res > 0) ? 0 : rc;
+    return (cfg.error_res > 0) ? 0 : rc;
 }
 
 
@@ -1028,7 +1023,7 @@
     size_t lump_size[WAD_LL__];
     wad_level_lump_no_t l;
 
-    if (yg_level_format == YGLF_HEXEN || !strcmp(Game, "hexen"))
+    if (yg_level_format == YGLF_HEXEN || !strcmp(cfg.Game, "hexen"))
     {
         Notify(-1, -1, "I refuse to save. Hexen mode is still",
                "too badly broken. You would lose data.");
@@ -1264,7 +1259,7 @@
 
 /* The file is now up to date */
     if (!Level || MadeMapChanges)
-        remind_to_build_nodes = 1;
+        cfg.remind_to_build_nodes = 1;
     MadeChanges = 0;
     MadeMapChanges = 0;
 
@@ -1319,7 +1314,7 @@
         && yg_texture_format == YGTF_NAMELESS)
     {
         const char *lump_name = "TEXTURES";
-        dir = FindMasterDir(MasterDir, lump_name);
+        dir = FindMasterDir(cfg.MasterDir, lump_name);
         if (dir == NULL)
         {
             warn("%s: lump not found in directory\n", lump_name);
@@ -1368,7 +1363,7 @@
     {
         const char *lump_name = "TEXTURES";
         i32 *offsets = 0;
-        dir = FindMasterDir(MasterDir, lump_name);
+        dir = FindMasterDir(cfg.MasterDir, lump_name);
         if (dir == NULL)        // In theory it always exists, though
         {
             warn("%s: lump not found in directory\n", lump_name);
@@ -1432,7 +1427,7 @@
     {
         const char *lump_name = "TEXTURE1";
         i32 *offsets = 0;
-        dir = FindMasterDir(MasterDir, lump_name);
+        dir = FindMasterDir(cfg.MasterDir, lump_name);
         if (dir != NULL)        // In theory it always exists, though
         {
             const Wad_file *wf = dir->wadfile;
@@ -1478,7 +1473,7 @@
             FreeMemory(offsets);
         }
         {
-            dir = FindMasterDir(MasterDir, "TEXTURE2");
+            dir = FindMasterDir(cfg.MasterDir, "TEXTURE2");
             if (dir)                /* Doom II has no TEXTURE2 */
             {
                 const Wad_file *wf = dir->wadfile;
@@ -1566,7 +1561,7 @@
     verbmsg("Reading flat names");
     NumFTexture = 0;
 
-    for (dir = MasterDir; (dir = FindMasterDir(dir, "F_START", "FF_START"));)
+    for (dir = cfg.MasterDir; (dir = FindMasterDir(dir, "F_START", "FF_START"));)
     {
         bool ff_start = !y_strnicmp(dir->dir.name, "FF_START", WAD_NAME);
         MDirPtr dir0;
--- a/src/lists.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/lists.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -155,19 +155,19 @@
 // (int) to prevent GCC warning
     win_height = y_max(height + 20, (int) (listdisp * FONTH + 10 + 28));
     if (x0 < 0)
-        x0 = (ScrMaxX - win_width) / 2;
+        x0 = (cfg.ScrMaxX - win_width) / 2;
     if (y0 < 0)
-        y0 = (ScrMaxY - win_height) / 2;
+        y0 = (cfg.ScrMaxY - win_height) / 2;
     x1 += x0;
     y1 += y0;
-    if (x1 + width - 1 < ScrMaxX)
+    if (x1 + width - 1 < cfg.ScrMaxX)
         x2 = x1 + width - 1;
     else
-        x2 = ScrMaxX;
-    if (y1 + height - 1 < ScrMaxY)
+        x2 = cfg.ScrMaxX;
+    if (y1 + height - 1 < cfg.ScrMaxY)
         y2 = y1 + height - 1;
     else
-        y2 = ScrMaxY;
+        y2 = cfg.ScrMaxY;
 
     entry_out_x0 = x0 + 10;
     entry_text_x0 = entry_out_x0 + HOLLOW_BORDER + NARROW_HSPACING;
--- a/src/locate.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/locate.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -27,7 +27,6 @@
 
 #include "locate.h"
 #include "macro.h"
-#include "trace.h"
 
 
 /*
@@ -132,13 +131,14 @@
 
         // Expand the macros in the path into the result buffer
         int r = macro_expand(pathname, sizeof pathname - 1, dirname,
-                             "%i", install_dir,
+                             "%i", cfg.install_dir,
                              "%v", yadex_version,
                              "~", home,
                              (const char *) 0);
         if (r != 0)
         {
-            trace("locate", "%s: Could not expand macro #%d", dirname, r);
+            if (cfg.Debug)
+                warn("%s: Could not expand macro #%d\n", dirname, r);
             continue;
         }
 
@@ -164,7 +164,8 @@
         r = stat(pathname, &s);
         if (r == 0 && !S_ISDIR(s.st_mode))
         {
-            trace("locate", "%s: %s: hit", name, pathname);
+            if (cfg.Debug)
+                warn("%s: %s: hit\n", name, pathname);
             return pathname;
         }
         else if (r == 0 && S_ISDIR(s.st_mode))
@@ -175,7 +176,8 @@
         {
             warn("%s: %s\n", pathname, strerror(errno));
         }
-        trace("locate", "%s: %s: miss (%s)", name, pathname, strerror(errno));
+        if (cfg.Debug)
+            warn("%s: %s: miss (%s)\n", name, pathname, strerror(errno));
     }
 
     return NULL;
--- a/src/menu.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/menu.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -704,15 +704,15 @@
         + items.back().y + item_height;
 
     if (user_ox0 < 0)
-        ox0 = (ScrMaxX - width) / 2;
+        ox0 = (cfg.ScrMaxX - width) / 2;
     else
         ox0 = user_ox0;
     ix0 = ox0 + BOX_BORDER;
     ix1 = ix0 + 2 * WIDE_HSPACING + width_chars * FONTW - 1;
     ox1 = ix1 + BOX_BORDER;
-    if (ox1 > ScrMaxX)
+    if (ox1 > cfg.ScrMaxX)
     {
-        int overlap = ox1 - ScrMaxX;
+        int overlap = ox1 - cfg.ScrMaxX;
         ox0 -= overlap;
         ix0 -= overlap;
         ix1 -= overlap;
@@ -720,7 +720,7 @@
     }
 
     if (user_oy0 < 0)
-        oy0 = (ScrMaxY - height) / 2;
+        oy0 = (cfg.ScrMaxY - height) / 2;
     else
         oy0 = user_oy0;
     iy0 = oy0 + BOX_BORDER;
--- a/src/menubar.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/menubar.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -257,7 +257,7 @@
         if (stale_x0_x1)
             compute_x0_x1();
         push_colour(menu_colour[0][0].bg);        /* 1 */
-        DrawScreenBox3D(0, 0, ScrMaxX, menubar_out_y1);
+        DrawScreenBox3D(0, 0, cfg.ScrMaxX, menubar_out_y1);
         set_colour(menu_colour[0][0].fg);
         for (int n = 0; n < nitems; n++)
         {
--- a/src/mkpalette.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/mkpalette.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -40,7 +40,7 @@
 {
     const char *lump_name = "PLAYPAL";
 
-    MDirPtr dir = FindMasterDir(MasterDir, lump_name);
+    MDirPtr dir = FindMasterDir(cfg.MasterDir, lump_name);
     if (dir == NULL)
     {
         warn("%s: lump not found\n", lump_name);
--- a/src/objects.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/objects.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -128,7 +128,7 @@
 
     case OBJ_VERTICES:
         {
-            int r = vertex_radius(Scale) * 3 / 2;
+            int r = vertex_radius(cfg.Scale) * 3 / 2;
             int scrx0 = SCREENX(Vertices[objnum].x) - r;
             int scrx9 = SCREENX(Vertices[objnum].x) + r;
             int scry0 = SCREENY(Vertices[objnum].y) - r;
@@ -144,8 +144,8 @@
         {
             SetLineThickness(1);
             const int mapx0 = MAPX(0);
-            const int mapy0 = MAPY(ScrMaxY);
-            const int mapx1 = MAPX(ScrMaxX);
+            const int mapy0 = MAPY(cfg.ScrMaxY);
+            const int mapx1 = MAPX(cfg.ScrMaxX);
             const int mapy1 = MAPY(0);
             for (n = 0; n < NumLineDefs; n++)
                 if (LineDefs[n].sidedef1 != -1
@@ -461,7 +461,7 @@
         }
         else
         {
-            Things[last].type = default_thing;
+            Things[last].type = cfg.def.thing;
             Things[last].angle = 0;
             Things[last].when = 0x07;
         }
@@ -542,7 +542,7 @@
             SideDefs[last].yoff = 0;
             strcpy(SideDefs[last].tex1, "-");
             strcpy(SideDefs[last].tex2, "-");
-            strcpy(SideDefs[last].tex3, default_middle_texture);
+            strcpy(SideDefs[last].tex3, cfg.def.middle_texture);
             SideDefs[last].sector = NumSectors - 1;
         }
         MadeMapChanges = 1;
@@ -570,13 +570,13 @@
         }
         else
         {
-            Sectors[last].floorh = default_floor_height;
-            Sectors[last].ceilh = default_ceiling_height;
-            strncpy(Sectors[last].floort, default_floor_texture,
+            Sectors[last].floorh = cfg.def.floor_height;
+            Sectors[last].ceilh = cfg.def.ceiling_height;
+            strncpy(Sectors[last].floort, cfg.def.floor_texture,
                     WAD_FLAT_NAME);
-            strncpy(Sectors[last].ceilt, default_ceiling_texture,
+            strncpy(Sectors[last].ceilt, cfg.def.ceiling_texture,
                     WAD_FLAT_NAME);
-            Sectors[last].light = default_light_level;
+            Sectors[last].light = cfg.def.light_level;
             Sectors[last].special = 0;
             Sectors[last].tag = 0;
         }
@@ -873,7 +873,7 @@
             InsertObject(OBJ_LINEDEFS, old, 0, 0);
             New = NumLineDefs - 1;
 
-            if (copy_linedef_reuse_sidedefs)
+            if (cfg.copy_linedef_reuse_sidedefs)
             {
                 /* AYM 1997-07-25: not very orthodox (the New linedef and 
                    the old one use the same sidedefs). but, in the case where
--- a/src/palview.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/palview.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -58,8 +58,8 @@
     const int pheight = lines * (pixels + 1);
     int width = 2 * BOX_BORDER + 2 * WIDE_HSPACING + pwidth;
     int height = 2 * BOX_BORDER + 3 * WIDE_VSPACING + pheight + 7 * FONTH;
-    int x0 = (ScrMaxX - width) / 2;
-    int y0 = (ScrMaxY - height) / 2;
+    int x0 = (cfg.ScrMaxX - width) / 2;
+    int y0 = (cfg.ScrMaxY - height) / 2;
     int nmaps = 0;                // Number of entries in the COLORMAP lump
     colormap_entry_t **colormap = 0;
     rgb_c *playpal = 0;
@@ -71,7 +71,7 @@
         for (size_t n = 0; n < DOOM_COLOURS; n++)
             playpal[n].set(0, 0, 0);
         const char *lump_name = "PLAYPAL";
-        MDirPtr dir = FindMasterDir(MasterDir, lump_name);
+        MDirPtr dir = FindMasterDir(cfg.MasterDir, lump_name);
         if (dir == NULL)
         {
             warn("%s: lump not found\n", lump_name);
@@ -105,7 +105,7 @@
     do
     {
         const char *lump_name = "COLORMAP";
-        MDirPtr dir = FindMasterDir(MasterDir, lump_name);
+        MDirPtr dir = FindMasterDir(cfg.MasterDir, lump_name);
         if (dir == NULL)
         {
             warn("%s: lump not found\n", lump_name);
--- a/src/pic2img.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/pic2img.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -103,7 +103,7 @@
     }
     else
     {
-        dir = (MDirPtr) FindMasterDir(MasterDir, picname);
+        dir = (MDirPtr) FindMasterDir(cfg.MasterDir, picname);
         if (dir == NULL)
         {
             warn("picture %.*s does not exist.\n", WAD_PIC_NAME, picname);
--- a/src/prefer.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/prefer.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -53,28 +53,28 @@
     width = 2 * BOX_BORDER + 2 * WIDE_HSPACING + 50 * FONTW;
     height = 2 * BOX_BORDER + 2 * WIDE_VSPACING + (int) (10.5 * FONTH);
     if (x0 < 0)
-        x0 = (ScrMaxX + 1 - width) / 2;
+        x0 = (cfg.ScrMaxX + 1 - width) / 2;
     if (y0 < 0)
-        y0 = (ScrMaxY + 1 - height) / 2;
+        y0 = (cfg.ScrMaxY + 1 - height) / 2;
     for (n = 0; n < 9; n++)
         menustr[n] = (char *) GetMemory(80);
     sprintf(menustr[8], "Preferences");
     sprintf(menustr[0], "Change default middle texture  (Current: %.*s)",
-            (int) WAD_TEX_NAME, default_middle_texture);
+            (int) WAD_TEX_NAME, cfg.def.middle_texture);
     sprintf(menustr[1], "Change default upper texture   (Current: %.*s)",
-            (int) WAD_TEX_NAME, default_upper_texture);
+            (int) WAD_TEX_NAME, cfg.def.upper_texture);
     sprintf(menustr[2], "Change default lower texture   (Current: %.*s)",
-            (int) WAD_TEX_NAME, default_lower_texture);
+            (int) WAD_TEX_NAME, cfg.def.lower_texture);
     sprintf(menustr[3], "Change default floor texture   (Current: %.*s)",
-            (int) WAD_FLAT_NAME, default_floor_texture);
+            (int) WAD_FLAT_NAME, cfg.def.floor_texture);
     sprintf(menustr[4], "Change default ceiling texture (Current: %.*s)",
-            (int) WAD_FLAT_NAME, default_ceiling_texture);
+            (int) WAD_FLAT_NAME, cfg.def.ceiling_texture);
     sprintf(menustr[5], "Change default floor height    (Current: %d)",
-            default_floor_height);
+            cfg.def.floor_height);
     sprintf(menustr[6], "Change default ceiling height  (Current: %d)",
-            default_ceiling_height);
+            cfg.def.ceiling_height);
     sprintf(menustr[7], "Change default light level     (Current: %d)",
-            default_light_level);
+            cfg.def.light_level);
     val = vDisplayMenu(x0, y0, menustr[8],
                        menustr[0], YK_, 0,
                        menustr[1], YK_, 0,
@@ -91,29 +91,29 @@
     switch (val)
     {
     case 1:
-        strcpy(texname, default_middle_texture);
+        strcpy(texname, cfg.def.middle_texture);
         ChooseWallTexture(subwin_x0, subwin_y0, "Choose a wall texture",
                           NumWTexture, WTexture, texname);
         if (strlen(texname) > 0)
-            strcpy(default_middle_texture, texname);
+            strcpy(cfg.def.middle_texture, texname);
         break;
     case 2:
-        strcpy(texname, default_upper_texture);
+        strcpy(texname, cfg.def.upper_texture);
         ChooseWallTexture(subwin_x0, subwin_y0, "Choose a wall texture",
                           NumWTexture, WTexture, texname);
         if (strlen(texname) > 0)
-            strcpy(default_upper_texture, texname);
+            strcpy(cfg.def.upper_texture, texname);
         break;
     case 3:
-        strcpy(texname, default_lower_texture);
+        strcpy(texname, cfg.def.lower_texture);
         ChooseWallTexture(subwin_x0, subwin_y0, "Choose a wall texture",
                           NumWTexture, WTexture, texname);
         if (strlen(texname) > 0)
-            strcpy(default_lower_texture, texname);
+            strcpy(cfg.def.lower_texture, texname);
         break;
     case 4:
         {
-            strcpy(flatname, default_floor_texture);
+            strcpy(flatname, cfg.def.floor_texture);
             char **flat_names
                 = (char **) GetMemory(NumFTexture * sizeof *flat_names);
             for (size_t n = 0; n < NumFTexture; n++)
@@ -122,12 +122,12 @@
                                NumFTexture, flat_names, flatname);
             FreeMemory(flat_names);
             if (strlen(flatname) > 0)
-                strcpy(default_floor_texture, flatname);
+                strcpy(cfg.def.floor_texture, flatname);
             break;
         }
     case 5:
         {
-            strcpy(flatname, default_ceiling_texture);
+            strcpy(flatname, cfg.def.ceiling_texture);
             char **flat_names
                 = (char **) GetMemory(NumFTexture * sizeof *flat_names);
             for (size_t n = 0; n < NumFTexture; n++)
@@ -137,29 +137,29 @@
                                flat_names, flatname);
             FreeMemory(flat_names);
             if (strlen(flatname) > 0)
-                strcpy(default_ceiling_texture, flatname);
+                strcpy(cfg.def.ceiling_texture, flatname);
             break;
         }
     case 6:
         val =
             InputIntegerValue(x0 + 42, subwin_y0, -512, 511,
-                              default_floor_height);
+                              cfg.def.floor_height);
         if (val != IIV_CANCEL)
-            default_floor_height = val;
+            cfg.def.floor_height = val;
         break;
     case 7:
         val =
             InputIntegerValue(x0 + 42, subwin_y0, -512, 511,
-                              default_ceiling_height);
+                              cfg.def.ceiling_height);
         if (val != IIV_CANCEL)
-            default_ceiling_height = val;
+            cfg.def.ceiling_height = val;
         break;
     case 8:
         val =
             InputIntegerValue(x0 + 42, subwin_y0, 0, 255,
-                              default_light_level);
+                              cfg.def.light_level);
         if (val != IIV_CANCEL)
-            default_light_level = val;
+            cfg.def.light_level = val;
         break;
 
     }
--- a/src/r_images.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/r_images.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -148,7 +148,7 @@
     if (yg_texture_lumps == YGTL_TEXTURES
         && yg_texture_format == YGTF_NAMELESS)
     {
-        dir = FindMasterDir(MasterDir, "TEXTURES");
+        dir = FindMasterDir(cfg.MasterDir, "TEXTURES");
         if (dir != NULL)
         {
             dir->wadfile->seek(dir->dir.start);
@@ -177,7 +177,7 @@
                  || yg_texture_format == YGTF_STRIFE11))
     {
         // Is it in TEXTURES ?
-        dir = FindMasterDir(MasterDir, "TEXTURES");
+        dir = FindMasterDir(cfg.MasterDir, "TEXTURES");
         if (dir != NULL)        // (Theoretically, it should always exist)
         {
             dir->wadfile->seek(dir->dir.start);
@@ -201,7 +201,7 @@
                  || yg_texture_format == YGTF_STRIFE11))
     {
         // Is it in TEXTURE1 ?
-        dir = FindMasterDir(MasterDir, "TEXTURE1");
+        dir = FindMasterDir(cfg.MasterDir, "TEXTURE1");
         if (dir != NULL)        // (Theoretically, it should always exist)
         {
             dir->wadfile->seek(dir->dir.start);
@@ -221,7 +221,7 @@
         // Well, then is it in TEXTURE2 ?
         if (texofs == 0)
         {
-            dir = FindMasterDir(MasterDir, "TEXTURE2");
+            dir = FindMasterDir(cfg.MasterDir, "TEXTURE2");
             if (dir != NULL)        // Doom II has no TEXTURE2
             {
                 dir->wadfile->seek(dir->dir.start);
--- a/src/s_door.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/s_door.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -85,7 +85,7 @@
         return;
     }
     if ((s > 2)
-        && !(Expert
+        && !(cfg.Expert
              || Confirm(-1, -1, "The door will have more than two sides.",
                         "Do you still want to create it?")))
     {
--- a/src/s_lift.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/s_lift.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -172,7 +172,7 @@
         if (Sectors[s].ceilh < Sectors[sector].ceilh)
         {
             if (strncmp(SideDefs[sd2].tex1, "-", WAD_TEX_NAME))
-                strncpy(SideDefs[sd2].tex1, default_upper_texture,
+                strncpy(SideDefs[sd2].tex1, cfg.def.upper_texture,
                         WAD_TEX_NAME);
         }
         /* if the floor of the sector is above the lift */
@@ -197,7 +197,7 @@
         sd1 = LineDefs[n].sidedef1;
         /* adjust the textures for the sidedef */
         if (!strncmp(SideDefs[sd1].tex3, "-", WAD_TEX_NAME))
-            strncpy(SideDefs[sd1].tex3, default_middle_texture, WAD_TEX_NAME);
+            strncpy(SideDefs[sd1].tex3, cfg.def.middle_texture, WAD_TEX_NAME);
         strncpy(SideDefs[sd1].tex1, "-", WAD_TEX_NAME);
         strncpy(SideDefs[sd1].tex2, "-", WAD_TEX_NAME);
         UnSelectObject(&ld1s, n);
--- a/src/s_misc.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/s_misc.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -106,8 +106,8 @@
     int delta = 0;                // user input for delta
 
 
-    x0 = (ScrMaxX - 25 - 44 * FONTW) / 2;
-    y0 = (ScrMaxY - 7 * FONTH) / 2;
+    x0 = (cfg.ScrMaxX - 25 - 44 * FONTW) / 2;
+    y0 = (cfg.ScrMaxY - 7 * FONTH) / 2;
     DrawScreenBox3D(x0, y0, x0 + 25 + 44 * FONTW, y0 + 7 * FONTH);
     set_colour(WHITE);
     DrawScreenText(x0 + 10, y0 + FONTH,
@@ -147,8 +147,8 @@
     int delta = 0;                // user input for delta
 
 
-    x0 = (ScrMaxX - 25 - 44 * FONTW) / 2;
-    y0 = (ScrMaxY - 7 * FONTH) / 2;
+    x0 = (cfg.ScrMaxX - 25 - 44 * FONTW) / 2;
+    y0 = (cfg.ScrMaxY - 7 * FONTH) / 2;
     DrawScreenBox3D(x0, y0, x0 + 25 + 44 * FONTW, y0 + 7 * FONTH);
     set_colour(WHITE);
     DrawScreenText(x0 + 10, y0 + FONTH, "Enter number of units to brighten");
--- a/src/spritdir.h	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/spritdir.h	Mon Sep 26 17:39:49 2011 +0300
@@ -33,7 +33,7 @@
 
 
 #include "lumpdir.h"
-
+#include "serialnum.h"
 
 /*
  *        Sprite_dir
--- a/src/sticker.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/sticker.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -269,7 +269,7 @@
     {
         register const img_pixel_t *image_ptr;
         register u16 *buf_ptr = (u16 *) buf;
-        if (cpu_big_endian == x_server_big_endian)
+        if (cfg.cpu_big_endian == x_server_big_endian)
         {
             if (padding == 0)
             {
@@ -347,7 +347,7 @@
     {
         register const img_pixel_t *image_ptr;
         register u32 *buf_ptr = (u32 *) buf;
-        if (cpu_big_endian == x_server_big_endian)
+        if (cfg.cpu_big_endian == x_server_big_endian)
         {
             if (padding == 0)
             {
--- a/src/textures.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/textures.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -131,7 +131,7 @@
         && yg_texture_format == YGTF_NAMELESS)
     {
         const char *lump_name = "TEXTURES";
-        dir = FindMasterDir(MasterDir, lump_name);
+        dir = FindMasterDir(cfg.MasterDir, lump_name);
         if (dir != NULL)
         {
             const Wad_file *wf = dir->wadfile;
@@ -187,7 +187,7 @@
                  || yg_texture_format == YGTF_STRIFE11))
     {
         const char *lump_name = "TEXTURES";
-        dir = FindMasterDir(MasterDir, lump_name);
+        dir = FindMasterDir(cfg.MasterDir, lump_name);
         if (dir != NULL)        // (Theoretically, it should always exist)
         {
             i32 *offsets = NULL;        // Array of offsets to texture names
@@ -245,7 +245,7 @@
         // Is it in TEXTURE1 ?
         {
             const char *lump_name = "TEXTURE1";
-            dir = FindMasterDir(MasterDir, lump_name);
+            dir = FindMasterDir(cfg.MasterDir, lump_name);
             if (dir != NULL)        // (Theoretically, it should always exist)
             {
                 const Wad_file *wf = dir->wadfile;
@@ -300,7 +300,7 @@
             const char *lump_name = "TEXTURE2";
             i32 *offsets = NULL;        // Array of offsets to texture names
 
-            dir = FindMasterDir(MasterDir, lump_name);
+            dir = FindMasterDir(cfg.MasterDir, lump_name);
             if (dir != NULL)        // Doom II has no TEXTURE2
             {
                 const Wad_file *wf = dir->wadfile;
@@ -483,7 +483,7 @@
     if (yg_texture_lumps == YGTL_TEXTURES
         && yg_texture_format == YGTF_NAMELESS)
     {
-        dir = FindMasterDir(MasterDir, "TEXTURES");
+        dir = FindMasterDir(cfg.MasterDir, "TEXTURES");
         if (dir != NULL)
         {
             dir->wadfile->seek(dir->dir.start);
@@ -511,9 +511,9 @@
              || yg_texture_format == YGTF_STRIFE11)
     {
         if (yg_texture_lumps == YGTL_TEXTURES)
-            dir = FindMasterDir(MasterDir, "TEXTURES");        // Doom alpha 0.5
+            dir = FindMasterDir(cfg.MasterDir, "TEXTURES");        // Doom alpha 0.5
         else if (yg_texture_lumps == YGTL_NORMAL)
-            dir = FindMasterDir(MasterDir, "TEXTURE1");
+            dir = FindMasterDir(cfg.MasterDir, "TEXTURE1");
         else
         {
             dir = 0;
@@ -547,7 +547,7 @@
         if (texofs == 0 && yg_texture_lumps == YGTL_NORMAL)
         {
             // Search for texname in TEXTURE2
-            dir = FindMasterDir(MasterDir, "TEXTURE2");
+            dir = FindMasterDir(cfg.MasterDir, "TEXTURE2");
             if (dir != NULL)        // Doom II has no TEXTURE2
             {
                 dir->wadfile->seek(dir->dir.start);
--- a/src/trace.cc	Mon Sep 26 17:14:54 2011 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-/*
- *        trace.cc
- *        Selective tracing system
- *        AYM 1999-11-30
- */
-
-
-/*
-This file is part of Yadex.
-
-Yadex incorporates code from DEU 5.21 that was put in the public domain in
-1994 by Raphaël Quinet and Brendon Wyber.
-
-The rest of Yadex is Copyright © 1997-2003 André Majorel and others.
-
-This program is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free Software
-Foundation; either version 2 of the License, or (at your option) any later
-version.
-
-This program is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License along with
-this program; if not, write to the Free Software Foundation, Inc., 59 Temple
-Place, Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-
-#include "yadex.h"
-#include "trace.h"
-
-
-// FIXME stopgap
-void trace(const char *domain, const char *fmt, ...)
-{
-    if (verbose)
-    {
-        va_list args;
-
-        fprintf(stdout, "%s: ", domain);
-        va_start(args, fmt);
-        vprintf(fmt, args);
-        va_end(args);
-        putchar('\n');
-    }
-}
--- a/src/trace.h	Mon Sep 26 17:14:54 2011 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,39 +0,0 @@
-/*
- *        trace.h
- *        Selective tracing system
- *        AYM 1999-11-30
- */
-
-
-/*
-This file is part of Yadex.
-
-Yadex incorporates code from DEU 5.21 that was put in the public domain in
-1994 by Raphaël Quinet and Brendon Wyber.
-
-The rest of Yadex is Copyright © 1997-2003 André Majorel and others.
-
-This program is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free Software
-Foundation; either version 2 of the License, or (at your option) any later
-version.
-
-This program is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License along with
-this program; if not, write to the Free Software Foundation, Inc., 59 Temple
-Place, Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-
-#ifndef YH_TRACE
-#define YH_TRACE
-
-
-// FIXME stopgap
-void trace(const char *domain, const char *fmt, ...);
-
-
-#endif /* DO NOT ADD ANYTHING AFTER THIS LINE */
--- a/src/v_merge.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/v_merge.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -173,7 +173,7 @@
     isldend = false;
 
     if (operation == 'i')
-        confirm_flag = insert_vertex_merge_vertices;
+        confirm_flag = cfg.insert_vertex_merge_vertices;
     else
         confirm_flag = YC_ASK_ONCE;
 
@@ -225,10 +225,10 @@
 //DisplayMessage  (-1, -1, "Checking vertices on a linedef");
 
 // Distance in map units that is equivalent to 4 pixels
-    int tolerance = (int) (4 / Scale);
+    int tolerance = (int) (4 / cfg.Scale);
 
     if (operation == 'i')
-        confirm_flag = insert_vertex_split_linedef;
+        confirm_flag = cfg.insert_vertex_split_linedef;
     else
         confirm_flag = YC_ASK_ONCE;
     ref = *list;
@@ -334,7 +334,7 @@
             y_snprintf(prompt, sizeof prompt,
                        "Linedefs %d and %d are superimposed", ld1, ld2);
             redraw = true;
-            if (Expert || Confirm2(-1, -1, &confirm_flag,
+            if (cfg.Expert || Confirm2(-1, -1, &confirm_flag,
                                    prompt,
                                    "(and perhaps others too). Merge them ?"))
             {
--- a/src/verbmsg.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/verbmsg.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -38,8 +38,9 @@
 {
     va_list args;
 
-    if (!verbose)
+    if (!cfg.verbose)
         return;
+
     va_start(args, fmt);
     vprintf(fmt, args);
 }
--- a/src/wadres.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/wadres.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -32,7 +32,7 @@
 #include "wadres.h"
 
 
-Wad_res::Wad_res(MDirPtr * md):sprites(md, &master_dir_serial)
+Wad_res::Wad_res(MDirPtr * md):sprites(md, &cfg.master_dir_serial)
 {
     ;
 }
--- a/src/wads.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/wads.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -33,10 +33,6 @@
 #include "wads.h"
 
 
-MDirPtr MasterDir = NULL;        // The master directory
-Serial_num master_dir_serial;        // The revision# thereof
-
-
 /*
  *        file_read_i16 - read little-endian 16-bit signed integers from a file
  *
@@ -204,8 +200,9 @@
 
 void WriteBytes(FILE * file, const void *buf, long size)
 {
-    if (!Registered)
+    if (!cfg.Registered)
         return;
+
     while (size > 0x8000)
     {
         if (fwrite(buf, 1, 0x8000, file) != 0x8000)
--- a/src/wads2.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/wads2.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -72,31 +72,33 @@
         newp->next = NULL;
         newp->wadfile = wf;
         memcpy(&(newp->dir), &(wf->directory[n]), sizeof(struct Directory));
-        if (MasterDir)
+        if (cfg.MasterDir)
             lastp->next = newp;
         else
-            MasterDir = newp;
+            cfg.MasterDir = newp;
         lastp = newp;
     }
-    master_dir_serial.bump();
+    cfg.master_dir_serial.bump();
 
-/* check if registered version */
-    if (FindMasterDir(MasterDir, "E2M1") == NULL
-        && FindMasterDir(MasterDir, "MAP01") == NULL
-        && FindMasterDir(MasterDir, "MAP33") == NULL
-        && strcmp(Game, "doom02")
-        && strcmp(Game, "doom04")
-        && strcmp(Game, "doom05") && strcmp(Game, "doompr"))
+    /* check if registered version */
+    if (FindMasterDir(cfg.MasterDir, "E2M1") == NULL
+        && FindMasterDir(cfg.MasterDir, "MAP01") == NULL
+        && FindMasterDir(cfg.MasterDir, "MAP33") == NULL
+        && strcmp(cfg.Game, "doom02")
+        && strcmp(cfg.Game, "doom04")
+        && strcmp(cfg.Game, "doom05")
+        && strcmp(cfg.Game, "doompr"))
     {
-        Registered = false;        // If you remove this, bad things will happen to you...
         printf("   *-----------------------------------------------------*\n");
         printf("   | Warning: this is the shareware version of the game. |\n");
         printf("   |     You won't be allowed to save your changes.      |\n");
         printf("   |       PLEASE REGISTER YOUR COPY OF THE GAME.        |\n");
         printf("   *-----------------------------------------------------*\n");
+        cfg.Registered = false;        // If you remove this, bad things will happen to you...
     }
     else
-        Registered = true;
+        cfg.Registered = true;
+
     return 0;
 }
 
@@ -205,7 +207,7 @@
             }
             else
             {
-                mdir = FindMasterDir(MasterDir, entryname);
+                mdir = FindMasterDir(cfg.MasterDir, entryname);
                 replaces = mdir != NULL;
                 /* if it is a level, do the same thing for the next 10 entries too */
                 if (levelname2levelno(entryname))
@@ -307,7 +309,7 @@
         /* if this entry is not in the master directory, then add it */
         if (!replaces)
         {
-            mdir = MasterDir;
+            mdir = cfg.MasterDir;
             while (mdir->next)
                 mdir = mdir->next;
             mdir->next = (MDirPtr) GetMemory(sizeof(struct MasterDirectory));
@@ -323,7 +325,7 @@
             state--;
     }
     verbmsg("\n");
-    master_dir_serial.bump();
+    cfg.master_dir_serial.bump();
 
 // Print list of levels found in this pwad
     if (level_list != NULL)
@@ -378,15 +380,15 @@
         wad_list.del();
 
 // Delete the master directory
-    curd = MasterDir;
-    MasterDir = NULL;
+    curd = cfg.MasterDir;
+    cfg.MasterDir = NULL;
     while (curd)
     {
         nextd = curd->next;
         FreeMemory(curd);
         curd = nextd;
     }
-    master_dir_serial.bump();
+    cfg.master_dir_serial.bump();
 }
 
 
@@ -400,7 +402,7 @@
     while (wad_list.get(wf))
     {
         // Check if the wad file is used by a directory entry
-        MDirPtr mdir = MasterDir;
+        MDirPtr mdir = cfg.MasterDir;
         while (mdir && mdir->wadfile != wf)
             mdir = mdir->next;
         if (mdir == 0)
@@ -508,7 +510,7 @@
 
 
 /*
- *        ListMasterDirectory - list the master directory
+ *        Listcfg.MasterDirectory - list the master directory
  */
 void ListMasterDirectory(FILE * file)
 {
@@ -523,13 +525,13 @@
     fprintf(file,
             "NAME____  FILE______________________________________________"
             "  SIZE__  START____\n");
-    for (dir = MasterDir; dir; dir = dir->next)
+    for (dir = cfg.MasterDir; dir; dir = dir->next)
     {
         strncpy(dataname, dir->dir.name, WAD_NAME);
         fprintf(file, "%-*s  %-50s  %6ld  x%08lx\n",
                 WAD_NAME, dataname, dir->wadfile->pathname(),
                 dir->dir.size, dir->dir.start);
-        if (file == stdout && lines++ > screen_lines - 4)
+        if (file == stdout && lines++ > cfg.screen_lines - 4)
         {
             lines = 0;
             printf
@@ -569,7 +571,7 @@
                 wad->directory[n].size,
                 wad->directory[n].start,
                 wad->directory[n].size + wad->directory[n].start - 1);
-        if (file == stdout && lines++ > screen_lines - 4)
+        if (file == stdout && lines++ > cfg.screen_lines - 4)
         {
             lines = 0;
             printf
@@ -606,15 +608,18 @@
     else
         printf("Building a new Main Wad file \"%s\" (size approx 10 MB)\n",
                filename);
-    if (FindMasterDir(MasterDir, "E2M4") == NULL
-        && FindMasterDir(MasterDir, "MAP01") == NULL
-        && FindMasterDir(MasterDir, "MAP33") == NULL
-        && strcmp(Game, "doom02")
-        && strcmp(Game, "doom04")
-        && strcmp(Game, "doom05") && strcmp(Game, "doompr"))
+    if (FindMasterDir(cfg.MasterDir, "E2M4") == NULL
+        && FindMasterDir(cfg.MasterDir, "MAP01") == NULL
+        && FindMasterDir(cfg.MasterDir, "MAP33") == NULL
+        && strcmp(cfg.Game, "doom02")
+        && strcmp(cfg.Game, "doom04")
+        && strcmp(cfg.Game, "doom05")
+        && strcmp(cfg.Game, "doompr"))
         fatal_error("You were warned: you are not allowed to do this.");
+
     if ((file = fopen(filename, "wb")) == NULL)
         fatal_error("unable to open file \"%s\"", filename);
+
     if (patchonly)
         WriteBytes(file, "PWAD", 4);
     else
@@ -627,7 +632,7 @@
     const Wad_file *iwad = 0;        // FIXME unreliable way of knowing the iwad
     wad_list.rewind();                // got to look into this
     wad_list.get(iwad);
-    for (cur = MasterDir; cur; cur = cur->next)
+    for (cur = cfg.MasterDir; cur; cur = cur->next)
     {
         if (patchonly && cur->wadfile == iwad)
             continue;
@@ -645,7 +650,7 @@
     dirstart = counter;
     counter = 12;
     dirnum = 0;
-    for (cur = MasterDir; cur; cur = cur->next)
+    for (cur = cfg.MasterDir; cur; cur = cur->next)
     {
         if (patchonly && cur->wadfile == iwad)
             continue;
@@ -687,7 +692,7 @@
     unsigned char buf[16];
     const int bytes_per_line = 16;
 
-    for (MDirPtr entry = MasterDir; entry != 0; entry = entry->next)
+    for (MDirPtr entry = cfg.MasterDir; entry != 0; entry = entry->next)
     {
         if (y_strnicmp(entry->dir.name, entryname, WAD_NAME) != 0)
             continue;
@@ -730,7 +735,7 @@
             }
             putc('\n', file);
 
-            if (file == stdout && lines++ > screen_lines - 4)
+            if (file == stdout && lines++ > cfg.screen_lines - 4)
             {
                 lines = 0;
                 printf("[%d%% - Q + Return to abort,"
@@ -770,7 +775,7 @@
 {
     MDirPtr entry;
 
-    for (entry = MasterDir; entry; entry = entry->next)
+    for (entry = cfg.MasterDir; entry; entry = entry->next)
         if (!y_strnicmp(entry->dir.name, entryname, WAD_NAME))
             break;
     if (entry)
@@ -821,7 +826,7 @@
 {
     MDirPtr entry;
 
-    for (entry = MasterDir; entry; entry = entry->next)
+    for (entry = cfg.MasterDir; entry; entry = entry->next)
         if (!y_strnicmp(entry->dir.name, entryname, WAD_NAME))
             break;
     if (entry)
@@ -967,7 +972,7 @@
                 continue;
         else
             y_snprintf(real_name, Y_FILE_NAME + 1, *dirname,
-                       Game ? Game : "");
+                       cfg.Game ? cfg.Game : "");
         al_saps(real_name, real_basename, Y_FILE_NAME);
         verbmsg("  Trying \"%s\"... ", real_name);
         if (file_exists(real_name))
--- a/src/x_hover.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/x_hover.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -160,7 +160,7 @@
 {
     static Close_obj object;
     const int screenslack = 15;        // Slack in pixels
-    double mapslack = fabs(screenslack / Scale);        // Slack in map units
+    double mapslack = fabs(screenslack / cfg.Scale);        // Slack in map units
     int xmin = (int) (x - mapslack + 0.5);
     int xmax = (int) (x + mapslack + 0.5);
     int ymin = (int) (y - mapslack + 0.5);
@@ -234,7 +234,7 @@
             object.obj.num = n;
             object.distance = dist;
             object.radius = (int) (hypot(dx, dy) / 2);
-            object.inside = dist < 2 * Scale;
+            object.inside = dist < 2 * cfg.Scale;
         }
     }
     return object;
@@ -311,7 +311,7 @@
 {
     static Close_obj closest;
     const int screenslack = 15;        // Slack in pixels
-    double mapslack = fabs(screenslack / Scale);        // Slack in map units
+    double mapslack = fabs(screenslack / cfg.Scale);        // Slack in map units
     int max_radius = (int) (get_max_thing_radius() + mapslack);
     int xmin = x - max_radius;
     int xmax = x + max_radius;
@@ -376,10 +376,10 @@
 static const Close_obj & get_cur_vertex(int x, int y)
 {
     static Close_obj object;
-    const int screenradius = vertex_radius(Scale);        // Radius in pixels
+    const int screenradius = vertex_radius(cfg.Scale);        // Radius in pixels
     const int screenslack = screenradius + 15;        // Slack in pixels
-    double mapslack = fabs(screenslack / Scale);        // Slack in map units
-    const int mapradius = (int) (screenradius / Scale);        // Radius in map units
+    double mapslack = fabs(screenslack / cfg.Scale);        // Slack in map units
+    const int mapradius = (int) (screenradius / cfg.Scale);        // Radius in map units
     int xmin = (int) (x - mapslack + 0.5);
     int xmax = (int) (x + mapslack + 0.5);
     int ymin = (int) (y - mapslack + 0.5);
--- a/src/yadex.cc	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/yadex.cc	Mon Sep 26 17:39:49 2011 +0300
@@ -60,92 +60,82 @@
 #include <readline/history.h>
 #endif
 
-/*
- *        Constants (declared in yadex.h)
- */
-const char *const log_file = "yadex.log";
-const char *const msg_unexpected = "unexpected error";
-const char *const msg_nomem = "Not enough memory";
-
-
-/*
- *        Not real variables -- just unique pointer values
- *        used by functions that return pointers to 
- */
-char error_non_unique[1];        // Found more than one
-char error_none[1];                // Found none
-char error_invalid[1];                // Invalid parameter
+const char *const yadex_log_filename = "yadex.log";
 
 
 /*
  *        Global variables
  */
-const char *install_dir = 0;        // Where Yadex is installed
-FILE *logfile = NULL;                // Filepointer to the error log
-bool Registered = false;        // Registered or shareware game?
-int screen_lines = 24;                // Lines that our TTY can display
-int remind_to_build_nodes = 0;        // Remind user to build nodes
-Wad_res wad_res(&MasterDir);
+Wad_res      wad_res(&cfg.MasterDir);
+YadexConfig  cfg;
+
+void InitializeConfig()
+{
+    cfg.install_dir = NULL,        // Where Yadex is installed
+    cfg.logfile = NULL,                // Filepointer to the error log
+    cfg.Registered = false,        // Registered or shareware game?
+    cfg.screen_lines = 24,                // Lines that our TTY can display
+    cfg.remind_to_build_nodes = false,        // Remind user to build nodes
+    cfg.config_file = NULL;
+    cfg.Debug = false;
+
+    // Set from command line and/or config file
+    cfg.autoscroll = false;
+    cfg.autoscroll_amp = 10;
+    cfg.autoscroll_edge = 30;
+    cfg.copy_linedef_reuse_sidedefs = false;
+    cfg.cpu_big_endian = false;
+
+    cfg.def.ceiling_height = 128;
+    strcpy(cfg.def.ceiling_texture, "CEIL3_5");
+    cfg.def.floor_height = 0;
+    strcpy(cfg.def.floor_texture, "FLOOR4_8");
+    cfg.def.light_level = 144;
+    strcpy(cfg.def.lower_texture, "STARTAN3");
+    strcpy(cfg.def.middle_texture, "STARTAN3");
+    strcpy(cfg.def.upper_texture, "STARTAN3");
+    cfg.def.thing = 3004;
+    cfg.double_click_timeout = 200;
+    cfg.Expert = false;
+    cfg.Game = NULL;
 
-// Set from command line and/or config file
-bool autoscroll = 0;
-unsigned long autoscroll_amp = 10;
-unsigned long autoscroll_edge = 30;
-const char *config_file = NULL;
-int copy_linedef_reuse_sidedefs = 0;
-int cpu_big_endian = 0;
-bool Debug = false;
-int default_ceiling_height = 128;
-char default_ceiling_texture[WAD_FLAT_NAME + 1] = "CEIL3_5";
-int default_floor_height = 0;
-char default_floor_texture[WAD_FLAT_NAME + 1] = "FLOOR4_8";
-int default_light_level = 144;
-char default_lower_texture[WAD_TEX_NAME + 1] = "STARTAN3";
-char default_middle_texture[WAD_TEX_NAME + 1] = "STARTAN3";
-char default_upper_texture[WAD_TEX_NAME + 1] = "STARTAN3";
-int default_thing = 3004;
-int double_click_timeout = 200;
-bool Expert = false;
-const char *Game = NULL;
-int grid_pixels_min = 10;
-int GridMin = 2;
-int GridMax = 128;
-int idle_sleep_ms = 50;
-bool InfoShown = true;
-int zoom_default = 0;                // 0 means fit
-int zoom_step = 0;                // 0 means sqrt(2)
-int digit_zoom_base = 100;
-int digit_zoom_step = 0;        // 0 means sqrt(2)
-confirm_t insert_vertex_split_linedef = YC_ASK_ONCE;
-confirm_t insert_vertex_merge_vertices = YC_ASK_ONCE;
-bool blindly_swap_sidedefs = false;
-const char *Iwad1 = NULL;
-const char *Iwad2 = NULL;
-const char *Iwad3 = NULL;
-const char *Iwad4 = NULL;
-const char *Iwad5 = NULL;
-const char *Iwad6 = NULL;
-const char *Iwad7 = NULL;
-const char *Iwad8 = NULL;
-const char *Iwad9 = NULL;
-const char *Iwad10 = NULL;
-const char *MainWad = NULL;
+    cfg.PatchWads = NULL;
+    cfg.Quiet = false;
+    cfg.Quieter = false;
+    cfg.scroll_less = 10;
+    cfg.scroll_more = 90;
+    cfg.Select0 = false;
+    cfg.show_help = false;
+    cfg.sprite_scale = 100;
+    cfg.SwapButtons = false;
+    cfg.verbose = 0;
+    cfg.welcome_message = 1;
+    cfg.bench = NULL;
+
+    memset(cfg.Iwad, 0, sizeof(cfg.Iwad));
+    cfg.MainWad = NULL;
+    
+    
+    cfg.grid_pixels_min = 10;
+    cfg.GridMin = 2;
+    cfg.GridMax = 128;
+    cfg.idle_sleep_ms = 50;
+    cfg.InfoShown = true;
+    cfg.zoom_default = 0;                // 0 means fit
+    cfg.zoom_step = 0;                // 0 means sqrt(2)
+    cfg.digit_zoom_base = 100;
+    cfg.digit_zoom_step = 0;        // 0 means sqrt(2)
+
 #ifdef AYM_MOUSE_HACKS
-int MouseMickeysH = 5;
-int MouseMickeysV = 5;
+    cfg.MouseMickeysH = 5;
+    cfg.MouseMickeysV = 5;
 #endif
-char **PatchWads = NULL;
-bool Quiet = false;
-bool Quieter = false;
-unsigned long scroll_less = 10;
-unsigned long scroll_more = 90;
-bool Select0 = false;
-int show_help = 0;
-int sprite_scale = 100;
-bool SwapButtons = false;
-int verbose = 0;
-int welcome_message = 1;
-const char *bench = 0;
+
+    cfg.insert_vertex_split_linedef = YC_ASK_ONCE;
+    cfg.insert_vertex_merge_vertices = YC_ASK_ONCE;
+    cfg.blindly_swap_sidedefs = false;
+}
+
 
 // Global variables declared in game.h
 yglf_t yg_level_format = YGLF__;
@@ -164,9 +154,7 @@
 /*
  *        Prototypes of private functions
  */
-static int parse_environment_vars();
 static void MainLoop();
-static void print_error_message(const char *fmt, va_list args);
 static void add_base_colours();
 static const Wad_file *wad_by_name(const char *pathname);
 static bool wad_already_loaded(const char *pathname);
@@ -174,23 +162,41 @@
 typedef struct
 {
     const char *game, *wadname;
-    const char **pwadloc;
 } GameInfo;
 
-GameInfo gameList[] = {
-    {"doom", "doom.wad", &Iwad1},
-    {"doom2", "doom2.wad", &Iwad2},
-    {"heretic", "heretic.wad", &Iwad3},
-    {"hexen", "hexen.wad", &Iwad4},
-    {"strife", "strife1.wad", &Iwad5},
-    {"doom02", "Doom alpha 0.2 IWAD", &Iwad6},
-    {"doom04", "Doom alpha 0.4 IWAD", &Iwad7},
-    {"doom05", "Doom alpha 0.5 IWAD", &Iwad8},
-    {"doompr", "Doom Press Release IWAD", &Iwad9},
-    {"strife10", "strife1.wad", &Iwad10}
+GameInfo gameList[IWAD_LAST] = {
+    {"doom",       "doom.wad"},
+    {"doom2",      "doom2.wad"},
+    {"heretic",    "heretic.wad"},
+    {"hexen",      "hexen.wad"},
+    {"strife",     "strife1.wad"},
+    {"doom02",     "Doom alpha 0.2 IWAD"},
+    {"doom04",     "Doom alpha 0.4 IWAD"},
+    {"doom05",     "Doom alpha 0.5 IWAD"},
+    {"doompr",     "Doom Press Release IWAD"},
+    {"strife10",   "strife1.wad"}
 };
 
-const int ngameList = sizeof(gameList) / sizeof(gameList[0]);
+
+/*
+ *        parse_environment_vars
+ *        Check certain environment variables.
+ */
+static void parse_environment_vars(void)
+{
+    char *value;
+
+    if ((value = getenv("YADEX_GAME")) != NULL)
+        cfg.Game = value;
+
+    if ((value = getenv("LINES")) != NULL)
+        cfg.screen_lines = atoi(value);
+    else
+        cfg.screen_lines = 0;
+
+    if (cfg.screen_lines == 0)
+        cfg.screen_lines = 24;
+}
 
 
 /*
@@ -201,21 +207,12 @@
 {
     int r;
 
-// Set <screen_lines>
-    if (getenv("LINES") != NULL)
-        screen_lines = atoi(getenv("LINES"));
-    else
-        screen_lines = 0;
-    if (screen_lines == 0)
-        screen_lines = 24;
+    InitializeConfig();
+    parse_environment_vars();
 
-// First detect manually --help and --version
-// because parse_command_line_options() cannot.
     if (argc == 2 && strcmp(argv[1], "--help") == 0)
     {
         print_usage(stdout);
-        if (fflush(stdout) != 0)
-            fatal_error("stdout: %s", strerror(errno));
         exit(0);
     }
     if (argc == 2 && strcmp(argv[1], "--version") == 0)
@@ -223,18 +220,16 @@
         puts(what());
         puts(config_file_magic);
         puts(ygd_file_magic);
-        if (fflush(stdout) != 0)
-            fatal_error("stdout: %s", strerror(errno));
         exit(0);
     }
 
-// Second a quick pass through the command line
-// arguments to detect -?, -f and -help.
+    // Second a quick pass through the command line
+    // arguments to detect -?, -f and -help.
     r = parse_command_line_options(argc - 1, argv + 1, 1);
     if (r)
         goto syntax_error;
 
-    if (show_help)
+    if (cfg.show_help)
     {
         print_usage(stdout);
         exit(1);
@@ -242,26 +237,24 @@
 
     printf("%s\n", what());
 
-// Where am I installed ? (the config file might be there)
+    // Where am I installed ? (the config file might be there)
 #if defined Y_DOS
     install_dir = spec_path(argv[0]);
 #endif
 
-// The config file provides some values.
-    if (config_file != NULL)
-        r = parse_config_file_user(config_file);
+    // The config file provides some values.
+    if (cfg.config_file != NULL)
+        r = parse_config_file_user(cfg.config_file);
     else
         r = parse_config_file_default();
+
     if (r == 0)
     {
         // Environment variables can override them.
-        r = parse_environment_vars();
-        if (r == 0)
-        {
-            // And the command line argument can override both.
-            r = parse_command_line_options(argc - 1, argv + 1, 2);
-        }
+        parse_environment_vars();
+        r = parse_command_line_options(argc - 1, argv + 1, 2);
     }
+
     if (r != 0)
     {
       syntax_error:
@@ -269,15 +262,15 @@
         exit(1);
     }
 
-    if (Game != NULL)
+    if (cfg.Game != NULL)
     {
         int n;
-        for (n = 0; n < ngameList; n++)
+        for (n = 0; n < IWAD_LAST; n++)
         {
             GameInfo *info = &gameList[n];
-            if (strcmp(Game, info->game) == 0)
+            if (strcmp(cfg.Game, info->game) == 0)
             {
-                if (*(info->pwadloc) == NULL)
+                if (cfg.Iwad[n] == NULL)
                 {
                     err("You have to tell me where %s is.", info->wadname);
                     fprintf(stderr,
@@ -285,83 +278,93 @@
                             n + 1, n + 1);
                     exit(1);
                 }
-                MainWad = *(info->pwadloc);
+                cfg.MainWad = cfg.Iwad[n];
             }
         }
     }
 
-    if (MainWad == NULL)
+    if (cfg.MainWad == NULL)
     {
         int n;
-        if (Game == NULL)
+        if (cfg.Game == NULL)
             err("You didn't say for which game you want to edit.");
         else
-            err("Unknown game \"%s\"", Game);
+            err("Unknown game \"%s\"", cfg.Game);
+
         fprintf(stderr,
                 "Use \"-g <game>\" on the command line or put \"game=<game>\" in yadex.cfg\n"
                 "where <game> is one of: ");
-        for (n = 0; n < ngameList; n++)
+
+        for (n = 0; n < IWAD_LAST; n++)
         {
             fprintf(stderr, "%s\"%s\"", n > 0 ? ", " : "", gameList[n].game);
         }
         fprintf(stderr, ".\n");
         exit(1);
     }
-    if (Debug)
+
+    if (cfg.Debug)
     {
-        logfile = fopen(log_file, "a");
-        if (logfile == NULL)
-            warn("can't open log file \"%s\" (%s)", log_file,
+        cfg.logfile = fopen(yadex_log_filename, "a");
+        if (cfg.logfile == NULL)
+        {
+            warn("Can't open log file \"%s\" (%s)", yadex_log_filename,
                  strerror(errno));
+        }
+
+        LogMessage(": Main IWAD = '%s'\n", cfg.MainWad);
         LogMessage(": Welcome to Yadex!\n");
     }
-    if (Quieter)
-        Quiet = true;
 
-// Sanity checks (useful when porting).
+    if (cfg.Quieter)
+        cfg.Quiet = true;
+
+    // Sanity checks (useful when porting).
     check_types();
     check_charset();
 
-// Misc. things done only once.
-    cpu_big_endian = native_endianness();
+    // Misc. things done only once.
+    cfg.cpu_big_endian = native_endianness();
     add_base_colours();
 
-// Load game definitions (*.ygd).
+    // Load game definitions (*.ygd).
     InitGameDefs();
-    LoadGameDefs(Game);
+    LoadGameDefs(cfg.Game);
 
-// Load the iwad and the pwads.
-    if (OpenMainWad(MainWad))
+    // Load the iwad and the pwads.
+    if (OpenMainWad(cfg.MainWad))
         fatal_error("If you don't give me an iwad, I'll quit. I'm serious.");
-    if (PatchWads)
+
+    if (cfg.PatchWads)
     {
         const char *const *pwad_name;
-        for (pwad_name = PatchWads; *pwad_name; pwad_name++)
+        for (pwad_name = cfg.PatchWads; *pwad_name; pwad_name++)
             OpenPatchWad(*pwad_name);
     }
-/* sanity check */
+
+    /* sanity check */
     CloseUnusedWadFiles();
 
-// BRANCH 1 : benchmarking (-b)
-    if (bench != 0)
+    // BRANCH 1 : benchmarking (-b)
+    if (cfg.bench != NULL)
     {
-        benchmark(bench);
+        benchmark(cfg.bench);
         return 0;                // Exit successfully
     }
 
 // BRANCH 2 : normal use ("yadex:" prompt)
     else
     {
-        if (welcome_message)
+        if (cfg.welcome_message)
             print_welcome(stdout);
 
-        if (strcmp(Game, "hexen") == 0)
+        if (strcmp(cfg.Game, "hexen") == 0)
             printf
                 ("WARNING: Hexen mode is experimental. Don't expect to be able to do any\n"
                  "real Hexen editing with it. You can edit levels but you can't save them.\n"
                  "And there might be other bugs... BE CAREFUL !\n\n");
 
-        if (strcmp(Game, "strife") == 0)
+        if (strcmp(cfg.Game, "strife") == 0)
             printf
                 ("WARNING: Strife mode is experimental. Many thing types, linedef types,\n"
                  "etc. are missing or wrong. And be careful, there might be bugs.\n\n");
@@ -374,9 +377,11 @@
     CloseWadFiles();
     FreeGameDefs();
     LogMessage(": The end!\n\n\n");
-    if (logfile != NULL)
-        fclose(logfile);
-    if (remind_to_build_nodes)
+
+    if (cfg.logfile != NULL)
+        fclose(cfg.logfile);
+
+    if (cfg.remind_to_build_nodes)
         printf("\n"
                "** You have made changes to one or more wads. Don't forget to pass\n"
                "** them through a nodes builder (E.G. BSP) before running them.\n"
@@ -386,22 +391,6 @@
 
 
 /*
- *        parse_environment_vars
- *        Check certain environment variables.
- *        Returns 0 on success, <>0 on error.
- */
-static int parse_environment_vars()
-{
-    char *value;
-
-    value = getenv("YADEX_GAME");
-    if (value != NULL)
-        Game = value;
-    return 0;
-}
-
-
-/*
    play a fascinating tune
 */
 
@@ -433,6 +422,28 @@
 
 
 /*
+ *        print_error_message
+ *        Print an error message to stderr.
+ */
+static void print_error_message(const char *fmt, va_list args)
+{
+    fflush(stdout);
+    fputs("Error: ", stderr);
+    vfprintf(stderr, fmt, args);
+    fputc('\n', stderr);
+    fflush(stderr);
+
+    if (cfg.Debug && cfg.logfile != NULL)
+    {
+        fputs("Error: ", cfg.logfile);
+        vfprintf(cfg.logfile, fmt, args);
+        fputc('\n', cfg.logfile);
+        fflush(cfg.logfile);
+    }
+}
+
+
+/*
  *        fatal_error
  *        Print an error message and terminate the program with code 2.
  */
@@ -471,27 +482,6 @@
 
 
 /*
- *        print_error_message
- *        Print an error message to stderr.
- */
-static void print_error_message(const char *fmt, va_list args)
-{
-    fflush(stdout);
-    fputs("Error: ", stderr);
-    vfprintf(stderr, fmt, args);
-    fputc('\n', stderr);
-    fflush(stderr);
-    if (Debug && logfile != NULL)
-    {
-        fputs("Error: ", logfile);
-        vfprintf(logfile, fmt, args);
-        fputc('\n', logfile);
-        fflush(logfile);
-    }
-}
-
-
-/*
  *        nf_bug
  *        Report about a non-fatal bug to stderr. The message
  *        should not expand to more than 80 characters.
@@ -551,7 +541,7 @@
     time_t tval;
     char *tstr;
 
-    if (Debug && logfile != NULL)
+    if (cfg.Debug && cfg.logfile != NULL)
     {
         va_start(args, logstr);
         /* if the message begins with ":", output the current date & time first */
@@ -560,10 +550,10 @@
             time(&tval);
             tstr = ctime(&tval);
             tstr[strlen(tstr) - 1] = '\0';
-            fprintf(logfile, "%s", tstr);
+            fprintf(cfg.logfile, "%s", tstr);
         }
-        vfprintf(logfile, logstr, args);
-        fflush(logfile);        /* AYM 19971031 */
+        vfprintf(cfg.logfile, logstr, args);
+        fflush(cfg.logfile);        /* AYM 19971031 */
     }
 }
 
@@ -684,7 +674,7 @@
         /* user asked to quit */
         else if (!strcmp(com, "quit") || !strcmp(com, "q"))
         {
-            if (!Registered)
+            if (!cfg.Registered)
                 printf("Remember to register your copy of the game !\n");
             break;
         }
@@ -707,7 +697,7 @@
             }
             else
             {
-                MDirPtr entry = FindMasterDir(MasterDir, com);
+                MDirPtr entry = FindMasterDir(cfg.MasterDir, com);
                 if (entry != NULL)
                 {
                     level_name = strdup(entry->dir.name);
@@ -719,10 +709,10 @@
                     // Hint absent-minded users
                     if ((tolower(*com) == 'e' && yg_level_name == YGLN_MAP01) ||
                         (tolower(*com) == 'm' && yg_level_name == YGLN_E1M1))
-                        printf(" You are in %s mode.", Game);
+                        printf(" You are in %s mode.", cfg.Game);
                     else
 
-                    if (tolower(*com) == 'e' && com[1] > '1' && !Registered)
+                    if (tolower(*com) == 'e' && com[1] > '1' && !cfg.Registered)
                         printf(" You have the shareware IWAD.");
 
                     printf("\n");
@@ -997,7 +987,7 @@
             while (is.key != YE_EXPOSE);
             com = strtok(NULL, " ");
             force_window_not_pixmap();        // FIXME quick hack
-            patch_dir.refresh(MasterDir);
+            patch_dir.refresh(cfg.MasterDir);
             {
                 char buf[WAD_NAME + 1];
                 *buf = '\0';
@@ -1025,7 +1015,7 @@
             while (is.key != YE_EXPOSE);
             com = strtok(NULL, " ");
             force_window_not_pixmap();        // FIXME quick hack
-            patch_dir.refresh(MasterDir);
+            patch_dir.refresh(cfg.MasterDir);
             {
                 char buf[WAD_TEX_NAME + 1];
                 *buf = '\0';
--- a/src/yadex.h	Mon Sep 26 17:14:54 2011 +0300
+++ b/src/yadex.h	Mon Sep 26 17:39:49 2011 +0300
@@ -64,6 +64,7 @@
 #include "windim.h"
 #include "ymemory.h"
 
+#include "serialnum.h"
 
 /*
  *        Platform-independant types and formats.
@@ -294,19 +295,32 @@
 const int YO_XOR = 'x';                // Argument = mask
 
 
-/*
- *        Even more stuff ("the macros and constants")
- */
-
-extern const char *const log_file;        // "yadex.log"
-
 // Convert screen/window coordinates to map coordinates
-#define MAPX(x)                (OrigX + (int) (((int) (x) - ScrCenterX) / Scale))
-#define MAPY(y)                (OrigY + (int) ((ScrCenterY - (int) (y)) / Scale))
+#define MAPX(x)         (cfg.OrigX + (int) (((int) (x) - cfg.ScrCenterX) / cfg.Scale))
+#define MAPY(y)         (cfg.OrigY + (int) ((cfg.ScrCenterY - (int) (y)) / cfg.Scale))
 
 // Convert map coordinates to screen/window coordinates
-#define SCREENX(x)        (ScrCenterX + (int) (((x) - OrigX) * Scale))
-#define SCREENY(y)        (ScrCenterY + (int) ((OrigY - (y)) * Scale))
+#define SCREENX(x)      (cfg.ScrCenterX + (int) (((x) - cfg.OrigX) * cfg.Scale))
+#define SCREENY(y)      (cfg.ScrCenterY + (int) ((cfg.OrigY - (y)) * cfg.Scale))
+enum {
+    IWAD_DOOM1 = 0,
+    IWAD_DOOM2,
+    IWAD_HERETIC,
+    IWAD_HEXEN,
+    IWAD_STRIFE,
+    IWAD_DOOM02,
+    IWAD_DOOM04,
+    IWAD_DOOM05,
+    IWAD_DOOMPR,
+    IWAD_STRIFE10,
+    IWAD_LAST
+};
+typedef struct
+{
+    // Defined in yadex.cc
+    const char *config_file;        // Name of the configuration file
+    const char *install_dir;        // Where yadex is installed
+    FILE *logfile;                // Filepointer to the error log
 
 // AYM 19980213: InputIntegerValue() uses this to mean that Esc was pressed
 #define IIV_CANCEL  INT_MIN
@@ -314,89 +328,98 @@
 
 
 
-/*
- *        Interfile global variables
- */
+    bool Debug;                // Are we debugging?
+    bool Registered;                // Registered or shareware iwad ?
+    int cpu_big_endian;        // Am I running on a big-endian CPU ?
+
+    /* Error resiliency of during loading of WAD / map data, 0 - 4
+     * 0 = Bail on all errors.
+     * 4 = Ignore almost anything.
+     */
+    int error_res;
+
+    int screen_lines;        // Lines that our TTY can display
+    bool remind_to_build_nodes;        // Remind the user to build nodes
 
-// Defined in yadex.cc
-extern const char *install_dir;        // Where yadex is installed
-extern FILE *logfile;                // Filepointer to the error log
-extern bool Registered;                // Registered or shareware iwad ?
-extern int screen_lines;        // Lines that our TTY can display
-extern int remind_to_build_nodes;        // Remind the user to build nodes
+    // Defaults
+    struct {
+        // For new sectors
+        int ceiling_height;
+        char ceiling_texture[WAD_FLAT_NAME + 1];
+
+        int floor_height;
+        char floor_texture[WAD_FLAT_NAME + 1];
+
+        int light_level;
+
+        // For new linedefs
+        char lower_texture[WAD_TEX_NAME + 1];
+        char middle_texture[WAD_TEX_NAME + 1];
+        char upper_texture[WAD_TEX_NAME + 1];
+
+        // For new things
+        int thing;        // For new THINGS
+    } def;
 
-// Defined in yadex.c and set from
-// command line and/or config file
-extern bool autoscroll;                // Autoscrolling enabled.
-extern unsigned long autoscroll_amp;        // Amplitude in percents of screen/window size.
-extern unsigned long autoscroll_edge;        // Max. dist. in pixels to edge.
-extern const char *config_file;        // Name of the configuration file
-extern int copy_linedef_reuse_sidedefs;
-extern int cpu_big_endian;        // Am I running on a big-endian CPU ?
-extern bool Debug;                // Are we debugging?
-extern int default_ceiling_height;        // For new sectors
-extern char default_ceiling_texture[WAD_FLAT_NAME + 1];        // For new sectors
-extern int default_floor_height;        // For new sectors
-extern char default_floor_texture[WAD_FLAT_NAME + 1];        // For new sectors
-extern int default_light_level;        // For new sectors
-extern char default_lower_texture[WAD_TEX_NAME + 1];        // For new linedefs
-extern char default_middle_texture[WAD_TEX_NAME + 1];        // For new linedefs
-extern int default_thing;        // For new THINGS
-extern char default_upper_texture[WAD_TEX_NAME + 1];        // For new linedefs
-extern int double_click_timeout;        // Max ms between clicks of double click.
-extern bool Expert;                // Don't ask for confirmation for some ops.
-extern const char *Game;        // Name of game "doom", "doom2", "heretic", ...
-extern int grid_pixels_min;        // Minimum grid step in pixels when not locked
-extern int GridMin;                // Minimum grid step in map units
-extern int GridMax;                // Maximum grid step in map units
-extern int idle_sleep_ms;        // Time to sleep after empty XPending()
-extern int zoom_default;        // Initial zoom factor for map
-extern int zoom_step;                // Step between zoom factors in percent
-extern int digit_zoom_base;        // Zoom factor of `1' key, in percent
-extern int digit_zoom_step;        // Step between digit keys, in percent 
-extern confirm_t insert_vertex_merge_vertices;
-extern confirm_t insert_vertex_split_linedef;
-extern bool blindly_swap_sidedefs;
-extern const char *Iwad1;        // Name of the Doom iwad
-extern const char *Iwad2;        // Name of the Doom II iwad
-extern const char *Iwad3;        // Name of the Heretic iwad
-extern const char *Iwad4;        // Name of the Hexen iwad
-extern const char *Iwad5;        // Name of the Strife iwad
-extern const char *Iwad6;        // Name of the Doom alpha 0.2 iwad
-extern const char *Iwad7;        // Name of the Doom alpha 0.4 iwad
-extern const char *Iwad8;        // Name of the Doom alpha 0.5 iwad
-extern const char *Iwad9;        // Name of the Doom press release iwad
-extern const char *Iwad10;        // Name of the Strife 1.0 iwad
-extern const char *MainWad;        // Name of the main wad file
+    const char *Game;        // Name of game "doom", "doom2", "heretic", ...
+    bool Quiet;                // Don't beep when an object is selected
+    bool Quieter;                // Don't beep, even on error
+    bool Expert;                // Don't ask for confirmation for some ops.
+    bool autoscroll;                // Autoscrolling enabled.
+    unsigned long autoscroll_amp;        // Amplitude in percents of screen/window size.
+    unsigned long autoscroll_edge;        // Max. dist. in pixels to edge.
+    int copy_linedef_reuse_sidedefs;
+    int double_click_timeout;        // Max ms between clicks of double click.
+    int grid_pixels_min;        // Minimum grid step in pixels when not locked
+    int GridMin;                // Minimum grid step in map units
+    int GridMax;                // Maximum grid step in map units
+    int idle_sleep_ms;        // Time to sleep after empty XPending()
+    int zoom_default;        // Initial zoom factor for map
+    int zoom_step;                // Step between zoom factors in percent
+    int digit_zoom_base;        // Zoom factor of `1' key, in percent
+    int digit_zoom_step;        // Step between digit keys, in percent 
+    confirm_t insert_vertex_merge_vertices;
+    confirm_t insert_vertex_split_linedef;
+    bool blindly_swap_sidedefs;
+
+
+    char *Iwad[IWAD_LAST];
+    char *MainWad;        // Name of the main wad file
+
 #ifdef AYM_MOUSE_HACKS
-extern int MouseMickeysH;
-extern int MouseMickeysV;
+    int MouseMickeysH;
+    int MouseMickeysV;
 #endif
-extern char **PatchWads;        // List of pwad files
-extern bool Quiet;                // Don't beep when an object is selected
-extern bool Quieter;                // Don't beep, even on error
-extern unsigned long scroll_less;        // %s of screenful to scroll by
-extern unsigned long scroll_more;        // %s of screenful to scroll by
-extern bool Select0;                // Autom. select obj. 0 when switching modes
-extern int show_help;                // Print usage message and exit.
-extern int sprite_scale;        // Relative scale used to display sprites
-extern bool SwapButtons;        // Swap right and middle mouse buttons
-extern int verbose;                // Verbose mode
-extern int welcome_message;        // Print the welcome message on startup.
-extern const char *bench;        // Benchmark to run
+    char **PatchWads;        // List of pwad files
+    unsigned long scroll_less;        // %s of screenful to scroll by
+    unsigned long scroll_more;        // %s of screenful to scroll by
+    bool Select0;                // Autom. select obj. 0 when switching modes
+    int show_help;                // Print usage message and exit.
+    int sprite_scale;        // Relative scale used to display sprites
+    bool SwapButtons;        // Swap right and middle mouse buttons
+    int verbose;                // Verbose mode
+    int welcome_message;        // Print the welcome message on startup.
+    const char *bench;        // Benchmark to run
 
-// Defined in gfx.cc
-extern int ScrMaxX;                // Maximum display X-coord of screen/window
-extern int ScrMaxY;                // Maximum display Y-coord of screen/window
-extern float Scale;                // Scale to draw map 20 to 1
+    // Defined in gfx.cc
+    bool no_pixmap, text_dot;
+    int ScrMaxX;                // Maximum display X-coord of screen/window
+    int ScrMaxY;                // Maximum display Y-coord of screen/window
+    float Scale;                // Scale to draw map 20 to 1
+    int OrigX;                        // Map X-coord of centre of screen/window
+    int OrigY;                        // Map Y-coord of centre of screen/window 
+    int ScrCenterX;                        // Display X-coord of centre of screen/window
+    int ScrCenterY;                        // Display Y-coord of centre of screen/window
 
-// Defined in wads.cc
-extern MDirPtr MasterDir;        // The master directory
-class Serial_num;
-extern Serial_num master_dir_serial;        // The revision# thereof
+    // Defined in wads.cc
+    MDirPtr MasterDir;        // The master directory
+    Serial_num master_dir_serial;        // The revision# thereof
 
-// Defined in edit.cc
-extern bool InfoShown;                // Is the bottom line displayed?
+    // Defined in edit.cc
+    bool InfoShown;                // Is the bottom line displayed?
+} YadexConfig;
+
+extern YadexConfig cfg;
 
 /*
  *        Prototypes
@@ -478,9 +501,6 @@
 const char *GetSectorTypeName(int);
 const char *GetSectorTypeLongName(int);
 
-// nop.cc
-void nop(...);
-
 // s_door.cc (previously in objects.cc)
 void MakeDoorFromSector(int);        /* SWAP! */