version 1.9, 2001/11/18 09:40:45
|
version 1.11, 2001/12/05 18:58:21
|
Line 1
|
Line 1
|
|
/* The LearningOnline Network with CAPA |
|
* Helaper functions for capa convertor. |
|
* $Id$ |
|
* |
|
* Copyright Michigan State University Board of Trustees |
|
* |
|
* This file is part of the LearningOnline Network with CAPA (LON-CAPA). |
|
* |
|
* LON-CAPA is free software; you can redistribute it and/or modify |
|
* it under the terms of the GNU General Public License as published by |
|
* the Free Software Foundation; either version 2 of the License, or |
|
* (at your option) any later version. |
|
* |
|
* LON-CAPA is distributed in the hope that it will be useful, |
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
* GNU General Public License for more details. |
|
* |
|
* You should have received a copy of the GNU General Public License |
|
* along with LON-CAPA; if not, write to the Free Software |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
* |
|
* /home/httpd/html/adm/gpl.txt |
|
* |
|
* http://www.lon-capa.org/ |
|
*/ |
|
|
/* =||>|===================== capaCommon.c =====================|<||= */ |
/* =||>|===================== capaCommon.c =====================|<||= */ |
/* created 1994 by Isaac Tsai */ |
/* created 1994 by Isaac Tsai */ |
/* 1994, 1995, 1996, 1997, 1998, 1999 copyrighted by Isaac Tsai */ |
/* 1994, 1995, 1996, 1997, 1998, 1999 copyrighted by Isaac Tsai */ |
Line 256 void flush_delayed()
|
Line 283 void flush_delayed()
|
} |
} |
|
|
|
|
void send_to(int which, char *text, va_list ap) |
int current_dest=DEFAULT_DEST; |
|
void change_destination(int which_dest) |
|
{ |
|
if (which_dest < MAX_DEST) { |
|
current_dest = which_dest; |
|
} else { |
|
fprintf(stderr,"Tried to set destination above MAX_DEST: %d", which_dest); |
|
exit(1); |
|
} |
|
} |
|
|
|
void send_to(int which_dest, int which, char *text, va_list ap) |
{ |
{ |
if (delay) { |
if (delay) { |
append_message(&dyn_delayed,text,ap); |
append_message(&dyn_delayed,text,ap); |
} else { |
} else { |
if (num_streams) { |
if (num_streams[which_dest]) { |
if (which == ALL_STREAMS) { |
if (which == ALL_STREAMS) { |
int i; |
int i; |
for (i=0;i<num_streams;i++) { append_message(&streams[i],text,ap); } |
for (i=0;i<num_streams[which_dest];i++) { append_message(&streams[which_dest][i],text,ap); } |
} else { |
} else { |
append_message(&streams[which],text,ap); |
append_message(&streams[which_dest][which],text,ap); |
} |
} |
} else { |
} else { |
vprintf(text,ap); |
vprintf(text,ap); |
Line 281 void send(char *text,...)
|
Line 319 void send(char *text,...)
|
{ |
{ |
va_list ap; |
va_list ap; |
va_start(ap,text); |
va_start(ap,text); |
send_to(ALL_STREAMS,text,ap); |
send_to(current_dest,ALL_STREAMS,text,ap); |
} |
} |
|
|
void send_stream(int which, char *text,...) |
void send_stream(int which, char *text,...) |
{ |
{ |
va_list ap; |
va_list ap; |
va_start(ap,text); |
va_start(ap,text); |
send_to(which,text,ap); |
send_to(current_dest,which,text,ap); |
} |
} |
|
|
int num_streams=0; |
int num_streams[MAX_DEST]; |
struct dyn_string streams[MAX_STREAMS]; |
struct dyn_string streams[MAX_DEST][MAX_STREAMS]; |
void start_streams(int num) { |
void start_streams(int which_dest, int num) { |
int i; |
int i; |
for(i=0; i<num; i++) { dyn_init(&streams[i]); } |
for(i=0; i<num; i++) { dyn_init(&streams[which_dest][i]); } |
for(i=1; i<num; i++) { mode[i]=mode[0]; } |
for(i=1; i<num; i++) { beg_mode[which_dest][i]=mode[current_dest][0]; |
num_streams=num; |
mode[which_dest][i]=mode[current_dest][0]; } |
|
num_streams[which_dest]=num; |
|
current_dest = which_dest; |
} |
} |
|
|
void end_streams(int which) { |
void end_streams(int which_dest, int which) { |
int i; |
int i; |
fputs(streams[which].str,stdout); |
start_mode(beg_mode[which_dest][which],NULL); |
for(i=0; i<num_streams; i++) { dyn_free(&streams[which]); } |
fputs(streams[which_dest][which].str,stdout); |
num_streams=0; |
for(i=0; i<num_streams[which_dest]; i++) { dyn_free(&streams[which_dest][which]); } |
mode[0]=mode[which]; |
num_streams[which_dest]=0; |
|
mode[DEFAULT_DEST][0]=mode[which_dest][which]; |
|
start_mode(mode[DEFAULT_DEST][0],NULL); |
|
} |
|
|
|
int is_dest_empty(int which_dest) { |
|
int i,empty=1; |
|
|
|
if ( num_streams[which_dest] ) { |
|
for(i=0; i<num_streams[which_dest]; i++) { |
|
if (streams[which_dest][i].str != NULL) { empty=0; break; } |
|
} |
|
} else { |
|
if (streams[which_dest][0].str != NULL) { empty=0; } |
|
} |
|
return empty; |
} |
} |
|
|
int watch_mode[MAX_STREAMS]; |
int mode[MAX_DEST][MAX_STREAMS]; |
|
int watch_mode[MAX_DEST][MAX_STREAMS]; |
|
int beg_mode[MAX_DEST][MAX_STREAMS]; |
void end_mode() |
void end_mode() |
{ |
{ |
end_mode_stream(ALL_STREAMS); |
end_mode_stream(current_dest, ALL_STREAMS); |
} |
} |
|
|
void end_mode_stream(int which) |
void end_mode_stream(int which_dest, int which) |
{ |
{ |
if (num_streams) { |
if (num_streams[which_dest]) { |
if (which == ALL_STREAMS) { |
if (which == ALL_STREAMS) { |
int i; |
int i; |
for (i=0;i<num_streams;i++) { end_mode_stream(i); } |
for (i=0;i<num_streams[which_dest];i++) { end_mode_stream(which_dest,i); } |
return; |
return; |
} |
} |
} else { |
} else { |
which=0;/* if streams aren't active make sure which is correct */ |
which=0;/* if streams aren't active make sure which is correct */ |
} |
} |
switch (mode[which]) { |
switch (mode[which_dest][which]) { |
case MODE_COMMENT: send_stream(which,"</comment>\n"); break; |
case MODE_COMMENT: send_stream(which,"</comment>\n"); break; |
case MODE_BLOCK: send_stream(which,"</block>\n"); break; |
case MODE_BLOCK: send_stream(which,"</block>\n"); break; |
case MODE_SCRIPT: send_stream(which,"</script>\n"); break; |
case MODE_SCRIPT: send_stream(which,"</script>\n"); break; |
case MODE_OUTTEXT: send_stream(which,"<endouttext />\n"); break; |
case MODE_OUTTEXT: send_stream(which,"<endouttext />\n"); break; |
case MODE_ANSWER: send_stream(which,"\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_IMPORT: send_stream(which,"</import>\n"); break; |
case MODE_NONE: break; |
case MODE_NONE: break; |
} |
} |
mode[which]=MODE_NONE; |
mode[which_dest][which]=MODE_NONE; |
watch_mode[which]=0; |
watch_mode[which_dest][which]=0; |
} |
} |
|
|
void start_mode(int newmode,char* args) |
void start_mode(int newmode,char* args) |
{ |
{ |
start_mode_stream(ALL_STREAMS,newmode,args); |
start_mode_stream(current_dest,ALL_STREAMS,newmode,args); |
} |
} |
|
|
void start_mode_stream(int which,int newmode,char* args) |
void start_mode_stream(int which_dest,int which,int newmode,char* args) |
{ |
{ |
if (num_streams) { |
if (num_streams[which_dest]) { |
if (which == ALL_STREAMS) { |
if (which == ALL_STREAMS) { |
int i; |
int i; |
for (i=0;i<num_streams;i++) { start_mode_stream(i,newmode,args); } |
for (i=0;i<num_streams[which_dest];i++) { start_mode_stream(which_dest,i,newmode,args); } |
return; |
return; |
} else { |
} else { |
if (newmode == mode[which]) return; |
if (newmode == mode[which_dest][which]) return; |
} |
} |
} else { |
} else { |
if (newmode == mode[0]) return; |
if (newmode == mode[which_dest][0]) return; |
which=0;/* if streams aren't active make sure which is correct */ |
which=0;/* if streams aren't active make sure which is correct */ |
} |
} |
end_mode_stream(which); |
end_mode_stream(which_dest,which); |
switch (newmode) { |
switch (newmode) { |
case MODE_COMMENT: send_stream(which,"<comment>\n"); break; |
case MODE_COMMENT: send_stream(which,"<comment>\n"); break; |
case MODE_BLOCK: send_stream(which,"<block %s>\n",args); break; |
case MODE_BLOCK: send_stream(which,"<block %s>\n",args); break; |
case MODE_SCRIPT: send_stream(which,"<script type=\"loncapa/perl\">\n"); break; |
case MODE_SCRIPT: send_stream(which,"<script type=\"loncapa/perl\">\n"); break; |
case MODE_OUTTEXT: send_stream(which,"<startouttext />\n"); break; |
case MODE_OUTTEXT: send_stream(which,"<startouttext />\n"); break; |
case MODE_ANSWER: send_stream(which,"\n"); break; |
case MODE_ANSWER: send_stream(which,"\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_IMPORT: send_stream(which,"<import>"); break; |
case MODE_NONE: break; |
case MODE_NONE: break; |
} |
} |
mode[which]=newmode; |
mode[which_dest][which]=newmode; |
} |
} |
|
|
int current_cache=-1; |
int current_cache=-1; |