Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "misc.h"
00022
00023 #ifdef HAVE_NCURSES_H
00024 # include <ncurses.h>
00025 #else // HAVE_NCURSES_H
00026 # ifdef HAVE_CURSES_H
00027 # include <curses.h>
00028 # else
00029 # error "Neither curses.h nor ncurses.h available"
00030 # endif // HAVE_CURSES_H
00031 #endif // HAVE_NCURSES_H
00032 #include "curswa.h"
00033
00034 #ifdef HAVE_STDIO_H
00035 #include <stdio.h>
00036 #else
00037 # error "Sorry, stdio.h needed"
00038 #endif
00039
00040 #ifdef HAVE_STRING_H
00041 #include <string.h>
00042 #endif
00043 #ifdef HAVE_STRINGS_H
00044 #include <strings.h>
00045 #endif
00046
00047
00048 #if defined(HAVE_TERMINALTITLE) && defined(HAVE_TERMNAME)
00049 #define CANSETTITLE
00050 #endif
00051
00057 static const char* xterms[] = {
00058 "xterm",
00059 "dtterm",
00060 NULL
00061 };
00062
00071 inline static int mystrcmp (const char* s1, const char* s2) {
00072 #ifdef HAVE_STRNCASECMP
00073 return strncasecmp (s1, s2, (strlen (s1) < strlen (s2) ? strlen (s1) : strlen (s2) ) );
00074 #elif HAVE_STRNCMP
00075 return strncmp (s1, s2, (strlen (s1) < strlen (s2) ? strlen (s1) : strlen (s2) ) );
00076 #elif HAVE_STRCMP
00077 return strcmp (s1, s2);
00078 #else
00079 # error "Sorry, strncasecmp, strncmp, or strcmp needed"
00080 #endif
00081 }
00082
00083
00084
00095 #ifdef HAVE_TERMNAME
00096 bool isXTerm() {
00097 const char** tmp = xterms;
00098 char* tn = termname();
00099
00100 while (*tmp != NULL) {
00101 if (mystrcmp (tn, *tmp) == 0) return true;
00102
00103 tmp++;
00104 }
00105
00106 return false;
00107 }
00108 #else
00109 bool isXTerm() {
00110 return false;
00111 }
00112 #endif // HAVE_TERMNAME
00113
00120 #ifdef CANSETTITLE
00121 void setTerminalTitle (const std::string& title) {
00122 if (isXTerm() ) {
00123 fprintf (stdout, "%c]0;%s%c", '\033', title.c_str(), '\007');
00124 fflush (stdout);
00125 }
00126 }
00127 #else // CANSETTITLE
00128 void setTerminalTitle (const std::string& title) {}
00129 #endif // CANSETTITLE