2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1992, 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * George V. Neville-Neil. All rights reserved.
9 * Sven Verdoolaege. All rights reserved.
11 * See the LICENSE file for redistribution information.
17 static const char sccsid[] = "$Id: perl.xs,v 8.42 2001/07/29 18:35:44 skimo Exp $ (Berkeley) $Date: 2001/07/29 18:35:44 $";
20 #include <sys/types.h>
21 #include <sys/queue.h>
24 #include <bitstring.h>
38 /* perl redefines them
41 #undef USE_DYNAMIC_LOADING
49 #include "../common/common.h"
50 #include "../perl_api/extern.h"
53 #define DEFSV GvSV(defgv)
56 #define ERRSV GvSV(errgv)
64 static void msghandler __P((SCR *, mtype_t, char *, size_t));
66 static char *errmsg = 0;
68 typedef struct _perl_data {
69 PerlInterpreter* interp;
70 SV *svcurscr, *svstart, *svstop, *svid;
74 #define CHAR2INTP(sp,n,nlen,w,wlen) \
75 CHAR2INT5(sp,((perl_data_t *)sp->wp->perl_private)->cw,n,nlen,w,wlen)
79 * Macros to point messages at the Perl message handler.
81 #define INITMESSAGE(sp) \
82 scr_msg = sp->gp->scr_msg; \
83 sp->gp->scr_msg = msghandler;
84 #define ENDMESSAGE(sp) \
85 sp->gp->scr_msg = scr_msg; \
86 if (rval) croak(errmsg);
88 void xs_init __P((pTHXo));
92 * Clean up perl interpreter
94 * PUBLIC: int perl_end __P((GS *));
101 * Call perl_run and perl_destuct to call END blocks and DESTROY
104 if (gp->perl_interp) {
105 perl_run(gp->perl_interp);
106 perl_destruct(gp->perl_interp);
107 #if defined(DEBUG) || defined(PURIFY) || defined(LIBRARY)
108 perl_free(gp->perl_interp);
110 /* XXX rather make sure only one thread calls perl_end */
118 * We don't use mortal SVs because no one will clean up after us
126 SV* sv = newSVpv(string, 0);
128 /* G_KEEPERR to catch syntax error; better way ? */
130 perl_eval_sv(sv, G_DISCARD | G_NOARGS | G_KEEPERR);
136 * Create the perl commands used by nvi.
138 * PUBLIC: int perl_init __P((SCR *));
147 char *bootargs[] = { "VI", NULL };
153 static char *args[] = { "", "-e", "" };
155 char *file = __FILE__;
160 if (gp->perl_interp == NULL) {
161 gp->perl_interp = perl_alloc();
162 perl_construct(gp->perl_interp);
163 if (perl_parse(gp->perl_interp, xs_init, 3, args, 0)) {
164 perl_destruct(gp->perl_interp);
165 perl_free(gp->perl_interp);
166 gp->perl_interp = NULL;
172 perl_call_argv("VI::bootstrap", G_DISCARD, bootargs);
173 perl_eval("$SIG{__WARN__}='VI::Warn'");
175 av_unshift(av = GvAVn(PL_incgv), 1);
176 av_store(av, 0, newSVpv(_PATH_PERLSCRIPTS,
177 sizeof(_PATH_PERLSCRIPTS)-1));
180 sfdisc(PerlIO_stdout(), sfdcnewnvi(scrp));
181 sfdisc(PerlIO_stderr(), sfdcnewnvi(scrp));
183 svcurscr = perl_get_sv("curscr", TRUE);
184 sv_magic((SV *)gv_fetchpv("STDOUT",TRUE, SVt_PVIO), svcurscr,
186 sv_magic((SV *)gv_fetchpv("STDERR",TRUE, SVt_PVIO), svcurscr,
188 #endif /* USE_SFIO */
191 MALLOC(scrp, pp, perl_data_t *, sizeof(perl_data_t));
192 wp->perl_private = pp;
193 memset(&pp->cw, 0, sizeof(pp->cw));
195 pp->interp = perl_clone(gp->perl_interp, 0);
196 if (1) { /* hack for bug fixed in perl-current (5.6.1) */
198 if (PL_scopestack_ix == 0) {
203 pp->interp = gp->perl_interp;
208 SvREADONLY_on(pp->svcurscr = perl_get_sv("curscr", TRUE));
209 SvREADONLY_on(pp->svstart = perl_get_sv("VI::StartLine", TRUE));
210 SvREADONLY_on(pp->svstop = perl_get_sv("VI::StopLine", TRUE));
211 SvREADONLY_on(pp->svid = perl_get_sv("VI::ScreenId", TRUE));
218 * Remove all refences to the screen to be destroyed
220 * PUBLIC: int perl_screen_end __P((SCR*));
223 perl_screen_end(scrp)
228 if (scrp->perl_private) {
229 sv_setiv((SV*) scrp->perl_private, 0);
238 croak("Perl command interrupted by SIGINT");
241 /* Create a new reference to an SV pointing to the SCR structure
242 * The perl_private part of the SCR structure points to the SV,
243 * so there can only be one such SV for a particular SCR structure.
244 * When the last reference has gone (DESTROY is called),
245 * perl_private is reset; When the screen goes away before
246 * all references are gone, the value of the SV is reset;
247 * any subsequent use of any of those reference will produce
248 * a warning. (see typemap)
257 if (!screen) return sv_setsv(rv, &PL_sv_undef), rv;
258 sv_upgrade(rv, SVt_RV);
259 if (!screen->perl_private) {
260 screen->perl_private = newSV(0);
261 sv_setiv(screen->perl_private, (IV) screen);
263 else SvREFCNT_inc(screen->perl_private);
264 SvRV(rv) = screen->perl_private;
266 return sv_bless(rv, gv_stashpv("VI", TRUE));
271 * perl_ex_perl -- :[line [,line]] perl [command]
272 * Run a command through the perl interpreter.
274 * PUBLIC: int perl_ex_perl __P((SCR*, CHAR_T *, size_t, db_recno_t, db_recno_t));
277 perl_ex_perl(scrp, cmdp, cmdlen, f_lno, t_lno)
281 db_recno_t f_lno, t_lno;
292 /* Initialize the interpreter. */
293 if (scrp->wp->perl_private == NULL && perl_init(scrp))
295 pp = scrp->wp->perl_private;
300 sv_setiv(pp->svstart, f_lno);
301 sv_setiv(pp->svstop, t_lno);
302 newVIrv(pp->svcurscr, scrp);
303 /* Backwards compatibility. */
304 newVIrv(pp->svid, scrp);
306 istat = signal(SIGINT, my_sighandler);
307 INT2CHAR(scrp, cmdp, STRLEN(cmdp)+1, np, nlen);
309 signal(SIGINT, istat);
311 SvREFCNT_dec(SvRV(pp->svcurscr));
312 SvROK_off(pp->svcurscr);
313 SvREFCNT_dec(SvRV(pp->svid));
316 err = SvPV(ERRSV, length);
320 err[length - 1] = '\0';
321 msgq(scrp, M_ERR, "perl: %s", err);
328 * replace a line with the contents of the perl variable $_
329 * lines are split at '\n's
330 * if $_ is undef, the line is deleted
331 * returns possibly adjusted linenumber
334 replace_line(scrp, line, t_lno, defsv)
336 db_recno_t line, *t_lno;
345 str = SvPV(defsv,len);
346 next = memchr(str, '\n', len);
347 CHAR2INTP(scrp, str, next ? (next - str) : len, wp, wlen);
348 api_sline(scrp, line, wp, wlen);
351 next = memchr(str = next, '\n', len);
352 CHAR2INTP(scrp, str, next ? (next - str) : len,
354 api_iline(scrp, ++line, wp, wlen);
358 api_dline(scrp, line--);
365 * perl_ex_perldo -- :[line [,line]] perl [command]
366 * Run a set of lines through the perl interpreter.
368 * PUBLIC: int perl_ex_perldo __P((SCR*, CHAR_T *, size_t, db_recno_t, db_recno_t));
371 perl_ex_perldo(scrp, cmdp, cmdlen, f_lno, t_lno)
375 db_recno_t f_lno, t_lno;
390 /* Initialize the interpreter. */
391 if (scrp->wp->perl_private == NULL && perl_init(scrp))
393 pp = scrp->wp->perl_private;
398 newVIrv(pp->svcurscr, scrp);
399 /* Backwards compatibility. */
400 newVIrv(pp->svid, scrp);
402 INT2CHAR(scrp, cmdp, STRLEN(cmdp)+1, np, nlen);
403 if (!(command = malloc(length = nlen - 1 + sizeof("sub {}"))))
405 snprintf(command, length, "sub {%s}", np);
410 cv = perl_eval_pv(command, FALSE);
413 estr = SvPV(ERRSV,length);
417 for (i = f_lno; i <= t_lno && !api_gline(scrp, i, &str, &len); i++) {
418 INT2CHAR(scrp, str, len, np, nlen);
419 sv_setpvn(DEFSV,np,nlen);
420 sv_setiv(pp->svstart, i);
421 sv_setiv(pp->svstop, i);
423 perl_call_sv(cv, G_SCALAR | G_EVAL);
424 estr = SvPV(ERRSV, length);
428 i = replace_line(scrp, i, &t_lno, DEFSV);
434 SvREFCNT_dec(SvRV(pp->svcurscr));
435 SvROK_off(pp->svcurscr);
436 SvREFCNT_dec(SvRV(pp->svid));
442 err: estr[length - 1] = '\0';
443 msgq(scrp, M_ERR, "perl: %s", estr);
450 * Perl message routine so that error messages are processed in
454 msghandler(sp, mtype, msg, len)
460 /* Replace the trailing <newline> with an EOS. */
461 /* Let's do that later instead */
462 if (errmsg) free (errmsg);
463 errmsg = malloc(len + 1);
464 memcpy(errmsg, msg, len);
470 typedef SCR * VI__OPT;
471 typedef SCR * VI__MAP;
472 typedef SCR * VI__MARK;
473 typedef SCR * VI__LINE;
481 typedef perl_tagq * VI__TAGQ;
482 typedef perl_tagq * VI__TAGQ2;
484 MODULE = VI PACKAGE = VI
487 # Set the message line to text.
489 # Perl Command: VI::Msg
490 # Usage: VI::Msg screenId text
501 api_imessage(screen, text);
506 # Perl Command: VI::EndScreen
507 # Usage: VI::EndScreen screenId
514 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
519 rval = api_escreen(screen);
523 # Create a new screen. If a filename is specified then the screen
524 # is opened with that file.
526 # Perl Command: VI::NewScreen
527 # Usage: VI::NewScreen screenId [file]
538 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
544 file = (items == 1) ? NULL : (char *)SvPV(ST(1),PL_na);
546 rval = api_edit(screen, file, &nsp, ix);
549 RETVAL = ix ? nsp : screen;
555 # Return the screen id associated with file name.
557 # Perl Command: VI::FindScreen
558 # Usage: VI::FindScreen file
567 RETVAL = api_fscreen(0, file);
572 # XS_VI_GetFileName --
573 # Return the file name of the screen
575 # Perl Command: VI::GetFileName
576 # Usage: VI::GetFileName screenId
584 PUSHs(sv_2mortal(newSVpv(screen->frp->name, 0)));
587 # -- Append the string text after the line in lineNumber.
589 # Perl Command: VI::AppendLine
590 # Usage: VI::AppendLine screenId lineNumber text
593 AppendLine(screen, linenumber, text)
599 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
606 rval = api_aline(screen, linenumber, text, length);
612 # Perl Command: VI::DelLine
613 # Usage: VI::DelLine screenId lineNum
616 DelLine(screen, linenumber)
621 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
626 rval = api_dline(screen, (db_recno_t)linenumber);
632 # Perl Command: VI::GetLine
633 # Usage: VI::GetLine screenId lineNumber
636 GetLine(screen, linenumber)
642 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
649 rval = api_gline(screen, (db_recno_t)linenumber, &p, &len);
653 PUSHs(sv_2mortal(newSVpv(len ? (char *)p : "", len)));
656 # Set lineNumber to the text supplied.
658 # Perl Command: VI::SetLine
659 # Usage: VI::SetLine screenId lineNumber text
662 SetLine(screen, linenumber, text)
668 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
677 CHAR2INTP(screen, text, length, line, len);
678 rval = api_sline(screen, linenumber, line, len);
682 # Insert the string text before the line in lineNumber.
684 # Perl Command: VI::InsertLine
685 # Usage: VI::InsertLine screenId lineNumber text
688 InsertLine(screen, linenumber, text)
694 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
703 CHAR2INTP(screen, text, length, line, len);
704 rval = api_iline(screen, linenumber, line, len);
708 # Return the last line in the screen.
710 # Perl Command: VI::LastLine
711 # Usage: VI::LastLine screenId
719 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
724 rval = api_lline(screen, &last);
732 # Return the mark's cursor position as a list with two elements.
735 # Perl Command: VI::GetMark
736 # Usage: VI::GetMark screenId mark
739 GetMark(screen, mark)
745 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
750 rval = api_getmark(screen, (int)mark, &cursor);
754 PUSHs(sv_2mortal(newSViv(cursor.lno)));
755 PUSHs(sv_2mortal(newSViv(cursor.cno)));
758 # Set the mark to the line and column numbers supplied.
760 # Perl Command: VI::SetMark
761 # Usage: VI::SetMark screenId mark line column
764 SetMark(screen, mark, line, column)
772 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
779 rval = api_setmark(screen, (int)mark, &cursor);
783 # Return the current cursor position as a list with two elements.
786 # Perl Command: VI::GetCursor
787 # Usage: VI::GetCursor screenId
795 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
800 rval = api_getcursor(screen, &cursor);
804 PUSHs(sv_2mortal(newSViv(cursor.lno)));
805 PUSHs(sv_2mortal(newSViv(cursor.cno)));
808 # Set the cursor to the line and column numbers supplied.
810 # Perl Command: VI::SetCursor
811 # Usage: VI::SetCursor screenId line column
814 SetCursor(screen, line, column)
821 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
828 rval = api_setcursor(screen, &cursor);
832 # Change the current focus to screen.
834 # Perl Command: VI::SwitchScreen
835 # Usage: VI::SwitchScreen screenId screenId
838 SwitchScreen(screenFrom, screenTo)
843 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
847 INITMESSAGE(screenFrom);
848 rval = api_swscreen(screenFrom, screenTo);
849 ENDMESSAGE(screenFrom);
852 # Associate a key with a perl procedure.
854 # Perl Command: VI::MapKey
855 # Usage: VI::MapKey screenId key perlproc
858 MapKey(screen, key, commandsv)
864 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
871 command = SvPV(commandsv, length);
872 rval = api_map(screen, key, command, length);
878 # Perl Command: VI::UnmapKey
879 # Usage: VI::UnmmapKey screenId key
882 UnmapKey(screen, key)
887 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
892 rval = api_unmap(screen, key);
898 # Perl Command: VI::SetOpt
899 # Usage: VI::SetOpt screenId setting
902 SetOpt(screen, setting)
907 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
913 svc = sv_2mortal(newSVpv(":set ", 5));
914 sv_catpv(svc, setting);
915 rval = api_run_str(screen, SvPV(svc, PL_na));
919 # Return the value of an option.
921 # Perl Command: VI::GetOpt
922 # Usage: VI::GetOpt screenId option
925 GetOpt(screen, option)
930 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
938 CHAR2INTP(screen, option, strlen(option)+1, wp, wlen);
939 rval = api_opts_get(screen, wp, &value, NULL);
943 PUSHs(sv_2mortal(newSVpv(value, 0)));
947 # Run the ex command cmd.
949 # Perl Command: VI::Run
950 # Usage: VI::Run screenId cmd
958 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
963 rval = api_run_str(screen, command);
974 if (sv_isa(screensv, "VI")) {
975 IV tmp = SvIV((SV*)SvRV(screensv));
976 screen = (SCR *) tmp;
979 croak("screen is not of type VI");
982 screen->perl_private = 0;
989 sv_catpv(ERRSV,warning);
991 #define TIED(kind,package) \
992 sv_magic((SV *) (var = \
993 (kind##V *)sv_2mortal((SV *)new##kind##V())), \
994 sv_setref_pv(sv_newmortal(), package, \
995 newVIrv(newSV(0), screen)),\
997 RETVAL = newRV((SV *)var)
1048 if ((ptag = malloc(sizeof(perl_tagq))) == NULL)
1051 ptag->sprv = newVIrv(newSV(0), screen);
1052 ptag->tqp = api_tagq_new(screen, tag);
1053 if (ptag->tqp != NULL) {
1055 PUSHs(sv_2mortal(sv_setref_pv(newSV(0), "VI::TAGQ", ptag)));
1058 ST(0) = &PL_sv_undef;
1062 MODULE = VI PACKAGE = VI::OPT
1069 # typemap did all the checking
1070 SvREFCNT_dec((SV*)SvIV((SV*)SvRV(ST(0))));
1078 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
1086 INITMESSAGE(screen);
1087 CHAR2INTP(screen, key, strlen(key)+1, wp, wlen);
1088 rval = api_opts_get(screen, wp, &value, &boolvalue);
1091 PUSHs(sv_2mortal((boolvalue == -1) ? newSVpv(value, 0)
1092 : newSViv(boolvalue)));
1094 } else ST(0) = &PL_sv_undef;
1099 STORE(screen, key, value)
1105 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
1111 INITMESSAGE(screen);
1112 CHAR2INTP(screen, key, strlen(key)+1, wp, wlen);
1113 rval = api_opts_set(screen, wp, SvPV(value, PL_na), SvIV(value),
1117 MODULE = VI PACKAGE = VI::MAP
1124 # typemap did all the checking
1125 SvREFCNT_dec((SV*)SvIV((SV*)SvRV(ST(0))));
1128 STORE(screen, key, commandsv)
1134 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
1140 INITMESSAGE(screen);
1141 command = SvPV(commandsv, length);
1142 rval = api_map(screen, key, command, length);
1151 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
1155 INITMESSAGE(screen);
1156 rval = api_unmap(screen, key);
1159 MODULE = VI PACKAGE = VI::MARK
1166 # typemap did all the checking
1167 SvREFCNT_dec((SV*)SvIV((SV*)SvRV(ST(0))));
1175 struct _mark cursor;
1176 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
1180 INITMESSAGE(screen);
1181 rval = api_getmark(screen, (int)mark, &cursor);
1184 av_push(RETVAL, newSViv(cursor.lno));
1185 av_push(RETVAL, newSViv(cursor.cno));
1191 STORE(screen, mark, pos)
1197 struct _mark cursor;
1198 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
1202 if (av_len(pos) < 1)
1203 croak("cursor position needs 2 elements");
1204 INITMESSAGE(screen);
1205 cursor.lno = SvIV(*av_fetch(pos, 0, 0));
1206 cursor.cno = SvIV(*av_fetch(pos, 1, 0));
1207 rval = api_setmark(screen, (int)mark, &cursor);
1211 FIRSTKEY(screen, ...)
1221 char key[] = {0, 0};
1226 *key = *(char *)SvPV(ST(1),PL_na);
1228 if (api_nextmark(screen, next, key) != 1) {
1230 PUSHs(sv_2mortal(newSVpv(key, 1)));
1231 } else ST(0) = &PL_sv_undef;
1233 MODULE = VI PACKAGE = VI::LINE
1240 # typemap did all the checking
1241 SvREFCNT_dec((SV*)SvIV((SV*)SvRV(ST(0))));
1243 # similar to SetLine
1246 STORE(screen, linenumber, text)
1252 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
1260 ++linenumber; /* vi 1 based ; perl 0 based */
1261 SvPV(ST(2), length);
1262 INITMESSAGE(screen);
1263 rval = api_lline(screen, &last);
1265 if (linenumber > last)
1266 rval = api_extend(screen, linenumber);
1268 CHAR2INTP(screen, text, length, line, len);
1269 rval = api_sline(screen, linenumber, line, len);
1273 # similar to GetLine
1276 FETCH(screen, linenumber)
1282 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
1288 ++linenumber; /* vi 1 based ; perl 0 based */
1289 INITMESSAGE(screen);
1290 rval = api_gline(screen, (db_recno_t)linenumber, &p, &len);
1294 PUSHs(sv_2mortal(newSVpv(len ? (char*)p : "", len)));
1296 # similar to LastLine
1304 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
1308 INITMESSAGE(screen);
1309 rval = api_lline(screen, &last);
1317 STORESIZE(screen, count)
1323 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
1327 INITMESSAGE(screen);
1328 rval = api_lline(screen, &last);
1331 rval = api_extend(screen, count);
1332 else while(last && last > count) {
1333 rval = api_dline(screen, last--);
1340 EXTEND(screen, count)
1352 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
1356 INITMESSAGE(screen);
1357 rval = api_lline(screen, &last);
1360 rval = api_dline(screen, last--);
1372 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
1377 INITMESSAGE(screen);
1378 rval = api_lline(screen, &last);
1381 for (i = 1; i < items; ++i) {
1382 line = SvPV(ST(i), len);
1383 if ((rval = api_aline(screen, last++, line, len)))
1394 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
1399 INITMESSAGE(screen);
1400 rval = api_lline(screen, &last);
1401 if (rval || last < 1)
1402 ST(0) = &PL_sv_undef;
1404 rval = api_gline(screen, last, &line, &len) ||
1405 api_dline(screen, last);
1407 PUSHs(sv_2mortal(newSVpv(len ? (char *)line : "", len)));
1417 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
1422 INITMESSAGE(screen);
1423 rval = api_lline(screen, &last);
1424 if (rval || last < 1)
1425 ST(0) = &PL_sv_undef;
1427 rval = api_gline(screen, (db_recno_t)1, &line, &len) ||
1428 api_dline(screen, (db_recno_t)1);
1430 PUSHs(sv_2mortal(newSVpv(len ? (char *)line : "", len)));
1435 UNSHIFT(screen, ...)
1439 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
1446 INITMESSAGE(screen);
1447 while (--items != 0) {
1448 np = SvPV(ST(items), nlen);
1449 CHAR2INTP(screen, np, nlen, line, len);
1450 if ((rval = api_iline(screen, (db_recno_t)1, line, len)))
1460 db_recno_t last, db_offset;
1461 void (*scr_msg) __P((SCR *, mtype_t, char *, size_t));
1462 int rval, length, common, len, i, offset;
1468 INITMESSAGE(screen);
1469 rval = api_lline(screen, &last);
1470 offset = items > 1 ? (int)SvIV(ST(1)) : 0;
1471 if (offset < 0) offset += last;
1474 croak("Invalid offset");
1476 length = items > 2 ? (int)SvIV(ST(2)) : last - offset;
1477 if (length > last - offset)
1478 length = last - offset;
1479 db_offset = offset + 1; /* 1 based */
1481 for (common = MIN(length, items - 3), i = 3; common > 0;
1482 --common, ++db_offset, --length, ++i) {
1483 rval |= api_gline(screen, db_offset, &line, &len);
1484 INT2CHAR(screen, line, len, np, nlen);
1485 PUSHs(sv_2mortal(newSVpv(nlen ? np : "", nlen)));
1486 np = SvPV(ST(i), nlen);
1487 CHAR2INTP(screen, np, nlen, line, len);
1488 rval |= api_sline(screen, db_offset, line, len);
1490 for (; length; --length) {
1491 rval |= api_gline(screen, db_offset, &line, &len);
1492 INT2CHAR(screen, line, len, np, nlen);
1493 PUSHs(sv_2mortal(newSVpv(len ? np : "", nlen)));
1494 rval |= api_dline(screen, db_offset);
1496 for (; i < items; ++i) {
1497 np = SvPV(ST(i), len);
1498 CHAR2INTP(screen, np, len, line, nlen);
1499 rval |= api_iline(screen, db_offset, line, nlen);
1503 MODULE = VI PACKAGE = VI::TAGQ
1506 Add(tagq, filename, search, msg)
1516 sp = (SCR *)SvIV((SV*)SvRV(tagq->sprv));
1518 croak("screen no longer exists");
1519 api_tagq_add(sp, tagq->tqp, filename, search, msg);
1529 sp = (SCR *)SvIV((SV*)SvRV(tagq->sprv));
1531 croak("screen no longer exists");
1532 api_tagq_push(sp, &tagq->tqp);
1536 # Can already be invalidated by push
1543 sp = (SCR *)SvIV((SV*)SvRV(tagq->sprv));
1545 api_tagq_free(sp, tagq->tqp);
1546 SvREFCNT_dec(tagq->sprv);