1 /* $NetBSD: ex_perl.c,v 1.3 2014/01/26 21:43:45 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 #include <sys/cdefs.h> 18 #if 0 19 #ifndef lint 20 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 "; 21 #endif /* not lint */ 22 #else 23 __RCSID("$NetBSD: ex_perl.c,v 1.3 2014/01/26 21:43:45 christos Exp $"); 24 #endif 25 26 #include <sys/types.h> 27 #include <sys/queue.h> 28 #include <sys/time.h> 29 30 #include <bitstring.h> 31 #include <ctype.h> 32 #include <limits.h> 33 #include <stdio.h> 34 #include <string.h> 35 #include <termios.h> 36 #include <unistd.h> 37 38 #include "../common/common.h" 39 40 /* 41 * ex_perl -- :[line [,line]] perl [command] 42 * Run a command through the perl interpreter. 43 * 44 * ex_perldo -- :[line [,line]] perldo [command] 45 * Run a set of lines through the perl interpreter. 46 * 47 * PUBLIC: int ex_perl __P((SCR*, EXCMD *)); 48 */ 49 int 50 ex_perl(SCR *sp, EXCMD *cmdp) 51 { 52 #ifdef HAVE_PERL_INTERP 53 CHAR_T *p; 54 size_t len; 55 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((UCHAR_T)*p)) 61 break; 62 if (cmdp->argc == 0 || len == 0) { 63 ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE); 64 return (1); 65 } 66 return (cmdp->cmd == &cmds[C_PERLCMD] ? 67 perl_ex_perl(sp, p, len, cmdp->addr1.lno, cmdp->addr2.lno) : 68 perl_ex_perldo(sp, p, len, cmdp->addr1.lno, cmdp->addr2.lno)); 69 #else 70 msgq(sp, M_ERR, "306|Vi was not loaded with a Perl interpreter"); 71 return (1); 72 #endif 73 } 74