Changeset 3f82515


Ignore:
Timestamp:
Feb 10, 2011, 9:08:33 PM (13 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.8, release-1.9
Children:
edd0be7
Parents:
6965867
git-author:
David Benjamin <davidben@mit.edu> (01/24/11 17:33:31)
git-committer:
David Benjamin <davidben@mit.edu> (02/10/11 21:08:33)
Message:
Rewrite aimwrite

This now makes more gratuitous use of glib and should, as a bonus, be
more sensible. In particular, we now consistently handle multi-word
recipients with and without -m. Also avoid duplicating sending code.
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    rdfe5829 r3f82515  
    19741974char *owl_command_aimwrite(int argc, const char *const *argv, const char *buff)
    19751975{
    1976   char *newbuff, *recip;
     1976  char *message = NULL;
     1977  GString *recip = g_string_new("");
    19771978  const char *const *myargv;
    1978   int i, j, myargc;
    1979   owl_message *m;
     1979  int myargc;
    19801980 
    19811981  if (!owl_global_is_aimloggedin(&g)) {
    1982     owl_function_makemsg("You are not logged in to AIM.");
    1983     return(NULL);
    1984   }
    1985 
    1986   if (argc < 2) {
    1987     owl_function_makemsg("Not enough arguments to the aimwrite command.");
    1988     return(NULL);
    1989   }
    1990 
    1991   myargv=argv;
    1992   if (argc<0) {
    1993     owl_function_error("Unbalanced quotes in aimwrite");
    1994     return(NULL);
    1995   }
    1996   myargc=argc;
    1997   if (myargc && *(myargv[0])!='-') {
    1998     myargc--;
    1999     myargv++;
    2000   }
     1982    owl_function_error("You are not logged in to AIM.");
     1983    goto err;
     1984  }
     1985
     1986  /* Skip argv[0]. */
     1987  myargv = argv+1;
     1988  myargc = argc-1;
    20011989  while (myargc) {
    20021990    if (!strcmp(myargv[0], "-m")) {
    2003       if (myargc<2) {
    2004         break;
     1991      if (myargc <= 1) {
     1992        owl_function_error("No message specified.");
     1993        goto err;
    20051994      }
    2006 
    20071995      /* Once we have -m, gobble up everything else on the line */
    20081996      myargv++;
    20091997      myargc--;
    2010       newbuff=owl_strdup("");
    2011       while (myargc) {
    2012         newbuff=owl_realloc(newbuff, strlen(newbuff)+strlen(myargv[0])+5);
    2013         strcat(newbuff, myargv[0]);
    2014         strcat(newbuff, " ");
    2015         myargc--;
    2016         myargv++;
    2017       }
    2018       if (strlen(newbuff) >= 1)
    2019         newbuff[strlen(newbuff) - 1] = '\0'; /* remove last space */
    2020 
    2021       recip=owl_strdup(argv[1]);
    2022       owl_aim_send_im(recip, newbuff);
    2023       m=owl_function_make_outgoing_aim(newbuff, recip);
    2024       if (m) {
    2025           owl_global_messagequeue_addmsg(&g, m);
    2026       } else {
    2027           owl_function_error("Could not create outgoing AIM message");
    2028       }
    2029 
    2030       owl_free(recip);
    2031       owl_free(newbuff);
    2032       return(NULL);
     1998      message = g_strjoinv(" ", (char**)myargv);
     1999      break;
    20332000    } else {
    2034       /* we don't care */
     2001      /* squish arguments together to make one screenname w/o spaces for now */
     2002      g_string_append(recip, myargv[0]);
    20352003      myargv++;
    20362004      myargc--;
     
    20382006  }
    20392007
    2040   /* squish arguments together to make one screenname w/o spaces for now */
    2041   newbuff=owl_malloc(strlen(buff)+5);
    2042   sprintf(newbuff, "%s ", argv[0]);
    2043   j=argc-1;
    2044   for (i=0; i<j; i++) {
    2045     strcat(newbuff, argv[i+1]);
    2046   }
    2047    
    2048   owl_function_aimwrite_setup(newbuff);
    2049   owl_free(newbuff);
    2050   return(NULL);
     2008  if (recip->str[0] == '\0') {
     2009    owl_function_error("No recipient specified");
     2010    goto err;
     2011  }
     2012
     2013  if (message != NULL)
     2014    owl_function_aimwrite(recip->str, message, false);
     2015  else
     2016    owl_function_aimwrite_setup(recip->str);
     2017 err:
     2018  g_string_free(recip, true);
     2019  owl_free(message);
     2020  return NULL;
    20512021}
    20522022
  • functions.c

    r9de316d1 r3f82515  
    350350}
    351351
    352 void owl_function_aimwrite_setup(const char *line)
    353 {
     352void owl_function_aimwrite_setup(const char *to)
     353{
     354  /* TODO: We probably actually want an owl_aimwrite object like
     355   * owl_zwrite. */
     356  char *line = owl_sprintf("aimwrite %s", to);
    354357  owl_function_write_setup("message");
    355358  owl_function_start_edit_win(line,
    356359                              &owl_callback_aimwrite,
    357                               owl_strdup(line),
     360                              owl_strdup(to),
    358361                              owl_free);
    359 
     362  owl_free(line);
    360363}
    361364
     
    477480
    478481void owl_callback_aimwrite(owl_editwin *e) {
    479   char *command = owl_editwin_get_cbdata(e);
    480   owl_function_aimwrite(command,
    481                         owl_editwin_get_text(e));
    482 }
    483 
    484 void owl_function_aimwrite(const char *line, const char *msg)
     482  char *to = owl_editwin_get_cbdata(e);
     483  owl_function_aimwrite(to, owl_editwin_get_text(e), true);
     484}
     485
     486void owl_function_aimwrite(const char *to, const char *msg, bool unwrap)
    485487{
    486488  int ret;
    487   const char *to;
    488489  char *format_msg;
    489490  owl_message *m;
    490491
    491   to = line + 9;
    492 
    493492  /* make a formatted copy of the message */
    494   format_msg=owl_strdup(msg);
    495   owl_text_wordunwrap(format_msg);
     493  format_msg = owl_strdup(msg);
     494  if (unwrap)
     495    owl_text_wordunwrap(format_msg);
    496496 
    497497  /* send the message */
Note: See TracChangeset for help on using the changeset viewer.