Changeset 8ee73f8d for readconfig.c
- Timestamp:
- Jun 30, 2002, 2:54:22 AM (23 years ago)
- Branches:
- master, barnowl_perlaim, debian, owl, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 039213e
- Parents:
- d36f2cb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
readconfig.c
r1aee7d9 r8ee73f8d 10 10 static const char fileIdent[] = "$Id$"; 11 11 12 13 14 EXTERN_C void boot_owl (pTHX_ CV* cv); 15 16 static void owl_perl_xs_init(pTHX) { 17 char *file = __FILE__; 18 dXSUB_SYS; 19 { 20 newXS("owl::bootstrap", boot_owl, file); 21 } 22 } 23 24 12 25 int owl_readconfig(char *file) { 13 26 int ret; 14 27 PerlInterpreter *p; 15 char buff[1024], filename[1024];28 char *codebuff, filename[1024]; 16 29 char *embedding[5]; 17 30 struct stat statbuff; … … 22 35 strcpy(filename, file); 23 36 } 24 25 37 embedding[0]=""; 26 38 embedding[1]=filename; … … 39 51 } 40 52 41 ret=perl_parse(p, NULL, 2, embedding, NULL);53 ret=perl_parse(p, owl_perl_xs_init, 2, embedding, NULL); 42 54 if (ret) return(-1); 43 55 … … 61 73 perl_get_av("owl::fields", TRUE); 62 74 63 /* load in owl_command() */ 64 strcpy(buff, "sub owl::command { \n"); 65 strcat(buff, " my $command = shift; \n"); 66 strcat(buff, " push @owl::commands, $command; \n"); 67 strcat(buff, "} \n"); 68 perl_eval_pv(buff, FALSE); 75 /* perl bootstrapping code*/ 76 codebuff = 77 " \n" 78 "package owl; \n" 79 " \n" 80 "bootstrap owl 0.01; \n" 81 " \n" 82 "package main; \n"; 83 84 perl_eval_pv(codebuff, FALSE); 69 85 70 86 … … 79 95 /* caller is responsible for freeing returned string */ 80 96 char *owl_config_execute(char *line) { 81 STRLEN n_a; 82 SV *command, *response; 83 AV *commands; 84 int numcommands, i; 97 STRLEN len; 98 SV *response; 85 99 char *out, *preout; 86 100 … … 90 104 response = perl_eval_pv(line, FALSE); 91 105 92 preout=SvPV(response, n_a);106 preout=SvPV(response, len); 93 107 /* leave enough space in case we have to add a newline */ 94 108 out = owl_malloc(strlen(preout)+2); 95 strcpy(out, preout); 109 strncpy(out, preout, len); 110 out[len] = '\0'; 96 111 if (!strlen(out) || out[strlen(out)-1]!='\n') { 97 112 strcat(out, "\n"); 98 113 } 99 100 /* execute all the commands, cleaning up the arrays as we go */101 commands=perl_get_av("owl::commands", TRUE);102 numcommands=av_len(commands)+1;103 for (i=0; i<numcommands; i++) {104 command=av_shift(commands);105 owl_function_command_norv(SvPV(command, n_a));106 }107 av_undef(commands);108 114 109 115 return(out); … … 214 220 } 215 221 } 222
Note: See TracChangeset
for help on using the changeset viewer.