version 1.2, 2000/05/03 15:35:11
|
version 1.3, 2000/05/15 20:33:33
|
Line 111 capa_parse(set,problem,filename,num_ques
|
Line 111 capa_parse(set,problem,filename,num_ques
|
int set;Problem_t **problem;char *filename;int *num_questions; |
int set;Problem_t **problem;char *filename;int *num_questions; |
void (*func_ptr)(); |
void (*func_ptr)(); |
{ |
{ |
int errcode; |
int errcode,temp; |
extern FILE *Input_stream[MAX_OPENED_FILE]; |
extern FILE *Input_stream[MAX_OPENED_FILE]; |
extern char Opened_filename[MAX_OPENED_FILE][QUARTER_K]; |
extern char Opened_filename[MAX_OPENED_FILE][QUARTER_K]; |
extern int Lexi_line; |
extern int Lexi_line; |
Line 152 extern void (*Status_Func)();
|
Line 152 extern void (*Status_Func)();
|
/*yyrestart(yyin);*/ |
/*yyrestart(yyin);*/ |
begin_text(); |
begin_text(); |
/*if ( !yyparse() ) { errcode = Lexi_qnum; } else { errcode = 0; }*/ |
/*if ( !yyparse() ) { errcode = Lexi_qnum; } else { errcode = 0; }*/ |
if (!yylex()) { errcode = Lexi_qnum; } else { errcode = 0; } |
if (!(temp=yylex())) { errcode = Lexi_qnum; } else { errcode = 0; } |
|
printf("\nExited on: %d\n",temp); |
|
printf("Flushing:\n"); |
|
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 164 extern void (*Status_Func)();
|
Line 167 extern void (*Status_Func)();
|
return (errcode); |
return (errcode); |
} |
} |
|
|
char* delayed; |
int dyn_maxlen=1000000; |
|
int delay; |
|
void dyn_init() |
|
{ |
|
dyn_delayed.len=0; |
|
dyn_delayed.max=0; |
|
dyn_delayed.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() |
|
{ |
|
if (dyn_delayed.str) {free(dyn_delayed.str);dyn_delayed.str=NULL;} |
|
} |
|
|
|
int append_message(struct dyn_string *dyn_msg,char *format,va_list ap) { |
|
char *new; |
|
int len,result; |
|
|
|
result=vasprintf(&new,format,ap); |
|
len=strlen(new); |
|
|
|
#ifdef DYN_DEBUG |
|
fprintf(stderr,"before: len %d; gcount %d; max %d\n", |
|
len,dyn_msg->len,dyn_msg->max); |
|
#endif /* DYN_DEBUG */ |
|
|
|
if (dyn_msg->len+len < dyn_maxlen) { |
|
if (dyn_msg->len+len>dyn_msg->max-2) { |
|
dyn_msg->max=(dyn_msg->len+len)*2; |
|
if (dyn_msg->max>dyn_maxlen) { dyn_msg->max=dyn_maxlen; } |
|
if (dyn_msg->max != 0) { |
|
dyn_msg->str=realloc(dyn_msg->str,dyn_msg->max); |
|
} else { |
|
return 1; |
|
} |
|
dyn_msg->str[dyn_msg->len]='\0'; |
|
} |
|
strcat(dyn_msg->str,new); |
|
dyn_msg->len+=len; |
|
} else { |
|
if (dyn_msg->max != dyn_maxlen-1) { /*already maxed out or can |
|
we fit this one in?*/ |
|
dyn_msg->max=dyn_maxlen; |
|
dyn_msg->str=realloc(dyn_msg->str,dyn_msg->max); |
|
dyn_msg->str[dyn_msg->len]='\0'; |
|
strncat(dyn_msg->str,new,dyn_msg->max-dyn_msg->len-1); |
|
dyn_msg->len=strlen(dyn_msg->str); |
|
} |
|
} |
|
free(new); |
|
|
|
#ifdef DYN_DEBUG |
|
fprintf(stderr,"after: len %d; gcount %d; max %d; strlen(dyn_msg): %d\n", |
|
len,dyn_msg->len,dyn_msg->max,strlen(dyn_msg->str)); |
|
#endif /* DYN_DEBUG */ |
|
|
|
return 1; |
|
} |
|
|
|
void start_delayed(){ delay=1; } |
|
void end_delayed(){ delay=0; } |
|
|
|
void add_dealyed(char *format, ...) { |
|
va_list ap; |
|
|
|
va_start(ap,format); |
|
append_message(&dyn_delayed,format,ap); |
|
} |
|
|
|
void flush_delayed() |
|
{ |
|
printf(dyn_delayed.str); |
|
dyn_free();dyn_init(); |
|
delay=0; |
|
} |
|
|
void send(char *text,...) |
void send(char *text,...) |
{ |
{ |
va_list ap; |
va_list ap; |
if (delayed) {printf(delayed);free(delayed);delayed=NULL;} |
|
va_start(ap,text); |
va_start(ap,text); |
vprintf(text,ap); |
if (delay) { |
|
append_message(&dyn_delayed,text,ap); |
|
} else { |
|
vprintf(text,ap); |
|
} |
} |
} |
|
|
void send_delayed(char *text,...) |
void end_mode() |
{ |
{ |
va_list ap; |
switch (mode) { |
va_start(ap,text); |
case MODE_COMMENT: send("</comment>\n"); break; |
vasprintf(&delayed,text,ap); |
case MODE_BLOCK: send("</block>\n"); break; |
|
case MODE_SCRIPT: send("</script>\n"); break; |
|
case MODE_OUTTEXT: send("</outtext>\n"); break; |
|
case MODE_NONE: break; |
|
} |
|
mode=MODE_NONE; |
} |
} |
|
|
void remove_delayed() |
void start_mode(int newmode,char* args) |
{ |
{ |
if (delayed) {free(delayed);delayed=NULL;} |
if (newmode == mode) return; |
|
end_mode(); |
|
switch (newmode) { |
|
case MODE_COMMENT: send("<comment>\n"); break; |
|
case MODE_BLOCK: send("<block %s>\n",args); break; |
|
case MODE_SCRIPT: send("<script>\n"); break; |
|
case MODE_OUTTEXT: send("<outtext>\n"); break; |
|
case MODE_NONE: break; |
|
} |
|
mode=newmode; |
} |
} |
/* =||>|===================== End of capaCommon.c =====================|<||= */ |
/* =||>|===================== End of capaCommon.c =====================|<||= */ |
|
|