diff --git a/log/Makefile b/log/Makefile
index 84cab141af6c0e185bc0ec46487272926fd0a31f..e27a46789ec42872a73ca31a23fd9137fb8fdcfc 100644
--- a/log/Makefile
+++ b/log/Makefile
@@ -50,23 +50,41 @@ CHIPMUNKFLAGS = $(ARCH_OPT)
 
 STDC = c11
 
-CFLAGS =  $(CHIPMUNKFLAGS) -I$(LOGINC) -I$(LOCINC) -I$(XINCLUDEDIR) -DLOGLIB=\"$(LOGLIBDIR)\" -DF_OK=0 -std=$(STDC) -g -Wall -Wextra
-
-DIGOBJ = $(TARGET_DIR)/logsim.o $(TARGET_DIR)/logdig.o $(TARGET_DIR)/logsimasm.o $(TARGET_DIR)/logsimed.o $(TARGET_DIR)/diggates.o \
-         $(TARGET_DIR)/loghier.o $(TARGET_DIR)/logsimh.o $(TARGET_DIR)/swap.o
-ANAOBJ = $(TARGET_DIR)/ana/globals.o $(TARGET_DIR)/ana/nsolver.o $(TARGET_DIR)/ana/main.o $(TARGET_DIR)/ana/inter.o \
-         $(TARGET_DIR)/ana/numbers.o $(TARGET_DIR)/ana/mmeter.o $(TARGET_DIR)/ana/iscope.o $(TARGET_DIR)/ana/devtechp.o\
-	 $(TARGET_DIR)/ana/vdiff.o $(TARGET_DIR)/ana/vswitch.o $(TARGET_DIR)/ana/stairs.o $(TARGET_DIR)/ana/runspec.o \
-	 $(TARGET_DIR)/ana/idiff.o $(TARGET_DIR)/ana/iswitch1.o $(TARGET_DIR)/ana/iswitch2.o $(TARGET_DIR)/ana/devtechn.o \
-	 $(TARGET_DIR)/ana/resfloat.o $(TARGET_DIR)/ana/capfloat.o $(TARGET_DIR)/ana/nfet4.o $(TARGET_DIR)/ana/pfet4.o \
-	 $(TARGET_DIR)/ana/nfet5.o $(TARGET_DIR)/ana/pfet5.o $(TARGET_DIR)/ana/pfet6.o $(TARGET_DIR)/ana/pspc1.o $(TARGET_DIR)/ana/nspc1.o\
-	 $(TARGET_DIR)/ana/nfet7t.o $(TARGET_DIR)/ana/nfet7f.o $(TARGET_DIR)/ana/pfet7t.o $(TARGET_DIR)/ana/pfet7f.o $(TARGET_DIR)/ana/thermal.o\
-	 $(TARGET_DIR)/ana/tc.o $(TARGET_DIR)/ana/moscap.o $(TARGET_DIR)/ana/ganglion.o $(TARGET_DIR)/ana/hres.o $(TARGET_DIR)/ana/physical.o\
-	 $(TARGET_DIR)/ana/npn1.o $(TARGET_DIR)/ana/pnp1.o $(TARGET_DIR)/ana/npn2.o $(TARGET_DIR)/ana/pnp2.o $(TARGET_DIR)/ana/diode1.o\
-	 $(TARGET_DIR)/ana/pwl.o $(TARGET_DIR)/ana/rtd.o
+CFLAGS = $(CHIPMUNKFLAGS) -I$(LOGINC) -I$(LOCINC) -I$(XINCLUDEDIR)	\
+	 -DLOGLIB=\"$(LOGLIBDIR)\" -DF_OK=0 -std=$(STDC) -g -w
+
+DIGOBJ = $(TARGET_DIR)/logsim.o $(TARGET_DIR)/logdig.o		\
+         $(TARGET_DIR)/logsimasm.o $(TARGET_DIR)/logsimed.o	\
+         $(TARGET_DIR)/diggates.o $(TARGET_DIR)/loghier.o	\
+         $(TARGET_DIR)/logsimh.o $(TARGET_DIR)/swap.o
+ANAOBJ = $(TARGET_DIR)/ana/globals.o $(TARGET_DIR)/ana/nsolver.o	\
+         $(TARGET_DIR)/ana/main.o $(TARGET_DIR)/ana/inter.o		\
+         $(TARGET_DIR)/ana/numbers.o $(TARGET_DIR)/ana/mmeter.o		\
+         $(TARGET_DIR)/ana/iscope.o $(TARGET_DIR)/ana/devtechp.o	\
+         $(TARGET_DIR)/ana/vdiff.o $(TARGET_DIR)/ana/vswitch.o		\
+         $(TARGET_DIR)/ana/stairs.o $(TARGET_DIR)/ana/runspec.o		\
+         $(TARGET_DIR)/ana/idiff.o $(TARGET_DIR)/ana/iswitch1.o		\
+         $(TARGET_DIR)/ana/iswitch2.o $(TARGET_DIR)/ana/devtechn.o	\
+         $(TARGET_DIR)/ana/resfloat.o $(TARGET_DIR)/ana/capfloat.o	\
+         $(TARGET_DIR)/ana/nfet4.o $(TARGET_DIR)/ana/pfet4.o		\
+         $(TARGET_DIR)/ana/nfet5.o $(TARGET_DIR)/ana/pfet5.o		\
+         $(TARGET_DIR)/ana/pfet6.o $(TARGET_DIR)/ana/pspc1.o		\
+         $(TARGET_DIR)/ana/nspc1.o $(TARGET_DIR)/ana/nfet7t.o		\
+         $(TARGET_DIR)/ana/nfet7f.o $(TARGET_DIR)/ana/pfet7t.o		\
+         $(TARGET_DIR)/ana/pfet7f.o $(TARGET_DIR)/ana/thermal.o		\
+         $(TARGET_DIR)/ana/tc.o $(TARGET_DIR)/ana/moscap.o		\
+         $(TARGET_DIR)/ana/ganglion.o $(TARGET_DIR)/ana/hres.o		\
+         $(TARGET_DIR)/ana/physical.o $(TARGET_DIR)/ana/npn1.o		\
+         $(TARGET_DIR)/ana/pnp1.o $(TARGET_DIR)/ana/npn2.o		\
+         $(TARGET_DIR)/ana/pnp2.o $(TARGET_DIR)/ana/diode1.o		\
+         $(TARGET_DIR)/ana/pwl.o $(TARGET_DIR)/ana/rtd.o
 
 SIMOBJ = $(TARGET_DIR)/logcom.o $(DIGOBJ) $(ANAOBJ)
-TOOLOBJ = $(SIMOBJ) $(TARGET_DIR)/logspc.o $(TARGET_DIR)/logntk.o
+TOOLOBJ = $(SIMOBJ) $(TARGET_DIR)/logspc.o $(TARGET_DIR)/logntk.o	\
+	  $(TARGET_DIR)/label.o $(TARGET_DIR)/wire.o			\
+	  $(TARGET_DIR)/page.o $(TARGET_DIR)/gate.o			\
+	  $(TARGET_DIR)/screen.o $(TARGET_DIR)/node.o			\
+	  $(TARGET_DIR)/tool.o
 
 
 $(TARGET_DIR)/ana/%.o: $(SRC_DIR)/ana/%.c
