7 #ifdef LIBVNCSERVER_HAVE_FCNTL_H
10 #ifdef LIBVNCSERVER_HAVE_SYS_TIME_H
13 #ifdef LIBVNCSERVER_HAVE_UNISTD_H
16 #ifdef LIBVNCSERVER_HAVE_SYS_WAIT_H
22 int main(int argc, char **argv)
24 rfbBool interactive=FALSE,sendOnlyWholeLines=TRUE;
25 int serverArgc,programArg0;
26 for(serverArgc=1;serverArgc<argc
27 && argv[serverArgc][0]=='-' && argv[serverArgc][1]!='-';serverArgc++)
28 if(!strcmp(argv[serverArgc],"-interactive")) {
30 sendOnlyWholeLines=FALSE;
32 rfbPurgeArguments(&argc,&serverArgc,1,argv);
34 programArg0=serverArgc;
35 if(programArg0<argc && argv[programArg0][0]=='-' && argv[programArg0][1]=='-')
39 if(programArg0<argc) {
40 int in[2],out[2],err[2],pid;
41 if(pipe(in)<0 || pipe(out)<0 || pipe(err)<0) {
42 rfbErr("Couldn't make pipes!");
51 /*setbuf(stdin,NULL);*/
52 execvp(argv[programArg0],argv+programArg0);
57 fd_set fs,fs1/*,ifs,ifs1*/;
58 struct timeval tv,tv1;
59 int i,c=1,num_fds,max_fd=out[0],status;
61 vncConsolePtr console=vcGetConsole(&serverArgc,argv,80,25,&vgaFont,FALSE);
63 console->doEcho = FALSE;
71 tv.tv_sec=0; tv.tv_usec=5000;
73 input_pipe=fdopen(in[1],"w");
74 setbuf(input_pipe,NULL);
75 while(c || waitpid(pid,&status,WNOHANG)==0) {
77 vcProcessEvents(console);
80 if(console->inputCount) {
81 if(sendOnlyWholeLines) {
82 for(i=0;i<console->inputCount;i++)
83 if(console->inputBuffer[i]=='\n') {
85 fwrite(console->inputBuffer,i,1,input_pipe);
87 /* fwrite(console->inputBuffer,i,1,stderr); */
88 if(console->inputCount>i)
89 memmove(console->inputBuffer,console->inputBuffer+i,console->inputCount-i);
90 console->inputCount-=i;
94 fwrite(console->inputBuffer,console->inputCount,1,input_pipe);
96 /* fwrite(console->inputBuffer,console->inputCount,1,stderr); */
97 console->inputCount=0;
102 num_fds=select(max_fd+1,&fs1,NULL,NULL,&tv1);
105 if(FD_ISSET(0,&fs1)) {
110 if(FD_ISSET(out[0],&fs1)) {
111 c=read(out[0],buffer,1024);
113 vcPutChar(console,buffer[i]);
115 if(FD_ISSET(err[0],&fs1)) {
116 c=read(err[0],buffer,1024);
118 vcPutChar(console,buffer[i]);