Ejemplo n.º 1
0
static void ctl_pass_playing_list(int init_number_of_files,
				  char * /*init_list_of_files*/ [])
{
	EventRecord	event;

	if( init_number_of_files!=0 ){
		cmsg(CMSG_FATAL, VERB_NORMAL,
		  "ctl_pass_playing_list: Sorry. Fatal error.");
	}
	
#ifdef MAC_USE_OMS
	mac_oms_setup();
#endif
	
	{
		FSSpec	spec;
		OSErr	err;
		err=FSMakeFSSpec(0, 0, MAC_STARTUP_FOLDER_NAME, &spec);
		if( err==noErr ){ mac_add_fsspec( &spec ); }
	}
	
	gQuit=false;
	while(!gQuit)
	{
		WaitNextEvent(everyEvent, &event, 1,0);
		mac_HandleEvent(&event);
	}	
	DoQuit();
}
Ejemplo n.º 2
0
void VProcess::Run()
{
	VTask *mainTask = VTask::GetMain();
	if (!testAssert( (mainTask != NULL) && mainTask->IsCurrent() && (mainTask->GetState() == TS_RUNNING) ))
		return;

	if (!fInitCalled)
		fInitOK = Init();
	
	if (fInitOK)
	{
		vFlushErrors();
		
		StartMessaging();
		
		DoRun();

		DoQuit();
		mainTask->Kill();

		StopMessaging();
	}
	else
	{
		vThrowError(VE_CANNOT_INITIALIZE_APPLICATION, "VApplication::DoInit failed");
	}
}
Ejemplo n.º 3
0
Archivo: lunxun.c Proyecto: jsvisa/apue
int DealRequest(int sock, char *buf) {
	int ret = 0;
	printf("Deal Request\n");
	if(strncasecmp(buf, "login", 5) != 0 && logined != 1) {
		msend(sock, "401 Please login first\r\n");
		return -1;
	}

	if(strncasecmp(buf, "list", 4) == 0) {
		ret = DoList(sock, buf);
	}
	else if(strncasecmp(buf, "cd", 2) == 0) {
		ret = DoChdir(sock, buf);
	}
	else if(strncasecmp(buf, "login", 5) == 0) {
		ret = DoLogin(sock, buf);
	}
	else if(strncasecmp(buf, "get", 3) == 0) {
		ret = DoGet(sock, buf);
	}
	else if(strncasecmp(buf, "quit", 4) == 0) {
		ret = DoQuit(sock, buf);
	}
	else {
		printf("Unknown Request:%s\n", buf);
		msend(sock, "400 Unknown command\r\n");
	}
	return ret;

}
Ejemplo n.º 4
0
static int ctl_read(int32* /*valp*/)
{
	int			ret;
	
	//if( gCursorIsWatch ){ gCursorIsWatch=false; InitCursor(); }
	if( gQuit ) DoQuit();	/* Quit Apple event occured */
	if( mac_rc ){ret=mac_rc; mac_rc=0; return ret;}
	if( !gBusy || UserWantsControl()){
		YieldToAnyThread();
	}
	return RC_NONE;
}
Ejemplo n.º 5
0
void OnTextInputEvent(SDL_Event * event)
{
	// If there is a visible popup then let it handle input instead of the underlying screen
	// should be done in a way to be sure the topmost popup has preference (maybe error, then check)
	if (UIPopupError != NULL && UIPopupError->Visible)
		UIPopupError->ParseTextInput(event);
	else if (UIPopupInfo != NULL && UIPopupInfo->Visible)
		UIPopupInfo->ParseTextInput(event);
	else if (UIPopupCheck != NULL && UIPopupCheck->Visible)
		UIPopupCheck->ParseTextInput(event);
	// if screen wants to exit
	else if (!sDisplay.ParseTextInput(event))
		DoQuit();
}
Ejemplo n.º 6
0
void OnMouseEvent(int mouseBtn, bool mouseDown, float mouseX, float mouseY)
{
	// Drop input when changing screens
	if (sDisplay.NextScreen != NULL)
		return;

	if (UIPopupError != NULL && UIPopupError->Visible)
		UIPopupError->ParseMouse(mouseBtn, mouseDown, mouseX, mouseY);
	else if (UIPopupInfo != NULL && UIPopupInfo->Visible)
		UIPopupInfo->ParseMouse(mouseBtn, mouseDown, mouseX, mouseY);
	else if (UIPopupCheck != NULL && UIPopupCheck->Visible)
		UIPopupCheck->ParseMouse(mouseBtn, mouseDown, mouseX, mouseY);
	else if (!sDisplay.ParseMouse(mouseBtn, mouseDown, mouseX, mouseY))
		DoQuit();
}
Ejemplo n.º 7
0
int main (int argc, const char * argv[])
    // The primary entry point.
{
    int             err;
    ConnectionRef   conn;
    
    conn = NULL;
    
    // If we get no arguments, just print the usage and fail.
    
    err = 0;
    if (argc == 1) {
        PrintUsage(argv[0]);
        err = ECANCELED;
    }
    
    // SIGPIPE is evil, so tell the system not to send it to us.
    
    if (err == 0) {
        err = MoreUNIXIgnoreSIGPIPE();
    }

    // Organise to have SIGINT delivered to a runloop callback.
    
    if (err == 0) {
        sigset_t    justSIGINT;
        
        (void) sigemptyset(&justSIGINT);
        (void) sigaddset(&justSIGINT, SIGINT);
        
        err = InstallSignalToSocket(
            &justSIGINT,
            CFRunLoopGetCurrent(),
            kCFRunLoopDefaultMode,
            SIGINTRunLoopCallback,
            NULL
        );
    }
    
    // Connect to the server.
    
    if (err == 0) {
        err = ConnectionOpen(&conn);
    }
    
    // Process the command line arguments.  Basically the arguments are a 
    // sequence of commands, which we process in order.  The logic is 
    // a little convoluted because some commands have arguments and because 
    // the "listen" command must come last.
    
    if (err == 0) {
        Boolean printTheUsage;
        int     argIndex;
        
		printTheUsage = false;
		
        argIndex = 1;
        while ( (err == 0) && (argIndex < argc) ) {
            if ( strcmp(argv[argIndex], "nop") == 0 ) {
                DoNOP(conn);
            } else if ( strcmp(argv[argIndex], "whisper") == 0 ) {
                argIndex += 1;
                if (argIndex < argc) {
                    DoWhisper(conn, argv[argIndex]);
                } else {
                    printTheUsage = true;
                    err = ECANCELED;
                }
            } else if ( strcmp(argv[argIndex], "shout") == 0 ) {
                argIndex += 1;
                if (argIndex < argc) {
                    DoShout(conn, argv[argIndex]);
                } else {
                    printTheUsage = true;
                    err = ECANCELED;
                }
            } else if ( strcmp(argv[argIndex], "listen") == 0 ) {
                if ( (argIndex + 1) == argc ) {         // if listen is the last argument
                    DoListen(conn);
                } else {
                    printTheUsage = true;
                    err = ECANCELED;
                }
            } else if ( strcmp(argv[argIndex], "quit") == 0 ) {
                DoQuit(conn);
            } else {
                printTheUsage = true;
                err = ECANCELED;
            }
            argIndex += 1;
        }
        
        if (printTheUsage) {
            PrintUsage(argv[0]);
        }
    }
    
    // Clean up.
    
    ConnectionClose(conn);

    if ( (err != 0) && (err != ECANCELED) ) {
        fprintf(stderr, "SimpleClientCF: Failed with error %d.\n", err);
    }
    
    return (err == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
Ejemplo n.º 8
0
static void goaway_PlayerWin()
{
	DoQuit();
}
Ejemplo n.º 9
0
void CheckEvents(float & mouseX, float & mouseY)
{
	SDL_Event event;
	bool mouseDown;
	int mouseBtn;

	while (SDL_PollEvent(&event))
	{
		switch (event.type)
		{
		case SDL_QUIT:
			DoQuit();
			break;

		case SDL_WINDOWEVENT:
			switch (event.window.event)
			{
				case SDL_WINDOWEVENT_RESIZED:
				case SDL_WINDOWEVENT_MAXIMIZED:
					if (event.window.data1 == 0
						|| event.window.data2 == 0)
						continue;

					ScreenW = event.window.data1;
					ScreenH = event.window.data2;

					SDL_SetWindowSize(Screen, ScreenW, ScreenH);
					
					glViewport(0, 0, ScreenW, ScreenH);
					glMatrixMode(GL_PROJECTION);
					glLoadIdentity();
					glOrtho(0, ScreenW, ScreenH, 0, -1, 1);
					glMatrixMode(GL_MODELVIEW);
					glLoadIdentity();
					break;
			}
			break;

		case SDL_MOUSEMOTION:
			if (sIni.Mouse)
			{
				mouseDown = false;
				mouseBtn = 0;
			}

			sDisplay.MoveCursor((float) event.button.x * RenderW * Screens / ScreenW,
				(float) event.button.y * RenderH / ScreenH);
			break;

		case SDL_MOUSEBUTTONDOWN:
		case SDL_MOUSEBUTTONUP:
			if (sIni.Mouse)
			{
				mouseDown = (event.type == SDL_MOUSEBUTTONDOWN);
				mouseBtn = event.button.button;

				if (mouseBtn == SDL_BUTTON_LEFT || mouseBtn == SDL_BUTTON_RIGHT)
					sDisplay.OnMouseButton(mouseDown);
			}
			break;

		case SDL_WINDOWEVENT_RESIZED:
			break;

		case SDL_KEYDOWN:
			OnKeyDownEvent(event.key.keysym.sym);
			break;

		case SDL_MOUSEWHEEL:
			if (event.wheel.y == 0)
				continue;

			mouseDown = true;
			mouseBtn = (event.wheel.y < 0 ? SDL_BUTTON_WHEELDOWN : SDL_BUTTON_WHEELUP);
			break;

		case SDL_JOYAXISMOTION:
			break;

		case SDL_JOYBUTTONDOWN:
			break;

		case SDL_TEXTINPUT:
		case SDL_TEXTEDITING:
			OnTextInputEvent(&event);
			break;

		case MAINTHREAD_EXEC_EVENT:
			break;
		}

		switch (event.type)
		{
			case SDL_MOUSEBUTTONDOWN:
			case SDL_MOUSEBUTTONUP:
			case SDL_MOUSEMOTION:
				mouseX = (float) event.button.x;
				mouseY = (float) event.button.y;
				OnMouseEvent(mouseBtn, mouseDown, mouseX, mouseY);
				break;

			case SDL_MOUSEWHEEL:
				OnMouseEvent(mouseBtn, mouseDown, mouseX, mouseY);
				break;
		}
	}
}
Ejemplo n.º 10
0
int main(int argc, char **argv)
{
  aThisApp.start(argc,argv);
  char *fname=(char *)NULL;
  if(aThisApp.argc>1) fname=aThisApp.argv[1];
  if(aThisApp.argc<2) {
    ARequesterFile *ww=new ARequesterFile();
    if(ww) fname=ww->show((char *)"Open file");
    else std::cerr<<"(Didn't get a request window)\n";
    if(ww) delete ww;
    ww=NULL;
  }
  if(!fname) {
    char msg[256];
    sprintf(msg,(char *)"usage: nupac {board filename}",aThisApp.argv[0]);
    ADialogMsg mw((char *)"Error!",msg);
    //return 5;
    return 0;
  }
  char *bname=fname;
  unsigned int t;
  char *temp;
  InitGame();
  for(t=1;t<aThisApp.argc;t++) {
    temp=aThisApp.argv[t];
    if(temp[0]=='-') {
      if(temp[1]=='d') {
        DisplayName=aThisApp.argv[t+1]; t++;  std::cerr<<"Display name is ";
        std::cerr<<DisplayName<<"\n";
      } else
      if(temp[1]=='p') { FOOBAR_PACMOVE=false; } else
      if(temp[1]=='m') { FOOBAR_MONO=1; } else
      if(temp[1]=='s') {
        sscanf(aThisApp.argv[t+1],(char *)"%d",(unsigned int *)&SPEED);
        t++;
        std::cerr<<"New speed is";
        std::cerr<<SPEED<<"\n";
      } else
      std::cerr<<aThisApp.argv[0]<<": bad command option\n";
    }
    else {
      bname=temp;
    }
  }
  std::cerr<<"Initial board is "<<bname<<"\n";
  DoTitle();
  QUITING=false;
  while(!QUITING) {
    std::cerr<<"Looping in main while !QUITING...\n";
    //StartLoading();
    CleanupBitmaps();
    if(bname) ReadBoardFromDisk(bname);
    else boardError=true;
    if(boardError) {
      QUITING=true;
    }
    else {
      ExploreBoard();
      SetupBitmaps();
      if(!QUITING) {
        SetSpriteShapes();
        DrawScreen();
        UpdateScore();  InitRound();
        DIED=true;
        while(DIED) {
          mainloop();
          UpdateScore();  InitRound();
          if(QUITING) DoQuit();
        }
      }
      bname=NextBoard;  boardError=false;
    }
  }
  std::cerr<<"Normal exit\n";
  return 0;
}
Ejemplo n.º 11
0
Archivo: commands.c Proyecto: aosm/X11
/*ARGSUSED*/
void
QuitAction(Widget w, XEvent *event, String *params, Cardinal *num_params)
{
    DoQuit(w, NULL, NULL);
}
Ejemplo n.º 12
0
int testConnect()
//---------------------------------------------------------------------------
// Init socket, get list of mails
//---------------------------------------------------------------------------
{
	SOCKET sc;
	char s[2048],t[256];
	int i;
	

startgetmess:

	//***** Get mailfile
#ifdef _WIN32
	if (WSAStartup(MAKEWORD(1, 1), &Data) != 0) return(DoQuit(FAILED_TO_START_SOCKETS));
#endif

	//***** Create Socket
	printf("Create socket: socket(PF_INET,SOCK_STREAM)\n");
	if ((sc = socket(PF_INET,SOCK_STREAM,0)) == INVALID_SOCKET)
	{
		return(DoQuit(FAILED_TO_OBTAIN_SOCKET_HANDLE));
	}

	//***** Resolve the servers IP
	printf("Resolve IP address for: %s\n",Host);
	struct hostent *adr;
	adr = gethostbyname(Host);
	if (!adr)
	{
		return(DoQuit(FAILED_TO_RESOLVE_HOST));
	}
	
	//***** Connect to server
	SOCKADDR_IN sin;
	sin.sin_port = htons((u_short) Port);
	sin.sin_family = adr->h_addrtype;
	memcpy((char *) &sin.sin_addr, adr->h_addr, adr->h_length);
	char AddrHexa[9];
	sprintf(AddrHexa,"%08lX",* (unsigned long int *) &sin.sin_addr);
	AddrHexa[8]=0;
	printf("Connect socket to: %s\n",AddrHexa);
#ifdef _WIN32
	if (connect(sc,(LPSOCKADDR) &sin,sizeof(sin)))
#else
	if (connect(sc,(const struct sockaddr *) &sin,sizeof(sin))) 
#endif
	{
		printf("Failed to connect !\n");
		return(DoQuit(FAILED_TO_CONNECT));
	}

	//***** Server welcome message
	printf("Connected !\n");
/*
	if ((iRet=Ack(sc))) {
		return(DoQuit(iRet));
	}
*/

	//***** Disconect
	return(DoQuit(0));
}