Dear Sir,
I am writing to thank you very much for your help.
Your advice did the trick.
Here is the amended rubbish
static PerlInterpreter *perl = NULL;
int main(int argc, char **argv, char **env){
char *embedding[] = { "", "p1.pl" };
char plugin_output[1024];
char buffer[512];
char tmpfname[32];
char fname[MAX_COMMANDLINE_LENGTH];
char *args[] = {"","0", "", "", NULL };
FILE *fp;
char command_line[MAX_COMMANDLINE_LENGTH];
char *ap ;
int exitstatus;
int pclose_result;
if ((perl=perl_alloc())==NULL) {
snprintf(buffer,sizeof(buffer),"Error: Could not allocate memory for
embedded Perl interpreter!\n");
buffer[sizeof(buffer)-1]='\x0';
printf("%s\n", buffer);
exit(1);
}
perl_construct(perl);
exitstatus=perl_parse(perl,xs_init,2,embedding,NULL);
if(!exitstatus){
exitstatus=perl_run(perl);
while(printf("Enter file name: ") &&
fgets(command_line,sizeof(command_line),stdin)){
dTHX;
dSP;
/* call the subroutine, passing it the filename as an argument
*/
command_line[strlen(command_line) -1] = '\0';
strncpy(fname,command_line,strcspn(command_line," "));
fname[strcspn(command_line," ")] = '\x0';--More--(51%)
args[0] = fname ;
args[3] = command_line + strlen(fname) + 1 ;
/* generate a temporary filename to which stdout can be
redirected. */
sprintf(tmpfname,"/tmp/embedded%d",getpid());
args[2] = tmpfname;
/* call our perl interpreter to compile and optionally cache the
command */
call_argv("Embed::Persistent::eval_file", G_DISCARD | G_EVAL,
args);
call_argv("Embed::Persistent::run_package", G_DISCARD | G_EVAL,
args);
/* check return status */
if(SvTRUE(ERRSV)){
pclose_result=-2;
printf("embedded perl ran %s with error
%s\n",fname,SvPV(ERRSV,PL_na));
}
/* read back stdout from script */
fp=fopen(tmpfname, "r");
/* default return string in case nothing was returned */
strcpy(plugin_output,"(No output!)");
fgets(plugin_output,sizeof(plugin_output)-1,fp);
plugin_output[sizeof(plugin_output)-1]='\x0';
fclose(fp);
unlink(tmpfname);
printf("embedded perl plugin output was %d,%s\n", pclose_result,
plugin_output);
}
}
dTHX;
PL_perl_destruct_level = 0;
perl_destruct(perl);
perl_free(perl);
exit(exitstatus);
}
Obviously I understand nothing whatsover about the use of the THX
macros.
In retrospect, what you say about using dSP before there is a Perl
interpreter seems very sensible, but this does not affect an unthreaded
Perl.
Please would you let me, and perhaps others, where one can find about
them ?
The example type documentation does not seem to consdier threaded Perls
(eg perlembed or perlxs).
Yours sincerely.
--
------------------------------------------------------------------------
Stanley Hopcroft
------------------------------------------------------------------------
'...No man is an island, entire of itself; every man is a piece of the
continent, a part of the main. If a clod be washed away by the sea,
Europe is the less, as well as if a promontory were, as well as if a
manor of thy friend's or of thine own were. Any man's death diminishes
me, because I am involved in mankind; and therefore never send to know
for whom the bell tolls; it tolls for thee...'
from Meditation 17, J Donne.