- setupterm((char *) 0, STDOUT_FILENO, (int *) 0);
- return (tputs(clear_screen, lines > 0 ? lines : 1, putch) == ERR)
+ TTY tty_settings;
+ int fd;
+ int c;
+ char *term;
+ bool opt_x = FALSE; /* clear scrollback if possible */
+
+ _nc_progname = _nc_rootname(argv[0]);
+ term = getenv("TERM");
+
+ while ((c = getopt(argc, argv, "T:Vx")) != -1) {
+ switch (c) {
+ case 'T':
+ use_env(FALSE);
+ use_tioctl(TRUE);
+ term = optarg;
+ break;
+ case 'V':
+ puts(curses_version());
+ ExitProgram(EXIT_SUCCESS);
+ case 'x': /* do not try to clear scrollback */
+ opt_x = TRUE;
+ break;
+ default:
+ usage();
+ /* NOTREACHED */
+ }
+ }
+ if (optind < argc)
+ usage();
+
+ fd = save_tty_settings(&tty_settings, FALSE);
+
+ setupterm(term, fd, (int *) 0);
+
+ ExitProgram((clear_cmd(opt_x) == ERR)