iPXE
editstring.h
Go to the documentation of this file.
1 #ifndef _IPXE_EDITSTRING_H
2 #define _IPXE_EDITSTRING_H
3 
4 /** @file
5  *
6  * Editable strings
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 /** An editable string */
13 struct edit_string {
14  /** Dynamically allocated string buffer */
15  char **buf;
16  /** Cursor position */
17  unsigned int cursor;
18 
19  /* The following items are the edit history */
20 
21  /** Last cursor position */
22  unsigned int last_cursor;
23  /** Start of modified portion of string */
24  unsigned int mod_start;
25  /** End of modified portion of string */
26  unsigned int mod_end;
27 };
28 
29 /**
30  * Initialise editable string
31  *
32  * @v string Editable string
33  * @v buf Dynamically allocated string buffer
34  *
35  * The @c buf parameter must be the address of a caller-provided
36  * pointer to a NUL-terminated string allocated using malloc() (or
37  * equivalent, such as strdup()). Any edits made to the string will
38  * realloc() the string buffer as needed.
39  *
40  * The caller may choose leave the initial string buffer pointer as @c
41  * NULL, in which case it will be allocated upon the first attempt to
42  * insert a character into the buffer. If the caller does this, then
43  * it must be prepared to find the pointer still @c NULL after
44  * editing, since the user may never attempt to insert any characters.
45  */
46 static inline __nonnull void init_editstring ( struct edit_string *string,
47  char **buf ) {
48 
49  string->buf = buf;
50 }
51 
52 extern __attribute__ (( nonnull ( 1 ) )) int
53 replace_string ( struct edit_string *string, const char *replacement );
54 
55 extern __nonnull int edit_string ( struct edit_string *string, int key );
56 
57 #endif /* _IPXE_EDITSTRING_H */
int replace_string(struct edit_string *string, const char *replacement)
Replace editable string.
Definition: editstring.c:228
unsigned int cursor
Cursor position.
Definition: editstring.h:17
unsigned int last_cursor
Last cursor position.
Definition: editstring.h:22
#define __nonnull
Declare a function's pointer parameters as non-null - i.e.
Definition: compiler.h:592
static __nonnull void init_editstring(struct edit_string *string, char **buf)
Initialise editable string.
Definition: editstring.h:46
const char * replacement
Definition: editstring.h:53
char ** buf
Dynamically allocated string buffer.
Definition: editstring.h:15
An editable string.
Definition: editstring.h:13
unsigned int mod_start
Start of modified portion of string.
Definition: editstring.h:24
__attribute__((nonnull(1))) int replace_string(struct edit_string *string
unsigned int mod_end
End of modified portion of string.
Definition: editstring.h:26
union @382 key
Sense key.
Definition: crypto.h:284
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)