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