void argv_check(int argc,char **argv){ if(argc<2){ help_print(); exit(EXIT_FAILURE); } int res,q_time=0; while((res = getopt(argc, argv, "q:fk"))!=-1){ switch (res){ case 'q': if(optarg == NULL){ help_print(); exit(EXIT_FAILURE); } ++q_time; memcpy(str_to_trans,optarg,strlen(optarg)+1);break; case 'f': simple_flag = 0;break; case 'k': ++q_time; keep_alive = 1;break; default: help_print(); exit(EXIT_FAILURE); } } if(q_time==0){ help_print(); exit(EXIT_FAILURE); } }
c_help() { register struct ww *w; if ((w = openiwin(wwnrow - 3, "Help")) == 0) { error("Can't open help window: %s.", wwerror()); return; } wwprintf(w, "The escape character is %c.\n", escapec); wwprintf(w, "(# represents one of the digits from 1 to 9.)\n\n"); if (help_print(w, "Short commands", help_shortcmd) >= 0) (void) help_print(w, "Long commands", help_longcmd); closeiwin(w); }
int main(int argc, char **argv) { const struct pppoat_module *m; const struct pppoat_if_module *im; void *m_data; void *im_data; int rd[2]; int wr[2]; int rc; pppoat_log_init(PPPOAT_DEBUG); if (argc > 1 && strcmp(argv[1], "--help") == 0) { help_print(stdout, argv[0]); exit(0); } if (argc > 1 && strcmp(argv[1], "--list") == 0) { module_list_print(stdout); exit(0); } im = if_module_tbl[0]; PPPOAT_ASSERT(im != NULL); m = module_find("udp"); PPPOAT_ASSERT(m != NULL); /* init modules */ rc = im->im_init(argc, argv, &im_data); PPPOAT_ASSERT_INFO(rc == 0, "rc=%d", rc); rc = m->m_init(argc, argv, &m_data); PPPOAT_ASSERT_INFO(rc == 0, "rc=%d", rc); /* create pipes for communication with pppd */ rc = pipe(rd); PPPOAT_ASSERT(rc == 0); rc = pipe(wr); PPPOAT_ASSERT(rc == 0); /* exec pppd */ rc = im->im_run(wr[0], rd[1], im_data); PPPOAT_ASSERT_INFO(rc == 0, "rc=%d", rc); close(rd[1]); close(wr[0]); /* run appropriate module's function */ rc = m->m_run(rd[0], wr[1], 0 /* XXX */, m_data); pppoat_error("main", "rc=%d", rc); /* finalisation */ im->im_stop(im_data); im->im_fini(im_data); m->m_fini(m_data); close(rd[0]); close(wr[1]); pppoat_log_fini(); return 0; }
int main(int argc, char *argv[]) { if (get_options(argc, argv) < 0) { help_print(); exit(1); } fprintf(stdout, "a %d, b %d, c %d\n", a, b, c); return 0; }
/** * Main entry point. * * @param argc The argument count. * @param argv The argument vector. * @return The exit code. */ int main(int argc, char *argv[]) { if (argc == 1) { printf("\nThis program needs some arguments ... \n Try add_list -h \n\n"); } int option = 0; int start = -1; int end = 0; // Handle command line arguments. while ((option = getopt(argc, argv, "hvs:e:")) != -1) { switch (option) { case 's': start = atoi(optarg); break; case 'e': end = atoi(optarg); break; case 'v': version_print(); exit(EXIT_FAILURE); case 'h': help_print(); exit(EXIT_FAILURE); default: usage_print(); exit(EXIT_FAILURE); } } // Validate our input. validate_input(start, end); // Create an arrays for threading. int threadCount = find_number_of_threads(start, end); ThreadData data[threadCount]; pthread_t threadIds[threadCount]; int i = 0; // Spawn threads. for (i = 0; i < threadCount; i++) { data[i].start = start + (i * CHUNK_SIZE); data[i].stop = data[i].start + CHUNK_SIZE - 1; data[i].result = 0; // If we've exceeded the end amount or reached our maximum threads then set the stop to the actual end. if ((data[i].stop > end) || (data[i].stop < end && i + 1 == threadCount)) { data[i].stop = end; } //// NOTE: Uncomment to view what ranges each thread is responsible for. //printf("%d: %d to %d\n", i + 1, data[i].start, data[i].stop); if (pthread_create(&threadIds[i], NULL, &gaussian_add, (void *)&data[i]) != 0) { printf("Could not create thread #%d.", i); } } // Wait for the threads to finish. unsigned long long sum = 0; for (i = 0; i < threadCount; i++) { if (pthread_join(threadIds[i], NULL) != 0) { printf("Could not join thread #%d\n", i + 1); } sum += data[i].result; } // Inform the user of the results and of the short cut. summary_print(threadCount, sum, start, end); return 0; }
int main(int argc, char* argv[]) { struct arguments arguments; struct board board; char buffer[256]; int format; char input; char* message; int status; // Game status. struct termios term_settings; int valid; // Parse arguments. message = arguments_parse(&arguments, argc, argv); if (message) { usage_print(message); } // Apply arguments. valid = 1; // Hack; overload to determine whether to play or quit. if (arguments.flags & ARGUMENTS_VERSION) { printf("%s\n", VERSION); valid = 0; } if (arguments.flags & ARGUMENTS_LEGAL) { printf("%s\n", legal); valid = 0; } if (arguments.flags & ARGUMENTS_HELP) { usage_print(NULL); } if (!valid) { exit(EXIT_SUCCESS); } if (arguments.flags & ARGUMENTS_MODE) { if (arguments.mode == mode_format) { setup_signal_handlers(); enter_alternate_buffer(); enter_format_mode(&term_settings); format = 1; } else if (arguments.mode == mode_plain) { format = 0; } } else if (isatty(STDOUT_FILENO) && isatty(STDIN_FILENO)) { setup_signal_handlers(); enter_alternate_buffer(); enter_format_mode(&term_settings); format = 1; } if (arguments.flags & ARGUMENTS_SEED) { srand(arguments.seed); } else { srand(time(NULL)); } // Set up the board. board_init(&board); if (!format) { fputs(legal, stdout); } // Play the game. play: valid = 1; while (!(status = board_done(&board))) { // Set up screen for next move. // Sorry about this ugly call. screen_print(&board, valid ? (format ? "\n\n" : "") : "\nInvalid move.\n", format); // Get the player's move. input = yoink(format); // Process player's move. if (input == 'w' || input == 'k') { valid = board_move_up(&board); } else if (input == 's' || input == 'j') { valid = board_move_down(&board); } else if (input == 'a' || input == 'h') { valid = board_move_left(&board); } else if (input == 'd' || input == 'l') { valid = board_move_right(&board); } else if (input == 'n') { // Start a new game (or not) based on user input. printf("Start a new game? [y/N] "); input = yoink(format); if (input == 'y' || input == 'Y') { board_reset(&board); } continue; } else if (input == '?') { help_print(); if (format) { printf("\nPress any key to continue."); input = yoink(format); } continue; } else { valid = 0; } // End player's move. if (valid) { board_plop(&board); } } // Print the final board. snprintf(buffer, sizeof(buffer), "\nGame over, you %s!\n\nPlay again? [y/n]\n", (status < 0) ? "LOSE" : "WIN"); screen_print(&board, buffer, format); // Check for new game. while ((input = yoink(format)) != 'y' && input != 'Y' && input != 'n' && input != 'N') { screen_print(&board, buffer, format); } if (input == 'y' || input == 'Y') { board_reset(&board); goto play; } // Restore the terminal. if (format) { restore_mode(); leave_alternate_buffer(); } // Free the board. board_free(&board); // Return success. return EXIT_SUCCESS; }