diff --git a/log/include/gate.h b/log/include/gate.h
new file mode 100644
index 0000000000000000000000000000000000000000..9df1f6f61c89df96819329431daa8dbd8d59d878
--- /dev/null
+++ b/log/include/gate.h
@@ -0,0 +1,26 @@
+#ifndef GATE_H
+#define GATE_H
+
+#include "logdef.h"
+
+static void uaddgate(short x, short y, short gtype);
+
+static void addgate1(short x, short y, short gtype);
+
+static void pconnectgate(log_grec *g, int *success);
+
+static void delgate(log_grec *g);
+
+static void disconnectgate(log_grec *g);
+
+static void closergate(short x, short y);
+
+static void disposegate(log_grec **g);
+
+static void copygate(log_grec *old, log_grec **g);
+
+static void newgate(log_grec **g, short gt);
+
+static void eragate(log_grec *g);
+
+#endif
diff --git a/log/include/label.h b/log/include/label.h
new file mode 100644
index 0000000000000000000000000000000000000000..8efe5a7d49d689718bcfc0b049b105df1ca2ea60
--- /dev/null
+++ b/log/include/label.h
@@ -0,0 +1,8 @@
+#ifndef LABEL_H
+#define LABEL_H
+
+#include "logdef.h"
+
+static void parselabel(na_strlist_t **lbl, short *numattrs, log_kattrrec **attr);
+
+#endif
diff --git a/log/include/logdef.h b/log/include/logdef.h
index fd0c4e9a47be43b9d258ff7d03ec00485a4f40d0..39dd6a741916814ccfd4a510b7b8d61132edc9b2 100644
--- a/log/include/logdef.h
+++ b/log/include/logdef.h
@@ -1,7 +1,6 @@
 #ifndef LOGDEF_H
 #define LOGDEF_H
 
-
 #include <p2c/mylib.h>
 #include <p2c/strlist.h>
 #include <p2c/newasm.h>
