+void exit_on_escapeseq(const char *buf, int len)
+{
+ static const char escseq[] = "\r~.";
+ static const char *state = escseq+1;
+ int i;
+
+ for (i = 0; i < len; i++) {
+ if (buf[i] == *state) {
+ state++;
+ if (*state == 0)
+ exit(0);
+ } else
+ state = escseq;
+ }
+}
+
+void usage(const char* argv0)
+{
+ fprintf(stderr, "Usage: %s [options] <device>\n", argv0);
+ fprintf(stderr, "Options:\n");
+ fprintf(stderr, " -d [+|-] create short positive/negative pulse on DTR\n");
+ fprintf(stderr, " -e ignore '~.' escape sequence\n");
+ fprintf(stderr, " -n do not switch the device to raw mode\n");
+ fprintf(stderr, " -r [+|-] create short positive/negative pulse on RTS\n");
+ fprintf(stderr, " -s <baudrate>\n");
+ fprintf(stderr, " -v verbose\n");
+}