Annotation of capa/capa51/GUITools/common.funct.c, revision 1.1
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:
! 129: void message()
! 130: {
! 131: unsigned char *message=
! 132: "***** ***** ************ ***** *****\n"
! 133: "****** ****** ****************** ***** *****\n"
! 134: " ****** ****** **** **** **** **** \n"
! 135: " ******* ******* **** **** **** **** \n"
! 136: " ******** ******** **** **** **** **** \n"
! 137: " **** **** **** **** **** **** **** \n"
! 138: " **** **** **** **** **** **** **** \n"
! 139: " **** **** **** **** **** **** **** \n"
! 140: " **** ******** **** **** **** **** \n"
! 141: " **** ****** **** *************** **** **** \n"
! 142: " **** **** **** *************** **** **** \n"
! 143: " **** ** **** **** **** **** \n"
! 144: " **** **** **** **** **** \n"
! 145: " **** **** **** **** **** \n"
! 146: " **** **** **** **** **** \n"
! 147: " **** **** **** **** **** **** \n"
! 148: " **** **** **** **** **** **** \n"
! 149: " **** **** **** **** **** **** \n"
! 150: "***** ***** ****************** ***************** \n"
! 151: "***** ***** ************ *********** \n"
! 152: "Copyright MSU Board of Trustees 1992-1999 \n"
! 153: "No Unauthorized Commercial Use or redistribution allowed. \n";
! 154: fprintf(stderr,message);
! 155: exit(0);
! 156: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>