+ char *x, *s;
+
+ if (*arg == '-' && (x = strchr(arg, '=')) != NULL) {
+ write(fd, arg, x - arg + 1);
+ arg += x - arg + 1;
+ }
+
+ if (strpbrk(arg, " \"'&;|[]()$#!*?^\\") != NULL) {
+ write(fd, "'", 1);
+ for (s = arg; (x = strchr(s, '\'')) != NULL; s = x + 1) {
+ write(fd, s, x - s + 1);
+ write(fd, "'", 1);
+ }
+ write(fd, s, strlen(s));
+ write(fd, "'", 1);
+ return;
+ }
+
+ write(fd, arg, strlen(arg));
+}
+
+static void write_filter_rules(int fd)
+{
+ struct filter_struct *ent;
+
+ write_sbuf(fd, " <<'#E#'\n");
+ for (ent = filter_list.head; ent; ent = ent->next) {
+ unsigned int plen;
+ char *p = get_rule_prefix(ent->match_flags, "- ", 0, &plen);
+ write_buf(fd, p, plen);
+ write_sbuf(fd, ent->pattern);
+ if (ent->match_flags & MATCHFLG_DIRECTORY)
+ write_byte(fd, '/');
+ write_byte(fd, eol_nulls ? 0 : '\n');
+ }
+ if (eol_nulls)
+ write_sbuf(fd, ";\n");
+ write_sbuf(fd, "#E#");
+}
+
+/* This routine tries to write out an equivalent --read-batch command
+ * given the user's --write-batch args. However, it doesn't really
+ * understand most of the options, so it uses some overly simple
+ * heuristics to munge the command line into something that will
+ * (hopefully) work. */
+void write_batch_shell_file(int argc, char *argv[], int file_arg_cnt)
+{
+ int fd, i, len;
+ char *p, filename[MAXPATHLEN];