9 int main(int argc
, char *argv
[])
18 i
= getopt(argc
, argv
, "q");
26 fprintf(stderr
, "usage: xtitle [-q] [STRING]\n");
31 if (!query
&& optind
== argc
) {
32 fprintf(stderr
, "xtitle: no string to set\n");
37 char *t
= getenv("TERM");
38 if (!t
|| strncmp(t
, "xterm", 5))
45 fd
= open("/dev/tty", O_RDWR
);
47 fprintf(stderr
, "xtitle: couldn't open terminal: %s", strerror(errno
));
55 hunoz
= write(fd
, "\33]0;", 4);
56 for (i
= optind
; i
< argc
; i
++) {
57 hunoz
= write(fd
, argv
[i
], strlen(argv
[i
]));
59 hunoz
= write(fd
, &sp
, 1);
61 hunoz
= write(fd
, "\7", 2);
69 n
.c_iflag
&= ~(IGNBRK
|BRKINT
|PARMRK
|ISTRIP
70 |INLCR
|IGNCR
|ICRNL
|IXON
);
71 n
.c_lflag
&= ~(ECHO
|ECHONL
|ICANON
|ISIG
|IEXTEN
);
72 n
.c_cflag
&= ~(CSIZE
|PARENB
);
74 tcsetattr(fd
, TCSAFLUSH
, &n
);
75 hunoz
= write(fd
, "\33[21t", 5);
78 if (read(fd
, &hack
, 1) < 1)
82 if (hack
== '\33') state
= 1;
85 if (hack
== ']') state
= 2; else state
= 0;
88 if (hack
== 'l') state
= 3; else state
= 0;
91 if (hack
== '\33') state
= 4; else putchar(hack
);
94 if (hack
== '\\') { state
= -1; putchar('\n'); }
95 else { putchar('\33'); putchar(hack
); state
= 3; }
100 tcsetattr(fd
, TCSAFLUSH
, &o
);