head	1.10;
access;
symbols
	perseant-exfatfs-base-20250801:1.10
	perseant-exfatfs-base-20240630:1.10
	perseant-exfatfs:1.10.0.36
	perseant-exfatfs-base:1.10
	cjep_sun2x:1.10.0.34
	cjep_sun2x-base:1.10
	cjep_staticlib_x-base1:1.10
	cjep_staticlib_x:1.10.0.32
	cjep_staticlib_x-base:1.10
	phil-wifi-20200421:1.10
	phil-wifi-20200411:1.10
	phil-wifi-20200406:1.10
	pgoyette-compat-merge-20190127:1.10
	pgoyette-compat-20190127:1.10
	pgoyette-compat-20190118:1.10
	pgoyette-compat-1226:1.10
	pgoyette-compat-1126:1.10
	pgoyette-compat-1020:1.10
	pgoyette-compat-0930:1.10
	pgoyette-compat-0906:1.10
	pgoyette-compat-0728:1.10
	pgoyette-compat-0625:1.10
	pgoyette-compat-0521:1.10
	pgoyette-compat-0502:1.10
	pgoyette-compat-0422:1.10
	pgoyette-compat-0415:1.10
	pgoyette-compat-0407:1.10
	pgoyette-compat-0330:1.10
	pgoyette-compat-0322:1.10
	pgoyette-compat-0315:1.10
	pgoyette-compat:1.10.0.30
	pgoyette-compat-base:1.10
	perseant-stdc-iso10646:1.10.0.28
	perseant-stdc-iso10646-base:1.10
	prg-localcount2-base3:1.10
	prg-localcount2-base2:1.10
	prg-localcount2-base1:1.10
	prg-localcount2:1.10.0.26
	prg-localcount2-base:1.10
	pgoyette-localcount-20170426:1.10
	bouyer-socketcan-base1:1.10
	pgoyette-localcount-20170320:1.10
	bouyer-socketcan:1.10.0.24
	bouyer-socketcan-base:1.10
	pgoyette-localcount-20170107:1.10
	pgoyette-localcount-20161104:1.10
	localcount-20160914:1.10
	pgoyette-localcount-20160806:1.10
	pgoyette-localcount-20160726:1.10
	pgoyette-localcount:1.10.0.22
	pgoyette-localcount-base:1.10
	netbsd-5-2-3-RELEASE:1.10
	netbsd-5-1-5-RELEASE:1.10
	yamt-pagecache-base9:1.10
	yamt-pagecache-tag8:1.10
	tls-earlyentropy:1.10.0.18
	tls-earlyentropy-base:1.10
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.10
	riastradh-drm2-base3:1.10
	netbsd-5-2-2-RELEASE:1.10
	netbsd-5-1-4-RELEASE:1.10
	netbsd-5-2-1-RELEASE:1.10
	netbsd-5-1-3-RELEASE:1.10
	agc-symver:1.10.0.20
	agc-symver-base:1.10
	tls-maxphys-base:1.10
	yamt-pagecache-base8:1.10
	netbsd-5-2:1.10.0.16
	yamt-pagecache-base7:1.10
	netbsd-5-2-RELEASE:1.10
	netbsd-5-2-RC1:1.10
	yamt-pagecache-base6:1.10
	yamt-pagecache-base5:1.10
	yamt-pagecache-base4:1.10
	netbsd-5-1-2-RELEASE:1.10
	netbsd-5-1-1-RELEASE:1.10
	yamt-pagecache-base3:1.10
	yamt-pagecache-base2:1.10
	yamt-pagecache:1.10.0.14
	yamt-pagecache-base:1.10
	bouyer-quota2-nbase:1.10
	bouyer-quota2:1.10.0.12
	bouyer-quota2-base:1.10
	matt-nb5-pq3:1.10.0.10
	matt-nb5-pq3-base:1.10
	netbsd-5-1:1.10.0.8
	netbsd-5-1-RELEASE:1.10
	netbsd-5-1-RC4:1.10
	netbsd-5-1-RC3:1.10
	netbsd-5-1-RC2:1.10
	netbsd-5-1-RC1:1.10
	netbsd-5-0-2-RELEASE:1.10
	netbsd-5-0-1-RELEASE:1.10
	jym-xensuspend-nbase:1.10
	netbsd-5-0:1.10.0.6
	netbsd-5-0-RELEASE:1.10
	netbsd-5-0-RC4:1.10
	netbsd-5-0-RC3:1.10
	netbsd-5-0-RC2:1.10
	jym-xensuspend:1.10.0.4
	jym-xensuspend-base:1.10
	netbsd-5-0-RC1:1.10
	netbsd-5:1.10.0.2
	netbsd-5-base:1.10
	matt-mips64-base2:1.9
	matt-mips64:1.9.0.32
	mjf-devfs2:1.9.0.30
	mjf-devfs2-base:1.9
	netbsd-4-0-1-RELEASE:1.9
	wrstuden-revivesa-base-3:1.9
	wrstuden-revivesa-base-2:1.9
	wrstuden-fixsa-newbase:1.9
	wrstuden-revivesa-base-1:1.9
	yamt-pf42-base4:1.9
	yamt-pf42-base3:1.9
	hpcarm-cleanup-nbase:1.9
	yamt-pf42-baseX:1.9
	yamt-pf42-base2:1.9
	wrstuden-revivesa:1.9.0.28
	wrstuden-revivesa-base:1.9
	yamt-pf42:1.9.0.26
	yamt-pf42-base:1.9
	keiichi-mipv6-nbase:1.9
	keiichi-mipv6:1.9.0.24
	keiichi-mipv6-base:1.9
	matt-armv6-nbase:1.9
	matt-armv6-prevmlocking:1.9
	wrstuden-fixsa-base-1:1.9
	netbsd-4-0:1.9.0.22
	netbsd-4-0-RELEASE:1.9
	cube-autoconf:1.9.0.20
	cube-autoconf-base:1.9
	netbsd-4-0-RC5:1.9
	netbsd-4-0-RC4:1.9
	netbsd-4-0-RC3:1.9
	netbsd-4-0-RC2:1.9
	netbsd-4-0-RC1:1.9
	matt-armv6:1.9.0.18
	matt-armv6-base:1.9
	matt-mips64-base:1.9
	hpcarm-cleanup:1.9.0.16
	hpcarm-cleanup-base:1.9
	netbsd-3-1-1-RELEASE:1.9
	netbsd-3-0-3-RELEASE:1.9
	wrstuden-fixsa:1.9.0.14
	wrstuden-fixsa-base:1.9
	abandoned-netbsd-4-base:1.9
	abandoned-netbsd-4:1.9.0.8
	netbsd-3-1:1.9.0.10
	netbsd-3-1-RELEASE:1.9
	netbsd-3-0-2-RELEASE:1.9
	netbsd-3-1-RC4:1.9
	netbsd-3-1-RC3:1.9
	netbsd-3-1-RC2:1.9
	netbsd-3-1-RC1:1.9
	netbsd-4:1.9.0.12
	netbsd-4-base:1.9
	chap-midi-nbase:1.9
	netbsd-3-0-1-RELEASE:1.9
	chap-midi:1.9.0.6
	chap-midi-base:1.9
	netbsd-3-0:1.9.0.4
	netbsd-3-0-RELEASE:1.9
	netbsd-3-0-RC6:1.9
	netbsd-3-0-RC5:1.9
	netbsd-3-0-RC4:1.9
	netbsd-3-0-RC3:1.9
	netbsd-3-0-RC2:1.9
	netbsd-3-0-RC1:1.9
	netbsd-2-0-3-RELEASE:1.8.4.2
	netbsd-2-1:1.8.6.1.0.2
	netbsd-2-1-RELEASE:1.8.6.1
	netbsd-2-1-RC6:1.8.6.1
	netbsd-2-1-RC5:1.8.6.1
	netbsd-2-1-RC4:1.8.6.1
	netbsd-2-1-RC3:1.8.6.1
	netbsd-2-1-RC2:1.8.6.1
	netbsd-2-1-RC1:1.8.6.1
	netbsd-2-0-2-RELEASE:1.8.4.2
	netbsd-3:1.9.0.2
	netbsd-3-base:1.9
	netbsd-2-0-1-RELEASE:1.8
	netbsd-2:1.8.0.6
	netbsd-2-base:1.8
	netbsd-2-0-RELEASE:1.8
	netbsd-2-0-RC5:1.8
	netbsd-2-0-RC4:1.8
	netbsd-2-0-RC3:1.8
	netbsd-2-0-RC2:1.8
	netbsd-2-0-RC1:1.8
	netbsd-2-0:1.8.0.4
	netbsd-2-0-base:1.8
	netbsd-1-6-PATCH002-RELEASE:1.8
	netbsd-1-6-PATCH002:1.8
	netbsd-1-6-PATCH002-RC4:1.8
	netbsd-1-6-PATCH002-RC3:1.8
	netbsd-1-6-PATCH002-RC2:1.8
	netbsd-1-6-PATCH002-RC1:1.8
	netbsd-1-6-PATCH001:1.8
	netbsd-1-6-PATCH001-RELEASE:1.8
	netbsd-1-6-PATCH001-RC3:1.8
	netbsd-1-6-PATCH001-RC2:1.8
	netbsd-1-6-PATCH001-RC1:1.8
	fvdl_fs64_base:1.8
	netbsd-1-6-RELEASE:1.8
	netbsd-1-6-RC3:1.8
	netbsd-1-6-RC2:1.8
	netbsd-1-6-RC1:1.8
	netbsd-1-6:1.8.0.2
	netbsd-1-6-base:1.8
	netbsd-1-5-PATCH003:1.7
	netbsd-1-5-PATCH002:1.7
	netbsd-1-5-PATCH001:1.7
	nvi_1_79:1.1.1.5
	netbsd-1-5-RELEASE:1.7
	netbsd-1-5-BETA2:1.7
	netbsd-1-5-BETA:1.7
	netbsd-1-4-PATCH003:1.7
	netbsd-1-5-ALPHA2:1.7
	netbsd-1-5:1.7.0.10
	netbsd-1-5-base:1.7
	minoura-xpg4dl-base:1.7
	minoura-xpg4dl:1.7.0.8
	netbsd-1-4-PATCH002:1.7
	wrstuden-devbsize-19991221:1.7
	wrstuden-devbsize:1.7.0.6
	wrstuden-devbsize-base:1.7
	comdex-fall-1999:1.7.0.4
	comdex-fall-1999-base:1.7
	netbsd-1-4-PATCH001:1.7
	netbsd-1-4-RELEASE:1.7
	netbsd-1-4:1.7.0.2
	netbsd-1-4-base:1.7
	netbsd-1-3-PATCH003:1.6
	netbsd-1-3-PATCH003-CANDIDATE2:1.6
	netbsd-1-3-PATCH003-CANDIDATE1:1.6
	netbsd-1-3-PATCH003-CANDIDATE0:1.6
	netbsd-1-3-PATCH002:1.6
	netbsd-1-3-PATCH001:1.6
	netbsd-1-3-RELEASE:1.6
	netbsd-1-3-BETA:1.6
	netbsd-1-3:1.6.0.2
	netbsd-1-3-base:1.6
	netbsd-1-2-PATCH001:1.6
	netbsd-1-2-RELEASE:1.6
	netbsd-1-2-BETA:1.6
	netbsd-1-2:1.6.0.4
	netbsd-1-2-base:1.6
	nvi_1_66:1.1.1.5
	BOSTIC:1.1.1
	netbsd-1-1-PATCH001:1.5
	netbsd-1-1-RELEASE:1.5
	netbsd-1-1:1.5.0.4
	netbsd-1-1-base:1.5
	netbsd-1-0-PATCH06:1.5
	netbsd-1-0-PATCH05:1.5
	netbsd-1-0-PATCH04:1.5
	netbsd-1-0-PATCH03:1.5
	netbsd-1-0-PATCH02:1.5
	netbsd-1-0-PATCH1:1.5
	netbsd-1-0-PATCH0:1.5
	netbsd-1-0-RELEASE:1.5
	netbsd-1-0:1.5.0.2
	nvi-1-34b:1.1.1.4
	nvi-1-33b:1.1.1.3
	netbsd-1-0-base:1.3
	nvi-1-11b:1.1.1.2
	nvi-1-03:1.1.1.1
	bostic-nvi:1.1.1;