diff --git a/log/include/logglobals.h b/log/include/logglobals.h
new file mode 100644
index 0000000000000000000000000000000000000000..4a61de5480ca70b88071765c974e8488bff9d049
--- /dev/null
+++ b/log/include/logglobals.h
@@ -0,0 +1,295 @@
+#ifndef LOGGLOBALS
+#define LOGGLOBALS
+
+#include "settings.h"
+#include "logstructs.h"
+
+extern char *GetChipmunkPath();
+char *my_strdup();
+#undef strdup
+#define strdup my_strdup
+#define newci_findprocedure2  findprocedure
+extern int findprocedure (char *name, void (**start)());
+
+
+/* 0*/
+/* If the pen is in "this" sector, */
+/* 1*/
+/*   switch to "this" state.       */
+/* 2*/
+/* 3*/
+/* 4*/
+/* 5*/
+/* 6*/
+/* 7*/
+/* 8*/
+/* 9*/
+/*10*/
+/*11*/
+/*12*/
+/*13*/
+/*14*/
+/*15*/
+/*16*/
+/*17*/
+/*18*/
+/*19*/
+/*20*/
+/*21*/
+/*22*/
+/*23*/
+
+static const rablisttype rablist = {
+        { 0, 0, 1 },
+        { 0, 4, 2 },
+        { 0, 3, 3 },
+        { 0, 2, 4 },
+        { 0, 1, 5 },
+        { 0, 0, 6 },
+        { 1, 0, 7 },
+        { 2, 0, 8 },
+        { 3, 0, 9 },
+        { 4, 0, 10 },
+        { 4, 1, 11 },
+        { 4, 2, -12 },
+        { 3, 2, 13 },
+        { 2, 2, 14 },
+        { 1, 2, 15 },
+        { 2, 2, -18 },
+        { 0, 2, 17 },
+        { 1, 2, 15 },
+        { 3, 2, -20 },
+        { 2, 3, -20 },
+        { 3, 3, 21 },
+        { 4, 3, -23 },
+        { 3, 4, -23 },
+        { 4, 4, 42 }
+};
+
+static const rabmustype discomadness = {
+        { 3, 46 },
+        { 0, 8 },
+        { 4, 10 },
+        { 0, 15 },
+        { 4, 12 },
+        { 0, 2 },
+        { 5, 35 },
+        { 0, 6 },
+        { 4, 35 },
+        { 0, 6 },
+        { 5, 8 },
+        { 0, 17 },
+        { 5, 12 },
+        { 0, 2 },
+        { 6, 35 },
+        { 0, 6 },
+        { 5, 35 },
+        { 0, 6 },
+        { 6, 8 },
+        { 0, 17 },
+        { 6, 12 },
+        { 0, 2 },
+        { 8, 35 },
+        { 0, 6 },
+        { 3, 35 },
+        { 0, 6 },
+        { 4, 8 },
+        { 0, 16 },
+        { 4, 12 },
+        { 0, 3 },
+        { 5, 50 },
+        { 0, 0 }
+};
+
+
+static log_action_t gg;   /* External global variables */
+
+static short cursx, cursy;   /* Current position of cursor */
+static short cursx1, cursy1;   /* Wire starting point */
+static short cursx2, cursy2;   /* Wire ending point */
+static short chairx, chairy;   /* Current position of crosshair */
+
+static int cursorflag;   /* Cursor is displayed */
+static int prevcursorflag;
+/* Cursor was displayed before operation began */
+static int chairflag;   /* Crosshair is on screen */
+static int chairflag2;   /* Crosshair will be on screen */
+static int rbandflag;   /* Rubber-band wire is on screen */
+static int rabbits, rabflag;   /* Rabbit mode */
+static int avoidrabbits;
+
+static short txacross, txdown, across, down, baseline, line1, line2,
+                         kindgroupbase, kindgroupleft, kindgroupright, kindgroupstart,
+                         kindgroupsize, histdown;
+
+static int entrycapslock;   /* Capslock status on entry */
+static int oldcapslock;   /* Previous capslock status */
+
+static int signalcaps;   /* Capslock flag for signal-name entry */
+static int labelcaps;   /* Capslock flag for label entry */
+
+static char (*index_)[9];   /* Index into gate library */
+static short *indexoffset;   /* Offset of each gate */
+static uchar *indexfile;   /* File number of each gate */
+static uchar *indexgroup;   /* Group number of each gate */
+static uchar *loadedgates;   /* Tells whether a gate is in the catalog */
+static log_krec *kind[maxmaxkinds];   /* Kind of gate in each catalog space */
+static kindgrouptype kindgroup;   /* Kind of gate in each menu-area space */
+static kindgrouptype kindsig;
+static kindattrtype kindattr;
+static na_strlist_t *gatefilenames;
+static short maxkinds, catwidth;
+static catboxrec *catboxes;
+static librstrrec *librstrs;
+
+static char *gatesname[maxgatesfiles];
+static char *loghelpname, *lognewsname;   /* Names of system files */
+
+static long temp1, temp2, temp3, temp4;   /* For use by main program */
+static char tempch;
+
+static short zoom;   /* Zooming level */
+static int ospointflag;   /* Starting point was touched */
+
+static long xoff0, yoff0;   /* Old XOFF, YOFF */
+
+static short curwcolor;   /* Current VLSI wire color */
+static char cureditmode;   /* Current editing (gate-tapping) mode */
+static short curlistgroup;   /* Current group in library list */
+
+static int vlsimode[log_maxpages];   /* Page contains VLSI circuits */
+static long xoffp[log_maxpages], yoffp[log_maxpages];
+/* XOFF, YOFF for non-current pages */
+static short gatecount[log_maxpages];   /* Highest used gate-ID number */
+static char *curfilename[log_maxpages];   /* Name of last-loaded file */
+static long realcurpage;
+
+static log_nrec *freenode;   /* Node "free" list */
+static log_grec *freegate;   /* Gate "free" list */
+
+static baseptrs copybuf;   /* Del/Copy/Paste buffer */
+
+static long htcount;   /* Number of timesteps in list */
+static short hncount;   /* Number of names in list */
+static short hnocount;   /* Old number of names in list */
+static short histtrig;   /* Number of signal which triggers history */
+static na_strlist_t *histlbl;
+static short histnumattrs;
+static log_kattrrec *histkattr;
+static log_gattrrec *histgattr;
+static short histgridmode, histgridwhich;
+static log_hnrec *histgridhn;
+static double histvalrange, histdivsacross;
+static int histonscreen;   /* Leading edge of trace is visible */
+static int histreset;   /* Clear the history memory */
+static double histtime;   /* Current time for history mode */
+
+static int probeflag;   /* Has the probe been checked? */
+
+static log_nrec *nodeconflictbase;   /* Node conflict list */
+static log_grec *gateconflictbase;   /* Gate conflict list */
+
+static cnfrec *cnfbase;   /* List of tool configuration lines */
+static na_strlist_t *colorbase;   /* List of configured colors */
+static macrorec *macrobase;   /* List of macro keys */
+static na_strlist_t *thingstodo, *nexttodo;   /* List of delayed commands */
+static na_strlist_t *messages;   /* List of delayed messages */
+static na_strlist_t *commandlist;   /* List of tool-activation commands */
+
+static char modename[9];   /* Word in 'mode' area of menu */
+static int modeflag;   /* Mode area contains a word */
+static long modetime;   /* Time (in minutes) in mode display */
+static log_krec *modeprobekind;
+
+static nk_keytransinfo *curkeytrans;   /* Current keyboard definitions */
+
+static enum {
+        normal, grid, delete__, copy_, paste, boxcursor
+} cursortype, oldcursortype;
+/* Type of cursor */
+
+/*  menupicture, errorpicture : m_picturevar;              { Various saved images */
+static short bottomcount;   /* How many nested BEGINBOTTOMs */
+
+static uchar rcolormap[16], gcolormap[16], bcolormap[16];
+
+static short gategreen, gateyellow, gatered, gateorange, gateblack, gatewhite;
+
+static short defineboxcolor, definebackcolor, definetextcolor, catboxcolor;
+
+static short messagepos;   /* Position of next message */
+static short messageright;   /* Maximum width of messages */
+
+static long fastsavetime;
+
+static long watchdog, rabtime;   /* Miscellaneous timers */
+
+static log_tool *simtype_ignore;   /* Non-simulated type */
+static log_tool *simtype_common;   /* Common-pin type */
+
+static double status_oldtime, status_oldtstep;
+static long status_oldmem;
+
+static rablistrec rabtable[rabtabsize];   /* Positions of rabbits */
+static short rabstate;   /* Rabbit recognizer state */
+
+static long helpptr;   /* Help descriptor */
+
+static int popup_grid;   /* Pop-up menus */
+static logmenurec *popupmenus[4];
+
+static filerecfilerec *libf1[maxgatesfiles];   /* Library files */
+static short libfstart[maxgatesfiles];
+/* First descriptor record in LIBF1 */
+static short libptr;   /* Most recently replaced catalog item */
+static short idxsize;   /* Number of gates in library */
+static char *librgroupnames[9];
+
+static short refrtimer, refrtimer0;   /* Time until screen is refreshed */
+
+static long tabletaddr;
+
+static char *dumpfname, *tracefname;
+static FILE *dumpfile, *tracefile;
+
+static long programmark;
+
+static char pushedbackkey, realkey;
+
+extern long EXCP_LINE;   /* Line number of last error */
+static long excpline;
+
+static short conflictdelay;
+
+static int eightcolors;   /* Has only 8 colors */
+static int onescreen;   /* Has only one screen */
+static int doingcnffunction;   /* This is an ACT_CNF, not an ACT_FUNC */
+static int justonecommand;   /* LOG -R mode, so exit after first cmd */
+static int displaynews;   /* LOGNEWS has not yet been displayed */
+static int immedscroll;   /* Don't need to defer 'REFR' function */
+static int tempverbose;   /* Verbose mode temporarily on */
+static int commandfound;   /* Function name was acknowledged */
+static int cursorhide;   /* Cursor is hidden */
+static int reportnowait;   /* Don't wait for key on bug reports */
+static int firsttraining;   /* Training used for first time */
+static int training;   /* Training mode for Help command */
+static int snapflag;   /* Snap-to-grid cursor */
+static int showsolder;   /* Display solder points */
+static int briefprobe;   /* Temporary probe mode */
+static int conflictenbl;   /* Conflict checking enabled */
+static int conflictstop;   /* Conflict stopping mode */
+static int anyconflicts;   /* Any active, reported conflicts? */
+static int steppingoff;   /* Single-step is turning simulation off */
+static int suppressdots;   /* Temporarily suppressing red dots */
+static int glowsolder;   /* Display solder dots in Glow mode */
+static int vlsi;   /* Current page is VLSI mode */
+
+
+extern void m_saveclip ();
+
+extern void nc_cursor_on ();
+
+extern void nc_cursor_off ();
+
+
+#endif
diff --git a/log/include/logstructs.h b/log/include/logstructs.h
new file mode 100644
index 0000000000000000000000000000000000000000..beb542e95782bce8dd8a4eb44d27fe68baac8e47
--- /dev/null
+++ b/log/include/logstructs.h
@@ -0,0 +1,131 @@
+#ifndef LOGSTRUCTS
+#define LOGSTRUCTS
+
+
+#include "logdef.h"
+
+/** ??? */
+typedef struct descrec {
+        long ptr;
+        uchar numvects, numpins, numpnums, lblsize, simtype, procsize;
+        /* log_kflags */ short flag;
+        schar xx1, yy1, xx2, yy2;
+} descrec;
+
+/** 2D vector */
+typedef struct ovectorrec {
+        schar x1, y1, x2, y2;
+} ovectorrec;
+
+/** Union representing a pack of 256 bytes */
+typedef union filerec {
+        uchar b[256];
+        schar sb[256];
+        char c[256];
+        short sh[128];
+        long i[64];
+        log_pac8 ix[32];
+        ovectorrec vec[64];
+        log_pinrec pin[64];
+        log_pnumrec pnum[64];
+        descrec desc[16];
+        log_pac4 c4[64];
+} filerec;
+
+typedef struct filerecfilerec {
+        FILE *f;
+        FILEBUFNC(f,filerec);
+} filerecfilerec;
+
+typedef struct rablistrec {
+        short x, y, next;
+} rablistrec;   /* Rabbit mode state descriptor */
+
+typedef rablistrec rablisttype[rablistsize + 1];
+
+typedef struct rabmusrec {
+        short note, time;
+} rabmusrec;   /* Rabbit music descriptor */
+
+typedef rabmusrec rabmustype[rabmussize];
+
+typedef short kindgrouptype[kindgroupmaxsize];
+typedef log_gattrrec *kindattrtype[kindgroupmaxsize];
+
+typedef uchar loadedgatesarray[(log_million + 7) / 8];
+typedef char indexarray[log_million][9];
+typedef short ioffsetarray[log_million];
+typedef uchar igrouparray[log_million];
+/* Index to gate library */
+
+typedef struct logmenurec {
+        char name[17];
+        char cmd[33];
+        int *bool_;
+} logmenurec;   /* Pop-up menu options */
+
+typedef logmenurec logmenutype[8];
+
+
+
+/* Pointer to node-combination record */
+/* Pointer to temporary solder */
+/* Pointer to configuration record */
+/* Pointer to macro key record */
+/* Pointer to box in catalog page */
+/* Pointer to library string record */
+
+
+typedef struct cnrec {
+        log_nrec *n, **np;
+        int done;
+        struct cnrec *next;
+} cnrec;   /* Delayed Combinenodes record */
+
+
+typedef struct blobrec {
+        log_hwrec *hw;
+        log_vwrec *vw;
+        short x, y;
+        struct blobrec *next;
+} blobrec;
+
+
+typedef struct cnfrec {
+        char tool[17];
+        struct cnfrec *next;
+        char s[256];   /*not fully allocated*/
+} cnfrec;   /* Tool configuration record */
+
+
+typedef struct macrorec {
+        char key;
+        struct macrorec *next;
+        char name[33];
+} macrorec;   /* Macro key */
+
+typedef struct catboxrec {
+        short pos, count;
+        struct catboxrec *next;
+} catboxrec;   /* yow */
+
+
+typedef struct librstrrec {
+        char name[9];
+        char *str;
+        struct librstrrec *left, *right;
+} librstrrec;
+
+
+typedef struct baseptrs {
+        log_grec *gcopy;
+        log_srec *scopy;
+        log_hwrec *hwcopy;
+        log_vwrec *vwcopy;
+        log_lrec *lcopy;
+        log_brec *bcopy;
+        short x1copy, y1copy, x2copy, y2copy, dxcopy, dycopy, pgnum;
+        int valid;
+} baseptrs;
+
+#endif
diff --git a/log/include/node.h b/log/include/node.h
new file mode 100644
index 0000000000000000000000000000000000000000..2189e4189a149132dc311a9cb5316bc5867b73c2
--- /dev/null
+++ b/log/include/node.h
@@ -0,0 +1,24 @@
+#ifndef NODE_H
+#define NODE_H
+
+#include "logdef.h"
+
+static void dumpnodes();
+
+static void switchnode(log_nrec **n, log_nrec *n2);
+
+static void disposenode(log_nrec **n);
+
+static void copynode(log_nrec *old, log_nrec **n);
+
+static void newnode(log_nrec **n, uchar st);
+
+/* Local variables for checkcombine: */
+struct LOC_checkcombine {
+	cnrec **cnbase;
+	short passcount;
+	int good;
+	log_tool *cursimtype;
+};
+
+#endif
diff --git a/log/include/page.h b/log/include/page.h
new file mode 100644
index 0000000000000000000000000000000000000000..3f65d1d328af0d2193098463f111ff1d8c33b633
--- /dev/null
+++ b/log/include/page.h
@@ -0,0 +1,6 @@
+#ifndef PAGE_H
+#define PAGE_H
+
+static void chpage(short pg);
+
+#endif
diff --git a/log/include/screen.h b/log/include/screen.h
new file mode 100644
index 0000000000000000000000000000000000000000..603ef74e22a49b33953bc1bfe3a1c74b3f949b8e
--- /dev/null
+++ b/log/include/screen.h
@@ -0,0 +1,60 @@
+#ifndef SCREEN_H
+#define SCREEN_H
+
+#include "logdef.h"
+
+static void plainxformcoords(log_grec *g, short *x, short *y);
+
+static void clipoff();
+
+static void initscreen();
+
+static void initscreen2();
+
+static void refrscreen1();
+
+static void refrscreen();
+
+static void endbottom();
+
+static void beginbottom();
+
+static void refreshsoon();
+
+static void refresh();
+
+static void drawnodec(log_nrec *n, short c);
+
+static void drawgatex(log_grec *g);
+
+static void drawgatexc(log_grec *g, short c);
+
+static void udrawgatec(short x, short y, short g, short c);
+
+static void drawgatec(short x, short y, short g, short c);
+
+static void clearscreen();
+
+static void remcursor();
+
+static void clipon();
+
+static void centerstr2(short x, short y, char *s);
+
+static void rightstr2(short x, short y, char *s);
+
+static void drawstr2(short x, short y, char *s);
+
+static void clearalpha();
+
+static void xformcoords(log_grec *g, short *x, short *y);
+
+static void setdimgate(log_grec *g, int dim);
+
+static void hidecursorrect_hook(long x1, long y1, long x2, long y2);
+
+static void unhidecursor_hook();
+
+static void hidecursor_hook();
+
+#endif
diff --git a/log/include/settings.h b/log/include/settings.h
new file mode 100644
index 0000000000000000000000000000000000000000..39be2a94083d71a790b4c70e6c1a127aacc19102
--- /dev/null
+++ b/log/include/settings.h
@@ -0,0 +1,117 @@
+#ifndef SETTINGS_H
+#define SETTINGS_H
+
+#define debuglog        false
+#define debugprint      true
+
+#ifndef LOGLIB
+
+#define LOGLIB          "/LIB/LOG"
+#endif
+
+#define gridcen         25   /* Center of "grid" used while drawing gates */
+
+#define memtolerance    20000   /* Minimum "safe" amount of free memory */
+
+#define charheight      8   /* Height of text characters */
+
+#define tapdelay        30  /* How long to wait before a "tap" becomes a "press" */
+#define taptolerance    5   /* How far you can move before a "tap" becomes a "press" */
+#define knobwait        25   /* How long to wait for the knob during scroll */
+
+#define deffastmin      2   /* Simulator delay for good response (csecs) */
+#define deffastmax      50   /* Simulator delay for fast simulation */
+#define deffastrate     35   /* Centiseconds per increase in fastspeed */
+
+#define frytime         50   /* How long a frying object fries, in csecs */
+
+#define chrplain        128
+#define chrinverse      129
+#define chrunderl       132
+
+#define chrgreen        136
+#define chryellow       137
+#define chrblack        138
+#define chrred          139
+#define chrcyan         140
+#define chrwhite        141
+#define chrblue         142
+#define chrpurple       143
+
+#define EXEC            "\003"   /* ASCII code of EXECUTE key */
+#define CTRLD           "\253"   /* Control-D */
+
+
+#define maxmaxkinds     255   /* Maximum number of gates in catalog */
+
+#define maxgatesfiles   15
+#define defmaxsignal    500   /* Maximum number of TO/FROM nodes */
+#define defhtmaxcount   500   /* Maximum number of history timesteps */
+
+#define origin          16384   /* Origin of grid coordinate system */
+
+#define topmessagepos   2   /* Position of first message */
+
+#define maxrots         8   /* Number of gate orientations */
+
+#define hscrollspd      2   /* Knob-scrolling speed */
+#define vscrollspd      2
+#define hfastscrollspd  10   /* Menu-box-scrolling speed */
+#define vfastscrollspd  10
+
+#define watchdogtime    500   /* Time limit for CLR I/O "watchdog" timer */
+
+#define refrdelay       70   /* Delay before refreshing screen */
+
+#define baselinewidth   80
+#define kindgroupmaxsize  40   /* Stuff about gate slots in menu area */
+
+#define kindgroupspacing  (gridcen * 2)
+
+#define maxsafescale    (gridcen / log_scale0)
+
+#define menux1          1
+#define menux2          48
+#define menux3          (-69)
+#define menux4          (-27)
+
+#define pigsfly         false   /*  */
+
+#define gattrrecsize    (sizeof(log_gattrrec) + ((sizeof(log_gattrrec)) & 1))
+#define kattrrecsize    (sizeof(log_kattrrec) + ((sizeof(log_kattrrec)) & 1))
+
+#define histleft        40
+#define histvscale      6
+/*(histdown div 24) * 2*/
+#define histdivision    30
+
+#define histsweeptype   1
+#define histtrigsig     2
+#define histstarttime   3
+#define histstoptime    4
+#define histfullaction  5
+#define histminstep     6
+#define histmaxstep     7
+#define histmaxcount    8
+#define histcurcount    9
+#define histalignsigs   10
+#define histfirsttime   11
+#define histcurtime     12
+#define histsecdiv      13
+#define histcurtstep    14
+
+#define histsweep_contin  0
+#define histsweep_onreset  1
+#define histsweep_trig  2
+#define histsweep_manual  3
+
+#define rablistsize     23   /* Size of Rabbit State Machine */
+#define rabtabsize      10   /* Maximum number of rabbits on screen */
+#define rabmussize      32   /* Length of rabbit theme music */
+#define rabdelay        30000   /* Time to wait for rabbit: 5 Minutes */
+
+#define NAMEGAP         (3 * gg.scale) /* signallabel horizontal offset */
+
+#define maxeditmodes    4
+
+#endif
diff --git a/log/include/tool.h b/log/include/tool.h
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/log/include/wire.h b/log/include/wire.h
new file mode 100644
index 0000000000000000000000000000000000000000..4bcd797e958272e6f0df349ed1fa1656523041d4
--- /dev/null
+++ b/log/include/wire.h
@@ -0,0 +1,22 @@
+#ifndef WIRE_H
+#define WIRE_H
+
+#include "logdef.h"
+
+static void addvwire2(short x, short y1, short y2);
+
+static void addhwire2(short x1, short x2, short y);
+
+static void delvwire(log_vwrec *vw);
+
+static void delhwire(log_hwrec *hw);
+
+static void closerwire(short x, short y);
+
+/* Local variables for wantsolder: */
+struct LOC_wantsolder
+{
+	int hasred, hasgreen, hasyellow, hasblue;
+};
+
+#endif
diff --git a/log/src/gate.c b/log/src/gate.c
index 26d3bfca7678b68ca8d30cf0ed4367af36817134..d9b76e0b511dcbf6dd5e7874f984d8dbfff3fa23 100644
--- a/log/src/gate.c
+++ b/log/src/gate.c
@@ -1,5 +1,9 @@
 
 #include <p2c/p2c.h>
