9 int main(int argc, char *argv[])
17 i = getopt(argc, argv, "q");
25 fprintf(stderr, "usage: xtitle [-q] [STRING]\n");
30 if (!query && optind == argc) {
31 fprintf(stderr, "xtitle: no string to set\n");
36 char *t = getenv("TERM");
37 if (!t || strncmp(t, "xterm", 5))
44 fd = open("/dev/tty", O_RDWR);
46 fprintf(stderr, "xtitle: couldn't open terminal: %s", strerror(errno));
54 write(fd, "\33]0;", 4);
55 for (i = optind; i < argc; i++) {
56 write(fd, argv[i], strlen(argv[i]));
68 n.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
69 |INLCR|IGNCR|ICRNL|IXON);
70 n.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
71 n.c_cflag &= ~(CSIZE|PARENB);
73 tcsetattr(fd, TCSAFLUSH, &n);
74 write(fd, "\33[21t", 5);
77 if (read(fd, &hack, 1) < 1)
81 if (hack == '\33') state = 1;
84 if (hack == ']') state = 2; else state = 0;
87 if (hack == 'l') state = 3; else state = 0;
90 if (hack == '\33') state = 4; else putchar(hack);
93 if (hack == '\\') { state = -1; putchar('\n'); }
94 else { putchar('\33'); putchar(hack); state = 3; }
99 tcsetattr(fd, TCSAFLUSH, &o);