locks; strict;
comment	@ * @;


1.10
date	2008.10.29.16.49.37;	author christos;	state dead;
branches;
next	1.9;

1.9
date	2005.02.12.12.53.23;	author aymeric;	state Exp;
branches;
next	1.8;

1.8
date	2002.04.09.01.47.33;	author thorpej;	state Exp;
branches
	1.8.4.1
	1.8.6.1;
next	1.7;

1.7
date	98.01.09.08.07.52;	author perry;	state Exp;
branches;
next	1.6;

1.6
date	96.05.20.03.47.39;	author mrg;	state Exp;
branches;
next	1.5;

1.5
date	94.08.17.20.12.37;	author cgd;	state Exp;
branches
	1.5.2.1;
next	1.4;

1.4
date	94.08.17.16.36.00;	author cgd;	state Exp;
branches;
next	1.3;

1.3
date	94.03.28.04.29.25;	author cgd;	state Exp;
branches;
next	1.2;

1.2
date	94.01.24.06.40.23;	author cgd;	state Exp;
branches;
next	1.1;

1.1
date	94.01.24.05.53.03;	author cgd;	state Exp;
branches
	1.1.1.1;
next	;

1.8.4.1
date	2005.02.12.12.24.13;	author aymeric;	state Exp;
branches;
next	1.8.4.2;

