Rev 8342 | Rev 11125 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8342 | Rev 8849 | ||
---|---|---|---|
Line 50... | Line 50... | ||
50 | j=0; p=list; k=*p-t; |
50 | j=0; p=list; k=*p-t; |
51 | if(k==0) return k; if(k>0) return -1; |
51 | if(k==0) return k; if(k>0) return -1; |
52 | p=list+(items-1)*item_size; |
52 | p=list+(items-1)*item_size; |
53 | k=*p-t; if(k==0) return items-1; if(k<0) return ~items; |
53 | k=*p-t; if(k==0) return items-1; if(k<0) return ~items; |
54 | for(i1=0,i2=items-1;i2>i1+1;) { |
54 | for(i1=0,i2=items-1;i2>i1+1;) { |
55 |
|
55 | j=(i2+i1)/2; |
56 |
|
56 | p=list+(j*item_size); |
57 |
|
57 | k=*p-t; |
58 |
|
58 | if(k==0) return j; |
59 |
|
59 | if(k>0) {i2=j; continue;} |
60 |
|
60 | if(k<0) {i1=j; continue;} |
61 | } |
61 | } |
62 | return ~i2; |
62 | return ~i2; |
63 | } |
63 | } |
64 | 64 | ||
65 | /* remove old cache items */ |
65 | /* remove old cache items */ |
Line 69... | Line 69... | ||
69 | time_t now; |
69 | time_t now; |
70 | struct classdata *cd; |
70 | struct classdata *cd; |
71 | struct sheetdata *sd; |
71 | struct sheetdata *sd; |
72 | now=time(NULL); |
72 | now=time(NULL); |
73 | for(i=0;i<classcaches;i++) { |
73 | for(i=0;i<classcaches;i++) { |
74 |
|
74 | cd=classcache[i].ptr; |
75 |
|
75 | if(now<cd->start+CLASSCACHE_DELAY) continue; |
76 |
|
76 | cd->access=0; |
77 |
|
77 | memmove(classcache+i,classcache+i+1,(classcaches-i-1)*sizeof(classcache[0])); |
78 |
|
78 | classcaches--; |
79 | } |
79 | } |
80 | for(i=0;i<sheetcaches;i++) { |
80 | for(i=0;i<sheetcaches;i++) { |
81 |
|
81 | sd=sheetcache[i].ptr; |
82 |
|
82 | if(now<sd->start+SHEETCACHE_DELAY) continue; |
83 |
|
83 | sd->access=0; |
84 |
|
84 | memmove(sheetcache+i,sheetcache+i+1,(sheetcaches-i-1)*sizeof(sheetcache[0])); |
85 |
|
85 | sheetcaches--; |
86 | } |
86 | } |
87 | } |
87 | } |
88 | 88 | ||
89 | /* Locate the cache number of a class */ |
89 | /* Locate the cache number of a class */ |
90 | struct classdata *getclasscache(char *cl) |
90 | struct classdata *getclasscache(char *cl) |
Line 95... | Line 95... | ||
95 | char buf[MAX_LINELEN+1], buf2[MAX_LINELEN+1]; |
95 | char buf[MAX_LINELEN+1], buf2[MAX_LINELEN+1]; |
96 | char *p1, *p2, *q1, *q2; |
96 | char *p1, *p2, *q1, *q2; |
97 | time_t tt; |
97 | time_t tt; |
98 | tt=0, oldest=0; |
98 | tt=0, oldest=0; |
99 | for(i=0;i<classcaches;i++) { |
99 | for(i=0;i<classcaches;i++) { |
100 |
|
100 | cd=classcache[i].ptr; |
101 |
|
101 | if(tt>cd->start) {tt=cd->start; oldest=i;} |
102 |
|
102 | if(strcmp(cd->name,cl)==0) { |
103 |
|
103 | cd->access++; |
104 |
|
104 | return cd; |
105 |
|
105 | } |
106 | } |
106 | } |
107 | if(classcaches>=MAX_CLASSCACHE) { |
107 | if(classcaches>=MAX_CLASSCACHE) { |
108 |
|
108 | i=oldest;cd=classcache[i].ptr; |
109 |
|
109 | cd->access=0; |
110 |
|
110 | memmove(classcache+i,classcache+i+1,(classcaches-i-1)*sizeof(classcache[0])); |
111 |
|
111 | classcaches--; |
112 | } |
112 | } |
113 | for(i=0;i<MAX_CLASSCACHE && classdata[i].access>0; i++); |
113 | for(i=0;i<MAX_CLASSCACHE && classdata[i].access>0; i++); |
114 | if(i>classcaches) return NULL; |
114 | if(i>classcaches) return NULL; |
115 | cd=classdata+i; cd->access=1; |
115 | cd=classdata+i; cd->access=1; |
116 | classcache[classcaches++].ptr=cd; |
116 | classcache[classcaches++].ptr=cd; |
117 | snprintf(cd->name,sizeof(cd->name),"%s",cl); |
117 | snprintf(cd->name,sizeof(cd->name),"%s",cl); |
118 | cd->start=time(NULL); cd->exocnt=0; |
118 | cd->start=time(NULL); cd->exocnt=0; |
119 | /* Now get the exo data */ |
119 | /* Now get the exo data */ |
120 | wlogdaccessfile(buf,"r","sheets/.require"); |
120 | wlogdaccessfile(buf,"r","sheets/.require"); |
121 | for(i=k=0,p1=buf; *p1; i++,p1=p2) { |
121 | for(i=k=0,p1=buf; *p1; i++,p1=p2) { |
122 |
|
122 | p2=strchr(p1,'\n'); if(p2) *p2++=0; else p2=p1+strlen(p1); |
123 |
|
123 | for(j=0,q1=find_word_start(p1); *q1 && k<MAX_CLASSEXOS; j++,q1=find_word_start(q2)) { |
124 |
|
124 | q2=find_word_end(q1); if(*q2) *q2++=0; |
125 |
|
125 | cd->exos[k].num=(i<<8)+j;cd->exos[k].require=atof(q1); |
126 |
|
126 | cd->exos[k].weight=0; |
127 |
|
127 | k++; |
128 |
|
128 | } |
129 | 129 | ||
130 | } |
130 | } |
131 | if(k>=MAX_CLASSEXOS) return NULL; |
131 | if(k>=MAX_CLASSEXOS) return NULL; |
132 | cd->exocnt=k; cd->examstart=k; cd->modif=0; |
132 | cd->exocnt=k; cd->examstart=k; cd->modif=0; |
133 | wlogdaccessfile(buf,"r","sheets/.weight"); |
133 | wlogdaccessfile(buf,"r","sheets/.weight"); |
134 | for(i=k=0,p1=buf; *p1; i++,p1=p2) { |
134 | for(i=k=0,p1=buf; *p1; i++,p1=p2) { |
135 |
|
135 | p2=strchr(p1,'\n'); if(p2) *p2++=0; else p2=p1+strlen(p1); |
136 |
|
136 | for(j=0,q1=find_word_start(p1); *q1 && k<MAX_CLASSEXOS; j++,q1=find_word_start(q2)) { |
137 |
|
137 | q2=find_word_end(q1); if(*q2) *q2++=0; |
138 |
|
138 | if(cd->exos[k].num==(i<<8)+j) { |
139 |
|
139 | cd->exos[k].weight=atof(q1); |
140 |
|
140 | k++; |
141 |
|
141 | } |
142 |
|
142 | else while(k<cd->exocnt && cd->exos[k].num<(i<<8)+j) k++; |
143 |
|
143 | } |
144 | } |
144 | } |
145 | if(stat("exams/.exams",&st)==0) cd->modif=st.st_mtime; else return cd; |
145 | if(stat("exams/.exams",&st)==0) cd->modif=st.st_mtime; else return cd; |
146 | wlogdaccessfile(buf,"r","exams/.exams"); |
146 | wlogdaccessfile(buf,"r","exams/.exams"); |
147 | if(buf[0]==0) return cd; |
147 | if(buf[0]==0) return cd; |
148 | if(buf[0]==':') p1=buf-1; else p1=strstr(buf,"\n:"); |
148 | if(buf[0]==':') p1=buf-1; else p1=strstr(buf,"\n:"); |
149 | for(n=m=0,k=cd->exocnt; p1 && k<MAX_CLASSEXOS && m<MAX_EXOS; p1=p2,m++) { |
149 | for(n=m=0,k=cd->exocnt; p1 && k<MAX_CLASSEXOS && m<MAX_EXOS; p1=p2,m++) { |
150 |
|
150 | p1+=2; |
151 |
|
151 | p2=strstr(p1,"\n:"); if(p2) *p2=0; |
152 | // |
152 | // if(*find_word_start(p1)<'1') continue; /* status */ |
153 |
|
153 | fnd_line(p1,3,buf2); if(buf2[0]==0) continue; |
154 |
|
154 | q1=find_word_start(buf2); q2=find_word_end(q1); |
155 |
|
155 | if(*q2) *q2++=0; |
156 |
|
156 | q2=find_word_start(q2); *find_word_end(q2)=0; |
157 |
|
157 | i=atoi(q1); j=atoi(q2); if(i<=0 || j<=0) continue; |
158 |
|
158 | cd->exos[k].num=0xFF00+m; |
159 |
|
159 | cd->exos[k].weight=i; cd->exos[k].require=j; /* weight: duration. require: retries */ |
160 |
|
160 | fnd_line(p1,6,buf2); q1=find_word_start(buf2); |
161 |
|
161 | singlespace(q1); strip_trailing_spaces(q1); |
162 |
|
162 | cd->ctptr[k-cd->exocnt]=n; cd->ctbuf[n]=0; |
163 |
|
163 | if(n+strlen(q1)>CTBUFLEN-MAX_EXOS-16) *q1=0; /* silent truncation */ |
164 |
|
164 | l=strlen(q1)+1; memmove(cd->ctbuf+n,q1,l); n+=l; |
165 |
|
165 | k++; |
166 | } |
166 | } |
167 | cd->examcnt=k-cd->exocnt; cd->exocnt=k; |
167 | cd->examcnt=k-cd->exocnt; cd->exocnt=k; |
168 | return cd; |
168 | return cd; |
169 | } |
169 | } |
170 | // misprint ?? sheetdata ?? does not seem to be used. |
170 | // misprint ?? sheetdata ?? does not seem to be used. |