Annotation of capa/capa51/GUITools/grader.c, revision 1.1
1.1 ! albertel 1: /*
! 2: * grader.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 <grader.h>
! 11:
! 12: extern Tcl_Interp *gInterp;
! 13:
! 14: int Grader_Init(Tcl_Interp *interp);
! 15:
! 16: int main(int argc,char **argv)
! 17: {
! 18: char * rDisplay,*q,buffer[BUFFER_SIZE];
! 19: char filename[BUFFER_SIZE];
! 20: int found=1;
! 21:
! 22: gInterp=Tcl_CreateInterp();
! 23: if (gInterp ==NULL)
! 24: {
! 25: fprintf(stderr,"Couldn't get a new Tcl Interp\n");
! 26: return -1;
! 27: }
! 28:
! 29: rDisplay = getenv("DISPLAY");
! 30:
! 31: if (rDisplay==NULL)
! 32: {
! 33: fprintf(stderr,"getenv for DISPLAY returned NULL\n");
! 34: return -2;
! 35: }
! 36:
! 37: if (Tcl_SetVar2 (gInterp, "env", "DISPLAY", rDisplay, TCL_GLOBAL_ONLY) == NULL)
! 38: {
! 39: fprintf(stderr,"Couldn't set env(DISPLAY) = %s\n",rDisplay);
! 40: return -3;
! 41: }
! 42:
! 43: q = Tcl_Merge(argc-1, argv+1);
! 44: Tcl_SetVar(gInterp, "argv", q, TCL_GLOBAL_ONLY);
! 45: ckfree(q);
! 46: sprintf(buffer, "%d", argc-1);
! 47: Tcl_SetVar(gInterp, "argc", buffer, TCL_GLOBAL_ONLY);
! 48: Tcl_SetVar(gInterp, "argv0", argv[0],TCL_GLOBAL_ONLY);
! 49: Tcl_SetVar(gInterp, "tcl_interactive","0", TCL_GLOBAL_ONLY);
! 50:
! 51: if (Tcl_Init(gInterp) == TCL_ERROR)
! 52: {
! 53: fprintf(stderr,"Tcl_Init error\n");
! 54: fprintf(stderr,"%d\n",TCL_ERROR);
! 55: fprintf(stderr,"%s\n",gInterp->result);
! 56: return -4;
! 57: }
! 58:
! 59: if (Tk_Init(gInterp) == TCL_ERROR)
! 60: {
! 61: fprintf(stderr,"Tk_Init error\n");
! 62: fprintf(stderr,"%d\n",TCL_ERROR);
! 63: fprintf(stderr,"%s\n",gInterp->result);
! 64: return -5;
! 65: }
! 66:
! 67: Grader_Init(gInterp);
! 68:
! 69: sprintf(filename,"./utils.tcl");
! 70: if( capa_access(filename, F_OK) == -1 ) {
! 71: sprintf(filename,"/usr/local/bin/Grader/utils.tcl");
! 72: if( capa_access(filename, F_OK) == -1 ) {
! 73: sprintf(filename,"/usr/local/lib/CAPA45/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/utils.tcl");
! 78: if( capa_access(filename, F_OK) == -1 ) {
! 79: sprintf(filename,"/usr/local/lib/CAPA45/Grader/utils.tcl");
! 80: if( capa_access(filename, F_OK) == -1 ) {
! 81: sprintf(filename,"/usr/lib/utils.tcl");
! 82: if( capa_access(filename, F_OK) == -1 ) { /* I gave up! */
! 83: found=0;
! 84: }
! 85: }
! 86: }
! 87: }
! 88: }
! 89: }
! 90: }
! 91:
! 92: if( found ) {
! 93: if (Tcl_EvalFile(gInterp, filename) != TCL_OK)
! 94: {
! 95: fprintf(stderr,"%s\n",gInterp->result);
! 96: return -6;
! 97: }
! 98: } else {
! 99: fprintf(stderr,"Unable to find utils.tcl\n");
! 100: exit(-7);
! 101: }
! 102:
! 103: sprintf(filename,"./common.tcl");
! 104: if( capa_access(filename, F_OK) == -1 ) {
! 105: sprintf(filename,"/usr/local/bin/Grader/common.tcl");
! 106: if( capa_access(filename, F_OK) == -1 ) {
! 107: sprintf(filename,"/usr/local/lib/CAPA45/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/common.tcl");
! 112: if( capa_access(filename, F_OK) == -1 ) {
! 113: sprintf(filename,"/usr/local/lib/CAPA45/Grader/common.tcl");
! 114: if( capa_access(filename, F_OK) == -1 ) {
! 115: sprintf(filename,"/usr/lib/common.tcl");
! 116: if( capa_access(filename, F_OK) == -1 ) { /* I gave up! */
! 117: found=0;
! 118: }
! 119: }
! 120: }
! 121: }
! 122: }
! 123: }
! 124: }
! 125: if( found ) {
! 126: if (Tcl_EvalFile(gInterp, filename) != TCL_OK)
! 127: {
! 128: fprintf(stderr,"%s\n",gInterp->result);
! 129: return -6;
! 130: }
! 131: } else {
! 132: fprintf(stderr,"Unable to find common.tcl\n");
! 133: exit(-7);
! 134: }
! 135:
! 136: sprintf(filename,"./grader.tcl");
! 137: if( access(filename, F_OK) == -1 ) {
! 138: sprintf(filename,"/usr/local/lib/CAPA45/grader.tcl");
! 139: if( access(filename, F_OK) == -1 ) {
! 140: sprintf(filename,"/usr/local/lib/grader.tcl");
! 141: if( access(filename, F_OK) == -1 ) {
! 142: sprintf(filename,"/usr/local/lib/CAPA45/Grader/grader.tcl");
! 143: if( access(filename, F_OK) == -1 ) {
! 144: sprintf(filename,"/usr/lib/grader.tcl");
! 145: if( access(filename, F_OK) == -1 ) {
! 146: sprintf(filename,"/usr/local/bin/Grader/grader.tcl");
! 147: if( access(filename, F_OK) == -1 ) { /* I gave up! */
! 148: found=0;
! 149: }
! 150: }
! 151: }
! 152: }
! 153: }
! 154: }
! 155:
! 156: /*
! 157: fprintf(stderr,"HEY STILL IN DEVELOPEMENT MODE\n");
! 158: if (Tcl_EvalFile(gInterp, "grader.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 grader.tcl\n");
! 175: exit(-7);
! 176: }
! 177:
! 178: return 0;
! 179: }
! 180:
! 181:
! 182:
! 183:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>