8 static struct varbuf vbin,vbout;
11 void chatfn_quit(void)
13 vbputstring(&vbout,"Closing...\n");
17 void chatfn_test0(void)
21 vbprintf(&vbout,"Test-0 command run times: %d\n",total++);
24 void chatfn_test2(void)
28 vbprintf(&vbout,"Test-2 command run times: %d, arg0=\"%s\", arg1=\"%s\"\n",
29 total++,chat_cmdpars[0],chat_cmdpars[1]);
32 const struct chat_cmdtab chat_cmdtable[]={
33 {"test0",0,chatfn_test0,"Test command with no arguments"},
34 {"test2",2,chatfn_test2,"Test command with 2 arguments"},
37 int main(int argc,char **argv)
44 for (arg=1;arg<argc;arg++)
45 printf("Ignored argument %d: %s\n",arg,*++argv);
46 VB_LOG(CRIT,"Trying CRIT dumb logging for the %dst time",1);
48 vbinit(&vbout); chat_vbout=&vbout;
50 fputs("> ",stdout); fflush(stdout);
51 while ((offs=vbchrn(&vbin,0,'\n',+1))==-1) {
52 if (!vbin.free) vbgrow(&vbin,0);
53 now=read(STDIN_FILENO,vbin.l->buf+vbin.l->size-vbin.free,vbin.free);
55 printf("\nError while reading input: %s\n",strerror(errno));
61 buf=realloc(buf,min(2*(offs+1),1024));
62 vbread(&vbin,buf,offs+1);
64 chat_proccmd("vbtest",buf);
65 vbreadfd(&vbout,STDOUT_FILENO);