File:  [LON-CAPA] / capa / capa51 / GUITools / quizzer.c
Revision 1.1: download - view: text, annotated - select for diffs
Tue Sep 28 21:25:36 1999 UTC (24 years, 8 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
Initial revision

    1: /*
    2:  * quizzer.c
    3:  * Copyright Guy Albertelli II 1996
    4:  */
    5: #include <stdio.h>
    6: #include <tk.h>
    7: #include <stdlib.h>
    8: #include <Capa/capaCommon.h>
    9: #include <unistd.h>
   10: #include <quizzer.h>
   11: 
   12: extern Tcl_Interp *gInterp;
   13: 
   14: int Quizzer_Init(Tcl_Interp *interp);
   15: int main(int argc, char**argv)
   16: {
   17:   char * rDisplay,*q,filename[BUFFER_SIZE],buffer[BUFFER_SIZE];
   18:   int  found=1;
   19: 
   20:   gInterp=Tcl_CreateInterp();
   21:   if (gInterp ==NULL)
   22:   {
   23:     fprintf(stderr,"Couldn't get a new Tcl Interp\n");
   24:     return -1;
   25:   }
   26: 
   27:   rDisplay = getenv("DISPLAY");
   28:   
   29:   if (rDisplay==NULL)
   30:   {
   31:     fprintf(stderr,"getenv for DISPLAY returned NULL\n");
   32:     return -2;
   33:   }
   34:   
   35:   if (Tcl_SetVar2 (gInterp, "env", "DISPLAY", rDisplay, TCL_GLOBAL_ONLY) == NULL) 
   36:   {
   37:     fprintf(stderr,"Couldn't set env(DISPLAY) = %s\n",rDisplay);
   38:     return -3;
   39:   }
   40: 
   41:   q = Tcl_Merge(argc-1, argv+1);
   42:   Tcl_SetVar(gInterp, "argv", q, TCL_GLOBAL_ONLY);
   43:   ckfree(q);
   44:   sprintf(buffer, "%d", argc-1);
   45:   Tcl_SetVar(gInterp, "argc", buffer, TCL_GLOBAL_ONLY);
   46:   Tcl_SetVar(gInterp, "argv0", argv[0],TCL_GLOBAL_ONLY);
   47:   Tcl_SetVar(gInterp, "tcl_interactive","0", TCL_GLOBAL_ONLY);
   48: 
   49:   if (Tcl_Init(gInterp) == TCL_ERROR) 
   50:   {
   51:     fprintf(stderr,"Tcl_Init error\n");
   52:     fprintf(stderr,"%d\n",TCL_ERROR);
   53:     fprintf(stderr,"%s\n",gInterp->result);
   54:     return -4;
   55:   }
   56:   
   57:   if (Tk_Init(gInterp) == TCL_ERROR) 
   58:   {
   59:     fprintf(stderr,"Tk_Init error\n");
   60:     fprintf(stderr,"%d\n",TCL_ERROR);
   61:     fprintf(stderr,"%s\n",gInterp->result);
   62:     return -5;
   63:   }
   64: 
   65:   Quizzer_Init(gInterp);
   66: 
   67:   sprintf(filename,"./utils.tcl");
   68:   if( capa_access(filename, F_OK) == -1 ) {
   69:     sprintf(filename,"/usr/local/bin/Quizzer/utils.tcl");
   70:     if( capa_access(filename, F_OK) == -1 ) {
   71:       sprintf(filename,"/usr/local/lib/CAPA45/utils.tcl");
   72:       if( capa_access(filename, F_OK) == -1 ) {
   73: 	sprintf(filename,"/usr/local/lib/utils.tcl");
   74: 	if( capa_access(filename, F_OK) == -1 ) {
   75: 	  sprintf(filename,"/usr/local/lib/utils.tcl");
   76: 	  if( capa_access(filename, F_OK) == -1 ) {
   77: 	    sprintf(filename,"/usr/local/lib/CAPA45/Quizzer/utils.tcl");
   78: 	    if( capa_access(filename, F_OK) == -1 ) {
   79: 	      sprintf(filename,"/usr/lib/utils.tcl");
   80: 	      if( capa_access(filename, F_OK) == -1 ) { /* I gave up! */
   81: 		found=0;
   82: 	      } 
   83: 	    }
   84: 	  }
   85: 	} 
   86:       }
   87:     }
   88:   }
   89: 
   90:   if( found ) {
   91:     if (Tcl_EvalFile(gInterp, filename) != TCL_OK) 
   92:       {
   93: 	fprintf(stderr,"%s\n",gInterp->result);
   94: 	return -6;
   95:       }
   96:   } else {
   97:     fprintf(stderr,"Unable to find utils.tcl\n");
   98:     exit(-7);
   99:   }
  100: 
  101:   sprintf(filename,"./common.tcl");
  102:   if( capa_access(filename, F_OK) == -1 ) {
  103:     sprintf(filename,"/usr/local/bin/Quizzer/common.tcl");
  104:     if( capa_access(filename, F_OK) == -1 ) {
  105:       sprintf(filename,"/usr/local/lib/CAPA45/common.tcl");
  106:       if( capa_access(filename, F_OK) == -1 ) {
  107: 	sprintf(filename,"/usr/local/lib/common.tcl");
  108: 	if( capa_access(filename, F_OK) == -1 ) {
  109: 	  sprintf(filename,"/usr/local/lib/common.tcl");
  110: 	  if( capa_access(filename, F_OK) == -1 ) {
  111: 	    sprintf(filename,"/usr/local/lib/CAPA45/Quizzer/common.tcl");
  112: 	    if( capa_access(filename, F_OK) == -1 ) {
  113: 	      sprintf(filename,"/usr/lib/common.tcl");
  114: 	      if( capa_access(filename, F_OK) == -1 ) { /* I gave up! */
  115: 		found=0;
  116: 	      } 
  117: 	    }
  118: 	  }
  119: 	} 
  120:       }
  121:     }
  122:   }  
  123:   if( found ) {
  124:     if (Tcl_EvalFile(gInterp, filename) != TCL_OK) 
  125:       {
  126: 	fprintf(stderr,"%s\n",gInterp->result);
  127: 	return -6;
  128:       }
  129:   } else {
  130:     fprintf(stderr,"Unable to find common.tcl\n");
  131:     exit(-7);
  132:   }
  133:   sprintf(filename,"./quizzer.tcl");
  134:   if( capa_access(filename, F_OK) == -1 ) {
  135:     sprintf(filename,"/usr/local/bin/Quizzer/quizzer.tcl");
  136:     if( capa_access(filename, F_OK) == -1 ) {
  137:       sprintf(filename,"/usr/local/lib/CAPA45/quizzer.tcl");
  138:       if( capa_access(filename, F_OK) == -1 ) {
  139: 	sprintf(filename,"/usr/local/lib/quizzer.tcl");
  140: 	if( capa_access(filename, F_OK) == -1 ) {
  141: 	  sprintf(filename,"/usr/local/lib/quizzer.tcl");
  142: 	  if( capa_access(filename, F_OK) == -1 ) {
  143: 	    sprintf(filename,"/usr/local/lib/CAPA45/Quizzer/quizzer.tcl");
  144: 	    if( capa_access(filename, F_OK) == -1 ) {
  145: 	      sprintf(filename,"/usr/lib/quizzer.tcl");
  146: 	      if( capa_access(filename, F_OK) == -1 ) { /* I gave up! */
  147: 		found=0;
  148: 	      } 
  149: 	    }
  150: 	  }
  151: 	} 
  152:       }
  153:     }
  154:   }
  155: 
  156:   /*
  157:   fprintf(stderr,"HEY STILL IN DEVELOPEMENT MODE\n");
  158:   if (Tcl_EvalFile(gInterp, "quizzer.tcl") 
  159:       != TCL_OK) 
  160:   {
  161:     fprintf(stderr,"%s\n",gInterp->result);
  162:     return -6;
  163:   }
  164:   */
  165:   
  166:   if( found ) {
  167:     if (Tcl_EvalFile(gInterp, filename) != TCL_OK) 
  168:     {
  169:       fprintf(stderr,"%s\n",gInterp->result);
  170:       return -6;
  171:     }
  172:     while(Tcl_DoOneEvent(TCL_ALL_EVENTS));
  173:   } else {
  174: 	fprintf(stderr,"Unable to find quizzer.tcl\n");
  175: 	exit(-7);
  176:   }
  177:   return 0;
  178: }
  179: 
  180: 
  181: 

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