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