+#include <p2c/newkbd.h>
+#include "logfont.h"
+#include "logglobals.h"
+#include "gate.h"
 
 /*================  INSIDEGATE  ==================*/
 /*=                                              =*/
diff --git a/log/src/label.c b/log/src/label.c
index 8ab234f0fe3b7012b71dc7b45bdf53bd05bf183a..2aeaea8c936abedce3721b884ec41b03d3c572c4 100644
--- a/log/src/label.c
+++ b/log/src/label.c
@@ -1,5 +1,10 @@
 
-#include <p2c/p2c.j>
+#include <p2c/p2c.h>
+#include <p2c/newkbd.h>
+#include "settings.h"
+#include "logglobals.h"
+#include "logfont.h"
+#include "label.h"
 
 /**
  *  @param lbl: list of character to parse
diff --git a/log/src/log.c b/log/src/log.c
index d2f9244647d7cb7d051b6cdb728646582fdfbea7..5f4c5fb17181977bc8fc5306823fcacbbc006330 100644
--- a/log/src/log.c
+++ b/log/src/log.c
@@ -65,530 +65,16 @@
 #include <p2c/newasm.h>
 #include <p2c/newcrt.h>
 
-extern char *GetChipmunkPath();
-char *my_strdup();
-#undef strdup
-#define strdup my_strdup
-#define newci_findprocedure2  findprocedure
-extern int findprocedure (char *name, void (**start)());
+#include "settings.h"
+#include "logstructs.h"
+#include "logglobals.h"
 
-
-#define debuglog        false
-#define debugprint      true
-
-#ifndef LOGLIB
-
-#define LOGLIB          "/LIB/LOG"
-#endif
-
-#define gridcen         25   /* Center of "grid" used while drawing gates */
-
-#define memtolerance    20000   /* Minimum "safe" amount of free memory */
-
-#define charheight      8   /* Height of text characters */
-
-#define tapdelay        30  /* How long to wait before a "tap" becomes a "press" */
-#define taptolerance    5   /* How far you can move before a "tap" becomes a "press" */
-#define knobwait        25   /* How long to wait for the knob during scroll */
-
-#define deffastmin      2   /* Simulator delay for good response (csecs) */
-#define deffastmax      50   /* Simulator delay for fast simulation */
-#define deffastrate     35   /* Centiseconds per increase in fastspeed */
-
-#define frytime         50   /* How long a frying object fries, in csecs */
-
-#define chrplain        128
-#define chrinverse      129
-#define chrunderl       132
-
-#define chrgreen        136
-#define chryellow       137
-#define chrblack        138
-#define chrred          139
-#define chrcyan         140
-#define chrwhite        141
-#define chrblue         142
-#define chrpurple       143
-
-#define EXEC            "\003"   /* ASCII code of EXECUTE key */
-#define CTRLD           "\253"   /* Control-D */
-
-
-#define maxmaxkinds     255   /* Maximum number of gates in catalog */
-
-#define maxgatesfiles   15
-#define defmaxsignal    500   /* Maximum number of TO/FROM nodes */
-#define defhtmaxcount   500   /* Maximum number of history timesteps */
-
-#define origin          16384   /* Origin of grid coordinate system */
-
-#define topmessagepos   2   /* Position of first message */
-
-#define maxrots         8   /* Number of gate orientations */
-
-#define hscrollspd      2   /* Knob-scrolling speed */
-#define vscrollspd      2
-#define hfastscrollspd  10   /* Menu-box-scrolling speed */
-#define vfastscrollspd  10
-
-#define watchdogtime    500   /* Time limit for CLR I/O "watchdog" timer */
-
-#define refrdelay       70   /* Delay before refreshing screen */
-
-#define baselinewidth   80
-#define kindgroupmaxsize  40   /* Stuff about gate slots in menu area */
-
-#define kindgroupspacing  (gridcen * 2)
-
-#define maxsafescale    (gridcen / log_scale0)
-
-#define menux1          1
-#define menux2          48
-#define menux3          (-69)
-#define menux4          (-27)
-
-#define pigsfly         false   /*  */
-
-#define gattrrecsize    (sizeof(log_gattrrec) + ((sizeof(log_gattrrec)) & 1))
-#define kattrrecsize    (sizeof(log_kattrrec) + ((sizeof(log_kattrrec)) & 1))
-
-#define histleft        40
-#define histvscale      6
-/*(histdown div 24) * 2*/
-#define histdivision    30
-
-#define histsweeptype   1
-#define histtrigsig     2
-#define histstarttime   3
-#define histstoptime    4
-#define histfullaction  5
-#define histminstep     6
-#define histmaxstep     7
-#define histmaxcount    8
-#define histcurcount    9
-#define histalignsigs   10
-#define histfirsttime   11
-#define histcurtime     12
-#define histsecdiv      13
-#define histcurtstep    14
-
-#define histsweep_contin  0
-#define histsweep_onreset  1
-#define histsweep_trig  2
-#define histsweep_manual  3
-
-#define rablistsize     23   /* Size of Rabbit State Machine */
-#define rabtabsize      10   /* Maximum number of rabbits on screen */
-#define rabmussize      32   /* Length of rabbit theme music */
-#define rabdelay        30000   /* Time to wait for rabbit: 5 Minutes */
-
-#define NAMEGAP         (3 * gg.scale) /* signallabel horizontal offset */
-
-
-typedef struct descrec {
-	long ptr;
-	uchar numvects, numpins, numpnums, lblsize, simtype, procsize;
-	/* log_kflags */ short flag;
-	schar xx1, yy1, xx2, yy2;
-} descrec;
-
-typedef struct ovectorrec {
-	schar x1, y1, x2, y2;
-} ovectorrec;
-
-typedef union filerec {
-	uchar b[256];
-	schar sb[256];
-	char c[256];
-	short sh[128];
-	long i[64];
-	log_pac8 ix[32];
-	ovectorrec vec[64];
-	log_pinrec pin[64];
-	log_pnumrec pnum[64];
-	descrec desc[16];
-	log_pac4 c4[64];
-} filerec;
-
-typedef struct filerecfilerec {
-	FILE *f;
-	FILEBUFNC(f,filerec);
-} filerecfilerec;
-
-typedef struct rablistrec {
-	short x, y, next;
-} rablistrec;   /* Rabbit mode state descriptor */
-
-typedef rablistrec rablisttype[rablistsize + 1];
-
-typedef struct rabmusrec {
-	short note, time;
-} rabmusrec;   /* Rabbit music descriptor */
-
-typedef rabmusrec rabmustype[rabmussize];
-
-typedef short kindgrouptype[kindgroupmaxsize];
-typedef log_gattrrec *kindattrtype[kindgroupmaxsize];
-
-typedef uchar loadedgatesarray[(log_million + 7) / 8];
-typedef char indexarray[log_million][9];
-typedef short ioffsetarray[log_million];
-typedef uchar igrouparray[log_million];
-/* Index to gate library */
-
-typedef struct logmenurec {
-	char name[17];
-	char cmd[33];
-	int *bool_;
-} logmenurec;   /* Pop-up menu options */
-
-typedef logmenurec logmenutype[8];
-
-
-
-/* Pointer to node-combination record */
-/* Pointer to temporary solder */
-/* Pointer to configuration record */
-/* Pointer to macro key record */
-/* Pointer to box in catalog page */
-/* Pointer to library string record */
-
-
-typedef struct cnrec {
-	log_nrec *n, **np;
-	int done;
-	struct cnrec *next;
-} cnrec;   /* Delayed Combinenodes record */
-
-
-typedef struct blobrec {
-	log_hwrec *hw;
-	log_vwrec *vw;
-	short x, y;
-	struct blobrec *next;
-} blobrec;
-
-
-typedef struct cnfrec {
-	char tool[17];
-	struct cnfrec *next;
-	char s[256];   /*not fully allocated*/
-} cnfrec;   /* Tool configuration record */
-
-
-typedef struct macrorec {
-	char key;
-	struct macrorec *next;
-	char name[33];
-} macrorec;   /* Macro key */
-
-
-typedef struct catboxrec {
-	short pos, count;
-	struct catboxrec *next;
-} catboxrec;   /* yow */
-
-
-typedef struct librstrrec {
-	char name[9];
-	char *str;
-	struct librstrrec *left, *right;
-} librstrrec;
-
-
-typedef struct baseptrs {
-	log_grec *gcopy;
-	log_srec *scopy;
-	log_hwrec *hwcopy;
-	log_vwrec *vwcopy;
-	log_lrec *lcopy;
-	log_brec *bcopy;
-	short x1copy, y1copy, x2copy, y2copy, dxcopy, dycopy, pgnum;
-	int valid;
-} baseptrs;
-
-
-
-/* 0*/
-/* If the pen is in "this" sector, */
-/* 1*/
-/*   switch to "this" state.       */
-/* 2*/
-/* 3*/
-/* 4*/
-/* 5*/
-/* 6*/
-/* 7*/
-/* 8*/
-/* 9*/
-/*10*/
-/*11*/
-/*12*/
-/*13*/
-/*14*/
-/*15*/
-/*16*/
-/*17*/
-/*18*/
-/*19*/
-/*20*/
-/*21*/
-/*22*/
-/*23*/
-
-static const rablisttype rablist = {
-	{ 0, 0, 1 },
-	{ 0, 4, 2 },
-	{ 0, 3, 3 },
-	{ 0, 2, 4 },
-	{ 0, 1, 5 },
-	{ 0, 0, 6 },
-	{ 1, 0, 7 },
-	{ 2, 0, 8 },
-	{ 3, 0, 9 },
-	{ 4, 0, 10 },
-	{ 4, 1, 11 },
-	{ 4, 2, -12 },
-	{ 3, 2, 13 },
-	{ 2, 2, 14 },
-	{ 1, 2, 15 },
-	{ 2, 2, -18 },
-	{ 0, 2, 17 },
-	{ 1, 2, 15 },
-	{ 3, 2, -20 },
-	{ 2, 3, -20 },
-	{ 3, 3, 21 },
-	{ 4, 3, -23 },
-	{ 3, 4, -23 },
-	{ 4, 4, 42 }
-};
-
-static const rabmustype discomadness = {
-	{ 3, 46 },
-	{ 0, 8 },
-	{ 4, 10 },
-	{ 0, 15 },
-	{ 4, 12 },
-	{ 0, 2 },
-	{ 5, 35 },
-	{ 0, 6 },
-	{ 4, 35 },
-	{ 0, 6 },
-	{ 5, 8 },
-	{ 0, 17 },
-	{ 5, 12 },
-	{ 0, 2 },
-	{ 6, 35 },
-	{ 0, 6 },
-	{ 5, 35 },
-	{ 0, 6 },
-	{ 6, 8 },
-	{ 0, 17 },
-	{ 6, 12 },
-	{ 0, 2 },
-	{ 8, 35 },
-	{ 0, 6 },
-	{ 3, 35 },
-	{ 0, 6 },
-	{ 4, 8 },
-	{ 0, 16 },
-	{ 4, 12 },
-	{ 0, 3 },
-	{ 5, 50 },
-	{ 0, 0 }
-};
-
-#define maxeditmodes    4
-
-
-static log_action_t gg;   /* External global variables */
-
-static short cursx, cursy;   /* Current position of cursor */
-static short cursx1, cursy1;   /* Wire starting point */
-static short cursx2, cursy2;   /* Wire ending point */
-static short chairx, chairy;   /* Current position of crosshair */
-
-static int cursorflag;   /* Cursor is displayed */
-static int prevcursorflag;
-/* Cursor was displayed before operation began */
-static int chairflag;   /* Crosshair is on screen */
-static int chairflag2;   /* Crosshair will be on screen */
-static int rbandflag;   /* Rubber-band wire is on screen */
-static int rabbits, rabflag;   /* Rabbit mode */
-static int avoidrabbits;
-
-static short txacross, txdown, across, down, baseline, line1, line2,
-			 kindgroupbase, kindgroupleft, kindgroupright, kindgroupstart,
-			 kindgroupsize, histdown;
-
-static int entrycapslock;   /* Capslock status on entry */
-static int oldcapslock;   /* Previous capslock status */
-
-static int signalcaps;   /* Capslock flag for signal-name entry */
-static int labelcaps;   /* Capslock flag for label entry */
-
-static char (*index_)[9];   /* Index into gate library */
-static short *indexoffset;   /* Offset of each gate */
-static uchar *indexfile;   /* File number of each gate */
-static uchar *indexgroup;   /* Group number of each gate */
-static uchar *loadedgates;   /* Tells whether a gate is in the catalog */
-static log_krec *kind[maxmaxkinds];   /* Kind of gate in each catalog space */
-static kindgrouptype kindgroup;   /* Kind of gate in each menu-area space */
-static kindgrouptype kindsig;
-static kindattrtype kindattr;
-static na_strlist_t *gatefilenames;
-static short maxkinds, catwidth;
-static catboxrec *catboxes;
-static librstrrec *librstrs;
-
-static char *gatesname[maxgatesfiles];
-static char *loghelpname, *lognewsname;   /* Names of system files */
-
-static long temp1, temp2, temp3, temp4;   /* For use by main program */
-static char tempch;
-
-static short zoom;   /* Zooming level */
-static int ospointflag;   /* Starting point was touched */
-
-static long xoff0, yoff0;   /* Old XOFF, YOFF */
-
-static short curwcolor;   /* Current VLSI wire color */
-static char cureditmode;   /* Current editing (gate-tapping) mode */
-static short curlistgroup;   /* Current group in library list */
-
-static int vlsimode[log_maxpages];   /* Page contains VLSI circuits */
-static long xoffp[log_maxpages], yoffp[log_maxpages];
-/* XOFF, YOFF for non-current pages */
-static short gatecount[log_maxpages];   /* Highest used gate-ID number */
-static char *curfilename[log_maxpages];   /* Name of last-loaded file */
-static long realcurpage;
-
-static log_nrec *freenode;   /* Node "free" list */
-static log_grec *freegate;   /* Gate "free" list */
-
-static baseptrs copybuf;   /* Del/Copy/Paste buffer */
-
-static long htcount;   /* Number of timesteps in list */
-static short hncount;   /* Number of names in list */
-static short hnocount;   /* Old number of names in list */
-static short histtrig;   /* Number of signal which triggers history */
-static na_strlist_t *histlbl;
-static short histnumattrs;
-static log_kattrrec *histkattr;
-static log_gattrrec *histgattr;
-static short histgridmode, histgridwhich;
-static log_hnrec *histgridhn;
-static double histvalrange, histdivsacross;
-static int histonscreen;   /* Leading edge of trace is visible */
-static int histreset;   /* Clear the history memory */
-static double histtime;   /* Current time for history mode */
-
-static int probeflag;   /* Has the probe been checked? */
-
-static log_nrec *nodeconflictbase;   /* Node conflict list */
-static log_grec *gateconflictbase;   /* Gate conflict list */
-
-static cnfrec *cnfbase;   /* List of tool configuration lines */
-static na_strlist_t *colorbase;   /* List of configured colors */
-static macrorec *macrobase;   /* List of macro keys */
-static na_strlist_t *thingstodo, *nexttodo;   /* List of delayed commands */
-static na_strlist_t *messages;   /* List of delayed messages */
-static na_strlist_t *commandlist;   /* List of tool-activation commands */
-
-static char modename[9];   /* Word in 'mode' area of menu */
-static int modeflag;   /* Mode area contains a word */
-static long modetime;   /* Time (in minutes) in mode display */
-static log_krec *modeprobekind;
-
-static nk_keytransinfo *curkeytrans;   /* Current keyboard definitions */
-
-static enum {
-	normal, grid, delete__, copy_, paste, boxcursor
-} cursortype, oldcursortype;
-/* Type of cursor */
-
-/*  menupicture, errorpicture : m_picturevar;              { Various saved images */
-static short bottomcount;   /* How many nested BEGINBOTTOMs */
-
-static uchar rcolormap[16], gcolormap[16], bcolormap[16];
-
-static short gategreen, gateyellow, gatered, gateorange, gateblack, gatewhite;
-
-static short defineboxcolor, definebackcolor, definetextcolor, catboxcolor;
-
-static short messagepos;   /* Position of next message */
-static short messageright;   /* Maximum width of messages */
-
-static long fastsavetime;
-
-static long watchdog, rabtime;   /* Miscellaneous timers */
-
-static log_tool *simtype_ignore;   /* Non-simulated type */
-static log_tool *simtype_common;   /* Common-pin type */
-
-static double status_oldtime, status_oldtstep;
-static long status_oldmem;
-
-static rablistrec rabtable[rabtabsize];   /* Positions of rabbits */
-static short rabstate;   /* Rabbit recognizer state */
-
-static long helpptr;   /* Help descriptor */
-
-static int popup_grid;   /* Pop-up menus */
-static logmenurec *popupmenus[4];
-
-static filerecfilerec *libf1[maxgatesfiles];   /* Library files */
-static short libfstart[maxgatesfiles];
-/* First descriptor record in LIBF1 */
-static short libptr;   /* Most recently replaced catalog item */
-static short idxsize;   /* Number of gates in library */
-static char *librgroupnames[9];
-
-static short refrtimer, refrtimer0;   /* Time until screen is refreshed */
-
-static long tabletaddr;
-
-static char *dumpfname, *tracefname;
-static FILE *dumpfile, *tracefile;
-
-static long programmark;
-
-static char pushedbackkey, realkey;
-
-extern long EXCP_LINE;   /* Line number of last error */
-static long excpline;
-
-static short conflictdelay;
-
-static int eightcolors;   /* Has only 8 colors */
-static int onescreen;   /* Has only one screen */
-static int doingcnffunction;   /* This is an ACT_CNF, not an ACT_FUNC */
-static int justonecommand;   /* LOG -R mode, so exit after first cmd */
-static int displaynews;   /* LOGNEWS has not yet been displayed */
-static int immedscroll;   /* Don't need to defer 'REFR' function */
-static int tempverbose;   /* Verbose mode temporarily on */
-static int commandfound;   /* Function name was acknowledged */
-static int cursorhide;   /* Cursor is hidden */
-static int reportnowait;   /* Don't wait for key on bug reports */
-static int firsttraining;   /* Training used for first time */
-static int training;   /* Training mode for Help command */
-static int snapflag;   /* Snap-to-grid cursor */
-static int showsolder;   /* Display solder points */
-static int briefprobe;   /* Temporary probe mode */
-static int conflictenbl;   /* Conflict checking enabled */
-static int conflictstop;   /* Conflict stopping mode */
-static int anyconflicts;   /* Any active, reported conflicts? */
-static int steppingoff;   /* Single-step is turning simulation off */
-static int suppressdots;   /* Temporarily suppressing red dots */
-static int glowsolder;   /* Display solder dots in Glow mode */
-static int vlsi;   /* Current page is VLSI mode */
-
-
-extern void m_saveclip ();
-
-extern void nc_cursor_on ();
-
-extern void nc_cursor_off ();
+#include "screen.h"
+#include "label.h"
+#include "gate.h"
+#include "wire.h"
+#include "node.h"
+#include "page.h"
 
 
 static char *ioresult_message(char *Result, long iores)
