remove _() non-ansism
[p5sagit/p5-mst-13.2.git] / ext / ByteLoader / ByteLoader.xs
CommitLineData
b295d113 1#include "EXTERN.h"
2#include "perl.h"
3#include "XSUB.h"
e8edd1e6 4#include "byterun.h"
b295d113 5
e8edd1e6 6static void
7freadpv(U32 len, void *data, XPV *pv)
8{
9 New(666, pv->xpv_pv, len, char);
10 fread(pv->xpv_pv, 1, len, (FILE*)data);
11 pv->xpv_len = len;
12 pv->xpv_cur = len - 1;
13}
b295d113 14
15static I32
16#ifdef PERL_OBJECT
17byteloader_filter(CPerlObj *pPerl, int idx, SV *buf_sv, int maxlen)
18#else
19byteloader_filter(int idx, SV *buf_sv, int maxlen)
20#endif
21{
a6c40364 22 dTHR;
b295d113 23 OP *saveroot = PL_main_root;
24 OP *savestart = PL_main_start;
e8edd1e6 25 struct bytestream bs;
b295d113 26
27 bs.data = PL_rsfp;
20ce7b12 28 bs.fgetc = (int(*) (void*))fgetc;
29 bs.fread = (int(*) (char*,size_t,size_t,void*))fread;
b295d113 30 bs.freadpv = freadpv;
e8edd1e6 31
32 byterun(bs);
b295d113 33
34 if (PL_in_eval) {
35 OP *o;
36
37 PL_eval_start = PL_main_start;
38
39 o = newSVOP(OP_CONST, 0, newSViv(1));
40 PL_eval_root = newLISTOP(OP_LINESEQ, 0, PL_main_root, o);
41 PL_main_root->op_next = o;
42 PL_eval_root = newUNOP(OP_LEAVEEVAL, 0, PL_eval_root);
43 o->op_next = PL_eval_root;
44
45 PL_main_root = saveroot;
46 PL_main_start = savestart;
47 }
48
49 return 0;
50}
51
52MODULE = ByteLoader PACKAGE = ByteLoader
53
54PROTOTYPES: ENABLE
55
56void
57import(...)
58 PPCODE:
59 filter_add(byteloader_filter, NULL);
60
61void
62unimport(...)
63 PPCODE:
64 filter_del(byteloader_filter);