1.8.4.2
date	2005.02.12.12.46.26;	author aymeric;	state Exp;
branches;
next	;

1.8.6.1
date	2005.05.06.14.42.18;	author riz;	state Exp;
branches;
next	;

1.5.2.1
date	94.08.17.20.12.37;	author cgd;	state dead;
branches;
next	1.5.2.2;

1.5.2.2
date	94.08.17.20.12.38;	author cgd;	state Exp;
branches;
next	;

1.1.1.1
date	94.01.24.05.53.04;	author cgd;	state Exp;
branches;
next	1.1.1.2;

1.1.1.2
date	94.03.28.02.54.13;	author cgd;	state Exp;
branches;
next	1.1.1.3;

1.1.1.3
date	94.08.17.16.16.37;	author cgd;	state Exp;
branches;
next	1.1.1.4;

1.1.1.4
date	94.08.17.19.17.49;	author cgd;	state Exp;
branches;
next	1.1.1.5;

1.1.1.5
date	96.05.20.01.55.19;	author mrg;	state Exp;
branches;
next	;


desc
@@


1.10
log
@bye old vi!
@
text
@/*	$NetBSD: ex_map.c,v 1.9 2005/02/12 12:53:23 aymeric Exp $	*/

/*-
 * Copyright (c) 1992, 1993, 1994
 *	The Regents of the University of California.  All rights reserved.
 * Copyright (c) 1992, 1993, 1994, 1995, 1996
 *	Keith Bostic.  All rights reserved.
 *
 * See the LICENSE file for redistribution information.
 */

