Index: zwrite.c
===================================================================
--- zwrite.c	(revision d953ede767fb537e3eacf7d9962809191ec38c5c)
+++ zwrite.c	(revision 6329cd5136a27361dedf94bb92e20fa2d327e43c)
@@ -11,12 +11,35 @@
 }
 
+CALLER_OWN owl_zwrite *owl_zwrite_new(int argc, const char *const *argv)
+{
+  owl_zwrite *z = g_new(owl_zwrite, 1);
+  if (owl_zwrite_create(z, argc, argv) < 0) {
+    owl_zwrite_delete(z);
+    return NULL;
+  }
+  return z;
+}
+
 G_GNUC_WARN_UNUSED_RESULT int owl_zwrite_create_from_line(owl_zwrite *z, const char *line)
 {
-  int argc, badargs, myargc;
+  int argc;
   char **argv;
-  const char *const *myargv;
+  int ret;
+
+  /* parse the command line for options */
+  argv = owl_parseline(line, &argc);
+  if (argc < 0) {
+    owl_function_error("Unbalanced quotes in zwrite");
+    return -1;
+  }
+  ret = owl_zwrite_create(z, argc, strs(argv));
+  g_strfreev(argv);
+  return ret;
+}
+
+G_GNUC_WARN_UNUSED_RESULT int owl_zwrite_create(owl_zwrite *z, int argc, const char *const *argv)
+{
+  int badargs = 0;
   char *msg = NULL;
-
-  badargs=0;
   
   /* start with null entries */
@@ -31,62 +54,54 @@
   z->noping=0;
   z->recips = g_ptr_array_new();
-  z->zwriteline = g_strdup(line);
-
-  /* parse the command line for options */
-  argv=owl_parseline(line, &argc);
-  myargv=strs(argv);
-  if (argc<0) {
-    owl_function_error("Unbalanced quotes in zwrite");
-    return(-1);
-  }
-  myargc=argc;
-  if (myargc && *(myargv[0])!='-') {
-    z->cmd=g_strdup(myargv[0]);
-    myargc--;
-    myargv++;
-  }
-  while (myargc) {
-    if (!strcmp(myargv[0], "-c")) {
-      if (myargc<2) {
-	badargs=1;
-	break;
-      }
-      z->class=owl_validate_utf8(myargv[1]);
-      myargv+=2;
-      myargc-=2;
-    } else if (!strcmp(myargv[0], "-i")) {
-      if (myargc<2) {
-	badargs=1;
-	break;
-      }
-      z->inst=owl_validate_utf8(myargv[1]);
-      myargv+=2;
-      myargc-=2;
-    } else if (!strcmp(myargv[0], "-r")) {
-      if (myargc<2) {
-	badargs=1;
-	break;
-      }
-      z->realm=owl_validate_utf8(myargv[1]);
-      myargv+=2;
-      myargc-=2;
-    } else if (!strcmp(myargv[0], "-s")) {
-      if (myargc<2) {
-	badargs=1;
-	break;
-      }
-      z->zsig=owl_validate_utf8(myargv[1]);
-      myargv+=2;
-      myargc-=2;
-    } else if (!strcmp(myargv[0], "-O")) {
-      if (myargc<2) {
-	badargs=1;
-	break;
-      }
-      z->opcode=owl_validate_utf8(myargv[1]);
-      myargv+=2;
-      myargc-=2;
-    } else if (!strcmp(myargv[0], "-m")) {
-      if (myargc<2) {
+  z->zwriteline = owl_argv_quote(argc, argv);
+
+  if (argc && *(argv[0])!='-') {
+    z->cmd=g_strdup(argv[0]);
+    argc--;
+    argv++;
+  }
+  while (argc) {
+    if (!strcmp(argv[0], "-c")) {
+      if (argc<2) {
+	badargs=1;
+	break;
+      }
+      z->class=owl_validate_utf8(argv[1]);
+      argv+=2;
+      argc-=2;
+    } else if (!strcmp(argv[0], "-i")) {
+      if (argc<2) {
+	badargs=1;
+	break;
+      }
+      z->inst=owl_validate_utf8(argv[1]);
+      argv+=2;
+      argc-=2;
+    } else if (!strcmp(argv[0], "-r")) {
+      if (argc<2) {
+	badargs=1;
+	break;
+      }
+      z->realm=owl_validate_utf8(argv[1]);
+      argv+=2;
+      argc-=2;
+    } else if (!strcmp(argv[0], "-s")) {
+      if (argc<2) {
+	badargs=1;
+	break;
+      }
+      z->zsig=owl_validate_utf8(argv[1]);
+      argv+=2;
+      argc-=2;
+    } else if (!strcmp(argv[0], "-O")) {
+      if (argc<2) {
+	badargs=1;
+	break;
+      }
+      z->opcode=owl_validate_utf8(argv[1]);
+      argv+=2;
+      argc-=2;
+    } else if (!strcmp(argv[0], "-m")) {
+      if (argc<2) {
 	badargs=1;
 	break;
@@ -99,25 +114,23 @@
 
       /* Once we have -m, gobble up everything else on the line */
-      myargv++;
-      myargc--;
-      msg = g_strjoinv(" ", (char**)myargv);
+      argv++;
+      argc--;
+      msg = g_strjoinv(" ", (char**)argv);
       break;
-    } else if (!strcmp(myargv[0], "-C")) {
+    } else if (!strcmp(argv[0], "-C")) {
       z->cc=1;
-      myargv++;
-      myargc--;
-    } else if (!strcmp(myargv[0], "-n")) {
+      argv++;
+      argc--;
+    } else if (!strcmp(argv[0], "-n")) {
       z->noping=1;
-      myargv++;
-      myargc--;
+      argv++;
+      argc--;
     } else {
       /* anything unattached is a recipient */
-      g_ptr_array_add(z->recips, owl_validate_utf8(myargv[0]));
-      myargv++;
-      myargc--;
+      g_ptr_array_add(z->recips, owl_validate_utf8(argv[0]));
+      argv++;
+      argc--;
     }
   }
-
-  g_strfreev(argv);
 
   if (badargs) {
