PLplot
5.10.0
|
00001 // Main program for Tcl-interface to PLplot. Allows interpretive 00002 // execution of plotting primitives without regard to output driver. 00003 // 00004 // Maurice LeBrun 00005 // IFS, University of Texas at Austin 00006 // 19-Jun-1994 00007 // 00008 // Copyright (C) 2004 Joao Cardoso 00009 // 00010 // This file is part of PLplot. 00011 // 00012 // PLplot is free software; you can redistribute it and/or modify 00013 // it under the terms of the GNU Library General Public License as published 00014 // by the Free Software Foundation; either version 2 of the License, or 00015 // (at your option) any later version. 00016 // 00017 // PLplot is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU Library General Public License for more details. 00021 // 00022 // You should have received a copy of the GNU Library General Public License 00023 // along with PLplot; if not, write to the Free Software 00024 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00025 // 00026 // 00027 00028 #include "plplotP.h" 00029 #define USINGPLDLL 00030 #include "pltcl.h" 00031 #ifdef HAVE_ITCL 00032 # ifndef HAVE_ITCLDECLS_H 00033 # define RESOURCE_INCLUDED 00034 # endif 00035 # include <itcl.h> 00036 #endif 00037 00038 static int 00039 AppInit( Tcl_Interp *interp ); 00040 00041 //-------------------------------------------------------------------------- 00042 // main -- 00043 // 00044 // Just a stub routine to call pltclMain. The latter is nice to have when 00045 // building extended tclsh's, since then you don't have to rely on sucking 00046 // the Tcl main out of libtcl (which doesn't work correctly on all 00047 // systems/compilers/linkers/etc). Hopefully in the future Tcl will 00048 // supply a sufficiently capable tclMain() type function that can be used 00049 // instead. 00050 //-------------------------------------------------------------------------- 00051 00052 int 00053 main( int argc, const char **argv ) 00054 { 00055 exit( pltclMain( argc, argv, NULL, AppInit ) ); 00056 } 00057 00058 //-------------------------------------------------------------------------- 00059 // plExitCmd 00060 // 00061 // PLplot/Tcl extension command -- handle exit. 00062 // The reason for overriding the normal exit command is so we can tell 00063 // the PLplot library to clean up. 00064 //-------------------------------------------------------------------------- 00065 00066 static int 00067 plExitCmd( ClientData clientData, Tcl_Interp *interp, int argc, char **argv ) 00068 { 00069 const char *tmp = Tcl_GetStringResult( interp ); 00070 (void) argc; 00071 (void) argv; 00072 (void) clientData; 00073 00074 // Print error message if one given 00075 if ( tmp != NULL && tmp != '\0' ) 00076 fprintf( stderr, "%s\n", Tcl_GetStringResult( interp ) ); 00077 00078 plspause( 0 ); 00079 plend(); 00080 00081 Tcl_UnsetVar( interp, "tcl_prompt1", 0 ); 00082 Tcl_Eval( interp, "tclexit" ); 00083 00084 return TCL_OK; 00085 } 00086 00087 //-------------------------------------------------------------------------- 00088 // prPromptCmd 00089 // 00090 // PLplot/Tcl extension command -- print the prompt. 00091 // Allows much more flexible setting of the prompt. 00092 //-------------------------------------------------------------------------- 00093 00094 static int 00095 prPromptCmd( ClientData clientData, Tcl_Interp *interp, int argc, char **argv ) 00096 { 00097 PLStream *pls; 00098 char prompt[80]; 00099 (void) argc; 00100 (void) argv; 00101 (void) clientData; 00102 00103 plgpls( &pls ); 00104 00105 if ( pls->ipls == 0 ) 00106 sprintf( prompt, "pltext; puts -nonewline \"pltcl> \"; flush stdout" ); 00107 else 00108 sprintf( prompt, "pltext; puts -nonewline \"pltcl_%d> \"; flush stdout", pls->ipls ); 00109 00110 Tcl_VarEval( interp, prompt, 0 ); 00111 00112 return TCL_OK; 00113 } 00114 00115 // 00116 //-------------------------------------------------------------------------- 00117 // 00118 // AppInit -- 00119 // 00120 // This procedure performs application-specific initialization. 00121 // Most applications, especially those that incorporate additional 00122 // packages, will have their own version of this procedure. 00123 // 00124 // Results: 00125 // Returns a standard Tcl completion code, and leaves an error 00126 // message in interp->result if an error occurs. 00127 // 00128 // Side effects: 00129 // Depends on the startup script. 00130 // 00131 //-------------------------------------------------------------------------- 00132 // 00133 00134 static int 00135 AppInit( Tcl_Interp *interp ) 00136 { 00137 // 00138 // Call the init procedures for included packages. Each call should 00139 // look like this: 00140 // 00141 // if (Mod_Init(interp) == TCL_ERROR) { 00142 // return TCL_ERROR; 00143 // } 00144 // 00145 // where "Mod" is the name of the module. 00146 // 00147 if ( Tcl_Init( interp ) == TCL_ERROR ) 00148 { 00149 printf( "Error Tcl_Init\n" ); 00150 return TCL_ERROR; 00151 } 00152 #ifdef HAVE_ITCL 00153 if ( Itcl_Init( interp ) == TCL_ERROR ) 00154 { 00155 return TCL_ERROR; 00156 } 00157 #endif 00158 if ( Pltcl_Init( interp ) == TCL_ERROR ) 00159 { 00160 return TCL_ERROR; 00161 } 00162 00163 // Application-specific startup. That means: for use in pltcl ONLY. 00164 00165 // Rename "exit" to "tclexit", and insert custom exit handler 00166 00167 Tcl_VarEval( interp, "rename exit tclexit", (char *) NULL ); 00168 00169 Tcl_CreateCommand( interp, "exit", (Tcl_CmdProc *) plExitCmd, 00170 (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL ); 00171 00172 Tcl_CreateCommand( interp, "pr_prompt", (Tcl_CmdProc *) prPromptCmd, 00173 (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL ); 00174 00175 // Custom prompt, to make sure we are in text mode when entering commands 00176 00177 Tcl_SetVar( interp, "tcl_prompt1", "pr_prompt", 0 ); 00178 00179 return TCL_OK; 00180 }