42 insert_delete ( struct
edit_string *
string,
size_t delete_len,
43 const
char *insert_text );
45 unsigned int character );
61 static
int insert_delete ( struct
edit_string *
string,
size_t delete_len,
62 const
char *insert_text ) {
63 size_t old_len, max_delete_len, move_len, insert_len, new_len;
68 string->mod_start =
string->cursor;
69 string->mod_end =
string->cursor;
73 old_len = ( buf ?
strlen ( buf ) : 0 );
75 max_delete_len = ( old_len -
string->cursor );
76 if ( delete_len > max_delete_len )
77 delete_len = max_delete_len;
78 move_len = ( max_delete_len - delete_len );
79 insert_len = ( insert_text ?
strlen ( insert_text ) : 0 );
80 new_len = ( old_len - delete_len + insert_len );
84 ( buf +
string->cursor + delete_len ), move_len );
91 }
else if ( ( new_len > old_len ) || ( ! buf ) ) {
97 ( buf +
string->cursor ), move_len );
100 memcpy ( ( buf +
string->cursor ), insert_text, insert_len );
101 string->cursor += insert_len;
107 string->mod_end = ( ( new_len > old_len ) ? new_len : old_len );
120 unsigned int character ) {
121 char insert_text[2] = { character,
'\0' };
123 return insert_delete (
string, 0, insert_text );
134 rc = insert_delete (
string, 1,
NULL );
145 if (
string->cursor > 0 ) {
157 const char *buf = *(
string->buf);
158 size_t cursor =
string->cursor;
160 while ( cursor &&
isspace ( buf[ cursor - 1 ] ) ) {
163 while ( cursor && ( !
isspace ( buf[ cursor - 1 ] ) ) ) {
166 string->cursor = cursor;
175 size_t old_cursor =
string->cursor;
179 rc = insert_delete (
string, ( old_cursor -
string->cursor ),
NULL );
189 size_t old_cursor =
string->cursor;
193 rc = insert_delete (
string, old_cursor,
NULL );
205 rc = insert_delete (
string, ~( (
size_t ) 0 ),
NULL );
232 return insert_delete (
string, ~( (
size_t ) 0 ),
replacement );
257 const char *buf = *(
string->buf);
258 size_t len = ( buf ?
strlen ( buf ) : 0 );
262 string->last_cursor =
string->cursor;
263 string->mod_start =
string->cursor;
264 string->mod_end =
string->cursor;
267 if ( (
key >= 0x20 ) && (
key <= 0x7e ) ) {
270 }
else switch (
key ) {
300 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.