+ bandlimit_sendend(stab.st_size, &interval_usec);
+
+ fold= f;
+ told= told_file;
+ }
+}
+
+void usagemessage(void) {
+ puts("usage: rcopy-repeatedly [<options>] <file> <file>\n"
+ " <file> may be <local-file> or [<user>@]<host>:<file>\n"
+ " exactly one of each of the two forms must be provided\n"
+ " a file is taken as remote if it has a : before the first /\n"
+ "options\n"
+ " --help\n");
+}
+
+static void of_help(const struct cmdinfo *ci, const char *val) {
+ usagemessage();
+ if (ferror(stdout)) diee("could not write usage message to stdout");
+ exit(0);
+}
+
+typedef struct {
+ const char *userhost, *path;
+} FileSpecification;
+
+static FileSpecification srcspec, dstspec;
+static int upload=-1; /* -1 means not yet known; 0 means download */
+
+static const struct cmdinfo cmdinfos[]= {
+ { "help", .call= of_help },
+ { "receiver", .iassignto=&upload, .arg=1 },
+ { "sender", .iassignto=&upload, .arg=0 },
+ { 0 }
+};
+
+static void server(const char *filename) {
+ int c;
+ commsi= stdin;
+ commso= stdout;
+ fprintf(commso, "%s0002 %c\n", banner, upload?'u':'d');
+ send_flush();
+ c= fgetc(commsi); if (c==EOF) die_badrecv("initial go");
+ if (c!=REPLMSG_GO) die_protocol("initial go message was %#02x instead",c);
+
+ if (upload)
+ receiver(filename);
+ else
+ sender(filename);
+}
+
+static void client(void) {
+ int uppipe[2], downpipe[2], r;
+ pid_t child;
+
+ mpipe(uppipe);
+ mpipe(downpipe);
+
+ FileSpecification *remotespec= srcspec.userhost ? &srcspec : &dstspec;
+ const char *remotemode= srcspec.userhost ? "--sender" : "--receiver";
+
+ child= fork();
+ if (child==-1) diee("fork failed");
+ if (!child) {
+ mdup2(uppipe[0],0);
+ mdup2(downpipe[1],1);
+ close(uppipe[0]); close(downpipe[0]);
+ close(uppipe[1]); close(downpipe[1]);
+ execlp(rsh_program,
+ rsh_program, remotespec->userhost, rcopy_repeatedly_program,
+ remotemode, remotespec->path, (char*)0);
+ diee("failed to execute rsh program `%s'",rsh_program);