tools/llvm: Do not build with symbols
[minix3.git] / external / bsd / nvi / dist / ex / ex_abbrev.c
blobab629df07d5e9a45230ed7edebbeffcf2e792ac5
1 /* $NetBSD: ex_abbrev.c,v 1.2 2013/11/22 15:52:05 christos Exp $ */
2 /*-
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.
9 */
11 #include "config.h"
13 #ifndef lint
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 ";
15 #endif /* not lint */
17 #include <sys/types.h>
18 #include <sys/queue.h>
19 #include <sys/time.h>
21 #include <bitstring.h>
22 #include <ctype.h>
23 #include <limits.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
28 #include "../common/common.h"
29 #include "../vi/vi.h"
32 * ex_abbr -- :abbreviate [key replacement]
33 * Create an abbreviation or display abbreviations.
35 * PUBLIC: int ex_abbr __P((SCR *, EXCMD *));
37 int
38 ex_abbr(SCR *sp, EXCMD *cmdp)
40 CHAR_T *p;
41 size_t len;
43 switch (cmdp->argc) {
44 case 0:
45 if (seq_dump(sp, SEQ_ABBREV, 0) == 0)
46 msgq(sp, M_INFO, "105|No abbreviations to display");
47 return (0);
48 case 2:
49 break;
50 default:
51 abort();
55 * Check for illegal characters.
57 * !!!
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])) {
68 msgq(sp, M_ERR,
69 "106|Abbreviations must end with a \"word\" character");
70 return (1);
72 for (p = cmdp->argv[0]->bp; *p != '\0'; ++p)
73 if (ISBLANK((UCHAR_T)p[0])) {
74 msgq(sp, M_ERR,
75 "107|Abbreviations may not contain tabs or spaces");
76 return (1);
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])) {
82 msgq(sp, M_ERR,
83 "108|Abbreviations may not mix word/non-word characters, except at the end");
84 return (1);
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))
89 return (1);
91 F_SET(sp->gp, G_ABBREV);
92 return (0);
96 * ex_unabbr -- :unabbreviate key
97 * Delete an abbreviation.
99 * PUBLIC: int ex_unabbr __P((SCR *, EXCMD *));
102 ex_unabbr(SCR *sp, EXCMD *cmdp)
104 ARGS *ap;
106 ap = cmdp->argv[0];
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");
111 return (1);
113 return (0);