update to 1.01
[nvi.git] / ex / ex_abbrev.c
blob7184dc44c78713d86bf3f5665d81242c49e99bf7
1 /*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
6 */
8 #ifndef lint
9 static char sccsid[] = "$Id: ex_abbrev.c,v 8.6 1993/12/22 16:15:15 bostic Exp $ (Berkeley) $Date: 1993/12/22 16:15:15 $";
10 #endif /* not lint */
12 #include <sys/types.h>
14 #include <ctype.h>
16 #include "vi.h"
17 #include "seq.h"
18 #include "excmd.h"
21 * ex_abbr -- :abbreviate [key replacement]
22 * Create an abbreviation or display abbreviations.
24 int
25 ex_abbr(sp, ep, cmdp)
26 SCR *sp;
27 EXF *ep;
28 EXCMDARG *cmdp;
30 switch (cmdp->argc) {
31 case 0:
32 if (seq_dump(sp, SEQ_ABBREV, 0) == 0)
33 msgq(sp, M_INFO, "No abbreviations to display.");
34 return (0);
35 case 2:
36 break;
37 default:
38 abort();
41 if (seq_set(sp, NULL, 0, cmdp->argv[0]->bp, cmdp->argv[0]->len,
42 cmdp->argv[1]->bp, cmdp->argv[1]->len, SEQ_ABBREV, 1))
43 return (1);
44 F_SET(sp->gp, G_ABBREV);
45 return (0);
49 * ex_unabbr -- :unabbreviate key
50 * Delete an abbreviation.
52 int
53 ex_unabbr(sp, ep, cmdp)
54 SCR *sp;
55 EXF *ep;
56 EXCMDARG *cmdp;
58 ARGS *ap;
60 ap = cmdp->argv[0];
61 if (!F_ISSET(sp->gp, G_ABBREV) ||
62 seq_delete(sp, ap->bp, ap->len, SEQ_ABBREV)) {
63 msgq(sp, M_ERR, "\"%s\" is not an abbreviation.", ap->bp);
64 return (1);
66 return (0);
70 * abbr_save --
71 * Save the abbreviation sequences to a file.
73 int
74 abbr_save(sp, fp)
75 SCR *sp;
76 FILE *fp;
78 return (seq_save(sp, fp, "abbreviate ", SEQ_ABBREV));