Annotation of capa/capa51/GUITools/quizzer.c, revision 1.4

1.2       albertel    1: /* main program startup for Quizzer
                      2:    Copyright (C) 1992-2000 Michigan State University
                      3: 
                      4:    The CAPA system is free software; you can redistribute it and/or
1.4     ! albertel    5:    modify it under the terms of the GNU General Public License as
1.2       albertel    6:    published by the Free Software Foundation; either version 2 of the
                      7:    License, or (at your option) any later version.
                      8: 
                      9:    The CAPA system is distributed in the hope that it will be useful,
                     10:    but WITHOUT ANY WARRANTY; without even the implied warranty of
                     11:    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1.4     ! albertel   12:    General Public License for more details.
1.2       albertel   13: 
1.4     ! albertel   14:    You should have received a copy of the GNU General Public
1.2       albertel   15:    License along with the CAPA system; see the file COPYING.  If not,
                     16:    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
                     17:    Boston, MA 02111-1307, USA.
                     18: 
                     19:    As a special exception, you have permission to link this program
                     20:    with the TtH/TtM library and distribute executables, as long as you
                     21:    follow the requirements of the GNU GPL in regard to all of the
                     22:    software in the executable aside from TtH/TtM.
                     23: */
                     24: 
1.1       albertel   25: /*
                     26:  * quizzer.c
1.2       albertel   27:  * Guy Albertelli II 1996
1.1       albertel   28:  */
                     29: #include <stdio.h>
                     30: #include <tk.h>
                     31: #include <stdlib.h>
