repl.h 867 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
/*-----------------------------------------------------------------------------
 *  Author: Nelso G. Jost (nelsojost@gmail.com)
 *  License: GPLv2
 *  Purpose: Read-Eval-Print-Loop functionality
 *---------------------------------------------------------------------------*/
#ifndef REPL_H
#define REPL_H


typedef struct
{
    const char *name;
    void (*func)(String);
    const char *prototype;
    const char *help;
} REPL_COMMAND;


class REPL
{
public:
    REPL(REPL_COMMAND command_map[]);

    String prompt=">";

    void run(void);
    void print_help(void);
    void log(String msg);

private:
    REPL_COMMAND * _fp_map;
    String _command="";

    void _backspace(void);
    void _clear_line(void);

    void _history_previous(void);
    void _history_next(void);

    int _execute_command(void);
};

String get_arg(String command, int index);

#endif