File:  [Isaki's NoNo m68k/m88k emulator] / nono / debugger / console.h
Revision 1.1.1.4 (vendor branch): download - view: text, annotated - select for diffs
Wed Apr 29 17:04:53 2026 UTC (2 months, 3 weeks ago) by root
Branches: MAIN, Isaki
CVS tags: v014, v013, v012, v011, HEAD
nono 0.2.0

//
// nono
// Copyright (C) 2020 nono project
// Licensed under nono-license.txt
//

#pragma once

#include "header.h"
#if defined(HAVE_HISTEDIT_H)
#include <histedit.h>
#endif

// コンソールの基本クラス
class Console
{
 public:
	Console();
	virtual ~Console() { }

	// 初期化
	virtual bool Init() = 0;
	// 受け付ける
	virtual bool Accept() = 0;

	// EditLine を初期化する
	void InitEditLine(const char *prompt);

	virtual void Close();

	// プロンプトを出力する
	void Prompt();

	void Print(const char *fmt, ...) __printflike(2, 3);
	void Flush();

	// 1行読み込む。
	// 正常に読み込めれば true を返す。
	// バッファは \0 で終端してある。
	bool Gets(std::string&);

	// 受信データがあれば正、なければ 0 を返す。エラーなら負数を返す。
	// msec はタイムアウト値の指定。0 ならポーリング。(タイムアウトなしは-1)
	int Poll(int msec = 0);

 protected:
	void FDOpen();

	struct {
		int fd;
		FILE *file;
	} inp {}, out {};

	// Editline を使うかどうかのフラグ。継承側がセットする。
	// 今のところ TCP console では動かないのでこんなことになっている。
	bool use_editline {};

	// Editline
	const char *prompt {};
#if defined(HAVE_HISTEDIT_H)
	EditLine *el {};
	History *hist {};
	HistEvent hev {};
#endif

 private:
	// Gets() の下請け
#if defined(HAVE_HISTEDIT_H)
	bool Gets_editline(std::string& buf);
#endif
	bool Gets_normal(std::string& buf);
};

// 標準入出力コンソール
class ConsoleStdio : public Console
{
 public:
	ConsoleStdio();
	~ConsoleStdio() override;

	bool Init() override;
	bool Accept() override;
	void Close() override;
};

// TCP コンソール
class ConsoleTCP : public Console
{
	using inherited = Console;
 public:
	ConsoleTCP();
	~ConsoleTCP() override;

	bool Init() override;
	bool Accept() override;
	void Close() override;

 private:
	int ls {};
	int sock {};
	struct addrinfo *res {};
	struct addrinfo *ai {};
};

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.