int main(int argc, char *argv[]) { char *input; /* input filename (program to run) */ progname=argv[0]; input=parse_command_line(argc, argv); /* parse options, get input filename */ init_machine(); /* initialize machine */ load_imem(input); /* load the instructions */ if( interactive ) { printf("pendvm %s -- matt debergalis <*****@*****.**>\n",VERSION); loop(); /* never returns */ } else { int result=step_processor(-1); /* just go on until halt */ if( !result ) return 0; /* all was good */ /* something went wrong - give 'coredump' and exit */ printf("\n"); /* already printed error message */ com_reg(NULL, 0); /* this is wrong... */ display_state(); printf("\n"); return 1; } }
int main(int argc, char *argv[]) { //Manipulate cpu set and create a hardwall cpu_set_t set; tmc_cpus_clear(&set); tmc_cpus_add_cpu(&set,0); tmc_cpus_add_cpu(&set,35); tmc_udn_init(&set); //Initialize init(argc,argv); display_state(); //Create threads int count; for(count=0; count<nthreads; count++) pthread_create(&threads[count],NULL,thread_fn,(void*)(&thread_id[count])); void *retval; for(count=0; count<nthreads; count++) pthread_join(threads[count],&retval); finalize(); }
void KLFDisplayLabel::displayError(const QString& errorMessage, bool labelenabled) { pDisplayError = errorMessage; display_state(Error); // setEnabled(labelenabled); setLabelEnabled(labelenabled); }
int main() { State initial_state; Game game; int i, color, value, column; Card deck[52]; printf( "Freecell Solver\n\n" ); memset( &initial_state, 0, sizeof(initial_state) ); // Populate deck for( i=0, color=0, value=1; i<sizeof(deck)/sizeof(deck[0]); ++i ) { deck[i].value = value; deck[i].color = color; ++value; if( value > 13 ) { value = 1; color = (++color)%Color_Max; } } //Shuffle deck for( i=1000+rand()%1000; i>0; --i ) { int from = rand() % 52; int to = rand() % 52; Card temp; temp = deck[to]; deck[to] = deck[from]; deck[from] = temp; } // Populate initial_state for( i=0, column=0; i<sizeof(deck)/sizeof(deck[0]); ++i ) { push_to_column( &initial_state, &deck[i], column ); column = (++column) % COLUMN_NB; } // DUMP display_state( &initial_state ); game_init( &game, &initial_state ); start_crawling( &game ); return 0; }
void KLFDisplayLabel::display(QImage displayimg, QImage tooltipimage, bool labelenabled) { KLF_DEBUG_BLOCK(KLF_FUNC_NAME) ; pDisplayImage = displayimg; pDisplayTooltip = tooltipimage; display_state(Ok); // setEnabled(labelenabled); setLabelEnabled(labelenabled); }
int main(int argc, char *argv[]) { printf("MM_UDN starting benchmark.....\n"); //Manipulate cpu set and create a hardwall printf("Setting CPUs and UDN...\n"); cpu_set_t set; tmc_cpus_clear(&set); tmc_cpus_add_cpu(&set,0); tmc_cpus_add_cpu(&set,35); tmc_udn_init(&set); //Initialize init(argc,argv); #ifdef __DEBUG__ display_state(); #endif //Create threads printf("Creating worker threads....\n"); int count; for(count=0; count<nthreads; count++) pthread_create(&threads[count],NULL,thread_fn,(void*)(&thread_id[count])); //Start the watchdog thread printf("Creating watchdog thread....\n"); pthread_create(&watchdog_th,NULL,watchdog,NULL); //Wait for the worker threads to join printf("Main thread waiting to join...\n"); void *retval; for(count=0; count<nthreads; count++) pthread_join(threads[count],&retval); finalize(); }
int main(int argc, char *argv[]) { struct termios pts; /* termios settings on port */ struct termios sts; /* termios settings on stdout/in */ struct sigaction sact; /* used to initialize the signal handler */ int opt; strcpy(device, "/dev/ttyUSB0"); while ( (opt = getopt(argc, argv, "h?D:b:d:p:f:s:e:r:")) != -1 ) { switch (opt) { /* help message */ case 'h': usage(); return 0; break; /* set the serial device name */ case 'D': strcpy(device, optarg); break; /* set the baud rate */ case 'b': curr_state.baud_rate = atoi(optarg); break; /* data bits */ case 'd': curr_state.data_bits = optarg[0]; break; /* parity */ case 'p': curr_state.parity = optarg[0]; break; /* setup flow control */ case 'f': curr_state.flow_control = optarg[0]; break; /* stop bits */ case 's': curr_state.stop_bits = optarg[0]; break; /* echo type */ case 'e': curr_state.echo_type = optarg[0]; break; /* NL to CR mapping on output */ case 'r': curr_state.onlcr_mapping = optarg[0]; break; default: break; } /* end switch */ } /* end while */ /* open the device */ pf = open(device, O_RDWR); if (pf < 0) { fprintf(stderr, "\n ERROR: cannot open device %s\n\n", device); exit(1); } /* save old serial port config */ tcgetattr(pf, &pts); memcpy(&pots, &pts, sizeof(pots)); /* setup serial port with new settings */ init_comm(&pts); fprintf(stdout, "\nWelcome to Nanocomsole " VERSION); display_state(); fprintf(stdout, "Press CTRL+T for menu options\n\n"); /* Now deal with the local terminal side */ tcgetattr(STDIN_FILENO, &sts); memcpy(&sots, &sts, sizeof(sots)); /* to be used upon exit */ init_stdin(&sts); tcsetattr(STDIN_FILENO, TCSANOW, &sts); /* set the signal handler to restore the old termios handler */ sact.sa_handler = cleanup_termios; sigaction(SIGHUP, &sact, NULL); sigaction(SIGINT, &sact, NULL); sigaction(SIGPIPE, &sact, NULL); sigaction(SIGTERM, &sact, NULL); /* run the main program loop */ mux_loop(pf); /* unreachable line ?? */ cleanup_termios(0); return 0; }
void KLFDisplayLabel::displayClear() { display_state(Clear); // setEnabled(false); setLabelEnabled(false); }
void* play_game_one(void *data) { int id = (int) data; char buffer[BUFFER_SIZE]; int nwritten; int *player_hand_values = players_hand_values[id], *dealer_hand_values = dealers_hand_values[id]; int *player_hand_suits = players_hand_suits[id], *dealer_hand_suits = dealers_hand_suits[id]; int i; nplayers[id] = 0; ndealers[id] = 0; pthread_mutex_lock(&card_mutex); { for (i = 0; i < 2; ++i) { player_hand_values[nplayers[id]] = card_values[ncard]; player_hand_suits[nplayers[id]] = card_suits[ncard]; ++ncard; ++nplayers[id]; } dealer_hand_values[ndealers[id]] = card_values[ncard]; dealer_hand_suits[ndealers[id]] = card_suits[ncard]; ++ncard; ++ndealers[id]; } pthread_mutex_unlock(&card_mutex); buffer[0] = value_codes[player_hand_values[0]]; buffer[1] = suit_codes[player_hand_suits[0]]; buffer[2] = value_codes[player_hand_values[1]]; buffer[3] = suit_codes[player_hand_suits[1]]; buffer[4] = value_codes[dealer_hand_values[0]]; buffer[5] = suit_codes[dealer_hand_suits[0]]; buffer[6] = 0; if (BUFFER_SIZE != (nwritten = write(clientSockFds[id], buffer, BUFFER_SIZE))) { printf("Error! Couldn't write to client %d. Client will be disconnected.\n", clientSockFds[id]); close(clientSockFds[id]); clientSockFds[id] = 0; return NULL; } /* while player wishes to receive more cards */ while (TRUE) { if (read_with_timeout(clientSockFds[id], buffer, tv_wait_rcv)) { printf("\n"); printf("Player %d Hand: ", clientSockFds[id]); display_state(player_hand_values, player_hand_suits, nplayers[id]); printf("Dealer Hand with player %d: ", clientSockFds[id]); display_state(dealer_hand_values, dealer_hand_suits, ndealers[id]); printf("I received from player %d: %s\n", clientSockFds[id], buffer); if (strcmp(buffer, HIT) == 0) { pthread_mutex_lock(&card_mutex); { player_hand_values[nplayers[id]] = card_values[ncard]; player_hand_suits[nplayers[id]] = card_suits[ncard]; buffer[0] = value_codes[player_hand_values[nplayers[id]]]; buffer[1] = suit_codes[player_hand_suits[nplayers[id]]]; buffer[2] = 0; ++ncard; ++nplayers[id]; } pthread_mutex_unlock(&card_mutex); if (BUFFER_SIZE != (nwritten = write(clientSockFds[id], buffer, BUFFER_SIZE))) { printf("Error! Couldn't write to player %d.\n", clientSockFds[id]); close(clientSockFds[id]); clientSockFds[id] = 0; return NULL; } if (calc_sum(player_hand_values, nplayers[id]) > 21) { printf("Player %d busted. Dealer wins.\n", clientSockFds[id]); close(clientSockFds[id]); clientSockFds[id] = 0; return NULL; } else if (calc_sum(player_hand_values, nplayers[id]) == 21) break; } else if (strcmp(buffer, STAND) == 0) break; else { printf("Player %d didn't respond with a known command. Player will be disconnected.\n", clientSockFds[id]); close(clientSockFds[id]); clientSockFds[id] = 0; return NULL; } } else { printf("Player %d didn't respond on time. Player will be disconnected.\n", clientSockFds[id]); close(clientSockFds[id]); clientSockFds[id] = 0; return NULL; } } return NULL; }
void play_game_all(int nclients) { int id; pthread_t threads[MAX_PLAYERS]; init_cards(); for (id = 0; id < nclients; ++id) pthread_create(&threads[id], NULL, play_game_one, (void*) id); for (id = 0; id < nclients; ++id) pthread_join(threads[id], NULL); for (id = 0; id < MAX_PLAYERS; ++id) { if (clientSockFds[id] > 0) { int i = 0; int nwritten; char buffer[BUFFER_SIZE]; int player_sum, dealer_sum; int *player_hand_values = players_hand_values[id], *dealer_hand_values = dealers_hand_values[id]; int *player_hand_suits = players_hand_suits[id], *dealer_hand_suits = dealers_hand_suits[id]; while (calc_sum(dealer_hand_values, ndealers[id]) < 17) { dealer_hand_values[ndealers[id]] = card_values[ncard]; dealer_hand_suits[ndealers[id]] = card_suits[ncard]; buffer[i++] = value_codes[dealer_hand_values[ndealers[id]]]; buffer[i++] = suit_codes[dealer_hand_suits[ndealers[id]]]; ++ncard; ++ndealers[id]; } buffer[i] = 0; printf("\n"); printf("Player %d Hand: ", clientSockFds[id]); display_state(player_hand_values, player_hand_suits, nplayers[id]); printf("Dealer %d Hand: ", clientSockFds[id]); display_state(dealer_hand_values, dealer_hand_suits, ndealers[id]); if (BUFFER_SIZE != (nwritten = write(clientSockFds[id], buffer, BUFFER_SIZE))) { printf("Error! Couldn't write to player %d.\n", clientSockFds[id]); close(clientSockFds[id]); return; } player_sum = calc_sum(player_hand_values, nplayers[id]); dealer_sum = calc_sum(dealer_hand_values, ndealers[id]); if (dealer_sum > 21) printf("\nDealer busted! Player %d wins!\n", clientSockFds[id]); else if (player_sum == dealer_sum) printf("\nPlayer %d and dealer have the same score. It's a push!\n", clientSockFds[id]); else if (player_sum < dealer_sum) printf("\nDealer has a higher score than player %d. Dealer wins!\n", clientSockFds[id]); else printf("\nPlayer %d has a higher score. Player wins!\n", clientSockFds[id]); } } }