Changeset 8ee73f8d


Ignore:
Timestamp:
Jun 30, 2002, 2:54:22 AM (22 years ago)
Author:
Erik Nygren <nygren@mit.edu>
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
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.
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    rd36f2cb r8ee73f8d  
    3535                This starts a zpunt command filled in with
    3636                the proposed zpunt.
     37        Fixed a memory reference bug in delete and undelete commands.
     38        Added support for perl to call directly back into owl.
     39        Changed the implementation of owl::command("...") to immediately
     40                call back into owl.  This allows perl to get the return
     41                value of strings returned by owl commands.
     42        Added the getview command which returns the name of the current
     43                view's filter. 
     44        Added the getvar command which returns the value of a variable.
     45        Added an example to examples/owlconf.erik which uses TAB to
     46                narrow and restore the view. 
     47        Added an example to examples/owlconf.erik which uses M-c to
     48                color messages matching the current one green.
    3749       
    38501.2.0-pre-erikdevel-17
  • Makefile.in

    r1aee7d9 r8ee73f8d  
    77CFLAGS=@CFLAGS@
    88LDFLAGS=@LDFLAGS@
     9XSUBPPDIR=@XSUBPPDIR@
    910
    1011OBJS=list.o message.o mainwin.o popwin.o zephyr.o messagelist.o commands.o \
     
    1213     functions.o zwrite.o viewwin.o help.o filter.o regex.o history.o view.o \
    1314     dict.o variable.o varstubs.o filterelement.o \
    14      keypress.o keymap.o keybinding.o cmd.o context.o
     15     keypress.o keymap.o keybinding.o cmd.o context.o perlglue.o
    1516
    16 AUTOGEN=owl_prototypes.h varstubs.c
     17AUTOGEN=owl_prototypes.h varstubs.c perlglue.c
    1718
    1819owl: $(AUTOGEN) $(OBJS) owl.o
     
    3334proto: owl_prototypes.h
    3435
     36perlglue.c: perlglue.xs
     37        perl $(XSUBPPDIR)/xsubpp -typemap $(XSUBPPDIR)/typemap -prototypes perlglue.xs > perlglue.c
    3538
    3639varstubs.c: variable.c stubgen.pl
  • commands.c

    rd36f2cb r8ee73f8d  
    485485              "prints a message into the debug log",
    486486              "debug <message>", ""),
     487
     488  OWLCMD_ARGS("getview", owl_command_getview, OWL_CTX_INTERACTIVE,
     489              "returns the name of the filter for the current view",
     490              "", ""),
     491
     492  OWLCMD_ARGS("getvar", owl_command_getvar, OWL_CTX_INTERACTIVE,
     493              "returns the value of a variable",
     494              "getvar <varname>", ""),
    487495
    488496  /****************************************************************/
     
    12741282  int move_after = 1;
    12751283
    1276   if (!strcmp(argv[1], "--no-move")) {
     1284  if (argc>1 && !strcmp(argv[1], "--no-move")) {
    12771285    move_after = 0;
    12781286    argc--;
     
    13071315  int move_after = 1;
    13081316
    1309   if (!strcmp(argv[1], "--no-move")) {
     1317  if (argc>1 && !strcmp(argv[1], "--no-move")) {
    13101318    move_after = 0;
    13111319    argc--;
     
    14031411}
    14041412
    1405 
     1413char *owl_command_getview(int argc, char **argv, char *buff) {
     1414  char *filtname;
     1415  if (argc != 1) {
     1416    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
     1417    return NULL;
     1418  }
     1419  filtname = owl_view_get_filtname(owl_global_get_current_view(&g));
     1420  if (filtname) filtname = owl_strdup(filtname);
     1421  return filtname;
     1422}
     1423
     1424char *owl_command_getvar(int argc, char **argv, char *buff) {
     1425  char tmpbuff[1024];
     1426  if (argc != 2) {
     1427    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
     1428    return NULL;
     1429  }
     1430  if (owl_variable_get_tostring(owl_global_get_vardict(&g),
     1431                                argv[1], tmpbuff, 1024)) {
     1432    return NULL;
     1433  }
     1434  return owl_strdup(tmpbuff);
     1435}
    14061436
    14071437/*********************************************************************/
  • configure

    r7d4fbcd r8ee73f8d  
    15611561CFLAGS=${CFLAGS}\ ${FOO}
    15621562
     1563echo $ac_n "checking for the perl xsubpp precompiler""... $ac_c" 1>&6
     1564echo "configure:1565: checking for the perl xsubpp precompiler" >&5
     1565XSUBPPDIR="`(perl -MExtUtils::MakeMaker -e 'print ExtUtils::MakeMaker->new({NAME => qw(owl)})->tool_xsubpp;') | grep ^XSUBPPDIR | sed -e 's/XSUBPPDIR = //g;'`"
     1566if test -n "${XSUBPPDIR}"; then
     1567   echo "$ac_t""${XSUBPPDIR}" 1>&6
     1568else
     1569   { echo "configure: error: not found" 1>&2; exit 1; }
     1570fi
     1571
    15631572FOO=`perl -MExtUtils::Embed -e ldopts`
    15641573echo Adding perl LDFLAGS ${FOO}
     
    15681577ac_safe=`echo "/usr/share/terminfo" | sed 'y%./+-%__p_%'`
    15691578echo $ac_n "checking for /usr/share/terminfo""... $ac_c" 1>&6
    1570 echo "configure:1571: checking for /usr/share/terminfo" >&5
     1579echo "configure:1580: checking for /usr/share/terminfo" >&5
    15711580if eval "test \"`echo '$''{'ac_cv_file_$ac_safe'+set}'`\" = set"; then
    15721581  echo $ac_n "(cached) $ac_c" 1>&6
     
    15931602ac_safe=`echo "/usr/share/lib/terminfo" | sed 'y%./+-%__p_%'`
    15941603echo $ac_n "checking for /usr/share/lib/terminfo""... $ac_c" 1>&6
    1595 echo "configure:1596: checking for /usr/share/lib/terminfo" >&5
     1604echo "configure:1605: checking for /usr/share/lib/terminfo" >&5
    15961605if eval "test \"`echo '$''{'ac_cv_file_$ac_safe'+set}'`\" = set"; then
    15971606  echo $ac_n "(cached) $ac_c" 1>&6
     
    16191628
    16201629fi
     1630
     1631
    16211632
    16221633
     
    17561767s%@CC@%$CC%g
    17571768s%@CPP@%$CPP%g
     1769s%@XSUBPPDIR@%$XSUBPPDIR%g
    17581770
    17591771CEOF
  • configure.in

    r1aee7d9 r8ee73f8d  
    8383CFLAGS=${CFLAGS}\ ${FOO}
    8484
     85dnl Find the location of XSUBPP
     86AC_MSG_CHECKING(for the perl xsubpp precompiler)
     87XSUBPPDIR="`(perl -MExtUtils::MakeMaker -e 'print ExtUtils::MakeMaker->new({NAME => qw(owl)})->tool_xsubpp;') | grep ^XSUBPPDIR | sed -e 's/XSUBPPDIR = //g;'`"
     88if test -n "${XSUBPPDIR}"; then
     89   AC_MSG_RESULT(${XSUBPPDIR})
     90else
     91   AC_MSG_ERROR(not found)
     92fi
     93
    8594dnl Add LDFLAGS for embeded perl
    8695FOO=`perl -MExtUtils::Embed -e ldopts`
     
    97106dnl AC_CHECK_FUNCS(gethostname strdup)
    98107
     108AC_SUBST(XSUBPPDIR)
     109
    99110AC_OUTPUT(Makefile)
  • examples/owlconf.erik

    rb950088 r8ee73f8d  
    6666sub sepbartokens_set {
    6767    owl::command(sprintf "set -q appendtosepbar \"%s\"", (join " ", @sepbartokens));
     68}
     69
     70my $restoreview = undef;
     71sub swapview {
     72    my $curview = owl::command("getview");
     73    if ($restoreview) {
     74        owl::command("view $restoreview");
     75        $restoreview = undef;
     76    } else {
     77        $restoreview = $curview;
     78        owl::command("smartnarrow");
     79    }
     80}
     81
     82my $lastcolored = undef;
     83sub colorthread {
     84    if ($lastcolored) {
     85        owl::command("filter $lastcolored -c default");
     86    }
     87    my $smartfilt = owl::command("smartfilter");
     88    if (!$smartfilt or $smartfilt eq $lastcolored) {
     89        owl::command("filter $lastcolored -c default");
     90        $lastcolored = undef;
     91    } else {
     92        owl::command("filter $smartfilt -c green");
     93        $lastcolored = $smartfilt;
     94    }
    6895}
    6996
     
    97124    owl::command("bindkey recv M-l command ( expunge ; view all )");
    98125    owl::command("bindkey recv M-K command ( smartnarrow ; delete view ; expunge ; view all )");
     126
     127    # toggle between a view and a smartnarrow with TAB
     128    owl::command("alias swapview perl swapview();");
     129    owl::command("bindkey recv C-i command swapview");
     130
     131    # color the current thread
     132    owl::command("alias colorthread perl colorthread();");
     133    owl::command("bindkey recv M-c command colorthread");
    99134
    100135    # Make 'M-s' insert a <scritchscritchscritch> sequence with a random
  • 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.