Changeset bdbec0a for functions.c


Ignore:
Timestamp:
Oct 23, 2009, 3:49:11 PM (12 years ago)
Author:
Karl Ramm <kcr@1ts.org>
Branches:
master, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
b644688
Parents:
fb7742c
git-author:
Karl Ramm <kcr@1ts.org> (09/25/09 11:18:41)
git-committer:
Karl Ramm <kcr@1ts.org> (10/23/09 15:49:11)
Message:
refactor and clean owl editwin startup functions

Take function.c:owl_function_{z,aim}write_setup and perlglue.xs:start_edit_win,
and collide at .8c producing owl_function_write_setup which calls
owl_function_start_edit_win.

(Also ditching another three fugly char[1024]s)

Really, this ought to be in perl.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    rb7ee89b rbdbec0a  
    281281}
    282282
     283void owl_function_start_edit_win(const char *line, void (*callback)(owl_editwin *), void *data)
     284{
     285  owl_editwin *e;
     286  char *s;
     287
     288  /* create and setup the editwin */
     289  e = owl_global_get_typwin(&g);
     290  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE,
     291                        owl_global_get_msg_history(&g));
     292  owl_editwin_clear(e);
     293  owl_editwin_set_dotsend(e);
     294  s = owl_sprintf("----> %s\n", line);
     295  owl_editwin_set_locktext(e, s);
     296  owl_free(s);
     297
     298  /* make it active */
     299  owl_global_set_typwin_active(&g);
     300
     301  owl_editwin_set_cbdata(owl_global_get_typwin(&g), data);
     302  owl_global_set_buffercallback(&g, callback);
     303}
     304
     305static void owl_function_write_setup(const char *line, const char *noun, void (*callback)(owl_editwin *))
     306{
     307
     308  if (!owl_global_get_lockout_ctrld(&g))
     309    owl_function_makemsg("Type your %s below.  "
     310                         "End with ^D or a dot on a line by itself."
     311                         "  ^C will quit.", noun);
     312  else
     313    owl_function_makemsg("Type your %s below.  "
     314                         "End with a dot on a line by itself.  ^C will quit.",
     315                         noun);
     316
     317  owl_function_start_edit_win(line, callback, NULL);
     318  owl_global_set_buffercommand(&g, line);
     319}
     320
    283321void owl_function_zwrite_setup(const char *line)
    284322{
    285   owl_editwin *e;
    286   char buff[1024];
    287323  owl_zwrite z;
    288324  int ret;
     
    302338  owl_zwrite_free(&z);
    303339
    304   /* create and setup the editwin */
    305   e=owl_global_get_typwin(&g);
    306   owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE, owl_global_get_msg_history(&g));
    307 
    308   if (!owl_global_get_lockout_ctrld(&g)) {
    309     owl_function_makemsg("Type your zephyr below.  End with ^D or a dot on a line by itself.  ^C will quit.");
    310   } else {
    311     owl_function_makemsg("Type your zephyr below.  End with a dot on a line by itself.  ^C will quit.");
    312   }
    313 
    314   owl_editwin_clear(e);
    315   owl_editwin_set_dotsend(e);
    316   strcpy(buff, "----> ");
    317   strncat(buff, line, 1016);
    318   strcat(buff, "\n");
    319   owl_editwin_set_locktext(e, buff);
    320 
    321   /* make it active */
    322   owl_global_set_typwin_active(&g);
    323 
    324   owl_global_set_buffercommand(&g, line);
    325   owl_global_set_buffercallback(&g, &owl_callback_zwrite);
     340  owl_function_write_setup(line, "zephyr", &owl_callback_zwrite);
    326341}
    327342
    328343void owl_function_aimwrite_setup(const char *line)
    329344{
    330   owl_editwin *e;
    331   char buff[1024];
    332 
    333   /* check the arguments */
    334 
    335   /* create and setup the editwin */
    336   e=owl_global_get_typwin(&g);
    337   owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE, owl_global_get_msg_history(&g));
    338 
    339   if (!owl_global_get_lockout_ctrld(&g)) {
    340     owl_function_makemsg("Type your message below.  End with ^D or a dot on a line by itself.  ^C will quit.");
    341   } else {
    342     owl_function_makemsg("Type your message below.  End with a dot on a line by itself.  ^C will quit.");
    343   }
    344 
    345   owl_editwin_clear(e);
    346   owl_editwin_set_dotsend(e);
    347   strcpy(buff, "----> ");
    348   strcat(buff, line);
    349   strcat(buff, "\n");
    350   owl_editwin_set_locktext(e, buff);
    351 
    352   /* make it active */
    353   owl_global_set_typwin_active(&g);
    354 
    355   owl_global_set_buffercommand(&g, line);
    356   owl_global_set_buffercallback(&g, &owl_callback_aimwrite);
     345  owl_function_write_setup(line, "message", &owl_callback_aimwrite);
    357346}
    358347
Note: See TracChangeset for help on using the changeset viewer.