15a16,18
> #include <config.h>
> #include <curses.h>
> 
18,19c21
< #include "config.h"
< #ifdef DOINGX
---
> #ifdef HAVE_X11_X_H
23,25c25
< #else
< #include <curses.h>
< #endif
---
> #endif /* HAVE_X11_X_H */
27d26
< #include <stdio.h>
30c29
< #ifdef DOINGX
---
> #ifdef HAVE_X11_X_H
33c32
< #endif
---
> #endif /* HAVE_X11_X_H */
45c44
< #ifdef DOINGX
---
> #ifdef HAVE_X11_X_H
50c49,50
< #endif
---
> int	using_X = FALSE;	/* set once we find $DISPLAY is working */
> #endif /* HAVE_X11_X_H */
120c120
< #if !defined(DOINGX) && defined(SIGWINCH)
---
> #if defined(SIGWINCH)
213c213
< #ifdef DOINGX
---
> #ifdef HAVE_X11_X_H
222c222,224
< #endif
---
>     int try_X = TRUE;	/* should we try to use X? */
> #endif /* HAVE_X11_X_H */
> 
240c242
< #ifdef DOINGX
---
> #ifdef HAVE_X11_X_H
245c247
< #else
---
> #endif /* HAVE_X11_X_H */
247d248
< #endif /* DOINGX */
290,298c291,299
< #ifdef DOINGX
<                         case 'n': 
< 		                argv++;
< 		                argc--;
< 		                /*userfont = strdup(argv[0]);*/
< 		                userfont = argv[0];
< 		                break;
<                         case 'g':
< 		                argv++;
---
> #ifdef HAVE_X11_X_H
> 			case 'n': 
> 				argv++;
> 				argc--;
> 				/*userfont = strdup(argv[0]);*/
> 				userfont = argv[0];
> 				break;
> 			case 'g':
> 				argv++;
302c303
< #endif DOINGX
---
> #endif /* HAVE_X11_X_H */
305c306,310
< #ifdef DOINGX
---
> #ifdef HAVE_X11_X_H
> 	    case 'X':
> 		    try_X = FALSE;
> 		    break;
>   
312c317
< #endif DOINGX
---
> #endif /* HAVE_X11_X_H */
333,335c338,341
< #ifdef DOINGX
<     sc_Xinit(copyc, copyv);
< #endif DOINGX
---
> #ifdef HAVE_X11_X_H
>     if (try_X)	/* sets using_X if it seems it might work... */
> 	sc_Xinit(copyc, copyv);
> #endif /* HAVE_X11_X_H */
342,344c348,349
< #ifndef DOINGX
<     startdisp();
< #endif
---
>     if (!using_X)
> 	startdisp();
406c411
< #if !defined(DOINGX) && defined(SIGWINCH)
---
> #if defined(SIGWINCH)
408c413
< 	if (hitwinch)
---
> 	if (using_X && hitwinch)
420,421c425,428
< #ifdef DOINGX
< 	if (!seenerr)
---
> #ifdef HAVE_X11_X_H
> 	if (using_X)
> 	{	
> 	   if (!seenerr)
423,424c430,431
< 	seenerr = 0;	/* note, this is here (vs below ifdef DOINGX),
< 				because in X nmgetch() may set seenerr */
---
> 	   seenerr = 0;	/* note, this is here (vs below),
> 			because in X nmgetch() may set seenerr */
426,427c433,434
< 	c = nmgetch();
< 	if (!running)	/* nmgetch would set this in Main_Menu() */
---
> 	    c = nmgetch();
> 	    if (!running)	/* nmgetch would set this in Main_Menu() */
429,430c436,439
< #else
< 	seenerr = 0;
---
> 	} else { /* curses below */
> #endif /* HAVE_X11_X_H */
> 
> 	    seenerr = 0;
432c441
< 	(void) refresh(); /* 5.3 does a refresh in getch */ 
---
> 	    (void) refresh(); /* 5.3 does a refresh in getch */ 
434,437c443,448
< 	c = nmgetch();
< 	getyx(stdscr, tempy, tempx);
< 	clearlines(1,1);
< 	(void) move(tempy, tempx);
---
> 	    c = nmgetch();
> 	    getyx(stdscr, tempy, tempx);
> 	    clearlines(1,1);
> 	    (void) move(tempy, tempx);
> #ifdef HAVE_X11_X_H
> 	}
451c462
< #if !defined(DOINGX) && defined(SIGTSTP)
---
> #ifdef SIGTSTP
465,467c476,478
< #ifndef DOINGX
< 		    (void) clearok(stdscr,1);
< #endif
---
> 		    if (!using_X)
> 			(void) clearok(stdscr,1);
> 
475,477c486,487
< #ifndef DOINGX
< 		    (void) clearok(stdscr,1);
< #endif
---
> 		    if (!using_X)
> 			(void) clearok(stdscr,1);
624,626c634,636
< #ifndef DOINGX
< 		    (void) refresh();
< #endif
---
> 		    if (!using_X)
> 			(void) refresh();
> 
807,809c817,819
< #ifndef DOINGX
< 		    deraw();
< #endif
---
> 		    if (!using_X)
> 			deraw();
> 
841,843c851,852
< #ifndef DOINGX
< 		    goraw();
< #endif
---
> 		    if (!using_X)
> 			goraw();
856,858c865,866
< #ifndef DOINGX
< 		    (void) refresh();
< #endif
---
> 		    if (!using_X)
> 			(void) refresh();
1044,1046c1052,1054
< 		case 'M': File_Menu(5); break;	/* Merge "file" */
< 		case 'R': File_Menu(6); break;	/* Merge "macrofile" */
< 		case 'D': File_Menu(7); break;	/* mdir "macrodir" */
---
> 		case 'M': File_Menu(6); break;	/* Merge "file" */
> 		case 'R': File_Menu(7); break;	/* Merge "macrofile" */
> 		case 'D': File_Menu(8); break;	/* mdir "macrodir" */
1227,1230c1235,1238
< sig_type doquit(int);
< sig_type dump_me(int);
< #if !defined(DOINGX) && defined(SIGWINCH)
< sig_type winchg(int);
---
> RETSIGTYPE doquit(int);
> RETSIGTYPE dump_me(int);
> #ifdef SIGWINCH
> RETSIGTYPE winchg(int);
1235,1238c1243,1246
< sig_type doquit();
< sig_type dump_me();
< #if !defined(DOINGX) && defined(SIGWINCH)
< sig_type winchg();
---
> RETSIGTYPE doquit();
> RETSIGTYPE dump_me();
> #ifdef SIGWINCH
> RETSIGTYPE winchg();
1247,1249c1255,1256
< #ifndef DOINGX
<     (void) signal(SIGALRM, time_out);
< #endif
---
>     if (!using_X)
> 	(void) signal(SIGALRM, time_out);
1254,1255c1261,1263
< #if !defined(DOINGX) && defined(SIGWINCH)
<     (void) signal(SIGWINCH, winchg);
---
> #ifdef SIGWINCH
>     if (!using_X)
> 	(void) signal(SIGWINCH, winchg);
1259,1260c1267,1268
< #if !defined(DOINGX) && defined(SIGWINCH)
< sig_type
---
> #if defined(SIGWINCH)
> RETSIGTYPE
1268c1276
< sig_type
---
> RETSIGTYPE
1277c1285
< sig_type
---
> RETSIGTYPE
1282,1284c1290,1291
< #ifndef DOINGX
<     deraw();
< #endif
---
>     if (!using_X)
> 	deraw();
1381c1388
< #ifdef DOINGX
---
> #ifdef HAVE_X11_X_H
1395,1397d1401
< #ifdef DOINGX
<     /* TempX_Loc = event.xbutton.x; */
< #endif
1400c1404,1406
< #ifdef DOINGX
---
> #ifdef HAVE_X11_X_H
>       if (using_X)
>       {
1408c1414,1415
< #else
---
>       } else {
> #endif /* HAVE_X11_X_H */
1419c1426,1428
< #endif
---
> #ifdef HAVE_X11_X_H
>       }
> #endif /* HAVE_X11_X_H */
1421,1422c1430,1434
< #ifdef DOINGX
< 	XDrawImageString(dpy,mainwin,maingc,
---
> #ifdef HAVE_X11_X_H
> 	if (using_X)
> 	{
> 
> 	   XDrawImageString(dpy,mainwin,maingc,
1425,1429c1437,1445
< #else
< 	move(2, 0);
< 	addstr(help_prompt[choice - 1]);
< 	clrtoeol();
< #endif
---
> 	} else {
> #endif /* HAVE_X11_X_H */
> 	   move(2, 0);
> 	   addstr(help_prompt[choice - 1]);
> 	   clrtoeol();
> #ifdef HAVE_X11_X_H
> 	}
> #endif /* HAVE_X11_X_H */
> 
1433,1437c1449,1450
<     /*** HACK COURTESY OF MIKE ***/
< #ifdef DOINGX
<     XNextEvent(dpy,&event);
< 
<     switch(event.type)
---
> #ifdef HAVE_X11_X_H
>     if (!using_X)
1438a1452,1455
>       XNextEvent(dpy,&event);
> 
>       switch(event.type)
>       {
1496,1497c1513,1514
< 
< #else
---
> WE NEED HELP HERE
> #endif /* HAVE_X11_X_H */
1501c1518,1519
< #endif
---
> #endif /* DOINGX */
> WE NEED HELP HERE
1817,1818c1835,1837
< #ifdef DOINGX
< 		XDrawImageString(dpy,mainwin,maingc,
---
> #ifdef HAVE_X11_X_H
> 		if (using_X)
> 		{	XDrawImageString(dpy,mainwin,maingc,
1821,1825c1840,1847
< 		XFlush(dpy);
< #else
< 		addstr(stringbuf);
< 		refresh();
< #endif
---
> 			XFlush(dpy);
> 		} else {
> #endif /* HAVE_X11_X_H */
> 			addstr(stringbuf);
> 			refresh();
> #ifdef HAVE_X11_X_H
> 		}
> #endif /* HAVE_X11_X_H */
1887,1891c1909,1915
< #ifdef DOINGX
< 		redraw_current(maingc);
< #else
< 		repaint(lastmx, lastmy, fwidth[lastcol]);
< #endif
---
> #ifdef HAVE_X11_X_H
> 		if (using_X)
> 			redraw_current(maingc);
> 		else
> #endif /* HAVE_X11_X_H */
> 			repaint(lastmx, lastmy, fwidth[lastcol]);
> 
1898,1902c1922,1928
< #ifdef DOINGX
< 		redraw_current(maingc);
< #else
< 		repaint(lastmx, lastmy, fwidth[lastcol]);
< #endif
---
> #ifdef HAVE_X11_X_H
> 		if (using_X)
> 			redraw_current(maingc);
> 		else
> #endif /* HAVE_X11_X_H */
> 			repaint(lastmx, lastmy, fwidth[lastcol]);
> 
2031c2057
<     static char tmp[PATHLEN];
---
>     char	*defwfile;
2061,2062c2087,2095
< 		get_default_path(tmp);
< 		(void) sprintf(line, "get [\"source\"] \"%s", tmp);
---
> 		if (curfile)
> 		{	defwfile = what_file(curfile, NULL);
> 			(void) sprintf (line, "get [\"source\"] \"%s",
> 					defwfile);
> 			scxfree(defwfile);
> 		}
> 		else
> 			(void) sprintf (line, "get [\"source\"] \"");
> 				
2066,2067c2099,2106
< 		get_default_path(tmp);
< 		(void) sprintf(line, "put [\"dest\" range] \"%s", tmp);
---
> 		if (*curfile)
> 		{	defwfile = what_file(curfile, NULL);
> 			(void) sprintf (line, "put [\"dest\" range] \"%s", 
> 					defwfile);
> 			scxfree(defwfile);
> 		}
> 		else
> 			(void) sprintf (line, "put [\"dest\" range] \"");
2071d2109
< 		(void) sprintf (line, "write [\"dest\" range] \"");
2073,2077c2111,2113
< 		{	char	*defwfile;
< 
< 			defwfile = what_file(curfile, ".asc");
< 			sprintf(stringbuf, "Default file is \"%s\"", defwfile);
< 			scerror(stringbuf);
---
> 		{	defwfile = what_file(curfile, ".asc");
> 			(void) sprintf (line, "write [\"dest\" range] \"%s", 
> 					defwfile);
2080,2088d2115
< /*
< 		get_default_path(tmp);
< 		if (*curfile)
< 		{ 	char	*defwfile;
< 
< 			defwfile = fsuffix(tmp, ".asc");
< 		        sprintf(line, "write [\"dest\" range] \"%s", 
< 				defwfile);
< 		}
2090,2091c2117
< 		    sprintf(line, "write [\"dest\" range] \"%s", tmp);
< */
---
> 			(void) sprintf (line, "write [\"dest\" range] \"");
2096d2121
< 		(void) sprintf(line, "tbl [\"dest\" range] \"");
2102,2103c2127,2128
< 			sprintf(stringbuf, "Default table is \"%s\"", defwfile);
< 			scerror(stringbuf);
---
> 			(void) sprintf(line, "tbl [\"dest\" range] \"%s", 
> 				       defwfile);
2106,2130d2130
< /*
< 		get_default_path(tmp);
< 		if (*curfile)
< 		{	char 	*deftfile;
< 			char 	*suffix;
< 			if (tbl_style == 0)
< 			  	suffix = ".cln";
< 			else if (tbl_style == TBL)
< 				suffix = ".tbl";
< 			else if (tbl_style == LATEX)
< 				suffix = ".lat";
< 			else if (tbl_style == SLATEX)
< 				suffix = ".stx";
< 			else if (tbl_style == TEX)
< 				suffix = ".tex";
< 			else
< 				suffix = NULL;
< 
< 			if (suffix != NULL)
< 			{   deftfile = fsuffix(tmp, suffix);
< 			    sprintf(line, "tbl [\"dest\" range] \"%s", 
< 				    deftfile);
< 			    scxfree(deftfile);
< 			} 	
< 		}
2132,2133c2132
<  		   (void) sprintf(line, "tbl [\"dest\" range] \"%s", tmp);
< */
---
> 			(void) sprintf(line, "tbl [\"dest\" range] \"");
2138,2139c2137,2147
< 		get_default_dir(tmp);
< 		(void) sprintf (line, "read [\"source\" range] \"%s", tmp);
---
> 		if (*curfile)
> 		{	char	*defwfile;
> 
> 			/* what_file() scmalloc's space */
> 			defwfile = what_file(curfile, NULL);
> 			(void) sprintf (line, "read [\"source\" range] \"%s", 
> 					defwfile);
> 			scxfree(defwfile);
> 		}
> 		else
> 			(void) sprintf (line, "read [\"source\" range] \"");
2144,2145c2152,2162
< 		get_default_dir(tmp);
< 		(void) sprintf(line,"merge [\"merge_file\"] \"%s", tmp);
---
> 		if (*curfile)
> 		{	char	*defwfile;
> 
> 			/* what_file() scmalloc's space */
> 			defwfile = what_file(curfile, NULL);
> 			(void) sprintf(line,"merge [\"merge_file\"] \"%s", 
> 				       defwfile);
> 			scxfree(defwfile);
> 		}
> 		else
> 			(void) sprintf(line,"merge [\"merge_file\"] \"");
2149a2167,2178
> 		if (*curfile)
> 		{	char	*defwfile;
> 
> 			/* what_file() scmalloc's space */
> 			defwfile = what_file(curfile, NULL);
> 			(void) sprintf(line,"merge [\"macro_file\"] \"%s", 
> 				       defwfile);
> 			scxfree(defwfile);
> 		}
> 		else
> 		(void) sprintf(line,"merge [\"macro_file\"] \"");
> /*
2151c2180,2185
< 		(void)sprintf(line,"merge [\"macro_file\"] \"%s", tmp);
---
> 		if (mdir)
> 			(void) sprintf (line,"merge [\"macro_file\"] \"%s/%s", 
> 					mdir, tmp);
> 		else
> 			(void) sprintf (line,"merge [\"macro_file\"] \"%s",tmp);
> */
2156,2157c2190,2193
< 		get_default_dir(tmp);
< 		(void) sprintf(line, "mdir [\"macro_dir\"] \"%s", tmp);
---
> 		if (mdir)
> 			(void) sprintf(line, "mdir [\"macro_dir\"] \"%s",mdir);
> 		else
> 			(void) sprintf(line, "mdir [\"macro_dir\"] \"");
2284,2288c2320,2326
< #ifdef DOINGX
< 		Graph_Menu();
< #else
< 		scerror("Graphing is not yet supported in curses");
< #endif
---
> #ifdef HAVE_X11_X_H
> 		if (using_X)
> 			Graph_Menu();
> 		else
> #endif /* HAVE_X11_X_H */
> 			scerror("Graphing is not yet supported in curses");
> 
2300,2304c2338,2343
< #ifdef DOINGX	/* many things are X specific ... */
<                 Color_Menu();
< #else
< 		message("Color curses isn't yet supported");
< #endif /* DOINGX */
---
> #ifdef HAVE_X11_X_H	/* many things are X specific ... */
> 		if (using_X)
> 			Color_Menu();
> 		else
> #endif /* HAVE_X11_X_H */
> 			message("Color curses isn't yet supported");
2313c2352
< #ifdef DOINGX
---
> #ifdef HAVE_X11_X_H
2342c2381
< #endif
---
> #endif /* HAVE_X11_X_H */
