Component index
Section index

Component STREAMP


	    streamp is a simple component to help split a streamed input into
	    chunks. It does the buffering, filling and processing logic.
	    The following example output lines (text lines) but read bytes
	    5 at a time. So fill() is called until process() sees a full line
	    and output it.
	    One way to test this sample is to copy a text file in /tmp/foo
	    and do
	    /tmp/x streamp </tmp/foo >/tmp/
	    cmp /tmp/foo /tmp/ && echo ok
	void sample_streamp()
	    <call streamp>();
	    <f fill>
	        return fread (buf,1,5,stdin);
	    <f process>
	        // Check if there is a end of line
	        const void *pt = memchr (buf,'\n',len);
	        int used = 0;
	        if (pt != NULL){
	            used = (char*)pt - (char*)buf;
	            printf ("%*.*s\n",used,used,(const char *)buf);
	            fprintf (stderr,"length %d is not enough\n",len);
	        return used;