1 /* $NetBSD: ex_abbrev.c,v 1.2 2013/11/22 15:52:05 christos Exp $ */
3 * Copyright (c) 1992, 1993, 1994
4 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 1992, 1993, 1994, 1995, 1996
6 * Keith Bostic. All rights reserved.
8 * See the LICENSE file for redistribution information.
14 static const char sccsid
[] = "Id: ex_abbrev.c,v 10.10 2001/12/16 18:18:54 skimo Exp (Berkeley) Date: 2001/12/16 18:18:54 ";
17 #include <sys/types.h>
18 #include <sys/queue.h>
21 #include <bitstring.h>
28 #include "../common/common.h"
32 * ex_abbr -- :abbreviate [key replacement]
33 * Create an abbreviation or display abbreviations.
35 * PUBLIC: int ex_abbr __P((SCR *, EXCMD *));
38 ex_abbr(SCR
*sp
, EXCMD
*cmdp
)
45 if (seq_dump(sp
, SEQ_ABBREV
, 0) == 0)
46 msgq(sp
, M_INFO
, "105|No abbreviations to display");
55 * Check for illegal characters.
58 * Another fun one, historically. See vi/v_ntext.c:txt_abbrev() for
59 * details. The bottom line is that all abbreviations have to end
60 * with a "word" character, because it's the transition from word to
61 * non-word characters that triggers the test for an abbreviation. In
62 * addition, because of the way the test is done, there can't be any
63 * transitions from word to non-word character (or vice-versa) other
64 * than between the next-to-last and last characters of the string,
65 * and there can't be any <blank> characters. Warn the user.
67 if (!inword(cmdp
->argv
[0]->bp
[cmdp
->argv
[0]->len
- 1])) {
69 "106|Abbreviations must end with a \"word\" character");
72 for (p
= cmdp
->argv
[0]->bp
; *p
!= '\0'; ++p
)
73 if (ISBLANK((UCHAR_T
)p
[0])) {
75 "107|Abbreviations may not contain tabs or spaces");
78 if (cmdp
->argv
[0]->len
> 2)
79 for (p
= cmdp
->argv
[0]->bp
,
80 len
= cmdp
->argv
[0]->len
- 2; len
; --len
, ++p
)
81 if (inword(p
[0]) != inword(p
[1])) {
83 "108|Abbreviations may not mix word/non-word characters, except at the end");
87 if (seq_set(sp
, NULL
, 0, cmdp
->argv
[0]->bp
, cmdp
->argv
[0]->len
,
88 cmdp
->argv
[1]->bp
, cmdp
->argv
[1]->len
, SEQ_ABBREV
, SEQ_USERDEF
))
91 F_SET(sp
->gp
, G_ABBREV
);
96 * ex_unabbr -- :unabbreviate key
97 * Delete an abbreviation.
99 * PUBLIC: int ex_unabbr __P((SCR *, EXCMD *));
102 ex_unabbr(SCR
*sp
, EXCMD
*cmdp
)
107 if (!F_ISSET(sp
->gp
, G_ABBREV
) ||
108 seq_delete(sp
, ap
->bp
, ap
->len
, SEQ_ABBREV
)) {
109 msgq_wstr(sp
, M_ERR
, ap
->bp
,
110 "109|\"%s\" is not an abbreviation");