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
00022 static char rcsid[] =
00023 "$Id: tclSadie.c,v 2.5 1999/09/11 03:36:14 gopalan Exp $";
00024
00025 static int FLAG = 0;
00026 static int DIRECTORY = 1;
00027 static int CMDFILE = 2;
00028
00029 static int libhomeset = 0;
00030 static char libhome[200];
00031 static int nogui = 0;
00032 static char cmdfile[200];
00033 static int cmdfileset = 0;
00034 static char *ProgName;
00035
00036
00037
00038
00039 short nlev;
00040 short csize;
00041 double weight;
00042 double *count;
00043 PIXEL gain;
00044 PIXEL bias;
00045 PIXEL gmin;
00046 PIXEL gmax;
00047 PIXEL thresh;
00048 PIXEL gbrk[2][4];
00049 PIXEL *table;
00050
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; info exists env(TCLSADIE_HOME)", -1);
00136 Tcl_EvalObj (interp, cmds);
00137 Tcl_GetIntFromObj (interp, Tcl_GetObjResult (interp), &result);
00138
00139
00140 if (result)
00141 {
00142 cmds = Tcl_NewStringObj ("global env; set env(TCLSADIE_HOME)", -1);
00143 Tcl_EvalObj (interp, cmds);
00144 libdir = Tcl_GetStringFromObj (Tcl_GetObjResult (interp), NULL);
00145 sprintf (libhome, "%s", libdir);
00146 }
00147
00148 return result;
00149 }
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 int
00162 setlibdir_default (Tcl_Interp * interp)
00163 {
00164 Tcl_Obj *cmds = NULL;
00165 char *libdirroot = NULL;
00166 int result;
00167
00168
00169 cmds = Tcl_NewStringObj ("file dirname [info nameofexecutable]", -1);
00170 Tcl_EvalObj (interp, cmds);
00171 libdirroot = Tcl_GetStringFromObj (Tcl_GetObjResult (interp), NULL);
00172 sprintf (libhome, "%s/../lib/tclSadie", libdirroot);
00173
00174 return 1;
00175 }
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187 void
00188 setlibdir (Tcl_Interp * interp)
00189 {
00190 char testfile[250];
00191 Tcl_Obj *cmds = NULL;
00192
00193
00194
00195
00196
00197 if (!libhomeset)
00198 {
00199
00200 if (!setlibdir_env (interp))
00201 {
00202
00203 setlibdir_default (interp);
00204 }
00205 }
00206
00207
00208 sprintf (testfile, "%s/tclSadie_main.tcl", libhome);
00209 if (verifyfile (interp, testfile))
00210 {
00211 Tcl_SetVar2 (interp, "SadieVar", "libdir", libhome, TCL_GLOBAL_ONLY);
00212 cmds =
00213 Tcl_NewStringObj
00214 ("global SadieVar auto_path; lappend auto_path $SadieVar(libdir)",
00215 -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_HOME or the command line option -d.\n");
00227 usage ();
00228 exit (0);
00229 }
00230 }
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242 int
00243 Tcl_AppInit (Tcl_Interp * interp
00244 )
00245 {
00246 int status;
00247 Tcl_Obj *cmds = NULL;
00248
00249 msg_ptr = (char *) Tcl_Alloc (1024);
00250
00251 MainTclInterp = interp;
00252
00253 status = Tcl_Init (interp);
00254
00255 if (status != TCL_OK)
00256 {
00257 return TCL_ERROR;
00258 }
00259
00260
00261 status = Tk_Init (interp);
00262
00263 if (status != TCL_OK)
00264 {
00265 return TCL_ERROR;
00266 }
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279 if (Sadie_FileIO_Init (interp) == TCL_ERROR)
00280 {
00281 return TCL_ERROR;
00282 }
00283 if (Sadie_General_Init (interp) == TCL_ERROR)
00284 {
00285 return TCL_ERROR;
00286 }
00287 if (Sadie_Plot_Init (interp) == TCL_ERROR)
00288 {
00289 return TCL_ERROR;
00290 }
00291 if (Sadie_NewFunctions_Init (interp) == TCL_ERROR)
00292 {
00293 return TCL_ERROR;
00294 }
00295 if (Sadie_Contrast_Init (interp) == TCL_ERROR)
00296 {
00297 return TCL_ERROR;
00298 }
00299 if (Sadie_Filter_Init (interp) == TCL_ERROR)
00300 {
00301 return TCL_ERROR;
00302 }
00303 if (Sadie_Geometry_Init (interp) == TCL_ERROR)
00304 {
00305 return TCL_ERROR;
00306 }
00307 if (Sadie_Multi_Init (interp) == TCL_ERROR)
00308 {
00309 return TCL_ERROR;
00310 }
00311 if (Sadie_Classify_Init (interp) == TCL_ERROR)
00312 {
00313 return TCL_ERROR;
00314 }
00315 if (Sadie_Tools_Init (interp) == TCL_ERROR)
00316 {
00317 return TCL_ERROR;
00318 }
00319 if (Sadie_Image_Init (interp) == TCL_ERROR)
00320 {
00321 return TCL_ERROR;
00322 }
00323
00324
00325 setlibdir (interp);
00326 printf ("Initializing tclSadie with TCLSADIE_HOME=%s\n", libhome);
00327
00328
00329 if (Tcl_Eval (interp, "tclSadie_main_init") == TCL_ERROR)
00330 {
00331 return TCL_ERROR;
00332 }
00333 Tk_MainLoop ();
00334
00335 return TCL_OK;
00336 }
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348 int
00349 main (int argc, char **argv)
00350 {
00351 int i;
00352 int state = FLAG;
00353
00354
00355
00356 ProgName = argv[0];
00357
00358 for (i = 1; i < argc; i++)
00359 {
00360 char *arg = argv[i];
00361
00362 if (state == FLAG && *arg == '-')
00363 {
00364 switch (arg[1])
00365 {
00366 case 'n':
00367
00368 nogui = 1;
00369 break;
00370 case 'd':
00371
00372 state = DIRECTORY;
00373 break;
00374 case 'f':
00375
00376 state = CMDFILE;
00377 break;
00378 default:
00379 usage ();
00380 exit (0);
00381 break;
00382 }
00383 }
00384 else if (state == DIRECTORY && *arg != '-')
00385 {
00386 sprintf (libhome, "%s", arg);
00387 libhomeset = 1;
00388 state = FLAG;
00389 }
00390 else if (state == CMDFILE && *arg != '-')
00391 {
00392 sprintf (cmdfile, "%s", arg);
00393 cmdfileset = 1;
00394 state = FLAG;
00395 }
00396 else
00397 {
00398 usage ();
00399 exit (0);
00400 }
00401 }
00402
00403 if (nogui && !cmdfileset)
00404 {
00405 fprintf (stderr,
00406 "\nERROR: Attempting to run tclSadie with no gui without a command file!\n");
00407 usage ();
00408 exit (0);
00409 }
00410 else if (state != FLAG)
00411 {
00412 fprintf (stderr, "\nERROR: Expecting parameter after: %s\n",
00413 argv[i - 1]);
00414 usage ();
00415 exit (0);
00416 }
00417
00418
00419 Tk_Main (1, argv, Tcl_AppInit);
00420
00421 return 0;
00422 }