Example #1
0
void putchar_raw(uint8_t c)
{
	usb_tx_buffer[usb_tx_len++] = c;
	if (usb_tx_len == sizeof(usb_tx_buffer))
	{
		flush_stdout();
	}
}
int phantom_console_window_putc(int c)
{
#if TIMED_FLUSH
    phantom_undo_timed_call( &cons_timer );
#endif

#if NET_TIMED_FLUSH
    cancel_net_timer(&cons_upd_timer);
#endif

    switch(c)
    {
    case '\b':
        if(cbufpos > 0) cbufpos--;
        goto noflush;
        //return c;

    case '\t':
        while(cbufpos % 8)
        {
            if(cbufpos >= BUFS)
                break;
            put_buf(' ');
        }
        goto noflush;
        //return c;

    case '\n':
    case '\r':
        put_buf( c );
        goto flush;

    default:
        put_buf( c );
        if( cbufpos >= BUFS )
            goto flush;

noflush:
#if TIMED_FLUSH
        phantom_request_timed_call( &cons_timer, 0 );
#endif

#if NET_TIMED_FLUSH
        set_net_timer(&cons_upd_timer, 100, flush_stdout, 0, 0 );
#endif

        return c;
    }

flush:
    flush_stdout(0);
    return c;
}
Example #3
0
int putchar(int c)
{
	if (c == '\n')
	{
		putchar_raw('\r');
	}
	putchar_raw(c);
	if (c == '\n')
	{
		flush_stdout();
	}
	return c;
}
/* Print the program name and error message MESSAGE, which is a printf-style
   format string with optional args.
   If ERRNUM is nonzero, print its corresponding system error message.
   Exit with status STATUS if it is nonzero.  */
void
error (int status, int errnum, const char *message, ...)
{
  va_list args;

  flush_stdout ();
  
  fprintf (stderr, "%s: ", program_name);

  va_start (args, message);
  vfprintf (stderr, message, args);
  va_end (args);

  ++error_message_count;
  if (errnum)
    print_errno_message (errnum);

  fflush (stderr);
  if (status)
    exit (status);
}
Example #5
0
int console_run()
{
	int ret = 1;
	
	if (usb_rx_len)
	{
		for (int i = 0; i < usb_rx_len; ++i)
		{
			char ch = usb_rx_buffer[i];
			if (ch == 3)
			{
				printf("Stop\n");
				debug_update = 0;
				ret = 0;
				
				// Clear the command buffer
				command_len = 0;
			} else if (ch == '\r')
			{
				putchar('\n');
				if (command_len >= MAX_COMMAND_SIZE)
				{
					// Command too long
					printf("Command too long\n");
				} else {
					// We still have room for the terminator
					command_buffer[command_len] = 0;
					
					// Execute the command
					console_execute_buffer();
				}
				
				// Clear the command buffer
				command_len = 0;
			} else if (ch == 8 || ch == 0x7f)
			{
				// Backspace
				if (command_len)
				{
					putchar(8);
					putchar(32);
					putchar(8);
					flush_stdout();
					--command_len;
				}
				continue;
			} else {
				if (ch >= 0x20 && ch <= 0x7e && command_len < MAX_COMMAND_SIZE)
				{
					// Add to command buffer
					command_buffer[command_len++] = ch;
					putchar(ch);
					flush_stdout();
				}
				continue;
			}
			print_prompt();
		}
		
		// Clear the buffer and keep reading
		usb_rx_start();
	}
	
	return ret;
}
Example #6
0
static void print_prompt()
{
	putchar('>');
	putchar(' ');
	flush_stdout();
}