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.
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.
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
|
static |
Synchronise console with edited string.
string | Editable string |
Definition at line 46 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 88 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 104 of file readline.c.
References history_entry(), readline_history_entry::string, and readline_history_entry::temp.
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 122 of file readline.c.
References DBGC, 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 150 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 177 of file readline.c.
References assert(), DBGC, free, history_entry(), readline_history::next, NULL, strdup(), and readline_history_entry::string.
Referenced by readline_history().
|
static |
Clean up history after editing.
history | History buffer |
Definition at line 206 of file readline.c.
References assert(), readline_history::depth, readline_history::entries, free, history_entry(), NULL, readline_history_entry::string, and readline_history_entry::temp.
Referenced by readline_history().
void history_free | ( | struct readline_history * | history | ) |
Free history buffer.
history | History buffer |
Definition at line 231 of file readline.c.
References assert(), readline_history::entries, free, NULL, readline_history_entry::string, and readline_history_entry::temp.
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 257 of file readline.c.
References assert(), CR, CTRL_C, done, ECANCELED, edit_string(), error, ETIMEDOUT, free, getkey(), history_append(), history_cleanup(), history_move(), init_editstring(), key, KEY_DOWN, KEY_UP, LF, memset(), NULL, printf(), prompt(), putchar(), rc, replace_string(), string, sync_console(), and timeout().
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 349 of file readline.c.
References NULL, prompt(), and readline_history().