Annotation of nono/debugger/console.h, revision 1.1

1.1     ! root        1: //
        !             2: // nono
        !             3: // Copyright (C) 2019 [email protected]
        !             4: //
        !             5: 
        !             6: #pragma once
        !             7: 
        !             8: #include "header.h"
        !             9: #if defined(HAVE_HISTEDIT_H)
        !            10: #include <histedit.h>
        !            11: #endif
        !            12: 
        !            13: // コンソールの基本クラス
        !            14: class Console
        !            15: {
        !            16:  public:
        !            17:        Console();
        !            18:        virtual ~Console() { }
        !            19: 
        !            20:        // 初期化
        !            21:        virtual bool Init() = 0;
        !            22:        virtual bool Open() = 0;
        !            23: 
        !            24:        // EditLine を初期化する
        !            25:        void InitEditLine(const char *prompt);
        !            26: 
        !            27:        virtual void Close();
        !            28: 
        !            29:        // プロンプトを出力する
        !            30:        void Prompt();
        !            31: 
        !            32:        void Print(const char *fmt, ...) __printflike(2, 3);
        !            33:        void Flush();
        !            34: 
        !            35:        // 1行読み込む。
        !            36:        // 正常に読み込めれば true を返す。
        !            37:        // バッファは \0 で終端してある。
        !            38:        bool Gets(std::string&);
        !            39: 
        !            40:        // 受信データがあれば正、なければ 0 を返す。エラーなら負数を返す。
        !            41:        int  Poll();
        !            42: 
        !            43:  protected:
        !            44:        void FDOpen();
        !            45: 
        !            46:        struct {
        !            47:                int fd;
        !            48:                FILE *file;
        !            49:        } inp, out;
        !            50: 
        !            51:        // Editline を使うかどうかのフラグ。継承側がセットする。
        !            52:        // 今のところ TCP console では動かないのでこんなことになっている。
        !            53:        bool use_editline = false;
        !            54: 
        !            55:        // Editline
        !            56:        const char *prompt = NULL;
        !            57: #if defined(HAVE_HISTEDIT_H)
        !            58:        EditLine *el = NULL;
        !            59:        History *hist = NULL;
        !            60:        HistEvent hev {};
        !            61: #endif
        !            62: 
        !            63:  private:
        !            64:        // Gets() の下請け
        !            65: #if defined(HAVE_HISTEDIT_H)
        !            66:        bool Gets_editline(std::string& buf);
        !            67: #endif
        !            68:        bool Gets_normal(std::string& buf);
        !            69: };
        !            70: 
        !            71: // 標準入出力コンソール
        !            72: class ConsoleStdio
        !            73:        : public Console
        !            74: {
        !            75:  public:
        !            76:        ConsoleStdio();
        !            77:        virtual ~ConsoleStdio();
        !            78: 
        !            79:        bool Init();
        !            80:        bool Open();
        !            81:        void Close();
        !            82: };
        !            83: 
        !            84: // TCP コンソール
        !            85: class ConsoleTCP
        !            86:        : public Console
        !            87: {
        !            88:        typedef Console inherited;
        !            89:  public:
        !            90:        ConsoleTCP();
        !            91:        virtual ~ConsoleTCP();
        !            92: 
        !            93:        bool Init();
        !            94:        bool Open();
        !            95:        void Close();
        !            96: 
        !            97:  private:
        !            98:        int ls = 0;
        !            99:        int sock = 0;
        !           100:        struct addrinfo *res = NULL;
        !           101:        struct addrinfo *ai = NULL;
        !           102: };

unix.superglobalmegacorp.com

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