Main Page   Data Structures   File List   Data Fields   Globals  

tclSadie_proto.c

Go to the documentation of this file.
00001 /*
00002 ##########################################
00003 # tclSadie_proto.c.in -
00004 #   Template for creating tclSadie_proto.c, the main tclSadie program
00005 #   file.  tclSadie_proto.c calls tcl and tk libraries and sets up
00006 #   commands for calling SADIE functions through tcl.
00007 #
00008 # RCS: $Id: tclSadie_proto.c,v 2.1 1999/03/20 00:34:24 conner Exp $ 
00009 #
00010 # Digital Image Analysis Lab
00011 # Dept. of Electrical and Computer Engineering
00012 # University of Arizona
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 /* Global Sadie variables that must be set from within Tcl/Tk  */
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 /* RCS Indentification information */
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 /*-Copyright Information------------------------------------------------------*/
00070 /* Copyright (c) 1999 by the University of Arizona Digital Image Analysis Lab */
00071 /*----------------------------------------------------------------------------*/
00072 /*-General Information--------------------------------------------------------*/
00073 /*                                                                            */
00074 /*   This function displays the command line options for use when invoking    */
00075 /*   tclSadie.                                                                */
00076 /*                                                                            */
00077 /*----------------------------------------------------------------------------*/
00078 /*-Interface Information------------------------------------------------------*/
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 /*-Copyright Information------------------------------------------------------*/
00092 /* Copyright (c) 1999 by the University of Arizona Digital Image Analysis Lab */
00093 /*----------------------------------------------------------------------------*/
00094 /*-General Information--------------------------------------------------------*/
00095 /*                                                                            */
00096 /*   This function checks to see if a file exists.                            */
00097 /*                                                                            */
00098 /*----------------------------------------------------------------------------*/
00099 /*-Interface Information------------------------------------------------------*/
00100 int
00101 verifyfile (Tcl_Interp * interp,        /*  I  The Tcl/Tk command interpreter.                    */
00102             char *name          /*  I  The name of the file.                              */
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 /*-Copyright Information------------------------------------------------------*/
00118 /* Copyright (c) 1999 by the University of Arizona Digital Image Analysis Lab */
00119 /*----------------------------------------------------------------------------*/
00120 /*-General Information--------------------------------------------------------*/
00121 /*                                                                            */
00122 /*   This function checks to see if the environment variable TCLSADIE_PROTO_HOME    */
00123 /*   contains the location of the .tcl files needed by tclSadie.              */
00124 /*                                                                            */
00125 /*----------------------------------------------------------------------------*/
00126 /*-Interface Information------------------------------------------------------*/
00127 int
00128 setlibdir_env (Tcl_Interp * interp)
00129 {
00130   Tcl_Obj *cmds = NULL;
00131   char *libdir = NULL;
00132   int result;
00133 
00134   /* Verify that the environment variable TCLSADIE_PROTO_HOME exists */
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   /* Read the environment variable TCLSADIE_PROTO_HOME */
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 /*-Copyright Information------------------------------------------------------*/
00154 /* Copyright (c) 1999 by the University of Arizona Digital Image Analysis Lab */
00155 /*----------------------------------------------------------------------------*/
00156 /*-General Information--------------------------------------------------------*/
00157 /*                                                                            */
00158 /*   This function computes the default location of the .tcl files needed by  */
00159 /*   tclSadie, based on the location of the executable.                       */
00160 /*                                                                            */
00161 /*----------------------------------------------------------------------------*/
00162 /*-Interface Information------------------------------------------------------*/
00163 int
00164 setlibdir_default (Tcl_Interp * interp)
00165 {
00166   Tcl_Obj *cmds = NULL;
00167   char *libdirroot = NULL;
00168   int result;
00169 
00170   /* Read the environment variable TCLSADIE_PROTO_HOME */
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 /*-Copyright Information------------------------------------------------------*/
00180 /* Copyright (c) 1999 by the University of Arizona Digital Image Analysis Lab */
00181 /*----------------------------------------------------------------------------*/
00182 /*-General Information--------------------------------------------------------*/
00183 /*                                                                            */
00184 /*   This function determines the location of the .tcl library files needed   */
00185 /*   by tclSadie.                                                             */
00186 /*                                                                            */
00187 /*----------------------------------------------------------------------------*/
00188 /*-Interface Information------------------------------------------------------*/
00189 void
00190 setlibdir (Tcl_Interp * interp)
00191 {
00192   char testfile[250];
00193   Tcl_Obj *cmds = NULL;
00194 
00195   /*
00196    * First check if the library directory was supplied
00197    * on the command line.
00198    */
00199   if (!libhomeset)
00200     {
00201       /* Check if the environment variable TCLSADIE_PROTO_HOME exists */
00202       if (!setlibdir_env (interp))
00203         {
00204           /* Finally, as a last resort, try a default location */
00205           setlibdir_default (interp);
00206         }
00207     }
00208 
00209   /* Verify that tclSadie_main.tcl can be found in the library directory */
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   /* Initialize Tk values. */
00248   status = Tk_Init (interp);
00249 
00250   if (status != TCL_OK)
00251     {
00252       return TCL_ERROR;
00253     }
00254 
00255   /*
00256    * Call the init procedures for included packages.  Each call should
00257    * look like this:
00258    *
00259    * if (Mod_Init(interp) == TCL_ERROR) {
00260    *     return TCL_ERROR;
00261    * }
00262    *
00263    * where "Mod" is the name of the module.
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   /* Find the location of the library files */
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 /*-Copyright Information------------------------------------------------------*/
00331 /* Copyright (c) 1999 by the University of Arizona Digital Image Analysis Lab */
00332 /*----------------------------------------------------------------------------*/
00333 /*-General Information--------------------------------------------------------*/
00334 /*                                                                            */
00335 /*   This function parses command line arguements and spawns the Tcl/Tk       */
00336 /*   command interpreter used by tclSadie.                                    */
00337 /*                                                                            */
00338 /*----------------------------------------------------------------------------*/
00339 /*-Interface Information------------------------------------------------------*/
00340 int
00341 main (int argc, char **argv)
00342 {
00343   int i;
00344   int state = FLAG;
00345 
00346   /* Parse Command Line */
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               /* Do not use a gui interface */
00360               nogui = 1;
00361               break;
00362             case 'd':
00363               /* The next arg should be a directory */
00364               state = DIRECTORY;
00365               break;
00366             case 'f':
00367               /* The next arg should be a file */
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   /* Start TK interpreter without passing in command line options */
00411   Tk_Main (1, argv, Tcl_AppInit);
00412 
00413   return 0;
00414 }

Generated on Sun May 18 15:36:19 2003 for tclSadie by doxygen1.3