int main( int argc, char** argv ) { try{ PlatformSpecific::RegisterExceptionHandler(); std::cout << "ModernGDV Build " __DATE__ << std::endl; //Banner auf Konsole ausgeben printManual(); std::clog << std::fixed << std::setprecision( 4 ); //Kommandozeilenparameter in vector lesen std::vector<std::string> commandline; for (int i = 0; i < argc; ++i) commandline.push_back( std::string( argv[i] ) ); ModernGDV::Driver mgdv; { MyApp myApp( commandline, &mgdv ); mgdv.Run(); mgdv.SetApp( nullptr ); } return 0; } catch (std::exception& ex) { std::cerr << "\nUnhandled exception: " << ex.what() << "\n\n"; system( "pause" ); return -1; } catch ( ... ) { std::cerr << "\nUnhandled exception: Unknown exception\n\n"; system( "pause" ); return -1; } }
void printHelp() { if (cfg.help) { printManual(); exit(EXIT_SUCCESS); } }
int main(int argc, const char ** argv ) { cmd = (char*) *argv++; --argc; section = (char*) *argv++; --argc; manual = (char*) *argv++; --argc; stralloc tempCMD1 = {0}; tempCMD1 = generateSearchCMD( manual,tempCMD1); int fd[2]; pipe(fd); int status; pid_t child; if ( (child = fork() ) < 0 ) { return 0; } else if( child == 0 ) { dup2(fd[1],1); close(fd[0]); close(fd[1]); system(tempCMD1.s); stralloc_free(&tempCMD1); exit(255); } else { stralloc tempCMD2 = {0}; ssize_t nbytes; char buff[64]; close(fd[1]); while(( nbytes = read(fd[0] , buff , sizeof buff )) > 0 ) { stralloc_catb( &tempCMD2 , buff , nbytes ); }; stralloc temp = {0}; stralloc_copys( &temp , cmdCAT ); stralloc_cat( &temp , &tempCMD2 ); char *t = temp.s; printManual(t); stralloc_free(&tempCMD2); stralloc_free(&temp); } close(fd[0]); close(fd[1]); wait(&status); return 0; }
int main(int argc, char** argv ) { int fd; /* file descriptor */ char comm[20]; /* point to command string */ bzero(comm, sizeof(comm)); char rbuf[RCVBUF_SIZE]; /* receive buffer */ __tod_t texp; /* to receive the expended time */ int r; char* port = "/dev/ttyUSB0"; speed_t speed = B9600; switch ( argc ) { case 2: if (!strcmp(argv[1], "--help") || !strcmp (argv[1], "-h") ) printManual(); else printHelp(); exit(-1); case 3: contstr(argv[1], argv[2], comm ); break; case 4: contstr( argv[1], argv[2], comm ); speed = consspeed( argv[3] ); break; case 5: contstr( argv[1], argv[2], comm ); speed = consspeed( argv[3] ); port = argv[4]; break; default: printHelp(); exit ( -1 ); } fd = sio_open( port, speed, DATA_BITS_8, NO_PARITY, ONE_STOP_BIT); if (fd == ERR_PORT_OPEN) { printf("open port failed!\n"); return (-1); } comm[strlen(comm)] = '\r'; printf("send command: %s\n", comm ); sio_set_noncan(fd); sio_set_timer(fd, 0, 10); /* set timeout for 1 sec */ r = i7k_send_readt(fd, comm, rbuf, RCVBUF_SIZE, &texp); //char* cmd = "$01P\r"; //r = i7k_send_readt(fd, cmd, rbuf, RCVBUF_SIZE, &texp); char buff[16]; memcpy (buff, rbuf+1, 15); switch (r) { case 0: printf("time-out!\ntime expended: %llu us\n", texp); break; case -1: printf("error!\ntime expended: %llu us\n", texp); break; default: printf("ret: %s\ntime expended: %llu us\n", buff, texp); break; } sio_close(fd); return (0); }
int main(int argc, char *argv[]) { int i, j; /* processing of input parameters */ if (argc==1) {printManual(); return 0;} char algoname[100]; strcpy(algoname,argv[1]); char parameter[100]; if(argc>2) strcpy(parameter,argv[2]); char filename[100] = "source/bin/"; strcat(filename,algoname); FILE *fp = fopen(filename, "r"); if( !fp ) { if(!VERBOSE) printf("\n\tERROR: unable to execute program %s\n\n",filename); exit(1); } fclose(fp); //allocate space for text in shered memory srand( time(NULL) ); key_t tkey = rand()%1000; int try = 0; do { tkey = rand()%1000; tshmid = shmget(tkey, YSIZE*2, IPC_CREAT | 0666); } while(++try<ATTEMPT && tshmid<0); if (tshmid < 0) { perror("shmget"); exit(1); } if ((T = shmat(tshmid, NULL, 0)) == (unsigned char *) -1) { perror("shmat"); free_shm(); exit(1); } //allocate space for running time in shered memory srand( time(NULL) ); key_t ekey = rand()%1000; try = 0; do { ekey = rand()%1000; eshmid = shmget(ekey, 8, IPC_CREAT | 0666); } while((++try<ATTEMPT && eshmid<0) || ekey==tkey); if (eshmid < 0) { perror("shmget"); free_shm(); exit(1); } if ((e_time = shmat(eshmid, NULL, 0)) == (double *) -1) { perror("shmat"); free_shm(); exit(1); } //allocate space for preprocessing running time in shered memory key_t prekey = rand()%1000; try = 0; do { prekey = rand()%1000; preshmid = shmget(prekey, 8, IPC_CREAT | 0666); } while((++try<ATTEMPT && preshmid<0) || prekey==tkey || prekey==ekey); if (preshmid < 0) { perror("shmget"); free_shm(); exit(1); } if ((pre_time = shmat(preshmid, NULL, 0)) == (double *) -1) { perror("shmat"); free_shm(); exit(1); } for(i=0; i<SIGMA; i++) FREQ[i] = 0; //allocate space for pattern in shered memory key_t pkey = rand()%1000; try = 0; do { pkey = rand()%1000; pshmid = shmget(pkey, XSIZE+1, IPC_CREAT | 0666); } while((++try<ATTEMPT && pshmid<0) || pkey==tkey || pkey==ekey || pkey==prekey); if (pshmid < 0) { perror("shmget"); free_shm(); exit(1); } if ((P = shmat(pshmid, NULL, 0)) == (unsigned char *) -1) { perror("shmat"); free_shm(); exit(1); } for(i=0; i<SIGMA; i++) FREQ[i] = 0; //allocate space for the result number of occurrences in shared memory int *count; key_t rkey = rand()%1000; try = 0; do { rkey = rand()%1000; rshmid = shmget(rkey, 4, IPC_CREAT | 0666); } while((++try<ATTEMPT && rshmid<0) || rkey==tkey || rkey==pkey || pkey==ekey || pkey==prekey); if (rshmid < 0) { perror("shmget"); free_shm(); exit(1); } if ((count = shmat(rshmid, NULL, 0)) == (int *) -1) { perror("shmat"); free_shm(); exit(1); } if(!VERBOSE) printf("\n\tPlease, wait a moment.............."); fflush(stdout); //begin testing int rip = 0; int alpha, k, h, m, occur1, occur2, test=1; /*for(alpha = 2; alpha<=128; alpha*=2) { for(i=0; i<YSIZE; i++) T[i] = rand()%alpha; // compute the frequency of characters //for(j=0; j<SIGMA; j++) FREQ[j]=0; //for(j=0; j<YSIZE; j++) FREQ[T[j]]++; for(m = 2; m<=16; m*=2) { for(j=0; j<10; j++) { rip++; printf("\b\b\b\b\b\b[%.3d%%]",rip*10/28); fflush(stdout); (*count) = 0; k = j*2; for(h=0; h<m; h++) P[h] = T[k+h]; P[m]='\0'; occur1 = search(P,m,T,YSIZE); occur2 = execute(algoname,pkey,m,tkey,YSIZE,rkey,ekey,prekey,count,alpha); if(occur2>=0 && occur1 != occur2) { if(!VERBOSE) printf("\n\tERROR: test failed\n\n"); free_shm(); exit(1); } } } }*/ // 1) search for "a" in "aaaaaaaaaa" strcpy((char*)P,"a"); strcpy((char*)T,"aaaaaaaaaa"); if(!attempt(&rip,count,P,1,T,10,algoname,pkey,tkey,rkey,ekey,prekey,alpha,parameter,1)) exit(1); // 2) search for "aa" in "aaaaaaaaaa" strcpy((char*)P,"aa"); strcpy((char*)T,"aaaaaaaaaa"); if(!attempt(&rip,count,P,2,T,10,algoname,pkey,tkey,rkey,ekey,prekey,alpha,parameter,2)) exit(1); // 3) search for "aaaaaaaaaa" in "aaaaaaaaaa" strcpy((char*)P,"aaaaaaaaaa"); strcpy((char*)T,"aaaaaaaaaa"); if(!attempt(&rip,count,P,10,T,10,algoname,pkey,tkey,rkey,ekey,prekey,alpha,parameter,3)) exit(1); // 4) search for "b" in "aaaaaaaaaa" strcpy((char*)P,"b"); strcpy((char*)T,"aaaaaaaaaa"); if(!attempt(&rip,count,P,1,T,10,algoname,pkey,tkey,rkey,ekey,prekey,alpha,parameter,4)) exit(1); // 5) search for "abab" in "ababababab" strcpy((char*)P,"ab"); strcpy((char*)T,"ababababab"); if(!attempt(&rip,count,P,2,T,10,algoname,pkey,tkey,rkey,ekey,prekey,alpha,parameter,5)) exit(1); // 6) search for "a" in "ababababab" strcpy((char*)P,"a"); strcpy((char*)T,"ababababab"); if(!attempt(&rip,count,P,1,T,10,algoname,pkey,tkey,rkey,ekey,prekey,alpha,parameter,6)) exit(1); // 7) search for "aba" in "ababababab" strcpy((char*)P,"aba"); strcpy((char*)T,"ababababab"); if(!attempt(&rip,count,P,3,T,10,algoname,pkey,tkey,rkey,ekey,prekey,alpha,parameter,7)) exit(1); // 8) search for "abc" in "ababababab" strcpy((char*)P,"abc"); strcpy((char*)T,"ababababab"); if(!attempt(&rip,count,P,3,T,10,algoname,pkey,tkey,rkey,ekey,prekey,alpha,parameter,8)) exit(1); // 9) search for "ba" in "ababababab" strcpy((char*)P,"ba"); strcpy((char*)T,"ababababab"); if(!attempt(&rip,count,P,2,T,10,algoname,pkey,tkey,rkey,ekey,prekey,alpha,parameter,8)) exit(1); // 10) search for "babbbbb" in "ababababab" strcpy((char*)P,"babbbbb"); strcpy((char*)T,"ababababab"); if(!attempt(&rip,count,P,7,T,10,algoname,pkey,tkey,rkey,ekey,prekey,alpha,parameter,10)) exit(1); // 11) search for "bcdefg" in "bcdefghilm" strcpy((char*)P,"bcdefg"); strcpy((char*)T,"bcdefghilm"); if(!attempt(&rip,count,P,6,T,10,algoname,pkey,tkey,rkey,ekey,prekey,alpha,parameter,11)) exit(1); // 12) search for rand in rand for(h=0; h<10; h++) T[h] = rand()%128; for(h=0; h<4; h++) P[h] = T[h]; T[YSIZE] = P[4] = '\0'; if(!attempt(&rip,count,P,4,T,10,algoname,pkey,tkey,rkey,ekey,prekey,alpha,parameter,12)) exit(1); // 13) search for rand in rand for(h=0; h<10; h++) T[h] = rand()%128; for(h=0; h<4; h++) P[h] = T[h]; T[10] = P[4] = '\0'; if(!attempt(&rip,count,P,4,T,10,algoname,pkey,tkey,rkey,ekey,prekey,alpha,parameter,13)) exit(1); // 14) search for rand in rand for(h=0; h<64; h++) T[h] = rand()%128; for(h=0; h<40; h++) P[h] = T[h]; T[64] = P[40] = '\0'; if(!attempt(&rip,count,P,40,T,64,algoname,pkey,tkey,rkey,ekey,prekey,alpha,parameter,14)) exit(1); // 15) search for rand in rand for(h=0; h<64; h++) T[h] = rand()%128; for(h=0; h<40; h++) P[h] = T[h]; T[64] = P[40] = '\0'; if(!attempt(&rip,count,P,40,T,64,algoname,pkey,tkey,rkey,ekey,prekey,alpha,parameter,15)) exit(1); // 16) search for rand in rand for(h=0; h<64; h++) T[h] = 'a'; for(h=0; h<40; h++) P[h] = 'a'; T[64] = P[40] = '\0'; if(!attempt(&rip,count,P,40,T,64,algoname,pkey,tkey,rkey,ekey,prekey,alpha,parameter,16)) exit(1); // 17) search for rand in rand for(h=0; h<64; h+=2) T[h] = 'a'; for(h=1; h<64; h+=2) T[h] = 'b'; for(h=0; h<40; h+=2) P[h] = 'a'; for(h=1; h<40; h+=2) P[h] = 'b'; T[64] = P[40] = '\0'; if(!attempt(&rip,count,P,40,T,64,algoname,pkey,tkey,rkey,ekey,prekey,alpha,parameter,17)) exit(1); // 18) search for rand in rand for(h=0; h<64; h+=2) T[h] = 'a'; for(h=1; h<64; h+=2) T[h] = 'b'; for(h=0; h<40; h+=2) P[h] = 'a'; for(h=1; h<40; h+=2) P[h] = 'b'; P[39] = 'c'; T[64] = P[40] = '\0'; if(!attempt(&rip,count,P,40,T,64,algoname,pkey,tkey,rkey,ekey,prekey,alpha,parameter,18)) exit(1); // 19) search for "babbbbb" in "abababbbbb" strcpy((char*)P,"babbbbb"); strcpy((char*)T,"abababbbbb"); if(!attempt(&rip,count,P,7,T,10,algoname,pkey,tkey,rkey,ekey,prekey,alpha,parameter,19)) exit(1); // 20) search for "bababb" in "abababbbbb" strcpy((char*)P,"bababb"); strcpy((char*)T,"abababbbbb"); if(!attempt(&rip,count,P,6,T,10,algoname,pkey,tkey,rkey,ekey,prekey,alpha,parameter,20)) exit(1); if(!VERBOSE) printf("\n\tWell done! Test passed successfully\n\n"); //free shared memory free_shm(); return 0; }
int main(int argc, const char *argv[]) { int EXECUTE[NumAlgo]; char *ALGO_NAME[NumAlgo]; char *ALGO_DESCRIPTION[NumAlgo]; char *PATH[NumAlgo]; char filename[20], command[100]; int i,j; getAlgo(ALGO_NAME,EXECUTE); /* processing of input parameters */ if (argc==1) {printf("\n\tNo parameter given. Use -h for help.\n\n"); return 0;} if (!strcmp("-h", argv[1])) {printManual(); return 0;} int par = 1; while(par<argc) { int selected = 0; if (par<argc && !strcmp("-show", argv[par])) { par++; //shows all algorithms printf("The list of all string matching algorithms\n"); for(i=0; i<NumAlgo; i++) if(ALGO_NAME[i]) { printf("%s\n",ALGO_NAME[i]); } return 1; } if (par<argc && !strcmp("-which", argv[par])) { par++; //shows all selected algorithms printf("\n\tThe list of selected algorithms:\n"); for(i=0; i<NumAlgo; i++) if(ALGO_NAME[i] && EXECUTE[i]) { printf("\t-%s\n",ALGO_NAME[i]); } printf("\n"); return 1; } if (par<argc && !strcmp("-add", argv[par])) { par++; if(par>=argc) {printf("\n\n\tError in input parameters. Use -h for help.\n\n"); return 0;} strcpy(filename, argv[par++]); char path[50] = "source/bin/"; strcat(path,filename); FILE *fp = fopen(path, "r"); if( fp ) { //the file exists if(search_ALGO(ALGO_NAME,filename)>=0) printf("\n\n\tSMART error message\n\tError in input parameters....algorithm %s already in the set\n\n",filename); else { printf("\n\n\tAdding the algorithm %s to SMART\n",filename); fflush(stdout); printf("\tTesting the algorithm for correctness...."); fflush(stdout); //testing correctness of the algorithm sprintf(command,"./test ../bin/%s -nv",filename); fflush(stdout); if(system(command)) { printf("failed!\n"); printf("\tThe system is unable to add the algorithm %s to SMART.\n\tPlease, check for algorithm's correctness.\n\n",filename); } else { printf("ok\n"); for(i=0; i<NumAlgo && ALGO_NAME[i]; i++); EXECUTE[i] = 0; ALGO_NAME[i] = filename; printf("\tAlgorithm %s added succesfully.\n\n",filename); } } } else printf("\n\n\tSMART error message\n\tError in input parameters....program %s does not exist\n\n",path); } if (par<argc && !strcmp("-group", argv[par])) { par++; if(par>=argc) {printf("\n\n\tError in input parameters. Use -h for help.\n\n"); return 0;} strcpy(filename, argv[par++]); char path[50] = "source/bin/"; strcat(path,filename); FILE *fp = fopen(path, "r"); if( fp ) { //the file exists if(search_ALGO(ALGO_NAME,filename)>=0) printf("\n\n\tSMART error message\n\tError in input parameters....algorithm %s already in the set\n\n",filename); else { printf("\n\n\tAdding the algorithm %s to SMART\n",filename); fflush(stdout); printf("\tTesting the algorithm for correctness...."); fflush(stdout); //testing correctness of the algorithm sprintf(command,"./test ../bin/%s -nv",filename); fflush(stdout); if(system(command)) { printf("failed!\n"); printf("\tThe system is unable to add the algorithm %s to SMART.\n\tPlease, check for algorithm's correctness.\n\n",filename); } else { printf("ok\n"); for(i=0; i<NumAlgo && ALGO_NAME[i]; i++); EXECUTE[i] = 0; ALGO_NAME[i] = filename; printf("\tAlgorithm %s added succesfully.\n\n",filename); } } } else printf("\n\n\tSMART error message\n\tError in input parameters....program %s does not exist\n\n",path); } for(i=0; i<NumAlgo; i++) if(ALGO_NAME[i]) { if (par<argc && !strcmp(argv[par],ALGO_NAME[i])) { par++; if(EXECUTE[i]==0) { EXECUTE[i]=1; printf("\tThe %s algorithm has been selected\n",ALGO_NAME[i]); } else { EXECUTE[i]=0; printf("\tThe %s algorithm has been deselected\n",ALGO_NAME[i]); } selected = 1; } } if(selected) continue; if (par<argc && !strcmp("-all", argv[par])) { par++; for(i=0; i<NumAlgo; i++) if(ALGO_NAME[i]) EXECUTE[i]=1; continue; } if (par<argc && !strcmp("-none", argv[par])) { par++; for(i=0; i<NumAlgo; i++) if(ALGO_NAME[i]) EXECUTE[i]=0; continue; } if (par<argc) {printf("\tError in input parameters....no parameter %s\n\n",argv[par]); return 0;} } int order[NumAlgo]; for(i=0; i<NumAlgo; i++) order[i] = i; for(i=0; i<NumAlgo; i++) for(j=0; j<NumAlgo; j++) if(ALGO_NAME[order[j]] && ALGO_NAME[order[j+1]] && strcmp(ALGO_NAME[order[j]],ALGO_NAME[order[j+1]])>0) { int tmp = order[j]; order[j] = order[j+1]; order[j+1] = tmp; } FILE *fp = fopen("source/algorithms.h", "w"); for(j=0; j<NumAlgo; j++) if(ALGO_NAME[j]) fprintf(fp,"#%d #%s \n", EXECUTE[order[j]], ALGO_NAME[order[j]] ); fclose(fp); }
int main(int argc, const char * argv[]) { arguments_t arguments; atexit(cleanUp); parseArguments(argc - 1, &argv[1], &arguments); if (!arguments.fileName) { printManual(); return 0; } if (!readWad(&wad, arguments.fileName)) { printf("could not open %s.\n", argv[1]); return -1; } if (wad.type != NOWAD) { printf("reading file %s.\n", wad.name); } else { printf("%s is not a valid wad file.", wad.name); return -1; } if (arguments.badArgument) { printf("\n\"%s\" is not a valid option.\n\n", arguments.badArgument); printHelp(); return 0; } if (arguments.flags == ARG_NONE) { printf("\nnothing to do.\n\n"); printHelp(); return 0; } if (arguments.flags & ARG_HEADER) { printSeparator(); printHeader(&wad); } if (arguments.flags & ARG_DIRECTORY) { printSeparator(); printDirectory(&wad); } if (arguments.flags & ARG_PNAMES) { printSeparator(); printPNames(&wad); } if (arguments.flags & ARG_TEXTURE1) { printSeparator(); printTextures(&wad, "TEXTURE1"); } if (arguments.flags & ARG_TEXTURE2) { printSeparator(); printTextures(&wad, "TEXTURE2"); } if (arguments.flags & ARG_COLORMAP) { printSeparator(); printColormaps(&wad); } return 0; }