Minsky
tclmain.cc File Reference
#include <exception>
#include <fstream>
#include <map>
#include <string>
#include <boost/filesystem.hpp>
#include <cairoSurfaceImage.h>
#include <ctype.h>
#include <pango.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <tk.h>
#include <tkDecls.h>
#include "eco_hashmap.h"
#include "eco_strstream.h"
#include "ecolab.h"
#include "error.h"
#include "tcl++.h"
#include "timer.h"
#include "version.h"
#include <ecolab_epilogue.h>
Include dependency graph for tclmain.cc:

Go to the source code of this file.

Classes

struct  TCLcmd::trap::init_t
 

Namespaces

 ecolab
 
 minsky
 Creation and access to the minskyTCL_obj object, which has code to record whenever Minsky's state changes.
 
 TCLcmd
 
 TCLcmd::trap
 

Macros

#define SIG_DFL   ((__sighandler_t) 0) /* Default action. */
 
#define SIGILL   4 /* Illegal instruction (ANSI). */
 
#define SIGABRT   6 /* Abort (ANSI). */
 
#define SIGBUS   7 /* BUS error (4.2 BSD). */
 
#define SIGSEGV   11 /* Segmentation violation (ANSI). */
 

Functions

 NEWCMD (minsky_version, 0)
 
void printTimersAtEnd ()
 
int main (int argc, char *argv[])
 
void minsky::doOneEvent (bool idleTasksOnly)
 checks if any GUI events are waiting, and proces an event if so More...
 
 NEWCMD (GUI, 0)
 
 NEWCMD (tcl_findLibrary,-1)
 
 NEWCMD (exit_ecolab, 0)
 
void TCLcmd::trap::sighand (int s)
 
 TCLcmd::trap::NEWCMD (trap, 2)
 
void TCLcmd::trap::aborthand (int)
 
 TCLcmd::trap::NEWCMD (trapabort,-1)
 
 TCLcmd::NEWCMD (cli, 0)
 
int TCLcmd::tk_mac_OpenDocument (ClientData, Tcl_Interp *, int argc, const char **argv)
 

Variables

Tk_Window ecolab::mainWin =0
 
eco_string TCLcmd::trap::sigcmd [32]
 
hash_map< eco_string, int > TCLcmd::trap::signum
 
struct TCLcmd::trap::init_t TCLcmd::trap::init
 
static int TCLcmd::tk_mac_OpenDocument_dummy
 

Macro Definition Documentation

◆ SIG_DFL

#define SIG_DFL   ((__sighandler_t) 0) /* Default action. */

Definition at line 36 of file tclmain.cc.

Referenced by TCLcmd::trap::NEWCMD().

◆ SIGABRT

#define SIGABRT   6 /* Abort (ANSI). */

Definition at line 42 of file tclmain.cc.

Referenced by TCLcmd::trap::NEWCMD().

◆ SIGBUS

#define SIGBUS   7 /* BUS error (4.2 BSD). */

Definition at line 46 of file tclmain.cc.

Referenced by TCLcmd::trap::NEWCMD().

◆ SIGILL

#define SIGILL   4 /* Illegal instruction (ANSI). */

Definition at line 39 of file tclmain.cc.

Referenced by TCLcmd::trap::NEWCMD().

◆ SIGSEGV

#define SIGSEGV   11 /* Segmentation violation (ANSI). */

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 81 of file tclmain.cc.

References ecolab::mainWin.

