Changeset eb6cedc


Ignore:
Timestamp:
Jul 17, 2009, 11:52:30 PM (12 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
96f7b07
Parents:
b4ef908
git-author:
Nelson Elhage <nelhage@mit.edu> (07/17/09 23:31:14)
git-committer:
Nelson Elhage <nelhage@mit.edu> (07/17/09 23:52:30)
Message:
Push commands into BarnOwl:: instead of AUTOLOAD'ing them
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • cmd.c

    rc4ba74d reb6cedc  
    2727int owl_cmddict_add_from_list(owl_cmddict *cd, owl_cmd *cmds) {
    2828  owl_cmd *cur, *cmd;
    29   for (cur = cmds; cur->name != NULL; cur++) { 
    30     cmd = owl_malloc(sizeof(owl_cmd));
    31     owl_cmd_create_from_template(cmd, cur);
    32     owl_dict_insert_element(cd, cmd->name, (void*)cmd, NULL);
    33   }
    34   return 0;
     29  int ret = 0;
     30  for (cur = cmds; cur->name != NULL; cur++) {
     31    ret = owl_cmddict_add_cmd(cd, cur);
     32    if (ret < 0) break;
     33  }
     34  return ret;
    3535}
    3636
     
    6363    return -1;
    6464  }
    65   owl_function_debugmsg("Add cmd %s", cmd->name);
     65  owl_perlconfig_new_command(cmd->name);
    6666  return owl_dict_insert_element(cd, newcmd->name, (void*)newcmd, (void(*)(void*))owl_cmd_free);
    6767}
  • global.c

    ra556caa reb6cedc  
    4040
    4141  owl_variable_dict_setup(&(g->vars));
    42   owl_cmddict_setup(&(g->cmds));
    4342
    4443  g->lines=LINES;
     
    121120}
    122121
     122/* Called once perl has been initialized */
     123void owl_global_complete_setup(owl_global *g)
     124{
     125  owl_cmddict_setup(&(g->cmds));
     126}
     127
    123128void _owl_global_setup_windows(owl_global *g) {
    124129  int cols, typwin_lines;
  • owl.c

    r301c975 reb6cedc  
    235235    exit(1);
    236236  }
     237
     238  owl_global_complete_setup(&g);
    237239
    238240  /* setup the default filters */
  • perl/lib/BarnOwl.pm

    r22b54a7 reb6cedc  
    167167    $m->legacy_populate_global();
    168168    return &BarnOwl::Hooks::_receive_msg($m);
    169 }
    170 
    171 =head2 AUTOLOAD
    172 
    173 BarnOwl.pm has a C<AUTOLOAD> method that translates unused names in
    174 the BarnOwl:: namespace to a call to BarnOwl::command() with that
    175 command. Underscores are also translated to C<->s, so you can do
    176 e.g. C<BarnOwl::start_command()> and it will be translated into
    177 C<start-command>.
    178 
    179 So, if you're looking for functionality that you can't find in the
    180 perl interface, check C<:show commands> or C<commands.c> in the
    181 BarnOwl source tree -- there's a good chance it exists as a BarnOwl
    182 command.
    183 
    184 =head3 BUGS
    185 
    186 There are horrible quoting issues here. The AUTOLOAD simple joins your
    187 commands with spaces and passes them unmodified to C<::command>
    188 
    189 =cut
    190 
    191 # make BarnOwl::<command>("foo") be aliases to BarnOwl::command("<command> foo");
    192 sub AUTOLOAD {
    193     our $AUTOLOAD;
    194     my $called = $AUTOLOAD;
    195     $called =~ s/.*:://;
    196     $called =~ s/_/-/g;
    197     return &BarnOwl::command("$called ".join(" ",@_));
    198169}
    199170
  • perl/lib/BarnOwl/Hooks.pm

    ree183be reb6cedc  
    33
    44package BarnOwl::Hooks;
     5
     6use Carp;
    57
    68=head1 BarnOwl::Hooks
     
    180182}
    181183
     184sub _new_command {
     185    my $command = shift;
     186    (my $symbol = $command) =~ s/-/_/g;
     187    my $package = "BarnOwl";
     188
     189    if($symbol =~ m{^edit:(.+)$}) {
     190        $symbol = $1;
     191        $package = "BarnOwl::Editwin";
     192    } else {
     193        $symbol =~ s/:/_/;
     194    }
     195    {
     196        no strict 'refs';
     197        if(defined(*{"${package}::${symbol}"}{CODE})) {
     198            return;
     199        }
     200        *{"${package}::${symbol}"} = sub {
     201            if(@_ == 1 && $_[0] =~ m{\s}) {
     202                carp "DEPRECATED: ${package}::${symbol}: Tokenizing argument on ' '.\n"
     203                . "In future versions, the argument list will be passed to\n"
     204                . "'$command' directly. Tokenize yourself, or use BarnOwl::command()\n"
     205            }
     206            BarnOwl::command($command . " " . join(" ", @_))
     207          };
     208    }
     209}
    182210
    1832111;
  • perlconfig.c

    ra556caa reb6cedc  
    429429}
    430430
     431void owl_perlconfig_new_command(char *name)
     432{
     433  int i, count;
     434  SV *rv;
     435  dSP;
     436
     437  ENTER;
     438  SAVETMPS;
     439
     440  PUSHMARK(SP);
     441  XPUSHs(sv_2mortal(newSVpv(name, 0)));
     442  PUTBACK;
     443
     444  call_pv("BarnOwl::Hooks::_new_command", G_SCALAR|G_VOID);
     445
     446  SPAGAIN;
     447
     448  if(SvTRUE(ERRSV)) {
     449    owl_function_error("%s", SvPV_nolen(ERRSV));
     450  }
     451
     452  FREETMPS;
     453  LEAVE;
     454}
     455
    431456char *owl_perlconfig_perlcmd(owl_cmd *cmd, int argc, char **argv)
    432457{
Note: See TracChangeset for help on using the changeset viewer.