예제 #1
0
파일: cmdline.c 프로젝트: borand/realtime
void cmdlinePrintError(void)
{
	u08 * ptr;

	rprintf("\"",cmd_prompt_index);
	// print a notice header
	// (u08*) cast used to avoid compiler warning
	ptr = (u08*)CmdlineNotice;
	while(pgm_read_byte(ptr)) cmdlineOutputFunc( pgm_read_byte(ptr++) );

	// print the offending command
	ptr = CmdlineBuffer;
	while((*ptr) && (*ptr != ' ')) cmdlineOutputFunc(*ptr++);

	cmdlineOutputFunc(':');
	cmdlineOutputFunc(' ');

	// print the not-found message
	// (u08*) cast used to avoid compiler warning
	ptr = (u08*)CmdlineCmdNotFound;
	while(pgm_read_byte(ptr)) cmdlineOutputFunc( pgm_read_byte(ptr++) );

	rprintf("\"");
	cmdlinePrintPromptEnd();
}
예제 #2
0
파일: cmdline.c 프로젝트: borand/AVR
void cmdlineRepaint(void)
{
	u08* ptr;
	u08 i;

	// carriage return
	cmdlineOutputFunc(ASCII_CR);
	// print fresh prompt
	cmdlinePrintPrompt();
	// print the new command line buffer
	i = CmdlineBufferLength;
	ptr = CmdlineBuffer;
	while(i--) cmdlineOutputFunc(*ptr++);
}
예제 #3
0
파일: cmdline.c 프로젝트: lanwan/avrlib2
void cmdlinePrintError(void)
{
	uint8_t * ptr;

	// print a notice header
	// (uint8_t*) cast used to avoid compiler warning
	ptr = (uint8_t*)CmdlineNotice;
	while(pgm_read_byte(ptr)) cmdlineOutputFunc( pgm_read_byte(ptr++) );
	
	// print the offending command
	ptr = CmdlineBuffer;
	while((*ptr) && (*ptr != ' ')) cmdlineOutputFunc(*ptr++);

	cmdlineOutputFunc(':');
	cmdlineOutputFunc(' ');

	// print the not-found message
	// (uint8_t*) cast used to avoid compiler warning
	ptr = (uint8_t*)CmdlineCmdNotFound;
	while(pgm_read_byte(ptr)) cmdlineOutputFunc( pgm_read_byte(ptr++) );

	cmdlineOutputFunc('\r');
	cmdlineOutputFunc('\n');
}
예제 #4
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;
	}
}
예제 #5
0
void cmdlinePrintPrompt(void)
{
	// print a new command prompt
	u08* ptr = CmdlinePrompt;
	while(pgm_read_byte(ptr)) cmdlineOutputFunc( pgm_read_byte(ptr++) );
}