#include "config.h"

#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char sccsid[] = "@@(#)ex_map.c	10.9 (Berkeley) 3/6/96";
#else
__RCSID("$NetBSD: ex_map.c,v 1.9 2005/02/12 12:53:23 aymeric Exp $");
#endif
#endif /* not lint */

#include <sys/types.h>
#include <sys/queue.h>

#include <bitstring.h>
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "../common/common.h"

/*
 * ex_map -- :map[!] [input] [replacement]
 *	Map a key/string or display mapped keys.
 *
 * Historical note:
 *	Historic vi maps were fairly bizarre, and likely to differ in
 *	very subtle and strange ways from this implementation.  Two
 *	things worth noting are that vi would often hang or drop core
 *	if the map was strange enough (ex: map X "xy$@@x^V), or, simply
 *	not work.  One trick worth remembering is that if you put a
 *	mark at the start of the map, e.g. map X mx"xy ...), or if you
 *	put the map in a .exrc file, things would often work much better.
 *	No clue why.
 *
 * PUBLIC: int ex_map __P((SCR *, EXCMD *));
 */
int
ex_map(sp, cmdp)
	SCR *sp;
	EXCMD *cmdp;
{
	seq_t stype;
	CHAR_T *input, *p;

	stype = FL_ISSET(cmdp->iflags, E_C_FORCE) ? SEQ_INPUT : SEQ_COMMAND;

	switch (cmdp->argc) {
	case 0:
		if (seq_dump(sp, stype, 1) == 0)
			msgq(sp, M_INFO, stype == SEQ_INPUT ?
			    "132|No input map entries" :
			    "133|No command map entries");
		return (0);
	case 2:
		input = cmdp->argv[0]->bp;
		break;
	default:
		abort();
	}

	/*
	 * If the mapped string is #[0-9]* (and wasn't quoted) then store the
	 * function key mapping.  If the screen specific routine has been set,
	 * call it as well.  Note, the SEQ_FUNCMAP type is persistent across
	 * screen types, maybe the next screen type will get it right.
	 */
	if (input[0] == '#' && isdigit(input[1])) {
		for (p = input + 2; isdigit(*p); ++p);
		if (p[0] != '\0')
			goto nofunc;

		if (seq_set(sp, NULL, 0, input, cmdp->argv[0]->len,
		    cmdp->argv[1]->bp, cmdp->argv[1]->len, stype,
		    SEQ_FUNCMAP | SEQ_USERDEF))
			return (1);
		return (sp->gp->scr_fmap == NULL ? 0 :
		    sp->gp->scr_fmap(sp, stype, input, cmdp->argv[0]->len,
		    cmdp->argv[1]->bp, cmdp->argv[1]->len));
	}

	/* Some single keys may not be remapped in command mode. */
nofunc:	if (stype == SEQ_COMMAND && input[1] == '\0')
		switch (KEY_VAL(sp, input[0])) {
		case K_COLON:
		case K_ESCAPE:
		case K_NL:
			msgq(sp, M_ERR,
			    "134|The %s character may not be remapped",
			    KEY_NAME(sp, input[0]));
			return (1);
		}
	return (seq_set(sp, NULL, 0, input, cmdp->argv[0]->len,
	    cmdp->argv[1]->bp, cmdp->argv[1]->len, stype, SEQ_USERDEF));
}

