/** * Loop to Read commands in a Menu File. */ int MenuFunction::commandsReadData(const std::string &MenuName, const int &idx) { std::string path = getDirectoryPath(); path.append(MenuName); path.append(".menu"); int ret = 0; ret = commandsExist(MenuName,idx); if(ret < 1) return false; // Else Read and Parse it std::ifstream iFS; iFS.open(path.c_str()); if(!iFS.is_open()) { //errlog((char *)"Couldn't Open Menu Commands: %s\n", path.c_str()); return false; } CommandRecord cmdRecord; std::string cfgdata; for(;;) { std::getline(iFS, cfgdata, '\n'); commandsParse(cfgdata, idx, &cmdRecord); if(iFS.eof()) break; } iFS.close(); // Add to List of Commands. m_command_record.push_back(cmdRecord); return true; }
/* * Check if Command Exists (Used for Counting Commands) */ int MenuFunction::commandsExist(const std::string &MenuName, const int &idx) { //std::cout << "MenuFunction::cmdexist" << std::endl; std::string path = getDirectoryPath(); path.append(MenuName); path.append(".menu"); int ret = false; char sText[200]= {0}; // Open file for reading and parsing. std::ifstream iFS2; iFS2.open(path.c_str()); if(!iFS2.is_open()) { //errlog((char *)"Couldn't Open Menu Command [cmdexist()]: %s\n", path.c_str()); return ret; } // Loop Through and Find the The Command sprintf(sText,"[CommandRec%.03d]",idx); std::string cfgdata; std::string::size_type id1 = 0; while(std::getline(iFS2, cfgdata, '\n')) { id1 = cfgdata.find(sText, 0); if (id1 != std::string::npos) { ret = true; } } iFS2.close(); return ret; }
/* * Loop for Reading reading a menu */ int MenuFunction::menuReadData(const std::string &MenuName) { std::string path = getDirectoryPath(); path.append(MenuName); path.append(".menu"); std::cout << "Read Menu: " << path << std::endl; std::ifstream iFS; iFS.open(path.c_str()); if(!iFS.is_open()) { std::cout << "Error: Unable to Read Menu: " << path << std::endl; return false; } std::string cfgdata; while(std::getline(iFS,cfgdata,'\n')) { menuParseData(cfgdata); } iFS.close(); return true; }
bool CResourceGroupManager::getResourceFullPath(const std::string& resourceFileName, std::string& fullpath, E_RESOURCE_FILE_TYPE filetype) const { std::string dirPath; if (!getDirectoryPath(resourceFileName, dirPath, filetype)) return false; fullpath = dirPath + resourceFileName; return true; }
queryList* FSqueryTool( queryList *listpointer ) { void getDirectoryPath( ) ; void attributeDATE( ) ; void attributeNAME( ) ; resultList* attributeID( query *, int ) ; char oneLine[BUFFER_SIZE] ; // one line from the an opened file char *word ; // a token during string tokenization int numClauses ; queryList *tempQueries ; // a pointer to the query list arguement resultList *tempResults ; getDirectoryPath( ) ; tempQueries = listpointer ; tempResults = NULL ; while( tempQueries != NULL ) { for( numClauses = 0 ; numClauses <= tempQueries -> oneQuery -> numClauses ; numClauses++ ) { if( strcmp( tempQueries -> oneQuery -> myClauses[numClauses].attribute, "ID" ) == 0 ) { if( numClauses == 0 ) tempResults = attributeID( tempQueries -> oneQuery, numClauses ) ; else { if( strcmp( tempQueries -> oneQuery -> myClauses[numClauses-1].conjecture, "AND" ) == 0 ) tempResults = andResult( tempResults, attributeID( tempQueries -> oneQuery, numClauses ) ) ; if( strcmp( tempQueries -> oneQuery -> myClauses[numClauses-1].conjecture, "OR" ) == 0 ) tempResults = orResult(tempResults, attributeID( tempQueries -> oneQuery, numClauses ) ) ; } } if( strcmp( tempQueries -> oneQuery -> myClauses[numClauses].attribute, "DATE" ) == 0 ) { char fileTime[22] = { '\0' } ; dateResults = NULL; formatTimeStamp( fileTime, tempQueries -> oneQuery -> myClauses[numClauses].value ) ; fileQueryTime = parsedate( fileTime, NULL) ; strcpy( operatorType, tempQueries -> oneQuery -> myClauses[numClauses].operator ) ; attributeDATE( ) ; if( numClauses == 0 ) tempResults = dateResults ; else { if( strcmp( tempQueries -> oneQuery -> myClauses[numClauses-1].conjecture, "AND" ) == 0 ) tempResults = andResult( tempResults, dateResults ) ; if( strcmp( tempQueries -> oneQuery -> myClauses[numClauses-1].conjecture, "OR" ) == 0 ) tempResults = orResult( tempResults, dateResults ) ; } } if( strcmp( tempQueries -> oneQuery -> myClauses[numClauses].attribute, "NAME" ) == 0 ) { nameResults = NULL; strcpy( operatorType, tempQueries -> oneQuery -> myClauses[numClauses].operator ) ; strcpy( queryName, tempQueries -> oneQuery -> myClauses[numClauses].value ) ; attributeNAME( ) ; if( numClauses == 0 ) tempResults = nameResults ; else { if( strcmp( tempQueries -> oneQuery -> myClauses[numClauses-1].conjecture, "AND" ) == 0 ) tempResults = andResult( tempResults, nameResults ) ; if( strcmp( tempQueries -> oneQuery -> myClauses[numClauses-1].conjecture, "OR" ) == 0 ) tempResults = orResult( tempResults, nameResults ) ; } } } while ( tempResults != NULL ) { tempQueries -> oneQuery -> results = addResultItem( tempQueries -> oneQuery -> results, tempResults -> oneResult ) ; tempQueries -> oneQuery -> numFound++ ; tempResults = ( resultList* ) tempResults -> link ; } tempQueries = ( queryList* ) tempQueries -> link ; } return listpointer ; }
/** * Function to Read in a Menu set in the class */ void MenuFunction::menuStart(const std::string ¤tMenu) { if(m_previous_menu == currentMenu) { m_isLoadNewMenu = false; return ; } // Setup the current Menu Passed. m_curent_menu = currentMenu; std::string path = getDirectoryPath(); path.append(m_curent_menu); path.append(".menu"); FILE *fstr; fstr = fopen(path.c_str(),"rb+"); if(!fstr) { m_isLoadNewMenu = false; return; } else { fclose(fstr); } // Setup the Default Setting and And Clear Allocations. menuReload(); // Loading new Menu, Clear! if(!menuReadData(m_curent_menu)) { std::cout << "Error: menuStart() - Unable to Read Current Menu " << m_curent_menu << std::endl; return; } m_num_commands = commandsCount(m_curent_menu); // Clear And Reload Menu Commands. std::vector<CommandRecord>().swap(m_command_record); menuReadCommands(); m_isLoadNewMenu = false; if(m_num_commands == 0) { std::cout << "Error: No menu commands registered" << std::endl; return; } // Read Menu ANSI to String that will hold light-bars, Push to screen same-time // Will speed up display and make ghosting not appear as much if(m_menu_record.directive != "") { m_menu_io.displayMenuAnsi(m_menu_record.directive); } // First time load, Map Command Keys to HOTKEYS // If menu has changed, then reload commands. if(m_previous_menu != m_curent_menu) { // Reset Vector Lists. menuClearObjects(); m_first_commands_executed = 0; for(int i = 0; i != m_num_commands; i++) { // If we find a FIRSTCMD, Execute it right away! if(m_command_record[i].control_key == "FIRSTCMD") { menuDoCommands(&m_command_record[i]); ++m_first_commands_executed; continue; } // Get Light-bar Number of Commands // Registered as Light bars if(m_command_record[i].is_lightbar) { m_command_index.push_back(i); } // Check for Function Key Commands. if(m_command_record[i].control_key == "ESC") { //m_command_index_function.push_back(i); m_command_index_function.insert( std::make_pair(m_command_record[i].control_key, i) ); } else if(m_command_record[i].control_key == "LEFT") { //m_command_index_function.push_back(i); m_command_index_function.insert( std::make_pair(m_command_record[i].control_key, i) ); } else if(m_command_record[i].control_key == "RIGHT") { //m_command_index_function.push_back(i); m_command_index_function.insert( std::make_pair(m_command_record[i].control_key, i) ); } else if(m_command_record[i].control_key == "UP") { //m_command_index_function.push_back(i); m_command_index_function.insert( std::make_pair(m_command_record[i].control_key, i) ); } else if(m_command_record[i].control_key == "DOWN") { //m_command_index_function.push_back(i); m_command_index_function.insert( std::make_pair(m_command_record[i].control_key, i) ); } else if(m_command_record[i].control_key == "HOME") { //m_command_index_function.push_back(i); m_command_index_function.insert( std::make_pair(m_command_record[i].control_key, i) ); } else if(m_command_record[i].control_key == "END") { //m_command_index_function.push_back(i); m_command_index_function.insert( std::make_pair(m_command_record[i].control_key, i) ); } else if(m_command_record[i].control_key == "PAGEUP") { //m_command_index_function.push_back(i); m_command_index_function.insert( std::make_pair(m_command_record[i].control_key, i) ); } else if(m_command_record[i].control_key == "PAGEDN") { //m_command_index_function.push_back(i); m_command_index_function.insert( std::make_pair(m_command_record[i].control_key, i) ); } } // Return if we executed all commands as FIRSTCMD! if(m_first_commands_executed == m_num_commands) { return; } m_previous_menu = m_curent_menu; } m_output.clear(); // Set the Sizes m_num_esc_commands = m_command_index_function.size(); m_num_lightbar_commands = m_command_index.size(); if(m_num_lightbar_commands != 0) { // Throw out a menu prompt if there is one available. - Add MCI Parsing too! // Use Same X Row, these got reversed somehow!!! grrrr m_x_position = 1; m_y_position = m_command_record[m_command_index[0]].y_coord; } // Light-bar menu then draw if(m_num_lightbar_commands > 0) { // Setup of Remaining Light-bars in Low highlight Form for(int rep = 0; rep != m_num_lightbar_commands; rep++) { if(rep != m_choice) { m_x_position = m_command_record[m_command_index[rep]].x_coord; m_y_position = m_command_record[m_command_index[rep]].y_coord; sprintf(m_output_buffer,"\x1b[%i;%iH%s",m_y_position,m_x_position, (char *)m_command_record[m_command_index[rep]].inactive_string.c_str()); m_output += m_output_buffer; } else { m_x_position = m_command_record[m_command_index[rep]].x_coord; m_y_position = m_command_record[m_command_index[rep]].y_coord; sprintf(m_output_buffer,"\x1b[%i;%iH%s",m_y_position,m_x_position, (char *)m_command_record[m_command_index[rep]].active_string.c_str()); m_output += m_output_buffer; } } // Moves cursor to end of line during light-bars. sprintf(m_output_buffer,"\x1b[%i;79H",m_y_position); m_output += m_output_buffer; m_menu_io.sequenceToAnsi(m_output); } // Not Light-bars, print out menu ANSI. else { m_menu_io.sequenceToAnsi(m_output); } //Replace Messages Left... m_output.clear(); m_output = m_menu_record.menu_prompt; // If light-bar prompt, reset to beginning of line. if(m_num_lightbar_commands > 0) { m_x_position = 1; sprintf(m_output_buffer,"\x1b[%i;%iH%s",m_y_position,m_x_position, (char *)m_menu_record.menu_prompt.c_str()); m_output = m_output_buffer; } if(m_output.size() > 1) { m_menu_io.sequenceToAnsi(m_output); } }
int printDirectoryInDirectory(FILE * fp, Directory * directory, void * data) { if(directory->path) { myfprintf(fp,"directory: %s\n", getDirectoryPath(directory)); } return 0; }