1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
// ctest.c
#include <string.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <EXTERN.h>
#include <perl.h>
#include "perlxsi.c"
#define TAILLE_MAX 1000
#define TAILLE_FILE_PERL 25000
char e_str_file_pl [TAILLE_FILE_PERL];
int e_get_file_pl(char *qfilename);
static PerlInterpreter *my_perl;
main (int argc, char **argv, char **env)
{
char *embedding[] = { "", "-e", "0" };
int inta = 0;
PERL_SYS_INIT3(&argc,&argv,&env);
my_perl = perl_alloc();
perl_construct( my_perl );
//perl_parse(my_perl, xs_init, argc, my_argv, NULL);
perl_parse(my_perl, xs_init, 3, embedding, NULL);
PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
perl_run(my_perl);
/** Treat $a as an integer **/
//eval_pv("$a = 3; $a **= 2", TRUE);
//printf("a = %d\n", SvIV(get_sv("a", 0)));
/** Treat $a as a float **/
//eval_pv("$a = 3.14; $a **= 2", TRUE);
//printf("a = %f\n", SvNV(get_sv("a", 0)));
/** Treat $a as a string **/
inta = e_get_file_pl("testpl.txt") ;
eval_pv( e_str_file_pl , TRUE);
printf("a = %s\n", SvPV_nolen(get_sv("a", 0)));
perl_destruct(my_perl);
perl_free(my_perl);
PERL_SYS_TERM();
}
int e_get_file_pl(char *qfilename) {
FILE* fichier = NULL;
char chaine[TAILLE_MAX] = "";
memset(e_str_file_pl, 0, TAILLE_FILE_PERL );
fichier = fopen(qfilename, "r");
if (fichier != NULL) { while (fgets(chaine, TAILLE_MAX, fichier) != NULL) { strcat(e_str_file_pl,chaine); } fclose(fichier); }
return 0;
} |