MGE General C Library - API Documentation
Library of general C functions.
mgemessage.h
Go to the documentation of this file.
1 
16 /* **********************************************************************
17  * *
18  * Changelog *
19  * *
20  * Date Author Version Description *
21  * *
22  * 24/10/2017 MG 1.0.1 This ChangeLog introduced. *
23  * 04/11/2017 MG 1.0.2 Add Doxygen comments. *
24  * 09/11/2017 MG 1.0.3 Add SPDX license tag. *
25  * 02/01/2018 MG 1.0.4 Move to new source directory structure. *
26  * 04/08/2018 MG 1.0.5 Change mgemessage.offset to next_free *
27  * and make it size_t. *
28  * Change mgemessage.complete to bool. *
29  * 06/09/2018 MG 1.0.6 Add mgemessage struct initialiser. *
30  * 09/09/2018 MG 1.0.7 Move default message size macro to *
31  * internal header file as it should not *
32  * be part of the API. *
33  * 31/05/2019 MG 1.0.8 Use standard GNU ifdeffery around use *
34  * of AC_HEADER_STDBOOL. *
35  * 08/06/2019 MG 1.0.9 clang-format coding style changes. *
36  * 19/07/2020 MG 1.0.10 Remove get_msg() declaration, remove it *
37  * from API. *
38  * Remove deconstruct_msg() declaration, *
39  * remove it from API. *
40  * *
41  ************************************************************************
42  */
43 
44 #ifndef MGEMESSAGE_H
45 #define MGEMESSAGE_H
46 
47 #include <portability.h>
48 #include <sys/types.h>
49 
50 /* Standard GNU AC_HEADER_STDBOOL ifdeffery. */
51 #ifdef HAVE_STDBOOL_H
52  #include <stdbool.h>
53 #else
54  #ifndef HAVE__BOOL
55  #ifdef __cplusplus /* clang-format off */
56  typedef bool _Bool; /* clang-format on */
57  #else
58  #define _Bool signed char
59  #endif
60  #endif
61  #define bool _Bool
62  #define false 0
63  #define true 1
64  #define __bool_true_false_are_defined 1
65 #endif
66 
67 #include <mgebuffer.h>
68 
70 
74 struct mgemessage {
75  char *message;
76  size_t size;
77  size_t next_free;
78  bool complete;
79  char terminator;
80  char separator;
81  int argc;
82  char **argv;
83 };
84 
88 #define MGEMESSAGE_INIT(a, b) \
89  { \
90  .message = NULL, .size = 0, .next_free = 0, .complete = false, \
91  .terminator = a, .separator = b, .argc = 0, .argv = NULL \
92  }
93 
94 struct mgemessage *pull_msg(struct mgebuffer *buf, struct mgemessage *msg);
95 
96 void clear_msg(struct mgemessage *msg, const char terminator,
97  const char separator);
98 
99 void print_msg(struct mgemessage *msg);
100 
102 
103 #endif /* ndef MGEMESSAGE_H */
104 
A buffer object.
Definition: mgebuffer.h:52
char * message
The message buffer.
Definition: mgemessage.h:75
char separator
Message element delimitter.
Definition: mgemessage.h:80
struct mgemessage * pull_msg(struct mgebuffer *buf, struct mgemessage *msg)
Pull a message from a buffer object.
Definition: message.c:110
Header file to ease portability.
size_t size
Size of message buffer.
Definition: mgemessage.h:76
size_t next_free
Next free message location.
Definition: mgemessage.h:77
bool complete
Is message a complete message.
Definition: mgemessage.h:78
void print_msg(struct mgemessage *msg)
Print a message struct.
Definition: message.c:280
#define _Bool
Definition: mgemessage.h:58
char terminator
Message delimmitter.
Definition: mgemessage.h:79
char ** argv
Message arguments.
Definition: mgemessage.h:82
Message object.
Definition: mgemessage.h:74
#define END_C_DECLS
Use END_C_DECLS at the end of C declarations.
Definition: portability.h:50
void clear_msg(struct mgemessage *msg, const char terminator, const char separator)
Clear message struct.
Definition: message.c:262
Header file for buffer processing.
#define BEGIN_C_DECLS
BEGIN_C_DECLS should be used at the beginning of declarations so that C++ compilers don't mangle thei...
Definition: portability.h:46
int argc
Number of arguments to the message.
Definition: mgemessage.h:81