コード例 #1
0
ファイル: cmdline.c プロジェクト: borand/AVR
void cmdlineDoHistory(u08 action)
{
	switch(action)
	{
	case CMDLINE_HISTORY_SAVE:
		// copy CmdlineBuffer to history if not null string
		if( strlen(CmdlineBuffer) )
			strcpy(CmdlineHistory[0], CmdlineBuffer);
		break;
	case CMDLINE_HISTORY_PREV:
		// copy history to current buffer
		strcpy(CmdlineBuffer, CmdlineHistory[0]);
		// set the buffer position to the end of the line
		CmdlineBufferLength = strlen(CmdlineBuffer);
		CmdlineBufferEditPos = CmdlineBufferLength;
		// "re-paint" line
		cmdlineRepaint();
		break;
	case CMDLINE_HISTORY_NEXT:
		break;
	}
}
コード例 #2
0
ファイル: cmdline.c プロジェクト: borand/AVR
void cmdlineInputFunc(unsigned char c)
{
	u08 i;
	// process the received character

	// VT100 handling
	// are we processing a VT100 command?
	if(CmdlineInputVT100State == 2)
	{
		// we have already received ESC and [
		// now process the vt100 code
		switch(c)
		{
		case VT100_ARROWUP:
			cmdlineDoHistory(CMDLINE_HISTORY_PREV);
			break;
		case VT100_ARROWDOWN:
			cmdlineDoHistory(CMDLINE_HISTORY_NEXT);
			break;
		case VT100_ARROWRIGHT:
			// if the edit position less than current string length
			if(CmdlineBufferEditPos < CmdlineBufferLength)
			{
				// increment the edit position
				CmdlineBufferEditPos++;
				// move cursor forward one space (no erase)
				cmdlineOutputFunc(ASCII_ESC);
				cmdlineOutputFunc('[');
				cmdlineOutputFunc(VT100_ARROWRIGHT);
			}
			else
			{
				// else, ring the bell
				cmdlineOutputFunc(ASCII_BEL);
			}
			break;
		case VT100_ARROWLEFT:
			// if the edit position is non-zero
			if(CmdlineBufferEditPos)
			{
				// decrement the edit position
				CmdlineBufferEditPos--;
				// move cursor back one space (no erase)
				cmdlineOutputFunc(ASCII_BS);
			}
			else
			{
				// else, ring the bell
				cmdlineOutputFunc(ASCII_BEL);
			}
			break;
		default:
			break;
		}
		// done, reset state
		CmdlineInputVT100State = 0;
		return;
	}
	else if(CmdlineInputVT100State == 1)
	{
		// we last received [ESC]
		if(c == '[')
		{
			CmdlineInputVT100State = 2;
			return;
		}
		else
			CmdlineInputVT100State = 0;
	}
	else
	{
		// anything else, reset state
		CmdlineInputVT100State = 0;
	}

	// Regular handling
	if( (c >= 0x20) && (c < 0x7F) )
	{
		// character is printable
		// is this a simple append
		if(CmdlineBufferEditPos == CmdlineBufferLength)
		{
			// echo character to the output
			cmdlineOutputFunc(c);
			// add it to the command line buffer
			CmdlineBuffer[CmdlineBufferEditPos++] = c;
			// update buffer length
			CmdlineBufferLength++;
		}
		else
		{
			// edit/cursor position != end of buffer
			// we're inserting characters at a mid-line edit position
			// make room at the insert point
			CmdlineBufferLength++;
			for(i=CmdlineBufferLength; i>CmdlineBufferEditPos; i--)
				CmdlineBuffer[i] = CmdlineBuffer[i-1];
			// insert character
			CmdlineBuffer[CmdlineBufferEditPos++] = c;
			// repaint
			cmdlineRepaint();
			// reposition cursor
			for(i=CmdlineBufferEditPos; i<CmdlineBufferLength; i++)
				cmdlineOutputFunc(ASCII_BS);
		}
	}
	// handle special characters
	else if((c == ASCII_CR) | (c == ASCII_LF))
	{
		// user pressed [ENTER]
		// echo CR and LF to terminal

		//rprintf(""",""res"":");
		//rprintf(",");

		cmdlineOutputFunc(ASCII_CR);
		cmdlineOutputFunc(ASCII_LF);


		// add null termination to command
		CmdlineBuffer[CmdlineBufferLength++] = 0;
		CmdlineBufferEditPos++;
		// command is complete, process it
		cmdlineProcessInputString();
		// reset buffer
		CmdlineBufferLength = 0;
		CmdlineBufferEditPos = 0;
	}
	else if((c == ASCII_BS)|(c == ASCII_DEL))
	{
		if(CmdlineBufferEditPos)
		{
			// is this a simple delete (off the end of the line)
			if(CmdlineBufferEditPos == CmdlineBufferLength)
			{
				// destructive backspace
				// echo backspace-space-backspace
				cmdlineOutputFunc(ASCII_BS);
				cmdlineOutputFunc(' ');
				cmdlineOutputFunc(ASCII_BS);
				// decrement our buffer length and edit position
				CmdlineBufferLength--;
				CmdlineBufferEditPos--;
			}
			else
			{
				// edit/cursor position != end of buffer
				// we're deleting characters at a mid-line edit position
				// shift characters down, effectively deleting
				CmdlineBufferLength--;
				CmdlineBufferEditPos--;
				for(i=CmdlineBufferEditPos; i<CmdlineBufferLength; i++)
					CmdlineBuffer[i] = CmdlineBuffer[i+1];
				// repaint
				cmdlineRepaint();
				// add space to clear leftover characters
				cmdlineOutputFunc(' ');
				// reposition cursor
				for(i=CmdlineBufferEditPos; i<(CmdlineBufferLength+1); i++)
					cmdlineOutputFunc(ASCII_BS);
			}
		}
		else
		{
			// else, ring the bell
			cmdlineOutputFunc(ASCII_BEL);
		}
	}
//	else if(c == ASCII_DEL)
//	{
//		// not yet handled
//	}
	else if(c == ASCII_ESC)
	{
		CmdlineInputVT100State = 1;
	}
}
コード例 #3
0
ファイル: login.c プロジェクト: KhMassri/DTNWorkspace
void
UserLogin (char Temp)
{
  if (UserLoginStatus == WaitForUsername)
    {
      InputBufferUserPos = 0;
      UserLoginStatus = EnterUsername;
      Temp = '\r';
      bzero (InputBufferUser, InputBufferLen);
      bzero (InputBufferPass, InputBufferLen);
    }
  if (UserLoginStatus == EnterUsername)
    {
      if (Temp == '\r')
	{
	  if (InputBufferUserPos == 0)
	    DumpStringToUSB ("\n\rUsername>");
	  else
	    UserLoginStatus = WaitForPassword;
	}
      else if (InputBufferUserPos < InputBufferLen)
	{
	  InputBufferUser[InputBufferUserPos++] = Temp;
	  vSendByte (Temp);
	}
    }
  if (UserLoginStatus == WaitForPassword)
    {
      InputBufferPassPos = 0;
      UserLoginStatus = EnterPassword;
      Temp = '\r';
    }
  if (UserLoginStatus == EnterPassword)
    {
      if (Temp == '\r')
	{
	  if (InputBufferPassPos == 0)
	    DumpStringToUSB ("\n\rPassword>");
	  else
	    {
	      /*todo: check user dada */
	      if (InputBufferUser[0] == 'r' && InputBufferPass[0] == 'r')
		{
		  /*todo:  read/set User rights */
		  UserLoginStatus = LoggedIn;
		}
	      else
		UserLoginStatus = LoggedOut;
	    }
	}
      else if (InputBufferPassPos < InputBufferLen)
	{
	  InputBufferPass[InputBufferPassPos++] = Temp;
	  vSendByte (Temp);
	}
    }
  if (UserLoginStatus == LoggedIn)
    {
      DumpStringToUSB ("\n\r\n\r\n\rWelcome!\n\r\n\r");
      cmdlineRepaint ();
    }
  if (UserLoginStatus == LoggedOut)
    {
      DumpStringToUSB ("\n\r\n\r\n\rGood Bye, have a nive day!\n\r\n\r");
      UserLoginStatus = WaitForUsername;
    }
}