9 #define IGNORE(x) do if (x); while (0)
11 int main(int argc
, char *argv
[])
19 i
= getopt(argc
, argv
, "q");
27 fprintf(stderr
, "usage: xtitle [-q] [STRING]\n");
32 if (!query
&& optind
== argc
) {
33 fprintf(stderr
, "xtitle: no string to set\n");
38 char *t
= getenv("TERM");
39 if (!t
|| strncmp(t
, "xterm", 5))
46 fd
= open("/dev/tty", O_RDWR
);
48 fprintf(stderr
, "xtitle: couldn't open terminal: %s", strerror(errno
));
56 IGNORE(write(fd
, "\33]0;", 4));
57 for (i
= optind
; i
< argc
; i
++) {
58 IGNORE(write(fd
, argv
[i
], strlen(argv
[i
])));
60 IGNORE(write(fd
, &sp
, 1));
62 IGNORE(write(fd
, "\7", 2));
70 n
.c_iflag
&= ~(IGNBRK
|BRKINT
|PARMRK
|ISTRIP
71 |INLCR
|IGNCR
|ICRNL
|IXON
);
72 n
.c_lflag
&= ~(ECHO
|ECHONL
|ICANON
|ISIG
|IEXTEN
);
73 n
.c_cflag
&= ~(CSIZE
|PARENB
);
75 tcsetattr(fd
, TCSAFLUSH
, &n
);
76 IGNORE(write(fd
, "\33[21t", 5));
79 if (read(fd
, &hack
, 1) < 1)
83 if (hack
== '\33') state
= 1;
86 if (hack
== ']') state
= 2; else state
= 0;
89 if (hack
== 'l') state
= 3; else state
= 0;
92 if (hack
== '\33') state
= 4; else putchar(hack
);
95 if (hack
== '\\') { state
= -1; putchar('\n'); }
96 else { putchar('\33'); putchar(hack
); state
= 3; }
101 tcsetattr(fd
, TCSAFLUSH
, &o
);