xref: /minix3/external/bsd/nvi/dist/ex/ex_perl.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: ex_perl.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */
284d9c625SLionel Sambuc /*-
384d9c625SLionel Sambuc  * Copyright (c) 1992, 1993, 1994
484d9c625SLionel Sambuc  *	The Regents of the University of California.  All rights reserved.
584d9c625SLionel Sambuc  * Copyright (c) 1992, 1993, 1994, 1995, 1996
684d9c625SLionel Sambuc  *	Keith Bostic.  All rights reserved.
784d9c625SLionel Sambuc  * Copyright (c) 1995
884d9c625SLionel Sambuc  *	George V. Neville-Neil. All rights reserved.
984d9c625SLionel Sambuc  * Copyright (c) 1996
1084d9c625SLionel Sambuc  *	Sven Verdoolaege. All rights reserved.
1184d9c625SLionel Sambuc  *
1284d9c625SLionel Sambuc  * See the LICENSE file for redistribution information.
1384d9c625SLionel Sambuc  */
1484d9c625SLionel Sambuc 
1584d9c625SLionel Sambuc #include "config.h"
1684d9c625SLionel Sambuc 
17*0a6a1f1dSLionel Sambuc #include <sys/cdefs.h>
18*0a6a1f1dSLionel Sambuc #if 0
1984d9c625SLionel Sambuc #ifndef lint
2084d9c625SLionel Sambuc 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 ";
2184d9c625SLionel Sambuc #endif /* not lint */
22*0a6a1f1dSLionel Sambuc #else
23*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: ex_perl.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
24*0a6a1f1dSLionel Sambuc #endif
2584d9c625SLionel Sambuc 
2684d9c625SLionel Sambuc #include <sys/types.h>
2784d9c625SLionel Sambuc #include <sys/queue.h>
2884d9c625SLionel Sambuc #include <sys/time.h>
2984d9c625SLionel Sambuc 
3084d9c625SLionel Sambuc #include <bitstring.h>
3184d9c625SLionel Sambuc #include <ctype.h>
3284d9c625SLionel Sambuc #include <limits.h>
3384d9c625SLionel Sambuc #include <stdio.h>
3484d9c625SLionel Sambuc #include <string.h>
3584d9c625SLionel Sambuc #include <termios.h>
3684d9c625SLionel Sambuc #include <unistd.h>
3784d9c625SLionel Sambuc 
3884d9c625SLionel Sambuc #include "../common/common.h"
3984d9c625SLionel Sambuc 
4084d9c625SLionel Sambuc /*
4184d9c625SLionel Sambuc  * ex_perl -- :[line [,line]] perl [command]
4284d9c625SLionel Sambuc  *	Run a command through the perl interpreter.
4384d9c625SLionel Sambuc  *
4484d9c625SLionel Sambuc  * ex_perldo -- :[line [,line]] perldo [command]
4584d9c625SLionel Sambuc  *	Run a set of lines through the perl interpreter.
4684d9c625SLionel Sambuc  *
4784d9c625SLionel Sambuc  * PUBLIC: int ex_perl __P((SCR*, EXCMD *));
4884d9c625SLionel Sambuc  */
4984d9c625SLionel Sambuc int
ex_perl(SCR * sp,EXCMD * cmdp)5084d9c625SLionel Sambuc ex_perl(SCR *sp, EXCMD *cmdp)
5184d9c625SLionel Sambuc {
5284d9c625SLionel Sambuc #ifdef HAVE_PERL_INTERP
5384d9c625SLionel Sambuc 	CHAR_T *p;
5484d9c625SLionel Sambuc 	size_t len;
5584d9c625SLionel Sambuc 
5684d9c625SLionel Sambuc 	/* Skip leading white space. */
5784d9c625SLionel Sambuc 	if (cmdp->argc != 0)
5884d9c625SLionel Sambuc 		for (p = cmdp->argv[0]->bp,
5984d9c625SLionel Sambuc 		    len = cmdp->argv[0]->len; len > 0; --len, ++p)
6084d9c625SLionel Sambuc 			if (!ISBLANK((UCHAR_T)*p))
6184d9c625SLionel Sambuc 				break;
6284d9c625SLionel Sambuc 	if (cmdp->argc == 0 || len == 0) {
6384d9c625SLionel Sambuc 		ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
6484d9c625SLionel Sambuc 		return (1);
6584d9c625SLionel Sambuc 	}
6684d9c625SLionel Sambuc 	return (cmdp->cmd == &cmds[C_PERLCMD] ?
6784d9c625SLionel Sambuc 	    perl_ex_perl(sp, p, len, cmdp->addr1.lno, cmdp->addr2.lno) :
6884d9c625SLionel Sambuc 	    perl_ex_perldo(sp, p, len, cmdp->addr1.lno, cmdp->addr2.lno));
6984d9c625SLionel Sambuc #else
7084d9c625SLionel Sambuc 	msgq(sp, M_ERR, "306|Vi was not loaded with a Perl interpreter");
7184d9c625SLionel Sambuc 	return (1);
7284d9c625SLionel Sambuc #endif
7384d9c625SLionel Sambuc }
74