1 /* Perl scripting engine */
12 #include "config/home.h"
13 #include "main/module.h"
14 #include "osdep/osdep.h"
15 #include "scripting/perl/core.h"
16 #include "util/file.h"
18 /* The configure script runs "perl -MExtUtils::Embed -e ccopts -e ldopts",
19 * which should output the location of the DynaLoader.a where this function
20 * is defined. This prototype does not appear to be in any public header
22 EXTERN_C
void boot_DynaLoader (pTHX_ CV
* cv
);
24 #define PERL_HOOKS_FILENAME "hooks.pl"
27 PerlInterpreter
*my_perl
;
30 extern char **environ
;
35 get_global_hook_file(void)
37 static char buf
[] = CONFDIR STRING_DIR_SEP PERL_HOOKS_FILENAME
;
39 if (file_exists(buf
)) return buf
;
44 get_local_hook_file(void)
46 static char buf
[1024]; /* TODO: MAX_PATH ??? --Zas */
48 if (!elinks_home
) return NULL
;
49 snprintf(buf
, sizeof(buf
), "%s%s", elinks_home
, PERL_HOOKS_FILENAME
);
50 if (file_exists(buf
)) return buf
;
56 precleanup_perl(struct module
*module
)
60 perl_destruct(my_perl
);
66 cleanup_perl(struct module
*module
)
68 precleanup_perl(module
);
74 /** Tell Perl about XSUBs that were linked into ELinks. */
78 /* DynaLoader is the only Perl module whose library is
79 * statically linked into ELinks. DynaLoader::bootstrap will
80 * then load other libraries and register their XSUBs as
82 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader
, __FILE__
);
86 init_perl(struct module
*module
)
88 /* FIXME: it seems that some systems like OS/2 requires PERL_SYS_INIT3
89 * and PERL_SYS_TERM to open/close the same block, at least regarding
92 * Is passing @environ strictly needed ? --Zas */
94 /* PERL_SYS_INIT3 may not be defined, it depends on the system. */
96 char *my_argvec
[] = { NULL
, NULL
};
97 char **my_argv
= my_argvec
;
100 /* A hack to prevent unused variables warnings. */
101 my_argv
[my_argc
++] = "";
103 PERL_SYS_INIT3(&my_argc
, &my_argv
, &environ
);
106 my_perl
= perl_alloc();
108 char *hook_global
= get_global_hook_file();
109 char *hook_local
= get_local_hook_file();
110 char *global_argv
[] = { "", hook_global
};
111 char *local_argv
[] = { "", hook_local
};
114 perl_construct(my_perl
);
116 err
= perl_parse(my_perl
, xs_init
, 2, local_argv
, NULL
);
117 else if (hook_global
)
118 err
= perl_parse(my_perl
, xs_init
, 2, global_argv
, NULL
);
119 #ifdef PERL_EXIT_DESTRUCT_END
120 PL_exit_flags
|= PERL_EXIT_DESTRUCT_END
;
122 if (!err
) err
= perl_run(my_perl
);
123 if (err
) precleanup_perl(module
);