• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ui/misc.cc

Go to the documentation of this file.
00001 // $Id: misc.cc 3342 2010-09-17 18:32:00Z java $
00002 //
00003 // Copyright (C) 2008-2010  Rafael Ostertag
00004 //
00005 // This file is part of YAPET.
00006 //
00007 // YAPET is free software: you can redistribute it and/or modify it under the
00008 // terms of the GNU General Public License as published by the Free Software
00009 // Foundation, either version 3 of the License, or (at your option) any later
00010 // version.
00011 //
00012 // YAPET is distributed in the hope that it will be useful, but WITHOUT ANY
00013 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014 // FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00015 // details.
00016 //
00017 // You should have received a copy of the GNU General Public License along with
00018 // YAPET.  If not, see <http://www.gnu.org/licenses/>.
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" // Leave this here. It depends on the above includes.
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 // For convenience
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

Generated on Sun Sep 19 2010 15:37:13 for YAPET by  doxygen 1.7.1