char* getQuery(int index) { char *messages[AMOUNT_OF_QUERIES] = {GET_SEARCH_QUERY_MESSAGE_1, GET_SEARCH_QUERY_MESSAGE_2, GET_SEARCH_QUERY_MESSAGE_3, GET_SEARCH_QUERY_MESSAGE_4}; char *string = (char *) malloc(SIZE_OF_STRING); if (!string || index < 0 || index > AMOUNT_OF_QUERIES) return NULL; printf(messages[index]); fgets(string, SIZE_OF_STRING, stdin); removeLineBreak(string); return string; }
void TextBuffer::removeChar(TextLoc &loc ) { if ( loc.chr == 0 && loc.line == 0 ) { return; } else if ( loc.chr == 0 && loc.line > 0 ) { removeLineBreak(loc); } else { startEdit( loc.shift(0,-1), loc); _lines[loc.line].remChar(loc.chr--); endEdit(loc,loc); } }
int main(int argc, char *argv[]) { /**/ setlocale(LC_ALL, ""); int i, index, silent; int validFilesCount = 0; char *query = NULL; char dirPath[FILE_PATH_SIZE]; char dirPathCopy[FILE_PATH_SIZE]; StringCel *fileName = NULL; StringList fileNamesList = NULL; FileStats fileStats; memset(&fileStats, 0, sizeof(FileStats)); Mp3Data mp3Data; memset(&mp3Data, 0, sizeof(Mp3Data)); // Setting up arrays for easier handling Node trees[AMOUNT_OF_TREES]; void (*treeInsertFunctions[AMOUNT_OF_TREES]) (Node*, Mp3Data*) = {addToTitleAVL, addToArtistAVL, addToAlbumAVL, addToYearAVL}; void (*treeSearchFunctions[AMOUNT_OF_TREES]) (Node, char *) = {searchTitleAVL, searchArtistAVL, searchAlbumAVL, searchYearAVL}; memset(trees, 0, sizeof(trees)); do { printf(FILE_PATH_QUERY); fgets(dirPath, FILE_PATH_SIZE, stdin); removeLineBreak(dirPath); if(!strlen(dirPath)) continue; printf(SILENT_QUERY); silent = toupper(getchar()); fflush(stdin); strcpy(dirPathCopy, dirPath); reformatPath(dirPathCopy); // Searching for mp3 files in folder findFilesByExtensionWin(&fileNamesList, dirPathCopy, EXT_TO_SEARCH, &fileStats, silent != 'S'); if(!fileNamesList) { printf(FILE_PATH_ERROR); } } while (!fileNamesList); printf(FINISHED_SEARCHING_MESSAGE); /**/ // For every file found, adding it to trees while(fileNamesList) { fileName = (StringCel *) removeFromTopSL(&fileNamesList); if (readMp3Tag(fileName->string, &mp3Data)) { for (i = 0; i < AMOUNT_OF_TREES; i++) { treeInsertFunctions[i](trees+i, &mp3Data); } validFilesCount++; } free(fileName); fileName = NULL; } /**/ while(1) { index = getIndex(); system("cls"); if (index == MENU_OPTIONS_AMOUNT - 2) { break; } else if (index == -1) { printf(STATS_MESSAGE, fileStats.filesFound, fileStats.dirsSearched, validFilesCount, count(trees[1]), count(trees[2]), count(trees[3])); } else { query = getQuery(index); if (!query) break; treeSearchFunctions[index](trees[index], query); } } /**/ return 0; }