1.3       albertel   32: #include <pProj/capaCommon.h>
1.1       albertel   33: #include <unistd.h>
                     34: #include <quizzer.h>
                     35: 
                     36: extern Tcl_Interp *gInterp;
                     37: 
                     38: int Quizzer_Init(Tcl_Interp *interp);
                     39: int main(int argc, char**argv)
                     40: {
                     41:   char * rDisplay,*q,filename[BUFFER_SIZE],buffer[BUFFER_SIZE];
                     42:   int  found=1;
                     43: 
                     44:   gInterp=Tcl_CreateInterp();
                     45:   if (gInterp ==NULL)
                     46:   {
                     47:     fprintf(stderr,"Couldn't get a new Tcl Interp\n");
                     48:     return -1;
                     49:   }
                     50: 
                     51:   rDisplay = getenv("DISPLAY");
                     52:   
                     53:   if (rDisplay==NULL)
                     54:   {
                     55:     fprintf(stderr,"getenv for DISPLAY returned NULL\n");
                     56:     return -2;
                     57:   }
                     58:   
                     59:   if (Tcl_SetVar2 (gInterp, "env", "DISPLAY", rDisplay, TCL_GLOBAL_ONLY) == NULL) 
                     60:   {
                     61:     fprintf(stderr,"Couldn't set env(DISPLAY) = %s\n",rDisplay);
                     62:     return -3;
                     63:   }
                     64: 
                     65:   q = Tcl_Merge(argc-1, argv+1);
                     66:   Tcl_SetVar(gInterp, "argv", q, TCL_GLOBAL_ONLY);
                     67:   ckfree(q);
                     68:   sprintf(buffer, "%d", argc-1);
                     69:   Tcl_SetVar(gInterp, "argc", buffer, TCL_GLOBAL_ONLY);
                     70:   Tcl_SetVar(gInterp, "argv0", argv[0],TCL_GLOBAL_ONLY);
                     71:   Tcl_SetVar(gInterp, "tcl_interactive","0", TCL_GLOBAL_ONLY);
                     72: 
                     73:   if (Tcl_Init(gInterp) == TCL_ERROR) 
                     74:   {
                     75:     fprintf(stderr,"Tcl_Init error\n");
                     76:     fprintf(stderr,"%d\n",TCL_ERROR);
                     77:     fprintf(stderr,"%s\n",gInterp->result);
                     78:     return -4;
                     79:   }
                     80:   
                     81:   if (Tk_Init(gInterp) == TCL_ERROR) 
                     82:   {
                     83:     fprintf(stderr,"Tk_Init error\n");
                     84:     fprintf(stderr,"%d\n",TCL_ERROR);
                     85:     fprintf(stderr,"%s\n",gInterp->result);
                     86:     return -5;
                     87:   }
                     88: 
                     89:   Quizzer_Init(gInterp);
                     90: 
                     91:   sprintf(filename,"./utils.tcl");
                     92:   if( capa_access(filename, F_OK) == -1 ) {
                     93:     sprintf(filename,"/usr/local/bin/Quizzer/utils.tcl");
                     94:     if( capa_access(filename, F_OK) == -1 ) {
                     95:       sprintf(filename,"/usr/local/lib/CAPA45/utils.tcl");
                     96:       if( capa_access(filename, F_OK) == -1 ) {
                     97: 	sprintf(filename,"/usr/local/lib/utils.tcl");
                     98: 	if( capa_access(filename, F_OK) == -1 ) {
                     99: 	  sprintf(filename,"/usr/local/lib/utils.tcl");
                    100: 	  if( capa_access(filename, F_OK) == -1 ) {
                    101: 	    sprintf(filename,"/usr/local/lib/CAPA45/Quizzer/utils.tcl");
                    102: 	    if( capa_access(filename, F_OK) == -1 ) {
                    103: 	      sprintf(filename,"/usr/lib/utils.tcl");
                    104: 	      if( capa_access(filename, F_OK) == -1 ) { /* I gave up! */
                    105: 		found=0;
                    106: 	      } 
                    107: 	    }
                    108: 	  }
                    109: 	} 
                    110:       }
                    111:     }
                    112:   }
                    113: 
                    114:   if( found ) {
                    115:     if (Tcl_EvalFile(gInterp, filename) != TCL_OK) 
                    116:       {
                    117: 	fprintf(stderr,"%s\n",gInterp->result);
                    118: 	return -6;
                    119:       }
                    120:   } else {
                    121:     fprintf(stderr,"Unable to find utils.tcl\n");
                    122:     exit(-7);
                    123:   }
                    124: 
                    125:   sprintf(filename,"./common.tcl");
                    126:   if( capa_access(filename, F_OK) == -1 ) {
                    127:     sprintf(filename,"/usr/local/bin/Quizzer/common.tcl");
                    128:     if( capa_access(filename, F_OK) == -1 ) {
                    129:       sprintf(filename,"/usr/local/lib/CAPA45/common.tcl");
                    130:       if( capa_access(filename, F_OK) == -1 ) {
                    131: 	sprintf(filename,"/usr/local/lib/common.tcl");
                    132: 	if( capa_access(filename, F_OK) == -1 ) {
                    133: 	  sprintf(filename,"/usr/local/lib/common.tcl");
                    134: 	  if( capa_access(filename, F_OK) == -1 ) {
                    135: 	    sprintf(filename,"/usr/local/lib/CAPA45/Quizzer/common.tcl");
                    136: 	    if( capa_access(filename, F_OK) == -1 ) {
                    137: 	      sprintf(filename,"/usr/lib/common.tcl");
                    138: 	      if( capa_access(filename, F_OK) == -1 ) { /* I gave up! */
                    139: 		found=0;
                    140: 	      } 
                    141: 	    }
                    142: 	  }
                    143: 	} 
                    144:       }
                    145:     }
                    146:   }  
                    147:   if( found ) {
                    148:     if (Tcl_EvalFile(gInterp, filename) != TCL_OK) 
                    149:       {
                    150: 	fprintf(stderr,"%s\n",gInterp->result);
                    151: 	return -6;
                    152:       }
                    153:   } else {
                    154:     fprintf(stderr,"Unable to find common.tcl\n");
                    155:     exit(-7);
                    156:   }
                    157:   sprintf(filename,"./quizzer.tcl");
                    158:   if( capa_access(filename, F_OK) == -1 ) {
                    159:     sprintf(filename,"/usr/local/bin/Quizzer/quizzer.tcl");
                    160:     if( capa_access(filename, F_OK) == -1 ) {
                    161:       sprintf(filename,"/usr/local/lib/CAPA45/quizzer.tcl");
                    162:       if( capa_access(filename, F_OK) == -1 ) {
                    163: 	sprintf(filename,"/usr/local/lib/quizzer.tcl");
                    164: 	if( capa_access(filename, F_OK) == -1 ) {
                    165: 	  sprintf(filename,"/usr/local/lib/quizzer.tcl");
                    166: 	  if( capa_access(filename, F_OK) == -1 ) {
                    167: 	    sprintf(filename,"/usr/local/lib/CAPA45/Quizzer/quizzer.tcl");
                    168: 	    if( capa_access(filename, F_OK) == -1 ) {
                    169: 	      sprintf(filename,"/usr/lib/quizzer.tcl");
                    170: 	      if( capa_access(filename, F_OK) == -1 ) { /* I gave up! */
                    171: 		found=0;
                    172: 	      } 
                    173: 	    }
                    174: 	  }
                    175: 	} 
                    176:       }
                    177:     }
                    178:   }
                    179: 
                    180:   /*
                    181:   fprintf(stderr,"HEY STILL IN DEVELOPEMENT MODE\n");
                    182:   if (Tcl_EvalFile(gInterp, "quizzer.tcl") 
                    183:       != TCL_OK) 
                    184:   {
                    185:     fprintf(stderr,"%s\n",gInterp->result);
                    186:     return -6;
                    187:   }
                    188:   */
                    189:   
                    190:   if( found ) {
                    191:     if (Tcl_EvalFile(gInterp, filename) != TCL_OK) 
                    192:     {
                    193:       fprintf(stderr,"%s\n",gInterp->result);
                    194:       return -6;
                    195:     }
                    196:     while(Tcl_DoOneEvent(TCL_ALL_EVENTS));
                    197:   } else {
                    198: 	fprintf(stderr,"Unable to find quizzer.tcl\n");
                    199: 	exit(-7);
                    200:   }
                    201:   return 0;
                    202: }
                    203: 
                    204: 
                    205: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>