/*
 * ex_unmap -- (:unmap[!] key)
 *	Unmap a key.
 *
 * PUBLIC: int ex_unmap __P((SCR *, EXCMD *));
 */
int
ex_unmap(sp, cmdp)
	SCR *sp;
	EXCMD *cmdp;
{
	if (seq_delete(sp, cmdp->argv[0]->bp, cmdp->argv[0]->len,
	    FL_ISSET(cmdp->iflags, E_C_FORCE) ? SEQ_INPUT : SEQ_COMMAND)) {
		msgq_str(sp, M_INFO,
		    cmdp->argv[0]->bp, "135|\"%s\" isn't currently mapped");
		return (1);
	}
	return (0);
}
@


1.9
log
@Fix the RCSID's to be $NetBSD$ instead of $NetBSD
@
text
@d1 1
a1 1
/*	$NetBSD: ex_map.c,v 1.8 2002/04/09 01:47:33 thorpej Exp $	*/
d19 1
a19 1
__RCSID("$NetBSD$");
@


1.8
log
@Use __RCSID() and __COPYRIGHT().
@
text
@d1 1
a1 1
/*	$NetBSD: ex_map.c,v 1.7 1998/01/09 08:07:52 perry Exp $	*/
d19 1
a19 1
__RCSID("$NetBSD");
@


1.8.6.1
log
@Pull up revision 1.9 (requested by aymeric in ticket #1195):
Fix the RCSID's to be $NetBSD$ instead of $NetBSD
@
text
@d1 1
a1 1
/*	$NetBSD: ex_map.c,v 1.8 2002/04/09 01:47:33 thorpej Exp $	*/
d19 1
a19 1
__RCSID("$NetBSD$");
@


1.8.4.1
log
@Fix the RCSID's to be $NetBSD$ instead of $NetBSD
@
text
@d1 1
a1 1
/*	$NetBSD: ex_map.c,v 1.8 2002/04/09 01:47:33 thorpej Exp $	*/
d19 1
a19 1
__RCSID("$NetBSD$");
@


1.8.4.2
log
@Backout previous. Sorry.
@
text
@d19 1
a19 1
__RCSID("$NetBSD");
@


1.7
log
@RCS Id Police.
@
text
@d1 1
a1 1
/*	$NetBSD$	*/
d14 1
d16 1
d18 3
@


1.6
log
@merge in nvi 1.66
@
text
@d1 2
@


1.5
log
@clean up import.
@
text
@d4 2
d7 1
a7 27
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the University of
 *	California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
d10 2
d13 1
a13 1
static char sccsid[] = "@@(#)ex_map.c	8.19 (Berkeley) 8/17/94";
a17 1
#include <sys/time.h>
a21 1
#include <signal.h>
a24 1
#include <termios.h>
d26 1
a26 7
#include "compat.h"
#include <curses.h>
#include <db.h>
#include <regex.h>

#include "vi.h"
#include "excmd.h"
d41 2
d45 1
a45 1
ex_map(sp, ep, cmdp)
d47 1
a47 2
	EXF *ep;
	EXCMDARG *cmdp;
d49 1
a49 1
	enum seqtype stype;
d52 1
a52 1
	stype = F_ISSET(cmdp, E_FORCE) ? SEQ_INPUT : SEQ_COMMAND;
d57 3
a59 2
			msgq(sp, M_INFO, "No %s map entries",
			    stype == SEQ_INPUT ? "input" : "command");
d69 4
a72 5
	 * If the mapped string is #[0-9]* (and wasn't quoted) then store
	 * the function key mapping, and call the screen specific routine.
	 * Note, if the screen specific routine is able to create the
	 * mapping, the SEQ_FUNCMAP type stays around, maybe the next screen
	 * type can get it right.
d74 2
a75 2
	if (input[0] == '#') {
		for (p = input + 1; isdigit(*p); ++p);
d80 2
a81 1
		    cmdp->argv[1]->bp, cmdp->argv[1]->len, stype, SEQ_FUNCMAP))
