1 /* $NetBSD: ex_perl.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. 9 * Copyright (c) 1996 10 * Sven Verdoolaege. All rights reserved. 11 * 12 * See the LICENSE file for redistribution information. 13 */ 14 15 #include "config.h" 16 17 #ifndef lint 18 static const char sccsid[] = "Id: ex_perl.c,v 8.11 2001/06/25 15:19:18 skimo Exp (Berkeley) Date: 2001/06/25 15:19:18 "; 19 #endif /* not lint */ 20 21 #include <sys/types.h> 22 #include <sys/queue.h> 23 #include <sys/time.h> 24 25 #include <bitstring.h> 26 #include <ctype.h> 27 #include <limits.h> 28 #include <stdio.h> 29 #include <string.h> 30 #include <termios.h> 31 #include <unistd.h> 32 33 #include "../common/common.h" 34 35 /* 36 * ex_perl -- :[line [,line]] perl [command] 37 * Run a command through the perl interpreter. 38 * 39 * ex_perldo -- :[line [,line]] perldo [command] 40 * Run a set of lines through the perl interpreter. 41 * 42 * PUBLIC: int ex_perl __P((SCR*, EXCMD *)); 43 */ 44 int 45 ex_perl(SCR *sp, EXCMD *cmdp) 46 { 47 #ifdef HAVE_PERL_INTERP 48 CHAR_T *p; 49 size_t len; 50 51 /* Skip leading white space. */ 52 if (cmdp->argc != 0) 53 for (p = cmdp->argv[0]->bp, 54 len = cmdp->argv[0]->len; len > 0; --len, ++p) 55 if (!ISBLANK((UCHAR_T)*p)) 56 break; 57 if (cmdp->argc == 0 || len == 0) { 58 ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE); 59 return (1); 60 } 61 return (cmdp->cmd == &cmds[C_PERLCMD] ? 62 perl_ex_perl(sp, p, len, cmdp->addr1.lno, cmdp->addr2.lno) : 63 perl_ex_perldo(sp, p, len, cmdp->addr1.lno, cmdp->addr2.lno)); 64 #else 65 msgq(sp, M_ERR, "306|Vi was not loaded with a Perl interpreter"); 66 return (1); 67 #endif 68 } 69