Merge of Fredrik Hultin command_line
[people/xl0/gpxe.git] / src / include / cmdlinelib.h
1 /* Command line library */
2 #ifndef CMDLINELIB_H
3 #define CMDLINELIB_H
4
5 #define CMDL_BUFFER_SIZE 256
6 //#define CMDL_OUTPUT_SIZE 256
7 #define CMDL_PROMPT_SIZE 8
8 #define CMDL_MAX_TAB_COMPLETE_RESULT 256
9
10 typedef int (*cmdl_putchar_t)(int);
11 typedef int (*cmdl_printf_t)( const char *format, ... );
12 typedef int (*cmdl_getchar_t)();
13
14 #ifndef NULL
15 #define NULL    ((void *)0)
16 #endif
17
18 enum{
19         CMDL_LEFT,
20         CMDL_RIGHT
21 };
22
23 enum{
24         CMDLK_FW=6,
25         CMDLK_BW=2,
26         CMDLK_BS=8,
27         CMDLK_HOME=2,
28         CMDLK_END=5,
29         CMDLK_DELTOEND=11,
30         CMDLK_DELARG=23,
31         CMDLK_ENTER=0x0d,
32         CMDLK_RETURN=0x0a,
33         CMDLK_TAB=9
34 };
35
36 typedef struct{
37         
38         // buffers
39
40         //char* output;
41         char* buffer;
42         char* prompt;
43
44         // options and values
45
46         int cursor;
47         //int has_output;
48         int exit;
49         int refresh;
50         int tabstate;
51         int insert;
52
53         // callbacks
54         
55         cmdl_putchar_t putchar;
56         cmdl_getchar_t getchar;
57         cmdl_printf_t printf;
58
59 }cmd_line;
60
61 typedef struct{
62         int argc;
63         char **argv;
64 }cmdl_param_list;
65
66 void cmdl_setputchar(cmd_line* cmd, cmdl_putchar_t in);
67 void cmdl_setgetchar(cmd_line* cmd, cmdl_getchar_t in);
68 void cmdl_setprintf(cmd_line* cmd, cmdl_printf_t in);
69
70 //void cmdl_builtin_help(cmd_line* cmd, char* command);
71
72 void cmdl_parsechar(cmd_line* cmd, char in);
73
74 void cmdl_addreplace(cmd_line* cmd, char in);
75 void cmdl_addinsert(cmd_line* cmd, char in);
76 void cmdl_enterloop(cmd_line* cmd);
77 void cmdl_exec(cmd_line* cmd);
78 void cmdl_setexit(cmd_line* cmd, int exit);
79 int cmdl_getexit(cmd_line* cmd);
80 void cmdl_clearoutput(cmd_line* cmd);
81 void cmdl_clearbuffer(cmd_line* cmd);
82 int cmdl_printf(cmd_line* cmd, const char *format, ...);
83 char* cmdl_getoutput(cmd_line* cmd);
84 //void cmdl_addoutput_str(cmd_line* cmd, char output[CMDL_OUTPUT_SIZE]);
85 void cmdl_addstr(cmd_line* cmd, char* str);
86 int cmdl_movecursor(cmd_line* cmd, int direction);
87 char* cmdl_getbuffer(cmd_line* cmd);
88 void cmdl_addchar(cmd_line* cmd, char in);
89 int cmdl_check(cmd_line* cmd);
90 void cmdl_del(cmd_line* cmd);
91 cmd_line* cmdl_create();
92 void cmdl_free(cmd_line* cmd);
93 char *cmdl_getprompt(cmd_line* cmd);
94 void cmdl_setpropmt(cmd_line* cmd, char prompt[CMDL_PROMPT_SIZE]);
95 cmdl_param_list* cmdl_getparams(const char* command);
96 void cmdl_tabcomplete(cmd_line *cmd);
97
98 #endif
99