Annotation of capa/capa51/GUITools/common.funct.c, revision 1.3

1.1       albertel    1: /*
                      2:  * common.funct.c
                      3:  * Copyright Guy Albertelli II 1998
                      4:  * Portions Copyright Issac Tsai
                      5:  */
                      6: #include <stdio.h>
                      7: #include <tk.h>
                      8: #include <Capa/capaCommon.h>
                      9: #include <common.h>
                     10: #include <ctype.h>
                     11: #include <time.h>
                     12: #include <sys/types.h>
                     13: #include <sys/wait.h>
                     14: 
                     15: /* Used by the parse front end to escape any special characters in TCL */
                     16: /* arguments are source buffer, destination buffer, and where to start */
                     17: /* in the destination buffer                                           */
                     18: int capaPrepareBuffer(char *buf,char *buf2,int j)
                     19: {
                     20:   int i;
                     21:   for(i=0;i<strlen(buf);i++,j++)
                     22:     {
                     23:       switch(buf[i])
                     24: 	{
                     25: 	case '$':case '[': case ']': case '{': case '}': case '\\': case '"':
                     26: 	  buf2[j]='\\';
                     27: 	  j++;
                     28: 	  buf2[j]=buf[i];
                     29: 	  break;
                     30: 	default:
                     31: 	  buf2[j]=buf[i];
                     32: 	  break;
                     33: 	}
                     34:     }
                     35:   buf2[j]='\0';
                     36:   return j;
                     37: }
                     38: 
                     39: int bufInsert(Tcl_Interp*interp,char*window,char*string) 
                     40: {
                     41:   char *buf;
                     42:   char *buf2;
                     43: #ifdef _UPDATE
                     44:   char *update=";update";
                     45: #else
                     46:   char *update=" ";
                     47: #endif
                     48: 
                     49:   buf=capa_malloc(BUFFER_SIZE+strlen(string)*2,1);
                     50:   buf2=capa_malloc(BUFFER_SIZE+strlen(string)*3,1);
                     51:   capaPrepareBuffer(string,buf,0);
                     52:   sprintf(buf2,"%s insert end \"%s\" answer%s",window,buf,update);
                     53:   if (Tcl_Eval(interp,buf2) != TCL_OK) { fprintf(stderr,"problem with bufInsert\n"); }
                     54:   capa_mfree(buf);
                     55:   capa_mfree(buf2);
                     56: }
                     57: 
                     58: void print_begin_item(int mode,Tcl_Interp *interp,char *window,int q_idx)
                     59: {
                     60:   char buf[BUFFER_SIZE];
                     61:   switch(mode) {
                     62:     case TeX_MODE: bufInsert(interp,window, "\\item "); break;
                     63:     case ASCII_MODE:
                     64:           sprintf(buf, "%d) ", q_idx); 
                     65: 	  bufInsert(interp,window,buf); break;
                     66:     case HTML_MODE: bufInsert(interp,window, "<LI> "); break;
                     67:   }
                     68: }
                     69: 
                     70: void capaInsertAnswer(Problem_t *p,Tcl_Interp *interp, char *window) {
                     71:   extern int Parsemode_f;
                     72:   char* answer;
                     73: 
                     74:   answer=answers_string(Parsemode_f,p);
                     75:   bufInsert(interp,window,answer);
                     76:   capa_mfree(answer);
                     77: }
                     78: 
                     79: /* updates the gDate var with the current date and reregisters itself
                     80:  * to run in .8 seconds
                     81:  */
                     82: 
                     83: int capaDateUpdate(ClientData clientdata, Tcl_Interp *interp, int argc, 
                     84: 		   char *argv[])
                     85: {
                     86:   time_t rightNow=time(NULL);
                     87: 
                     88:   if (Tcl_SetVar(interp,"gDate",asctime(localtime(&rightNow)),
                     89: 		 TCL_GLOBAL_ONLY) == NULL)
                     90:     {
                     91:       fprintf(stderr,"Tcl_Eval error\n");
                     92:       fprintf(stderr,"%s\n",interp->result);
                     93:       return TCL_ERROR;
                     94:     }
                     95: 
                     96:   if (Tcl_Eval(interp,"after 800 { dateUpdate } ") != TCL_OK)
                     97:     {
                     98:       fprintf(stderr,"Tcl_Eval error\n");
                     99:       fprintf(stderr,"%s\n",interp->result);
                    100:       return TCL_ERROR;
                    101:     }
                    102:   return TCL_OK;
                    103: }
                    104: 
                    105: int capaGetExistingSections(ClientData clientdata, Tcl_Interp *interp, 
                    106: 			int argc, char *argv[])
                    107: {
                    108:   int i=0,result,sectionArray[MAX_SECTION_COUNT];
                    109:   char buf[BUFFER_SIZE];
                    110: 
                    111:   Tcl_ResetResult(interp);
                    112:   result=capa_get_section_count(sectionArray);
                    113:   if (result==-1)
                    114:     {
                    115:       Tcl_AppendElement(interp,"Unable to find a classl file.\n");
                    116:       return TCL_ERROR;
                    117:     }
                    118:   for(i=1;i<=sectionArray[0];i++) 
                    119:     {
                    120:       if ( sectionArray[i] !=0 ) 
                    121: 	{
                    122: 	  sprintf(buf,"%d %d",i, sectionArray[i]);
                    123: 	  Tcl_AppendElement(interp,buf);
                    124: 	}
                    125:     }
                    126:   return TCL_OK;
                    127: }
                    128: 
