void DefaultRenderFrontend::PrintHelpScreens() { #ifdef GET_KEY_EXISTS char c; int n, x, ok; Print_Usage(-1); for (n = 0; ; ) { BannerPrintf("\n"); BannerPrintf("[ Press 0 for general help, 1 to %d for help screen. Press 'q' to quit. ]", MAX_HELP_PAGE); do { ok = false; GET_KEY(x); c = (char)x; if((c >= '0') && (c <= '0' + MAX_HELP_PAGE)) { ok = true; n = (int)c - (int)'0'; } else if((c == 'q') || (c == 'Q')) ok = true; } while(!ok); BannerPrintf("\n"); if((c == 'q') || (c == 'Q')) break; Print_Usage(n); } #else int n; for (n = -1; n <= MAX_HELP_PAGE; n++) PrintUsage(n); #endif }
void Parse_Parameters(int argc, char **argv) { int currParam; for(currParam=0;currParam<argc;currParam++) { if ( strcmp(argv[currParam],"-rand") == 0 ) randSeed = atoi(argv[currParam+1]); if ( strcmp(argv[currParam],"-null") == 0 ) showGraphics = false; if ( strcmp(argv[currParam],"-h") == 0 || strcmp(argv[currParam],"--help") == 0 ) Print_Usage(); if ( strcmp(argv[currParam],"-cscript") == 0 ) captureScript = true; } }
int main( int argc, char **argv ) { int i; // Process command line options i = 1; while( i != argc ) { if( !strcmp( argv[i], "-h" ) ) { // Help Print_Usage(); } else if( !strcmp( argv[i], "-p" ) ) { // Print results print = true; } else if( !strcmp( argv[i], "-n" ) ) { // Number of steps i++; nsteps = atoi( argv[i] ); nsteps = nsteps <= 0 ? 1 : nsteps; } else if( !strcmp( argv[i], "-a" ) ) { // Angular velocity i++; avel = atof( argv[i] ); avel = avel <= 0.0 ? 1.0 : avel; } else { break; } i++; } // Initialize the scenario Initialize_Scene(); // Run the steps Do_Steps(); return 0; }
/* || Standard main */ int main( int argc, char *argv[] ) { HETB *hetb; FETB *fetb; char *i_filename; int i_faketape = FALSE; SInt32 rc; SInt32 fileno; SInt32 i; U32 uminsz; U32 umaxsz; U32 ubytes; U32 cminsz; U32 cmaxsz; U32 cbytes; U32 totblocks; U64 totubytes; U64 totcbytes; U32 opts = 0; SInt32 lResidue = max_bytes_dsply; /* amount of space left to print */ char *pgm; INITIALIZE_UTILITY( UTILITY_NAME, "Hercules AWS, HET and FakeTape tape map program", &pgm ); #define O_ALL 0xC0 #define O_FILES 0X80 #define O_LABELS 0X40 #define O_DATASETS 0X20 #define O_TAPEMAP_OUTPUT 0x10 #define O_TAPEMAP_INVOKED 0x08 #define O_SLANAL_OUT 0x04 if (! (opts & O_TAPEMAP_INVOKED) ) { opts = O_ALL; while( TRUE ) { rc = getopt( argc, argv, "ab:dfhlst" ); if( rc == -1 ) break; switch( rc ) { case 'a': opts = O_ALL; break; case 'b': max_bytes_dsply = atoi( optarg ); if ( max_bytes_dsply < 256 ) max_bytes_dsply = 256; else { int i; i = max_bytes_dsply % 4; max_bytes_dsply += (4-i); } opts = O_SLANAL_OUT; break; case 'd': opts = O_DATASETS; break; case 'f': opts = O_FILES; break; case 'h': Print_Usage( pgm ); return 1; case 'l': opts = O_LABELS; break; case 's': opts = O_SLANAL_OUT; break; case 't': opts = O_TAPEMAP_OUTPUT; break; default: Print_Usage( pgm ); return 1; } } } // end if (! (opts & O_TAPEMAP_INVOKED) ) argc -= optind; if( argc != 1 ) { Print_Usage( pgm ); exit( 1 ); } if( opts & O_ALL ) { printf( "%s", sep ); printf( "%-20.20s: %s\n", "Filename", argv[ optind ] ); } i_filename = argv[ optind ]; if ( ( rc = (int)strlen( i_filename ) ) > 4 && ( rc = strcasecmp( &i_filename[rc-4], ".fkt" ) ) == 0 ) { i_faketape = TRUE; } if ( i_faketape ) rc = fet_open( &fetb, i_filename, FETOPEN_READONLY ); else rc = het_open( &hetb, i_filename, HETOPEN_READONLY ); if( rc < 0 ) { if ( i_faketape ) { printf( "fet_open() returned %d\n", (int)rc ); fet_close( &fetb ); } else { printf( "het_open() returned %d\n", (int)rc ); het_close( &hetb ); } exit( 1 ); } BLANK_OUT ( gStdLblBuffer, sizeof ( gStdLblBuffer ) ); fileno = 0; gBlkCount = 0; uminsz = 0; umaxsz = 0; ubytes = 0; cminsz = 0; cmaxsz = 0; cbytes = 0; totblocks = 0; totubytes = 0; totcbytes = 0; while( TRUE ) { #ifdef EXTERNALGUI if( extgui ) { off_t curpos; /* Report progress every nnnK */ if ( i_faketape ) curpos = ftell( fetb->fh ); else curpos = ftell( hetb->fh ); if( ( curpos & PROGRESS_MASK ) != ( prevpos & PROGRESS_MASK ) ) { prevpos = curpos; EXTGUIMSG( "IPOS=%"PRId64"\n", (U64)curpos ); } } #endif /*EXTERNALGUI*/ if ( i_faketape) { rc = fet_read( fetb, gBuffer ); } else rc = het_read( hetb, gBuffer ); if( rc == HETE_EOT ) // FETE and HETE enums are the same { if( opts & O_TAPEMAP_OUTPUT ) { printf ("End of tape.\n"); } break; } if( rc == HETE_TAPEMARK ) { fileno += 1; lResidue = max_bytes_dsply; if( opts & O_TAPEMAP_OUTPUT ) { printf ("File %d: Blocks=%d, block size min=%d, max=%d\n", (int)fileno, (int)gBlkCount, (int)uminsz, (int)umaxsz ); } if( opts & O_FILES ) { printf ( "%s", sep ); printf ( "%-20.20s: %d\n", "File #", (int)fileno ); printf ( "%-20.20s: %d\n", "Blocks", (int)gBlkCount ); printf ( "%-20.20s: %d\n", "Min Blocksize", (int)uminsz ); printf ( "%-20.20s: %d\n", "Max Blocksize", (int)umaxsz ); if ( !i_faketape ) { printf ( "%-20.20s: %d\n", "Uncompressed bytes", (int)ubytes ); printf ( "%-20.20s: %d\n", "Min Blocksize-Comp", (int)cminsz ); printf ( "%-20.20s: %d\n", "Max Blocksize-Comp", (int)cmaxsz ); printf ( "%-20.20s: %d\n", "Compressed bytes", (int)cbytes ); } } totblocks += gBlkCount; totubytes += ubytes; totcbytes += cbytes; gPrevBlkCnt = gBlkCount; gBlkCount = 0; uminsz = 0; umaxsz = 0; ubytes = 0; cminsz = 0; cmaxsz = 0; cbytes = 0; continue; } if( rc < 0 ) { if ( i_faketape ) printf ( "fet_read() returned %d\n", (int)rc ); else printf ( "het_read() returned %d\n", (int)rc ); break; } gBlkCount += 1; if ( !i_faketape ) { ubytes += hetb->ublksize; cbytes += hetb->cblksize; if( uminsz == 0 || hetb->ublksize < uminsz ) uminsz = hetb->ublksize; if( hetb->ublksize > umaxsz ) umaxsz = hetb->ublksize; if( cminsz == 0 || hetb->cblksize < cminsz ) cminsz = hetb->cblksize; if( hetb->cblksize > cmaxsz ) cmaxsz = hetb->cblksize; } if ( rc >= 80 ) { for (i=0; i < 80; i++) { gStdLblBuffer[i] = ebcdic_to_ascii[gBuffer[i]]; } gStdLblBuffer[i] = '\0'; } if( opts & O_LABELS ) { Print_Label( rc ); } if( opts & O_TAPEMAP_OUTPUT ) { Print_Label_Tapemap( rc ); } if( opts & O_DATASETS ) { Print_Dataset( rc, fileno ); } if( opts & O_SLANAL_OUT ) { gLength = rc; if ( gLength == 80 ) { if ( 0 || memcmp ( gStdLblBuffer, "HDR", 3 ) == 0 || memcmp ( gStdLblBuffer, "EOF", 3 ) == 0 || memcmp ( gStdLblBuffer, "VOL", 3 ) == 0 || memcmp ( gStdLblBuffer, "EOV", 3 ) == 0 || memcmp ( gStdLblBuffer, "UHL", 3 ) == 0 || memcmp ( gStdLblBuffer, "UTL", 3 ) == 0 ) { if ( !Print_Standard_Labels ( ) ) { if ( gBlkCount <= 10 && ( gBlkCount == 1 || ( gBlkCount > 1 && lResidue > bytes_per_line ) ) ) { gLenPrtd = ( gBlkCount == 1 ? ( gLength <= max_bytes_dsply ? gLength : max_bytes_dsply ) : ( gLength <= lResidue ? gLength : lResidue ) ); lResidue -= Print_Block_Data ( gLenPrtd ); } } } else { if ( gBlkCount <= 10 && ( gBlkCount == 1 || ( gBlkCount > 1 && lResidue > bytes_per_line ) ) ) { gLenPrtd = ( gBlkCount == 1 ? ( gLength <= max_bytes_dsply ? gLength : max_bytes_dsply ) : ( gLength <= lResidue ? gLength : lResidue ) ); lResidue -= Print_Block_Data ( gLenPrtd ); } } } else { if ( ( gBlkCount <= 10 ) && ( ( gBlkCount == 1 ) || ( ( gBlkCount > 1 ) && ( lResidue > bytes_per_line ) ) ) ) { gLenPrtd = ( gBlkCount == 1 ? ( gLength <= max_bytes_dsply ? gLength : max_bytes_dsply ) : ( gLength <= lResidue ? gLength : lResidue ) ); lResidue -= Print_Block_Data ( gLenPrtd ); } } } } if( opts & O_FILES ) { printf ( "%s", sep ); printf ( "%-20.20s:\n", "Summary" ); printf ( "%-20.20s: %d\n", "Files", (int)fileno ); printf ( "%-20.20s: %d\n", "Blocks", (int)totblocks ); if ( !i_faketape ) { printf ( "%-20.20s: %llu\n", "Uncompressed bytes", (unsigned long long)totubytes ); printf ( "%-20.20s: %llu\n", "Compressed bytes", (unsigned long long)totcbytes ); printf ( "%-20.20s: %llu\n", "Reduction", (unsigned long long)(totubytes - totcbytes) ); } } if ( i_faketape ) fet_close( &fetb ); else het_close( &hetb ); return 0; }
int main(int argc, char *argv[]) { SWAP_DATA *swap_data; int status; int total_swap_size, swap_usage, swap_available; pid_t process_id; // create data structure swap_data = Init_Swap_Data(); if (! swap_data) { printf("Unable to allocate memory. Exiting.\n"); return 1; } // check command line arguments Get_Command_Line_Arguments(swap_data, argc, argv); // see if we should display version if (swap_data->show_version) Print_Version(); // see if we should display help if (swap_data->show_help) Print_Usage(); if ( (swap_data->show_version) || (swap_data->show_help) ) { Clean_Up_Swap_Data(swap_data); exit(0); } // give us random numbers srand( time(NULL) ); // try to load config file Read_Config_File(swap_data); // see if we should run as a daemon if (swap_data->daemon_mode) { #ifdef DEBUG printf("Forking\n"); #endif process_id = fork(); // parent if (! process_id) { Clean_Up_Swap_Data(swap_data); exit(0); } else // child process { setsid(); process_id = fork(); if (process_id) { Clean_Up_Swap_Data(swap_data); exit(0); } } } // end of using daemon mode // check to see if we need to create a PID file if (swap_data->create_pid_file) Create_PID_File(); Create_Swap_Directory(swap_data); // check to see if old swap file exists and, if so, remove it // register signal handler signal(SIGTERM, handler_sigterm); signal(SIGINT, handler_sigterm); while (keep_running) { // get current amount of swap space total_swap_size = Get_Total_Swap_Size(); // get current swap usage swap_usage = Get_Swap_Usage(); // cacluate available swap space remaining swap_available = total_swap_size - swap_usage; #ifdef DEBUG printf("Total swap: %d\n", total_swap_size); printf("Swap used: %d\n", swap_usage); printf("Swap free: %d\n", swap_available); #endif // if we are close to needing more swap, create/enlarge the swap file if (swap_data->grow_buffer > swap_available) { #ifdef DEBUG printf("Trying to grow swap file.\n"); #endif Resize_Swap_File(swap_data, ACTION_GROW); } // if we have plenty of swap space available, reduce the swap file else if ( (swap_data->current_swap_file_size > 0) && (swap_data->reduce_buffer < swap_available) ) { #ifdef DEBUG printf("Tring to shrink swap file.\n"); #endif Resize_Swap_File(swap_data, ACTION_SHRINK); } // wait before running another test sleep(5); } // end of endless loop #ifdef DEBUG printf("Left main loop, cleaning up.\n"); #endif // clean up Clean_Up_Swap_File(swap_data); Clean_Up_Swap_Data(swap_data); return 0; }
void scale_init(int argcc, char **argvv) { int i, j, num; int ii; char *p; struct scripttab *kk; if (argcc >=2) /* run mttest with options */ { for (i = 1; i < argcc; i++) { j = i; if(argvv[i][0] != '-') { Print_Usage(1); } if( (argvv[i][1] == 'h') || (argvv[i][1] == 'H') ) { Print_Usage(0); } if(argvv[i][1] == 'u') { uniprocessor ++; continue; } if (strlen(argvv[i]) == 2) { /* argument has blank separating key and number */ j++; if (argcc > j) { p = argvv[j]; num = atoi(p); } else { Print_Usage(1); } } else { /* argument has no blank separating key and number */ p = argvv[i] + 2; num = atoi(p); } switch (argvv[i][1]) { case 't': case 'T': nthreads = num; break; case 'b': case 'B': narrays = num; break; case 'r': case 'R': repeat_count = num; break; case 'j': case 'J': /* argument is a job name; p points to string */ for (ii = 0; ; ii++) { kk = &scripttab[ii]; if (kk->test_name == NULL) { /* Oops, name not found */ Print_Usage(2); } if( strcmp(kk->test_name, p) == 0 ) { /* found it */ break; } } job_index = ii; break; default: Print_Usage(1); } i = j; } } }