Esempio n. 1
0
void CConsoleEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	if( nChar == 13 )
	{
		MoveToEnd();
		Refresh();
		CString allText;
		GetWindowText(allText);
		allText = allText.Mid(m_last_title_pos);
		strncpy(m_cmd,allText,
			allText.GetLength() > (sizeof(m_cmd)-1)
			?
			sizeof(m_cmd)-1 : allText.GetLength()
			);
		
		// 回车
		CEdit::OnChar(nChar, nRepCnt, nFlags);
		// 保存命令
		SaveCommand(m_cmd);
		// 发送给父窗口
		LRESULT result = SendMessageToParent(m_cmd,NM_CONSOLE_ENTER);
		// 清空命令
		memset(m_cmd,0,sizeof(m_cmd));
		// 根据父窗口返回值
		// 父窗口返回0,表示处理完毕,需要返回初始命令状态
		if (!result)
		{
			// 回车(空一行)
			CEdit::OnChar(nChar, nRepCnt, nFlags);
			// 添加初始命令提示
			AddTexts(m_pretitle);
		}
		return;
	}
	else
	{
		if (nChar == 8)
		{
			if (GetCurrentPosition() <= m_last_title_pos)
				return;
		}
		// 输入必须在m_last_title_pos之后
		if (GetCurrentPosition() < m_last_title_pos)
			MoveToEnd();

	}
