- FILE *fp;
- struct stat sb;
-
- if (stat(path, &sb) < 0)
- failed(path);
- if ((sb.st_mode & S_IFMT) != S_IFCHR) {
- errno = ENOTTY;
- failed(path);
- }
- fp = fopen(path, "a+");
- if (fp == 0)
- failed(path);
- printf("opened %s\n", path);
- return fp;
+ FILE *fp;
+#ifdef USE_XTERM_PTY
+ int amaster;
+ int aslave;
+ char slave_name[1024];
+ char s_option[1024];
+ char *leaf;
+
+ if (openpty(&amaster, &aslave, slave_name, 0, 0) != 0)
+ failed("openpty");
+ if ((leaf = strrchr(slave_name, '/')) == 0) {
+ errno = EISDIR;
+ failed(slave_name);
+ }
+ sprintf(s_option, "-S%s/%d", slave_name, aslave);
+ if (fork()) {
+ execlp("xterm", "xterm", s_option, "-title", path, (char *) 0);
+ _exit(0);
+ }
+ fp = fdopen(amaster, "r+");
+#else
+ struct stat sb;
+
+ if (stat(path, &sb) < 0)
+ failed(path);
+ if ((sb.st_mode & S_IFMT) != S_IFCHR) {
+ errno = ENOTTY;
+ failed(path);
+ }
+ fp = fopen(path, "r+");
+ if (fp == 0)
+ failed(path);
+ printf("opened %s\n", path);
+#endif
+ return fp;
+}
+
+static int
+close_screen(SCREEN *sp GCC_UNUSED, void *arg GCC_UNUSED)
+{
+ (void) sp;
+ (void) arg;
+ return endwin();
+}
+
+static int
+read_screen(SCREEN *sp GCC_UNUSED, void *arg GCC_UNUSED)
+{
+ return getch();
+}
+
+static int
+write_screen(SCREEN *sp GCC_UNUSED, void *arg GCC_UNUSED)
+{
+ addstr((char *) arg);
+ refresh();
+ return OK;
+}
+
+static void
+show_ditto(DITTO * data, int count, char *msg)
+{
+ int n;
+
+ for (n = 0; n < count; n++) {
+ USING_SCREEN(data[n].screen, write_screen, (void *) msg);
+ }