2002-04-09 05:47:30 +04:00
|
|
|
/* $NetBSD: ex_abbrev.c,v 1.8 2002/04/09 01:47:32 thorpej Exp $ */
|
1998-01-09 11:03:16 +03:00
|
|
|
|
1994-01-24 08:52:58 +03:00
|
|
|
/*-
|
1994-03-28 08:28:20 +04:00
|
|
|
* Copyright (c) 1992, 1993, 1994
|
1994-01-24 08:52:58 +03:00
|
|
|
* The Regents of the University of California. All rights reserved.
|
1996-05-20 07:47:00 +04:00
|
|
|
* Copyright (c) 1992, 1993, 1994, 1995, 1996
|
|
|
|
* Keith Bostic. All rights reserved.
|
1994-01-24 08:52:58 +03:00
|
|
|
*
|
1996-05-20 07:47:00 +04:00
|
|
|
* See the LICENSE file for redistribution information.
|
1994-01-24 08:52:58 +03:00
|
|
|
*/
|
|
|
|
|
1996-05-20 07:47:00 +04:00
|
|
|
#include "config.h"
|
|
|
|
|
2002-04-09 05:47:30 +04:00
|
|
|
#include <sys/cdefs.h>
|
1994-01-24 08:52:58 +03:00
|
|
|
#ifndef lint
|
2002-04-09 05:47:30 +04:00
|
|
|
#if 0
|
1996-05-20 07:47:00 +04:00
|
|
|
static const char sccsid[] = "@(#)ex_abbrev.c 10.7 (Berkeley) 3/6/96";
|
2002-04-09 05:47:30 +04:00
|
|
|
#else
|
|
|
|
__RCSID("$NetBSD");
|
|
|
|
#endif
|
1994-01-24 08:52:58 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
1994-03-28 08:28:20 +04:00
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/time.h>
|
1994-01-24 08:52:58 +03:00
|
|
|
|
1994-03-28 08:28:20 +04:00
|
|
|
#include <bitstring.h>
|
1994-01-24 08:52:58 +03:00
|
|
|
#include <ctype.h>
|
1994-03-28 08:28:20 +04:00
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
1996-05-20 07:47:00 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1994-03-28 08:28:20 +04:00
|
|
|
|
1996-05-20 07:47:00 +04:00
|
|
|
#include "../common/common.h"
|
|
|
|
#include "../vi/vi.h"
|
1994-01-24 08:52:58 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ex_abbr -- :abbreviate [key replacement]
|
|
|
|
* Create an abbreviation or display abbreviations.
|
1996-05-20 07:47:00 +04:00
|
|
|
*
|
|
|
|
* PUBLIC: int ex_abbr __P((SCR *, EXCMD *));
|
1994-01-24 08:52:58 +03:00
|
|
|
*/
|
|
|
|
int
|
1996-05-20 07:47:00 +04:00
|
|
|
ex_abbr(sp, cmdp)
|
1994-01-24 08:52:58 +03:00
|
|
|
SCR *sp;
|
1996-05-20 07:47:00 +04:00
|
|
|
EXCMD *cmdp;
|
1994-01-24 08:52:58 +03:00
|
|
|
{
|
1994-08-17 20:35:35 +04:00
|
|
|
CHAR_T *p;
|
|
|
|
size_t len;
|
|
|
|
|
1994-01-24 08:52:58 +03:00
|
|
|
switch (cmdp->argc) {
|
|
|
|
case 0:
|
|
|
|
if (seq_dump(sp, SEQ_ABBREV, 0) == 0)
|
1996-05-20 07:47:00 +04:00
|
|
|
msgq(sp, M_INFO, "105|No abbreviations to display");
|
1994-01-24 08:52:58 +03:00
|
|
|
return (0);
|
|
|
|
case 2:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
1996-05-20 07:47:00 +04:00
|
|
|
/*
|
|
|
|
* Check for illegal characters.
|
|
|
|
*
|
|
|
|
* !!!
|
|
|
|
* Another fun one, historically. See vi/v_ntext.c:txt_abbrev() for
|
|
|
|
* details. The bottom line is that all abbreviations have to end
|
|
|
|
* with a "word" character, because it's the transition from word to
|
|
|
|
* non-word characters that triggers the test for an abbreviation. In
|
|
|
|
* addition, because of the way the test is done, there can't be any
|
|
|
|
* transitions from word to non-word character (or vice-versa) other
|
|
|
|
* than between the next-to-last and last characters of the string,
|
|
|
|
* and there can't be any <blank> characters. Warn the user.
|
|
|
|
*/
|
|
|
|
if (!inword(cmdp->argv[0]->bp[cmdp->argv[0]->len - 1])) {
|
|
|
|
msgq(sp, M_ERR,
|
|
|
|
"106|Abbreviations must end with a \"word\" character");
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
for (p = cmdp->argv[0]->bp; *p != '\0'; ++p)
|
|
|
|
if (isblank(p[0])) {
|
1994-08-17 20:35:35 +04:00
|
|
|
msgq(sp, M_ERR,
|
1996-05-20 07:47:00 +04:00
|
|
|
"107|Abbreviations may not contain tabs or spaces");
|
1994-08-17 20:35:35 +04:00
|
|
|
return (1);
|
|
|
|
}
|
1996-05-20 07:47:00 +04:00
|
|
|
if (cmdp->argv[0]->len > 2)
|
|
|
|
for (p = cmdp->argv[0]->bp,
|
|
|
|
len = cmdp->argv[0]->len - 2; len; --len, ++p)
|
|
|
|
if (inword(p[0]) != inword(p[1])) {
|
|
|
|
msgq(sp, M_ERR,
|
|
|
|
"108|Abbreviations may not mix word/non-word characters, except at the end");
|
|
|
|
return (1);
|
|
|
|
}
|
1994-08-17 20:35:35 +04:00
|
|
|
|
1994-01-24 08:52:58 +03:00
|
|
|
if (seq_set(sp, NULL, 0, cmdp->argv[0]->bp, cmdp->argv[0]->len,
|
1994-08-17 20:35:35 +04:00
|
|
|
cmdp->argv[1]->bp, cmdp->argv[1]->len, SEQ_ABBREV, SEQ_USERDEF))
|
1994-01-24 08:52:58 +03:00
|
|
|
return (1);
|
1994-08-17 20:35:35 +04:00
|
|
|
|
1994-01-24 08:52:58 +03:00
|
|
|
F_SET(sp->gp, G_ABBREV);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ex_unabbr -- :unabbreviate key
|
|
|
|
* Delete an abbreviation.
|
1996-05-20 07:47:00 +04:00
|
|
|
*
|
|
|
|
* PUBLIC: int ex_unabbr __P((SCR *, EXCMD *));
|
1994-01-24 08:52:58 +03:00
|
|
|
*/
|
|
|
|
int
|
1996-05-20 07:47:00 +04:00
|
|
|
ex_unabbr(sp, cmdp)
|
1994-01-24 08:52:58 +03:00
|
|
|
SCR *sp;
|
1996-05-20 07:47:00 +04:00
|
|
|
EXCMD *cmdp;
|
1994-01-24 08:52:58 +03:00
|
|
|
{
|
|
|
|
ARGS *ap;
|
|
|
|
|
|
|
|
ap = cmdp->argv[0];
|
|
|
|
if (!F_ISSET(sp->gp, G_ABBREV) ||
|
|
|
|
seq_delete(sp, ap->bp, ap->len, SEQ_ABBREV)) {
|
1996-05-20 07:47:00 +04:00
|
|
|
msgq_str(sp, M_ERR, ap->bp,
|
|
|
|
"109|\"%s\" is not an abbreviation");
|
1994-01-24 08:52:58 +03:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|