/**************改用字符比较********************/
	CEdit::OnChar(nChar, nRepCnt, nFlags);
}
Esempio n. 2
0
void CConsoleEdit::OnMenuPlaster()
{
	int nStart,nEnd;
	GetSel(nStart,nEnd);
	if(nStart == nEnd)
	{
		// 粘贴
		MoveToEnd();
		Paste();
		CString alltext;
		GetWindowText(alltext);
		MoveToEnd();
		// 得到命令
		alltext = alltext.Mid(m_last_title_pos,m_nLength-m_last_title_pos);
		strncpy(m_cmd,alltext,alltext.GetLength()>sizeof(m_cmd)?sizeof(m_cmd):alltext.GetLength());
	}
}
Esempio n. 3
0
void CConsoleEdit::OnMenuCopy()
{
	int nStart,nEnd;
	GetSel(nStart,nEnd);
	if(nStart != nEnd)
	{
		Copy();
		MoveToEnd();
		m_bcopy = true;
	}
}
Esempio n. 4
0
void OOPLyric::GoTo(double percentage, wxDC *pDC, bool bPaused) {
    wxASSERT(IsOk());

    if (percentage == 1) {
        MoveToEnd(pDC);
        return;
    }

    //==============================================

    m_currLine = m_parser->WhichLine(m_parser->GetTimeSum() * percentage);
    if (m_currLine == m_parser->end()) {
        wxLogDebug(L"Wrong position.");
        return;
    }

    //==============================================

    m_timer.Stop();
    RefreshLyric(pDC, bPaused);
}
Esempio n. 5
0
// 增加字符
// CEdit显示内容有限制,当超过该限制时,需要删除原来的内容,再增加内容
void CConsoleEdit::AddTexts(const char* str, int len)
{
	if(len == -1)	len = strlen(str);
	//KDebug("%d %d", m_nLength, len);
	if ((m_nLength + len) > MAX_DATA_NUM)
	{
		SetSel(0, len + 128, TRUE);
		ReplaceSel("");
		if (len > MAX_DATA_NUM)
		{
			CString result(str);
			result = result.Right(MAX_DATA_NUM);
			ReplaceSel(result);
			return;
		}
	}
	MoveToEnd();
	ReplaceSel(str);

	if (strcmp(str,m_pretitle)==0)
		m_last_title_pos = SendMessage( WM_GETTEXTLENGTH );
}
Esempio n. 6
0
/* ARGSUSED */
static void
InsertChar (
    Widget	ctxw,
    XEvent	*event,
    String	*params,
    Cardinal	*num_params)
{
    LoginWidget ctx = (LoginWidget)ctxw;

    char strbuf[128];
#ifndef XPM
    int  len;
#else
    int  len,pixels;
#endif /* XPM */
    KeySym  keysym = 0;

    if (ctx->login.xic) {
	static Status status;
	len = XmbLookupString(ctx->login.xic, &event->xkey, strbuf,
			      sizeof (strbuf), &keysym, &status);
    } else {
	static XComposeStatus compose_status = {NULL, 0};
	len = XLookupString (&event->xkey, strbuf, sizeof (strbuf),
			     &keysym, &compose_status);
    }
    strbuf[len] = '\0';

#ifdef XPM
    pixels = 3 + ctx->login.font->max_bounds.width * len +
    	     XTextWidth(ctx->login.font,
    	     		ctx->login.data.name,
    	     		strlen(ctx->login.data.name));
    	     	/* pixels to be added */
#endif /* XPM */

    /*
     * Note: You can override this default key handling
     * by the settings in the translation table
     * loginActionsTable at the end of this file.
     */
    switch (keysym) {
    case XK_Return:
    case XK_KP_Enter:
    case XK_Linefeed:
    case XK_Execute:
	FinishField(ctxw, event, params, num_params);
	return;
    case XK_BackSpace:
	DeleteBackwardChar(ctxw, event, params, num_params);
	return;
    case XK_Delete:
    case XK_KP_Delete:
    case DXK_Remove:
	/* Sorry, it's not a telex machine, it's a terminal */
	DeleteForwardChar(ctxw, event, params, num_params);
	return;
    case XK_Left:
    case XK_KP_Left:
	MoveBackwardChar(ctxw, event, params, num_params);
	return;
    case XK_Right:
    case XK_KP_Right:
	MoveForwardChar(ctxw, event, params, num_params);
	return;
    case XK_End:
    case XK_KP_End:
	MoveToEnd(ctxw, event, params, num_params);
	return;
    case XK_Home:
    case XK_KP_Home:
	MoveToBegining(ctxw, event, params, num_params);
	return;
    default:
	if (len == 0) {
	    if (!IsModifierKey(keysym))  /* it's not a modifier */
		XBell(XtDisplay(ctxw), 60);
	    return;
	} else
	    break;
    }

    switch (ctx->login.state) {
    case GET_NAME:
#ifndef XPM
	if (len + (int)strlen(ctx->login.data.name) >= NAME_LEN - 1)
#else
	if (
	        (len + (int)strlen(ctx->login.data.name) >= NAME_LEN - 1)/* &&
		(pixels <= LOGIN_W(ctx) - PROMPT_W(ctx))*/
	   )
#endif /* XPM */
	    len = NAME_LEN - strlen(ctx->login.data.name) - 2;
    case GET_PASSWD:
	if (len + (int)strlen(ctx->login.data.passwd) >= PASSWORD_LEN - 1)
	    len = PASSWORD_LEN - strlen(ctx->login.data.passwd) - 2;
    }
#ifndef XPM
    if (len == 0)
#else
    if (len == 0 || pixels >= LOGIN_W(ctx) - PROMPT_W(ctx))
#endif /* XPM */
	return;
    XorCursor (ctx);
    RemoveFail (ctx);
    switch (ctx->login.state) {
    case GET_NAME:
	EraseName (ctx, ctx->login.cursor);
	memmove( ctx->login.data.name + ctx->login.cursor + len,
	       ctx->login.data.name + ctx->login.cursor,
	       strlen (ctx->login.data.name + ctx->login.cursor) + 1);
	memmove( ctx->login.data.name + ctx->login.cursor, strbuf, len);
	DrawName (ctx, ctx->login.cursor);
	ctx->login.cursor += len;
	break;
    case GET_PASSWD:
	memmove( ctx->login.data.passwd + ctx->login.cursor + len,
	       ctx->login.data.passwd + ctx->login.cursor,
	       strlen (ctx->login.data.passwd + ctx->login.cursor) + 1);
	memmove( ctx->login.data.passwd + ctx->login.cursor, strbuf, len);
	ctx->login.cursor += len;

#ifdef XPM
	/*as good a place as any Caolan begin*/
	ctx->login.lastEventTime = time(NULL);
	/*as good a place as any Caolan end*/
#endif /* XPM */
	break;
    }
    XorCursor (ctx);
}
//------------------------------RemoveEmpty------------------------------------
// Remove empty basic blocks and useless branches.  
void PhaseCFG::RemoveEmpty() {
  // Move uncommon blocks to the end
  uint last = _num_blocks;
  uint i;
  assert( _blocks[0] == _broot, "" );
  for( i = 1; i < last; i++ ) {
    Block *b = _blocks[i];

    // Check for NeverBranch at block end.  This needs to become a GOTO to the
    // true target.  NeverBranch are treated as a conditional branch that
    // always goes the same direction for most of the optimizer and are used
    // to give a fake exit path to infinite loops.  At this late stage they
    // need to turn into Goto's so that when you enter the infinite loop you
    // indeed hang.
    if( b->_nodes[b->end_idx()]->Opcode() == Op_NeverBranch ) 
      convert_NeverBranch_to_Goto(b);

    // Look for uncommon blocks and move to end.  But dont' move the
    // root's successor block so it can remain the fall-through path.
    if( b->is_uncommon(_bbs) && (!b->pred(1) || _bbs[b->pred(1)->_idx] != _broot) ) {
      MoveToEnd(b, i);
      last--;                   // No longer check for being uncommon!
      if( no_flip_branch(b) ) { // Fall-thru case must follow?
        b = _blocks[i];         // Find the fall-thru block
        MoveToEnd(b, i);
        last--;
      }
      i--;                      // backup block counter post-increment
    }
  }

  // Remove empty blocks
  uint j1;
  last = _num_blocks;
  for( i=0; i < last; i++ ) {
    Block *b = _blocks[i];
    if (i > 0) {
      if (b->is_Empty() != Block::not_empty) {
        MoveToEnd(b, i);
        last--;
        i--;
      }
    }
  } // End of for all blocks

  // Fixup final control flow for the blocks.  Remove jump-to-next
  // block.  If neither arm of a IF follows the conditional branch, we
  // have to add a second jump after the conditional.  We place the
  // TRUE branch target in succs[0] for both GOTOs and IFs.
  for( i=0; i < _num_blocks; i++ ) {
    Block *b = _blocks[i];
    b->_pre_order = i;          // turn pre-order into block-index

    // Connector blocks need no further processing.
    if (b->is_connector()) {
      assert((i+1) == _num_blocks || _blocks[i+1]->is_connector(), 
             "All connector blocks should sink to the end");
      continue;
    }
    assert(b->is_Empty() != Block::completely_empty, 
           "Empty blocks should be connectors");

    Block *bnext = (i < _num_blocks-1) ? _blocks[i+1] : NULL;
    Block *bs0 = b->non_connector_successor(0);

    // Check for multi-way branches where I cannot negate the test to
    // exchange the true and false targets.
    if( no_flip_branch( b ) ) {
      // Bubble-sort the trailing projections.  Means the default target is
      // always listed first.  Makes reading the ASM code much easier,
      // especially for 3-way branches like LADD.
      int branch_idx = b->_nodes.size() - b->_num_succs;
for(uint j2=0;j2<b->_num_succs-1;j2++){
const ProjNode*p2=b->_nodes[branch_idx+j2]->as_Proj();
for(uint j3=j2+1;j3<b->_num_succs;j3++){
const ProjNode*p3=b->_nodes[branch_idx+j3]->as_Proj();
          if( p2->_con > p3->_con ) {
            b->_nodes.map(branch_idx + j2,(Node*)p3);
            b->_nodes.map(branch_idx + j3,(Node*)p2);
Block*btmp2=b->_succs[j2];
Block*btmp3=b->_succs[j3];
            b->_succs.map(j2,btmp3);
            b->_succs.map(j3,btmp2);
            p2 = p3;
          }
        }
      }
      // Find fall through case - if must fall into its target
      const ProjNode* p = b->_nodes[branch_idx + 0]->as_Proj();
      if( p->_con == 0 && b->non_connector_successor(0) != bnext ) // successor 0 is fall through case
        // but it is not the next block => insert a goto
insert_goto_at(i,0);
      // Remove all CatchProjs
      for (j1 = 0; j1 < b->_num_succs; j1++) b->_nodes.pop();        

    } else if (b->_num_succs == 1) {
      // Block ends in a Goto?
      if (bnext == bs0) {
        // We fall into next block; remove the Goto
        b->_nodes.pop();
      }

    } else if( b->_num_succs == 2 ) { // Block ends in a If?
      // Get opcode of 1st projection (matches _succs[0])
      // Note: Since this basic block has 2 exits, the last 2 nodes must
      //       be projections (in any order), the 3rd last node must be
      //       the IfNode (we have excluded other 2-way exits such as
      //       CatchNodes already).
      MachNode *iff   = b->_nodes[b->_nodes.size()-3]->as_Mach();
      ProjNode *proj0 = b->_nodes[b->_nodes.size()-2]->as_Proj();
      ProjNode *proj1 = b->_nodes[b->_nodes.size()-1]->as_Proj();

      // Assert that proj0 and succs[0] match up. Similarly for proj1 and succs[1].
      assert(proj0->raw_out(0) == b->_succs[0]->head(), "Mismatch successor 0");
      assert(proj1->raw_out(0) == b->_succs[1]->head(), "Mismatch successor 1");

      Block *bs1 = b->non_connector_successor(1);

      // Check for neither successor block following the current 
      // block ending in a conditional. If so, move one of the 
      // successors after the current one, provided that the
      // successor was previously unscheduled, but moveable 
      // (i.e., all paths to it involve a branch).
      if( bnext != bs0 && bnext != bs1 ) {

        // Choose the more common successor based on the probability
        // of the conditional branch.
        Block *bx = bs0;
        Block *by = bs1;

        // _prob is the probability of taking the true path. Make
        // p the probability of taking successor #1.
        float p = iff->as_MachIf()->_prob;
        if( proj0->Opcode() == Op_IfTrue ) {
          p = 1.0 - p;
        }
        
        // Prefer successor #1 if p > 0.5
        if (p > PROB_FAIR) {
          bx = bs1;
          by = bs0;
        }

        // Attempt the more common successor first
        if (MoveToNext(bx, i)) {
          bnext = bx;
        } else if (MoveToNext(by, i)) {
          bnext = by;
        }
      }

      // Check for conditional branching the wrong way.  Negate
      // conditional, if needed, so it falls into the following block
      // and branches to the not-following block.
      
      // Check for the next block being in succs[0].  We are going to branch
      // to succs[0], so we want the fall-thru case as the next block in 
      // succs[1].
      if (bnext == bs0) {      
        // Fall-thru case in succs[0], so flip targets in succs map
        Block *tbs0 = b->_succs[0];
        Block *tbs1 = b->_succs[1];
        b->_succs.map( 0, tbs1 );
        b->_succs.map( 1, tbs0 );
        // Flip projection for each target
        { ProjNode *tmp = proj0; proj0 = proj1; proj1 = tmp; }

      } else if( bnext == bs1 ) { // Fall-thru is already in succs[1]

      } else {                  // Else need a double-branch

        // The existing conditional branch need not change.
        // Add a unconditional branch to the false target.
        // Alas, it must appear in its own block and adding a
        // block this late in the game is complicated.  Sigh.
        insert_goto_at(i, 1);
      }

      // Make sure we TRUE branch to the target
      if( proj0->Opcode() == Op_IfFalse )
        iff->negate();
      
      b->_nodes.pop();          // Remove IfFalse & IfTrue projections
      b->_nodes.pop();
      
    } else {
      // Multi-exit block, e.g. a switch statement
      // But we don't need to do anything here
    }

  } // End of for all blocks

}
Esempio n. 8
0
// 这个是为了显示的时候初始内容不被选中
void CConsoleEdit::OnTimer(UINT nIDEvent) 
{
	MoveToEnd();
	CEdit::OnTimer(nIDEvent);
	KillTimer(1);
}