39 const char *insert_text )
58 const char *insert_text ) {
59 size_t old_len, max_delete_len, insert_len, max_insert_len, new_len;
64 max_delete_len = ( old_len -
string->cursor );
65 if ( delete_len > max_delete_len )
66 delete_len = max_delete_len;
67 insert_len = ( insert_text ?
strlen ( insert_text ) : 0 );
68 max_insert_len = ( (
string->len - 1 ) - ( old_len - delete_len ) );
69 if ( insert_len > max_insert_len )
70 insert_len = max_insert_len;
71 new_len = ( old_len - delete_len + insert_len );
74 string->mod_start =
string->cursor;
75 string->mod_end = ( ( new_len > old_len ) ? new_len : old_len );
80 ( max_delete_len + 1 - delete_len ) );
84 string->cursor += insert_len;
94 unsigned int character ) {
95 char insert_text[2] = { character,
'\0' };
114 if (
string->cursor > 0 ) {
142 size_t old_cursor =
string->cursor;
153 size_t old_cursor =
string->cursor;
200 string->last_cursor =
string->cursor;
201 string->mod_start =
string->cursor;
202 string->mod_end =
string->cursor;
205 if ( (
key >= 0x20 ) && (
key <= 0x7e ) ) {
208 }
else switch (
key ) {
238 string->cursor =
len;
void replace_string(struct edit_string *string, const char *replacement)
Replace editable string.
int edit_string(struct edit_string *string, int key)
Edit editable string.
static void backspace(struct edit_string *string) __nonnull
Delete character to left of current cursor position.
#define __nonnull
Declare a function's pointer parameters as non-null - i.e.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
int isspace(int character)
Check to see if character is a space.
size_t strlen(const char *src)
Get length of string.
static void insert_character(struct edit_string *string, unsigned int character) __nonnull
Insert character at current cursor position.
void * memmove(void *dest, const void *src, size_t len) __nonnull
static void kill_eol(struct edit_string *string) __nonnull
Delete to end of line.
static void kill_sol(struct edit_string *string) __nonnull
Delete to start of line.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define KEY_RIGHT
Right arrow.
static void insert_delete(struct edit_string *string, size_t delete_len, const char *insert_text) __attribute__((nonnull(1)))
Insert and/or delete text within an editable string.
static void kill_word(struct edit_string *string) __nonnull
Delete to end of previous word.
#define NULL
NULL pointer (VOID *)
static void previous_word(struct edit_string *string) __nonnull
Move to start of previous word.
#define KEY_LEFT
Left arrow.
static void delete_character(struct edit_string *string) __nonnull
Delete character at current cursor position.