Subversion Repositories wimsdev

Rev

Rev 9068 | Rev 9095 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9068 Rev 9093
Line 17... Line 17...
17
#include "../Lib/libwims.h"
17
#include "../Lib/libwims.h"
18
#include "oef2wims.h"
18
#include "oef2wims.h"
19
int prepcnt;
19
int prepcnt;
20
int ex_statement=0, ex_hint=0, ex_help=0, ex_solution=0, ex_latex=0;
20
int ex_statement=0, ex_hint=0, ex_help=0, ex_solution=0, ex_latex=0;
21
 
21
 
22
 
-
 
23
char vbuf_latex[MAX_LINELEN+1];
-
 
24
const size_t MAX_KEY_LEN=128;
22
const size_t MAX_KEY_LEN=128;
25
char vbuf_statement[MAX_LINELEN+1];
23
char vbuf_statement[MAX_LINELEN+1];
26
char vbuf_hint[MAX_LINELEN+1];
24
char vbuf_hint[MAX_LINELEN+1];
27
char vbuf_help[MAX_LINELEN+1];
25
char vbuf_help[MAX_LINELEN+1];
28
char vbuf_solution[MAX_LINELEN+1];
26
char vbuf_solution[MAX_LINELEN+1];
-
 
27
char vbuf_latex[MAX_LINELEN+1];
29
 
28
 
30
/* empty processor, template. */
29
/* empty processor, template. */
31
void empty(char *p[MAX_PARM]) {}
30
void empty(char *p[MAX_PARM]) {}
32
 
31
 
33
static void p_keyword(char *p[MAX_PARM], const char *key)
32
static void p_keyword(char *p[MAX_PARM], const char *key)
34
{
33
{
35
    p[0]=find_word_start(p[0]);
34
    p[0]=find_word_start(p[0]);
36
    if(strlen(p[0])>MAX_KEY_LEN) p[0][MAX_KEY_LEN]=0;
35
    if(strlen(p[0])>MAX_KEY_LEN) p[0][MAX_KEY_LEN]=0;
37
    fprintf(outf,"%s=%s\n", key, p[0]);
36
    fprintf(outf,"%s=%s\n", key, p[0]);
38
}
37
}
39
 
38
 
40
void p_author(char *p[MAX_PARM]) { p_keyword(p, "author"); }
39
void p_author(char *p[MAX_PARM]) { p_keyword(p, "author"); }
41
void p_email(char *p[MAX_PARM]) { p_keyword(p, "email"); }
40
void p_email(char *p[MAX_PARM]) { p_keyword(p, "email"); }
42
void p_keywords(char *p[MAX_PARM]) { p_keyword(p, "keywords"); }
41
void p_keywords(char *p[MAX_PARM]) { p_keyword(p, "keywords"); }
43
void p_title_ca(char *p[MAX_PARM]) { p_keyword(p, "title_ca"); }
42
void p_title_ca(char *p[MAX_PARM]) { p_keyword(p, "title_ca"); }
44
void p_title_cn(char *p[MAX_PARM]) { p_keyword(p, "title_cn"); }
43
void p_title_cn(char *p[MAX_PARM]) { p_keyword(p, "title_cn"); }
Line 48... Line 47...
48
void p_title_it(char *p[MAX_PARM]) { p_keyword(p, "title_it"); }
47
void p_title_it(char *p[MAX_PARM]) { p_keyword(p, "title_it"); }
49
void p_title_nl(char *p[MAX_PARM]) { p_keyword(p, "title_nl"); }
48
void p_title_nl(char *p[MAX_PARM]) { p_keyword(p, "title_nl"); }
50
void p_title_si(char *p[MAX_PARM]) { p_keyword(p, "title_si"); }
49
void p_title_si(char *p[MAX_PARM]) { p_keyword(p, "title_si"); }
51
 
50
 
