Back to index

texmacs  1.0.7.15
Functions | Variables
texmacs.cpp File Reference
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <locale.h>
#include <signal.h>
#include "boot.hpp"
#include "file.hpp"
#include "server.hpp"
#include "timer.hpp"
#include "data_cache.hpp"
#include "tm_window.hpp"
#include <cstdio>

Go to the source code of this file.

Functions

void clean_exit_on_segfault (int sig_num)
void TeXmacs_init_paths (int &argc, char **argv)
void TeXmacs_main (int argc, char **argv)
void immediate_options (int argc, char **argv)
int main (int argc, char **argv)

Variables

bool char_clip
bool reverse_colors
url tm_init_file
url tm_init_buffer_file
string my_init_cmds
int geometry_w
int geometry_h
int geometry_x
int geometry_y
tree the_et
bool texmacs_started
tm_ostreamcout = tm_ostream::cout
tm_ostreamcerr = tm_ostream::cerr

Function Documentation

void clean_exit_on_segfault ( int  sig_num)

Definition at line 77 of file texmacs.cpp.

                                     {
  FAILED ("segmentation fault");
}

Here is the caller graph for this function:

void immediate_options ( int  argc,
char **  argv 
)

Definition at line 388 of file texmacs.cpp.

                                          {
  if (get_env ("TEXMACS_HOME_PATH") == "")
#ifdef __MINGW32__
    set_env ("TEXMACS_HOME_PATH", get_env ("APPDATA") * "/TeXmacs");
#else
  set_env ("TEXMACS_HOME_PATH", get_env ("HOME") * "/.TeXmacs");
#endif
  if (get_env ("TEXMACS_HOME_PATH") == "") return;
  for (int i=1; i<argc; i++) {
    string s= argv[i];
    if ((N(s)>=2) && (s(0,2)=="--")) s= s (1, N(s));
    if ((s == "-S") || (s == "-setup")) {
      remove (url ("$TEXMACS_HOME_PATH/system/settings.scm"));
      remove (url ("$TEXMACS_HOME_PATH/system/setup.scm"));
      remove (url ("$TEXMACS_HOME_PATH/system/cache") * url_wildcard ("*"));
      remove (url ("$TEXMACS_HOME_PATH/fonts/error") * url_wildcard ("*"));
    }
    else if (s == "-delete-cache")
      remove (url ("$TEXMACS_HOME_PATH/system/cache") * url_wildcard ("*"));
    else if (s == "-delete-style-cache")
      remove (url ("$TEXMACS_HOME_PATH/system/cache") * url_wildcard ("__*"));
    else if (s == "-delete-font-cache")
      remove (url ("$TEXMACS_HOME_PATH/system/cache/font_cache.scm"));
    else if (s == "-delete-doc-cache") {
      remove (url ("$TEXMACS_HOME_PATH/system/cache/doc_cache"));
      remove (url ("$TEXMACS_HOME_PATH/system/cache/dir_cache.scm"));
      remove (url ("$TEXMACS_HOME_PATH/system/cache/stat_cache.scm"));
    }
    else if (s == "-delete-file-cache") {
      remove (url ("$TEXMACS_HOME_PATH/system/cache/doc_cache"));
      remove (url ("$TEXMACS_HOME_PATH/system/cache/file_cache"));
      remove (url ("$TEXMACS_HOME_PATH/system/cache/dir_cache.scm"));
      remove (url ("$TEXMACS_HOME_PATH/system/cache/stat_cache.scm"));
    }
    else if (s == "-log-file" && i + 1 < argc) {
      i++;
      char* log_file = argv[i];
      FILE* f= fopen (log_file, "w");
      if (! f || ! cout.open (f) || ! cerr.open (f))
        cerr << "TeXmacs] Error: could not open " << log_file << "\n";
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 435 of file texmacs.cpp.

                             {
  windows_delayed_refresh (1000000000);
  immediate_options (argc, argv);
  set_env ("LC_NUMERIC", "POSIX");
#ifdef MACOSX_EXTENSIONS
  // Reset TeXmacs if Alt is pressed during startup
  if (mac_alternate_startup()) {
    cout << "TeXmacs] Performing setup (Alt on startup)" << LF; 
    remove (url ("$TEXMACS_HOME_PATH/system/settings.scm"));
    remove (url ("$TEXMACS_HOME_PATH/system/setup.scm"));
    remove (url ("$TEXMACS_HOME_PATH/system/cache") * url_wildcard ("*"));
    remove (url ("$TEXMACS_HOME_PATH/fonts/error") * url_wildcard ("*"));    
  }
#endif
#ifdef QTTEXMACS
  // initialize the Qt application infrastructure
  new QApplication (argc, argv);
#endif
  TeXmacs_init_paths (argc, argv);
  //cout << "Bench  ] Started TeXmacs\n";
  the_et     = tuple ();
  the_et->obs= ip_observer (path ());
  cache_initialize ();
  bench_start ("initialize texmacs");
  init_texmacs ();
  bench_cumul ("initialize texmacs");
#ifdef ENABLE_TESTS
  test_routines ();
#endif
//#ifdef EXPERIMENTAL
//  test_environments ();
//#endif
  start_scheme (argc, argv, TeXmacs_main);
  cout.close ();
  cerr.close ();
  return 0;
}

Here is the call graph for this function:

void TeXmacs_init_paths ( int &  argc,
char **  argv 
)

Definition at line 86 of file texmacs.cpp.

                                            {
  (void) argc; (void) argv;
#ifdef QTTEXMACS
  url exedir = url_system (qt_application_directory ());
#else
  url exedir = url_system(argv[0]) * ".." ;
  if (! is_rooted(exedir)) {
    exedir = url_pwd() * exedir ;
  }
#endif

#if (defined(QTTEXMACS) && defined(Q_WS_MAC)) 
  // the following line can inibith external plugin loading
  // QCoreApplication::setLibraryPaths(QStringList());
  // ideally we would like to control the external plugins
  // and add the most useful (gif, jpeg, svg converters)
  // to the bundle package. I still do not have a reliable solution
  // so just allow everything that is reachable.
       
  // plugins need to be installed in TeXmacs.app/Contents/Plugins     
       QCoreApplication::addLibraryPath( QDir::cleanPath(QCoreApplication::applicationDirPath().append("/../Plugins")) );
  // cout << from_qstring ( QCoreApplication::libraryPaths () .join("\n") ) << LF;
       {
    // ensure that private versions of the Qt frameworks have priority on
    // other instances.
    // in the event that we load qt plugins which could possibly link to
    // other instances of the Qt libraries
    string buf;
    buf = as_string(exedir * "../Frameworks");
    if (get_env("DYLD_FRAMEWORK_PATH") != "") buf = buf * ":" * get_env("DYLD_FRAMEWORK_PATH");    
    set_env ("DYLD_FRAMEWORK_PATH", buf);    
    buf = as_string(exedir * "../Resources/lib");
    if (get_env("DYLD_LIBRARY_PATH") != "") buf = buf * ":" * get_env("DYLD_LIBRARY_PATH");    
    set_env ("DYLD_LIBRARY_PATH", buf);    
  }
#endif

#if defined(AQUATEXMACS) ||(defined(QTTEXMACS) && defined(Q_WS_MAC)) || (defined(X11TEXMACS) && defined (MACOSX_EXTENSIONS))
  // Mac bundle environment initialization
  // We set some environment variables when the executable
  // is in a .app bundle on MacOSX
  if (get_env ("TEXMACS_PATH") == "")
    set_env ("TEXMACS_PATH", as_string(exedir * "../Resources/share/TeXmacs"));
  //cout << get_env("PATH") * ":" * as_string(url("$PWD") * argv[0]
  // * "../../Resources/share/TeXmacs/bin") << LF;
  if (exists("/bin/bash")) {
    string shell_env =  eval_system("PATH='' /bin/bash -l -c 'echo $PATH'");
    set_env ("PATH", get_env("PATH") * ":" * shell_env * ":" *
           as_string (exedir * "../Resources/share/TeXmacs/bin"));
  } else {
    set_env ("PATH", get_env("PATH") * ":" *
               as_string (exedir * "../Resources/share/TeXmacs/bin"));
  }
  // system("set");
#endif

#ifdef __MINGW32__
  // Win bundle environment initialization
  // TEXMACS_PATH is set by assuming that the executable is in TeXmacs/bin/
  // HOME is set to USERPROFILE
  // PWD is set to HOME
  // if PWD is lacking, then the path resolution machinery may not work
  
  if (get_env ("TEXMACS_PATH") == "")
    set_env ("TEXMACS_PATH", as_string (exedir * ".."));
  if (get_env ("HOME") == "")
    set_env ("HOME", get_env("USERPROFILE"));
  // HACK
  // In WINE the variable PWD is already in the outer Unix environment 
  // so we need to override it to have a correct behaviour
  if ((get_env ("PWD") == "") || (get_env ("PWD")[0] == '/'))  {
    set_env ("PWD", as_string (exedir));
    // set_env ("PWD", get_env("HOME"));
  }
  // system("set");
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

void TeXmacs_main ( int  argc,
char **  argv 
)

Definition at line 169 of file texmacs.cpp.

                                     {
  int i;
  bool flag= true;
  string the_default_font;
  for (i=1; i<argc; i++)
    if (argv[i][0] == '\0') argc= i;
    else if (((argv[i][0] == '-') ||
             (argv[i][0] == '+')) && (argv[i][1] != '\0'))
    {
      string s= argv[i];
      if ((N(s)>=2) && (s(0,2)=="--")) s= s (1, N(s));
      if ((s == "-s") || (s == "-silent")) flag= false;
      else if ((s == "-V") || (s == "-verbose"))
       debug (DEBUG_FLAG_VERBOSE, true);
      else if ((s == "-d") || (s == "-debug")) debug (DEBUG_FLAG_STD, true);
      else if (s == "-debug-events") debug (DEBUG_FLAG_EVENTS, true);
      else if (s == "-debug-io") debug (DEBUG_FLAG_IO, true);
      else if (s == "-debug-bench") debug (DEBUG_FLAG_BENCH, true);
      else if (s == "-debug-history") debug (DEBUG_FLAG_HISTORY, true);
      else if (s == "-debug-qt") debug (DEBUG_FLAG_QT, true);
      else if (s == "-debug-keyboard") debug (DEBUG_FLAG_KEYBOARD, true);
      else if (s == "-debug-packrat") debug (DEBUG_FLAG_PACKRAT, true);
      else if (s == "-debug-flatten") debug (DEBUG_FLAG_FLATTEN, true);
      else if (s == "-debug-correct") debug (DEBUG_FLAG_CORRECT, true);
      else if (s == "-debug-all") {
       debug (DEBUG_FLAG_EVENTS, true);
       debug (DEBUG_FLAG_STD, true);
       debug (DEBUG_FLAG_IO, true);
       debug (DEBUG_FLAG_HISTORY, true);
       debug (DEBUG_FLAG_BENCH, true);
       debug (DEBUG_FLAG_QT, true);
      }
      else if ((s == "-fn") || (s == "-font")) {
       i++;
       if (i<argc) the_default_font= argv[i];
      }
      else if ((s == "-g") || (s == "-geometry")) {
       i++;
       if (i<argc) {
         string g= argv[i];
         int j=0, j1, j2, j3;
         for (j=0; j<N(g); j++)
           if (g[j] == 'x') break;
         j1=j; if (j<N(g)) j++;
         for (; j<N(g); j++)
           if ((g[j] == '+') || (g[j] == '-')) break;
         j2=j; if (j<N(g)) j++;
         for (; j<N(g); j++)
           if ((g[j] == '+') || (g[j] == '-')) break;
         j3=j;
         if (j1<N(g)) {
           geometry_w= max (as_int (g (0, j1)), 320);
           geometry_h= max (as_int (g (j1+1, j2)), 200);
         }
         if (j3<N(g)) {
           if (g[j2] == '-') geometry_x= as_int (g (j2, j3)) - 1;
           else geometry_x= as_int (g (j2+1, j3));
           if (g[j3] == '-') geometry_y= as_int (g (j3, N(g))) - 1;
           else geometry_y= as_int (g (j3+1, N(g)));
         }
       }
      }
      else if ((s == "-b") || (s == "-initialize-buffer")) {
       i++;
       if (i<argc) tm_init_buffer_file= url_system (argv[i]);
      }
      else if ((s == "-i") || (s == "-initialize")) {
       i++;
       if (i<argc) tm_init_file= url_system (argv[i]);
      }
      else if ((s == "-v") || (s == "-version")) {
       cout << "\n";
       cout << "TeXmacs version " << TEXMACS_VERSION << "\n";
       cout << TEXMACS_COPYRIGHT << "\n";
       cout << "\n";
       exit (0);
      }
      else if ((s == "-p") || (s == "-path")) {
       cout << get_env ("TEXMACS_PATH") << "\n";
       exit (0);
      }
      else if ((s == "-bp") || (s == "-binpath")) {
       cout << get_env ("TEXMACS_BIN_PATH") << "\n";
       exit (0);
      }
      else if ((s == "-q") || (s == "-quit"))
       my_init_cmds= my_init_cmds * " (quit-TeXmacs)";
      else if ((s == "-r") || (s == "-reverse"))
       reverse_colors= true;
      else if ((s == "-c") || (s == "-convert")) {
       i+=2;
       if (i<argc) {
         url in  ("$PWD", argv[i-1]);
         url out ("$PWD", argv[ i ]);
         my_init_cmds= my_init_cmds * " " *
           "(texmacs-load-buffer " * scm_quote (as_string (in)) *
           " \"generic\" 0 #f) " *
           "(export-buffer " * scm_quote (as_string (out)) * ")";
       }
      }
      else if ((s == "-x") || (s == "-execute")) {
       i++;
       if (i<argc) my_init_cmds= (my_init_cmds * " ") * argv[i];
      }
      else if (s == "-log-file") i++;
      else if ((s == "-Oc") || (s == "-no-char-clipping")) char_clip= false;
      else if ((s == "+Oc") || (s == "-char-clipping")) char_clip= true;
      else if ((s == "-S") || (s == "-setup") ||
              (s == "-delete-cache") || (s == "-delete-font-cache") ||
              (s == "-delete-style-cache") || (s == "-delete-file-cache") ||
              (s == "-delete-doc-cache"));
      else if (starts (s, "-psn"));
      else {
       cout << "\n";
       cout << "Options for TeXmacs:\n\n";
       cout << "  -b [file]  Specify scheme buffers initialization file\n";
       cout << "  -c [i] [o] Convert file 'i' into file 'o'\n";
       cout << "  -d         For debugging purposes\n";
       cout << "  -fn [font] Set the default TeX font\n";
       cout << "  -g [geom]  Set geometry of window in pixels\n";
       cout << "  -h         Display this help message\n";
       cout << "  -i [file]  Specify scheme initialization file\n";
       cout << "  -p         Get the TeXmacs path\n";
       cout << "  -q         Shortcut for -x \"(quit-TeXmacs)\"\n";
       cout << "  -r         Reverse video mode\n";
       cout << "  -s         Suppress information messages\n";
       cout << "  -S         Rerun TeXmacs setup program before starting\n";
       cout << "  -v         Display current TeXmacs version\n";
       cout << "  -V         Show some informative messages\n";
       cout << "  -x [cmd]   Execute scheme command\n";
       cout << "  -Oc        TeX characters bitmap clipping off\n";
       cout << "  +Oc        TeX characters bitmap clipping on (default)\n";
       cout << "\nPlease report bugs to <bugs@texmacs.org>\n";
       cout << "\n";
       exit (0);
      }
    }
  if (flag) debug (DEBUG_FLAG_AUTO, true);

  if (DEBUG_STD) cout << "TeXmacs] Installing internal plug-ins...\n";
  bench_start ("initialize plugins");
  init_plugins ();
  bench_cumul ("initialize plugins");
  if (DEBUG_STD) cout << "TeXmacs] Opening display...\n";
  
#if defined(X11TEXMACS) && defined(MACOSX_EXTENSIONS)
  init_mac_application ();
#endif
    
  gui_open (argc, argv);
  set_default_font (the_default_font);
  if (DEBUG_STD) cout << "TeXmacs] Starting server...\n";
  { // opening scope for server sv
  server sv;

  // HACK:
  // Qt and Guile want to change the locale. 
  // We need to force it to C to parse correctly the configuration files
  // (see as_double() in string.cpp)
  setlocale(LC_NUMERIC, "C");    
    
  for (i=1; i<argc; i++) {
    if (argv[i] == NULL) break;
    string s= argv[i];
    if ((N(s)>=2) && (s(0,2)=="--")) s= s (1, N(s));
    if ((s[0] != '-') && (s[0] != '+')) {
      if (DEBUG_STD) cout << "TeXmacs] Loading " << s << "...\n";
      load_buffer (url_system (s), "generic", 1);
    }
    if ((s == "-b") || (s == "-initialize-buffer") ||
       (s == "-c") || (s == "-convert") ||
       (s == "-fn") || (s == "-font") ||
       (s == "-i") || (s == "-initialize") ||
       (s == "-g") || (s == "-geometry") ||
       (s == "-x") || (s == "-execute") ||
       (s == "-log-file")) i++;
  }
  if (install_status == 1) {
    if (DEBUG_STD) cout << "TeXmacs] Loading welcome message...\n";
    load_buffer ("$TEXMACS_PATH/doc/about/welcome/first.en.tm", "help", 1);
  }
  else if (install_status == 2) {
    if (DEBUG_STD) cout << "TeXmacs] Loading upgrade message...\n";
    load_buffer (
      "$TEXMACS_HOME_PATH/doc/about/changes/changes-recent.en.tm", "help", 1);
  }
  if (no_bufs ()) {
    if (DEBUG_STD) cout << "TeXmacs] Creating 'no name' buffer...\n";
    open_window ();
  }

  bench_print ();
  bench_reset ("initialize texmacs");
  bench_reset ("initialize plugins");
  bench_reset ("initialize scheme");

  if (DEBUG_STD) cout << "TeXmacs] Starting event loop...\n";
  texmacs_started= true;
  signal (SIGSEGV, clean_exit_on_segfault);
  gui_start_loop ();

  if (DEBUG_STD) cout << "TeXmacs] Stopping server...\n";
  } // ending scope for server sv

  if (DEBUG_STD) cout << "TeXmacs] Closing display...\n";
  gui_close ();
  
#if defined(X11TEXMACS) && defined(MACOSX_EXTENSIONS)
  finalize_mac_application ();
#endif
  
  if (DEBUG_STD) cout << "TeXmacs] Good bye...\n";
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 57 of file texmacs.cpp.

bool char_clip

Definition at line 483 of file aqua_gui.mm.

Definition at line 56 of file texmacs.cpp.

Definition at line 18 of file tm_window.cpp.

Definition at line 18 of file tm_window.cpp.

Definition at line 19 of file tm_window.cpp.

Definition at line 19 of file tm_window.cpp.

Definition at line 28 of file tm_server.cpp.

Definition at line 30 of file x_init.cpp.

Definition at line 25 of file tm_server.cpp.

Definition at line 18 of file new_document.cpp.

Definition at line 21 of file tm_data.cpp.

Definition at line 26 of file tm_server.cpp.