#include #include #include #include #include "vblib.h" static struct varbuf vbin,vbout; static int closing=0; void chatfn_quit(void) { vbputstring(&vbout,"Closing...\n"); closing=1; } void chatfn_test0(void) { static int total=0; vbprintf(&vbout,"Test-0 command run times: %d\n",total++); } void chatfn_test2(void) { static int total=0; vbprintf(&vbout,"Test-2 command run times: %d, arg0=\"%s\", arg1=\"%s\"\n", total++,chat_cmdpars[0],chat_cmdpars[1]); } const struct chat_cmdtab chat_cmdtable[]={ {"test0",0,chatfn_test0,"Test command with no arguments"}, {"test2",2,chatfn_test2,"Test command with 2 arguments"}, {NULL,0,NULL,NULL}}; int main(int argc,char **argv) { int arg; char *buf=NULL; size_t bufsiz=0; ssize_t offs,now; for (arg=1;arg ",stdout); fflush(stdout); while ((offs=vbchrn(&vbin,0,'\n',+1))==-1) { if (!vbin.free) vbgrow(&vbin,0); now=read(STDIN_FILENO,vbin.l->buf+vbin.l->size-vbin.free,vbin.free); if (now<=0) { printf("\nError while reading input: %s\n",strerror(errno)); exit(EXIT_FAILURE); } vbin.free-=now; } if (bufsiz