@@ -3663,11 +3149,6 @@ static void trykbdscroll()
 	scroll();
 }
 
-/* Local variables for wantsolder: */
-struct LOC_wantsolder
-{
-	int hasred, hasgreen, hasyellow, hasblue;
-} ;
 
 static void markcolor(log_hwrec **hw, struct LOC_wantsolder *LINK)
 {
@@ -4431,7 +3912,7 @@ static void deleverything()
 /*=                                              =*/
 /*================================================*/
 
-static void changekind2(short i, short gtype, short sig, log_gattrec *attrs)
+static void changekind2(short i, short gtype, short sig, log_gattrrec *attrs)
 {
 	log_krec *k;
 
@@ -9944,7 +9425,7 @@ static void solderat(short x, short y)
 }
 
 
-static void findattrnum2(short numattrs, log_kattrec *kattr, na_strlist_t *lbl, char *name, char *kinds, short *num)
+static void findattrnum2(short numattrs, log_kattrrec *kattr, na_strlist_t *lbl, char *name, char *kinds, short *num)
 {
 	na_strlist_t *l1;
 
@@ -11334,7 +10815,7 @@ static void getexpr(struct LOC_historycommand *LINK)
 		setaxis(expr, LINK);
 }
 
-static void plotcmd(struct LOC_hostorycommand *LINK)
+static void plotcmd(struct LOC_historycommand *LINK)
 {
 	char STR1[256];
 
@@ -12912,7 +12393,7 @@ static void loadlog30(FILE **f, short ver)
 }
 
 
-static void readattrs(FILE **f, log_gattrrec **gattr, short numattrs, log_kattrrec *kattr, na_strelist_t *lbl, short count)
+static void readattrs(FILE **f, log_gattrrec **gattr, short numattrs, log_kattrrec *kattr, na_strlist_t *lbl, short count)
 {
 	short j, jj;
 	char ch;
@@ -13094,9 +12575,7 @@ static void loadfail(char *msg, struct LOC_loadpage *LINK)
 	_Escape(1);
 }
 
-static log_nrec *countnode_(short i, struct LOAC_loadpage *LINK)
-	short i;
-	struct LOC_loadpage *LINK;
+static log_nrec *countnode_(short i, struct LOC_loadpage *LINK)
 {
 	char STR2[256];
 
@@ -14071,7 +13550,7 @@ struct LOC_readpage {
 	char *reason;
 } ;
 
-static void loadfail__(char *msg, struct LOC_radpage *LINK)
+static void loadfail__(char *msg, struct LOC_readpage *LINK)
 {
 	strcpy(LINK->reason, msg);
 	_Escape(1);
@@ -14221,7 +13700,7 @@ struct LOC_toolcommand {
 	int refrflag, wasselected;
 } ;
 
-static void describe(long i, LOC_toolcommand *LINK)
+static void describe(long i, struct LOC_toolcommand *LINK)
 {
 	if (LINK->ta[i] == NULL)
 		return;
@@ -16102,16 +15581,6 @@ static void inithooks()
 
 #define rtn             "INITIALIZE"
 
-#if 0
-/* Local variables for initialize: */
-struct LOC_initialize {
-	short j;
-	na_strlist_t *loadgates, *logmenu;
-	char cmdbuf[81];
-	cnfrec *cnflast;
-} ;
-#endif
-
 static void beginfatal(struct LOC_initialize *LINK)
 {
 	if (P_escapecode == -20)
diff --git a/log/src/node.c b/log/src/node.c
index 8fc6cdac09f16e8799bc4d3bed8f317d290537a0..d35e30519a7ab32b50c966c6f1849cb5845d3301 100644
--- a/log/src/node.c
+++ b/log/src/node.c
@@ -1,5 +1,8 @@
 
 #include <p2c/p2c.h>
+#include <p2c/newkbd.h>
+#include "logglobals.h"
+#include "node.h"
 
 /*==================  ADDNODE  ===================*/
 /*=                                              =*/
@@ -531,15 +534,6 @@ static void queuecombine(cnrec **cnbase, log_nrec **n, log_nrec **n2)
 	cn->np = n2;
 }
 
-
-/* Local variables for checkcombine: */
-struct LOC_checkcombine {
-	cnrec **cnbase;
-	short passcount;
-	int good;
-	log_tool *cursimtype;
-} ;
-
 static void checknode(log_nrec *n, struct LOC_checkcombine *LINK)
 {
 	log_tool *newsimtype;
diff --git a/log/src/page.c b/log/src/page.c
index 0a93e3f2b43bba379c8e28f1cccd86050ed85b2c..cee935b8488a47701f510f8e1c17e4f43ca6ced3 100644
--- a/log/src/page.c
+++ b/log/src/page.c
@@ -1,5 +1,8 @@
 
 #include <p2c/p2c.h>
+#include <p2c/newkbd.h>
+#include "logglobals.h"
+#include "page.h"
 
 static void chpage(short pg)
 {
diff --git a/log/src/screen.c b/log/src/screen.c
index 177e83866d28014e0cec1b8a49d5257c387c0aab..bbdc6e51c708be2ad0ca46857c80f3ed3f4096c0 100644
--- a/log/src/screen.c
+++ b/log/src/screen.c
@@ -31,7 +31,11 @@
    */
 
 #include <p2c/p2c.h>
-
+#include <p2c/newkbd.h>
+#include <p2c/newcrt.h>
+#include "logglobals.h"
+#include "logfont.h"
+#include "screen.h"
 
 /*=================  INITSCREEN  =================*/
 /*=                                              =*/
diff --git a/log/src/tool.c b/log/src/tool.c
index 017c6c1af1409494fb37d9bc3e1fe7af4600e0e0..5e2df6d18c3ce673460e5a0315f5411057728d01 100644
--- a/log/src/tool.c
+++ b/log/src/tool.c
@@ -1,5 +1,8 @@
 
-#include <log/log.h>
+#include <p2c/p2c.h>
+#include <p2c/newkbd.h>
+#include "logdef.h"
+#include "logglobals.h"
 
 static void newtool(log_tool **t, char *name)
 {
diff --git a/log/src/wire.c b/log/src/wire.c
index 2d280ba768ba90fd2317aeebef75c716dfc81d5e..abb3d304e03a70ce8d47a77417cbb7d5ce19ce7b 100644
--- a/log/src/wire.c
+++ b/log/src/wire.c
@@ -1,5 +1,12 @@
 
 #include <p2c/p2c.h>
+#include <p2c/newkbd.h>
+#include "logglobals.h"
+#include "logdef.h"
+#include "wire.h"
+
+static void fryhwire(log_hwrec *hw);
+static void fryvwire(log_vwrec *vw);
 
 /*===================  NEWHW  ====================*/
 /*=                                              =*/
@@ -990,8 +997,7 @@ static void fryvwire(log_vwrec *vw)
         while (labs(timers_sysclock() - t0) < frytime)
 		{
                 m_color((long)gg.color.conflict);
-                vline(vw->x, vw->y
-1, vw->y2);
+                vline(vw->x, vw->y1, vw->y2);
                 m_color((long)gg.color.backgr);
                 vline(vw->x, vw->y1, vw->y2);
         }