/************************************************************************
 * This program is Copyright (C) 1986 by Jonathan Payne.  JOVE is       *
 * provided to you without charge, and with no warranty.  You may give  *
 * away copies of JOVE, including sources, provided that this notice is *
 * included in all the files.                                           *
 ************************************************************************/

#define	VERSION	"4.6.14.32#12"
#define WHO	"TRH"

#define NOT_JOVE
#include "tune.h"

static const char TEMPLATE[] = "\
/* Created by $Id: makevsn.c,v 14.32.0.12 1994/06/24 20:21:36 tom Exp tom $ */\n\
\n\
#define VERSION	\"%V\"\n\
#define SYSTEM	\"%S\"\n\
#define VERSION_SYSTEM_DATE_AND_GURU	\"%V) - (%S, %D %W\"\n\
";

#ifndef SYS
#   if unix
#	define	SYS	"UNIX"
#   endif
#   ifdef ATARIST
#	undef	SYS
#	define	SYS	"Atari TOS"
#   endif
#   ifdef MAC
#	undef SYS
#	define SYS	"Macintosh"
#   endif
#   ifdef MSDOS
#	undef	SYS
#	define	SYS	"MS-DOS PC"
#   endif
#   ifdef MINIX
#	undef	SYS
#	define	SYS	"Minix"
#   endif
#   ifdef V7
#	undef	SYS
#	define	SYS	"7th Ed. UNIX"
#   endif
#   ifdef SYSV
#	undef	SYS
#	define	SYS	"System V UNIX"
#   endif
#   ifdef BSD4_2
#	undef	SYS
#	define	SYS	"BSD 4.2 UNIX"
#   endif
#   ifdef BSD4_3
#	undef	SYS
#	define	SYS	"BSD 4.3 UNIX"
#   endif
#   ifdef SYSV_BSD
#	undef	SYS
#	define	SYS	"Hybrid SysV/BSD"
#   endif
#   ifdef hpux
#	undef	SYS
#	define	SYS	"HP-UX"
#   endif
#   ifdef aiws
#	undef	SYS
#	define	SYS	"AIX"
#   endif
#   ifdef SCO_SYSV
#	undef	SYS
#	define	SYS	"SCO UNIX"
#   endif
#   ifdef XENIX
#	undef	SYS
#	define	SYS	"Xenix"
#   endif
#   ifdef NeXT
#	undef SYS
#	define SYS	"NeXT"
#   endif
#   ifdef sun
#	undef SYS
#	define SYS	"Sun"
#   endif
#   ifdef ULTRIX
#	undef SYS
#	define SYS	"Ultrix"
#   endif
#   if vms
#	undef SYS
#	define SYS	"VMS"
#   endif
#   ifdef linux
#	undef SYS
#	define SYS	"Linux"
#   endif
#endif /* SYS */

/* #undef NULL /*  I'd rather have a warning than nothing at all... */
#include <stdio.h>
#include <time.h>

extern struct tm *localtime();	/* for those that don't have it in <time.h> */

static const char	*_pname;
static const char	*param[128];

static void usage __(( void ));
static void
usage()
{
	fprintf(stderr, "\
Usage: %s [-[letter] value]... [template]\n\
    default template: %s\n", _pname, TEMPLATE);
	exit(1);
}

/* strftime() style date/time formats. */

static const char *fullweekday __(( const struct tm *_(t) ));
static const char *
fullweekday(t)
register const struct tm	*t;
{
	static const char *const days[] = {
		"Sunday",	"Monday",	"Tuesday",	"Wednesday",
		"Thursday",	"Friday",	"Saturday"
	};
	return days[t->tm_wday];
}

static const char *abbrweekday __(( const struct tm *_(t) ));
static const char *
abbrweekday(t)
register const struct tm	*t;
{
	static char	result[4];
	strncpy(result, fullweekday(t), 3);
	return result;
}

static const char *fullmonth __(( const struct tm *_(t) ));
static const char *
fullmonth(t)
register const struct tm	*t;
{
	static const char *const months[] = {
		"January",	"February",	"March",	"April",
		"May",		"June",		"July",		"August",
		"September",	"October",	"November",	"December"
	};
	return months[t->tm_mon];
}

static const char *abbrmonth __(( const struct tm *_(t) ));
static const char *
abbrmonth(t)
register const struct tm	*t;
{
	static char	result[4];
	strncpy(result, fullmonth(t), 3);
	return result;
}

static const char *mday __(( const struct tm *_(t) ));
static const char *
mday(t)
register const struct tm	*t;
{
	static char	result[3];
	sprintf(result, "%02d", t->tm_mday);
	return result;
}

static const char *hour24 __(( const struct tm *_(t) ));
static const char *
hour24(t)
register const struct tm	*t;
{
	static char	result[3];
	sprintf(result, "%02d", t->tm_hour);
	return result;
}

static const char *hour12 __(( const struct tm *_(t) ));
static const char *
hour12(t)
register const struct tm	*t;
{
	static char	result[3];
	sprintf(result, "%02d", t->tm_hour % 12 ? t->tm_hour : 12);
	return result;
}

static const char *yearday __(( const struct tm *_(t) ));
static const char *
yearday(t)
register const struct tm	*t;
{
	static char	result[4];
	sprintf(result, "%03d", t->tm_yday + 1);
	return result;
}

static const char *month __(( const struct tm *_(t) ));
static const char *
month(t)
register const struct tm	*t;
{
	static char	result[3];
	sprintf(result, "%02d", t->tm_mon + 1);
	return result;
}

static const char *minute __(( const struct tm *_(t) ));
static const char *
minute(t)
register const struct tm	*t;
{
	static char	result[3];
	sprintf(result, "%02d", t->tm_min);
	return result;
}

static const char *second __(( const struct tm *_(t) ));
static const char *
second(t)
register const struct tm	*t;
{
	static char	result[3];
	sprintf(result, "%02d", t->tm_sec);
	return result;
}

