Annotation of capa/capa51/GUITools/grader.c, revision 1.2

1.2     ! albertel    1: /* interfaces to the C portions of CAPA for the grading of students
        !             2:    Copyright (C) 1992-2000 Michigan State University
        !             3: 
        !             4:    The CAPA system is free software; you can redistribute it and/or
        !             5:    modify it under the terms of the GNU Library General Public License as
        !             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
        !            12:    Library General Public License for more details.
        !            13: 
        !            14:    You should have received a copy of the GNU Library General Public
        !            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:  * grader.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>
                     32: #include <Capa/capaCommon.h>
                     33: #include <unistd.h>
                     34: #include <grader.h> 
                     35: 
                     36: extern Tcl_Interp *gInterp;
                     37: 
                     38: int Grader_Init(Tcl_Interp *interp);
                     39: 
                     40: int main(int argc,char **argv)
                     41: {
                     42:   char * rDisplay,*q,buffer[BUFFER_SIZE];
                     43:   char filename[BUFFER_SIZE];
                     44:   int found=1;
                     45: 
                     46:   gInterp=Tcl_CreateInterp();
                     47:   if (gInterp ==NULL)
                     48:   {
                     49:     fprintf(stderr,"Couldn't get a new Tcl Interp\n");
                     50:     return -1;
                     51:   }
                     52: 
                     53:   rDisplay = getenv("DISPLAY");
                     54:   
                     55:   if (rDisplay==NULL)
                     56:   {
                     57:     fprintf(stderr,"getenv for DISPLAY returned NULL\n");
                     58:     return -2;
                     59:   }
                     60:   
                     61:   if (Tcl_SetVar2 (gInterp, "env", "DISPLAY", rDisplay, TCL_GLOBAL_ONLY) == NULL) 
                     62:   {
                     63:     fprintf(stderr,"Couldn't set env(DISPLAY) = %s\n",rDisplay);
                     64:     return -3;
                     65:   }
                     66: 
                     67:   q = Tcl_Merge(argc-1, argv+1);
                     68:   Tcl_SetVar(gInterp, "argv", q, TCL_GLOBAL_ONLY);
                     69:   ckfree(q);
                     70:   sprintf(buffer, "%d", argc-1);
                     71:   Tcl_SetVar(gInterp, "argc", buffer, TCL_GLOBAL_ONLY);
                     72:   Tcl_SetVar(gInterp, "argv0", argv[0],TCL_GLOBAL_ONLY);
                     73:   Tcl_SetVar(gInterp, "tcl_interactive","0", TCL_GLOBAL_ONLY);
                     74: 
                     75:   if (Tcl_Init(gInterp) == TCL_ERROR) 
                     76:   {
                     77:     fprintf(stderr,"Tcl_Init error\n");
                     78:     fprintf(stderr,"%d\n",TCL_ERROR);
                     79:     fprintf(stderr,"%s\n",gInterp->result);
                     80:     return -4;
                     81:   }
                     82:   
                     83:   if (Tk_Init(gInterp) == TCL_ERROR) 
                     84:   {
                     85:     fprintf(stderr,"Tk_Init error\n");
                     86:     fprintf(stderr,"%d\n",TCL_ERROR);
                     87:     fprintf(stderr,"%s\n",gInterp->result);
                     88:     return -5;  
                     89:   }
                     90: 
                     91:   Grader_Init(gInterp);
                     92: 
                     93:   sprintf(filename,"./utils.tcl");
                     94:   if( capa_access(filename, F_OK) == -1 ) {
                     95:     sprintf(filename,"/usr/local/bin/Grader/utils.tcl");
                     96:     if( capa_access(filename, F_OK) == -1 ) {
                     97:       sprintf(filename,"/usr/local/lib/CAPA45/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/utils.tcl");
                    102: 	  if( capa_access(filename, F_OK) == -1 ) {
                    103: 	    sprintf(filename,"/usr/local/lib/CAPA45/Grader/utils.tcl");
                    104: 	    if( capa_access(filename, F_OK) == -1 ) {
                    105: 	      sprintf(filename,"/usr/lib/utils.tcl");
                    106: 	      if( capa_access(filename, F_OK) == -1 ) { /* I gave up! */
                    107: 		found=0;
                    108: 	      } 
                    109: 	    }
                    110: 	  }
                    111: 	} 
                    112:       }
                    113:     }
                    114:   }
                    115: 
                    116:   if( found ) {
                    117:     if (Tcl_EvalFile(gInterp, filename) != TCL_OK) 
                    118:       {
                    119: 	fprintf(stderr,"%s\n",gInterp->result);
                    120: 	return -6;
                    121:       }
                    122:   } else {
                    123:     fprintf(stderr,"Unable to find utils.tcl\n");
                    124:     exit(-7);
                    125:   }
                    126: 
                    127:   sprintf(filename,"./common.tcl");
                    128:   if( capa_access(filename, F_OK) == -1 ) {
                    129:     sprintf(filename,"/usr/local/bin/Grader/common.tcl");
                    130:     if( capa_access(filename, F_OK) == -1 ) {
                    131:       sprintf(filename,"/usr/local/lib/CAPA45/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/common.tcl");
                    136: 	  if( capa_access(filename, F_OK) == -1 ) {
                    137: 	    sprintf(filename,"/usr/local/lib/CAPA45/Grader/common.tcl");
                    138: 	    if( capa_access(filename, F_OK) == -1 ) {
                    139: 	      sprintf(filename,"/usr/lib/common.tcl");
                    140: 	      if( capa_access(filename, F_OK) == -1 ) { /* I gave up! */
                    141: 		found=0;
                    142: 	      } 
                    143: 	    }
                    144: 	  }
                    145: 	} 
                    146:       }
                    147:     }
                    148:   }  
                    149:   if( found ) {
                    150:     if (Tcl_EvalFile(gInterp, filename) != TCL_OK) 
                    151:       {
                    152: 	fprintf(stderr,"%s\n",gInterp->result);
                    153: 	return -6;
                    154:       }
                    155:   } else {
                    156:     fprintf(stderr,"Unable to find common.tcl\n");
                    157:     exit(-7);
                    158:   }
                    159: 
                    160:   sprintf(filename,"./grader.tcl");
                    161:   if( access(filename, F_OK) == -1 ) {
                    162:     sprintf(filename,"/usr/local/lib/CAPA45/grader.tcl");
                    163:     if( access(filename, F_OK) == -1 ) {
                    164:       sprintf(filename,"/usr/local/lib/grader.tcl");
                    165:       if( access(filename, F_OK) == -1 ) {
                    166:         sprintf(filename,"/usr/local/lib/CAPA45/Grader/grader.tcl");
                    167:         if( access(filename, F_OK) == -1 ) {
                    168:           sprintf(filename,"/usr/lib/grader.tcl");
                    169:           if( access(filename, F_OK) == -1 ) {
                    170: 	    sprintf(filename,"/usr/local/bin/Grader/grader.tcl");
                    171:             if( access(filename, F_OK) == -1 ) { /* I gave up! */
                    172:               found=0;
                    173:             } 
                    174:           }
                    175:         }
                    176:       } 
                    177:     }
                    178:   }
                    179:  
                    180:   /*
                    181:   fprintf(stderr,"HEY STILL IN DEVELOPEMENT MODE\n");
                    182:   if (Tcl_EvalFile(gInterp, "grader.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 grader.tcl\n");
                    199: 	exit(-7);
                    200:   }
                    201:   
                    202:   return 0;
                    203: }
                    204: 
                    205: 
                    206: 
                    207: 

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