82 {
83  const Timer timer("main");
84  // atexit(printTimersAtEnd);
85 
86 #ifdef _WIN32
87  ecolab::Pango::defaultFamily="Arial Unicode MS";
88 #else
89  ecolab::Pango::defaultFamily="Adobe Courier Regular";
90 #endif
91 
92 #if defined(NDEBUG) && defined(_WIN32)
93  ShowWindow(GetConsoleWindow(),SW_HIDE);
94 #endif
95 
96  Tcl_FindExecutable(argv[0]);
97  int r;
98 #ifndef MXE
99  // For MXE builds, override tcl_library and tk_library to the self-contained versions
100  r=Tcl_Init(interp());
101  if (r!=TCL_OK)
102 #endif
103  // one possible reason is that it failed to locate the TCL library, we we set tcl_library and try again
104  {
105  const path exeDir=path(Tcl_GetNameOfExecutable()).parent_path();
106  tclvar tcl_library("tcl_library", (exeDir/"library"/"tcl").string().c_str());
107  tclvar tk_library("tk_library", (exeDir/"library"/"tk").string().c_str());
108  if ((r=Tcl_Init(interp()))!=TCL_OK)
109  {
110  // on Macs, the TCL library may be located in
111  // ../lib/minsky/library to get around codesign's
112  // pernicketyness
113  tcl_library=(exeDir/".."/"lib"/"minsky"/"library"/"tcl").string();
114  tk_library=(exeDir/".."/"lib"/"minsky"/"library"/"tcl").string();
115  r=Tcl_Init(interp());
116  }
117  }
118  if (r!=TCL_OK)
119  {
120  fprintf(stderr,"%s\n",Tcl_GetStringResult(interp()));
121  fprintf(stderr,"%s\n",Tcl_GetVar(interp(),"errorInfo",0)); /* print out trace */
122  return 1; /* not a clean execution */
123  }
124 
125  /* set the TCL variables argc and argv to contain the
126  arguments. */
127  tclvar tcl_argc("argc"), tcl_argv("argv");
128  tcl_argc=argc;
129  for (int i=0; i<argc; i++) tcl_argv[i]=argv[i];
130 
131  path minskydir=path(Tcl_GetNameOfExecutable()).parent_path();
132  // if Minsky's libraries are not located with the executable, look in the lib
133  // directory (unix style installation)
134  if (!exists(minskydir/"minsky.tcl"))
135  minskydir/="../lib/minsky";
136  if (!exists(minskydir/"minsky.tcl"))
137  {
138  fprintf(stderr,"Minsky library not found!\n");
139  return 1;
140  }
141  const tclvar minskyHome("minskyHome",minskydir.string().c_str());
142 
143  srand(time(nullptr));
144 
145  if (Tcl_EvalFile(interp(), (minskydir/"minsky.tcl").string().c_str())!=TCL_OK)
146  {
147  fprintf(stderr,"%s\n",Tcl_GetStringResult(interp()));
148  fprintf(stderr,"%s\n",Tcl_GetVar(interp(),"errorInfo",0)); /* print out trace */
149  return 1; /* not a clean execution */
150  }
151 
152  while (mainWin) /* we are running GUI mode */
153  Tcl_DoOneEvent(0);
154  Tcl_DeleteInterp(interp());
155  Tcl_Finalize();
156 }
Tk_Window mainWin
Definition: tclmain.cc:66

◆ NEWCMD() [1/4]

NEWCMD ( minsky_version  ,
 
)

Definition at line 58 of file tclmain.cc.

59 {
60  tclreturn r;
61  r<<VERSION;
62 }

◆ NEWCMD() [2/4]

NEWCMD ( GUI  ,
 
)

Definition at line 178 of file tclmain.cc.

References ecolab::mainWin.

179 {
180  if (Tk_Init(interp())==TCL_ERROR)
181  {
182  fprintf(stderr,"Error initialising Tk: %s",Tcl_GetStringResult(interp()));
183  fprintf(stderr,"%s\n",Tcl_GetVar(interp(),"errorInfo",0));
184  /* If Tk_Init fails, it is not necessarily a fatal error. For
185  example, on unpatched macs, we get an error from the attempt
186  to create a console, yet Minsky works just fine without
187  one. */
188  }
189  CairoSurface::registerImage();
190 
191  mainWin = Tk_MainWindow(interp());
192  //XSetErrorHandler(minskyXErrorHandler);
193 }
Tk_Window mainWin
Definition: tclmain.cc:66

◆ NEWCMD() [3/4]

NEWCMD ( tcl_findLibrary  ,
1 
)

Definition at line 196 of file tclmain.cc.

196 {}

◆ NEWCMD() [4/4]

NEWCMD ( exit_ecolab  ,
 
)

Definition at line 198 of file tclmain.cc.

References ecolab::mainWin.

199 {
200  mainWin=0;
201 }
Tk_Window mainWin
Definition: tclmain.cc:66

◆ printTimersAtEnd()

void printTimersAtEnd ( )

Definition at line 69 of file tclmain.cc.

70 {
71  stop_timer("main");
72  print_timers();
73 }