Annotation of capa/capa51/GUITools/common.funct.c, revision 1.2
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:
! 146:
1.1 albertel 147: void message()
148: {
149: unsigned char *message=
150: "***** ***** ************ ***** *****\n"
151: "****** ****** ****************** ***** *****\n"
152: " ****** ****** **** **** **** **** \n"
153: " ******* ******* **** **** **** **** \n"
154: " ******** ******** **** **** **** **** \n"
155: " **** **** **** **** **** **** **** \n"
156: " **** **** **** **** **** **** **** \n"
157: " **** **** **** **** **** **** **** \n"
158: " **** ******** **** **** **** **** \n"
159: " **** ****** **** *************** **** **** \n"
160: " **** **** **** *************** **** **** \n"
161: " **** ** **** **** **** **** \n"
162: " **** **** **** **** **** \n"
163: " **** **** **** **** **** \n"
164: " **** **** **** **** **** \n"
165: " **** **** **** **** **** **** \n"
166: " **** **** **** **** **** **** \n"
167: " **** **** **** **** **** **** \n"
168: "***** ***** ****************** ***************** \n"
169: "***** ***** ************ *********** \n"
170: "Copyright MSU Board of Trustees 1992-1999 \n"
171: "No Unauthorized Commercial Use or redistribution allowed. \n";
172: fprintf(stderr,message);
173: exit(0);
174: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>