head 1.2; access; symbols SFIO_1999:1.1.1.2 SFIO_1998:1.1.1.2 SFIO_1997:1.1.1.1 ATT:1.1.1; locks; strict; comment @ * @; 1.2 date 99.09.11.12.42.11; author rse; state Exp; branches; next 1.1; 1.1 date 96.12.13.21.15.44; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 96.12.13.21.15.44; author rse; state Exp; branches; next 1.1.1.2; 1.1.1.2 date 97.03.07.00.54.56; author rse; state Exp; branches; next ; desc @@ 1.2 log @Incorporate stuff from RSE's Sfio98 variant @ text @#include "sftest.h" #include #if __STD_C static void alrmf(int sig) #else static void alrmf(sig) int sig; #endif { terror("Alarm went off\n"); } int main() { int fd[2]; Sfio_t *fr, *fw = NULL; char *s; int i, j, n; char buf[1024]; if(sfnew(sfstdout,buf,sizeof(buf),SF_UNBOUND,SF_STRING|SF_WRITE) != sfstdout) terror("Reopen sfstdout\n"); if(pipe(fd) < 0) terror("Can't open pipe\n"); if(!(fr = sfnew(NIL(Sfio_t*),NIL(Void_t*),(size_t)SF_UNBOUND,fd[0],SF_READ)) || !(fw = sfnew(NIL(Sfio_t*),NIL(Void_t*),(size_t)SF_UNBOUND,fd[1],SF_WRITE)) ) terror("Can't open stream\n"); signal(SIGALRM,alrmf); sfwrite(fw,"0123456789",10); alarm(4); if(sfread(fr,buf,10) != 10) terror("Can't read data from pipe\n"); sfwrite(fw,"0123456789",10); if(sfmove(fr,fw,(Sfoff_t)10,-1) != 10) terror("sfmove failed\n"); alarm(0); sfpurge(fw); sfclose(fw); sfpurge(fr); sfclose(fr); if(pipe(fd) < 0) terror("Can't open pipe2\n"); if(!(fr = sfnew(NIL(Sfio_t*),NIL(Void_t*),(size_t)SF_UNBOUND,fd[0],SF_READ)) || !(fw = sfnew(NIL(Sfio_t*),NIL(Void_t*),(size_t)SF_UNBOUND,fd[1],SF_WRITE)) ) terror("Can't open stream\n"); sfset(fr,SF_SHARE|SF_LINE,1); sfset(fw,SF_SHARE,1); if(sfwrite(fw,"1\n2\n3\n",6) != 6) terror("sfwrite failed0\n"); i = j = -1; if(sfscanf(fr,"%d%d\n%n",&i,&j,&n) != 2 || i != 1 || j != 2 || n != 4) terror("sfscanf failed0\n"); if(sfscanf(fr,"%d\n%n",&i,&n) != 1 || i != 3 || n != 2) terror("sfscanf failed1\n"); if(sfwrite(fw,"123\n",4) != 4) terror("sfwrite failed\n"); if(!(s = sfreserve(fr,4,0)) ) terror("sfreserve failed\n"); sfputr(fw,"abc",'\n'); if(sfmove(fr,fw,(Sfoff_t)1,'\n') != 1) terror("sfmove failed\n"); if(!(s = sfgetr(fr,'\n',1)) || strcmp(s,"abc") != 0) terror("sfgetr failed\n"); if(sfwrite(fw,"111\n222\n333\n444\n",16) != 16) terror("Bad write to pipe\n"); if(!(s = sfgetr(fr,'\n',1)) ) terror("sfgetr failed\n"); if(strcmp(s,"111") != 0) terror("sfgetr got wrong string\n"); if(sfmove(fr,sfstdout,(Sfoff_t)2,'\n') != 2) terror("sfmove failed2\n"); sfputc(sfstdout,0); if(strcmp("222\n333\n",buf) != 0) terror("sfmove got wrong data\n"); if(sfmove(fr,NIL(Sfio_t*),(Sfoff_t)1,'\n') != 1) terror("sfmove failed\n"); if(sfwrite(fw,"0123456789",11) != 11) terror("Bad write to pipe2\n"); if(!(s = sfreserve(fr,11,0)) ) terror("Bad peek size %d, expect 11\n",sfvalue(fr)); if(strncmp(s,"0123456789",10) != 0) terror("Bad peek str %s\n",s); return 0; } @ 1.1 log @Initial revision @ text @d5 1 a5 1 void alrmf(int sig) d7 1 a7 1 void alrmf(sig) d14 1 a14 1 main() d17 1 a17 1 Sfio_t *fr, *fw; d67 1 a67 1 if(sfmove(fr,fw,1,'\n') != 1) d80 1 a80 1 if(sfmove(fr,sfstdout,2,'\n') != 2) d85 1 a85 1 if(sfmove(fr,NIL(Sfio_t*),1,'\n') != 1) @ 1.1.1.1 log @Import of Sfio1997 @ text @@ 1.1.1.2 log @Import of Sfio1998 @ text @d67 1 a67 1 if(sfmove(fr,fw,(Sfoff_t)1,'\n') != 1) d80 1 a80 1 if(sfmove(fr,sfstdout,(Sfoff_t)2,'\n') != 2) d85 1 a85 1 if(sfmove(fr,NIL(Sfio_t*),(Sfoff_t)1,'\n') != 1) @