Back to index

texmacs  1.0.7.15
basic.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : basic.cpp
00004 * DESCRIPTION: fast global new and delete
00005 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #include "string.hpp"
00013 #include "scheme.hpp"
00014 #include "Freetype/tt_file.hpp"
00015 #include "dictionary.hpp"
00016 #include "sys_utils.hpp"
00017 
00018 /******************************************************************************
00019 * debugging
00020 ******************************************************************************/
00021 
00022 static int debug_status= 0;
00023 
00024 bool
00025 debug (int which, bool write_flag) {
00026   if (write_flag) {
00027     debug_status= debug_status | (1 << which);
00028     return 0;
00029   }
00030   else return (debug_status & (1 << which)) > 0;
00031 }
00032 
00033 int
00034 debug_off () {
00035   int status= debug_status;
00036   debug_status= 0;
00037   return status;
00038 }
00039 
00040 void
00041 debug_on (int status) {
00042   debug_status= status;
00043 }
00044 
00045 static void
00046 debug_set (int which, bool on) {
00047   if (on) debug_status= debug_status | (1 << which);
00048   else debug_status= debug_status & (~(1 << which));
00049 }
00050 
00051 void
00052 debug_set (string s, bool on) {
00053   if (s == "auto") debug_set (DEBUG_FLAG_AUTO, on);
00054   else if (s == "verbose") debug_set (DEBUG_FLAG_VERBOSE, on);
00055   else if (s == "events") debug_set (DEBUG_FLAG_EVENTS, on);
00056   else if (s == "std") debug_set (DEBUG_FLAG_STD, on);
00057   else if (s == "io") debug_set (DEBUG_FLAG_IO, on);
00058   else if (s == "bench") debug_set (DEBUG_FLAG_BENCH, on);
00059   else if (s == "history") debug_set (DEBUG_FLAG_HISTORY, on);
00060   else if (s == "qt") debug_set (DEBUG_FLAG_QT, on);
00061   else if (s == "keyboard") debug_set (DEBUG_FLAG_KEYBOARD, on);
00062   else if (s == "packrat") debug_set (DEBUG_FLAG_PACKRAT, on);
00063   else if (s == "flatten") debug_set (DEBUG_FLAG_FLATTEN, on);
00064   else if (s == "correct") debug_set (DEBUG_FLAG_CORRECT, on);
00065 }
00066 
00067 static bool
00068 debug_get (int which) {
00069   return (debug_status & (1 << which)) != 0;
00070 }
00071 
00072 bool
00073 debug_get (string s) {
00074   if (s == "auto") return debug_get (DEBUG_FLAG_AUTO);
00075   else if (s == "verbose") return debug_get (DEBUG_FLAG_VERBOSE);
00076   else if (s == "events") return debug_get (DEBUG_FLAG_EVENTS);
00077   else if (s == "std") return debug_get (DEBUG_FLAG_STD);
00078   else if (s == "io") return debug_get (DEBUG_FLAG_IO);
00079   else if (s == "bench") return debug_get (DEBUG_FLAG_BENCH);
00080   else if (s == "history") return debug_get (DEBUG_FLAG_HISTORY);
00081   else if (s == "qt") return debug_get (DEBUG_FLAG_QT);
00082   else if (s == "keyboard") return debug_get (DEBUG_FLAG_KEYBOARD);
00083   else if (s == "packrat") return debug_get (DEBUG_FLAG_PACKRAT);
00084   else if (s == "flatten") return debug_get (DEBUG_FLAG_FLATTEN);
00085   else if (s == "correct") return debug_get (DEBUG_FLAG_CORRECT);
00086   else return false;
00087 }
00088 
00089 /******************************************************************************
00090 * miscellaneous routines
00091 ******************************************************************************/
00092 
00093 int
00094 new_type_identifier () {
00095   static int id= 0;
00096   id--;
00097   return id;
00098 }
00099 
00100 static int current_indent= 0;
00101 
00102 tm_ostream&
00103 operator << (tm_ostream& out, display_control ctrl) {
00104   int i;
00105   switch (ctrl) {
00106   case INDENT:
00107     out << "  ";
00108     current_indent += 2;
00109     break;
00110   case UNINDENT:
00111     out << "\b\b";
00112     current_indent -= 2;
00113     break;
00114   case HRULE:
00115     for (i=current_indent; i<78; i++) out << "-";
00116   case LF:
00117     out << "\n";
00118     for (i=0; i<current_indent; i++) out << " ";
00119     break;    
00120   }
00121   return out;
00122 }
00123 
00124 /******************************************************************************
00125 * Various TeXmacs blends
00126 ******************************************************************************/
00127 
00128 bool
00129 gui_is_x () {
00130 #ifdef QTTEXMACS
00131   return false;
00132 #else
00133   return true;
00134 #endif
00135 }
00136 
00137 bool
00138 gui_is_qt () {
00139 #ifdef QTTEXMACS
00140   return true;
00141 #else
00142   return false;
00143 #endif
00144 }
00145 
00146 bool
00147 os_win32 () {
00148 #if defined (OS_WIN32)
00149   return true;
00150 #else
00151   return false;
00152 #endif
00153 }
00154 
00155 bool
00156 os_mingw () {
00157 #if defined (__MINGW__) || defined (__MINGW32__)
00158   return true;
00159 #else
00160   return false;
00161 #endif
00162 }
00163 
00164 bool
00165 os_macos () {
00166 #if defined (OS_MACOS)
00167   return true;
00168 #else
00169   return false;
00170 #endif
00171 }
00172 
00173 bool
00174 use_macos_fonts () {
00175 #ifdef OS_MACOS
00176   if (gui_is_qt ()) return true;
00177   string s= get_preference ("look and feel");
00178   if (s != "default" && s != "macos") return false;
00179   string l= get_output_language ();
00180   if (l == "bulgarian" || l == "russian" || l == "ukrainian") return false;
00181   return tt_font_exists ("LucidaGrande");
00182 #else
00183   return false;
00184 #endif
00185 }
00186 
00187 static const char*
00188 default_look_and_feel_impl () {
00189   if (os_mingw () || os_win32 ()) return "windows";
00190   else if (os_macos ()) return "macos";
00191   else if (get_env ("KDE_FULL_SESSION") != "") return "kde";
00192   else if (get_env ("GNOME_DESKTOP_SESSION_ID") != "") return "gnome";
00193   else if (eval_system ("pidof ksmserver") != "") return "kde";
00194   else if (eval_system ("pidof gnome-session") != "") return "gnome";
00195   //else if (eval_system ("pidof xfce-mcs-manage") != "") return "xfce";
00196   else return "emacs";
00197 }
00198 
00199 const char*
00200 default_look_and_feel () {
00201   static const char* ret= default_look_and_feel_impl ();
00202   return ret;
00203 }