1.2       albertel  129: /* finds how many set.db files there are */
                    130: int howManySetDBFile()
                    131: {
                    132:   char     filename[BUFFER_SIZE], *pathName;
                    133:   int     ii;
                    134:   
                    135:   pathName=getcwd(NULL,BUFFER_SIZE);
                    136:   ii=1;
                    137:   sprintf(filename,"%s/records/set%d.db",pathName,ii);
                    138:   while(!access(filename, F_OK)) {
                    139:     ii++;
                    140:     sprintf(filename,"%s/records/set%d.db",pathName,ii);
                    141:   }
                    142:   free(pathName);
                    143:   return (ii-1);
                    144: }
                    145: 
1.3     ! albertel  146: /* argv[1] is student number argv[2] is setnumber */
        !           147: int capaGetSpecifiCapaId(ClientData clientdata, Tcl_Interp *interp, int argc, 
        !           148: 			 char *argv[])
        !           149: {
        !           150:   char buf[MAX_BUFFER_SIZE];
        !           151:   if (argc==3) {
        !           152:     sprintf(buf,"%d",capa_PIN(argv[1],atoi(argv[2]),0));
        !           153:     Tcl_AppendElement(interp,buf);
        !           154:   } else {
        !           155:     sprintf(buf,"Usage: %s StudentNumber SetNumber",argv[0]);
        !           156:     Tcl_AppendElement(interp,buf);
        !           157:   }
        !           158:   return TCL_OK;
        !           159: }
        !           160: 
        !           161: /* argv[1] is student number argv[2] is section number argv[3] is setnumber */
        !           162: int capaIsSetOpen(ClientData clientdata, Tcl_Interp *interp, int argc, 
        !           163: 			 char *argv[])
        !           164: {
        !           165:   char buf[MAX_BUFFER_SIZE];
        !           166:   if (argc==4) {
        !           167:     sprintf(buf,"%d",capa_check_date(CHECK_OPEN_DATE,argv[1],atoi(argv[2]),atoi(argv[3])));
        !           168:     Tcl_AppendElement(interp,buf);
        !           169:   } else {
        !           170:     sprintf(buf,"Usage: %s StudentNumber SectionNumber SetNumber",argv[0]);
        !           171:     Tcl_AppendElement(interp,buf);
        !           172:   }
        !           173:   return TCL_OK;
        !           174: }
1.2       albertel  175: 
1.1       albertel  176: void message()
                    177: {
1.3     ! albertel  178:   signed char *message=
1.1       albertel  179: "*****                *****        ************        *****               *****\n"
                    180: "******              ******     ******************     *****               *****\n"
                    181: " ******            ******    ****              ****    ****               **** \n"
                    182: " *******          *******   ****                ****   ****               **** \n"
                    183: " ********        ********   ****                ****   ****               **** \n"
                    184: " **** ****      **** ****   ****                       ****               **** \n"
                    185: " ****  ****    ****  ****   ****                       ****               **** \n"
                    186: " ****   ****  ****   ****   ****                       ****               **** \n"
                    187: " ****    ********    ****    ****                      ****               **** \n"
                    188: " ****     ******     ****      ***************         ****               **** \n"
                    189: " ****      ****      ****         ***************      ****               **** \n"
                    190: " ****       **       ****                      ****    ****               **** \n"
                    191: " ****                ****                       ****   ****               **** \n"
                    192: " ****                ****                       ****   ****               **** \n"
                    193: " ****                ****                       ****   ****               **** \n"
                    194: " ****                ****   ****                ****   ****               **** \n"
                    195: " ****                ****   ****                ****   ****               **** \n"
                    196: " ****                ****    ****              ****     ****             ****  \n"
                    197: "*****                *****     ******************         *****************    \n"
                    198: "*****                *****        ************               ***********       \n"
                    199: "Copyright MSU Board of Trustees 1992-1999                                      \n"
                    200: "No Unauthorized Commercial Use or redistribution allowed.                      \n";
                    201:   fprintf(stderr,message);
                    202:   exit(0);
                    203: }

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