tools/llvm: Do not build with symbols
[minix3.git] / external / bsd / nvi / dist / ex / ex_tcl.c
blob47f3e345aa43cbf664a05bb00133761c5a8e9360
1 /* $NetBSD: ex_tcl.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.
7 * Copyright (c) 1995
8 * George V. Neville-Neil. All rights reserved.
10 * See the LICENSE file for redistribution information.
13 #include "config.h"
15 #ifndef lint
16 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 ";
17 #endif /* not lint */
19 #include <sys/types.h>
20 #include <sys/queue.h>
22 #include <bitstring.h>
23 #include <limits.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <termios.h>
27 #include <unistd.h>
29 #include "../common/common.h"
31 #ifdef HAVE_TCL_INTERP
32 #include <tcl.h>
33 #endif
35 /*
36 * ex_tcl -- :[line [,line]] tcl [command]
37 * Run a command through the tcl interpreter.
39 * PUBLIC: int ex_tcl __P((SCR*, EXCMD *));
41 int
42 ex_tcl(SCR *sp, EXCMD *cmdp)
44 #ifdef HAVE_TCL_INTERP
45 CHAR_T *p;
46 GS *gp;
47 size_t len;
48 char buf[128];
50 /* Initialize the interpreter. */
51 gp = sp->gp;
52 if (gp->tcl_interp == NULL && tcl_init(gp))
53 return (1);
55 /* Skip leading white space. */
56 if (cmdp->argc != 0)
57 for (p = cmdp->argv[0]->bp,
58 len = cmdp->argv[0]->len; len > 0; --len, ++p)
59 if (!ISBLANK((UCHAR_T)*p))
60 break;
61 if (cmdp->argc == 0 || len == 0) {
62 ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
63 return (1);
66 (void)snprintf(buf, sizeof(buf),
67 "set viScreenId %d\nset viStartLine %lu\nset viStopLine %lu",
68 sp->id, cmdp->addr1.lno, cmdp->addr2.lno);
69 if (Tcl_Eval(gp->tcl_interp, buf) == TCL_OK &&
70 Tcl_Eval(gp->tcl_interp, cmdp->argv[0]->bp) == TCL_OK)
71 return (0);
73 msgq(sp, M_ERR, "Tcl: %s", ((Tcl_Interp *)gp->tcl_interp)->result);
74 return (1);
75 #else
76 msgq(sp, M_ERR, "302|Vi was not loaded with a Tcl interpreter");
77 return (1);
78 #endif /* HAVE_TCL_INTERP */