00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <stdio.h>
00017 #include <tcl.h>
00018 #include <tk.h>
00019 #include "sadie.h"
00020
00021 static int FLAG = 0;
00022 static int DIRECTORY = 1;
00023 static int CMDFILE = 2;
00024
00025 static int libhomeset = 0;
00026 static char libhome[200];
00027 static int nogui = 0;
00028 static char cmdfile[200];
00029 static int cmdfileset = 0;
00030 static char *ProgName;
00031
00032
00033
00034
00035 short nlev;
00036 short csize;
00037 double weight;
00038 double *count;
00039 PIXEL gain;
00040 PIXEL bias;
00041 PIXEL gmin;
00042 PIXEL gmax;
00043 PIXEL thresh;
00044 PIXEL gbrk[2][4];
00045 PIXEL *table;
00046
00047
00048
00049 static char rcsid[] =
00050 "$Id: tclSadie_proto.c,v 2.1 1999/03/20 00:34:24 conner Exp $";
00051
00052 char *msg_ptr;
00053 Tcl_Interp *MainTclInterp;
00054
00055 int Sadie_FileIO_Init (Tcl_Interp * interp);
00056 int Sadie_General_Init (Tcl_Interp * interp);
00057 int Sadie_Plot_Init (Tcl_Interp * interp);
00058 int Sadie_NewFunctions_Init (Tcl_Interp * interp);
00059 int Sadie_Contrast_Init (Tcl_Interp * interp);
00060 int Sadie_Filter_Init (Tcl_Interp * interp);
00061 int Sadie_Geometry_Init (Tcl_Interp * interp);
00062 int Sadie_Multi_Init (Tcl_Interp * interp);
00063 int Sadie_Classify_Init (Tcl_Interp * interp);
00064 int Sadie_Tools_Init (Tcl_Interp * interp);
00065 int Sadie_Image_Init (Tcl_Interp * interp);
00066
00067 int Sadie_Proto_Init (Tcl_Interp * interp);
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 void
00080 usage (void)
00081 {
00082 fprintf (stderr, "\nUsage: %s [options]\n", ProgName);
00083 fprintf (stderr, "Options:\n");
00084 fprintf (stderr, "\t-d <tclSadie library directory>\n");
00085 fprintf (stderr, "\t-f <command script file>\n");
00086 fprintf (stderr, "\t-nogui\trun tclSadie without a graphical interface\n");
00087 fprintf (stderr, "\t-h\tprint this message\n");
00088 fprintf (stderr, "\n");
00089 }
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 int
00101 verifyfile (Tcl_Interp * interp,
00102 char *name
00103 )
00104 {
00105 Tcl_Obj *cmds = NULL;
00106 char tempstr[250];
00107 int result;
00108
00109 sprintf (tempstr, "file exists %s", name);
00110 cmds = Tcl_NewStringObj (tempstr, -1);
00111 Tcl_EvalObj (interp, cmds);
00112 Tcl_GetIntFromObj (interp, Tcl_GetObjResult (interp), &result);
00113
00114 return result;
00115 }
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 int
00128 setlibdir_env (Tcl_Interp * interp)
00129 {
00130 Tcl_Obj *cmds = NULL;
00131 char *libdir = NULL;
00132 int result;
00133
00134
00135 cmds = Tcl_NewStringObj ("global env
00136 info exists env(TCLSADIE_PROTO_HOME)", -1);
00137 Tcl_EvalObj (interp, cmds);
00138 Tcl_GetIntFromObj (interp, Tcl_GetObjResult (interp), &result);
00139
00140
00141 if (result)
00142 {
00143 cmds = Tcl_NewStringObj ("global env
00144 set env(TCLSADIE_PROTO_HOME)", -1);
00145 Tcl_EvalObj (interp, cmds);
00146 libdir = Tcl_GetStringFromObj (Tcl_GetObjResult (interp), NULL);
00147 sprintf (libhome, "%s", libdir);
00148 }
00149
00150 return result;
00151 }
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 int
00164 setlibdir_default (Tcl_Interp * interp)
00165 {
00166 Tcl_Obj *cmds = NULL;
00167 char *libdirroot = NULL;
00168 int result;
00169
00170
00171 cmds = Tcl_NewStringObj ("file dirname [info nameofexecutable]", -1);
00172 Tcl_EvalObj (interp, cmds);
00173 libdirroot = Tcl_GetStringFromObj (Tcl_GetObjResult (interp), NULL);
00174 sprintf (libhome, "%s/../lib/tclSadie", libdirroot);
00175
00176 return 1;
00177 }
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 void
00190 setlibdir (Tcl_Interp * interp)
00191 {
00192 char testfile[250];
00193 Tcl_Obj *cmds = NULL;
00194
00195
00196
00197
00198
00199 if (!libhomeset)
00200 {
00201
00202 if (!setlibdir_env (interp))
00203 {
00204
00205 setlibdir_default (interp);
00206 }
00207 }
00208
00209
00210 sprintf (testfile, "%s/tclSadie_main.tcl", libhome);
00211 if (verifyfile (interp, testfile))
00212 {
00213 Tcl_SetVar2 (interp, "SadieVar", "libdir", libhome, TCL_GLOBAL_ONLY);
00214 cmds = Tcl_NewStringObj ("global SadieVar auto_path
00215 lappend auto_path $SadieVar(libdir)", -1);
00216 Tcl_EvalObj (interp, cmds);
00217 }
00218 else
00219 {
00220 fprintf (stderr,
00221 "\nERROR: tclSadie library directory: %s is not valid!\n",
00222 libhome);
00223 fprintf (stderr,
00224 " \tYou can indicate the location of the library by using the\n");
00225 fprintf (stderr,
00226 " \tenvironment variable TCLSADIE_PROTO_HOME or the command line option -d.\n");
00227 usage ();
00228 exit (0);
00229 }
00230 }
00231
00232 int
00233 Tcl_AppInit (Tcl_Interp * interp)
00234 {
00235 int status;
00236 msg_ptr = (char *) Tcl_Alloc (1024);
00237
00238 MainTclInterp = interp;
00239
00240 status = Tcl_Init (interp);
00241
00242 if (status != TCL_OK)
00243 {
00244 return TCL_ERROR;
00245 }
00246
00247
00248 status = Tk_Init (interp);
00249
00250 if (status != TCL_OK)
00251 {
00252 return TCL_ERROR;
00253 }
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266 if (Sadie_FileIO_Init (interp) == TCL_ERROR)
00267 {
00268 return TCL_ERROR;
00269 }
00270 if (Sadie_General_Init (interp) == TCL_ERROR)
00271 {
00272 return TCL_ERROR;
00273 }
00274 if (Sadie_Plot_Init (interp) == TCL_ERROR)
00275 {
00276 return TCL_ERROR;
00277 }
00278 if (Sadie_NewFunctions_Init (interp) == TCL_ERROR)
00279 {
00280 return TCL_ERROR;
00281 }
00282 if (Sadie_Contrast_Init (interp) == TCL_ERROR)
00283 {
00284 return TCL_ERROR;
00285 }
00286 if (Sadie_Filter_Init (interp) == TCL_ERROR)
00287 {
00288 return TCL_ERROR;
00289 }
00290 if (Sadie_Geometry_Init (interp) == TCL_ERROR)
00291 {
00292 return TCL_ERROR;
00293 }
00294 if (Sadie_Multi_Init (interp) == TCL_ERROR)
00295 {
00296 return TCL_ERROR;
00297 }
00298 if (Sadie_Classify_Init (interp) == TCL_ERROR)
00299 {
00300 return TCL_ERROR;
00301 }
00302 if (Sadie_Tools_Init (interp) == TCL_ERROR)
00303 {
00304 return TCL_ERROR;
00305 }
00306 if (Sadie_Image_Init (interp) == TCL_ERROR)
00307 {
00308 return TCL_ERROR;
00309 }
00310
00311 if (Sadie_Proto_Init (interp) == TCL_ERROR)
00312 {
00313 return TCL_ERROR;
00314 }
00315
00316
00317 setlibdir (interp);
00318 printf ("Initializing tclSadie_proto with TCLSADIE_PROTO_HOME=%s\n",
00319 libhome);
00320
00321 if (Tcl_Eval (interp, "tclSadie_proto_init") == TCL_ERROR)
00322 {
00323 return TCL_ERROR;
00324 }
00325 Tk_MainLoop ();
00326
00327 return TCL_OK;
00328 }
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340 int
00341 main (int argc, char **argv)
00342 {
00343 int i;
00344 int state = FLAG;
00345
00346
00347
00348 ProgName = argv[0];
00349
00350 for (i = 1; i < argc; i++)
00351 {
00352 char *arg = argv[i];
00353
00354 if (state == FLAG && *arg == '-')
00355 {
00356 switch (arg[1])
00357 {
00358 case 'n':
00359
00360 nogui = 1;
00361 break;
00362 case 'd':
00363
00364 state = DIRECTORY;
00365 break;
00366 case 'f':
00367
00368 state = CMDFILE;
00369 break;
00370 default:
00371 usage ();
00372 exit (0);
00373 break;
00374 }
00375 }
00376 else if (state == DIRECTORY && *arg != '-')
00377 {
00378 sprintf (libhome, "%s", arg);
00379 libhomeset = 1;
00380 state = FLAG;
00381 }
00382 else if (state == CMDFILE && *arg != '-')
00383 {
00384 sprintf (cmdfile, "%s", arg);
00385 cmdfileset = 1;
00386 state = FLAG;
00387 }
00388 else
00389 {
00390 usage ();
00391 exit (0);
00392 }
00393 }
00394
00395 if (nogui && !cmdfileset)
00396 {
00397 fprintf (stderr,
00398 "\nERROR: Attempting to run tclSadie with no gui without a command file!\n");
00399 usage ();
00400 exit (0);
00401 }
00402 else if (state != FLAG)
00403 {
00404 fprintf (stderr, "\nERROR: Expecting parameter after: %s\n",
00405 argv[i - 1]);
00406 usage ();
00407 exit (0);
00408 }
00409
00410
00411 Tk_Main (1, argv, Tcl_AppInit);
00412
00413 return 0;
00414 }