Changeset d6c2e03


Ignore:
Timestamp:
Sep 30, 2011, 9:32:19 PM (10 years ago)
Author:
David Benjamin <davidben@mit.edu>
Children:
2dd9c48
Parents:
7b89e8c
git-author:
David Benjamin <davidben@mit.edu> (09/30/11 20:48:57)
git-committer:
David Benjamin <davidben@mit.edu> (09/30/11 21:32:19)
Message:
Allow building a zwrite from an argv

Add new versions of owl_zwrite_create and owl_zwrite_new. Note that this
means we rebuild z->zwriteline from scratch unconditionally. The only
behavior change is that the user's spacing and quoting is not preserved
in zwrite locktext.  For instance

  :zwrite     davidben       -i   "spaces yay?"

now gets a locktext of

  ----> zwrite davidben -i 'spaces yay?'

I think this isn't a big deal. It already happens for every other *write
locktext, and if we kill the buff argument, it'll happen there too.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • zwrite.c

    rd953ede rd6c2e03  
    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    owl_zwrite_delete(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;
     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, myargc;
    1743  const char *const *myargv;
    1844  char *msg = NULL;
     
    3157  z->noping=0;
    3258  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;
     59  z->zwriteline = owl_argv_quote(argc, argv);
     60
     61  myargc = argc;
     62  myargv = argv;
    4363  if (myargc && *(myargv[0])!='-') {
    4464    z->cmd=g_strdup(myargv[0]);
     
    119139  }
    120140
    121   g_strfreev(argv);
    122 
    123141  if (badargs) {
    124142    return(-1);
Note: See TracChangeset for help on using the changeset viewer.