From fad1ce08a07ad4e4a8e45e8a69374585c7f73653 Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <hch@lst.de>
Date: Thu, 17 Jan 2013 14:31:00 +0100
Subject: [PATCH] simplify the console abstractions

This is the low-level console abstraction and should deal in the
char * hardware format.  The upper layer (debug.cc) already handles
all conversion from std::string and boost formats.
---
 build.mak             |  2 +-
 debug.cc              | 11 ++++++++---
 drivers/console.cc    | 21 ---------------------
 drivers/console.hh    |  7 +------
 drivers/isa-serial.cc |  6 +++---
 drivers/isa-serial.hh |  2 +-
 6 files changed, 14 insertions(+), 35 deletions(-)
 delete mode 100644 drivers/console.cc

diff --git a/build.mak b/build.mak
index deb99d44d..7b8494ca3 100644
--- a/build.mak
+++ b/build.mak
@@ -94,7 +94,7 @@ fs +=	fs/ramfs/ramfs_vfsops.o \
 fs +=	fs/devfs/devfs_vnops.o \
 	fs/devfs/device.o
 
-drivers = drivers/vga.o drivers/console.o drivers/isa-serial.o
+drivers = drivers/vga.o drivers/isa-serial.o
 drivers += $(fs)
 drivers += mmu.o
 drivers += elf.o
diff --git a/debug.cc b/debug.cc
index 95ca67b61..3af1d3a6b 100644
--- a/debug.cc
+++ b/debug.cc
@@ -1,3 +1,4 @@
+#include <cstring>
 #include <iostream>
 #include <iomanip>
 #include "drivers/isa-serial.hh"
@@ -8,9 +9,13 @@ using namespace std;
 
 Debug* Debug::pinstance = 0;
 
-void Debug::out(const char* msg, bool lf) {
-  if (!_console) return;
-  (lf)? _console->writeln(msg):_console->write(msg);
+void Debug::out(const char* msg, bool lf)
+{
+    if (!_console)
+        return;
+    _console->write(msg, strlen(msg));
+    if (lf)
+        _console->newline();
 }
 
 void debug(const char *msg, bool lf)
diff --git a/drivers/console.cc b/drivers/console.cc
deleted file mode 100644
index 67a0b47c2..000000000
--- a/drivers/console.cc
+++ /dev/null
@@ -1,21 +0,0 @@
-#include "console.hh"
-
-void Console::write(const boost::format& fmt)
-{
-    return write(fmt.str());
-}
-
-void Console::writeln(const boost::format& fmt)
-{
-    return writeln(fmt.str());
-}
-
-void Console::write(std::string str)
-{
-    return write(str.c_str());
-}
-
-void Console::writeln(std::string str)
-{
-    return writeln(str.c_str());
-}
diff --git a/drivers/console.hh b/drivers/console.hh
index 895ac0474..d9392fa0c 100644
--- a/drivers/console.hh
+++ b/drivers/console.hh
@@ -6,13 +6,8 @@
 class Console {
 public:
     virtual ~Console() {}
-    virtual void write(const char *str) = 0;
+    virtual void write(const char *str, size_t len) = 0;
     virtual void newline() = 0;
-    void writeln(const char *str) { write(str); newline(); }
-    void write(std::string str);
-    void writeln(std::string str);
-    void write(const boost::format& fmt);
-    void writeln(const boost::format& fmt);
 };
 
 #endif
diff --git a/drivers/isa-serial.cc b/drivers/isa-serial.cc
index f0ee36d0d..7777f47ad 100644
--- a/drivers/isa-serial.cc
+++ b/drivers/isa-serial.cc
@@ -4,12 +4,12 @@ IsaSerialConsole::IsaSerialConsole() {
 	reset();
 }
 
-void IsaSerialConsole::write(const char *str)
+void IsaSerialConsole::write(const char *str, size_t len)
 {
-    while (*str) {
+    while (len > 0) {
     	writeByte(*str++);
+        len--;
     }
-
 }
 
 void IsaSerialConsole::writeByte(const char letter)
diff --git a/drivers/isa-serial.hh b/drivers/isa-serial.hh
index f5b9a5d6f..c9e8b0021 100644
--- a/drivers/isa-serial.hh
+++ b/drivers/isa-serial.hh
@@ -8,7 +8,7 @@
 class IsaSerialConsole : public Console {
 public:
 	IsaSerialConsole();
-    virtual void write(const char *str);
+    virtual void write(const char *str, size_t len);
     virtual void newline();
 private:
     static const u16 ioport = 0x3f8;
-- 
GitLab