static void processcommandline(int argc, char **argv) { int r; while ((r = getopt(argc, argv, "hvc:")) != -1) { switch (r) { case 'v': printversion(); break; case 'h': printusage(); exit(0); break; case 'c': configfilename = optarg; break; default: if (isprint(optopt)) fprintf(stderr, "unknown option '-%c'.\n", optopt); else fprintf(stderr, "unknown option character '-%x'.\n", optopt); exit(1); } } if (optind < argc) { printusage(); exit(1); } }
int main(int argc, char** argv) { int ch; char *melffilename; while ((ch = getopt(argc, argv, "ho:")) != -1){ switch (ch){ case 'o': melffilename = optarg; break; case 'h': case '?': printusage(); exit(EXIT_FAILURE); } } argc -= optind; argv += optind; if ((NULL != argv[0]) && (NULL != melffilename)) { convElfToMiniFile(argv[0], melffilename); } else{ printusage(); } return 0; }
int main(int argc, char *argv[]) { FILE *fp; unsigned int blknum, i; unsigned char block[BLOCKSIZE]; char c; blknum = 0; if (argc != 5) { printusage(argc, argv); exit(0); } while ((c = getopt(argc, argv, "n:f:h")) != -1) { switch(c) { case 'n': blknum = atoi(optarg); break; case 'f': fp = fopen(optarg, "r"); if (fp == NULL) { printf("Could not open file: '%s'\n", optarg); exit(1); } break; case 'h': printusage(argc, argv); exit(0); break; } } if (fp == NULL) { printf("Must specify filename!\n"); exit(1); } if (fseek(fp, BLOCKSIZE * blknum, SEEK_SET) < 0) { printf("Error seeking to block no. %d!\n", blknum); fclose(fp); exit(1); } if (fread(&block, BLOCKSIZE, 1, fp) != 1) { printf("Error reading block no. %d!\n", blknum); fclose(fp); exit(1); } /* Block was actually read; print it. */ for (i = 0; i < BLOCKSIZE; i++) { if ((i % 16) == 0) printf("\n"); printf("%02x ", block[i]); } printf("\n"); fclose(fp); return 0; }
int main(int argc, char **argv) { bool brief = false; afSetErrorHandler(errorHandler); if (argc == 1) { printusage(); return 0; } static struct option long_options[] = { {"short", 0, 0, 's'}, {"reporterror", 0, 0, 'r'}, {"help", 0, 0, 'h'}, {"version", 0, 0, 'v'}, {0, 0, 0, 0} }; int result; int option_index = 1; while ((result = getopt_long(argc, argv, "srhv", long_options, &option_index)) != -1) { switch (result) { case 's': brief = true; break; case 'r': reportError = true; break; case 'h': printusage(); exit(EXIT_SUCCESS); case 'v': printversion(); exit(EXIT_SUCCESS); } } int i = optind; while (i < argc) { bool processed = brief ? printshortinfo(argv[i]) : printfileinfo(argv[i]); i++; if (!brief && processed && i < argc) putchar('\n'); } return 0; }
int getargs(int argc, char **argv, argoptions * opt) { int i, rc, unknowncnt; if (opt == NULL) return -1; initoptions(opt); if (argc < 2) { // printusage(argv); Ok to not have params - default model #ifndef DEFAULT_MODELFILE return -1; #else return 0; #endif//DEFAULT_MODELFILE } i = 1; unknowncnt = 0; while (i < argc) { if (argv[i][0] == '-' || argv[i][0] == '+') { rc = getparm(argc, argv, i, opt); if (rc != -1) { i += rc; } else { printusage(argv); return -1; } } else { unknowncnt++; if (unknowncnt > 1) { fprintf(stderr, "Too many model file names found!\n"); printusage(argv); return -1; } else { strcpy(opt->filename, argv[i]); opt->foundfilename = 1; i++; } } } if (opt->foundfilename == -1) { fprintf(stderr, "Missing model file name!\n"); printusage(argv); return -1; } return 0; }
int main(int argc, char *argv[]) { point_t a, b, c, d; struct rt_wdb *fp; struct rt_nurb_internal *si; char *filename = "spltest.g"; int helpflag; if (argc < 1 || argc > 2) { printusage(argv); bu_exit(1,NULL); } helpflag = (argc == 2 && ( BU_STR_EQUAL(argv[1],"-h") || BU_STR_EQUAL(argv[1],"-?"))); if (argc == 1 || helpflag) { printusage(argv); if (helpflag) bu_exit(1,NULL); bu_log(" Program continues running:\n"); } if (argc == 2) filename = argv[1]; if ((fp = wdb_fopen(filename)) == NULL) { perror("unable to open geometry database for writing"); bu_exit(1, "unable to open new database [%s]\n", filename); } mk_id(fp, "Mike's Spline Test"); VSET(a, 0, 0, 0); VSET(b, 10, 0, -5); VSET(c, 10, 10, 10); VSET(d, 0, 10, 0); BU_ALLOC(si, struct rt_nurb_internal); si->magic = RT_NURB_INTERNAL_MAGIC; si->nsrf = 0; si->srfs = (struct face_g_snurb **)bu_malloc(sizeof(struct face_g_snurb *)*100, "allocate snurb ptrs"); make_face(si, a, b, c, d, 2); /* wdb_export */ mk_export_fwrite(fp, "spltest", (void *)si, ID_BSPLINE); bu_log("Saving file %s\n",filename); return 0; }
/******************************************** * getoptions() * * Parses argument list for options * * Any arguments in argv that are not * recognized here are assumed to be files. * This function returns the number of * the first non-option argument. It is up * to xdd_readfile() to make sure they * are actual filenames. ********************************************/ int getoptions(int argc, char **argv) { int ierr, opt, argnum; extern char *optarg; ierr = 0; argnum = 1; /* track number of args parsed */ /* set default options */ strcpy(outfilebase,"."); window_size = 1; /* loop through options */ while ((opt = getopt(argc, argv, "t:ko:h")) != -1) { switch (opt) { case 't': /* moving average */ window_size = atoi(optarg); argnum += 2; if (window_size <= 0) { fprintf(stderr,"\nwindow size must be more than 0.\n\n"); ierr++; } break; case 'k': /* use src, dst kernel trace files */ kernel_trace = 1; argnum += 1; break; case 'o': /* output file name */ strncpy(outfilebase,optarg,OUTFILENAME_LEN); outfilebase[OUTFILENAME_LEN-1] = '\0'; argnum += 2; if (strlen(outfilebase) == 0) ierr++; break; case 'h': /* help */ default: printusage(argv[0]); break; } } /* do we have two filenames and no parsing errors? */ if ( (argc-argnum < 1) || (ierr != 0) ) { printusage(argv[0]); } /* return the number of the first non-option argument */ return argnum; }
int mainprogram (int argc, char *argv[]) { char *outwavhdrfilename,*outwavdatfilename; int len; int result=0; if (parseArgs(argc,argv)!=0) { printusage(); return 0; } len = strlen(wavtool_args.outputfilename)+4+1; outwavhdrfilename = (char *)malloc(len*sizeof(char)); memset(outwavhdrfilename,0,len*sizeof(char)); outwavdatfilename = (char *)malloc(len*sizeof(char)); memset(outwavdatfilename,0,len*sizeof(char)); _snprintf(outwavhdrfilename,len,"%s.whd",wavtool_args.outputfilename); _snprintf(outwavdatfilename,len,"%s.dat",wavtool_args.outputfilename); if (!isFileExist(outwavhdrfilename)) { wfh_init(outwavhdrfilename); } if (!isFileExist(outwavdatfilename)) { wfd_init(outwavdatfilename); } len = wfd_append(outwavdatfilename,wavtool_args.inputfilename,wavtool_args.offset,wavtool_args.length,wavtool_args.ovr,wavtool_args.p,wavtool_args.v); result = wfh_putlength(outwavhdrfilename,len); return 0; }
//----------------------------------------------------------------------------- // Purpose: // Input : argc - // argv[] - // Output : int //----------------------------------------------------------------------------- int main( int argc, char* argv[] ) { SpewOutputFunc( SpewFunc ); Msg( "Valve Software - vcprojtomake.exe (%s)\n", __DATE__ ); Msg( "Modified for VS2010 Support by Killer Monkey\n" ); Msg( "<*****@*****.**>\n" ); CommandLine()->CreateCmdLine( argc, argv ); if ( CommandLine()->ParmCount() < 2) { printusage(); return 0; } CVCProjConvert proj; if ( !proj.LoadProject( CommandLine()->GetParm( 1 )) ) { Msg( "Failed to parse project\n" ); return -1; } OutputKeyValuesVersion(proj); CMakefileCreator makefile; makefile.CreateMakefiles( proj ); return 0; }
/* * main() : Entry point */ int main(int argc, char *argv[]) { if (argc < 2 || strcmp(argv[1], "-?") == 0) { /* Print usage */ return printusage(); } if (strcmp(argv[1], "-s") == 0) { /* Hash string */ return hashstring(argv[2]); } if (strcmp(argv[1], "-t") == 0) { /* Time trial */ return timetrial(); } if (strcmp(argv[1], "-x") == 0) { /* Test suite */ return testsuite(); } /* Hash file */ return hashfile(argv[1]); }
/* * help - tell about commands, or details of a particular command */ static void help( struct parse *pcmd, FILE *fp ) { struct xcmd *xcp; char *cmd; const char *list[100]; size_t word, words; size_t row, rows; size_t col, cols; size_t length; if (pcmd->nargs == 0) { words = 0; for (xcp = builtins; xcp->keyword != 0; xcp++) { if (*(xcp->keyword) != '?') list[words++] = xcp->keyword; } for (xcp = opcmds; xcp->keyword != 0; xcp++) list[words++] = xcp->keyword; qsort((void *)list, (size_t)words, sizeof(list[0]), helpsort); col = 0; for (word = 0; word < words; word++) { length = strlen(list[word]); col = max(col, length); } cols = SCREENWIDTH / ++col; rows = (words + cols - 1) / cols; fprintf(fp, "ntpdc commands:\n"); for (row = 0; row < rows; row++) { for (word = row; word < words; word += rows) fprintf(fp, "%-*.*s", col, col-1, list[word]); fprintf(fp, "\n"); } } else { cmd = pcmd->argval[0].string; words = findcmd(cmd, builtins, opcmds, &xcp); if (words == 0) { fprintf(stderr, "Command `%s' is unknown\n", cmd); return; } else if (words >= 2) { fprintf(stderr, "Command `%s' is ambiguous\n", cmd); return; } fprintf(fp, "function: %s\n", xcp->comment); printusage(xcp, fp); } }
static void CheckOptions(int argc, char **argv) { int n,m; int i; for(n=1;n<argc;n++) { /* an option ? */ if (argv[n][0]=='-') { /* is it "--" ? */ if (argv[n][1]=='-') { /* --blabla options are not used */ if (argv[n][2]) { printf("long option not recognized : %s\n",argv[n]); grr(argv[0]); } else return; } m=n; /* -blabla, check every letter */ for (i=1;argv[n][i];i++) { if (argv[n][i]=='d') if (visiobases_dir) { free(visiobases_dir); visiobases_dir=NULL; } if (argv[n][i]=='h') { printusage(argv[0]); exit(0); } if (argv[n][i]=='s') { if (++m==argc) grr(argv[0]); socketport=argv[m]; } if (argv[n][i]=='k') { if (++m==argc) grr(argv[0]); keyname=argv[m]; } if (argv[n][i]=='o') { if (++m==argc) grr(argv[0]); Parse(argv[m]); } if (argv[n][i]=='b') backup=1; if (argv[n][i]=='n') backup=0; if (argv[n][i]=='f') burstmode=VB_AUTOMATIC; if (argv[n][i]=='i') burstmode=VB_MANUAL; if (strchr(OPTIONS,argv[n][i])==NULL) { printf("option not recognized : -%c\n",argv[n][i]); grr(argv[0]); } } n=m; } } }
int main(int argc, char **argv) { int i; QStringList args; QPEApplication a(argc, argv); QWidget w; a.setMainWidget(&w); QWidget *d = a.desktop(); int width=d->width(); int height=d->height(); for(i=0; i < argc; i++) { args += argv[i]; } for(i=0; i < argc; i++) { if(args[i] == "-m") { return myMessageBox(width, height, &w, argc, args); } if(args[i] == "-f") { return fileviewer(&a, argc, args); } if(args[i] == "-i") { return input(width, height, &w, argc, args); } if(args[i] == "-h" || args[i] =="--help") { printusage(); return -1; } } printusage(); return -1; }
// // printhelp: prints the help for the program // static void printhelp(char *progname) { printusage(progname); fprintf(stderr,"TODO: help not well written\n"); fprintf(stderr,"press ESC to end the program (user must have context of the video window!).\n"); fprintf(stderr,"\n"); fprintf(stderr,"quick and dirty argument descriptions:\n"); fprintf(stderr," -h show help and exit\n"); fprintf(stderr," -p PATH load and save attributes files from/to PATH (should be a directory)\n"); }
void readoptions(int argc, char **argv, char **romfilename, int *fullscreen, tmachine *machine, video_mode *vmode, int *nosound, float *scale, int *codemasters) { int c; int option_index; struct option long_options[] = { {"fullscreen", no_argument, fullscreen, 1}, {"machine", required_argument, NULL, 't'}, {"mode", required_argument, NULL, 'm'}, {"nosound", no_argument, nosound, 1}, {"scale", required_argument, NULL, 's'}, {"codemasters", no_argument, codemasters, 1}, {"help", no_argument, NULL, 'h' }, { NULL, 0, NULL, 0} }; if(argc<=1) { printusage(); log4me_print("Try '"PACKAGE" --help' for more information.\n"); } while((c = getopt_long(argc, argv, "", long_options, &option_index))!=-1) { //printf("-> %c %d (%d)\n", c, (int)c, option_index); switch(c) { case 's': *scale = atof(optarg); if(*scale<1) { log4me_print("wrong scale parameter, set to default value\n"); *scale = DEFAULT_SCALE; } break; case 't': *machine = strcasecmp(optarg, "export")==0 ? EXPORT : JAPAN; break; case 'm': *vmode = strcasecmp(optarg, "pal")==0 ? VM_PAL : VM_NTSC; break; case 'h': printhelp(); exit(EXIT_SUCCESS); break; case '?': printhelp(); exit(EXIT_FAILURE); break; } } if(optind>=argc) { log4me_print("ROM filename missing.\n"); exit(EXIT_FAILURE); } *romfilename = argv[optind]; }
int main(int argc, char **argv) { double factor, temp; int i, j, doit, of, count, val, *col_list; if ( BU_STR_EQUAL(argv[1], "-h") || BU_STR_EQUAL(argv[1], "-?") ) printusage(); if (argc < 4) printusage(); sscanf(*(argv+1), "%lf", &factor); sscanf(*(argv+2), "%d", &of); col_list = (int *) bu_calloc(argc-2, sizeof(int), "int array"); for (i=3;i<argc;i++) { sscanf(*(argv+i), "%d", col_list+(i-3)); } count = 0; while (!feof(stdin)) { val = scanf("%lf", &temp); if (val<1) ; else { doit = 0; for (j=0;j<argc-3;j++) { if (col_list[j]==count) doit = 1; } if (doit) printf("%.10g\t", temp*factor); else printf("%.10g\t", temp); } if (count == (of-1)) printf("\n"); count = (count+1)%of; } bu_free(col_list, "int array"); return 0; }
int main(int argc, char **argv) { unsigned char ibuf[512]; double obuf[512]; int i, num; double scale = 1.0; size_t ret; if (BU_STR_EQUAL(argv[1], "-h") || BU_STR_EQUAL(argv[1], "-?")) printusage(); if (argc > 1) { if (BU_STR_EQUAL(argv[1], "-n")) scale = 1.0/255.0; else scale = atof(argv[1]); argc--; } if (argc > 1 || ZERO(scale) || isatty(fileno(stdin))) { fprintf(stderr, "bad argument\n"); printusage(); } while ((num = fread(&ibuf[0], sizeof(ibuf[0]), 512, stdin)) > 0) { if (EQUAL(scale, 1.0)) { for (i = 0; i < num; i++) obuf[i] = ibuf[i]; } else { for (i = 0; i < num; i++) obuf[i] = (double)ibuf[i] * scale; } ret = fwrite(&obuf[0], sizeof(obuf[0]), num, stdout); if (ret != (size_t)num) perror("fwrite"); } return 0; }
// // printhelp: prints the help for the program // static void printhelp(char *progname) { printusage(progname); fprintf(stderr,"TODO: help not well written\n"); fprintf(stderr,"press ESC to end the program (user must have context of the video window!).\n"); fprintf(stderr,"\n"); fprintf(stderr,"quick and dirty argument descriptions:\n"); fprintf(stderr," -a ASAP mode. just pump out frames as quickly as possible\n"); fprintf(stderr," -h show help and exit\n"); fprintf(stderr," -i PATH replay video located at PATH\n"); }
void printhelp() { printusage(); log4me_print("\nOptions:\n"); log4me_print(" --fullscreen\t: Set fullscreen mode\n"); log4me_print(" --machine MCH\t: Set machine type [japan/export] (default=japan)\n"); log4me_print(" --mode TYPE\t: Set video mode NTSC/PAL [ntsc/pal] (default=ntsc)\n"); log4me_print(" --nosound\t: Set sound off\n"); log4me_print(" --scale NUM\t: Increase the size of the screen by NUM (default=%d)\n", DEFAULT_SCALE); log4me_print(" --codemasters\t: Force the compatibility of Codemasters games\n"); }
// // printhelp: prints the help for the program // static void printhelp(char *progname) { printusage(progname); fprintf(stderr,"TODO: help not well written\n"); fprintf(stderr,"press ESC to end the program (user must have context of the video window!).\n"); fprintf(stderr,"\n"); fprintf(stderr,"quick and dirty argument descriptions:\n"); fprintf(stderr," -b attempt to connect to a bluetooth module already bonded on /dev/rfcomm0\n"); fprintf(stderr," -h show help and exit\n"); fprintf(stderr," -s step mode. grab one picture each time the user presses a key\n"); }
void settiestr(char*s){ int i,j,c; i= strlen(s); if((i> 2*MAXLEN)||i%2==1)printusage(),exit(BAD_OPTIONS); tiestrlen= i/2; j= 0; for(i= 0;i<tiestrlen;i++){ tiestr[i]= hexnum(s[j++])<<4; tiestr[i]+= hexnum(s[j++]); } }
/* Main */ int main(int argc,char **argv){ FILE *resfile,*outfile; int i,j,k,cc,b,first,col,maxcols,hex,external,header,override,include,ppm; int ppm_w,ppm_h,num,nbytes; char name[100],*filename,*ptr; unsigned char *data; if(argc<2){ printusage(); exit(1); } outfile=stdout; maxcols=16; hex=1; external=0; header=1; override=0;
int main(int argc, char *argv[]) { if (argc >= 3) { if ( 0 == strcmp("red",argv[1]) ) { setreg(ledctl_red,0); setreg(leddata_red,strcmp("off",argv[2])?1:0); } else { setreg(ledctl_green,0); setreg(leddata_green,strcmp("off",argv[2])?1:0); } } else { printusage(); return -1; } return 0; }
int mygo(int argc, char **argv, opts* op){ int c; opterr = 0; while ((c = getopt (argc, argv, "abdhi:n:o:t:")) != -1){ switch (c){ case 'a': break; case 'b': break; case 'd': op->pw = 1; break; case 'h': printusage(); exit(0); break; case 'i': //Infile needed: sprintf(op->ifn,"%s",optarg); case 't': op->threshold = atoi(optarg); break; case 'w': op->pw = 1; break; case '?': fprintf(stderr,"INPUT ERROR:\n"); if (optopt == 'c') fprintf (stderr, "Option -%c requires an argument.\n", optopt); else if (isprint (optopt)) fprintf (stderr, "Unknown option `-%c'.\n", optopt); else fprintf (stderr,"Unknown option character `\\x%x'.\n", optopt); return 1; default: abort (); } } // printf ("aflag = %d, bflag = %d, cvalue = %s\n", // aflag, bflag, cvalue); }
int main(int argc, char* argv[]) { short rotornumbers = 0123; int rpositions[3] = {0}; char* input_filename; FILE* fd; /* Checks the cli arguments */ if (parseoptions(argc, argv, &input_filename, &rotornumbers, rpositions) == EXIT_FAILURE) { printusage(argv[0]); return EXIT_FAILURE; } if ((fd = fopen(input_filename, "r")) == NULL) { perror("fopen:"); return EXIT_FAILURE; } cryptstream(fd, rotornumbers, rpositions); return EXIT_SUCCESS; }
int main(int argc, char **argv){ int err = 0; char c; uint32_t start_ip = 0, end_ip = 0; int delay = 100; struct option opts[] = { {"start", 1, NULL, 's'}, {"end", 1, NULL, 'e'}, {"delay", 1, NULL, 'd'}, }; /** * Get the options for the program */ while(((c = getopt_long(argc, argv, "s:S:e:E:d:D", opts, NULL)) != (char)-1) ){ switch(c){ case 's': start_ip = ntohl((uint32_t)inet_addr(optarg)); break; case 'e': end_ip = ntohl((uint32_t)inet_addr(optarg)); break; case 'd': delay = atoi(optarg); break; default: fprintf(stderr, "Unkown option %c\n", c); printusage(argc, argv); exit(1); } } // set the interface to the last value if(optind > 0 && optind < argc ){ strncpy(interface, argv[optind],IFNAMSIZ); }else{ printusage(argc, argv); return 1; } /** * Check to see if running as root */ if(geteuid()) { // non root user fprintf(stderr, "You must run this program as root! This is needed to open" \ " raw sockets and capture raw packets.\n"); return 1; } /** * Done checking the inputs! Start the program logic */ // set the ip utility if(sysarp_set(iplink_path,interface,0) < 0){ fprintf(stderr, "Error pausing the system ARP replies.\n"); err = 1; goto cleanup; } //debugging: printf("doing send_arp on %s with %u, %u, and %u\n", interface, start_ip, end_ip, delay); printf("starting... "); if( send_arp(interface, start_ip, end_ip, delay) < 0 ){ fprintf(stderr, "Error sending ARPs on the interface.\n"); err = 1; goto cleanup; } printf("done!\n"); cleanup: if(sysarp_set(iplink_path,interface,1) < 0){ fprintf(stderr, "Could not resume the system ARP replies\n"); } return err; }
int main(int argc, char **argv) { int c; const char *extension = ".txt"; bool verbose = false; uint64_t data[13]; initializeMemUsageCounter(); while ((c = getopt(argc, argv, "ve:h")) != -1) switch (c) { case 'e': extension = optarg; break; case 'v': verbose = true; break; case 'h': printusage(argv[0]); return 0; default: abort(); } if (optind >= argc) { printusage(argv[0]); return -1; } char *dirname = argv[optind]; size_t count; size_t *howmany = NULL; uint32_t **numbers = read_all_integer_files(dirname, extension, &howmany, &count); if (numbers == NULL) { printf( "I could not find or load any data file with extension %s in " "directory %s.\n", extension, dirname); return -1; } uint32_t maxvalue = 0; for (size_t i = 0; i < count; i++) { if( howmany[i] > 0 ) { if(maxvalue < numbers[i][howmany[i]-1]) { maxvalue = numbers[i][howmany[i]-1]; } } } uint64_t totalcard = 0; for (size_t i = 0; i < count; i++) { totalcard += howmany[i]; } uint64_t successivecard = 0; for (size_t i = 1; i < count; i++) { successivecard += howmany[i-1] + howmany[i]; } uint64_t cycles_start = 0, cycles_final = 0; RDTSC_START(cycles_start); std::vector<vector> bitmaps = create_all_bitmaps(howmany, numbers, count); RDTSC_FINAL(cycles_final); if (bitmaps.empty()) return -1; if(verbose) printf("Loaded %d bitmaps from directory %s \n", (int)count, dirname); uint64_t totalsize = getMemUsageInBytes(); data[0] = totalsize; if(verbose) printf("Total size in bytes = %" PRIu64 " \n", totalsize); uint64_t successive_and = 0; uint64_t successive_or = 0; uint64_t total_or = 0; uint64_t total_count = 0; uint64_t successive_andnot = 0; uint64_t successive_xor = 0; RDTSC_START(cycles_start); for (int i = 0; i < (int)count - 1; ++i) { vector v; std::set_intersection(bitmaps[i].begin(), bitmaps[i].end(),bitmaps[i+1].begin(), bitmaps[i+1].end(),std::back_inserter(v)); successive_and += v.size(); } RDTSC_FINAL(cycles_final); data[1] = cycles_final - cycles_start; if(verbose) printf("Successive intersections on %zu bitmaps took %" PRIu64 " cycles\n", count, cycles_final - cycles_start); RDTSC_START(cycles_start); for (int i = 0; i < (int)count - 1; ++i) { vector v; std::set_union(bitmaps[i].begin(), bitmaps[i].end(),bitmaps[i+1].begin(), bitmaps[i+1].end(),std::back_inserter(v)); successive_or += v.size(); } RDTSC_FINAL(cycles_final); data[2] = cycles_final - cycles_start; if(verbose) printf("Successive unions on %zu bitmaps took %" PRIu64 " cycles\n", count, cycles_final - cycles_start); RDTSC_START(cycles_start); if(count>1) { vector v; std::set_union(bitmaps[0].begin(), bitmaps[0].end(),bitmaps[1].begin(), bitmaps[1].end(),std::back_inserter(v)); for (int i = 2; i < (int)count ; ++i) { vector newv; std::set_union(v.begin(), v.end(),bitmaps[i].begin(), bitmaps[i].end(),std::back_inserter(newv)); v.swap(newv); } total_or = v.size(); } RDTSC_FINAL(cycles_final); data[3] = cycles_final - cycles_start; if(verbose) printf("Total naive unions on %zu bitmaps took %" PRIu64 " cycles\n", count, cycles_final - cycles_start); RDTSC_START(cycles_start); if(count>1) { const vector ** allofthem = new const vector* [count]; for(int i = 0 ; i < (int) count; ++i) allofthem[i] = & bitmaps[i]; vector totalorbitmap = fast_logicalor(count, allofthem); total_or = totalorbitmap.size(); delete[] allofthem; } RDTSC_FINAL(cycles_final); data[4] = cycles_final - cycles_start; if(verbose) printf("Total heap unions on %zu bitmaps took %" PRIu64 " cycles\n", count, cycles_final - cycles_start); RDTSC_START(cycles_start); uint64_t quartcount = 0; for (size_t i = 0; i < count ; ++i) { if ( std::binary_search(bitmaps[i].begin(),bitmaps[i].end(),maxvalue/4 ) ) quartcount ++; if ( std::binary_search(bitmaps[i].begin(),bitmaps[i].end(),maxvalue/2 ) ) quartcount ++; if ( std::binary_search(bitmaps[i].begin(),bitmaps[i].end(),3*maxvalue/4 ) ) quartcount ++; } RDTSC_FINAL(cycles_final); data[5] = cycles_final - cycles_start; if(verbose) printf("Quartile queries on %zu bitmaps took %" PRIu64 " cycles\n", count, cycles_final - cycles_start); if(verbose) printf("Collected stats %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 "\n",successive_and,successive_or,total_or,quartcount); RDTSC_START(cycles_start); for (int i = 0; i < (int)count - 1; ++i) { vector v; std::set_difference(bitmaps[i].begin(), bitmaps[i].end(),bitmaps[i+1].begin(), bitmaps[i+1].end(),std::back_inserter(v)); successive_andnot += v.size(); } RDTSC_FINAL(cycles_final); data[6] = cycles_final - cycles_start; if(verbose) printf("Successive differences on %zu bitmaps took %" PRIu64 " cycles\n", count, cycles_final - cycles_start); RDTSC_START(cycles_start); for (int i = 0; i < (int)count - 1; ++i) { vector v; std::set_symmetric_difference(bitmaps[i].begin(), bitmaps[i].end(),bitmaps[i+1].begin(), bitmaps[i+1].end(),std::back_inserter(v)); successive_xor += v.size(); } RDTSC_FINAL(cycles_final); data[7] = cycles_final - cycles_start; if(verbose) printf("Successive symmetric differences on %zu bitmaps took %" PRIu64 " cycles\n", count, cycles_final - cycles_start); RDTSC_START(cycles_start); for (size_t i = 0; i < count; ++i) { vector & b = bitmaps[i]; for(auto j = b.begin(); j != b.end() ; j++) { total_count++; } } RDTSC_FINAL(cycles_final); data[8] = cycles_final - cycles_start; assert(total_count == totalcard); if(verbose) printf("Iterating over %zu bitmaps took %" PRIu64 " cycles\n", count, cycles_final - cycles_start); assert(successive_xor + successive_and == successive_or); /** * and, or, andnot and xor cardinality */ uint64_t successive_andcard = 0; uint64_t successive_orcard = 0; uint64_t successive_andnotcard = 0; uint64_t successive_xorcard = 0; RDTSC_START(cycles_start); for (int i = 0; i < (int)count - 1; ++i) { std::set_intersection(bitmaps[i].begin(), bitmaps[i].end(),bitmaps[i+1].begin(), bitmaps[i+1].end(),inserter(successive_andcard)); } RDTSC_FINAL(cycles_final); data[9] = cycles_final - cycles_start; RDTSC_START(cycles_start); for (int i = 0; i < (int)count - 1; ++i) { std::set_union(bitmaps[i].begin(), bitmaps[i].end(),bitmaps[i+1].begin(), bitmaps[i+1].end(),inserter(successive_orcard)); } RDTSC_FINAL(cycles_final); data[10] = cycles_final - cycles_start; RDTSC_START(cycles_start); for (int i = 0; i < (int)count - 1; ++i) { std::set_difference(bitmaps[i].begin(), bitmaps[i].end(),bitmaps[i+1].begin(), bitmaps[i+1].end(),inserter(successive_andnotcard)); } RDTSC_FINAL(cycles_final); data[11] = cycles_final - cycles_start; RDTSC_START(cycles_start); for (int i = 0; i < (int)count - 1; ++i) { std::set_symmetric_difference(bitmaps[i].begin(), bitmaps[i].end(),bitmaps[i+1].begin(), bitmaps[i+1].end(),inserter(successive_xorcard)); } RDTSC_FINAL(cycles_final); data[12] = cycles_final - cycles_start; assert(successive_andcard == successive_and); assert(successive_orcard == successive_or); assert(successive_xorcard == successive_xor); assert(successive_andnotcard == successive_andnot); /** * end and, or, andnot and xor cardinality */ printf(" %20.2f %20.2f %20.2f %20.2f %20.2f %20.2f %20.2f %20.2f %20.2f %20.2f %20.2f %20.2f %20.2f\n", data[0]*8.0/totalcard, data[1]*1.0/successivecard, data[2]*1.0/successivecard, data[3]*1.0/totalcard, data[4]*1.0/totalcard, data[5]*1.0/(3*count), data[6]*1.0/successivecard, data[7]*1.0/successivecard, data[8]*1.0/totalcard, data[9]*1.0/successivecard, data[10]*1.0/successivecard, data[11]*1.0/successivecard, data[12]*1.0/successivecard ); for (int i = 0; i < (int)count; ++i) { free(numbers[i]); numbers[i] = NULL; // paranoid } free(howmany); free(numbers); return 0; }
int main(int argc, char **argv) { int c; int tnum; int subprocs; pid_t deadpid; int status; int len; isc_boolean_t first; testspec_t *pts; struct sigaction sa; isc_mem_debugging = ISC_MEM_DEBUGRECORD; first = ISC_TRUE; subprocs = 1; T_timeout = T_TCTOUT; /* * -a option is now default. */ memset(T_tvec, 0xff, sizeof(T_tvec)); /* * Parse args. */ while ((c = isc_commandline_parse(argc, argv, ":at:c:d:n:huxq:b:")) != -1) { if (c == 'a') { /* * Flag all tests to be run. */ memset(T_tvec, 0xff, sizeof(T_tvec)); } else if (c == 'b') { T_dir = isc_commandline_argument; } else if (c == 't') { tnum = atoi(isc_commandline_argument); if ((tnum > 0) && (tnum < T_MAXTESTS)) { if (first) { /* * Turn off effect of -a default * and allow multiple -t and -n * options. */ memset(T_tvec, 0, sizeof(T_tvec)); first = ISC_FALSE; } /* * Flag test tnum to be run. */ tnum -= 1; T_tvec[tnum / 8] |= (0x01 << (tnum % 8)); } } else if (c == 'c') { T_config = isc_commandline_argument; } else if (c == 'd') { T_debug = atoi(isc_commandline_argument); } else if (c == 'n') { pts = &T_testlist[0]; tnum = 0; while (pts->pfv != NULL) { if (! strcmp(pts->func_name, isc_commandline_argument)) { if (first) { memset(T_tvec, 0, sizeof(T_tvec)); first = ISC_FALSE; } T_tvec[tnum/8] |= (0x01 << (tnum%8)); break; } ++pts; ++tnum; } if (pts->pfv == NULL) { fprintf(stderr, "no such test %s\n", isc_commandline_argument); exit(1); } } else if (c == 'h') { printhelp(); exit(0); } else if (c == 'u') { printusage(); exit(0); } else if (c == 'x') { subprocs = 0; } else if (c == 'q') { T_timeout = atoi(isc_commandline_argument); } else if (c == ':') { fprintf(stderr, "Option -%c requires an argument\n", isc_commandline_option); exit(1); } else if (c == '?') { fprintf(stderr, "Unrecognized option -%c\n", isc_commandline_option); exit(1); } } /* * Set cwd. */ if (T_dir != NULL && chdir(T_dir) != 0) { fprintf(stderr, "chdir %s failed\n", T_dir); exit(1); } /* * We don't want buffered output. */ (void)setbuf(stdout, NULL); (void)setbuf(stderr, NULL); /* * Setup signals. */ sa.sa_flags = 0; sigfillset(&sa.sa_mask); sa.sa_handler = t_sighandler; (void)sigaction(SIGINT, &sa, NULL); (void)sigaction(SIGALRM, &sa, NULL); /* * Output start stanza to journal. */ snprintf(T_buf, sizeof(T_buf), "%s:", argv[0]); len = strlen(T_buf); (void) t_getdate(T_buf + len, T_BIGBUF - len); t_putinfo("S", T_buf); /* * Setup the test environment using the config file. */ if (T_config == NULL) T_config = T_DEFAULT_CONFIG; t_initconf(T_config); if (T_debug) t_dumpconf(T_config); /* * Now invoke all the test cases. */ tnum = 0; pts = &T_testlist[0]; while (*pts->pfv != NULL) { if (T_tvec[tnum / 8] & (0x01 << (tnum % 8))) { if (subprocs) { T_pid = fork(); if (T_pid == 0) { (*pts->pfv)(); exit(0); } else if (T_pid > 0) { T_int = 0; sa.sa_handler = t_sighandler; (void)sigaction(SIGALRM, &sa, NULL); alarm(T_timeout); deadpid = (pid_t) -1; while (deadpid != T_pid) { deadpid = waitpid(T_pid, &status, 0); if (deadpid == T_pid) { if (WIFSIGNALED(status)) { if (WTERMSIG(status) == SIGTERM) t_info( "the test case timed out\n"); else t_info( "the test case caused exception %d\n", WTERMSIG(status)); t_result(T_UNRESOLVED); } } else if ((deadpid == -1) && (errno == EINTR) && T_int) { kill(T_pid, SIGTERM); T_int = 0; } else if ((deadpid == -1) && ((errno == ECHILD) || (errno == ESRCH))) break; } alarm(0); sa.sa_handler = SIG_IGN; (void)sigaction(SIGALRM, &sa, NULL); } else { t_info("fork failed, errno == %d\n", errno); t_result(T_UNRESOLVED); } } else { (*pts->pfv)(); } } ++pts; ++tnum; } snprintf(T_buf, sizeof(T_buf), "%s:", argv[0]); len = strlen(T_buf); (void) t_getdate(T_buf + len, T_BIGBUF - len); t_putinfo("E", T_buf); return(0); }
// application entry point void main(int argc,char *argv[]) { int system_time=0; int frame_counter=0; int time0; char s[20]=""; if (argc<2) { printusage(); return; } // parses command line parameters parsecmdline(argc-2,argv+2); // initializes the video mode and geometry module int mode=-1; if (vbe_init()) { mode=vbe_findmode(scrwidth,scrheight,8); if (!mode) mode=-1; } if (mode==-1) vbe_done(); if (!vbe_setmode(mode,backbuffl)) goto err; setscreensize(vbe_width,vbe_height); scr_cols=vbe_width; scr_bpp=vbe_bpp; // initializes the keyboard kbd_init(); // initializes the timer timer_init(); // initializes the mouse mouse_init(); // reads the map if (!map_init(argv[1])) goto err; vbe_setpal((Tcolor *)palette,0,256); // main loop time0=timer_clocks; while(player_idle(timer_clocks)) { // draws the current frame draw_init(vbe_backbuffer,vbe_width,vbe_height); map_draw(); // calculates the frame rate frame_counter++; int dt=timer_clocks-time0; if (dt>500) { float fps = (frame_counter*1000.)/dt; sprintf(s,"%.1f FPS",fps); time0 = timer_clocks; frame_counter = 0; } textout(vbe_backbuffer,0,0,s,255); // flips the video pages vbe_flip(waitfl); // applies the mouse movement if (player_keys & kRUN) player_rotate(-mousedy*0.01,0,-mousedx*0.01); else player_rotate(-mousedy*0.005,0,-mousedx*0.005); mousedx=0;mousedy=0; // clears the keyboard queue while (kbhit()) getch(); } err: vbe_done(); vbe_settext(); }
//************************************************************************************************** // main // int main(int argc, char** argv) { char cc; char indat[256*1024]; // huge because I am a lazy man char *indatloc; int readcnt; int totallen; unsigned numcams; // process user cli gFlagUserCliValid=0; gFlagUserCliHelp=0; gFlagUseBluetooth=0; if(0 != parseargs(argc,argv)) { printusage(argv[0]); exit(1); } if(0 == gFlagUserCliValid) { printusage(argv[0]); exit(1); } if(0 != gFlagUserCliHelp) { printhelp(argv[0]); exit(0); } if(0 == gFlagUseBluetooth) { // russ: this is a little inelegant gCamin = fopen("/dev/ttyACM0","r"); if(0 == gCamin) { fprintf(stderr, "Could not open /dev/ttyACM0 for reading; trying /dev/ttyACM1\n"); gCamin = fopen("/dev/ttyACM1", "r"); if(0 == gCamin) { fprintf(stderr, "Could not open /dev/ttyACM1 for reading\n"); return -1; } gCamout = fopen("/dev/ttyACM1","w"); if(0 == gCamout) { fprintf(stderr, "Could not open /dev/ttyACM1 for writing\n"); fclose(gCamin); return -1; } } else { gCamout = fopen("/dev/ttyACM0","w"); if(0 == gCamout) { fprintf(stderr, "Could not open /dev/ttyACM0 for writing\n"); fclose(gCamin); return -1; } } } else { // use bluetooth gCamin = fopen("/dev/rfcomm0", "r"); if(0 == gCamin) { fprintf(stderr, "Could not open /dev/rfcomm0 for reading\n"); return -1; } gCamout = fopen("/dev/rfcomm0","w"); if(0 == gCamout) { fprintf(stderr, "Could not open /dev/rfcomm0 for writing\n"); fclose(gCamin); return -1; } } // find out if the device has 1 or 2 cameras fputc((char)SYMBOL_SOF,gCamout); dbgPrintOp("tx: 0x%02X\n", (unsigned char)SYMBOL_SOF); fputc((char)OPCODE_REQ_NUM_CAMS,gCamout); dbgPrintOp("tx: 0x%02X\n", (unsigned char)OPCODE_REQ_NUM_CAMS); fflush(gCamout); readuntilchar(gCamin,SYMBOL_SOF); dbgPrintOp("tx: 0x%02X\n", (unsigned char)SYMBOL_SOF); indat[0] = readchar(gCamin); dbgPrintOp("tx: 0x%02X\n", (unsigned char)indat[0]); if(OPCODE_RESP_NUM_CAMS != (unsigned char)indat[0]) { assert(OPCODE_RESP_NUM_CAMS == (unsigned char)indat[0]); } numcams = readchar(gCamin); dbgPrintOp("tx: 0x%02X\n", (unsigned char)numcams); assert((0 < numcams) && (MAX_CAMS >= numcams)); // print numcams on stdout for pipe interface printf("%c",SYMBOL_SOF); printf("%c",OPCODE_RESP_NUM_CAMS); printf("%c",(unsigned char)numcams); fflush(stdout); while(1) { // TODO: should be a function fputc((char)SYMBOL_SOF,gCamout); fputc((char)OPCODE_SINGLE_FRAME,gCamout); fflush(gCamout); readuntilchar(gCamin,SYMBOL_SOF); dbgPrintOp("rx: 0x%02X\n", (unsigned char)SYMBOL_SOF); printf("%c",SYMBOL_SOF); indat[0] = readchar(gCamin); dbgPrintOp("rx: 0x%02X\n", (unsigned char)indat[0]); printf("%c",indat[0]); if(OPCODE_FRAME != (unsigned char)indat[0]) { assert(OPCODE_FRAME == (unsigned char)indat[0]); } totallen=0; indatloc=indat; while(FRAME_LEN*numcams > totallen) { readcnt = fread(indatloc,1,(FRAME_LEN*numcams)-totallen,gCamin); totallen+=readcnt; indatloc+=readcnt; } *indatloc = '\0'; printf("%s",indat); fflush(stdout); cc = getch(); // look for ESC key if(ESC_KEY == cc) { break; } } // tell listening program that we're done here printf("%c",SYMBOL_SOF); printf("%c",SYMBOL_EXIT); fflush(stdout); fclose(gCamin); fclose(gCamout); return 0; }