#include "sftest.h"
tmain()
{
char* s;
if(argc > 1)
{ if(strcmp(argv[1],"-r") == 0)
{ if(!(s = sfgetr(sfstdin,'\n',1)) || strcmp(s,"Line2") != 0)
terror("Coprocess getr did not get Line2");
if(!(s = sfgetr(sfstdin,'\n',1)) || strcmp(s,"Line3") != 0)
terror("Coprocess getr did not get Line3");
}
else
{ Sfio_t* f = sfopen(NIL(Sfio_t*),NIL(char*),"swr");
if(!f)
terror("Can't open string stream");
if(sfmove(sfstdin,f,(Sfoff_t)2,'\n') != 2)
terror("Coprocess sfmove failed");
sfseek(f,(Sfoff_t)0,0);
if(!(s = sfgetr(f,'\n',1)) || strcmp(s,"Line2") != 0)
terror("Coprocess move did not get Line2");
if(!(s = sfgetr(f,'\n',1)) || strcmp(s,"Line3") != 0)
terror("Coprocess move did not get Line3");
}
texit(0);
}
if(sfopen(sfstdout, tstfile("sf", 0), "w") != sfstdout )
terror("Opening file");
if(sfputr(sfstdout,"Line1",'\n') < 0 ||
sfputr(sfstdout,"Line2",'\n') < 0 ||
sfputr(sfstdout,"Line3",'\n') < 0 ||
sfputr(sfstdout,"Line4",'\n') < 0)
terror("Writing data");
sfopen(sfstdout,"/dev/null","w");
if(sfopen(sfstdin, tstfile("sf", 0),"r") != sfstdin)
terror("Opening to read");
if(!(s = sfgetr(sfstdin,'\n',1)) || strcmp(s,"Line1") != 0)
terror("Did not get Line1 for sfgetr");
sfsync(sfstdin);
system(sfprints("%s -r",argv[0]));
sfseek(sfstdin, (Sfoff_t)lseek(sffileno(sfstdin), (off_t)0, 1), 0);
if(!(s = sfgetr(sfstdin,'\n',1)) || strcmp(s,"Line4") != 0)
terror("Did not get Line4 for sfgetr");
if(sfopen(sfstdin, tstfile("sf", 0), "r") != sfstdin)
terror("Opening to read");
if(!(s = sfgetr(sfstdin,'\n',1)) || strcmp(s,"Line1") != 0)
terror("Did not get Line1 for sfmove");
sfsync(sfstdin);
system(sfprints("%s -m",argv[0]));
sfseek(sfstdin, (Sfoff_t)lseek(sffileno(sfstdin), (off_t)0, 1), 0);
if(!(s = sfgetr(sfstdin,'\n',1)) || strcmp(s,"Line4") != 0)
terror("Did not get Line4 for sfmove");
#ifdef HEAD
if(sfopen(sfstdin, tstfile("sf", 0), "r") != sfstdin)
terror("Opening to read");
if(!(s = sfgetr(sfstdin,'\n',1)) || strcmp(s,"Line1") != 0)
terror("Did not get Line1 for head");
sfsync(sfstdin);
system("head -2 > /dev/null");
sfseek(sfstdin, (Sfoff_t)lseek(sffileno(sfstdin), (off_t)0, 1), 0);
if(!(s = sfgetr(sfstdin,'\n',1)) || strcmp(s,"Line4") != 0)
terror("Did not get Line4 for head");
#endif
texit(0);
}