static const char *ampm __(( const struct tm *_(t) ));
static const char *
ampm(t)
register const struct tm	*t;
{
	return (t->tm_hour < 12) ? "am" : "pm";
}

static const char *weekday __(( const struct tm *_(t) ));
static const char *
weekday(t)
register const struct tm	*t;
{
	static char	result[2];
	sprintf(result, "%d", t->tm_wday);
	return result;
}

static const char *shortyear __(( const struct tm *_(t) ));
static const char *
shortyear(t)
register const struct tm	*t;
{
	static char	result[3];
	sprintf(result, "%02d", t->tm_year % 100);
	return result;
}

static const char *fullyear __(( const struct tm *_(t) ));
static const char *
fullyear(t)
register const struct tm	*t;
{
	static char	result[5];
	sprintf(result, "%04d", t->tm_year + 1900);
	return result;
}

/* My own date/time formats. */

static const char *today __(( const struct tm *_(t) ));
static const char *
today(t)
register const struct tm	*t;
{
	static char	result[10];

	sprintf(result, "%2d-%.3s-%02d",
		t->tm_mday, abbrmonth(t), t->tm_year % 100);
	return result;
}

static const char *thetime __(( const struct tm *_(t) ));
static const char *
thetime(t)
register const struct tm	*t;
{
	static char	result[9];
	sprintf(result, "%2d:%02d:%02d", t->tm_hour, t->tm_min, t->tm_sec);
	return result;
}

static const char *unixtime __(( const struct tm *_(t) ));
static const char *
unixtime(t)
register const struct tm	*t;
{
	static char result[25];
	strncpy(result, asctime(t), 24);
	return result;
}


void
main(argc, argv)
int	argc;
register char	*argv[];
{
	time_t	now = time(NULL);
	struct tm *t = localtime(&now);

	register char		c;
	register const char	*arg, *p;

	_pname = *argv++;
	if (--argc == 0 && isatty(fileno(stdout)))
		usage();

	/* Fill in default parameters */
#ifdef	SYS
	param['S'] = SYS;
#endif
#ifdef	WHO
	param['W'] = WHO;
#endif
#ifdef	VERSION
	param['V'] = VERSION;
#endif
	param['U'] = unixtime(t);
	param['D'] = today(t);
	param['T'] = thetime(t);

	/* See strftime() for the following formats. */ 
	param['a'] = abbrweekday(t);
	param['A'] = fullweekday(t);
	param['b'] = abbrmonth(t);
	param['B'] = fullmonth(t);
	/* param['c'] = ldatetime(t); */
	param['d'] = mday(t);
	param['H'] = hour24(t);
	param['I'] = hour12(t);
	param['j'] = yearday(t);
	param['m'] = month(t);
	param['M'] = minute(t);
	param['p'] = ampm(t);
	param['s'] = second(t);	/* should be 'S' but that is already in use. */
	param['w'] = weekday(t);
	/* param['x'] = ldate(t); */
	/* param['X'] = ltime(t); */
	param['y'] = shortyear(t);
	param['Y'] = fullyear(t);
	/* param['Z'] = thetimezone(t); */

	while ((arg = *argv++) && *arg == '-') {
		arg++;
		if ((c = *arg++) == '\0')
			break;
		if (c == '-') {		/* -- flags end of opts. */
			arg = *argv++;
			break;
		}
		if (*arg == '\0' && (arg = *argv++) == NULL)
			break;
		param[c] = arg;
	}
	if (arg == NULL)
		arg = TEMPLATE;

	while (c = *arg++) {
		if (c != '%') {
			putchar(c);
			continue;
		}
		if ((c = *arg++) == '\0')
			break;
		if (c == '%') {
			putchar(c);
			continue;
		}
		if ((p = param[c]) == NULL)
			continue;
		while (c = *p++) {
			switch (c) {
			case '\\':
			case '"':
				putchar('\\');
				break;
			}
			putchar(c);
		}
	}
	putchar('\n');

	exit(0);
}

