41 insert_delete ( struct
edit_string *
string,
size_t delete_len,
42 const
char *insert_text );
44 unsigned int character );
60 static
int insert_delete ( struct
edit_string *
string,
size_t delete_len,
61 const
char *insert_text ) {
62 size_t old_len, max_delete_len, move_len, insert_len, new_len;
67 string->mod_start =
string->cursor;
68 string->mod_end =
string->cursor;
72 old_len = ( buf ?
strlen ( buf ) : 0 );
74 max_delete_len = ( old_len -
string->cursor );
75 if ( delete_len > max_delete_len )
76 delete_len = max_delete_len;
77 move_len = ( max_delete_len - delete_len );
78 insert_len = ( insert_text ?
strlen ( insert_text ) : 0 );
79 new_len = ( old_len - delete_len + insert_len );
83 ( buf +
string->cursor + delete_len ), move_len );
90 }
else if ( ( new_len > old_len ) || ( ! buf ) ) {
96 ( buf +
string->cursor ), move_len );
99 memcpy ( ( buf +
string->cursor ), insert_text, insert_len );
100 string->cursor += insert_len;
106 string->mod_end = ( ( new_len > old_len ) ? new_len : old_len );
119 unsigned int character ) {
120 char insert_text[2] = { character,
'\0' };
122 return insert_delete (
string, 0, insert_text );
133 rc = insert_delete (
string, 1,
NULL );
144 if (
string->cursor > 0 ) {
156 const char *buf = *(
string->buf);
157 size_t cursor =
string->cursor;
159 while ( cursor &&
isspace ( buf[ cursor - 1 ] ) ) {
162 while ( cursor && ( !
isspace ( buf[ cursor - 1 ] ) ) ) {
165 string->cursor = cursor;
174 size_t old_cursor =
string->cursor;
178 rc = insert_delete (
string, ( old_cursor -
string->cursor ),
NULL );
188 size_t old_cursor =
string->cursor;
192 rc = insert_delete (
string, old_cursor,
NULL );
204 rc = insert_delete (
string, ~( (
size_t ) 0 ),
NULL );
231 return insert_delete (
string, ~( (
size_t ) 0 ),
replacement );
256 const char *buf = *(
string->buf);
257 size_t len = ( buf ?
strlen ( buf ) : 0 );
261 string->last_cursor =
string->cursor;
262 string->mod_start =
string->cursor;
263 string->mod_end =
string->cursor;
266 if ( (
key >= 0x20 ) && (
key <= 0x7e ) ) {
269 }
else switch (
key ) {
299 string->cursor =
len;
struct arbelprm_rc_send_wqe rc
int replace_string(struct edit_string *string, const char *replacement)
Replace editable string.
static __attribute__((nonnull(1)))
int edit_string(struct edit_string *string, int key)
Edit editable string.
static int insert_character(struct edit_string *string, unsigned int character)
Insert character at current cursor position.
static void backspace(struct edit_string *string)
Delete character to left of current cursor position.
#define ENOMEM
Not enough space.
#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.
void * memmove(void *dest, const void *src, size_t len) __nonnull
static void kill_eol(struct edit_string *string)
Delete to end of line.
static void kill_sol(struct edit_string *string)
Delete to start of line.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define KEY_RIGHT
Right arrow.
void * realloc(void *old_ptr, size_t new_size)
Reallocate memory.
static void kill_word(struct edit_string *string)
Delete to end of previous word.
#define NULL
NULL pointer (VOID *)
static void previous_word(struct edit_string *string)
Move to start of previous word.
#define KEY_LEFT
Left arrow.
static void delete_character(struct edit_string *string)
Delete character at current cursor position.