version 1.3, 1999/11/18 23:57:19 |
version 1.6, 2003/11/18 11:08:27 |
|
|
/*$OpenXM: OpenXM/src/kan96xx/plugin/file2.c,v 1.2 1999/11/18 00:54:17 takayama Exp $ */ |
/*$OpenXM: OpenXM/src/kan96xx/plugin/file2.c,v 1.5 2003/11/17 05:45:47 takayama Exp $ */ |
#include <stdio.h> |
#include <stdio.h> |
#include <sys/time.h> |
#include <sys/time.h> |
#include <sys/types.h> |
#include <sys/types.h> |
Line 56 FILE2 *fp2open(int fd) { |
|
Line 56 FILE2 *fp2open(int fd) { |
|
fp2->watch = 0; |
fp2->watch = 0; |
fp2->watchFile = NULL; |
fp2->watchFile = NULL; |
fp2->mathcapList = NULL; |
fp2->mathcapList = NULL; |
|
fp2->log_incomming = NULL; |
|
fp2->log_outgoing = NULL; |
return(fp2); |
return(fp2); |
} |
} |
|
|
Line 98 int fp2fputc(int c,FILE2 *fp2) { |
|
Line 100 int fp2fputc(int c,FILE2 *fp2) { |
|
printf("fp2 = %x.\n",(int) fp2); |
printf("fp2 = %x.\n",(int) fp2); |
} |
} |
if (fp2->watch || WatchStream) { |
if (fp2->watch || WatchStream) { |
if (fp2->watch) fp = fp2->watchFile; |
if (fp2->watch) fp = fp2->watchFile; |
else fp = stderr; |
else fp = stderr; |
|
fprintf(stderr,"put to <%x> ",fp2->fd); /* output the channel for debug */ |
if (c >= ' ' && c <='z') { |
if (c >= ' ' && c <='z') { |
fprintf(fp," %2x(%c)-> ",c& 0xff,c); |
fprintf(fp," %2x(%c)-> ",c& 0xff,c); |
}else{ |
}else{ |
Line 107 int fp2fputc(int c,FILE2 *fp2) { |
|
Line 110 int fp2fputc(int c,FILE2 *fp2) { |
|
} |
} |
fflush(NULL); |
fflush(NULL); |
} |
} |
|
if (fp2->log_outgoing != NULL) fputc(c,fp2->log_outgoing); |
if (checkfp2(fp2," fp2fputc ") == -1) return(-1); |
if (checkfp2(fp2," fp2fputc ") == -1) return(-1); |
(fp2->writeBuf)[fp2->writepos] = c; |
(fp2->writeBuf)[fp2->writepos] = c; |
(fp2->writepos)++; |
(fp2->writepos)++; |
Line 127 int fp2fgetc(FILE2 *fp2) { |
|
Line 131 int fp2fgetc(FILE2 *fp2) { |
|
fp2->readpos++; |
fp2->readpos++; |
c = fp2->readBuf[fp2->readpos -1]; |
c = fp2->readBuf[fp2->readpos -1]; |
if (fp2->watch || WatchStream) { |
if (fp2->watch || WatchStream) { |
if (fp2->watch) fp = fp2->watchFile; |
if (fp2->watch) fp = fp2->watchFile; |
else fp = stderr; |
else fp = stderr; |
|
fprintf(fp,"get from <%x> ",fp2->fd); /* output the channel for debug*/ |
if (c >= ' ' && c <= 'z') { |
if (c >= ' ' && c <= 'z') { |
fprintf(fp," %2x(%c) ",c,c); |
fprintf(fp," %2x(%c) ",c,c); |
}else{ |
}else{ |
fprintf(fp," %2x( ) ",c); |
fprintf(fp," %2x( ) ",c); |
} |
} |
fflush(NULL); |
fflush(NULL); |
} |
} |
|
if (fp2->log_incomming != NULL) fputc(c,fp2->log_incomming); |
return(c); |
return(c); |
}else{ |
}else{ |
fp2->readpos = 0; |
fp2->readpos = 0; |
Line 143 int fp2fgetc(FILE2 *fp2) { |
|
Line 149 int fp2fgetc(FILE2 *fp2) { |
|
read(fp2->fd, fp2->readBuf, fp2->limit); |
read(fp2->fd, fp2->readBuf, fp2->limit); |
if (fp2->readsize == 0) { |
if (fp2->readsize == 0) { |
if (fp2->watch || WatchStream) { |
if (fp2->watch || WatchStream) { |
if (fp2->watch) fp = fp2->watchFile; |
if (fp2->watch) fp = fp2->watchFile; |
else fp = stderr; |
else fp = stderr; |
fprintf(fp," <%2x ",c); |
fprintf(fp," <%2x ",c); |
fflush(NULL); |
fflush(NULL); |
} |
} |
|
if (fp2->log_incomming != NULL) fputc(c,fp2->log_incomming); |
return(-1); |
return(-1); |
} |
} |
else { |
else { |
Line 217 int fp2clearReadBuf(FILE2 *fp2) { |
|
Line 224 int fp2clearReadBuf(FILE2 *fp2) { |
|
if (FD_ISSET(fd,&readfds)) { |
if (FD_ISSET(fd,&readfds)) { |
n = read(fd,tmp00, TMP00SIZE); |
n = read(fd,tmp00, TMP00SIZE); |
if (n <= 0) { |
if (n <= 0) { |
fprintf(stderr,"fp2clearReadBuf: File is closed or read error.\n"); |
fprintf(stderr,"fp2clearReadBuf: File is closed or read error.\n"); |
return(-1); |
return(-1); |
} |
} |
if ( n < TMP00SIZE ) { |
if ( n < TMP00SIZE ) { |
return(0); |
return(0); |
} |
} |
}else { |
}else { |
return(0); |
return(0); |
Line 271 int fp2stopWatch(FILE2 *fp2) |
|
Line 278 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; |
|
} |