Line Editor. More...
![]() |
Data Structures | |
struct | _EDITHISTORY |
Line input history. More... | |
struct | _EDLINE |
Edit line information structure. More... | |
Defines | |
#define | EDIT_MAX_HISTORY 16 |
Maximum number of history entries. | |
Typedefs | |
typedef struct _EDITHISTORY | EDITHISTORY |
Line input history. | |
typedef int(* | EDLINEGET )(void *) |
Input routine type. | |
typedef int(* | EDLINEPUT )(void *, int) |
Output routine type. | |
typedef int(* | EDLINEMAP )(int, int *) |
Character mapping routine type. | |
typedef struct _EDLINE | EDLINE |
Edit line information structure. | |
Functions | |
void | EdLineRegisterInput (EDLINE *el, EDLINEGET get, void *param) |
Register an input routine. | |
void | EdLineRegisterOutput (EDLINE *el, EDLINEPUT put, void *param) |
Register an output routine. | |
int | EdLineKeyMap (int key, int *seq) |
Default key mapping routine. | |
void | EdLineRegisterKeymap (EDLINE *el, EDLINEMAP map) |
Register a key mapping routine. | |
EDLINE * | EdLineOpen (uint16_t mode) |
Open a line editor. | |
void | EdLineClose (EDLINE *el) |
Close a line editor. | |
int | EdLineRead (EDLINE *el, char *buf, int siz) |
Read a line. | |
EDITHISTORY * | EditHistoryCreate (int siz) |
Create an editor history table. | |
void | EditHistoryDestroy (EDITHISTORY *hist) |
Create an editor history table. | |
void | EditHistorySet (EDITHISTORY *hist, int idx, char *buf) |
Replace the specified history table entry. | |
int | EditHistoryGet (EDITHISTORY *hist, int idx, char *buf, int siz) |
Retrieve the specified history table entry. | |
void | EditHistoryInsert (EDITHISTORY *hist, int idx, char *buf) |
Insert a new history table entry at the specified position. | |
int | EdLineKeyMapVt100 (int key, int *seq) |
Optional VT100 key mapping routine. | |
Edit mode flags | |
Used when calling EdLineOpen to enable specific line editor features. | |
#define | EDIT_MODE_ECHO 0x0001 |
Enables echoing of input characters. | |
#define | EDIT_MODE_BINARY 0x0002 |
Enables binary mode (currently unused). | |
#define | EDIT_MODE_HISTORY 0x0004 |
Enables input line history. | |
Line editor input commands | |
Special keys which are interpreted by the editor as commands. | |
#define | EDIT_KEY_IGNORE 0x00 |
No operation. Default is Ctrl-@. | |
#define | EDIT_KEY_HOME 0x01 |
Move cursor to line begin. Default is Ctrl-A. | |
#define | EDIT_KEY_LEFT 0x02 |
Move cursor left. Default is Ctrl-B. | |
#define | EDIT_KEY_END 0x05 |
Move cursor to line end. Default is Ctrl-E. | |
#define | EDIT_KEY_RIGHT 0x06 |
Move cursor right. Default is Ctrl-F. | |
#define | EDIT_KEY_REMOVE 0x08 |
Delete left character. Default is Ctrl-H. | |
#define | EDIT_KEY_ENTER 0x0a |
Confirm input. Default is Ctrl-J. | |
#define | EDIT_KEY_UP 0x12 |
History upwards. Default is Ctrl-R. | |
#define | EDIT_KEY_DOWN 0x16 |
History downwards. Default is Ctrl-V. | |
#define | EDIT_KEY_RESTORE 0x1b |
Restore default. Default is ESC. | |
Line editor output commands | |
#define | EDIT_CHAR_SPACE ' ' |
Clear character right. | |
#define | EDIT_CHAR_BACKSPACE '\b' |
Move cursor left. | |
#define | EDIT_CHAR_ALARM '\a' |
Invoke audible alarm. | |
#define | EDIT_STR_EOL "\r\n" |
Terminate input. |
Line Editor.
#define EDIT_MODE_ECHO 0x0001 |
Enables echoing of input characters.
Definition at line 63 of file edline.h.
Referenced by EdLineRead(), LuaThread(), and main().
#define EDIT_MODE_BINARY 0x0002 |
#define EDIT_MODE_HISTORY 0x0004 |
Enables input line history.
Definition at line 67 of file edline.h.
Referenced by EdLineOpen(), EdLineRead(), and LuaThread().
#define EDIT_KEY_IGNORE 0x00 |
No operation. Default is Ctrl-@.
Definition at line 78 of file edline.h.
Referenced by EdLineKeyMap(), and EdLineKeyMapVt100().
#define EDIT_KEY_HOME 0x01 |
Move cursor to line begin. Default is Ctrl-A.
Definition at line 82 of file edline.h.
Referenced by EdLineRead().
#define EDIT_KEY_LEFT 0x02 |
Move cursor left. Default is Ctrl-B.
Definition at line 86 of file edline.h.
Referenced by EdLineKeyMapVt100(), and EdLineRead().
#define EDIT_KEY_END 0x05 |
Move cursor to line end. Default is Ctrl-E.
Definition at line 90 of file edline.h.
Referenced by EdLineRead().
#define EDIT_KEY_RIGHT 0x06 |
Move cursor right. Default is Ctrl-F.
Definition at line 94 of file edline.h.
Referenced by EdLineKeyMapVt100(), and EdLineRead().
#define EDIT_KEY_REMOVE 0x08 |
Delete left character. Default is Ctrl-H.
Definition at line 98 of file edline.h.
Referenced by EdLineRead().
#define EDIT_KEY_ENTER 0x0a |
Confirm input. Default is Ctrl-J.
Definition at line 102 of file edline.h.
Referenced by EdLineKeyMap(), and EdLineRead().
#define EDIT_KEY_UP 0x12 |
History upwards. Default is Ctrl-R.
Definition at line 107 of file edline.h.
Referenced by EdLineKeyMapVt100(), and EdLineRead().
#define EDIT_KEY_DOWN 0x16 |
History downwards. Default is Ctrl-V.
Definition at line 111 of file edline.h.
Referenced by EdLineKeyMapVt100(), and EdLineRead().
#define EDIT_KEY_RESTORE 0x1b |
Restore default. Default is ESC.
Definition at line 115 of file edline.h.
Referenced by EdLineRead().
#define EDIT_CHAR_SPACE ' ' |
#define EDIT_CHAR_BACKSPACE '\b' |
#define EDIT_CHAR_ALARM '\a' |
#define EDIT_STR_EOL "\r\n" |
#define EDIT_MAX_HISTORY 16 |
Maximum number of history entries.
The first entry with index 0 is used to restore the default value.
Definition at line 61 of file edline.c.
Referenced by EdLineOpen().
typedef struct _EDITHISTORY EDITHISTORY |
Line input history.
typedef int(* EDLINEMAP)(int, int *) |
Register an input routine.
Applications may use this function to replace the default character input routine.
el | Pointer to an EDLINE structure, obtained by a previous call to EdLineOpen. |
get | Pointer to the new input routine. If NULL, then the default routine is restored. |
param | Optional parameter, which is passed to the input routine. |
Definition at line 105 of file edline.c.
References _EDLINE::el_get, and _EDLINE::el_iparm.
Referenced by EdLineOpen().
Register an output routine.
Applications may use this function to replace the default character output routine.
el | Pointer to an EDLINE structure, obtained by a previous call to EdLineOpen. |
put | Pointer to the new output routine. If NULL, then the default routine is restored. |
param | Optional parameter, which is passed to the output routine. |
Definition at line 128 of file edline.c.
References _EDLINE::el_oparm, and _EDLINE::el_put.
Referenced by EdLineOpen().
int EdLineKeyMap | ( | int | key, |
int * | seq | ||
) |
Default key mapping routine.
Replaces carriage returns and linefeeds by EDIT_KEY_ENTER. Linefeeds immediately following carriage returns are ignored. May be replaced by calling EdLineRegisterKeymap().
This routine may be called by other key mapping routines.
key | Input character to remap. |
seq | Pointer to an integer, which is used by the key mapping routine to store the current state. Note, that its value must be preserved by the caller between calls to EdLineRead. |
Definition at line 156 of file edline.c.
References EDIT_KEY_ENTER, and EDIT_KEY_IGNORE.
Referenced by EdLineKeyMapVt100(), and EdLineRegisterKeymap().
Register a key mapping routine.
el | Pointer to an EDLINE structure, obtained by a previous call to EdLineOpen. |
map | Pointer to the new mapping routine. If NULL, then the default routine is restored. |
Definition at line 183 of file edline.c.
References EdLineKeyMap(), and _EDLINE::el_map.
Referenced by EdLineOpen(), and LuaThread().
Open a line editor.
mode | Mode flags, may contain any combination of
|
Definition at line 202 of file edline.c.
References calloc, EDIT_MAX_HISTORY, EDIT_MODE_HISTORY, EditHistoryCreate(), EdLineRegisterInput(), EdLineRegisterKeymap(), EdLineRegisterOutput(), _EDLINE::el_hist, _EDLINE::el_mode, stdin, and stdout.
Referenced by LuaThread(), and main().
void EdLineClose | ( | EDLINE * | el | ) |
Close a line editor.
Releases all occupied memory.
el | Pointer to an EDLINE structure, obtained by a previous call to EdLineOpen. |
Definition at line 229 of file edline.c.
References EditHistoryDestroy(), _EDLINE::el_hist, and free().
Referenced by LuaThread().
int EdLineRead | ( | EDLINE * | el, |
char * | buf, | ||
int | siz | ||
) |
Read a line.
This functions offers some editing capabilities and is typically used for text input by human users.
Line editing can be done by entering any of the following control characters:
Note, that these commands may be modified by the currently registered remapping routine.
el | Pointer to an EDLINE structure, obtained by a previous call to EdLineOpen. |
buf | Pointer to the buffer that receives the text line. If it contains a string on entry, this will be used as the default value. |
siz | Number of bytes available in the buffer. The maximum length of the text string is 1 less, so the string is always properly terminated. |
Definition at line 326 of file edline.c.
References EDIT_CHAR_ALARM, EDIT_CHAR_BACKSPACE, EDIT_CHAR_SPACE, EDIT_KEY_DOWN, EDIT_KEY_END, EDIT_KEY_ENTER, EDIT_KEY_HOME, EDIT_KEY_LEFT, EDIT_KEY_REMOVE, EDIT_KEY_RESTORE, EDIT_KEY_RIGHT, EDIT_KEY_UP, EDIT_MODE_ECHO, EDIT_MODE_HISTORY, EDIT_STR_EOL, EditHistoryGet(), EditHistoryInsert(), EditHistorySet(), _EDLINE::el_get, _EDLINE::el_hist, _EDLINE::el_iparm, _EDLINE::el_map, _EDLINE::el_mode, _EDLINE::el_oparm, _EDLINE::el_put, _EDLINE::el_seq, EOF, and strlen().
EDITHISTORY* EditHistoryCreate | ( | int | siz | ) |
Create an editor history table.
siz | Maximum number of history entries. |
Definition at line 64 of file history.c.
References calloc, free(), _EDITHISTORY::hist_siz, _EDITHISTORY::hist_tab, and malloc().
Referenced by EdLineOpen().
void EditHistoryDestroy | ( | EDITHISTORY * | hist | ) |
Create an editor history table.
Releases occupied memory.
hist | Pointer to an EDITHISTORY structure, obtained by a previous call to EditHistoryCreate. |
Definition at line 87 of file history.c.
References free(), _EDITHISTORY::hist_siz, and _EDITHISTORY::hist_tab.
Referenced by EdLineClose().
void EditHistorySet | ( | EDITHISTORY * | hist, |
int | idx, | ||
char * | buf | ||
) |
Replace the specified history table entry.
idx | Index in to the history table. |
buf | Pointer to the string that will replace the existing one. |
hist | Pointer to an EDITHISTORY structure, obtained by a previous call to EditHistoryCreate. |
Definition at line 109 of file history.c.
References free(), _EDITHISTORY::hist_tab, and strdup().
Referenced by EdLineRead().
int EditHistoryGet | ( | EDITHISTORY * | hist, |
int | idx, | ||
char * | buf, | ||
int | siz | ||
) |
Retrieve the specified history table entry.
idx | Index in to the history table. |
hist | Pointer to an EDITHISTORY structure, obtained by a previous call to EditHistoryCreate. |
Definition at line 131 of file history.c.
References _EDITHISTORY::hist_tab, memcpy(), and strlen().
Referenced by EdLineRead().
void EditHistoryInsert | ( | EDITHISTORY * | hist, |
int | idx, | ||
char * | buf | ||
) |
Insert a new history table entry at the specified position.
All following entries are moved up by 1. If the table is full, then the top most entry will be removed.
idx | Index in to the history table. |
buf | Pointer to the new string. If it doesn't differ from the existing entry, than nothing will be changed. |
hist | Pointer to an EDITHISTORY structure, obtained by a previous call to EditHistoryCreate. |
Definition at line 165 of file history.c.
References free(), _EDITHISTORY::hist_siz, _EDITHISTORY::hist_tab, strcmp(), and strdup().
Referenced by EdLineRead().
int EdLineKeyMapVt100 | ( | int | key, |
int * | seq | ||
) |
Optional VT100 key mapping routine.
Pass this function to EdLineRegisterKeymap to enable VT100 key mapping.
This routine has been tested with the TeraTerm terminal emulator after loading the keymap contained in ibmkeyb.cnf. It allows to use the arrow keys for moving the cursor and walking through the history. This should work with most other VT100 emulations as well.
The following command sequences are remapped:
Internally calls EdLineKeyMap to handle carriage return and linefeed.
key | Input character to remap. |
seq | Pointer to an integer, which is used by the key mapping routine to store the current state. Note, that its value must be preserved by the caller between calls to EdLineRead. |
Definition at line 82 of file vt100.c.
References EDIT_KEY_DOWN, EDIT_KEY_IGNORE, EDIT_KEY_LEFT, EDIT_KEY_RIGHT, EDIT_KEY_UP, and EdLineKeyMap().
Referenced by LuaThread().