X-Git-Url: https://git.distorted.org.uk/~mdw/misc/blobdiff_plain/8d769cc9146d71188f2ffe9cd5a9160706614f1d..HEAD:/xtitle.c diff --git a/xtitle.c b/xtitle.c index 94e9af6..a6696d3 100644 --- a/xtitle.c +++ b/xtitle.c @@ -6,34 +6,17 @@ #include #include -#ifdef BASH_BUILTIN -#include "bash/config.h" -#include "bash/shell.h" -#include "bash/builtins.h" -#include "bash/builtins/common.h" -#include "bash/builtins/bashgetopt.h" -#endif +#define IGNORE(x) do if (x); while (0) -#ifdef BASH_BUILTIN -int xtitle_builtin(WORD_LIST *list) -#else int main(int argc, char *argv[]) -#endif { int query = 0; int fd; int openned = 0; + int i; -#ifdef BASH_BUILTIN - reset_internal_getopt(); -#endif for (;;) { -#ifdef BASH_BUILTIN - int i; - i = internal_getopt(list, "q"); -#else - int i = getopt(argc, argv, "q"); -#endif + i = getopt(argc, argv, "q"); if (i < 0) break; switch (i) { @@ -41,20 +24,12 @@ int main(int argc, char *argv[]) query = 1; break; default: -#ifdef BASH_BUILTIN - builtin_usage(); -#else - fprintf(stderr, "usage: xtitle [-q] [string]\n"); -#endif + fprintf(stderr, "usage: xtitle [-q] [STRING]\n"); return (1); } } -#ifdef BASH_BUILTIN - if (!query && loptend == 0) { -#else if (!query && optind == argc) { -#endif fprintf(stderr, "xtitle: no string to set\n"); return (1); } @@ -77,28 +52,14 @@ int main(int argc, char *argv[]) } if (!query) { -#ifdef BASH_BUILTIN - WORD_LIST *l = loptend; char sp = ' '; - write(fd, "\33]0;", 4); - while (l) { - write(fd, l->word->word, strlen(l->word->word)); - if (l->next) - write(fd, &sp, 1); - l = l->next; - } - write(fd, "\7", 2); -#else - int i; - char sp = ' '; - write(fd, "\33]0;", 4); + IGNORE(write(fd, "\33]0;", 4)); for (i = optind; i < argc; i++) { - write(fd, argv[i], strlen(argv[i])); + IGNORE(write(fd, argv[i], strlen(argv[i]))); if (i < argc - 1) - write(fd, &sp, 1); + IGNORE(write(fd, &sp, 1)); } - write(fd, "\7", 2); -#endif + IGNORE(write(fd, "\7", 2)); } else { struct termios o, n; char hack; @@ -112,7 +73,7 @@ int main(int argc, char *argv[]) n.c_cflag &= ~(CSIZE|PARENB); n.c_cflag |= CS8; tcsetattr(fd, TCSAFLUSH, &n); - write(fd, "\33[21t", 5); + IGNORE(write(fd, "\33[21t", 5)); while (state != -1) { if (read(fd, &hack, 1) < 1) @@ -145,25 +106,3 @@ int main(int argc, char *argv[]) return (0); } - - -#ifdef BASH_BUILTIN - -static char *xtitle_doc[] = { - "Either set or read the title of the current xterm window. With the", - "-q option, writes the current xterm title to standard output. Without", - "the -q option, sets the xterm title to be the arguments given,", - "separated by space characters. [By Mark Wooding, mdw@nsict.org]", - 0 -}; - -struct builtin xtitle_struct = { - "xtitle", - xtitle_builtin, - BUILTIN_ENABLED, - xtitle_doc, - "xtitle [-q] [arguments]", - 0 -}; - -#endif