52
void p_computeanswer(char *p[MAX_PARM])
51
void p_computeanswer(char *p[MAX_PARM])
53
{
52
{
54
    p[0]=find_word_start(p[0]);
53
    p[0]=find_word_start(p[0]);
55
    *find_word_end(p[0])=0;
54
    *find_word_end(p[0])=0;
56
    if(strcasecmp(p[0],"yes"))
55
    if(strcasecmp(p[0],"yes"))
57
      fprintf(outf,"computeanswer=no\n");
56
      fprintf(outf,"computeanswer=no\n");
58
    else fprintf(outf,"computeanswer=%s\n",p[0]);
57
    else fprintf(outf,"computeanswer=%s\n",p[0]);
59
}
58
}
60
 
59
 
61
void p_precision(char *p[MAX_PARM])
60
void p_precision(char *p[MAX_PARM])
62
{
61
{
63
    int pr;
62
    int pr;
64
    pr=atoi(p[0]);
63
    pr=atoi(p[0]);
65
    if(pr<0 || pr>100000000) return;
64
    if(pr<0 || pr>100000000) return;
66
    fprintf(outf,"precision=%d\n",pr);
65
    fprintf(outf,"precision=%d\n",pr);
67
}
66
}
68
 
67
 
69
void p_css(char *p[MAX_PARM])
68
void p_css(char *p[MAX_PARM])
70
{
69
{
71
    char vbuf_css[MAX_LINELEN+1];
70
    char vbuf_css[MAX_LINELEN+1];
72
    if(p==NULL) return;
71
    if(p==NULL) return;
73
    snprintf(vbuf_css,sizeof(vbuf_css),"%s",p[0]); subst(vbuf_css);
72
    snprintf(vbuf_css,sizeof(vbuf_css),"%s",p[0]); subst(vbuf_css);
74
    fprintf(outf,"oefcss=%s\n",vbuf_css);
73
    fprintf(outf,"oefcss=%s\n",vbuf_css);
75
}
74
}
76
 
75
 
77
void p_credits(char *p[MAX_PARM])
76
void p_credits(char *p[MAX_PARM])
78
{
77
{
79
    char vbuf_credits[MAX_LINELEN+1];
78
    char vbuf_credits[MAX_LINELEN+1];
80
    if(p==NULL) return;
79
    if(p==NULL) return;
Line 83... Line 82...
83
    singlespace(vbuf_credits);
82
    singlespace(vbuf_credits);
84
    fprintf(outf,"credits=%s\n\n", vbuf_credits);
83
    fprintf(outf,"credits=%s\n\n", vbuf_credits);
85
}
84
}
86
 
85
 
87
void p_wims(char *p[MAX_PARM])
86
void p_wims(char *p[MAX_PARM])
88
{
87
{
89
    char vbuf[MAX_LINELEN+1];
88
    char vbuf[MAX_LINELEN+1];
90
    snprintf(vbuf,sizeof(vbuf),"%s",p[0]); subst(vbuf);
89
    snprintf(vbuf,sizeof(vbuf),"%s",p[0]); subst(vbuf);
91
/* the second condition could be removed?
90
/* the second condition could be removed?
92
 * To be very careful! */
91
 * To be very careful! */
93
    if(strchr(vbuf,'=')==NULL || strchr(vbuf,'!')!=NULL) return;
92
    if(strchr(vbuf,'=')==NULL || strchr(vbuf,'!')!=NULL) return;
Line 116... Line 115...
116
    if(left>=right-1E-50 || left<-1E50 || right>1E50) return;
115
    if(left>=right-1E-50 || left<-1E50 || right>1E50) return;
117
    fprintf(outf,"leftrange=%f\nrightrange=%f\n",left,right);
116
    fprintf(outf,"leftrange=%f\nrightrange=%f\n",left,right);
118
}
117
}
119
 
118
 
120
void p_language(char *p[MAX_PARM])
119
void p_language(char *p[MAX_PARM])
121
{
120
{
122
    p[0]=find_word_start(p[0]);
121
    p[0]=find_word_start(p[0]);
123
    *find_word_end(p[0])=0;
122
    *find_word_end(p[0])=0;
124
    if(strlen(p[0])==2) fprintf(outf,"language=%s\n",p[0]);
123
    if(strlen(p[0])==2) fprintf(outf,"language=%s\n",p[0]);
125
}
124
}
126
 
125
 
Line 142... Line 141...
142
      fprintf(outf,"question=%s\n",executed_str);
141
      fprintf(outf,"question=%s\n",executed_str);
143
      ex_statement=1;
