Fix up bad git subtree import.
This commit is contained in:
15
misc/kforth/v1/linux/defs.h
Normal file
15
misc/kforth/v1/linux/defs.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef __KF_LINUX_DEFS_H__
|
||||
#define __KF_LINUX_DEFS_H__
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef int32_t KF_INT;
|
||||
typedef uint32_t KF_UINT;
|
||||
typedef int64_t KF_LONG;
|
||||
|
||||
typedef uintptr_t KF_ADDR;
|
||||
constexpr uint8_t STACK_SIZE = 128;
|
||||
constexpr size_t ARENA_SIZE = 65535;
|
||||
|
||||
#endif
|
||||
82
misc/kforth/v1/linux/io.cc
Normal file
82
misc/kforth/v1/linux/io.cc
Normal file
@@ -0,0 +1,82 @@
|
||||
#include <iostream>
|
||||
#include "../io.h"
|
||||
#include "io.h"
|
||||
|
||||
char
|
||||
Console::rdch()
|
||||
{
|
||||
std::cout.flush();
|
||||
return getchar();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Console::wrch(char c)
|
||||
{
|
||||
std::cout << c;
|
||||
}
|
||||
|
||||
|
||||
size_t
|
||||
Console::rdbuf(char *buf, size_t len, bool stopat, char stopch)
|
||||
{
|
||||
size_t n = 0;
|
||||
char ch;
|
||||
|
||||
while (n < len) {
|
||||
ch = this->rdch();
|
||||
if (ch == 0x04) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (stopat && stopch == ch) {
|
||||
break;
|
||||
}
|
||||
|
||||
buf[n++] = ch;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Console::wrbuf(char *buf, size_t len)
|
||||
{
|
||||
for (size_t n = 0; n < len; n++) {
|
||||
this->wrch(buf[n]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Line I/O
|
||||
bool
|
||||
Console::rdln(char *buf, size_t len, size_t *readlen) {
|
||||
size_t n = 0;
|
||||
char ch;
|
||||
bool line = false;
|
||||
|
||||
while (n < len) {
|
||||
ch = this->rdch();
|
||||
|
||||
if (ch == '\n') {
|
||||
line = true;
|
||||
break;
|
||||
}
|
||||
|
||||
buf[n++] = ch;
|
||||
}
|
||||
|
||||
if (nullptr != readlen) {
|
||||
*readlen = n;
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Console::wrln(char *buf, size_t len)
|
||||
{
|
||||
this->wrbuf(buf, len);
|
||||
this->wrch(0x0a);
|
||||
}
|
||||
25
misc/kforth/v1/linux/io.h
Normal file
25
misc/kforth/v1/linux/io.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef __KF_IO_LINUX_H__
|
||||
#define __KF_IO_LINUX_H__
|
||||
|
||||
#include "io.h"
|
||||
#include "defs.h"
|
||||
|
||||
class Console : public IO {
|
||||
public:
|
||||
~Console() {};
|
||||
char rdch(void);
|
||||
void wrch(char c);
|
||||
|
||||
// Buffer I/O.
|
||||
size_t rdbuf(char *buf, size_t len, bool stopat, char stopch);
|
||||
void wrbuf(char *buf, size_t len);
|
||||
|
||||
// Line I/O
|
||||
bool rdln(char *buf, size_t len, size_t *readlen);
|
||||
void wrln(char *buf, size_t len);
|
||||
|
||||
void newline(void) { this->wrch('\n'); };
|
||||
private:
|
||||
};
|
||||
|
||||
#endif // __KF_IO_LINUX_H__
|
||||
Reference in New Issue
Block a user