Changeset 7483942


Ignore:
Timestamp:
Jan 23, 2012, 5:30:46 PM (10 years ago)
Author:
GitHub Merge Button <merge-button@github.com>
Parents:
d126a19 (diff), 6df57d4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:
Merge 6df57d4264483d81d678c5981c422da79199945e into d126a19eb5f8a883b722fb26d21fb7b62b2aedeb
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    rf89cc6f r7483942  
    479479
    480480  OWLCMD_ARGS("away", owl_command_away, OWL_CTX_INTERACTIVE,
    481               "Set, enable or disable both AIM and zephyr away messages",
     481              "Set, enable or disable all away messages",
    482482              "away [ on | off | toggle ]\n"
    483483              "away <message>",
    484               "Turn on or off the AIM and zephyr away message.  If\n"
     484              "Turn on or off all away messages.  If\n"
    485485              "'message' is specified turn them on with that message,\n"
    486486              "otherwise use the default.\n"
    487               "\n"
    488               "This command really just runs the 'aaway' and 'zaway'\n"
    489               "commands together\n"
    490487              "\n"
    491488              "SEE ALSO: aaway, zaway"),
     
    15311528char *owl_command_away(int argc, const char *const *argv, const char *buff)
    15321529{
    1533   if ((argc==1) ||
    1534       ((argc==2) && !strcmp(argv[1], "on"))) {
     1530  bool away_off;
     1531  const char *message = NULL;
     1532
     1533  if (argc == 1 ||
     1534      (argc == 2 && !strcmp(argv[1], "on"))) {
     1535    away_off = false;
    15351536    owl_global_set_aaway_msg(&g, owl_global_get_aaway_msg_default(&g));
    15361537    owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
     1538  } else if (argc == 2 && !strcmp(argv[1], "off")) {
     1539    away_off = true;
     1540  } else if (argc == 2 && !strcmp(argv[1], "toggle")) {
     1541    away_off = owl_function_is_away();
     1542  } else {
     1543    away_off = false;
     1544    message = skiptokens(buff, 1);
     1545  }
     1546
     1547  if (away_off) {
     1548    owl_function_aaway_off();
     1549    owl_function_zaway_off();
     1550    owl_perlconfig_perl_call_norv("BarnOwl::Hooks::_away_off", 0, NULL);
     1551    owl_function_makemsg("Away messages off.");
     1552  } else if (message != NULL) {
     1553    owl_global_set_aaway_msg(&g, message);
     1554    owl_global_set_zaway_msg(&g, message);
    15371555    owl_function_aaway_on();
    15381556    owl_function_zaway_on();
     1557    owl_perlconfig_perl_call_norv("BarnOwl::Hooks::_away_on", 1, &message);
     1558    owl_function_makemsg("Away messages set (%s).", message);
     1559  } else {
     1560    owl_function_aaway_on();
     1561    owl_function_zaway_on();
     1562    owl_perlconfig_perl_call_norv("BarnOwl::Hooks::_away_on", 0, NULL);
    15391563    owl_function_makemsg("Away messages set.");
    1540     return NULL;
    1541   }
    1542 
    1543   if (argc==2 && !strcmp(argv[1], "off")) {
    1544     owl_function_aaway_off();
    1545     owl_function_zaway_off();
    1546     return NULL;
    1547   }
    1548 
    1549   if (argc==2 && !strcmp(argv[1], "toggle")) {
    1550     /* if either one is on, turn it off, otherwise toggle both (turn
    1551      *  them both on)
    1552      */
    1553     if (!owl_global_is_zaway(&g) && !owl_global_is_aaway(&g)) {
    1554       owl_function_aaway_toggle();
    1555       owl_function_zaway_toggle();
    1556       owl_function_makemsg("Away messages set.");
    1557     } else {
    1558       if (owl_global_is_zaway(&g)) owl_function_zaway_toggle();
    1559       if (owl_global_is_aaway(&g)) owl_function_aaway_toggle();
    1560       owl_function_makemsg("Away messages off.");
    1561     }
    1562     return NULL;
    1563   }
    1564 
    1565   buff = skiptokens(buff, 1);
    1566   owl_global_set_aaway_msg(&g, buff);
    1567   owl_global_set_zaway_msg(&g, buff);
    1568   owl_function_aaway_on();
    1569   owl_function_zaway_on();
    1570   owl_function_makemsg("Away messages set.");
     1564  }
     1565
    15711566  return NULL;
    15721567}
  • functions.c

    recfbdcc r7483942  
    993993}
    994994
     995bool owl_function_is_away(void)
     996{
     997  return owl_global_is_zaway(&g) ||
     998         owl_global_is_aaway(&g) ||
     999         owl_perlconfig_perl_call_bool("BarnOwl::Hooks::_get_is_away", 0, NULL);
     1000}
     1001
    9951002void owl_function_quit(void)
    9961003{
  • owl_perl.h

    rf271129 r0c71c58  
    44#include <stdio.h>
    55
    6 #define OWL_PERL_VOID_CALL (void)POPs;
     6/*
     7 * This macro defines a convenience wrapper around the boilerplate
     8 * of pushing char * arguments on to the stack for perl calling.
     9 *
     10 * Arguments are
     11 * * i     - the counter variable to use, which must be declared prior
     12 *           to calling this macro
     13 * * argc  - the number of arguments
     14 * * argv  - an array of char*s, of length at least argc; the arguments
     15 *           to push on to the stack
     16 */
     17#define OWL_PERL_PUSH_ARGS(i, argc, argv) { \
     18  for (i = 0; i < argc; i++) { \
     19    XPUSHs(sv_2mortal(owl_new_sv(argv[i]))); \
     20  } \
     21}
    722
    823/*
    924 * This macro defines a convenience wrapper around the boilerplate of
    10  * calling a method on a perl object (SV*) from C.
     25 * the perlcall methods.
    1126 *
    1227 * Arguments are
    13  * * obj    - the SV* to call the method on
    14  * * meth   - a char* method name
    15  * * args   - a code block responsible for pushing args (other than the object)
    16  * * err    - a string with a %s format specifier to log in case of error
    17  * * fatalp - if true, perl errors terminate BarnOwl
    18  * * ret    - a code block executed if the call succeeded
     28 * * call       - the line of code to make the perl call
     29 * * args       - a code block responsible for pushing args
     30 * * err        - a string with a %s format specifier to log in case of error
     31 * * fatalp     - if true, perl errors terminate BarnOwl
     32 * * discardret - should be true if no return is expected
     33 *                (if the call is passed the flag G_DISCARD or G_VOID)
     34 * * ret        - a code block executed if the call succeeded
    1935 *
    2036 * See also: `perldoc perlcall', `perldoc perlapi'
    2137 */
    22 #define OWL_PERL_CALL_METHOD(obj, meth, args, err, fatalp, ret) { \
    23     int count; \
    24     dSP; \
    25     ENTER; \
    26     SAVETMPS; \
    27     PUSHMARK(SP); \
    28     XPUSHs(obj); \
    29     {args} \
    30     PUTBACK; \
    31     \
    32     count = call_method(meth, G_SCALAR|G_EVAL); \
    33     \
    34     SPAGAIN; \
    35     \
    36     if(count != 1) { \
    37       fprintf(stderr, "perl returned wrong count: %d\n", count); \
    38       abort();                                                   \
     38#define OWL_PERL_CALL(call, args, err, fatalp, discardret, ret) { \
     39  int count; \
     40  dSP; \
     41  \
     42  ENTER; \
     43  SAVETMPS; \
     44  \
     45  PUSHMARK(SP); \
     46  {args} \
     47  PUTBACK; \
     48  \
     49  count = call; \
     50  \
     51  SPAGAIN; \
     52  \
     53  if (!discardret && count != 1) { \
     54    croak("Perl returned wrong count: %d\n", count); \
     55  } \
     56  \
     57  if (SvTRUE(ERRSV)) { \
     58    if (fatalp) { \
     59      fprintf(stderr, err, SvPV_nolen(ERRSV)); \
     60      exit(-1); \
     61    } else { \
     62      owl_function_error(err, SvPV_nolen(ERRSV)); \
     63      if (!discardret) (void)POPs; \
     64      sv_setsv(ERRSV, &PL_sv_undef); \
    3965    } \
    40     if (SvTRUE(ERRSV)) { \
    41       if(fatalp) { \
    42         printf(err, SvPV_nolen(ERRSV)); \
    43         exit(-1); \
    44       } else { \
    45         owl_function_error(err, SvPV_nolen(ERRSV)); \
    46         (void)POPs; \
    47         sv_setsv(ERRSV, &PL_sv_undef); \
    48       } \
    49     } else { \
    50       ret; \
    51     } \
    52     PUTBACK; \
    53     FREETMPS; \
    54     LEAVE; \
     66  } else if (!discardret) { \
     67    ret; \
     68  } \
     69  PUTBACK; \
     70  FREETMPS; \
     71  LEAVE; \
    5572}
    5673
  • perl/lib/BarnOwl/Hooks.pm

    rb8a3e00 r6df57d4  
    5757from every function registered with this hook will be appended and
    5858displayed in a popup window, with zephyr formatting parsed.
     59
     60=item $awayOn
     61
     62Called, for all protocol handlers, to go away, with the away message,
     63if any.
     64
     65=item $awayOff
     66
     67Called, for all protocol handlers, to come back from away.
     68
     69=item $getIsAway
     70
     71Called to check away status for all protocol handlers.  Protocol
     72handlers should return a true value if any account of the user is away
     73for the given protocol, and a false value otherwise.
    5974
    6075=item $getQuickstart
     
    7590                    $receiveMessage $newMessage
    7691                    $mainLoop $getBuddyList
    77                     $getQuickstart);
     92                    $getQuickstart
     93                    $awayOn $awayOff $getIsAway);
    7894
    7995our %EXPORT_TAGS = (all => [@EXPORT_OK]);
     
    88104our $getBuddyList = BarnOwl::Hook->new;
    89105our $getQuickstart = BarnOwl::Hook->new;
     106our $awayOn = BarnOwl::Hook->new;
     107our $awayOff = BarnOwl::Hook->new;
     108our $getIsAway = BarnOwl::Hook->new;
    90109
    91110# Internal startup/shutdown routines called by the C code
     
    201220}
    202221
     222sub _away_on {
     223    $awayOn->run(@_);
     224}
     225
     226sub _away_off {
     227    $awayOff->run();
     228}
     229
     230sub _get_is_away {
     231    my @is_away = grep { $_ } $getIsAway->run();
     232    return scalar @is_away;
     233}
     234
    203235sub _new_command {
    204236    my $command = shift;
  • perlconfig.c

    r7803326 r57ad328  
    224224CALLER_OWN char *owl_perlconfig_call_with_message(const char *subname, const owl_message *m)
    225225{
    226   dSP ;
    227   int count;
    228   SV *msgref, *srv;
    229   char *out;
    230  
    231   ENTER ;
    232   SAVETMPS;
    233  
    234   PUSHMARK(SP) ;
     226  SV *msgref, *rv;
     227  char *out = NULL;
     228
    235229  msgref = owl_perlconfig_message2hashref(m);
    236   XPUSHs(sv_2mortal(msgref));
    237   PUTBACK ;
    238  
    239   count = call_pv(subname, G_SCALAR|G_EVAL);
    240  
    241   SPAGAIN ;
    242 
    243   if (SvTRUE(ERRSV)) {
    244     owl_function_error("Perl Error: '%s'", SvPV_nolen(ERRSV));
    245     /* and clear the error */
    246     sv_setsv (ERRSV, &PL_sv_undef);
    247   }
    248 
    249   if (count != 1) {
    250     fprintf(stderr, "bad perl!  no biscuit!  returned wrong count!\n");
    251     abort();
    252   }
    253 
    254   srv = POPs;
    255 
    256   if (srv) {
    257     out = g_strdup(SvPV_nolen(srv));
    258   } else {
    259     out = NULL;
    260   }
    261  
    262   PUTBACK ;
    263   FREETMPS ;
    264   LEAVE ;
    265 
     230
     231  OWL_PERL_CALL((call_pv(subname, G_SCALAR|G_EVAL))
     232                ,
     233                XPUSHs(sv_2mortal(msgref));
     234                ,
     235                "Perl Error: '%s'"
     236                ,
     237                false
     238                ,
     239                false
     240                ,
     241                rv = POPs;
     242                if (rv && SvPOK(rv))
     243                  out = g_strdup(SvPV_nolen(rv));
     244                );
    266245  return out;
    267246}
     
    273252CALLER_OWN char *owl_perlconfig_message_call_method(const owl_message *m, const char *method, int argc, const char **argv)
    274253{
    275   dSP;
    276   unsigned int count, i;
    277   SV *msgref, *srv;
    278   char *out;
     254  SV *msgref, *rv;
     255  char *out = NULL;
     256  int i;
    279257
    280258  msgref = owl_perlconfig_message2hashref(m);
    281259
    282   ENTER;
    283   SAVETMPS;
    284 
    285   PUSHMARK(SP);
    286   XPUSHs(sv_2mortal(msgref));
    287   for(i=0;i<argc;i++) {
    288     XPUSHs(sv_2mortal(owl_new_sv(argv[i])));
    289   }
    290   PUTBACK;
    291 
    292   count = call_method(method, G_SCALAR|G_EVAL);
    293 
    294   SPAGAIN;
    295 
    296   if(count != 1) {
    297     fprintf(stderr, "perl returned wrong count %u\n", count);
    298     abort();
    299   }
    300 
    301   if (SvTRUE(ERRSV)) {
    302     owl_function_error("Error: '%s'", SvPV_nolen(ERRSV));
    303     /* and clear the error */
    304     sv_setsv (ERRSV, &PL_sv_undef);
    305   }
    306 
    307   srv = POPs;
    308 
    309   if (srv) {
    310     out = g_strdup(SvPV_nolen(srv));
    311   } else {
    312     out = NULL;
    313   }
    314 
    315   PUTBACK;
    316   FREETMPS;
    317   LEAVE;
    318 
     260  OWL_PERL_CALL(call_method(method, G_SCALAR|G_EVAL)
     261                ,
     262                XPUSHs(sv_2mortal(msgref));
     263                OWL_PERL_PUSH_ARGS(i, argc, argv);
     264                ,
     265                "Perl Error: '%s'"
     266                ,
     267                false
     268                ,
     269                false
     270                ,
     271                rv = POPs;
     272                if (rv && SvPOK(rv))
     273                  out = g_strdup(SvPV_nolen(rv));
     274                );
    319275  return out;
    320276}
     
    455411void owl_perlconfig_new_command(const char *name)
    456412{
    457   dSP;
    458 
    459   ENTER;
    460   SAVETMPS;
    461 
    462   PUSHMARK(SP);
    463   XPUSHs(sv_2mortal(owl_new_sv(name)));
    464   PUTBACK;
    465 
    466   call_pv("BarnOwl::Hooks::_new_command", G_VOID|G_EVAL);
    467 
    468   SPAGAIN;
    469 
    470   if(SvTRUE(ERRSV)) {
    471     owl_function_error("%s", SvPV_nolen(ERRSV));
    472   }
    473 
    474   FREETMPS;
    475   LEAVE;
     413  OWL_PERL_CALL(call_pv("BarnOwl::Hooks::_new_command", G_VOID|G_EVAL);
     414                ,
     415                XPUSHs(sv_2mortal(owl_new_sv(name)));
     416                ,
     417                "Perl Error: '%s'"
     418                ,
     419                false
     420                ,
     421                true
     422                ,
     423                );
     424}
     425
     426CALLER_OWN char *owl_perlconfig_perl_call(const char *method, int argc, const char *const *argv)
     427{
     428  SV *rv;
     429  char *out = NULL;
     430  int i;
     431  OWL_PERL_CALL(call_pv(method, G_SCALAR|G_EVAL)
     432                ,
     433                OWL_PERL_PUSH_ARGS(i, argc, argv);
     434                ,
     435                "Perl Error: '%s'"
     436                ,
     437                false
     438                ,
     439                false
     440                ,
     441                rv = POPs;
     442                if (rv && SvPOK(rv))
     443                  out = g_strdup(SvPV_nolen(rv));
     444                );
     445  return out;
     446}
     447
     448int owl_perlconfig_perl_call_int(const char *method, int argc, const char *const *argv)
     449{
     450  SV *rv;
     451  int ret = -1;
     452  int i;
     453  OWL_PERL_CALL(call_pv(method, G_SCALAR|G_EVAL)
     454                ,
     455                OWL_PERL_PUSH_ARGS(i, argc, argv);
     456                ,
     457                "Perl Error: '%s'"
     458                ,
     459                false
     460                ,
     461                false
     462                ,
     463                rv = POPs;
     464                if (rv && SvIOK(rv))
     465                  ret = SvIV(rv);
     466                );
     467  return ret;
     468}
     469
     470bool owl_perlconfig_perl_call_bool(const char *method, int argc, const char *const *argv)
     471{
     472  SV *rv;
     473  bool ret = false;
     474  int i;
     475  OWL_PERL_CALL(call_pv(method, G_SCALAR|G_EVAL)
     476                ,
     477                OWL_PERL_PUSH_ARGS(i, argc, argv);
     478                ,
     479                "Perl Error: '%s'"
     480                ,
     481                false
     482                ,
     483                false
     484                ,
     485                rv = POPs;
     486                if (rv)
     487                  ret = SvTRUE(rv);
     488                );
     489  return ret;
     490}
     491
     492void owl_perlconfig_perl_call_norv(const char *method, int argc, const char *const *argv)
     493{
     494  int i;
     495  OWL_PERL_CALL(call_pv(method, G_DISCARD|G_EVAL)
     496                ,
     497                OWL_PERL_PUSH_ARGS(i, argc, argv);
     498                ,
     499                "Perl Error: '%s'"
     500                ,
     501                false
     502                ,
     503                true
     504                ,
     505                );
    476506}
    477507
     
    479509CALLER_OWN char *owl_perlconfig_perlcmd(const owl_cmd *cmd, int argc, const char *const *argv)
    480510{
    481   int i, count;
    482   char * ret = NULL;
    483   SV *rv;
    484   dSP;
    485 
    486   ENTER;
    487   SAVETMPS;
    488 
    489   PUSHMARK(SP);
    490   for(i=0;i<argc;i++) {
    491     XPUSHs(sv_2mortal(owl_new_sv(argv[i])));
    492   }
    493   PUTBACK;
    494 
    495   count = call_sv(cmd->cmd_perl, G_SCALAR|G_EVAL);
    496 
    497   SPAGAIN;
    498 
    499   if(SvTRUE(ERRSV)) {
    500     owl_function_error("%s", SvPV_nolen(ERRSV));
    501     (void)POPs;
    502   } else {
    503     if(count != 1)
    504       croak("Perl command %s returned more than one value!", cmd->name);
    505     rv = POPs;
    506     if(SvTRUE(rv)) {
    507       ret = g_strdup(SvPV_nolen(rv));
    508     }
    509   }
    510 
    511   FREETMPS;
    512   LEAVE;
    513 
    514   return ret;
     511  int i;
     512  SV* rv;
     513  char *out = NULL;
     514
     515  OWL_PERL_CALL(call_sv(cmd->cmd_perl, G_SCALAR|G_EVAL)
     516                ,
     517                OWL_PERL_PUSH_ARGS(i, argc, argv);
     518                ,
     519                "Perl Error: '%s'"
     520                ,
     521                false
     522                ,
     523                false
     524                ,
     525                rv = POPs;
     526                if (rv && SvPOK(rv))
     527                  out = g_strdup(SvPV_nolen(rv));
     528                );
     529  return out;
    515530}
    516531
     
    523538{
    524539  SV *cb = owl_editwin_get_cbdata(e);
    525   SV *text;
    526   dSP;
    527 
    528   if(cb == NULL) {
     540  SV *text = owl_new_sv(owl_editwin_get_text(e));
     541
     542  if (cb == NULL) {
    529543    owl_function_error("Perl callback is NULL!");
    530544    return;
    531545  }
    532   text = owl_new_sv(owl_editwin_get_text(e));
    533 
    534   ENTER;
    535   SAVETMPS;
    536 
    537   PUSHMARK(SP);
    538   XPUSHs(sv_2mortal(text));
    539   XPUSHs(sv_2mortal(newSViv(success)));
    540   PUTBACK;
    541  
    542   call_sv(cb, G_DISCARD|G_EVAL);
    543 
    544   if(SvTRUE(ERRSV)) {
    545     owl_function_error("%s", SvPV_nolen(ERRSV));
    546   }
    547 
    548   FREETMPS;
    549   LEAVE;
     546
     547  OWL_PERL_CALL(call_sv(cb, G_DISCARD|G_EVAL)
     548                ,
     549                XPUSHs(sv_2mortal(text));
     550                XPUSHs(sv_2mortal(newSViv(success)));
     551                ,
     552                "Perl Error: '%s'"
     553                ,
     554                false
     555                ,
     556                true
     557                ,
     558                );
    550559}
    551560
  • sepbar.c

    r6eb3ed9 r6df57d4  
    6767  }
    6868
    69   if (owl_global_is_zaway(&g) || owl_global_is_aaway(&g)) {
     69  if (owl_function_is_away()) {
    7070    getyx(sepwin, y, x);
    7171    wmove(sepwin, y, x+2);
    7272    wattron(sepwin, A_BOLD);
    7373    wattroff(sepwin, A_REVERSE);
    74     if (owl_global_is_zaway(&g) && owl_global_is_aaway(&g)) {
    75       waddstr(sepwin, " AWAY ");
    76     } else if (owl_global_is_zaway(&g)) {
    77       waddstr(sepwin, " Z-AWAY ");
    78     } else if (owl_global_is_aaway(&g)) {
    79       waddstr(sepwin, " A-AWAY ");
    80     }
     74    waddstr(sepwin, " AWAY ");
    8175    wattron(sepwin, A_REVERSE);
    8276    wattroff(sepwin, A_BOLD);
  • style.c

    r14be3a5 r0c71c58  
    2323{
    2424  SV *sv = NULL;
    25   OWL_PERL_CALL_METHOD(s->perlobj,
    26                        "description",
    27                        ;,
    28                        "Error in style_get_description: %s",
    29                        0,
    30                        sv = SvREFCNT_inc(POPs);
    31                        );
    32   if(sv) {
     25  OWL_PERL_CALL(call_method("description", G_SCALAR|G_EVAL),
     26                XPUSHs(s->perlobj);,
     27                "Error in style_get_description: %s",
     28                0,
     29                false,
     30                sv = SvREFCNT_inc(POPs);
     31                );
     32  if (sv) {
    3333    return SvPV_nolen(sv_2mortal(sv));
    3434  } else {
     
    5050 
    5151  /* Call the perl object */
    52   OWL_PERL_CALL_METHOD(s->perlobj,
    53                        "format_message",
    54                        XPUSHs(sv_2mortal(owl_perlconfig_message2hashref(m)));,
    55                        "Error in format_message: %s",
    56                        0,
    57                        sv = SvREFCNT_inc(POPs);
    58                        );
     52  OWL_PERL_CALL(call_method("format_message", G_SCALAR|G_EVAL),
     53                XPUSHs(s->perlobj);
     54                XPUSHs(sv_2mortal(owl_perlconfig_message2hashref(m)));,
     55                "Error in format_message: %s",
     56                0,
     57                false,
     58                sv = SvREFCNT_inc(POPs);
     59                );
    5960
    60   if(sv) {
     61  if (sv) {
    6162    body = SvPV_nolen(sv);
    6263  } else {
  • doc/barnowl.1

    rbad4496 r8135737  
    3535.TP
    3636\fB\-c\fP, \fB\-\-config\-file\fP=\fIFILE\fP
    37 Specify an alternate config file for \fBBarnOwl\fP to use.  By default,
    38 \fBBarnOwl\fP uses \fI~/.barnowlconf\fP if it exists, and \fI~/.owlconf\fP otherwise.
     37Specify an alternate config file for \fBBarnOwl\fP to use.  The config file is
     38an arbitrary Perl script evaluated in the \fImain\fP package, and if it
     39overrides the \fIBarnOwl::startup\fP method that is run when \fBBarnOwl\fP
     40starts.  (Compare \fI~/.owl/startup\fP, which contains \fBBarnOwl\fP commands
     41that are run at startup after the config file is loaded.)
     42
     43By default, \fBBarnOwl\fP uses the first of \fI~/.owl/init.pl\fP,
     44\fI~/.barnowlconf\fP, or \fI~/.owlconf\fP that exists.
    3945
    4046.TP
  • global.c

    r9078f69 r219f52c  
    7575  g_free(cd);
    7676
    77   owl_messagelist_create(&(g->msglist));
     77  g->msglist = owl_messagelist_new();
    7878
    7979  _owl_global_init_windows(g);
     
    109109
    110110  /* Create the widgets */
    111   owl_mainwin_init(&(g->mw), g->mainpanel.recwin);
     111  g->mw = owl_mainwin_new(g->mainpanel.recwin);
    112112  owl_msgwin_init(&(g->msgwin), g->mainpanel.msgwin);
    113113  owl_sepbar_init(g->mainpanel.sepwin);
     
    241241/* windows */
    242242
    243 owl_mainwin *owl_global_get_mainwin(owl_global *g) {
    244   return(&(g->mw));
     243owl_mainwin *owl_global_get_mainwin(owl_global *g)
     244{
     245  return g->mw;
    245246}
    246247
     
    256257
    257258owl_messagelist *owl_global_get_msglist(owl_global *g) {
    258   return(&(g->msglist));
     259  return g->msglist;
    259260}
    260261
  • mainwin.c

    r099597c rab88b05  
    44static void owl_mainwin_resized(owl_window *w, void *user_data);
    55
    6 void owl_mainwin_init(owl_mainwin *mw, owl_window *window)
     6CALLER_OWN owl_mainwin *owl_mainwin_new(owl_window *window)
    77{
     8  owl_mainwin *mw = g_new(owl_mainwin, 1);
    89  mw->curtruncated=0;
    910  mw->lastdisplayed=-1;
     
    1617  /* For now, we do not bother with connecting up dependencies; that'll be a
    1718   * future refactor of the mainwin */
     19
     20  return mw;
    1821}
    1922
  • messagelist.c

    rf271129 r219f52c  
    11#include "owl.h"
    22
    3 void owl_messagelist_create(owl_messagelist *ml)
     3CALLER_OWN owl_messagelist *owl_messagelist_new(void)
    44{
     5  owl_messagelist *ml = g_new(owl_messagelist, 1);
    56  ml->list = g_ptr_array_new();
     7  return ml;
    68}
    79
    8 void owl_messagelist_cleanup(owl_messagelist *ml, bool free_messages)
     10void owl_messagelist_delete(owl_messagelist *ml, bool free_messages)
    911{
    1012  if (free_messages)
    1113    g_ptr_array_foreach(ml->list, (GFunc)owl_message_delete, NULL);
    1214  g_ptr_array_free(ml->list, true);
     15  g_free(ml);
    1316}
    1417
  • owl.c

    r3b17b57 r8135737  
    4141  fprintf(stderr, "  -v,--version        print the Barnowl version number and exit\n");
    4242  fprintf(stderr, "  -h,--help           print this help message\n");
    43   fprintf(stderr, "  -c,--config-file    specify an alternate config file\n");
    4443  fprintf(stderr, "  -s,--config-dir     specify an alternate config dir (default ~/.owl)\n");
     44  fprintf(stderr, "  -c,--config-file    specify an alternate config file (default ~/.owl/init.pl)\n");
    4545  fprintf(stderr, "  -t,--tty            set the tty name\n");
    4646}
     
    585585  );
    586586
     587  owl_function_debugmsg("startup: setting context interactive");
     588
     589  owl_global_pop_context(&g);
     590  owl_global_push_context(&g, OWL_CTX_INTERACTIVE|OWL_CTX_RECV, NULL, "recv", NULL);
     591
    587592  /* process the startup file */
    588593  owl_function_debugmsg("startup: processing startup file");
     
    596601      owl_function_error("No such style: %s", owl_global_get_default_style(&g));
    597602
    598   owl_function_debugmsg("startup: setting context interactive");
    599 
    600   owl_global_pop_context(&g);
    601   owl_global_push_context(&g, OWL_CTX_INTERACTIVE|OWL_CTX_RECV, NULL, "recv", NULL);
    602 
    603603  source = owl_window_redraw_source_new();
    604604  g_source_attach(source, NULL);
  • owl.h

    rb9517cf r219f52c  
    452452  char *name;
    453453  owl_filter *filter;
    454   owl_messagelist ml;
     454  owl_messagelist *ml;
    455455  const owl_style *style;
    456456  int cachedmsgid;
     
    533533
    534534typedef struct _owl_global {
    535   owl_mainwin mw;
     535  owl_mainwin *mw;
    536536  owl_popwin *pw;
    537537  owl_msgwin msgwin;
     
    551551  int curmsg_vert_offset;
    552552  owl_view current_view;
    553   owl_messagelist msglist;
     553  owl_messagelist *msglist;
    554554  WINDOW *input_pad;
    555555  owl_mainpanel mainpanel;
  • perl/lib/BarnOwl.pm

    r7803326 r8135737  
    329329our @all_commands;
    330330
    331 if(!$configfile && -f $ENV{HOME} . "/.barnowlconf") {
    332     $configfile = $ENV{HOME} . "/.barnowlconf";
    333 }
    334 $configfile ||= $ENV{HOME}."/.owlconf";
     331if(!$configfile) {
     332    if (-f get_config_dir() . "/init.pl") {
     333        $configfile = get_config_dir() . "/init.pl";
     334    } elsif (-f $ENV{HOME} . "/.barnowlconf") {
     335        $configfile = $ENV{HOME} . "/.barnowlconf";
     336    } else {
     337        $configfile = $ENV{HOME}."/.owlconf";
     338    }
     339}
    335340
    336341# populate global variable space for legacy owlconf files
  • perl/lib/BarnOwl/ModuleLoader.pm

    rf544216 rf34728b  
    127127}
    128128
     129sub complete_module_name {
     130    return sort(keys %modules);
     131}
     132
    129133sub register_keybindings {
    130134    BarnOwl::new_command('reload-modules', sub {BarnOwl::ModuleLoader->reload}, {
     
    138142                           description => q{Reloads a single module located in ~/.owl/modules or the system modules directory}
    139143                          });
     144
     145    BarnOwl::Completion::register_completer('reload-module', \&complete_module_name);
    140146}
    141147
  • perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm

    rb8a3e00 r678f607  
    14821482}
    14831483
     1484sub complete_jabberlogout {
     1485    my $ctx = shift;
     1486    if($ctx->word == 1) {
     1487        return ("-A", complete_account() );
     1488    } else {
     1489        return ();
     1490    }
     1491}
     1492
    14841493BarnOwl::Completion::register_completer(jwrite => sub { BarnOwl::Module::Jabber::complete_jwrite(@_) });
     1494BarnOwl::Completion::register_completer(jabberlogout => sub { BarnOwl::Module::Jabber::complete_jabberlogout(@_) });
    14851495
    148614961;
  • util.c

    r6646fdb r7b89e8c  
    262262CALLER_OWN char *owl_arg_quote(const char *arg)
    263263{
    264   GString *buf = g_string_new("");;
     264  GString *buf = g_string_new("");
    265265  owl_string_append_quoted_arg(buf, arg);
     266  return g_string_free(buf, false);
     267}
     268
     269/* Returns a quoted version of argv. owl_parseline on the result should give
     270 * back the input. */
     271CALLER_OWN char *owl_argv_quote(int argc, const char *const *argv)
     272{
     273  int i;
     274  GString *buf = g_string_new("");
     275  for (i = 0; i < argc; i++) {
     276    if (i > 0)
     277      g_string_append_c(buf, ' ');
     278    owl_string_append_quoted_arg(buf, argv[i]);
     279  }
    266280  return g_string_free(buf, false);
    267281}
  • variable.c

    rf271129 rd126a19  
    116116               "both,in,out"),
    117117
    118   OWLVAR_BOOL( "colorztext" /* %OwlVarStub */, 1,
    119                "allow @color() in zephyrs to change color",
    120                "Note that only messages received after this variable\n"
    121                "is set will be affected." ),
     118  OWLVAR_BOOL_FULL( "colorztext" /* %OwlVarStub */, 1,
     119                    "allow @color() in zephyrs to change color",
     120                    NULL, NULL, owl_variable_colorztext_set, NULL),
    122121
    123122  OWLVAR_BOOL( "fancylines" /* %OwlVarStub */, 1,
     
    496495  }
    497496  return owl_variable_bool_set_default(v, newval);
     497}
     498
     499int owl_variable_colorztext_set(owl_variable *v, const void *newval)
     500{
     501  int ret = owl_variable_bool_set_default(v, newval);
     502  /* flush the format cache so that we see the update, but only if we're done initializing BarnOwl */
     503  if (owl_global_get_msglist(&g) != NULL)
     504    owl_messagelist_invalidate_formats(owl_global_get_msglist(&g));
     505  if (owl_global_get_mainwin(&g) != NULL) {
     506    owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS);
     507    owl_mainwin_redisplay(owl_global_get_mainwin(&g));
     508  }
     509  return ret;
    498510}
    499511
  • view.c

    rf271129 r219f52c  
    66  v->filter=f;
    77  v->style=s;
    8   owl_messagelist_create(&(v->ml));
     8  v->ml = owl_messagelist_new();
    99  owl_view_recalculate(v);
    1010}
     
    1919{
    2020  if (owl_filter_message_match(v->filter, m)) {
    21     owl_messagelist_append_element(&(v->ml), m);
     21    owl_messagelist_append_element(v->ml, m);
    2222  }
    2323}
     
    3030  int i, j;
    3131  const owl_messagelist *gml;
    32   owl_messagelist *ml;
    3332  owl_message *m;
    3433
    3534  gml=owl_global_get_msglist(&g);
    36   ml=&(v->ml);
    3735
    3836  /* nuke the old list, don't free the messages */
    39   owl_messagelist_cleanup(ml, false);
    40   owl_messagelist_create(&(v->ml));
     37  owl_messagelist_delete(v->ml, false);
     38  v->ml = owl_messagelist_new();
    4139
    4240  /* find all the messages we want */
     
    4543    m=owl_messagelist_get_element(gml, i);
    4644    if (owl_filter_message_match(v->filter, m)) {
    47       owl_messagelist_append_element(ml, m);
     45      owl_messagelist_append_element(v->ml, m);
    4846    }
    4947  }
     
    7270owl_message *owl_view_get_element(const owl_view *v, int index)
    7371{
    74   return(owl_messagelist_get_element(&(v->ml), index));
     72  return owl_messagelist_get_element(v->ml, index);
    7573}
    7674
    7775void owl_view_delete_element(owl_view *v, int index)
    7876{
    79   owl_messagelist_delete_element(&(v->ml), index);
     77  owl_messagelist_delete_element(v->ml, index);
    8078}
    8179
    8280void owl_view_undelete_element(owl_view *v, int index)
    8381{
    84   owl_messagelist_undelete_element(&(v->ml), index);
     82  owl_messagelist_undelete_element(v->ml, index);
    8583}
    8684
    8785int owl_view_get_size(const owl_view *v)
    8886{
    89   return(owl_messagelist_get_size(&(v->ml)));
     87  return owl_messagelist_get_size(v->ml);
    9088}
    9189
     
    158156void owl_view_cleanup(owl_view *v)
    159157{
    160   owl_messagelist_cleanup(&v->ml, false);
     158  owl_messagelist_delete(v->ml, false);
    161159  g_free(v->name);
    162160}
  • zephyr.c

    rf271129 rd953ede  
    909909  g_free(to);
    910910
    911   z = owl_zwrite_new(tmpbuff);
     911  z = owl_zwrite_new_from_line(tmpbuff);
    912912  g_free(tmpbuff);
    913913  if (z == NULL) {
  • zwrite.c

    rf271129 ref4074b  
    11#include "owl.h"
    22
    3 CALLER_OWN owl_zwrite *owl_zwrite_new(const char *line)
     3CALLER_OWN owl_zwrite *owl_zwrite_new_from_line(const char *line)
    44{
    55  owl_zwrite *z = g_new(owl_zwrite, 1);
    6   if (owl_zwrite_create_from_line(z, line) < 0) {
    7     owl_zwrite_delete(z);
     6  if (owl_zwrite_create_from_line(z, line) != 0) {
     7    g_free(z);
    88    return NULL;
    99  }
     
    1111}
    1212
     13CALLER_OWN owl_zwrite *owl_zwrite_new(int argc, const char *const *argv)
     14{
     15  owl_zwrite *z = g_new(owl_zwrite, 1);
     16  if (owl_zwrite_create(z, argc, argv) != 0) {
     17    g_free(z);
     18    return NULL;
     19  }
     20  return z;
     21}
     22
    1323G_GNUC_WARN_UNUSED_RESULT int owl_zwrite_create_from_line(owl_zwrite *z, const char *line)
    1424{
    15   int argc, badargs, myargc;
     25  int argc;
    1626  char **argv;
    17   const char *const *myargv;
     27  int ret;
     28
     29  /* parse the command line for options */
     30  argv = owl_parseline(line, &argc);
     31  if (argc < 0) {
     32    owl_function_error("Unbalanced quotes in zwrite");
     33    return -1;
     34  }
     35  ret = owl_zwrite_create(z, argc, strs(argv));
     36  g_strfreev(argv);
     37  return ret;
     38}
     39
     40G_GNUC_WARN_UNUSED_RESULT int owl_zwrite_create(owl_zwrite *z, int argc, const char *const *argv)
     41{
     42  int badargs = 0;
    1843  char *msg = NULL;
    19 
    20   badargs=0;
    2144 
    2245  /* start with null entries */
     
    3154  z->noping=0;
    3255  z->recips = g_ptr_array_new();
    33   z->zwriteline = g_strdup(line);
    34 
    35   /* parse the command line for options */
    36   argv=owl_parseline(line, &argc);
    37   myargv=strs(argv);
    38   if (argc<0) {
    39     owl_function_error("Unbalanced quotes in zwrite");
    40     return(-1);
    41   }
    42   myargc=argc;
    43   if (myargc && *(myargv[0])!='-') {
    44     z->cmd=g_strdup(myargv[0]);
    45     myargc--;
    46     myargv++;
    47   }
    48   while (myargc) {
    49     if (!strcmp(myargv[0], "-c")) {
    50       if (myargc<2) {
    51         badargs=1;
    52         break;
    53       }
    54       z->class=owl_validate_utf8(myargv[1]);
    55       myargv+=2;
    56       myargc-=2;
    57     } else if (!strcmp(myargv[0], "-i")) {
    58       if (myargc<2) {
    59         badargs=1;
    60         break;
    61       }
    62       z->inst=owl_validate_utf8(myargv[1]);
    63       myargv+=2;
    64       myargc-=2;
    65     } else if (!strcmp(myargv[0], "-r")) {
    66       if (myargc<2) {
    67         badargs=1;
    68         break;
    69       }
    70       z->realm=owl_validate_utf8(myargv[1]);
    71       myargv+=2;
    72       myargc-=2;
    73     } else if (!strcmp(myargv[0], "-s")) {
    74       if (myargc<2) {
    75         badargs=1;
    76         break;
    77       }
    78       z->zsig=owl_validate_utf8(myargv[1]);
    79       myargv+=2;
    80       myargc-=2;
    81     } else if (!strcmp(myargv[0], "-O")) {
    82       if (myargc<2) {
    83         badargs=1;
    84         break;
    85       }
    86       z->opcode=owl_validate_utf8(myargv[1]);
    87       myargv+=2;
    88       myargc-=2;
    89     } else if (!strcmp(myargv[0], "-m")) {
    90       if (myargc<2) {
     56  z->zwriteline = owl_argv_quote(argc, argv);
     57
     58  if (argc && *(argv[0])!='-') {
     59    z->cmd=g_strdup(argv[0]);
     60    argc--;
     61    argv++;
     62  }
     63  while (argc) {
     64    if (!strcmp(argv[0], "-c")) {
     65      if (argc<2) {
     66        badargs=1;
     67        break;
     68      }
     69      z->class=owl_validate_utf8(argv[1]);
     70      argv+=2;
     71      argc-=2;
     72    } else if (!strcmp(argv[0], "-i")) {
     73      if (argc<2) {
     74        badargs=1;
     75        break;
     76      }
     77      z->inst=owl_validate_utf8(argv[1]);
     78      argv+=2;
     79      argc-=2;
     80    } else if (!strcmp(argv[0], "-r")) {
     81      if (argc<2) {
     82        badargs=1;
     83        break;
     84      }
     85      z->realm=owl_validate_utf8(argv[1]);
     86      argv+=2;
     87      argc-=2;
     88    } else if (!strcmp(argv[0], "-s")) {
     89      if (argc<2) {
     90        badargs=1;
     91        break;
     92      }
     93      z->zsig=owl_validate_utf8(argv[1]);
     94      argv+=2;
     95      argc-=2;
     96    } else if (!strcmp(argv[0], "-O")) {
     97      if (argc<2) {
     98        badargs=1;
     99        break;
     100      }
     101      z->opcode=owl_validate_utf8(argv[1]);
     102      argv+=2;
     103      argc-=2;
     104    } else if (!strcmp(argv[0], "-m")) {
     105      if (argc<2) {
    91106        badargs=1;
    92107        break;
     
    99114
    100115      /* Once we have -m, gobble up everything else on the line */
    101       myargv++;
    102       myargc--;
    103       msg = g_strjoinv(" ", (char**)myargv);
     116      argv++;
     117      argc--;
     118      msg = g_strjoinv(" ", (char**)argv);
    104119      break;
    105     } else if (!strcmp(myargv[0], "-C")) {
     120    } else if (!strcmp(argv[0], "-C")) {
    106121      z->cc=1;
    107       myargv++;
    108       myargc--;
    109     } else if (!strcmp(myargv[0], "-n")) {
     122      argv++;
     123      argc--;
     124    } else if (!strcmp(argv[0], "-n")) {
    110125      z->noping=1;
    111       myargv++;
    112       myargc--;
     126      argv++;
     127      argc--;
    113128    } else {
    114129      /* anything unattached is a recipient */
    115       g_ptr_array_add(z->recips, owl_validate_utf8(myargv[0]));
    116       myargv++;
    117       myargc--;
     130      g_ptr_array_add(z->recips, owl_validate_utf8(argv[0]));
     131      argv++;
     132      argc--;
    118133    }
    119134  }
    120135
    121   g_strfreev(argv);
    122 
    123136  if (badargs) {
     137    owl_zwrite_cleanup(z);
    124138    return(-1);
    125139  }
     
    129143      z->recips->len == 0) {
    130144    owl_function_error("You must specify a recipient for zwrite");
     145    owl_zwrite_cleanup(z);
    131146    return(-1);
    132147  }
     
    254269  owl_zwrite z;
    255270  int rv;
    256   rv=owl_zwrite_create_from_line(&z, cmd);
    257   if (rv) return(rv);
     271  rv = owl_zwrite_create_from_line(&z, cmd);
     272  if (rv != 0) return rv;
    258273  if (!owl_zwrite_is_message_set(&z)) {
    259274    owl_zwrite_set_message(&z, msg);
Note: See TracChangeset for help on using the changeset viewer.