00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #define NEED_PLDEBUG
00040 #include "plserver.h"
00041
00042
00043
00044
00045 static char *client_name;
00046 static char *auto_path;
00047 static int child;
00048 #ifdef PLD_dp
00049 static int dp;
00050 #endif
00051 static char *client_host;
00052 static char *client_port;
00053
00054 static Tk_ArgvInfo argTable[] = {
00055 { "-client_name", TK_ARGV_STRING, (char *) NULL, (char *) &client_name,
00056 "Client main window name to connect to" },
00057 { "-client_host", TK_ARGV_STRING, (char *) NULL, (char *) &client_host,
00058 "Client host to connect to" },
00059 { "-client_port", TK_ARGV_STRING, (char *) NULL, (char *) &client_port,
00060 "Client port (Tcl-DP) to connect to" },
00061 { "-auto_path", TK_ARGV_STRING, (char *) NULL, (char *) &auto_path,
00062 "Additional directory(s) to autoload" },
00063 { "-child", TK_ARGV_CONSTANT, (char *) 1, (char *) &child,
00064 "Set ONLY when child of PLplot TK driver" },
00065 { (char *) NULL, TK_ARGV_END, (char *) NULL, (char *) NULL,
00066 (char *) NULL }
00067 };
00068
00069
00070
00071 static int
00072 plExitCmd( ClientData clientData, Tcl_Interp *interp, int argc, char **argv );
00073
00074
00075
00076 static void
00077 tcl_cmd( Tcl_Interp *interp, char *cmd );
00078
00079
00080
00081 static int
00082 AppInit( Tcl_Interp *interp );
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 int
00096 main( int argc, const char **argv )
00097 {
00098 int i, myargc = argc;
00099 const char *myargv[20];
00100 Tcl_Interp *interp;
00101 char *helpmsg = "Command-specific options:";
00102
00103 #ifdef DEBUG
00104 fprintf( stderr, "Program %s called with arguments :\n", argv[0] );
00105 for ( i = 1; i < argc; i++ )
00106 {
00107 fprintf( stderr, "%s ", argv[i] );
00108 }
00109 fprintf( stderr, "\n" );
00110 #endif
00111
00112
00113
00114 interp = Tcl_CreateInterp();
00115
00116
00117
00118 for ( i = 0; i < argc; i++ )
00119 {
00120 myargv[i] = argv[i];
00121 }
00122
00123
00124
00125
00126 if ( Tk_ParseArgv( interp, (Tk_Window) NULL, &argc, argv,
00127 argTable, TK_ARGV_NO_DEFAULTS ) != TCL_OK )
00128 {
00129 fprintf( stderr, "\n(plserver) %s\n\n", interp->result );
00130 fprintf( stderr, "\
00131 The client_<xxx> and -child options should not be used except via the\n\
00132 PLplot/Tk driver.\n\n(wish) " );
00133 if ( strncmp( interp->result, helpmsg, strlen( helpmsg ) ) )
00134 exit( 1 );
00135 }
00136
00137
00138
00139 #if TCL_MAJOR_VERSION < 7 || ( TCL_MAJOR_VERSION == 7 && TCL_MINOR_VERSION < 5 )
00140 Tcl_DeleteInterp( interp );
00141 #endif
00142
00143
00144
00145
00146 exit( pltkMain( myargc, myargv, NULL, AppInit ) );
00147 }
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 static int
00170 AppInit( Tcl_Interp *interp )
00171 {
00172 Tk_Window mainWindow = Tk_MainWindow( interp );
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 if ( Pltk_Init( interp ) == TCL_ERROR )
00185 {
00186 return TCL_ERROR;
00187 }
00188
00189
00190
00191
00192
00193 if ( child != 0 )
00194 Tcl_SetVar( interp, "child", "1", 0 );
00195
00196
00197
00198
00199
00200 if ( client_name != NULL )
00201 {
00202 Tcl_SetVar( interp, "client_name", client_name, 0 );
00203 tcl_cmd( interp, "set dp 0" );
00204 #ifdef PLD_dp
00205 dp = 0;
00206 #endif
00207 }
00208 else if ( client_port != NULL )
00209 {
00210 #ifdef PLD_dp
00211 Tcl_SetVar( interp, "client_port", client_port, 0 );
00212 if ( client_host != NULL )
00213 Tcl_SetVar( interp, "client_host", client_host, 0 );
00214 dp = 1; tcl_cmd( interp, "set dp 1" );
00215 #else
00216 Tcl_AppendResult( interp,
00217 "no Tcl-DP support in this version of plserver",
00218 (char *) NULL );
00219 return TCL_ERROR;
00220 #endif
00221 }
00222
00223
00224
00225 if ( auto_path != NULL )
00226 {
00227 Tcl_SetVar( interp, "dir", auto_path, 0 );
00228 tcl_cmd( interp, "set auto_path [list $dir $auto_path]" );
00229 }
00230
00231
00232
00233 tcl_cmd( interp, "rename exit tkexit" );
00234
00235 Tcl_CreateCommand( interp, "exit", (Tcl_CmdProc *) plExitCmd,
00236 (ClientData) mainWindow, (Tcl_CmdDeleteProc *) NULL );
00237
00238
00239
00240 set_plplot_parameters( interp );
00241
00242 return TCL_OK;
00243 }
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253 static int
00254 plExitCmd( ClientData clientData, Tcl_Interp *interp, int argc, char **argv )
00255 {
00256 int value = 0;
00257
00258
00259
00260 if ( interp->result != NULL && interp->result[0] != '\0' )
00261 fprintf( stderr, "%s\n", interp->result );
00262
00263
00264
00265 if ( ( argc != 1 ) && ( argc != 2 ) )
00266 {
00267 Tcl_AppendResult( interp, "wrong # args: should be \"", argv[0],
00268 " ?returnCode?\"", (char *) NULL );
00269 return TCL_ERROR;
00270 }
00271 if ( ( argc != 1 ) && ( Tcl_GetInt( interp, argv[1], &value ) != TCL_OK ) )
00272 {
00273 Tcl_AppendResult( interp, "non-integer return code: \"", argv[1],
00274 "\"", (char *) NULL );
00275 return TCL_ERROR;
00276 }
00277
00278
00279
00280 Tcl_VarEval( interp, "plserver_link_end", (char **) NULL );
00281
00282
00283
00284 return Tcl_VarEval( interp, "tkexit", argv[1], (char **) NULL );
00285 }
00286
00287
00288
00289
00290
00291
00292
00293 static void
00294 tcl_cmd( Tcl_Interp *interp, char *cmd )
00295 {
00296 int result;
00297
00298 dbug_enter( "tcl_cmd" );
00299 pldebug( "tcl_cmd", "evaluating command %s\n", cmd );
00300
00301 result = Tcl_VarEval( interp, cmd, (char **) NULL );
00302 if ( result != TCL_OK )
00303 {
00304 Tcl_Eval( interp, "exit" );
00305 exit( 1 );
00306 }
00307 }