--- loncom/homework/CAPA-converter/capaCommon.c 2001/07/11 23:00:57 1.7 +++ loncom/homework/CAPA-converter/capaCommon.c 2001/12/04 15:17:57 1.10 @@ -1,3 +1,30 @@ +/* The LearningOnline Network with CAPA + * Helaper functions for capa convertor. + * $Id: capaCommon.c,v 1.10 2001/12/04 15:17:57 albertel Exp $ + * + * 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 =====================|<||= */ /* created 1994 by Isaac Tsai */ /* 1994, 1995, 1996, 1997, 1998, 1999 copyrighted by Isaac Tsai */ @@ -153,8 +180,9 @@ extern void (*Status_Func)(); begin_text(); /*if ( !yyparse() ) { errcode = Lexi_qnum; } else { errcode = 0; }*/ if (!(temp=yylex())) { errcode = Lexi_qnum; } else { errcode = 0; } - printf("\nExited on: %d\n",temp); - printf("Flushing:\n"); + fprintf(stderr,"\nExited on: %d\n",temp); + fprintf(stderr,"Current cache: %d\n",current_cache); + fprintf(stderr,"Flushing:\n"); flush_delayed(); /* fclose(Input_stream[0]);*/ /*The Lexer handles closing this*/ /* print_symb_stat(); */ @@ -169,26 +197,31 @@ extern void (*Status_Func)(); int dyn_maxlen=1000000; int delay; -void dyn_init() +void dyn_init(struct dyn_string *dyn) { - dyn_delayed.len=0; - dyn_delayed.max=0; - dyn_delayed.str=NULL; + dyn->len=0; + dyn->max=0; + dyn->str=NULL; } -/* this can be used to free up the str components if the output - compenants are used internally, as in the reinit code -*/ -void dyn_free() +void dyn_free(struct dyn_string* dyn) { - 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) { char *new; 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); #ifdef DYN_DEBUG @@ -237,52 +270,163 @@ void add_delayed(char *format, ...) { va_start(ap,format); append_message(&dyn_delayed,format,ap); -} + if (do_cache[current_cache]) { + append_message(&cached_data[current_cache],format,ap); + } +} void flush_delayed() { - if (dyn_delayed.str) fputs(dyn_delayed.str,stdout); - dyn_free();dyn_init(); 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) { append_message(&dyn_delayed,text,ap); } else { - vprintf(text,ap); + if (num_streams) { + if (which == ALL_STREAMS) { + int i; + for (i=0;i\n"); break; - case MODE_BLOCK: send("\n"); break; - case MODE_SCRIPT: send("\n"); break; - case MODE_OUTTEXT: send("\n"); break; - case MODE_ANSWER: send("\n"); break; + end_mode_stream(ALL_STREAMS); +} + +void end_mode_stream(int which) +{ + if (num_streams) { + if (which == ALL_STREAMS) { + int i; + for (i=0;i\n"); break; + case MODE_BLOCK: send_stream(which,"\n"); break; + case MODE_SCRIPT: send_stream(which,"\n"); break; + case MODE_OUTTEXT: send_stream(which,"\n"); break; + case MODE_ANSWER: send_stream(which,"\n"); break; + case MODE_HINT: send_stream(which,"\n\n\n"); break; + case MODE_IMPORT: send_stream(which,"\n"); break; case MODE_NONE: break; } - mode=MODE_NONE; + mode[which]=MODE_NONE; + watch_mode[which]=0; } void start_mode(int newmode,char* args) { - if (newmode == mode) return; - end_mode(); + start_mode_stream(ALL_STREAMS,newmode,args); +} + +void start_mode_stream(int which,int newmode,char* args) +{ + if (num_streams) { + if (which == ALL_STREAMS) { + int i; + for (i=0;i\n"); break; - case MODE_BLOCK: send("\n",args); break; - case MODE_SCRIPT: send("