Explicitly request literal mode after .Xr.
[netbsd-mini2440.git] / dist / nvi / ex / ex_tcl.c
blob97ff581e4abbf77c17f3cd7a869543619bcaab0d
1 /* $NetBSD$ */
3 /*-
4 * Copyright (c) 1992, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (c) 1992, 1993, 1994, 1995, 1996
7 * Keith Bostic. All rights reserved.
8 * Copyright (c) 1995
9 * George V. Neville-Neil. All rights reserved.
11 * See the LICENSE file for redistribution information.
14 #include "config.h"
16 #ifndef lint
17 static const char sccsid[] = "Id: ex_tcl.c,v 8.11 2001/06/25 15:19:21 skimo Exp (Berkeley) Date: 2001/06/25 15:19:21";
18 #endif /* not lint */
20 #include <sys/types.h>
21 #include <sys/queue.h>
23 #include <bitstring.h>
24 #include <limits.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <termios.h>
28 #include <unistd.h>
30 #include "../common/common.h"
32 #ifdef HAVE_TCL_INTERP
33 #include <tcl.h>
34 #endif
36 /*
37 * ex_tcl -- :[line [,line]] tcl [command]
38 * Run a command through the tcl interpreter.
40 * PUBLIC: int ex_tcl __P((SCR*, EXCMD *));
42 int
43 ex_tcl(SCR *sp, EXCMD *cmdp)
45 #ifdef HAVE_TCL_INTERP
46 CHAR_T *p;
47 GS *gp;
48 size_t len;
49 char buf[128];
51 /* Initialize the interpreter. */
52 gp = sp->gp;
53 if (gp->tcl_interp == NULL && tcl_init(gp))
54 return (1);
56 /* Skip leading white space. */
57 if (cmdp->argc != 0)
58 for (p = cmdp->argv[0]->bp,
59 len = cmdp->argv[0]->len; len > 0; --len, ++p)
60 if (!isblank(*p))
61 break;
62 if (cmdp->argc == 0 || len == 0) {
63 ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
64 return (1);
67 (void)snprintf(buf, sizeof(buf),
68 "set viScreenId %d\nset viStartLine %lu\nset viStopLine %lu",
69 sp->id, cmdp->addr1.lno, cmdp->addr2.lno);
70 if (Tcl_Eval(gp->tcl_interp, buf) == TCL_OK &&
71 Tcl_Eval(gp->tcl_interp, cmdp->argv[0]->bp) == TCL_OK)
72 return (0);
74 msgq(sp, M_ERR, "Tcl: %s", ((Tcl_Interp *)gp->tcl_interp)->result);
75 return (1);
76 #else
77 msgq(sp, M_ERR, "302|Vi was not loaded with a Tcl interpreter");
78 return (1);
79 #endif /* HAVE_TCL_INTERP */