version 1.8, 2001/11/15 21:42:42
|
version 1.9, 2001/11/18 09:40:45
|
Line 153 extern void (*Status_Func)();
|
Line 153 extern void (*Status_Func)();
|
begin_text(); |
begin_text(); |
/*if ( !yyparse() ) { errcode = Lexi_qnum; } else { errcode = 0; }*/ |
/*if ( !yyparse() ) { errcode = Lexi_qnum; } else { errcode = 0; }*/ |
if (!(temp=yylex())) { errcode = Lexi_qnum; } else { errcode = 0; } |
if (!(temp=yylex())) { errcode = Lexi_qnum; } else { errcode = 0; } |
/* printf("\nExited on: %d\n",temp); */ |
fprintf(stderr,"\nExited on: %d\n",temp); |
/* printf("Flushing:\n"); */ |
fprintf(stderr,"Current cache: %d\n",current_cache); |
|
fprintf(stderr,"Flushing:\n"); |
flush_delayed(); |
flush_delayed(); |
/* fclose(Input_stream[0]);*/ /*The Lexer handles closing this*/ |
/* fclose(Input_stream[0]);*/ /*The Lexer handles closing this*/ |
/* print_symb_stat(); */ |
/* print_symb_stat(); */ |
Line 169 extern void (*Status_Func)();
|
Line 170 extern void (*Status_Func)();
|
|
|
int dyn_maxlen=1000000; |
int dyn_maxlen=1000000; |
int delay; |
int delay; |
void dyn_init() |
void dyn_init(struct dyn_string *dyn) |
{ |
{ |
dyn_delayed.len=0; |
dyn->len=0; |
dyn_delayed.max=0; |
dyn->max=0; |
dyn_delayed.str=NULL; |
dyn->str=NULL; |
} |
} |
|
|
/* this can be used to free up the str components if the output |
void dyn_free(struct dyn_string* dyn) |
compenants are used internally, as in the reinit code |
|
*/ |
|
void dyn_free() |
|
{ |
{ |
if (dyn_delayed.str) {free(dyn_delayed.str);dyn_delayed.str=NULL;} |
if (dyn->str) { |
|
free(dyn->str);dyn->str=NULL; |
|
dyn->len=0; |
|
dyn->max=0; |
|
} |
} |
} |
|
|
|
|
int append_message(struct dyn_string *dyn_msg,char *format,va_list ap) { |
int append_message(struct dyn_string *dyn_msg,char *format,va_list ap) { |
char *new; |
char *new; |
int len,result; |
int len,result; |
|
|
result=vasprintf(&new,format,ap); |
if ((result=vasprintf(&new,format,ap))==-1) { |
|
fprintf(stderr,"vaspintf didn't like :%s:",format); |
|
exit(1); |
|
} |
len=strlen(new); |
len=strlen(new); |
|
|
#ifdef DYN_DEBUG |
#ifdef DYN_DEBUG |
Line 237 void add_delayed(char *format, ...) {
|
Line 243 void add_delayed(char *format, ...) {
|
|
|
va_start(ap,format); |
va_start(ap,format); |
append_message(&dyn_delayed,format,ap); |
append_message(&dyn_delayed,format,ap); |
} |
if (do_cache[current_cache]) { |
|
append_message(&cached_data[current_cache],format,ap); |
|
} |
|
} |
|
|
void flush_delayed() |
void flush_delayed() |
{ |
{ |
if (dyn_delayed.str) fputs(dyn_delayed.str,stdout); |
|
dyn_free();dyn_init(); |
|
delay=0; |
delay=0; |
|
if (dyn_delayed.str) { send(dyn_delayed.str); } |
|
dyn_free(&dyn_delayed);dyn_init(&dyn_delayed); |
} |
} |
|
|
void send(char *text,...) |
|
|
void send_to(int which, char *text, va_list ap) |
{ |
{ |
va_list ap; |
|
va_start(ap,text); |
|
if (delay) { |
if (delay) { |
append_message(&dyn_delayed,text,ap); |
append_message(&dyn_delayed,text,ap); |
} else { |
} else { |
vprintf(text,ap); |
if (num_streams) { |
|
if (which == ALL_STREAMS) { |
|
int i; |
|
for (i=0;i<num_streams;i++) { append_message(&streams[i],text,ap); } |
|
} else { |
|
append_message(&streams[which],text,ap); |
|
} |
|
} else { |
|
vprintf(text,ap); |
|
} |
} |
} |
|
if (do_cache[current_cache]) { |
|
append_message(&cached_data[current_cache],text,ap); |
|
} |
|
} |
|
|
|
void send(char *text,...) |
|
{ |
|
va_list ap; |
|
va_start(ap,text); |
|
send_to(ALL_STREAMS,text,ap); |
} |
} |
|
|
|
void send_stream(int which, char *text,...) |
|
{ |
|
va_list ap; |
|
va_start(ap,text); |
|
send_to(which,text,ap); |
|
} |
|
|
|
int num_streams=0; |
|
struct dyn_string streams[MAX_STREAMS]; |
|
void start_streams(int num) { |
|
int i; |
|
for(i=0; i<num; i++) { dyn_init(&streams[i]); } |
|
for(i=1; i<num; i++) { mode[i]=mode[0]; } |
|
num_streams=num; |
|
} |
|
|
|
void end_streams(int which) { |
|
int i; |
|
fputs(streams[which].str,stdout); |
|
for(i=0; i<num_streams; i++) { dyn_free(&streams[which]); } |
|
num_streams=0; |
|
mode[0]=mode[which]; |
|
} |
|
|
|
int watch_mode[MAX_STREAMS]; |
void end_mode() |
void end_mode() |
{ |
{ |
switch (mode) { |
end_mode_stream(ALL_STREAMS); |
case MODE_COMMENT: send("</comment>\n"); break; |
} |
case MODE_BLOCK: send("</block>\n"); break; |
|
case MODE_SCRIPT: send("</script>\n"); break; |
void end_mode_stream(int which) |
case MODE_OUTTEXT: send("<endouttext />\n"); break; |
{ |
case MODE_ANSWER: send("\n"); break; |
if (num_streams) { |
case MODE_HINT: send("<endouttext />\n</hintpart>\n</hintgroup>\n"); break; |
if (which == ALL_STREAMS) { |
|
int i; |
|
for (i=0;i<num_streams;i++) { end_mode_stream(i); } |
|
return; |
|
} |
|
} else { |
|
which=0;/* if streams aren't active make sure which is correct */ |
|
} |
|
switch (mode[which]) { |
|
case MODE_COMMENT: send_stream(which,"</comment>\n"); break; |
|
case MODE_BLOCK: send_stream(which,"</block>\n"); break; |
|
case MODE_SCRIPT: send_stream(which,"</script>\n"); break; |
|
case MODE_OUTTEXT: send_stream(which,"<endouttext />\n"); break; |
|
case MODE_ANSWER: send_stream(which,"\n"); break; |
|
case MODE_HINT: send_stream(which,"<endouttext />\n</hintpart>\n</hintgroup>\n"); break; |
|
case MODE_IMPORT: send_stream(which,"</import>\n"); break; |
case MODE_NONE: break; |
case MODE_NONE: break; |
} |
} |
mode=MODE_NONE; |
mode[which]=MODE_NONE; |
|
watch_mode[which]=0; |
} |
} |
|
|
void start_mode(int newmode,char* args) |
void start_mode(int newmode,char* args) |
{ |
{ |
if (newmode == mode) return; |
start_mode_stream(ALL_STREAMS,newmode,args); |
end_mode(); |
} |
|
|
|
void start_mode_stream(int which,int newmode,char* args) |
|
{ |
|
if (num_streams) { |
|
if (which == ALL_STREAMS) { |
|
int i; |
|
for (i=0;i<num_streams;i++) { start_mode_stream(i,newmode,args); } |
|
return; |
|
} else { |
|
if (newmode == mode[which]) return; |
|
} |
|
} else { |
|
if (newmode == mode[0]) return; |
|
which=0;/* if streams aren't active make sure which is correct */ |
|
} |
|
end_mode_stream(which); |
switch (newmode) { |
switch (newmode) { |
case MODE_COMMENT: send("<comment>\n"); break; |
case MODE_COMMENT: send_stream(which,"<comment>\n"); break; |
case MODE_BLOCK: send("<block %s>\n",args); break; |
case MODE_BLOCK: send_stream(which,"<block %s>\n",args); break; |
case MODE_SCRIPT: send("<script type=\"loncapa/perl\">\n"); break; |
case MODE_SCRIPT: send_stream(which,"<script type=\"loncapa/perl\">\n"); break; |
case MODE_OUTTEXT: send("<startouttext />\n"); break; |
case MODE_OUTTEXT: send_stream(which,"<startouttext />\n"); break; |
case MODE_ANSWER: send("\n"); break; |
case MODE_ANSWER: send_stream(which,"\n"); break; |
case MODE_HINT: send("<hintgroup>\n<hintpart on=\"default\">\n<startouttext />\n"); break; |
case MODE_HINT: send_stream(which,"<hintgroup>\n<hintpart on=\"default\">\n<startouttext />\n"); break; |
|
case MODE_IMPORT: send_stream(which,"<import>"); break; |
case MODE_NONE: break; |
case MODE_NONE: break; |
} |
} |
mode=newmode; |
mode[which]=newmode; |
|
} |
|
|
|
int current_cache=-1; |
|
int do_cache[MAX_CACHE]; |
|
struct dyn_string cached_data[MAX_CACHE]; |
|
|
|
void new_cache() |
|
{ |
|
current_cache++; |
|
do_cache[current_cache]=1; |
|
if (current_cache>MAX_CACHE) { exit(CACHE_ERROR); } |
|
dyn_init(&cached_data[current_cache]); |
|
} |
|
|
|
void start_cache() |
|
{ |
|
do_cache[current_cache]=1; |
|
} |
|
|
|
void stop_cache() |
|
{ |
|
do_cache[current_cache]=0; |
|
} |
|
|
|
void delete_cache() |
|
{ |
|
if (current_cache > -1) { |
|
dyn_free(&cached_data[current_cache]); |
|
current_cache--; |
|
} |
} |
} |
/* =||>|===================== End of capaCommon.c =====================|<||= */ |
/* =||>|===================== End of capaCommon.c =====================|<||= */ |
|
|