int main(int argc, char* argv[]) { //***System.out.println("MLCS Version 1.0\n"); //get input parameters and initialize global variables if(argc<3){ printf("Too few parameters! Please provide parameters in order as follows,\n"); printf("(1) The number of Strings.\n"); printf("(2) Alphabet size (4 or 20).\n"); printf("(3) Input file name.\n"); exit(1); } MAXSTR = atoi(argv[1]); ABC_len = atoi(argv[2]); if (ABC_len==4){ ABC_str = ABC_str_4; ABC_idx = ABC_idx_4; }else if (ABC_len==20){ ABC_str = ABC_str_20; ABC_idx = ABC_idx_20; }else{ printf("Unsupported alphabet size!\n"); return 1; } strcpy(data_file_fullname, argv[3]); //check the content of the input sequence file FILE *my_file = fopen(data_file_fullname, "r"); if (my_file == NULL) { printf("Empty string file: %s!\n", data_file_fullname); return 1; } else { MAXSTRSIZE = 0; char cur_line[10000]; while (!feof(my_file)) { fscanf(my_file, "%s\n", cur_line); //sscanf(cur_line, "%s", cur_line); int len = strlen(cur_line); if (!len) continue; if (len > MAXSTRSIZE) MAXSTRSIZE = len; cur_n_str ++; } fclose(my_file); } if (cur_n_str == 0){ printf("\nNumber of input strings is %d.\n", cur_n_str); return 1; }else if (MAXSTR > cur_n_str){ MAXSTR = cur_n_str; } printf("\nNumber of input strings is %d.\n", MAXSTR); //allocate memory for global variables data = Allocate2DArray<char>(MAXSTR, MAXSTRSIZE+1); str_lngth = new int[MAXSTR]; //read input strings and do preprocessing cur_n_str = 0; int i, j; my_file = fopen(data_file_fullname, "r"); while (!feof(my_file) && (cur_n_str < MAXSTR)) { fscanf(my_file, "%s\n", data[cur_n_str]); int len = strlen(data[cur_n_str]); if (!len)continue; str_lngth[cur_n_str]=len; //printf("string N%d: '%s'\n", cur_n_str, data[cur_n_str]); cur_T.push_back(Allocate2DArray<short>(len+1, ABC_len)); for (i=0; i<ABC_len; i++) { cur_T[cur_n_str][len][i] = len+1; } for (j=len-1; j>=0; j--) { for (i=0; i<ABC_len; i++) { cur_T[cur_n_str][j][i] = cur_T[cur_n_str][j+1][i]; } cur_T[cur_n_str][j][ABC_idx[data[cur_n_str][j]-'A']] = j; } cur_n_str ++; } fclose(my_file); ComputeM(); //find MLCS of strings Mainloop(); //release memory Free2DArray<char>(data); delete[] str_lngth; for (i=0; i<cur_T.size(); i++){ short** temp = cur_T[i]; Free2DArray<short>(temp); } for (i=0; i<(MAXSTR+1)/2; i++) { short** temp = cur_M[i]; Free2DArray<short>(temp); } printf("Done!\n"); return 0; }
/*========================================================================= // Name: main() // Desc: Entrypoint //=======================================================================*/ int main(int argc, char *argv[]) { printf("-----------------------------------------------------\n"); printf(" BlueCube (improved version v0.9 hosted on github) \n"); printf(" just another tetris clone, \n"); printf(" written by Sebastian Falbesoner <theStack> \n"); printf("-----------------------------------------------------\n"); /* First, check whether sound should be activated */ bSoundActivated = 1; if ((argc == 2) && (strcmp(argv[1], "--nosound") == 0)) { printf("No sound is used!\n"); bSoundActivated = 0; } /* Init randomizer */ printf("Initializing randomizer... "); srand(time(NULL)); printf("done.\n"); /* Let's init the graphics and sound system */ printf("Starting up SDL... "); InitSDLex(); printf("done.\n"); if (bSoundActivated) { printf("Initializing sound subsystem... "); InitSound(); printf("done.\n"); } /* Load font */ printf("Loading font files... "); font = LoadFontfile("font/font.dat", "font/widths.dat"); printf("done.\n"); /* Load soundfiles */ if (bSoundActivated) { printf("Loading sound files... "); LoadSound("sound/killline.snd", &sndLine); LoadSound("sound/nextlev.snd", &sndNextlevel); printf("done.\n"); } printf("=== Let the fun begin! ===\n"); /* Init star background */ InitStars(); if (bSoundActivated) { ClearPlayingSounds(); SDL_PauseAudio(0); } /* Start menu first, please... */ gamestate = STATE_MENU; /* Call main loop */ Mainloop(); /* Free sounds again */ if (bSoundActivated) { printf("Releasing memory for sound samples... "); SDL_FreeWAV(sndLine.samples); SDL_FreeWAV(sndNextlevel.samples); printf("done.\n"); } /* Free font again */ printf("Releasing memory for fonts... "); FreeFont(font); printf("done.\n"); return 0; }