distrib: run libtoolize
[nvi.git] / ex / ex_tcl.c
bloba022a80b1092de186e9d58de97d646d2a12bd831
1 /*-
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1992, 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
6 * Copyright (c) 1995
7 * George V. Neville-Neil. All rights reserved.
9 * See the LICENSE file for redistribution information.
12 #include "config.h"
14 #ifndef lint
15 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 $";
16 #endif /* not lint */
18 #include <sys/types.h>
19 #include <sys/queue.h>
21 #include <bitstring.h>
22 #include <limits.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <termios.h>
26 #include <unistd.h>
28 #include "../common/common.h"
30 #ifdef HAVE_TCL_INTERP
31 #include <tcl.h>
32 #endif
34 /*
35 * ex_tcl -- :[line [,line]] tcl [command]
36 * Run a command through the tcl interpreter.
38 * PUBLIC: int ex_tcl __P((SCR*, EXCMD *));
40 int
41 ex_tcl(SCR *sp, EXCMD *cmdp)
43 #ifdef HAVE_TCL_INTERP
44 CHAR_T *p;
45 GS *gp;
46 size_t len;
47 char buf[128];
49 /* Initialize the interpreter. */
50 gp = sp->gp;
51 if (gp->tcl_interp == NULL && tcl_init(gp))
52 return (1);
54 /* Skip leading white space. */
55 if (cmdp->argc != 0)
56 for (p = cmdp->argv[0]->bp,
57 len = cmdp->argv[0]->len; len > 0; --len, ++p)
58 if (!isblank(*p))
59 break;
60 if (cmdp->argc == 0 || len == 0) {
61 ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
62 return (1);
65 (void)snprintf(buf, sizeof(buf),
66 "set viScreenId %d\nset viStartLine %lu\nset viStopLine %lu",
67 sp->id, cmdp->addr1.lno, cmdp->addr2.lno);
68 if (Tcl_Eval(gp->tcl_interp, buf) == TCL_OK &&
69 Tcl_Eval(gp->tcl_interp, cmdp->argv[0]->bp) == TCL_OK)
70 return (0);
72 msgq(sp, M_ERR, "Tcl: %s", ((Tcl_Interp *)gp->tcl_interp)->result);
73 return (1);
74 #else
75 msgq(sp, M_ERR, "302|Vi was not loaded with a Tcl interpreter");
76 return (1);
77 #endif /* HAVE_TCL_INTERP */