=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/plugin/file2.c,v retrieving revision 1.1.1.1 retrieving revision 1.6 diff -u -p -r1.1.1.1 -r1.6 --- OpenXM/src/kan96xx/plugin/file2.c 1999/10/08 02:12:05 1.1.1.1 +++ OpenXM/src/kan96xx/plugin/file2.c 2003/11/18 11:08:27 1.6 @@ -1,3 +1,4 @@ +/*$OpenXM: OpenXM/src/kan96xx/plugin/file2.c,v 1.5 2003/11/17 05:45:47 takayama Exp $ */ #include #include #include @@ -9,7 +10,7 @@ #else void *GC_malloc(int size); #endif - +int WatchStream = 0; /* Note: 1997, 12/6 cf. SS475/kxx/openxxx.tex, SS475/memo1.txt The functions in file2.c should not accept interruptions during its critical operations. The synchronization mechanism @@ -55,6 +56,8 @@ FILE2 *fp2open(int fd) { fp2->watch = 0; fp2->watchFile = NULL; fp2->mathcapList = NULL; + fp2->log_incomming = NULL; + fp2->log_outgoing = NULL; return(fp2); } @@ -91,18 +94,23 @@ int fp2fclose(FILE2 *fp2) { } int fp2fputc(int c,FILE2 *fp2) { + FILE *fp; if (debug1) { printf("fp2fputc is called with %2x, fp2->writepos=%d, ",c,fp2->writepos); printf("fp2 = %x.\n",(int) fp2); } - if (fp2->watch) { + if (fp2->watch || WatchStream) { + if (fp2->watch) fp = fp2->watchFile; + else fp = stderr; + fprintf(stderr,"put to <%x> ",fp2->fd); /* output the channel for debug */ if (c >= ' ' && c <='z') { - fprintf(fp2->watchFile," %2x(%c)-> ",c,c); + fprintf(fp," %2x(%c)-> ",c& 0xff,c); }else{ - fprintf(fp2->watchFile," %2x( )-> ",c); + fprintf(fp," %2x( )-> ",c& 0xff); } fflush(NULL); } + if (fp2->log_outgoing != NULL) fputc(c,fp2->log_outgoing); if (checkfp2(fp2," fp2fputc ") == -1) return(-1); (fp2->writeBuf)[fp2->writepos] = c; (fp2->writepos)++; @@ -116,29 +124,37 @@ int fp2fputc(int c,FILE2 *fp2) { int fp2fgetc(FILE2 *fp2) { int c; + FILE *fp; /* printf("fp2fgetc is called. "); fflush(NULL); */ if (checkfp2(fp2," fp2fgetc ") == -1) return(-1); if (fp2->readpos < fp2->readsize) { fp2->readpos++; c = fp2->readBuf[fp2->readpos -1]; - if (fp2->watch) { + if (fp2->watch || WatchStream) { + if (fp2->watch) fp = fp2->watchFile; + else fp = stderr; + fprintf(fp,"get from <%x> ",fp2->fd); /* output the channel for debug*/ if (c >= ' ' && c <= 'z') { - fprintf(fp2->watchFile," %2x(%c) ",c,c); + fprintf(fp," %2x(%c) ",c,c); }else{ - fprintf(fp2->watchFile," %2x( ) ",c); + fprintf(fp," %2x( ) ",c); } fflush(NULL); } + if (fp2->log_incomming != NULL) fputc(c,fp2->log_incomming); return(c); }else{ fp2->readpos = 0; fp2 ->readsize = read(fp2->fd, fp2->readBuf, fp2->limit); if (fp2->readsize == 0) { - if (fp2->watch) { - fprintf(fp2->watchFile," <%2x ",c); - fflush(NULL); + if (fp2->watch || WatchStream) { + if (fp2->watch) fp = fp2->watchFile; + else fp = stderr; + fprintf(fp," <%2x ",c); + fflush(NULL); } + if (fp2->log_incomming != NULL) fputc(c,fp2->log_incomming); return(-1); } else { @@ -208,11 +224,11 @@ int fp2clearReadBuf(FILE2 *fp2) { if (FD_ISSET(fd,&readfds)) { n = read(fd,tmp00, TMP00SIZE); if (n <= 0) { - fprintf(stderr,"fp2clearReadBuf: File is closed or read error.\n"); - return(-1); + fprintf(stderr,"fp2clearReadBuf: File is closed or read error.\n"); + return(-1); } if ( n < TMP00SIZE ) { - return(0); + return(0); } }else { return(0); @@ -262,3 +278,14 @@ int fp2stopWatch(FILE2 *fp2) } } +int fp2log(FILE2 *fp,FILE *incomming,FILE *outgoing) { + fp->log_incomming = incomming; + fp->log_outgoing = outgoing; + return 0; +} +int fp2stopLog(FILE2 *fp) { + if (fp->log_incomming != NULL) fclose(fp->log_incomming); + if (fp->log_outgoing != NULL) fclose(fp->log_outgoing); + fp->log_incomming = fp->log_outgoing = NULL; + return 0; +}