Ejemplo n.º 1
0
Archivo: main.c Proyecto: te-bachi/cgr
int main(int argc, char* argv[]) {
	// If intialising of SDL fails -> quit the program with error code 1
	if (!init_SDL()) {
		quit_program(1);
	}
	
	// If intialising of OpenGL fails -> quit the program with error code 1
	if (!init_OpenGL(default_width, default_height)) {
		quit_program(1);
	}
	
	// Repeat forever
	while(true) {
		// Draw your graphics
		draw_screen();
		
		// Process any ocuring events 
		process_events();
		fflush(stdout);
	}
	
	// You shouldn't get here. Only if someone changes the while condition...
	quit_program(0);
	
	return 0;
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: te-bachi/cgr
void process_events() {
	SDL_Event event;
	
	while (SDL_PollEvent(&event)) {
		
		switch (event.type) {
			case SDL_QUIT:
				quit_program( 0 );
				break;
				
			case SDL_KEYDOWN:
				switch (event.key.keysym.sym) {
					
					case SDLK_ESCAPE:
						quit_program(0);
						break;
						
					case SDLK_F1:
						quit_program(0);
						break;
						
					case SDLK_a:
						if (enableDethTest) {
							enableDethTest = false;
							printf("enable depth test\n");
							glEnable(GL_DEPTH_TEST);
						} else {
							enableDethTest = true;
							printf("disable depth test\n");
							glDisable(GL_DEPTH_TEST); 
						}
						fflush(stdout);
						break;
						
					default:
						break;
				}
				break;
			
			case SDL_VIDEORESIZE:
				init_SDL_Video(event.resize.w, event.resize.h);
				//init_OpenGL(event.resize.w, event.resize.h);
				break;
				
			case SDL_SYSWMEVENT:
				break;
				
			default:
				break;
		}
	}
}
Ejemplo n.º 3
0
Archivo: main.c Proyecto: te-bachi/cgr
bool init_SDL() {
	
	if (SDL_Init(SDL_INIT_VIDEO) < 0 ) {			// First, initialize SDL's video subsystem (video only)
		fprintf(stderr, "Video initialization failed: %s\n", SDL_GetError());
		quit_program(1);						  // Failed, exit
	}
	
	init_SDL_Video(default_width, default_height);
	
	return true;
}
Ejemplo n.º 4
0
void check_pipe(void)
{
   int i;
#if NSIG < 256
   unsigned char sig;
#else
   int sig;
#endif
   const char *func = "check_pipe";

   if (signals_pending[0] < 0) return;

   if( ioctl(signals_pending[0], FIONREAD, &i) != 0 ) {
      msg(LOG_ERR, func, "Can't get the number of pending signals: %m");
      return;
   }
#if NSIG >= 256
   i /= sizeof(int);
#endif

   while( --i >= 0 ) {
      ssize_t ret_val;
      do
      {
         ret_val = read(signals_pending[0], &sig, sizeof(sig));
      } while (ret_val == (ssize_t)-1 && errno == EINTR);
      if (ret_val != (ssize_t)sizeof(sig) ) {
         msg(LOG_ERR, func, "Error retrieving pending signal: %m");
         return;
      }

      if( debug.on ) {
         msg(LOG_DEBUG, func, "Got signal %s", sig_name(sig));
      }

      switch(sig) {
         case SERVER_EXIT_SIG:       child_exit();           break;
         case RECONFIG_HARD_SIG:     hard_reconfig();        break;
         case OLD_RECONFIG_HARD_SIG: hard_reconfig();        break;
         case TERMINATION_SIG:       terminate_program();    break;
         case STATE_DUMP_SIG:        dump_internal_state();  break;
         case CONSISTENCY_CHECK_SIG: user_requested_check(); break;
         case QUIT_SIG:              quit_program();         break;
         default:
            msg(LOG_ERR, func, "unexpected signal: %s in signal pipe", 
               sig_name(sig));
      }
   }
}
Ejemplo n.º 5
0
/************************************
 * Main program 		    *
 ************************************/
int32_t main()
{
       int32_t		    quit = 0,i, correct,number;
       char		    buf[257];
       char		    *langs[]={
	      "US\0","DE\0","SE\0","FR\0","IT\0",
       };

/* Read UAE configuration */
       i = GetUaeConfig( &config );

       while( quit == 0 ) {
	      printf(" UAE-Control v0.1\n\n");
	      printf(" 1) Reset\n");
	      printf(" 2) Debug\n");
	      printf(" 3) Exit Emulator\n");
	      printf(" 4) Change framerate     (Currently : %ld)\n", config.framerate);
	      printf(" 5) Toggle sound         (Currently : %s)\n", config.do_output_sound ? "ON" : "OFF");
	      printf(" 6) Toggle fake joystick (Currently : %s)\n", config.do_fake_joystick ? "ON" : "OFF");
	      printf(" 7) Change language      (Currently : %s)\n", langs[config.keyboard]);
	      printf(" 8) Eject a disk\n");
	      printf(" 9) Insert a disk\n");
	      printf("10) Exit UAE-Control\n\n");
	      correct = 0;
	      while( correct == 0 ) {
		     printf(" Command : ");
		     gets( buf );
		     i = atoi( buf );
		     if ((i > 0) && (i < 11))
		       correct = 1;
	      }
	      switch( i ) {
	       case 1:
		     HardReset();
		     break;
	       case 2:
		     DebugFunc();
		     break;
	       case 3:
		     ExitEmu();
		     break;
	       case 4:
		     printf(" Enter new framerate (1-20) :");
		     gets( buf );
		     number = atoi( buf );
		     if (SetFrameRate (number))
			    GetUaeConfig(&config);
		     else
			    printf(" Illegal value, not changed.\n");
		     break;
	       case 5:
		     if (config.do_output_sound)
		       DisableSound();
		     else
		       EnableSound();
		     GetUaeConfig( &config );
		     break;
	       case 6:
		     if (config.do_fake_joystick)
		       DisableJoystick();
		     else
		       EnableJoystick();
		     GetUaeConfig( &config );
		     break;
	       case 7:
		     printf(" 1 = US, 2 = DE, 3 = SE, 4 = FR, 5 = IT\n");
		     printf(" What will it be : ");
		     gets( buf );
		     number = atoi( buf );
		     if ((number >= 1) && (number <= 5)) {
			    ChangeLanguage( number-1 );
			    GetUaeConfig( &config );
		     } else {
			    printf(" Illegal value, not changed.\n");
		     }
		     break;
	       case 8:
		     print_drive_status();
		     printf(" Eject which drive (1-4): ");
		     gets( buf );
		     number = atoi( buf );
		     if ((number >= 1) && (number <=4 )) {
			    EjectDisk( number-1 );
			    GetUaeConfig( &config );
		     } else {
			    printf(" Illegal drive, not changed.\n");
		     }
		     break;
	       case 9:
		     print_drive_status();
		     printf(" Enter disk to drive (1-4): ");
		     gets( buf );
		     number = atoi( buf );
		     if ((number >= 1) && (number <= 4)) {
			    printf("Name of diskfile :");
			    gets( buf );
			    InsertDisk( (UBYTE *)&buf, number - 1 );
			    GetUaeConfig( &config );
		     } else {
			    printf(" Illegal drive, not changed.\n");
		     }
		     break;
	       case 10:
		     quit = 1;
		     break;
	      }
       }
       quit_program(0, "");
       return(0);
}
Ejemplo n.º 6
0
void main(int argc, char **argv)
{
	char *stop;
	int	opts;
	char *debugstr;
	int	debuglvl;
	int	i;
	int	modemstate;
	int	modeminits;

	breaklist_init();

	progbasename = argv[0];

	if ((stop = rindex(argv[0], '/'))) progbasename = ++stop;

		/* Die Argumente des Programms einlesen und den Debuglevel	*/
		/* setzen.																	*/

	debugstr		= NULL;
	isdnttyname	= NULL;

	while ((opts = getopt_long(argc, argv, "vhx:d:", arguments, (int *)0)) != EOF)
	{
		switch (opts)
		{
			case 'x':
				debugstr = optarg;
				break;

			case 'd':
				isdnttyname = optarg;
				break;

			case 'v':
				show_usage(200, 0);
				break;

			case 'h':
			default:
				show_usage(200, 1);
				break;
		}
	}

	if (debugstr)
	{
		if (strcasecmp(debugstr, "FULL") != 0)
		{
			debuglvl = LOG_E;

			for (i = 0; i < strlen(debugstr); i++)
			{
				switch (debugstr[i])
				{
					case 'W':
					case 'w':
						debuglvl |= LOG_W;
						break;
					
					case 'I':
						debuglvl |= LOG_I;
						break;
					
					case 'A':
						debuglvl |= LOG_A;
						break;
					
					case 'D':
						debuglvl |= LOG_D;
						break;
				}
			}
		}
		else debuglvl = LOG_X;

		log_set_debuglevel(debuglvl);
	}

	umask(xstrtoo(VBOX_ROOT_UMASK, 0));

		/* Pfadangaben vom Devicenamen abschneiden und überprüfen ob	*/
		/* das Device vom Benutzer gelesen und beschrieben werden		*/
		/* kann (eigentlich nicht nötig, da nur unter Rootrechten ge-	*/
		/* startet werden kann.														*/

	if (isdnttyname)
	{
		if ((stop = rindex(isdnttyname, '/'))) isdnttyname = ++stop;

		printstring(savettydname, "%s"     , isdnttyname);
		printstring(temppathname, "/dev/%s", isdnttyname);
		
		if (access(temppathname, F_OK|R_OK|W_OK) != 0)
		{
			fprintf(stderr, "\n%s: error: \"%s\" doesn't exist or is not accessible!\n\n", progbasename, temppathname);

			quit_program(100);
		}
	}
	else
	{
		fprintf(stderr, "\n%s: error: isdn tty name is required!\n", progbasename);

		show_usage(100, 1);
	}

		/* Prüfen ob das Programm unter Rootrechten gestartet wurde. Die	*/
		/* Rechte werden später auf die des jeweiligen Benutzers geän-		*/
		/* dert, zum Start sind aber Rootrechte nötig.							*/

	if (getuid() != 0)
	{
		fprintf(stderr, "\n%s: error: need root privilegs to start!\n\n", progbasename);

		quit_program(100);
	}

		/* Jetzt wird der Log geöffnet. Der Name des aktuellen Devices	*/
		/* wird an das Ende angehängt.											*/

	printstring(temppathname, "%s/vboxgetty-%s.log", LOGDIR, isdnttyname);

	log_open(temppathname);

		/* Tcl-Interpreter starten. Für die momentanen Funktionen wird	*/
		/* Version 8 oder höher benötigt.										*/

	if (scr_create_interpreter() == -1)
	{
		log_line(LOG_E, "Can't create/initialize the tcl interpreter!\n");
		
		quit_program(100);
	}

	log_line(LOG_I, "Running vbox version %s (with tcl version %s).\n", VERSION, scr_tcl_version());

		/* Konfiguration des getty's abarbeiten. Zuerst wird die globale,	*/
		/* dann die des jeweiligen tty's eingelesen.								*/

	if (vboxgettyrc_parse(isdnttyname) == -1)
	{
		log_line(LOG_E, "Unable to read/parse configuration!\n");
	
		quit_program(100);
	}

		/* Modem Device öffnen und die interne Initialisierung	*/
		/* ausführen (nicht der normale Modeminit).					*/

	printstring(temppathname, "/dev/%s", isdnttyname);

	log_line(LOG_D, "Opening modem device \"%s\" (38400, CTS/RTS)...\n", temppathname);

	if (vboxmodem_open(&vboxmodem, temppathname) == -1)
	{
		log_line(LOG_E, "Can't open/setup modem device (%s).\n", vboxmodem_error());

		quit_program(100);
	}

		/* Lock- und PID-Datei für den getty und das entsprechende	*/
		/* Device erzeugen.														*/

	printstring(temppathname, "%s/LCK..%s", LOCKDIR, isdnttyname);
	
	if (lock_create(temppathname) == -1) quit_program(100);

	printstring(temppathname, "%s/vboxgetty-%s.pid", PIDDIR, isdnttyname);

	pid_create(temppathname);

		/* Signalhändler installieren. Alle möglichen Signale werden	*/
		/* auf quit_program() umgelenkt.											*/

	signal(SIGINT , quit_program);
	signal(SIGTERM, quit_program);
	signal(SIGHUP , quit_program);

		/* Hauptloop: Der Loop wird nur verlassen, wenn während der	*/
		/* Abarbeitung ein Fehler aufgetreten ist. Das Programm be-	*/
		/* endet sich danach!													*/
	
	modemstate = VBOXMODEM_STAT_INIT;
	modeminits = 0;
	
	while (modemstate != VBOXMODEM_STAT_EXIT)
	{
		switch (modemstate)
		{
			case VBOXMODEM_STAT_INIT:

				if (run_modem_init() == -1)
				{
					if ((i = (int)xstrtol(rc_get_entry(rc_getty_c, "badinitsexit"), 10)) > 0)
					{
						modeminits++;
						
						if (modeminits >= i)
						{
							modemstate = VBOXMODEM_STAT_EXIT;
							modeminits = 0;
							
							log_line(LOG_E, "Exit program while bad init limit are reached.\n");
						}
						else log_line(LOG_W, "Bad initialization - Program will exist on %d trys!\n", (i - modeminits));
					}
				}
				else
				{
					modemstate = VBOXMODEM_STAT_WAIT;
					modeminits = 0;
				}
				break;

			case VBOXMODEM_STAT_WAIT:
				
				modem_flush(&vboxmodem, 0);

				if (modem_wait(&vboxmodem) == 0)
				{
					modemstate = VBOXMODEM_STAT_RING;
					modeminits = 0;
				}
				else modemstate = VBOXMODEM_STAT_TEST;
				
				break;

			case VBOXMODEM_STAT_TEST:
			
				log_line(LOG_D, "Checking if modem is still alive...\n");
				
				if (modem_command(&vboxmodem, "AT", "OK") > 0)
				{
					modemstate = VBOXMODEM_STAT_WAIT;
					modeminits = 0;
				}
				else modemstate = VBOXMODEM_STAT_INIT;
				
				break;
				
			case VBOXMODEM_STAT_RING:
			
				modem_set_nocarrier(&vboxmodem, 0);
				process_incoming_call();
				modem_hangup(&vboxmodem);

				if (set_process_permissions(0, 0, xstrtoo(VBOX_ROOT_UMASK, 0)) != 0)
					modemstate = VBOXMODEM_STAT_EXIT;
				else
 					modemstate = VBOXMODEM_STAT_INIT;
				
				break;

			default:

				log_line(LOG_E, "Unknown modem status %d!\n", modemstate);
				
				modemstate = VBOXMODEM_STAT_INIT;
				
				break;
		}
	}

	quit_program(0);
}
Ejemplo n.º 7
0
/**
* Handler to check user input, and see if it matches any avaible commands.
* Will call the right methods for executing commands
*/
void handle_keyboard(sp_session *session, struct play_queue* node)
{
    char buffer[1024];

    fgets(buffer, sizeof(buffer), stdin);
    strtok(buffer, "\n");

    if (strcmp(buffer, "search") == 0) {
        player_reset();
        run_search(session);

    } else if ((strcmp(buffer, "list") == 0) || (strcmp(buffer, "ls") == 0 )) {
        print_playlists(session, pc);

    } else if(strcmp(buffer, "qshuffle") == 0) {
        queue_shuffle();

    } else if (strcmp(buffer, "queueadd") == 0) {
        sp_playlist* pl = parse_play_command(session, buffer, node);
        printf("done finding playlist \n");

        if(pl != NULL) printf("queueadd: %s\n", sp_playlist_name(pl));
        else {
            printf("no playlist\n");
            return;
        }

        int index;
        char input[10];
        fputs("Song number: ", stdout);
        fgets(input, sizeof(input) - 1, stdin);
        sscanf(input, "%d", &index);
        if(sp_playlist_num_tracks(pl) < index) {
            printf("index too high!\n");
            return;
        }

        sp_track* track = pl_find_song_by_id(pl, index);
        if(track != NULL) queue_add_first(track);

    } else if (strcmp(buffer, "list songs") == 0 ) {
        //release all threads
        sp_playlist* pl = playlist_find_by_num(session, pc);
        print_tracks_in_playlist(session, pl);

    } else if (strcmp(buffer, "help") == 0) {
        print_commands();

    } else if (strcmp(buffer, "queue") == 0) {
        queue_print(node);

    } else if (strcmp(buffer, "shuffle mode") == 0) {
        print_commands();

    } else if(strncmp(buffer, "play", strlen("play")) == 0) {
        player_reset();
        sp_playlist* pl = parse_play_command(session, buffer, node);
        if(pl!=NULL) queue_add_playlist(pl);
        else {
            printf("ERROR playlist is null\n");
            return;
        }
        queue_go_next(session);


    } else if(strncmp(buffer, "shuffle", strlen("shuffle")) == 0) {
        player_reset();
        shuffle_mode = TRUE;
        sp_playlist* pl = parse_play_command(session, buffer, node);
        if(pl!=NULL) queue_add_playlist(pl);
        else {
            printf("ERROR playlist is null\n");
            return;
        }
        queue_shuffle();
        queue_go_next(session);

    } else if(strcmp(buffer, "pause") == 0 || strcmp(buffer, "p") == 0) {
        player_pause(session);
        play_info();

    } else if (strcmp(buffer, "next") == 0 || strcmp(buffer, "n") == 0) {
        end_track(session);

    } else if (strcmp(buffer, "stop") == 0) {

    } else if (strcmp(buffer, "info") == 0) {
        play_info();
    } else if (strcmp(buffer, "quit") == 0) {
        queue_free();
        quit_program(session);
    } else {
        printf("Unkown command!\n");
    }
    printf("> ");
    fflush(stdout);

    return;
}
Ejemplo n.º 8
0
/*****************************************
* Main program                           *
*****************************************/
int main()
{
    int quit = 0, i;
    struct IntuiMessage *msg;
    struct Gadget *button;
    struct StringInfo *strinfo;
    char buf[257];
    UWORD koodi, msgID;
    ULONG classi, number;
    APTR address;
    ULONG CycleTags[3];

    CycleTags[0] = GTCY_Active;
    CycleTags[1] = (ULONG) & number;
    CycleTags[2] = TAG_DONE;

    /* Read UAE configuration */
    i = GetUaeConfig(&config);
    i = setup_window();
    if (i == 0) {
	quit_program(1, "Cannot setup a window!");
	return 1;
    }
    while (quit == 0) {
	WaitPort(window->UserPort);
	while (msg = (struct IntuiMessage *) GT_GetIMsg(window->UserPort)) {
	    classi = msg->Class;
	    koodi = msg->Code;
	    address = msg->IAddress;
	    if (classi == IDCMP_GADGETUP) {
		msgID = ((struct Gadget *) msg->IAddress)->GadgetID;
		button = (struct Gadget *) msg->IAddress;
		if (button->SpecialInfo) {
		    strinfo = (struct StringInfo *) button->SpecialInfo;
		}
	    } else
		msgID = msg->Code;

	    GT_ReplyIMsg((struct IntuiMessage *) msg);
	    switch (classi) {
	    case IDCMP_CLOSEWINDOW:
		quit = 1;
		break;
	    case IDCMP_GADGETUP:
		switch (msgID) {
		case GAD_EXITEMU:
		    ExitEmu();
		    break;
		case GAD_EJECT_DF0:
		    EjectDisk(0);
		    Delay(30);
		    GetUaeConfig(&config);
		    print_drive_status();
		    break;
		case GAD_EJECT_DF1:
		    EjectDisk(1);
		    Delay(30);
		    GetUaeConfig(&config);
		    print_drive_status();
		    break;
		case GAD_EJECT_DF2:
		    EjectDisk(2);
		    Delay(30);
		    GetUaeConfig(&config);
		    print_drive_status();
		    break;
		case GAD_EJECT_DF3:
		    EjectDisk(3);
		    Delay(30);
		    GetUaeConfig(&config);
		    print_drive_status();
		    break;
		case GAD_SOUND:
		    if (config.do_output_sound)
			DisableSound();
		    else
			EnableSound();

		    Delay(30);
		    GetUaeConfig(&config);
		    break;
		case GAD_JOYSTICK:
		    if (config.do_fake_joystick)
			DisableJoystick();
		    else
			EnableJoystick();

		    Delay(30);
		    GetUaeConfig(&config);
		    break;
		case GAD_FRAMERATE:
		    SetFrameRate(strinfo->LongInt);
		    Delay(30);
		    GetUaeConfig(&config);
		    break;
		case GAD_INSERT_DF0:
		    strcpy(buf, config.df0_name);
		    if (get_string(buf, 255)) {
			InsertDisk((UBYTE *) buf, 0);
			Delay(30);
			GetUaeConfig(&config);
			print_drive_status();
		    }
		    break;
		case GAD_INSERT_DF1:
		    strcpy(buf, config.df1_name);
		    if (get_string(buf, 255)) {
			InsertDisk((UBYTE *) buf, 1);
			Delay(30);
			GetUaeConfig(&config);
			print_drive_status();
		    }
		    break;
		case GAD_INSERT_DF2:
		    strcpy(buf, config.df2_name);
		    if (get_string(buf, 255)) {
			InsertDisk((UBYTE *) buf, 2);
			Delay(30);
			GetUaeConfig(&config);
			print_drive_status();
		    }
		    break;
		case GAD_INSERT_DF3:
		    strcpy(buf, config.df3_name);
		    if (get_string(buf, 255)) {
			InsertDisk((UBYTE *) buf, 3);
			Delay(30);
			GetUaeConfig(&config);
			print_drive_status();
		    }
		    break;
		case GAD_LANGUAGE:
		    number = config.keyboard;
		    number++;
		    if (number == 5)
			number = 0;
		    ChangeLanguage(number);
		    Delay(30);
		    GetUaeConfig(&config);
		    break;
		case GAD_RESET:
		    ColdReboot();
		    break;
		case GAD_DEBUG:
		    DebugFunc();
		    break;
		default:
		    break;
		}
		break;
	    default:
		break;
	    }
	}
    }
    quit_program(0, "");
    return (0);
}