コード例 #1
0
ファイル: testmock.c プロジェクト: bronson/io
static void process_args(io_poller *poller, int argc, char **argv)
{
    char buf[256], *cp;
    int optidx, i, c;

	optidx = 0;
	static struct option longopts[] = {
		// name, has_arg (1=reqd,2=opt), flag, val
		{"mock", 1, 0, 'm'},
		{"client", 1, 0, 'c'},
		{"server", 1, 0, 's'},
		{0, 0, 0, 0},
	};

	// dynamically create the option string from the long
	// options.  Why oh why doesn't glibc do this for us???
	cp = buf;
	for(i=0; longopts[i].name; i++) {
		if(!longopts[i].flag) {
			*cp++ = longopts[i].val;
			if(longopts[i].has_arg > 0) *cp++ = ':';
			if(longopts[i].has_arg > 1) *cp++ = ':';
		}
	}
	*cp++ = '\0';

	for(;;) {
		c = getopt_long(argc, argv, buf, longopts, &optidx);
		if(c == -1) break;
		
		switch(c) {
        case 'c':
        	init_poller(poller, IO_POLLER_ANY);
        	initiate_connection(poller, optarg);
            break;

		case 'm':
			init_poller(poller, IO_POLLER_MOCK);
			prepare_mock_test(poller, optarg);
			break;

		case 's':
			init_poller(poller, IO_POLLER_ANY);
			create_listener(poller, optarg);
			break;
			
		case '?':
			// getopt_long already printed the error message
			exit(1);
		}
	}
}
コード例 #2
0
ファイル: tvmemul.c プロジェクト: BrickBot/leJOS
void run(void)
{
  #if DEBUG_RUNS
  int count = 0;
  #endif

  init_poller();
  // Initialize binary image state
  initialize_binary();

  // Initialize memory
  {
    TWOBYTES size;

    memory_init ();
#if SEGMENTED_HEAP
    size = EXTRA_MEMORY_SIZE;
    region = (byte *) malloc (size * sizeof (TWOBYTES));
    memory_add_region (region, region + size * sizeof (TWOBYTES));
#endif
    size = MEMORY_SIZE;
    region = (byte *) malloc (size * sizeof (TWOBYTES));
    memory_add_region (region, region + size * sizeof (TWOBYTES));
  }

  // Initialize exceptions
  init_exceptions();
  // Create the boot thread (bootThread is a special global)
  bootThread = (Thread *) new_object_for_class (JAVA_LANG_THREAD);
  
  #if DEBUG_THREADS
  printf ("Created bootThread: %d. Initializing...\n", (int) bootThread);
  #endif
  
  #if DEBUG_RUNS
  for (count = 0; count < 100; count++)
  {
  #endif // DEBUG_RUNS

  #if DEBUG_RCX_MEMORY
  {
    TWOBYTES numNodes, biggest, freeMem;	
    scan_memory (&numNodes, &biggest, &freeMem);
    printf ("nodes = %d\n", (int) numNodes);
    printf ("biggest = %d\n", (int) biggest);
    printf ("freeMem = %d\n", (int) freeMem);
  }
  #endif

  init_threads();
  if (!init_thread (bootThread))
  {
    printf ("Unable to initialize threading module.\n");
    exit (1);	  
  }
  // Execute the bytecode interpreter
  set_program_number (0);
  #if DEBUG_STARTUP
  printf ("Engine starting.\n");
  #endif
  engine();
  // Engine returns when all non-daemon threads are dead
  #if DEBUG_STARTUP
  printf ("Engine finished.\n");
  #endif

  #if DEBUG_RUNS
  }
  #endif // DEBUG_RUNS
}