Changeset 8ee73f8d for readconfig.c


Ignore:
Timestamp:
Jun 30, 2002, 2:54:22 AM (19 years ago)
Author:
Erik Nygren <nygren@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
039213e
Parents:
d36f2cb
Message:
	Fixed a memory reference bug in delete and undelete commands.
	Added support for perl to call directly back into owl.
	Changed the implementation of owl::command("...") to immediately
	        call back into owl.  This allows perl to get the return
		value of strings returned by owl commands.
	Added the getview command which returns the name of the current
	        view's filter.
	Added the getvar command which returns the value of a variable.
	Added an example to examples/owlconf.erik which uses TAB to
		narrow and restore the view.
	Added an example to examples/owlconf.erik which uses M-c to
		color messages matching the current one green.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • readconfig.c

    r1aee7d9 r8ee73f8d  
    1010static const char fileIdent[] = "$Id$";
    1111
     12
     13
     14EXTERN_C void boot_owl (pTHX_ CV* cv);
     15
     16static 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
    1225int owl_readconfig(char *file) {
    1326  int ret;
    1427  PerlInterpreter *p;
    15   char buff[1024], filename[1024];
     28  char *codebuff, filename[1024];
    1629  char *embedding[5];
    1730  struct stat statbuff;
     
    2235    strcpy(filename, file);
    2336  }
    24 
    2537  embedding[0]="";
    2638  embedding[1]=filename;
     
    3951  }
    4052
    41   ret=perl_parse(p, NULL, 2, embedding, NULL);
     53  ret=perl_parse(p, owl_perl_xs_init, 2, embedding, NULL);
    4254  if (ret) return(-1);
    4355
     
    6173  perl_get_av("owl::fields", TRUE);
    6274 
    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);
    6985
    7086
     
    7995/* caller is responsible for freeing returned string */
    8096char *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;
    8599  char *out, *preout;
    86100
     
    90104  response = perl_eval_pv(line, FALSE);
    91105
    92   preout=SvPV(response, n_a);
     106  preout=SvPV(response, len);
    93107  /* leave enough space in case we have to add a newline */
    94108  out = owl_malloc(strlen(preout)+2);
    95   strcpy(out, preout);
     109  strncpy(out, preout, len);
     110  out[len] = '\0';
    96111  if (!strlen(out) || out[strlen(out)-1]!='\n') {
    97112    strcat(out, "\n");
    98113  }
    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);
    108114
    109115  return(out);
     
    214220  }
    215221}
     222
Note: See TracChangeset for help on using the changeset viewer.