std::string CXBindingsCppHandlersGenerator::FindRealTypeFor( const std::string& typeBase ) { std::string type = typeBase; if( boost::algorithm::contains(type,":") ) { type = after_first( type, ':' ); } std::string realType; std::string newType = type; std::string oldType; if( IsBaseType( type ) ) { newType = GetBaseType(type); oldType = type; } else { CXBindingsStringStringMap::iterator it = m_types.find( type ); while( it != m_types.end() && newType != oldType) { oldType = newType; newType = it->second; it = m_types.find( newType ); } if( newType != "enum" ) newType = "object"; } realType = newType; return realType; }
/* Returns number of characters at the beginning of the str which form one * logical symbol. Takes UTF-8 encoding and terminal escape sequences into * account. */ static size_t get_char_width_esc(const char str[]) { return (*str == '\033') ? (size_t)(after_first(str, 'm') - str) : utf8_chrw(str); }
std::string CXBindingsGenerator::GetRealType( const std::string& typeBase , CXBindingsGeneratorOptions& options ) { std::string type = typeBase; if( boost::algorithm::contains(type,":") ) { type = after_first( type, ':' ); } std::string realType = type; std::string ns; if( IsKnownType( type ) ) { CXBindingsStringStringMap& types = m_genfile->GetTypeInfo().GetTypes(); CXBindingsStringStringMap::iterator it = types.find( type ); if( it == types.end() ) { return type; } return it->second; } if( boost::algorithm::contains(realType,":") ) { ns = before_first( realType , ':' ); realType = after_first( realType, ':' ); } //if( ns.empty() ) //ns = options.ns; realType = GetObjectName( realType , options ); //realType = ns + realType; CXBindingsStringStringMap& types = m_genfile->GetTypeInfo().GetTypes(); types[type] = realType; //wxLogMessage( type + " - ") + realType ; return realType; }
/* Menu-specific shortcut handler. Returns code that specifies both taken * actions and what should be done next. */ static KHandlerResponse filetypes_khandler(menu_info *m, const wchar_t keys[]) { if(wcscmp(keys, L"c") == 0) { const char *prog_str = after_first(m->data[m->pos], '|'); if(prog_str[0] != '\0') { menu_morph_into_cmdline(CLS_COMMAND, prog_str, 1); return KHR_MORPHED_MENU; } } return KHR_UNHANDLED; }
/* Menu-specific shortcut handler. Returns code that specifies both taken * actions and what should be done next. */ static KHandlerResponse commands_khandler(menu_info *m, const wchar_t keys[]) { if(wcscmp(keys, L"dd") == 0) { /* Remove element. */ char cmd_buf[512]; break_at(m->items[m->pos], ' '); snprintf(cmd_buf, sizeof(cmd_buf), "delcommand %s", m->items[m->pos]); execute_cmdline_command(cmd_buf); remove_current_item(m); return KHR_REFRESH_WINDOW; } else if(wcscmp(keys, L"c") == 0) { const char *const rhs = skip_whitespace(after_first(m->items[m->pos], ' ')); /* Insert command RHS. */ if(rhs[0] == ':') { menu_morph_into_cmdline(CLS_COMMAND, skip_whitespace(rhs + 1), 0); } else if(rhs[0] == '/') { menu_morph_into_cmdline(CLS_FSEARCH, rhs + 1, 0); } else if(rhs[0] == '=') { menu_morph_into_cmdline(CLS_FILTER, rhs + 1, 0); } else { /* filter commands go here. */ menu_morph_into_cmdline(CLS_COMMAND, rhs, (rhs[0] != '!')); } return KHR_MORPHED_MENU; } return KHR_UNHANDLED; }
/* Builds the mount command based on the file type program. * Accepted formats are: * FUSE_MOUNT|some_mount_command %SOURCE_FILE %DESTINATION_DIR [%FOREGROUND] * and * FUSE_MOUNT2|some_mount_command %PARAM %DESTINATION_DIR [%FOREGROUND] * %CLEAR is an obsolete name of %FOREGROUND. * Always sets value of *foreground. */ TSTATIC void format_mount_command(const char mount_point[], const char file_name[], const char param[], const char format[], size_t buf_size, char buf[], int *foreground) { char *buf_pos; const char *prog_pos; char *escaped_path; char *escaped_mount_point; *foreground = 0; escaped_path = escape_filename(file_name, 0); escaped_mount_point = escape_filename(mount_point, 0); buf_pos = buf; buf_pos[0] = '\0'; prog_pos = after_first(format, '|'); while(*prog_pos != '\0') { if(*prog_pos == '%') { char cmd_buf[96]; char *cmd_pos; cmd_pos = cmd_buf; while(*prog_pos != '\0' && *prog_pos != ' ') { *cmd_pos = *prog_pos; if(cmd_pos - cmd_buf < sizeof(cmd_buf)) cmd_pos++; prog_pos++; } *cmd_pos = '\0'; if(!strcmp(cmd_buf, "%SOURCE_FILE")) { copy_str(buf_pos, buf_size - (buf_pos - buf), escaped_path); buf_pos += strlen(buf_pos); } else if(!strcmp(cmd_buf, "%PARAM")) { copy_str(buf_pos, buf_size - (buf_pos - buf), param); buf_pos += strlen(buf_pos); } else if(!strcmp(cmd_buf, "%DESTINATION_DIR")) { copy_str(buf_pos, buf_size - (buf_pos - buf), escaped_mount_point); buf_pos += strlen(buf_pos); } else if(!strcmp(cmd_buf, "%FOREGROUND") || !strcmp(cmd_buf, "%CLEAR")) { *foreground = 1; } } else { *buf_pos = *prog_pos; if(buf_pos - buf < buf_size - 1) buf_pos++; prog_pos++; } } *buf_pos = '\0'; free(escaped_mount_point); free(escaped_path); }
CXBindingsHandlerFileInfo CXBindingsCppHandlersGenerator::DoGenerateRuleCodeFor( CXBindingsRuleInfo& ruleInfo , CXBindings& grammar , CXBindingsGeneratorOptions& options ) { CXBindingsHandlerFileInfo res; //wxLogMessage( "\t\t Rule make is : ") + ruleInfo.make ; //wxLogMessage( "\t\t Rule name is : ") + ruleInfo.name.content ; //wxLogMessage( "\t\t Rule type is : ") + ruleInfo.type.content ; CXBindingsStringStringMap& types = m_genfile->GetTypeInfo().GetTypes(); std::string realType = ruleInfo.type.content; //wxLogMessage( "\t\t Real type is : ") + realType ; if( ruleInfo.make =="object") realType = ruleInfo.name.content; std::string typeTemplate = ruleInfo.type.stemplate; CXBindingsStringStringMap::iterator it = types.find( realType ); std::string typeExt = GetRealType( realType , options ); // if( !IsKnownType( realType ) ) // typeExt = GetRealType( realType , options ); // if( it != types.end() ) { typeExt = it->second; //typeExt = realType; } //wxLogMessage( "\t\t Real type is : ") + realType ; if( boost::contains(realType,":") ) realType = after_first(realType,':') ; //wxLogMessage( "\t\t Real type is : ") + realType ; std::string savedType = realType; // Find here type corrspondances std::string rType = FindRealTypeFor( realType ); if( ruleInfo.make =="object") rType = "object" ; if( ruleInfo.make =="child_enumerator") rType = "enum" ; if( typeTemplate == "array") { //realType = "std::vector< ") + realType + wxT(" >" ; rType = "array" + rType; } //wxLogMessage( "Registering type for : ") + ruleInfo.name.content + " type is :") + realType + wxT(" ") + rType + wxT(" rule make is :" + ruleInfo.make ; m_types[ruleInfo.name.content] = rType; if( ruleInfo.make == "import") { // We have to add here all informations about the object from which this one is derived // this information is contained in the realType variable /* for each element in the info object of the grammar */ CXBindings& grammar = m_interpreterInfo.grammar; CXBindingsInfo& info = grammar.GetInfo(); CXBindingsArrayString genOrder = info.GetGeneration().GetObjects(); /* The first thing to do is to estabilsh the generation objects dependecy list * So that object will be generated in the right order... */ CXBindingsArrayString dependencies; for( unsigned int i = 0; i < genOrder.size() ; ++i ){ CXBindingsArrayGrammarObjectInfoMap& objectsInfoMap = m_interpreterInfo.objects; CXBindingsArrayGrammarObjectInfo& objectsInfo = objectsInfoMap[genOrder[i]]; for( unsigned int j = 0; j < objectsInfo.size() ; ++j ) { std::string name = objectsInfo[j].properties["name" ]; name = GetRealType( name , options ); //wxLogMessage( "Checking bases for") + name + "-") + typeExt + wxT("-" + realType ; if( name == typeExt ) { std::pair< std::string , CXBindingsHandlerFileInfo> inf( name , m_objectInfos[name] ); res.bases.push_back( inf ); //wxLogMessage( "Adding bases for") + name + "-") + typeExt + wxT("-" + realType ; return res; } } } std::pair< std::string , CXBindingsHandlerFileInfo> inf( typeExt , m_objectInfos[typeExt] ); res.bases.push_back( inf ); return res; } if( ruleInfo.make == "property") { std::pair< std::string , std::string > mpair( ruleInfo.name.content , typeExt ); res.properties.push_back( mpair ); } else if( ruleInfo.make == "attribute") { std::pair< std::string , std::string > mpair( ruleInfo.name.content , typeExt ); res.attributes.push_back( mpair ); } if( ruleInfo.make == "property" || ruleInfo.make == "attribute" || ruleInfo.make == "variant_accessor" || ruleInfo.make == "variant_array_accessor") { std::pair< std::string , std::string > mpair( ruleInfo.name.content , typeExt ); res.dependencies.push_back( mpair ); } return res; }