MGE General C Library - API Documentation  v1.4.1
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  * 16/04/2021 MG 1.0.11 Add print_def_msg_values() prototype. *
41  * *
42  ************************************************************************
43  */
44 
45 #ifndef MGEMESSAGE_H
46 #define MGEMESSAGE_H
47 
48 #include <portability.h>
49 #include <sys/types.h>
50 
51 /* Standard GNU AC_HEADER_STDBOOL ifdeffery. */
52 #ifdef HAVE_STDBOOL_H
53  #include <stdbool.h>
54 #else
55  #ifndef HAVE__BOOL
56  #ifdef __cplusplus /* clang-format off */
57  typedef bool _Bool; /* clang-format on */
58  #else
59  #define _Bool signed char
60  #endif
61  #endif
62  #define bool _Bool
63  #define false 0
64  #define true 1
65  #define __bool_true_false_are_defined 1
66 #endif
67 
68 #include <mgebuffer.h>
69 
71 
75 struct mgemessage {
76  char *message;
77  size_t size;
78  size_t next_free;
79  bool complete;
80  char terminator;
81  char separator;
82  int argc;
83  char **argv;
84 };
85 
89 #define MGEMESSAGE_INIT(a, b) \
90  { \
91  .message = NULL, .size = 0, .next_free = 0, .complete = false, \
92  .terminator = a, .separator = b, .argc = 0, .argv = NULL \
93  }
94 
95 struct mgemessage *pull_msg(struct mgebuffer *buf, struct mgemessage *msg);
96 
97 void clear_msg(struct mgemessage *msg, const char terminator,
98  const char separator);
99 
100 void print_msg(struct mgemessage *msg);
101 
102 void print_def_msg_values(void);
103 
105 
106 #endif /* ndef MGEMESSAGE_H */
107 
A buffer object.
Definition: mgebuffer.h:53
char * message
The message buffer.
Definition: mgemessage.h:76
char separator
Message element delimitter.
Definition: mgemessage.h:81
struct mgemessage * pull_msg(struct mgebuffer *buf, struct mgemessage *msg)
Pull a message from a buffer object.
Definition: message.c:111
Header file to ease portability.
size_t size
Size of message buffer.
Definition: mgemessage.h:77
size_t next_free
Next free message location.
Definition: mgemessage.h:78
bool complete
Is message a complete message.
Definition: mgemessage.h:79
void print_msg(struct mgemessage *msg)
Print a message struct.
Definition: message.c:281
#define _Bool
Definition: mgemessage.h:59
char terminator
Message delimmitter.
Definition: mgemessage.h:80
char ** argv
Message arguments.
Definition: mgemessage.h:83
Message object.
Definition: mgemessage.h:75
#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:263
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&#39;t mangle thei...
Definition: portability.h:46
void print_def_msg_values(void)
Print default values to stdout, for debugging.
Definition: message.c:300
int argc
Number of arguments to the message.
Definition: mgemessage.h:82