/*======================================================================*
 * $Log: makevsn.c,v $
 * Revision 14.32.0.12  1994/06/24  20:21:36  tom
 *   + bugfixes: fix bug in delete/kill (introduced in #11),
 *     surround scratch-buffer names with *'s,
 *     use 'N instead of .N to uniquize buffer names.
 *
 * Revision 14.32.0.11  1994/06/03  11:55:38  tom
 *   - new variable: "indentation-increment".
 *
 *   - "handle-tab" does not depend anymore on being bound to tab key.
 *     Uses "indentation-increment" to determine the amount of indentation
 *     in text and fundamental mode mode.  If tabbing from beginning of
 *     line, lines up with indent of the previous line; if previous line is
 *     not indented, uses value of "left-margin"; if that turns out to be
 *     zero, uses the value of "indentation-increment".
 *
 *   - Kill commands (except kill-region) are now useful in view mode:
 *     they copy the region they're supposed to kill to the kill ring and
 *     move the cursor to the end of that region.
 *
 *   - bugfixes: Linux makefile entry; POSIX tty + BSD line discipline
 *     handling of i-processes; fix bogus modify-detection for files > 64k
 *     on MS-DOS.
 *
 * Internal changes:
 *   - (makevsn main): add support for strftime() formats.
 *
 * Revision 14.32.0.10  1994/04/07  02:07:23  tom
 *   - new command: "case-region-capitalize".
 *
 *   - new variables "keyseq-timeout-in-ms",
 *     "sentence-end" (replaces "sentence-format-string"), "sentence-sep".
 *
 *   - "fill-paragraph" now uses the "sentence-*" variables to determine the
 *     end-of-sentence, and th number of spaces that should follow it.
 *
 *   - new macros: "grep", "man", "next-line-first-non-blank",
 *     "transpose-s-expressions", "transpose-words".
 *
 *   - ported to Linux, HP-UX 9.01 (native cc)
 *
 * Internal changes:
 *   - bugfixes: auto-execute commands are executed in order of their definition;
 *     make job-control work in subprocesses with POSIX terminal control; fix
 *     timeout bug in input key handling; make CRLF conversion work with
 *     subprocesses; fix bug in "define-macro" error handling; fix bug in color
 *     handling that affected cursor color.
 *   - portability: replace `register va_list' with `va_register va_list'.
 *
 * Revision 14.32.0.9  1994/02/01  20:37:32  tom
 * External changes:
 *
 *   - new variable: "dbx-program-pattern".
 *
 *   - bugfixes: avoid possible crash in "dirs-extract" handling; revert
 *     in-macro support for i-search to avoid unwanted interactions with macros.
 *
 *   - Added "doc/jove.qref" (Quick reference card) to the distribution.
 *
 *   - Ported top HP-UX 9.01
 *
 *   - Atari-ST: add support for Swedish, Norsk, Danish, Swiss keyboards.
 *
 * Revision 14.32.0.8  1993/11/12  01:33:16  tom
 * External changes:
 *
 *   - new commands:
 *     "search-forward-re", "search-forward-lit",
 *     "search-forward-re-nd", "search-forward-lit-nd",
 *     "search-backward-re", "search-backward-lit",
 *     "search-backward-re-nd", "search-backward-lit-nd"
 *
 *   + separate default strings for regexp- and literal search.
 *
 *   - i-search now knows how to handle keybindings to "accent", macros,
 *     "clear-and-redraw" and "redraw-screen" without stopping the search;
 *      C-W (yank-word) and C-Y (yank-line) are new commands;
 *     is truly interactive, even when started from a macro;
 *     handles control chars in the default search string correctly.
 *
 * Internal changes:
 *   + bugfixes (another longstanding one in overwrite mode handling; COLOR)
 *
 * Revision 14.32.0.7  1993/10/29  03:20:28  tom
 * (MS-DOS): add hack to recognize <Alt-Shift><letter> and <Alt-Ctrl><letter>;
 * various bugfixes for MS-DOS (COLOR!).
 *
 * Revision 14.32.0.6  1993/10/28  00:55:21  tom
 * (Atari): port to gcc (2.3.3) + gnulib;
 * (Atari, MS-DOS, VMS): allow case-insensitive filename completion;
 * (Atari, MS-DOS): expand environment variables in shell commands.
 *
 * Revision 14.32.0.5  1993/09/29  00:06:13  tom
 * (forward-character): fix bug in overwrite mode.
 *
 * Revision 14.32.0.4  1993/08/02  17:22:52  tom
 * Some improvements in regexp engine.
 *
 * Revision 14.32.0.3  1993/07/28  16:00:33  tom
 * patch: fix bugs in lazy COLOR mode;
 * don't enable color for implicit color terminals by default.
 *
 * Revision 14.32.0.2  1993/07/14  22:02:25  tom
 * patch: fix some COLOR-related bugs introduced in 14.32.
 *
 * Revision 14.32.0.1  1993/07/07  12:12:58  tom
 * (F_TEXT): new option for f_open et al.
 *
 * Revision 14.32  1993/04/09  00:46:25  tom
 * External changes:
 *
 *   + "case-ignore-search" ignores case only for lower-case characters in the
 *     search string; upper-case and accented characters must match exactly.
 *
 *   - mode-line's %P format shows "All" if the whole buffer contents are
 *     visible in the window.
 *
 *   - JOVE can be configured to allow direct editing of files with DOS-style
 *     newline convention, using a compile-time option and the user variables
 *     "binary-read-files" and "binary-write-files".
 *
 *   - "color-erase-glitch", "color-standout-glitch" - new variables to describe
 *     terminal peculiarities regarding color (rainbow JOVE only).
 *
 * Internal changes:
 *   - (display-filetype): optimize symlinks to autonfsmount directory.
 *   - (ATARI ST): make it work for MiNT.
 *   - improve SIGWINCH handling.
 *   - optimize color handling; support SCO-termcap style color capabilities.
 *
 * Revision 14.31.0.2  1993/03/25  00:26:11  tom
 * allow compile-time CRLF option for non-DOS systems.
 *
 * Revision 14.31.0.1  1993/03/19  09:25:38  tom
 * Internal changes:
 *  - fix MS-DOS getchar() botch for non-standard scancodes;
 *  - reaffirm port to HP-UX.
 *
 * Revision 14.31  1993/02/18  10:10:18  tom
 * External changes:
 *
 *   + Abbrev mode, if "auto-case-abbrev", first looks for the literal abbrev
 *     before looking up the lowercased abbrev.  That means that abbrevs that
 *     contain caps are now found (and expanded literally); only full-lowercase
 *     abbrevs are subject to auto-case expansion.
 *
 *   - "auto-execute-command" with prefix argument shows the list of auto-execs.
 *
 *   - "disable-biff" now takes effect immediately.
 *
 *   + As a special case, "execute-macro" now interprets prefix argument 0,
 *     when propagated to it by "ESC + make-macro-interactive", as
 *     `execute 0 times'.  In all other cases a zero prefix argument
 *     means `execute until failure'.
 *
 * Internal changes:
 *   - re-TINY-fied through lots of small optimizations.
 *   - remove (void) casts to non-void function calls since these just clutter
 *     the code (imho).
 *   - cache HH:MM string for %t modeline directive so that it is updated just
 *     once per minute; this allows a working %t in TINY jove that --for lack
 *     of code space-- gets current time from a separate program.
 *   - RErecur() now preserves replacement SEARCH string too.
 *   - fixed bug in re-visit file code in file_exists().
 *   - fixed bug in "dirs-unique" handling in pushd.
 *
 * Revision 14.30  1993/01/26  18:43:18  tom
 * External changes:  (features marked with `-' not available in TINY joves)
 *
 *   - new commands:
 *     "append-buffer" - append buffer contents to a file.
 *
 *   - new variables:
 *     "dirs-extract", "dirs-unique" - affect behaviour of pushd,
 *     "prompt-with-prefix-arg".
 *
 *   + new macros:
 *     "join-previous-line" (ESC &), "join-next-line" (ESC $)
 * 	join lines, with a single space in between.
 *     "news"
 * 	show this list of recent changes to JOVE.
 *
 *   - new bindings:
 *       window-find-map V	- view-file
 *       help-map N	- news
 *       help-map T	- tutorial
 *       ESC ESC		- help
 *
 *   + "delete-white-space" with a numeric argument now deletes whitespace
 *     before (if negative) or after (if positive) point.
 *
 *   - directory handling is upgraded with features from tcsh(1):
 *     - "pushd" and "popd" accept prefix argument to emulate tcsh's
 *       "pushd +N" / "popd +N", pushd also accepts +N on its command line;
 *     - "dirs" with prefix argument gives a long listing of the directory stack;
 *     - file names can be prefixed with "=N" indicating the Nth directory
 *       in the stack, or "=-" indicating the previously visited directory;
 *     - directory stack is initialized from the environment variable "DIRS".
 *
 *   + "find-file" to an existing buffer now checks whether the file on disk
 *     has been changed since you last visited or saved it, and offers to
 *     visit it if it has been changed.
 *
 *   + The file-saving commands now offer to overwrite read-only files.
 *     (but only if you are allowed to chmod it.)
 *
 *   + make "newline" and friends do what "delete-blank-tail" promises.
 *
 *   + new RegExp directive: "\!" negate match status of previous subexpr.
 *     (this is an experiment; it may go away later)
 *
 *   - prefix argument ("digit" and friends) is now interpreted as an octal
 *     number if the first digit you enter is `0'.
 *
 * Internal changes:
 *   - re-TINY-fied through lots of small optimizations.
 *   - internal reorganization of RegExp compiler; allow long jump offsets.
 *   - better integration of normal and sparse keymaps; add (optional) bit
 *     vector to cache sparsemap key bindings; improve determination of
 *     active keymaps: allow prefix maps to be overlaid.
 *   - generalize hashed InJoverc command lookup to variables.
 *   - be more careful to call modify() before the actual modifications
 *     take place so they can be avoided if file-changed confirmation fails.
 *   - fix bug in [beep] visible bell.
 *
 * Revision 14.29  1992/11/07  17:05:31  tom
 * External changes:
 *
 *   - Error parsing is now incremental (i.e., "next-error" looks for more
 *     errors to parse if you are at the end of the error list) to make
 *     "i-process-parse" more convenient.
 *
 * Internal changes:
 *   - Portability: tested and debugged for NeXTOS 3.0, SunOS 4.1.1, Ultrix 4.3,
 *     SCO 3.2.2.
 *   - new_proc() now leaves process buffer current, analogous to
 *     non-interactive processes.
 *
 * Revision 14.28  1992/09/23  01:01:38  tom
 * External changes:
 *
 *   - new commands: <none> (in fact, the "sparse-bind" commands introduced in
 *     14.27 have been removed.  Sparse keymaps are now integrated in the regular
 *     keymap binding mechanism)
 *
 *   - new variables: "default-color".
 *
 *   - jove_recover: rephrase mail message and -subject to say what it means.
 *
 * Internal changes:
 *   - Portability: use new general portability conventions as prescribed by
 *     the headers "portdefs.h" and "portansi.h"; move some duplicated
 *     system-dependencies from jove.h to tune.h, and from *.c to the
 *     appropriate *.h files; (hopefully) improved Posix compatibility.
 *   - integrate sparsemaps in regular keymap binding/lookup mechanism;
 *     make "window-find" and "help" commands `transparent' to keymap binding,
 *     so commands can be bound directly to, for example, "C-X 4 <key>".
 *     (non FIXED_MAPS only)
 *   - improve COLOR support (by introduction of non-standard termcapabilities:
 *     esp., color remap).
 *   - improve VARTERM code so that it lives more happily alongside windowing
 *     systems.
 *   - fix bug which caused "apropos" to botch after a failed "search-reverse"
 *     (that was an old one that finally crept up with me.)
 *   - preserve highlighting in "window-find".
 *
 * Revision 14.27  1992/09/10  03:36:25  tom
 * External changes:
 *
 *   - new commands: "up-list".
 *
 *   - new variables: "quote-char".
 *
 *   - jove_recover: rename "-syscrash" option to "-preserve".
 *
 * Internal changes:
 *   - use QuoteChar variable instead of constant CTL('Q').
 *   - make macros work in Interactive environments.
 *   - force display of [Ambiguous] etc. in file name completion when
 *     "completion-auto-help" is set.
 *   - improve detection of linked and changed files.
 *   - implement DEF_REF scheme.
 *   - fixed some typos, cleanup empty `#' directives in *.h files.
 *   - rename "re1.c" to "search.c".
 *   - make setmaps error messages conform to standard "parse-errors" format.
 *
 * Revision 14.26  1992/08/26  23:57:07  tom
 * External changes:
 *
 *   - new commands: "abbrev-expand", "append-next-kill"
 *
 *   - new variables: "completion-auto-help", "erase-char", "i-shell",
 *     "i-shell-flags".  "erase-char" is a constant set to current 'stty
 *     erase' value; "i-shell" is initialized from environment var. ESHELL.
 *
 *   - "describe-variable" now shows current value of the variable.
 *
 *   - jove_recover: add "-check" and "-user username" options, avoid
 *     overwriting existing files in REC_DIR in "-syscrash".
 *
 * Internal changes:
 *   - PRIVATE-ized Variable definitions that were used only in a single module.
 *   - add RCS Ids and Logs to all source files.
 *   - some random reTINYfying.
 *   - fixed bug in process-dbx-mode handling (introduced in 14.18)
 *   - block SIGWINCH signals during "pause-jove", so that JOVE sees window
 *     resizes when it is resumed.
 *   - Make "execute-macro" work after "make-macro-interactive" (Interactive
 *     state is saved and restored on a per-active macro basis).
 *   - use current VDISABLE character (if any) on Posix systems.
 *   - in "wind-find", execute macros immediately so they have no
 *     unexpected (visual) side-effects.
 *
 * Revision 14.25  1992/07/06  21:33:06  tom
 * External changes:
 *
 *   - filename expansion now uses braces ${ } instead of parentheses $( )
 *     to delimit environment variables, like most UNIX shells.
 *
 *   - "display-filetype" now knows most (if not all) "ls -F" like file types.
 *
 *   - added commands to manipulate user-defined and ``sparse'' keymaps.
 *
 *   - allow single `+' or `-' in commands taking a number to increment
 *     or decrement by 1 (this includes "find-buffer".)
 *
 *   - add "xon-xoff" program to distribution.
 *
 * Internal changes:
 *   - *lots* of changes for dynamic keymap support.
 *   - *lots* of random optimizations (still not squeezed dry yet!)
 *   - use the repeat count in printf "%c" format.
 *   - cleanup NO_PROCDECL code for tiny compilers.
 *   - add filename length check in ParseName.
 *   - add #error directives in a non-ANSI_C-friendly way.
 *   - moved some routine to more logical modules.
 *   - fixed wording in recover -syscrash mail message.
 *   - some portability fixes.
 *
 * Revision 14.24  1992/07/05  14:51:44  trh
 * External changes:
 *
 *   - new command "tab-to-next-column" (ESC TAB), with related variables
 *     "column-format" and "column-tabstop".
 *
 *   - new variable "display-filetype" for "ls -F" style type flags in
 *     filename completion.
 *
 *   - "apropos" now uses a regular expression as keyword.
 *
 *   - "kill-{word,sentence,s-expr}" commands now handle numeric argument 0
 *     specially by killing the entire current entity.
 *
 *   - "case-word-capitalize" is now consistent with other "case-word"
 *     commands in handling negative numeric arguments.
 *
 * Internal changes:
 *   - store number of sub-expressions in compiled regexp so that other
 *     regexp compiles don't botch it.
 *   - un-highlight error line if errors are invalidated.
 *
 * Revision 14.23  1992/04/15  01:00:32  trh
 * External changes:
 *
 *   - in minibuf: ^C bound to `insert Current word', ^S (insert filename)
 *     now takes numeric argument as buffer number.
 *
 *   - make "screen-wide" work on MS-DOS (with VGA video controller)
 *
 *   - interactive search now recognizes single-character keystrokes which
 *     are bound to it as repeat/reversal character, next to builtin ^S/^R.
 *
 * Internal changes:
 *   - finish KEYALIAS with support for extended termcap keydefs.
 *   - finish HIGHLIGHT code.
 *   - add SCO termcap color support: Sf, Sr, sp capabilities.  Also remap
 *     CO -> SC, Co -> CO, Li -> LI since Co was already used in SCO termcap.
 *   - add signal() emulation for true POSIX systems.
 *
 * Revision 14.22  1992/03/28  20:01:44  trh
 * External changes:
 *
 *   - lines,  columns, cps, ttyname, version, system, model:
 * 	new constant (read-only) variables
 *
 *   - highlight:
 * 	new variable controls highlighting of tag-, error-, and DBX matches
 * 	(provided terminal has highlight capability, of course;)
 *
 *   - scratch-buffer, file-buffer:
 * 	new commands to change the buffer type;
 *
 *   - source:
 * 	generalized `if' conditional statement; can now handle environment
 * 	variables, internal JOVE variables and constants, and relational
 * 	operators;
 *
 *   - mode-line:
 * 	extended functionality to %( %) conditionals; %V (version) directive;
 *
 * Internal changes:
 *   - facilitate character table management; include tools to generate chartables
 *     from a master directory and a simple table-like charset description;
 *   - add SELECTABLE chartable compile-time option.  This is used on MS-DOS
 *     to implement codepage support;
 *   - revision of KEYALIAS support for arcane termcap function-key name
 *     conventions.
 *
 * Revision 14.21  1992/03/11  12:29:28  trh
 * External changes:
 * 	- new constant "term" shows current terminal name.
 * 	  (constants are like variable except their value cannot be changed)
 *
 * 	- (MSDOS only) new variable "use-direct-video" controls whether screen
 * 	  output is done by writing directly to the video-RAM (which is fast)
 * 	  or using the BIOS system calls.  This is normally "ON", but you can
 * 	  turn it off if this gives problems on your DOS machine (like flicker)
 *
 * Internal changes:
 * 	- Complete Posix-ation: use symbolic constants in calls to open, creat;
 * 	- add support for CONSTANT variables.
 * 	- make COLOR work correctly in combination with scrolling.
 * 	- port MS-DOS code to Turbo/Borland C.
 * 	- improve MOUSE response with fast output devices.
 *
 * Revision 14.20  1992/02/13  21:22:56  trh
 * External changes:
 *
 *   - sentence-format-string:
 * 	New variable, a regular expression that defines end-of-sentence.
 *
 *   - tex-error-parse:
 * 	New macro to handle error messages in a TeX logfile.
 *
 * Internal changes:
 *   - sources are now pretty Posix.1 compliant if _POSIX_SOURCE is defined;
 *     still uses signal() though.
 *
 * Revision 14.19  1991/12/10  15:15:12  trh
 * External changes:
 *
 *   - skip-partial-tabs:
 * 	New variable for old behaviour of {next,previous}-line on Tabs.
 * 	(compile-time option SKIPTABS)
 *
 *   - compile-it:
 * 	variable "make" renamed to "compile-command", I think this is
 * 	less confusing;
 * 	ALWAYS insert previous command as default on C-U C-X C-E, not just
 * 	on non-"cc","make" commands, to be consistent.
 *
 *   - parse-errors:
 * 	Can now handle error message formats where the error messages
 * 	contain only the line number, provided the file name is mentioned
 * 	at least once.  Since the same mechanism is used for
 * 	"process-dbx-output", you can now also use it to handle the
 * 	Gnu debugger! (if you set "dbx-format-string" right)
 *
 *   - *minibuf*:
 * 	"forward-character" now rings the bell if you are at the end of the
 * 	line, instead of replacing it with the next line in *minibuf*.
 * 	(at which the current line was irretrievably lost)
 *
 *   - mode-line:
 * 	Added functionality to %( %): items between %N( %) are printed only
 * 	if the width of the screen is >= N.
 *
 * Internal changes:
 *   - Error parsing now uses Marks to point to the error lines; this means
 *     that the position _within_ the line is maintained correctly.  This
 *     is especially nice in spelling correction;
 *   - lots of improvements (hopefully:-) in the Makefiles;
 *   - re.c: some minor optimizations, add REreset() to re_sindex that was
 *     missing since the beginning of time, remove locrater check at \< \>
 *     since it screwed up "s|\<[a-z]* *||".
 *   - tty.c: assume baud rate 38400 if ospeed==EXT (most systems seem to
 *     have this nowadays...), make LOAD_AV code compile on NeXT--still not
 *     sure it actually _works_!
 *
 * Revision 14.18  1991/12/10  15:13:20  trh
 * External changes:
 *
 *  - mode-line
 * 	add %L (line-number) and %P (relative position) directives.
 *
 *  - query-replace-in-region (C-X Q)
 * 	new command; its name says it all.
 *
 *  - query-replace
 * 	add [C-]D (delete) command; abort if abort-char typed.
 *
 *  - shell-command-leaves-point-at-end
 * 	new variable; for original behaviour of shell commands.
 *
 *  - wrap-process-lines
 * 	new variable (re-introduced from JOVE 4.14).
 *
 * Internal changes:
 *  - fix a bug in Atari-ST shell-command I/O redirection;
 *  - restore kbd state when fork() fails in PIPEPROCS environment;
 *  - support POSIX's TERMIOS tty mode setting;
 *  - introduced locrater stuff in REmatch for more accurate replace;
 *  - re-TINY-fied.
 *  - make pointer arrays const where possible.
 *  - found and fixed "junk from dead pty" bug. (finally!)
 *
 * Revision 14.17  1991/11/14  19:21:54  trh
 * CONVEX port; add i-process color; fix Minor => Major both in C_like_Mode.
 *
 * Revision 14.15  1991/09/20  18:25:48  trh
 * abbrev.c:
 * remove private mode_names; use centralized MajorName[] instead;
 * in define-abbrev, provide default phrase for existing abbrevs, so
 * you can edit it (non-TINY only).
 * ask.c:
 * some changes due to user-defineable "abort-char", dynamic allocation of
 * string variables.
 * atari_st.c:
 * port to gcc.
 * buf.c:
 * Centralize names of Major and Minor modes here (through DEF_{MAJ,MIN} macros)
 * c.c:
 * add Perl mode support; make preprocessor macro definitions line up with
 * the beginning of the macro name in situations like:
 * #define aap(noot, mies) do { \
 *         ^--- braces line up here.
 *         }
 * ctype.c:
 * add Perl mode support.
 * disp.c:
 * ModeLine: remove Major/Minor mode names: these are centralized in buf.c;
 * add "page-overlap" variable; some changes due to user-defineable "abort-char".
 * extend.c:
 * remove DEF_PREFIX definitions; user-defineable "abort-char";
 * dynamic allocation of string variables (no builtin string size limits).
 * fp.c:
 * remove superfluous '#include <sys/stat.h>" which I overlooked when I moved
 * this to "io.h".
 * funcdefs.c:
 * some changes due to new DEF_ conventions.
 * insert.c:
 * add Perl mode support.
 * io.c:
 * fix NULLCHARS bug in file_write; file_backup regular files only.
 * iproc.c:
 * some minor changes.
 * jinstall.c:
 * some changes to support dynamic string variable allocation.
 * jove.c:
 * some minor changes.
 * jove.h:
 * revision of DEF_ macros:
 * some renames to make them all the same length (so VMS sort can handle them),
 * add pretty-name parameter to MAJ and MIN to centralize Mode name definition,
 * MAP passes the map address, and STR is changed to support dynamic string
 * allocation (which obsoletes the `Len' field);
 * add definition of `struct sparsemap'; update function prototypes.
 * last.c:
 * *** Initial revision ***
 * misc.c:
 * add "simulate-input", "help", "goto-character"; make "transpose-characters"
 * bidirectional; calculate internal "buffer-position" on numeric argument
 * (CRLF systems only) as opposed to position in the actual file.
 * msdos.c:
 * fix some typos.
 * proc.c:
 * dynamic allocation of string variables.
 * process.h:
 * some changes due to dynamic string allocation.
 * re.c:
 * dynamic allocation of string variables; fix portability botch in
 * RE compilation of `+'.
 * re.h:
 * some changes due to dynamic string allocation.
 * re1.c:
 * dynamic allocation of string variables; support for user-definable "abort-char".
 * readdir.h:
 * Atari ST: port to gcc needed some changes.
 * readme:
 * update it for JOVE According to Tom (beta-release to Jonathan Payne)
 * rec.c:
 * restore to existing buffer iff it is empty; add -syscrash support.
 * setmaps.c:
 * some changes due to new DEF_ conventions.
 * term.c:
 * fix typo in VARTERM code.
 * tune.h:
 * add Atari ST gcc portability.
 * util.c:
 * add "abort-char"; add dynamic string variable allocation handler: set_str();
 * add sparsemap handler (for "window-find" and "help"); add DEF_MAP here
 * (replacing DEF_PREFIX in extend.c).
 * vars.c:
 * change to new DEF_ conventions.
 * vms.c:
 * some improvements in UNIX <=> VMS filename translation.
 * wind.c:
 * change to generic sparsemap handler in "window-find".
 *
 * Revision 14.14  1991/09/20  18:16:08  trh
 * ask.c:
 * make sure ^@ does not terminate real_ask; be more careful in variable
 * name extraction in `env_expand'; add VMS support (env_expand;arg_expand).
 * atari_st.c:
 * change result type of `alarm' to `int'.
 * ctype.c:
 * fix typo in NeXT character set; #undef T/F before redefinition.
 * disp.c:
 * VMS-specific %C modeline message.
 * io.c:
 * make "prefix-3 R" conditional on !defined(ExecNow); some minor changes.
 * io.h:
 * rename L_END to (official BSD) L_XTND; remove VMS definition of CRLF;
 * add `read_one_char'.
 * ipr-pipe.inc:
 * move --NumProcs from `proc_close' to iproc.c:`kill_off'.
 * ipr-pty.inc:
 * avoid race conditions by not closing pty in SIGCHLD interrupt handler;
 * move BTL_BLIT conditional code to tty.h.
 * ipr-vms.inc:
 * Initial revision.
 * iproc.c:
 * add VMS support; avoid race conditions on ptys by careful order in kill_off.
 * jove.c:
 * some revisions in finish (interrupt handling).
 * msdos.c:
 * change result type of `alarm' to `int'.
 * proc.c:
 * fix VMS "error-format" string.
 * process.h:
 * finalize VMS support.
 * rec.c:
 * make self-record-file check more robust.
 * screen.c:
 * fix fatal error message in make_scr.
 * term.c:
 * enlarge TSPACE for non-TINY systems.
 * tty.c:
 * remove BTL_BLIT conditional code (now handled in tty.h); make sure that
 * Meta-Delete (\377) works by setting Quit character to IntChar.
 * tty.h:
 * handle BTL_BLIT jwinsize support here.
 * tune.h:
 * finalize VMS support; conditional definition of bcmp,bzero,(r)index.
 * util.c:
 * special VMS support in `syserr'.
 * vms.c:
 * add VMS-specific error handling; make keyboard input interrupt-driven in
 * order to handle IntChar; revise broadcast-message handling, make it work
 * with sub-shell; add IPROCS support.
 *
 * Revision 14.13  1991/08/15  23:04:34  trh
 * ask.c:
 * ported to VMS (esp. file name completion/expansion)
 * atari_st.c:
 * redefine key F10 as "k;" instead of "k0", move mktmpe() to util.c;
 * add `stat()' which tries to generate unique I-node numbers.
 * buf.c:
 * some minor changes; VMS port: use `ino_xxx' manipulation macros.
 * ctype.c:
 * fix some accent character definitions for AIX.
 * disp.c:
 * reTINYfied; add "update-screen" command.
 * extend.c:
 * in DoAutoExec: use ExecNow instead of ExecCmd for immediate macro
 * execution; some minor changes for VMS.
 * fkeys.c:
 * add KEYALIAS for AIX: "kw==kH"; some rewording in comments.
 * fp.c:
 * replace `errno' in error messages with `syserr()'; generalize CRLF.
 * io.c:
 * add execution of macro bound to "prefix-3 R" and retry on failed
 * read_file open; protect `rel_name' against undefined PWD; VMS support
 * in ParseName; replace `errno' in error messages with `syserr()'.
 * io.h:
 * replace `putchar' with `putch' to avoid conflicts with stdio library
 * (this could not be dealt with using a re#define); add generic CRLF
 * compilation option; revise conditional declaration of `rel_name';
 * centralize `#include <sys/stat.h>' here.
 * ipr-pipe.inc:
 * replace `errno' in error messages with `syserr()'.
 * ipr-pty.inc:
 * replace `errno' in error messages with `syserr()'.
 * jove.h:
 * reTINYfied; add VMS support.
 * macros.c:
 * add "trace-macros" variable.
 * msdos.c:
 * redefine key F10 as "k;" instead of "k0", move `mktmpe()' to util.c;
 * add `stat()' which tries to generate unique I-node numbers.
 * proc.c:
 * add error parsing string for VMS VAXC compiler, and other VMS support.
 * process.h:
 * add VMS support.
 * readdir.h:
 * add MACintosh and VMS support.
 * rec.c:
 * use `ino_xxx' manipulation macros for benefit of VMS.
 * rec.h:
 * replace `ino_t' with `INO_T' to hide VMS<->others differences.
 * screen.c:
 * replace `HZ' with `Hz' to avoid name clash with macro on some unices;
 * replace putchar with putch; take care with initializing lengths of
 * `multiple' ins/del. char. capabilities (for VMS `smg' termcap emulation).
 * term.c:
 * add optional VARTERM code for "screen-{dense,normal,wide,narrow}" commands.
 * termcap.h:
 * add VMS `smg-termcap' support; replace `HZ' with `Hz' (name clash);
 * correct some `const' declaration inconsistencies.
 * tty.c:
 * add VMS hooks; replace `errno' with `syserr()' in error messages;
 * make `charp' work for AIX console which botches on select with timeout
 * zero; add VARTERM code in `ttsize'.
 * tune.txt:
 * add VMS support; fix MSDOS device names.
 * util.c:
 * add `syserr()' for symbolic `errno' messages; add VMS support in `basename';
 * move `mktmpe()' to here.
 * wind.c:
 * WINDOWS (Mac) support in `SetTop()'.
 *
 * Revision 14.12  1991/07/02  15:09:10  trh
 * ask.c:
 * Improve recursive ask, allow "recursive-edit".
 * atari_st.c:
 * get colors right (at last; I finally got hold of a color monitor...)
 * some small fixes in Push().
 * buf.c:
 * Oops! screwed up buffer deletion in 14.11. Add display of modified
 * buffers only on "ESC - list-buffers".
 * disp.c:
 * make mode-line stand out against message line in COLOR mode.
 * extend.c:
 * some minor cleanups; save message line in do_help() while attempting
 * to read help databases.
 * fmt.c:
 * some minor cleanups; don't allow "%r" directive if BAD_VARARGS.
 * insert.c:
 * in "hash-insert", detect existing "else" and "endif" directives,
 * adjust indentation of existing preprocessor directives if `#' re-typed
 * at start of line.
 * io.h:
 * define L_{SET,INCR,END} and [RWF]_OK macros here if not already defined
 * jinstall.c:
 * add `R'eplace-copy, `H'ome and `S'earch-path commands;
 * add "-c <configurationfile>" command-line option.
 * jove.c:
 * some minor cleanups; add FULLRECOVER hooks; allow "recursive-edit"
 * while Asking; be more accurate in update intervals: make sure update
 * occurs at a full minute.
 * jove.h:
 * some minor cleanups; add `unbell()' macro.
 * keymaps.txt:
 * fix sentinel in "window-find" map; add DigitCmd map for do_command().
 * keysubst.c:
 * allow "keysubst - template-file <Bindings" syntax.
 * macros.c:
 * cancel bell on caught macros; add informative message in "make-macros-
 * interactive"; add direct keybinding in "define-macro" if an argument
 * is given (in ".joverc" only).
 * misc.c:
 * use name of current macro (if any) as prompt in "print-message".
 * msdos.c:
 * fix a minor screwup in UnixToBuf.
 * para.c:
 * fix Point-placement bug in RegJustify(); some minor cleanups.
 * portsrv.c:
 * improve the chances that PORTSRV_SHOULD_BUFFER indeed buffers
 * unbuffered process output (at least on Minix...)
 * readdir.h:
 * add declaration of `ask_dir_only'; unconditionally declare alphacomp().
 * rec.c:
 * add FULLRECOVER implementation (i.e., internal "recover" command).
 * screen.c:
 * some minor cleanups; remove text_color==bg_color check in req_color()
 * since set_color() already deals with it (and it potentially screws up
 * the background color).
 * tty.c:
 * cleanup separation of TERMIO and SGTTY code; some minor cleanups.
 * tune.h:
 * add FULLRECOVER; add BAD_VARARGS and VA_...PROPAGATE macros which depend
 * on it (BAD_VARARGS Inhibits the use of printf("%r") directive);
 * add ULTRIX target.
 * tune.txt:
 * add Home (!unix), Path (Atari).
 *
 * Revision 14.11  1991/07/01  23:01:06  trh
 * ask.c:
 * TINYfied; handle AskNextLine in NextLine now, so key rebindings work
 * as  expected; add ^S (^\) command to insert current filename;
 * add command-line filename expansion option (for non-UNIX systems),
 * this is controlled by "expand-command-line-argument" variable.
 * atari_st.c:
 * revision of shell-command handling: now UnixToBuf is the
 * interface instead of ShellToBuf, to avoid duplication of system-
 * independent code (see also proc.c).  Lots of I/O redirection revisions:
 * `_shell_p' (gulam) redirection is handled by insering '<' and '>>'
 * directives in the command.  Slight changeds in FileSelector... JOVE
 * should be .PRG for fileselector to work (at least from the desktop).
 * buf.c:
 * centralize selection of default buffer- and file names in functions
 * `def_buf' and `def_bfile'; add "pick-buffer" command: like "select-buffer"
 * but refuses to create new buffers.
 * extend.c:
 * some minor cleanups; show data_obj type in "descibe-key"; support user-
 * defined macro help-file (~/.jovehelp (unix) or ~\jove.hlp (DOS)).
 * (non-TINY only)
 * fp.c:
 * add F_IGN_0 file read option: ignore Null characters when file is read.
 * (for NULLCHARS compilation option only; otherwise Null-chars are ignored
 * anyway...) This was highly desirable in read_pipe (proc.c)...
 * insert.c:
 * LineInsert: use lsave() instead of SavLine(); allow repeat count in
 * "yank-pop" as in "yank", reorganized Yank and YankPop for this.
 * io.c:
 * TINYfied; fix partial-last-line bug in `read_file'; improve DOS-filename
 * parsing (recognize device names); improve OverWrite mode kludge in `lsave'
 * (but it's still a kludge...)
 * io.h:
 * add f_eof(fp) macro; add F_IGN_0 flag.
 * jove.c:
 * TINYfied; allow stdin pipe for non-UNIX systems; hook in command-line
 * filename expansion; move "quick-exit" and "exit-jove" from misc.c to
 * here; don't touch curwind if error is caught in macro execution.
 * jove.h:
 * add BNAMESIZE + prototypes for new routines.
 * keysubst.c:
 * fully ANSIfied (at last).
 * macros.c:
 * cancel bell on caught macro errors; add informative message in
 * "make-macro-interactive".
 * marks.c:
 * simplify PopMark, DoSetMark, IFixMarks; add (unconditional) set_mark().
 * misc.c:
 * move "quick-exit" and "exit-jove" to jove.c; make EditParam work for
 * SCO unix/Xenix; repair NULLCHARS dot-char display bug in "buffer-position".
 * mouse.inc:
 * be more precise about when to allow mouse commands; make mouse work as
 * expected in OverWrite mode (see also io.c:lsave and util.c:DotTo).
 * move.c:
 * "{next,previous}-line" now work as expected when Asking;
 * `beyond-end-of-line' handling in OverWrite mode moved to DotTo/how_far.
 * msdos.c:
 * reviosion of shell-command" handling: now UnixToBuf is interface instead
 * of ShellToBuf to avoid duplication of system-independent code.
 * proc.c:
 * extend ShelToBuf and UnixToBuf with optional input-filename parameter
 * (for "filter-region"); add some more meaningful prompts to "shell-command";
 * change monitoring progress in read_pipe to a (nearly) system-independent
 * way (does not depend anymore on interruptability of pipes).
 * re.c:
 * resolve global-variable naming conflict in re_ask (for pdp11 V7 compiler).
 * re1.c:
 * fix null-replacement bug in substitute.
 * recover.c:
 * add some robustness; speed up record-file access.
 * screen.c:
 * add curstoLL() == Placur(ILI, 0).
 * screen.h:
 * duplicate declarations of ILI, LI, CO to aviod inclusion of termcap.h
 * in most modules; some minor cleanups.
 * tty.c:
 * add clock() implementation of DoSit for (unix) systems that support it.
 * tune.txt:
 * add JoveHlp[], DevNames[] (MSDOS).
 * util.c:
 * `DotTo' now checks goal column against actual line length,
 * and handles `beyond-end-of-line' condition in OverWrite mode.
 * wind.c:
 * make "scroll-step" variable visible again (it was lost somehow...);
 * tiewind now uses top-line saved in the buffer instead of blindly
 * CentWind()ing.
 *
 *======================================================================*/
