<commit_before>#include "Console.h"

Console::Console()
  : currentRow(0),
    currentColumn(0)
{
}

Console::~Console()
{
}

void
Console::write(const char* string)
{
   while (*string)
   {
      putChar(*string++);
   }
   
   setCursor(currentRow, currentColumn);
}

void
Console::stepRow()
{
   currentRow++;
  
   if (currentRow > getRows() - 1)
   {
      // generic scroll or smart scroll by driver?
      scrollScreen();
      currentColumn = 0;
      currentRow = getRows() - 1; // just flow over to the top now
      setCursor(getRows() - 1, 0);
   }
}

void
Console::stepColumn()
{
      currentColumn++;
      if (currentColumn > getColumns() - 1) {
	 currentColumn = 0;
	 stepRow();
      }
}

void
Console::putChar(char ch)
{
   switch (ch)
   {
      case '\n':
	 stepRow();
	 currentColumn = 0;
	 break;
      case '\r':
	 break;
      default:
	 putChar(ch, currentRow, currentColumn);
	 stepColumn();
	 break;
   }
}

enum {
   PRINTF_FLAG_SIGNED = 1,
   PRINTF_FLAG_UNSIGNED = 1 << 1,
   PRINTF_FLAG_LOWERHEX = 1 << 2,
   PRINTF_FLAG_UPPERHEX = 1 << 3
};

int
Console::printf(const char* format, ...)
{
   int retval = 0;

   while (*format != 0)
   {
      if (format != '%')
      {
	 putChar(*format++);
	 retval++;
      }
      else
      {
	 // let's see what's after %
	 format++; 

	 // "%d %llu %hd"

	 int flags = 0;
	 switch (*format)
	 {
	    case 'd':
	       flags |= PRINTF_FLAG_SIGNED;
	       format++;
	       break;
	    case 'u':
	       flags |= PRINTF_FLAG_UNSIGNED;
	       format++;
	       break;
	    case 'x':
	       flags |= PRINTF_FLAG_LOWERHEX;
	       format++;
	       break;
	    case 'X':
	       flags |= PRINTF_FLAG_UPPERHEX;
	       format++;
	       break;
	    default:
	       // just print whatever it was...	
	       putChar(*format++);
	       retval++;
	 }
	 
      }
   }
}
<commit_msg>more printf<commit_after>#include "Console.h"

#include <stdarg.h>

Console::Console()
  : currentRow(0),
    currentColumn(0)
{
}

Console::~Console()
{
}

void
Console::write(const char* string)
{
   while (*string)
   {
      putChar(*string++);
   }
   
   setCursor(currentRow, currentColumn);
}

void
Console::stepRow()
{
   currentRow++;
  
   if (currentRow > getRows() - 1)
   {
      // generic scroll or smart scroll by driver?
      scrollScreen();
      currentColumn = 0;
      currentRow = getRows() - 1; // just flow over to the top now
      setCursor(getRows() - 1, 0);
   }
}

void
Console::stepColumn()
{
      currentColumn++;
      if (currentColumn > getColumns() - 1) {
	 currentColumn = 0;
	 stepRow();
      }
}

void
Console::putChar(char ch)
{
   switch (ch)
   {
      case '\n':
	 stepRow();
	 currentColumn = 0;
	 break;
      case '\r':
	 break;
      default:
	 putChar(ch, currentRow, currentColumn);
	 stepColumn();
	 break;
   }
}

enum {
   PRINTF_FLAG_SIGNED = 1,
   PRINTF_FLAG_UNSIGNED = 1 << 1,
   PRINTF_FLAG_LOWERHEX = 1 << 2,
   PRINTF_FLAG_UPPERHEX = 1 << 3
};

int
Console::printf(const char* format, ...)
{
   va_list ap;
   int retval = 0;

   va_start(ap);

   while (*format != 0)
   {
      if (*format != '%')
      {
	 putChar(*format++);
	 retval++;
      }
      else
      {
	 int flags = 0;
	 // let's see what's after %
	 format++; 

	 // "%d %llu %hd"
	 switch (*format)
	 {
	    case 0:
	       break;
	    case 'd':
	       flags |= PRINTF_FLAG_SIGNED;
	       format++;
	       break;
	    case 'u':
	       flags |= PRINTF_FLAG_UNSIGNED;
	       format++;
	       break;
	    case 'x':
	       flags |= PRINTF_FLAG_LOWERHEX;
	       format++;
	       break;
	    case 'X':
	       flags |= PRINTF_FLAG_UPPERHEX;
	       format++;
	       break;
	    default:
	       // just print whatever it was...	
	       putChar(*format++);
	       retval++;
	 }
	 
      }
   }

out:
   va_end(ap);

   return retval;
}

{'fraction_non_alphanumeric': 0.14905857740585773, 'fraction_numerical': 0.010721757322175732, 'mean_word_length': 2.0237154150197627, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6857606', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1329, 'n_words': 307}