142
      ex_statement=1;
144
    }
143
    }
145
}
144
}
146
 
145
 
147
void p_hint(char *p[MAX_PARM])
146
void p_gen(int *ex_gen, char vbuf_gen[], char *name_gen, char *p[MAX_PARM])
148
{
147
{
149
    if(ex_hint<0) return;
148
    if(*ex_gen<0) return;
150
    if(ex_hint>0 || p==NULL) {
149
    if(*ex_gen>0 || p==NULL) {
151
      out_exec(vbuf_hint,"hint");
150
      out_exec(vbuf_gen, name_gen);
152
      ex_hint=-1; return;
151
      *ex_gen=-1; return;
153
    }
152
    }
154
    snprintf(vbuf_hint,sizeof(vbuf_hint),"%s",p[0]); subst(vbuf_hint);
153
    snprintf(vbuf_gen,MAX_LINELEN,"%s",p[0]); subst(vbuf_gen);
155
    if(strchr(vbuf_hint,'\\')!=NULL) {
154
    if(strchr(vbuf_gen,'\\')!=NULL) {
156
      fprintf(outf,"hint=%s\n",executed_str);
155
      fprintf(outf,"%s=%s\n", name_gen, executed_str);
157
      ex_hint=1;
156
      *ex_gen=1;
158
    }
157
    }
159
    else {
158
    else {
160
      singlespace(vbuf_hint);
159
      singlespace(vbuf_gen);
161
      fprintf(outf,"hint=!nosubst %s\n\n", vbuf_hint);
160
      fprintf(outf,"%s=!nosubst %s\n\n", name_gen, vbuf_gen);
162
    }
161
    }
163
}
162
}
164
 
163
 
165
void p_help(char *p[MAX_PARM])
164
void p_hint(char *p[MAX_PARM]) {p_gen(&ex_hint, vbuf_hint, "hint", p);}
166
{
-
 
167
    if(ex_help<0) return;
-
 
168
    if(ex_help>0 || p==NULL) {
-
 
169
      out_exec(vbuf_help,"help");
-
 
170
      ex_help=-1; return;
-
 
171
    }
-
 
172
    snprintf(vbuf_help,sizeof(vbuf_help),"%s",p[0]); subst(vbuf_help);
-
 
173
    if(strchr(vbuf_help,'\\')!=NULL) {
-
 
174
      fprintf(outf,"help=%s\n",executed_str);
-
 
175
      ex_help=1;
-
 
176
    }
-
 
177
    else {
-
 
178
      singlespace(vbuf_help);
-
 
179
      fprintf(outf,"help=!nosubst %s\n\n", vbuf_help);
165
void p_help(char *p[MAX_PARM]) {p_gen(&ex_help, vbuf_help, "help", p);}
180
    }
-
 
181
}
-
 
182
 
-
 
183
void p_solution(char *p[MAX_PARM])
-
 
184
{
-
 
185
    if(ex_solution<0) return;
-
 
186
    if(ex_solution>0 || p==NULL) {
-
 
187
      out_exec(vbuf_solution,"solution");
166
void p_solution(char *p[MAX_PARM]) {p_gen(&ex_solution, vbuf_solution, "solution", p);}
188
      ex_solution=-1; return;
-
 
189
    }
-
 
190
    snprintf(vbuf_solution,sizeof(vbuf_solution),"%s",p[0]);
-
 
191
    subst(vbuf_solution);
-
 
192
    if(strchr(vbuf_solution,'\\')!=NULL) {
-
 
193
      fprintf(outf,"solution=%s\n",executed_str);
-
 
194
      ex_solution=1;
-
 
195
    }
-
 
196
    else {
-
 
197
      singlespace(vbuf_solution);
-
 
198
      fprintf(outf,"solution=!nosubst %s\n\n", vbuf_solution);
-
 
199
    }
-
 
200
}
-
 
201
 
167
 
202
void p_latex(char *p[MAX_PARM])
168
void p_latex(char *p[MAX_PARM])
203
{
169
{
204
    if(ex_latex<0) return;
170
    if(ex_latex<0) return;
205
    if(ex_latex>0 || p==NULL) {
171
    if(ex_latex>0 || p==NULL) {