/* Fvwm command input interface. Copyright 1996, Toshi Isogai. No guarantees or warantees or anything are provided. Use this program at your own risk. Permission to use this program for any purpose is given, as long as the copyright is kept intact. */ #include "FvwmConsole.h" #define MYVERSION "1.3" char *MyName; int Fd[2]; /* pipe to fvwm */ int Ns; /* socket handles */ char Name[80]; /* name of this program in executable format */ char *S_name; /* socket name */ void server( void ); void DeadPipe( int ); void CloseSocket(); void ErrMsg( char *msg ); void SigHandler( int ); int main(int argc, char *argv[]){ char *tmp, *s; char client[120]; char **eargv; int i,j,k; char *xterm_a[] = { "-title", Name, "-name", Name, "-e", NULL, NULL }; int clpid; /* Why is this not just put in the initializer of xterm_a? Apparently, it is a non-standard extension to use a non-constant address (of client) in an initializer (of xterm_a). */ xterm_a[5] = client; /* Save the program name - its used for error messages and option parsing */ tmp = argv[0]; s=strrchr(argv[0], '/'); if (s != NULL) tmp = s + 1; strcpy( Name, tmp ); MyName = safemalloc(strlen(tmp)+2); strcpy(MyName,"*"); strcat(MyName, tmp); /* construct client's name */ strcpy( client, argv[0] ); strcat( client, "C" ); if(argc < FARGS) { fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName, MYVERSION); exit(1); } if( ( eargv =(char **)safemalloc((argc+12)*sizeof(char *)) ) == NULL ) { ErrMsg( "allocation" ); } /* copy arguments */ eargv[0] = XTERM; j = 1; for ( i=FARGS ; i1) { send(Ns, tline, strlen(tline),0); } GetConfigLine(Fd,&tline); } send(Ns, C_END, strlen(C_END), 0); strcpy( ver, MyName); strcat( ver, " Ver. " ); strcat( ver, MYVERSION); strcat( ver, "\n" ); send(Ns, ver, strlen(ver), 0 ); while (1){ FD_ZERO(&fdset); FD_SET(Ns, &fdset); FD_SET(Fd[1], &fdset); select(FD_SETSIZE,SELECT_TYPE_ARG234 &fdset, 0, 0, NULL); if (FD_ISSET(Fd[1], &fdset)){ if( ReadFvwmPacket(Fd[1],header,&body) > 0) { if(header[1] == M_PASS) { msglen = strlen((char *)&body[3]); if( msglen > MAX_MESSAGE_SIZE-2 ) { msglen = MAX_MESSAGE_SIZE-2; } send( Ns, (char *)&body[3], msglen, 0 ); } free(body); } } if (FD_ISSET(Ns, &fdset)){ if( recv( Ns, buf, MAX_COMMAND_SIZE,0 ) == 0 ) { /* client is terminated */ break; } /* process the own unique commands */ SendText(Fd,buf,0); /* send command */ } } CloseSocket(); exit(0); } /******************************************/ /* print error message on stderr and exit */ /******************************************/ void ErrMsg( char *msg ) { fprintf( stderr, "%s server error in %s, errno %d\n", Name, msg, errno ); CloseSocket(); exit(1); }