d83 2
a84 1
		return (sp->s_fmap(sp, stype, input, cmdp->argv[0]->len,
d94 2
a95 1
			msgq(sp, M_ERR, "The %s character may not be remapped",
d106 2
d110 1
a110 1
ex_unmap(sp, ep, cmdp)
d112 1
a112 2
	EXF *ep;
	EXCMDARG *cmdp;
d115 3
a117 2
	    F_ISSET(cmdp, E_FORCE) ? SEQ_INPUT : SEQ_COMMAND)) {
		msgq(sp, M_INFO, "\"%s\" isn't mapped", cmdp->argv[0]->bp);
a120 14
}

/*
 * map_save --
 *	Save the mapped sequences to a file.
 */
int
map_save(sp, fp)
	SCR *sp;
	FILE *fp;
{
	if (seq_save(sp, fp, "map ", SEQ_COMMAND))
		return (1);
	return (seq_save(sp, fp, "map! ", SEQ_INPUT));
@


1.5.2.1
log
@file ex_map.c was added on branch netbsd-1-0 on 1994-08-17 20:12:38 +0000
@
text
@d1 160
@


1.5.2.2
log
@clean up import.
@
text
@a0 160
/*-
 * Copyright (c) 1992, 1993, 1994
 *	The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the University of
 *	California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef lint
static char sccsid[] = "@@(#)ex_map.c	8.19 (Berkeley) 8/17/94";
#endif /* not lint */

#include <sys/types.h>
#include <sys/queue.h>
#include <sys/time.h>

#include <bitstring.h>
#include <ctype.h>
#include <limits.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>

#include "compat.h"
#include <curses.h>
#include <db.h>
#include <regex.h>

#include "vi.h"
#include "excmd.h"

/*
 * ex_map -- :map[!] [input] [replacement]
 *	Map a key/string or display mapped keys.
 *
 * Historical note:
 *	Historic vi maps were fairly bizarre, and likely to differ in
 *	very subtle and strange ways from this implementation.  Two
 *	things worth noting are that vi would often hang or drop core
 *	if the map was strange enough (ex: map X "xy$@@x^V), or, simply
 *	not work.  One trick worth remembering is that if you put a
 *	mark at the start of the map, e.g. map X mx"xy ...), or if you
 *	put the map in a .exrc file, things would often work much better.
 *	No clue why.
 */
int
ex_map(sp, ep, cmdp)
	SCR *sp;
	EXF *ep;
	EXCMDARG *cmdp;
{
	enum seqtype stype;
	CHAR_T *input, *p;

	stype = F_ISSET(cmdp, E_FORCE) ? SEQ_INPUT : SEQ_COMMAND;

	switch (cmdp->argc) {
	case 0:
		if (seq_dump(sp, stype, 1) == 0)
			msgq(sp, M_INFO, "No %s map entries",
			    stype == SEQ_INPUT ? "input" : "command");
		return (0);
	case 2:
		input = cmdp->argv[0]->bp;
		break;
	default:
		abort();
	}

	/*
	 * If the mapped string is #[0-9]* (and wasn't quoted) then store
	 * the function key mapping, and call the screen specific routine.
	 * Note, if the screen specific routine is able to create the
	 * mapping, the SEQ_FUNCMAP type stays around, maybe the next screen
	 * type can get it right.
	 */
	if (input[0] == '#') {
		for (p = input + 1; isdigit(*p); ++p);
		if (p[0] != '\0')
			goto nofunc;

		if (seq_set(sp, NULL, 0, input, cmdp->argv[0]->len,
		    cmdp->argv[1]->bp, cmdp->argv[1]->len, stype, SEQ_FUNCMAP))
			return (1);
		return (sp->s_fmap(sp, stype, input, cmdp->argv[0]->len,
		    cmdp->argv[1]->bp, cmdp->argv[1]->len));
	}

	/* Some single keys may not be remapped in command mode. */
nofunc:	if (stype == SEQ_COMMAND && input[1] == '\0')
		switch (KEY_VAL(sp, input[0])) {
		case K_COLON:
		case K_ESCAPE:
		case K_NL:
			msgq(sp, M_ERR, "The %s character may not be remapped",
			    KEY_NAME(sp, input[0]));
			return (1);
		}
	return (seq_set(sp, NULL, 0, input, cmdp->argv[0]->len,
	    cmdp->argv[1]->bp, cmdp->argv[1]->len, stype, SEQ_USERDEF));
}

/*
 * ex_unmap -- (:unmap[!] key)
 *	Unmap a key.
 */
int
ex_unmap(sp, ep, cmdp)
	SCR *sp;
	EXF *ep;
	EXCMDARG *cmdp;
{
	if (seq_delete(sp, cmdp->argv[0]->bp, cmdp->argv[0]->len,
	    F_ISSET(cmdp, E_FORCE) ? SEQ_INPUT : SEQ_COMMAND)) {
		msgq(sp, M_INFO, "\"%s\" isn't mapped", cmdp->argv[0]->bp);
		return (1);
	}
	return (0);
}

/*
 * map_save --
 *	Save the mapped sequences to a file.
 */
int
map_save(sp, fp)
	SCR *sp;
	FILE *fp;
{
	if (seq_save(sp, fp, "map ", SEQ_COMMAND))
		return (1);
	return (seq_save(sp, fp, "map! ", SEQ_INPUT));
}
@


1.4
log
@clean up import.  still have to hack some things.
@
text
@d35 1
a35 1
static const char sccsid[] = "@@(#)ex_map.c	8.18 (Berkeley) 8/17/94";
@


1.3
log
@nvi 1.11(beta) from bostic.  reconcile conflicts/kill rcsids.
@
text
@d35 1
a35 1
static char sccsid[] = "@@(#)ex_map.c	8.8 (Berkeley) 3/8/94";
d52 1
a56 1
#include "seq.h"
d80 1
a80 4
	CHAR_T *input;
	size_t nlen;
	int key;
	char *name, buf[10];
d87 1
a87 1
			msgq(sp, M_INFO, "No %s map entries.",
d98 5
a102 2
	 * If the mapped string is #[0-9] (and wasn't quoted in any
	 * way, then map to a function key.
d104 20
a123 10
	nlen = 0;
	if (input[0] == '#' && isdigit(input[1]) && !input[2]) {
		key = atoi(input + 1);
		nlen = snprintf(buf, sizeof(buf), "f%d", key);
#ifdef notdef
		if (FKEY[key]) {		/* CCC */
			input = FKEY[key];
			name = buf;
		} else {
			msgq(sp, M_ERR, "This terminal has no %s key.", buf);
d126 2
a127 21
#else
		name = NULL;
#endif
	} else {
		name = NULL;

		/* Some single keys may not be remapped in command mode. */
		if (stype == SEQ_COMMAND && input[1] == '\0')
			switch (term_key_val(sp, input[0])) {
			case K_COLON:
			case K_CR:
			case K_ESCAPE:
			case K_NL:
				msgq(sp, M_ERR,
				    "The %s character may not be remapped.",
				    charname(sp, input[0]));
				return (1);
			}
	}
	return (seq_set(sp, name, nlen, input, cmdp->argv[0]->len,
	    cmdp->argv[1]->bp, cmdp->argv[1]->len, stype, S_USERDEF));
d142 1
a142 1
		msgq(sp, M_INFO, "\"%s\" isn't mapped.", cmdp->argv[0]->bp);
@


1.2
log
@more Ids than you'll ever want.
@
text
@d2 1
a2 1
 * Copyright (c) 1992, 1993
d35 1
a35 2
/* from: static char sccsid[] = "@@(#)ex_map.c	8.6 (Berkeley) 12/2/93"; */
static char *rcsid = "$Id$";
d39 2
d42 1
d44 3
d49 5
d136 1
a136 1
	    cmdp->argv[1]->bp, cmdp->argv[1]->len, stype, 1));
@


1.1
log
@Initial revision
@
text
@d35 2
a36 1
static char sccsid[] = "@@(#)ex_map.c	8.6 (Berkeley) 12/2/93";
@


1.1.1.1
log
@nvi 1.03, from ftp.cs.berkeley.edu, per keith bostic's permission.
@
text
@@


1.1.1.2
log
@nvi/nex 1.11beta from bostic.
@
text
@d2 1
a2 1
 * Copyright (c) 1992, 1993, 1994
d35 1
a35 1
static char sccsid[] = "@@(#)ex_map.c	8.8 (Berkeley) 3/8/94";
a38 2
#include <sys/queue.h>
#include <sys/time.h>
a39 1
#include <bitstring.h>
a40 3
#include <limits.h>
#include <signal.h>
#include <stdio.h>
a42 5
#include <termios.h>

#include "compat.h"
#include <db.h>
#include <regex.h>
d125 1
a125 1
	    cmdp->argv[1]->bp, cmdp->argv[1]->len, stype, S_USERDEF));
