iPXE
|
Minimal readline. More...
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <ipxe/console.h>
#include <ipxe/keys.h>
#include <ipxe/editstring.h>
#include <readline/readline.h>
Go to the source code of this file.
Macros | |
#define | READLINE_MAX 1024 |
Functions | |
FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
static void | sync_console (struct edit_string *string) |
Synchronise console with edited string. More... | |
static struct readline_history_entry * | history_entry (struct readline_history *history, unsigned int depth) |
Locate history entry. More... | |
static const char * | history_fetch (struct readline_history *history, unsigned int depth) |
Read string from history buffer. More... | |
static void | history_store (struct readline_history *history, unsigned int depth, const char *string) |
Write temporary string copy to history buffer. More... | |
static const char * | history_move (struct readline_history *history, int offset, const char *old_string) |
Move to new history depth. More... | |
static void | history_append (struct readline_history *history, const char *string) |
Append new history entry. More... | |
static void | history_cleanup (struct readline_history *history) |
Clean up history after editing. More... | |
void | history_free (struct readline_history *history) |
Free history buffer. More... | |
int | readline_history (const char *prompt, const char *prefill, struct readline_history *history, unsigned long timeout, char **line) |
Read line from console (with history) More... | |
char * | readline (const char *prompt) |
Read line from console. More... | |
Minimal readline.
Definition in file readline.c.
#define READLINE_MAX 1024 |
Definition at line 41 of file readline.c.
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
|
static |
Synchronise console with edited string.
string | Editable string |
Definition at line 48 of file readline.c.
References len, mod_end, mod_start, putchar(), string, and strlen().
Referenced by readline_history().
|
static |
Locate history entry.
history | History buffer |
depth | Depth within history buffer |
entry | History entry |
Definition at line 89 of file readline.c.
References readline_history::entries, readline_history::next, and offset.
Referenced by history_append(), history_cleanup(), history_fetch(), and history_store().
|
static |
Read string from history buffer.
history | History buffer |
depth | Depth within history buffer |
string | String |
Definition at line 105 of file readline.c.
References entry, and history_entry().
Referenced by history_move().
|
static |
Write temporary string copy to history buffer.
history | History buffer |
depth | Depth within history buffer |
string | String |
Definition at line 123 of file readline.c.
References DBGC, entry, free, history_entry(), strdup(), and readline_history_entry::temp.
Referenced by history_move().
|
static |
Move to new history depth.
history | History buffer |
offset | Offset by which to change depth |
old_string | String (possibly modified) at current depth |
new_string | String at new depth, or NULL for no movement |
Definition at line 151 of file readline.c.
References readline_history::depth, history_fetch(), history_store(), NULL, offset, and READLINE_HISTORY_MAX_DEPTH.
Referenced by readline_history().
|
static |
Append new history entry.
history | History buffer |
string | String |
Definition at line 178 of file readline.c.
References assert(), DBGC, entry, free, history_entry(), readline_history::next, NULL, and strdup().
Referenced by readline_history().
|
static |
Clean up history after editing.
history | History buffer |
Definition at line 207 of file readline.c.
References assert(), readline_history::depth, readline_history::entries, entry, free, history_entry(), and NULL.
Referenced by readline_history().
void history_free | ( | struct readline_history * | history | ) |
Free history buffer.
history | History buffer |
Definition at line 232 of file readline.c.
References assert(), readline_history::entries, entry, free, and NULL.
Referenced by shell().
int readline_history | ( | const char * | prompt, |
const char * | prefill, | ||
struct readline_history * | history, | ||
unsigned long | timeout, | ||
char ** | line | ||
) |
Read line from console (with history)
prompt | Prompt string |
prefill | Prefill string, or NULL for no prefill |
history | History buffer, or NULL for no history |
timeout | Timeout period, in ticks (0=indefinite) |
line | Line read from console (excluding terminating newline) |
rc | Return status code |
The returned line is allocated with malloc(); the caller must eventually call free() to release the storage.
Definition at line 258 of file readline.c.
References assert(), edit_string::buf, CR, CTRL_C, done, ECANCELED, edit_string(), ENOMEM, ETIMEDOUT, free, getkey(), history_append(), history_cleanup(), history_move(), init_editstring(), key, KEY_DOWN, KEY_UP, LF, memset(), NULL, printf(), prompt(), putchar(), rc, READLINE_MAX, realloc(), replace_string(), string, strlen(), sync_console(), timeout(), and zalloc().
Referenced by readline(), and shell().
char* readline | ( | const char * | prompt | ) |
Read line from console.
prompt | Prompt string |
line | Line read from console (excluding terminating newline) |
The returned line is allocated with malloc(); the caller must eventually call free() to release the storage.
Definition at line 363 of file readline.c.
References NULL, prompt(), and readline_history().