// D: Mounts an array of agents corresponding to the elements of an array // concept void CDTTManagerAgent::MountAgentsFromArrayConcept( CDialogAgent *pdaParent, // the parent where the agents will be mounted string sArrayConceptName, // the name of the array concept string sAgentsType, // the type of the agents to be mounted string sAgentsName, // the name for the agents to be mounted // this should normally include a # somewhere // which will get replaced by the index string sAgentsConceptName, // the name of the concept for each agent string sAgentsDynamicID) // the dynamic id to use for each agent // this can be any string containing #, // and # will be replaced by the index { // go through the array and for each element create and mount an agent for(int i = 0; i < pdaParent->C(sArrayConceptName).GetSize(); i++) { CDialogAgent* pNewAgent = pDTTManager->MountAgent(pdaParent, sAgentsType, ReplaceSubString(sAgentsName, "#", FormatString("%d", i)), "", mmAsLastChild); // if the agent has a concept associated with it, give it the part // of the array if(sAgentsConceptName != "") { pNewAgent->C(sAgentsConceptName) = pdaParent->C("%s.%d", sArrayConceptName.c_str(), i); } // set the agent index in the array pNewAgent->SetDynamicAgentID( ReplaceSubString(sAgentsDynamicID, "#", FormatString("%d", i))); } }
/** \brief Construct an error object. \param [in] szMsg The error message text. \param [in] iPos the position related to the error. \param [in] sTok The token string related to this error. */ ParserError::ParserError(const char_type *szMsg, int iPos, const string_type &sTok) :m_strMsg(szMsg) ,m_strFormula() ,m_strTok(sTok) ,m_iPos(iPos) ,m_iErrc(ecGENERIC) ,m_ErrMsg(ParserErrorMsg::Instance()) { stringstream_type stream; stream << (int)m_iPos; ReplaceSubString(m_strMsg, _T("$POS$"), stream.str()); ReplaceSubString(m_strMsg, _T("$TOK$"), m_strTok); }
/** \brief Construct an error object. \param [in] iErrc the error code. \param [in] iPos the position in the expression where the error occurred. \param [in] sTok The token string related to this error. */ ParserError::ParserError(EErrorCodes iErrc, int iPos, const string_type &sTok) :m_strMsg() ,m_strFormula() ,m_strTok(sTok) ,m_iPos(iPos) ,m_iErrc(iErrc) ,m_ErrMsg(ParserErrorMsg::Instance()) { m_strMsg = m_ErrMsg[m_iErrc]; stringstream_type stream; stream << (int)m_iPos; ReplaceSubString(m_strMsg, _T("$POS$"), stream.str()); ReplaceSubString(m_strMsg, _T("$TOK$"), m_strTok); }
/** \brief Replace all occurences of a substring with another string. */ void ParserError::ReplaceSubString( string_type &sSource, const string_type &sFind, char_type cReplaceWith) const { stringstream_type stream; stream << cReplaceWith; ReplaceSubString(sSource, sFind, stream.str()); }
//------------------------------------------------------------------------------ string_type ParserError::GetMsg() const { string_type sMsg(m_sMsg); ReplaceSubString(sMsg, _T("$EXPR$"), m_Err.Expr); ReplaceSubString(sMsg, _T("$IDENT$"), m_Err.Ident); ReplaceSubString(sMsg, _T("$POS$"), m_Err.Pos); ReplaceSubString(sMsg, _T("$ARG$"), m_Err.Arg); ReplaceSubString(sMsg, _T("$TYPE1$"), m_Err.Type1); ReplaceSubString(sMsg, _T("$TYPE2$"), m_Err.Type2); ReplaceSubString(sMsg, _T("$HINT$"), m_Err.Hint); return sMsg; }
/* * CheckAbbrev - look for an abbreviation, and expand it */ bool CheckAbbrev( const char *data, int *ccnt ) { int i, j, owl, col; alias_list *curr; size_t len; if( EditFlags.Modeless ) { return( false ); } /* * get the current string, and matching alias */ len = *ccnt; *ccnt = 0; if( len == 0 ) { return( false ); } curr = checkGenericAlias( data, len, abHead ); if( curr == NULL ) { return( false ); } i = CurrentPos.column - 1 - len; j = CurrentPos.column - 2; /* * replace with full form */ owl = WorkLine->len; WorkLine->len = ReplaceSubString( WorkLine->data, WorkLine->len, i, j, curr->expand, strlen( curr->expand ) ); col = CurrentPos.column + WorkLine->len - owl; GoToColumn( col, WorkLine->len + 1 ); return( true ); } /* CheckAbbrev */
/* * Substitute - perform substitution */ vi_rc Substitute( linenum n1, linenum n2, char *data ) { char *sstr, *rstr, *newr; char flag[20], *linedata; bool iflag = false; bool gflag = false; bool undoflag = false; bool restline = false; bool splitpending = false; bool undoline = false; int i, rlen, slen; bool splitme; long changecnt = 0, linecnt = 0; linenum llineno, ll, lastline = 0, extra; i_mark pos; vi_rc rc; LastSubstituteCancelled = 0; LastChangeCount = 0; LastLineCount = 0; sstr = alloca( MAX_INPUT_LINE ); if( sstr == NULL ) { return( ERR_NO_STACK ); } strcpy( sstr, data ); rc = ModificationTest(); if( rc != ERR_NO_ERR ) { return( rc ); } strcpy( data, sstr ); rstr = alloca( MAX_INPUT_LINE ); if( rstr == NULL ) { return( ERR_NO_STACK ); } if( NextWordSlash( data, sstr ) < 0 ) { return( ERR_INVALID_SUBS_CMD ); } if( NextWordSlash( data, rstr ) < 0 ) { return( ERR_INVALID_SUBS_CMD ); } slen = NextWord1( data, flag ); for( i = 0; i < slen; i++ ) { switch( flag[i] ) { case 'g': gflag = true; break; case 'i': case 'c': iflag = true; break; } } rc = CurrentRegComp( sstr ); if( rc != ERR_NO_ERR ) { return( rc ); } /* * verify last line */ if( n2 > CurrentFile->fcbs.tail->end_line ) { rc = CFindLastLine( &ll ); if( rc != ERR_NO_ERR ) { return( rc ); } if( n2 > ll ) { return( ERR_INVALID_LINE_RANGE ); } } /* * set for start of search */ if( EditFlags.Verbose && EditFlags.EchoOn ) { ClearWindow( MessageWindow ); } SaveCurrentFilePos(); llineno = n1 - 1; EditFlags.AllowRegSubNewline = true; newr = StaticAlloc(); for( pos.column = 0, pos.line = n1; pos.line <= n2; nextSearchStartPos( &pos, gflag, rlen ) ) { /* * get regular expression, and build replacement string */ rc = FindRegularExpression( NULL, &pos, &linedata, n2, 0 ); if( rc != ERR_NO_ERR || pos.line > n2 ) { break; } slen = GetCurrRegExpLength(); splitme = RegSub( CurrentRegularExpression, rstr, newr, pos.line ); rlen = strlen( newr ); ProcessingMessage( pos.line ); /* * if in global mode, see if we already have an undo for * this line */ if( gflag ) { if( lastline != pos.line ) { undoline = false; } } /* * interactive mode? yes, then display text and ask to change */ if( iflag ) { change_resp rsp; if( !restline ) { ClearWindow( MessageWindow ); } restline = true; GoToLineNoRelCurs( pos.line ); if( EditFlags.GlobalInProgress ) { EditFlags.DisplayHold = false; DCDisplayAllLines(); EditFlags.DisplayHold = true; } HilightSearchString( &pos, slen ); rsp = ChangePrompt(); if( rsp == CHANGE_NO ) { ResetDisplayLine(); rlen = 1; continue; } else if( rsp == CHANGE_CANCEL ) { ResetDisplayLine(); LastSubstituteCancelled = 1; break; } else if( rsp == CHANGE_ALL ) { ResetDisplayLine(); iflag = false; } } /* * set up for global undo if we haven't already */ if( !undoflag ) { StartUndoGroup( UndoStack ); undoflag = true; } /* * bump change counts */ changecnt++; if( llineno != pos.line ) { if( splitpending ) { splitpending = false; extra = SplitUpLine( llineno ); n2 += extra; pos.line += extra; } linecnt++; llineno = pos.line; } /* * get copy of line, and verify that new stuff fits */ CurrentPos.line = pos.line; rc = CGimmeLinePtr( pos.line, &CurrentFcb, &CurrentLine ); if( rc != ERR_NO_ERR ) { break; } if( CurrentLine->len + rlen - slen >= EditVars.MaxLine ) { rc = ERR_LINE_FULL; break; } /* * now build the individual undo */ CurrentFcb->non_swappable = true; if( !undoline ) { CurrentLineReplaceUndoStart(); CurrentLineReplaceUndoEnd( true ); if( gflag ) { undoline = true; lastline = pos.line; } } /* * remove the old string */ GetCurrentLine(); WorkLine->len = ReplaceSubString( WorkLine->data, WorkLine->len, pos.column, pos.column + slen - 1, newr, rlen ); if( iflag ) { DisplayWorkLine( true ); } ReplaceCurrentLine(); /* * if not global, only do this change on this line */ if( splitme ) { splitpending = true; } CurrentFcb->non_swappable = false; } StaticFree( newr ); EditFlags.AllowRegSubNewline = false; /* * is there still a split line pending? */ if( splitpending ) { SplitUpLine( llineno ); } RestoreCurrentFilePos(); if( restline ) { SetCurrentLine( CurrentPos.line ); GoToColumnOK( CurrentPos.column ); } if( undoflag ) { EndUndoGroup( UndoStack ); } switch( rc ) { case ERR_NO_ERR: case ERR_LINE_FULL: case ERR_FIND_PAST_TERM_LINE: case ERR_FIND_NOT_FOUND: case ERR_FIND_END_OF_FILE: /* * display results */ if( rc == ERR_LINE_FULL ) { Message1( "Stopped at line %l - line full", pos.line ); } else { Message1( "%l changes on %l lines", changecnt, linecnt ); LastLineCount = linecnt; LastChangeCount = changecnt; } DCDisplayAllLines(); rc = ERR_NO_ERR; break; default: break; } return( rc ); } /* Substitute */