@


1.1.1.3
log
@new public version of nvi
@
text
@d35 1
a35 1
static const char sccsid[] = "@@(#)ex_map.c	8.18 (Berkeley) 8/17/94";
a51 1
#include <curses.h>
d56 1
d80 4
a83 1
	CHAR_T *input, *p;
d90 1
a90 1
			msgq(sp, M_INFO, "No %s map entries",
d101 2
a102 5
	 * If the mapped string is #[0-9]* (and wasn't quoted) then store
	 * the function key mapping, and call the screen specific routine.
	 * Note, if the screen specific routine is able to create the
	 * mapping, the SEQ_FUNCMAP type stays around, maybe the next screen
	 * type can get it right.
d104 10
a113 7
	if (input[0] == '#') {
		for (p = input + 1; isdigit(*p); ++p);
		if (p[0] != '\0')
			goto nofunc;

		if (seq_set(sp, NULL, 0, input, cmdp->argv[0]->len,
		    cmdp->argv[1]->bp, cmdp->argv[1]->len, stype, SEQ_FUNCMAP))
d115 19
a133 2
		return (sp->s_fmap(sp, stype, input, cmdp->argv[0]->len,
		    cmdp->argv[1]->bp, cmdp->argv[1]->len));
d135 2
a136 13

	/* Some single keys may not be remapped in command mode. */
nofunc:	if (stype == SEQ_COMMAND && input[1] == '\0')
		switch (KEY_VAL(sp, input[0])) {
		case K_COLON:
		case K_ESCAPE:
		case K_NL:
			msgq(sp, M_ERR, "The %s character may not be remapped",
			    KEY_NAME(sp, input[0]));
			return (1);
		}
	return (seq_set(sp, NULL, 0, input, cmdp->argv[0]->len,
	    cmdp->argv[1]->bp, cmdp->argv[1]->len, stype, SEQ_USERDEF));
d151 1
a151 1
		msgq(sp, M_INFO, "\"%s\" isn't mapped", cmdp->argv[0]->bp);
@


1.1.1.4
log
@new public version of nvi
@
text
@d35 1
a35 1
static char sccsid[] = "@@(#)ex_map.c	8.19 (Berkeley) 8/17/94";
@


1.1.1.5
log
@import of nvi 1.66
@
text
@a3 2
 * Copyright (c) 1992, 1993, 1994, 1995, 1996
 *	Keith Bostic.  All rights reserved.
d5 27
a31 1
 * See the LICENSE file for redistribution information.
a33 2
#include "config.h"

d35 1
a35 1
static const char sccsid[] = "@@(#)ex_map.c	10.9 (Berkeley) 3/6/96";
d40 1
d45 1
d49 1
d51 7
a57 1
#include "../common/common.h"
a71 2
 *
 * PUBLIC: int ex_map __P((SCR *, EXCMD *));
d74 1
a74 1
ex_map(sp, cmdp)
d76 2
a77 1
	EXCMD *cmdp;
d79 1
a79 1
	seq_t stype;
d82 1
a82 1
	stype = FL_ISSET(cmdp->iflags, E_C_FORCE) ? SEQ_INPUT : SEQ_COMMAND;
d87 2
a88 3
			msgq(sp, M_INFO, stype == SEQ_INPUT ?
			    "132|No input map entries" :
			    "133|No command map entries");
d98 5
a102 4
	 * If the mapped string is #[0-9]* (and wasn't quoted) then store the
	 * function key mapping.  If the screen specific routine has been set,
	 * call it as well.  Note, the SEQ_FUNCMAP type is persistent across
	 * screen types, maybe the next screen type will get it right.
d104 2
a105 2
	if (input[0] == '#' && isdigit(input[1])) {
		for (p = input + 2; isdigit(*p); ++p);
d110 1
a110 2
		    cmdp->argv[1]->bp, cmdp->argv[1]->len, stype,
		    SEQ_FUNCMAP | SEQ_USERDEF))
d112 1
a112 2
		return (sp->gp->scr_fmap == NULL ? 0 :
		    sp->gp->scr_fmap(sp, stype, input, cmdp->argv[0]->len,
d122 1
a122 2
			msgq(sp, M_ERR,
			    "134|The %s character may not be remapped",
a132 2
 *
 * PUBLIC: int ex_unmap __P((SCR *, EXCMD *));
d135 1
a135 1
ex_unmap(sp, cmdp)
d137 2
a138 1
	EXCMD *cmdp;
d141 2
a142 3
	    FL_ISSET(cmdp->iflags, E_C_FORCE) ? SEQ_INPUT : SEQ_COMMAND)) {
		msgq_str(sp, M_INFO,
		    cmdp->argv[0]->bp, "135|\"%s\" isn't currently mapped");
d146 14
@
