40 " -V log level: LOG_INFO, LOG_NOTICE, LOG_ERR, LOG_DEBUG\n"
53 while ((
getoptret = getopt(argc, argv,
"hvV:")) != EOF) {
56 fprintf(stderr,
"Date de compilation : %s a %s.\n", __DATE__, __TIME__);
59 if (!strcmp(
"LOG_NULL", optarg))
61 else if (!strcmp(
"LOG_NOTICE", optarg))
63 else if (!strcmp(
"LOG_INFO", optarg))
65 else if (!strcmp(
"LOG_ERR", optarg))
67 else if (!strcmp(
"LOG_DEBUG", optarg))
70 fprintf(stderr,
"%s n'est pas un niveau de log valide.\n", optarg);
77 fprintf(stderr,
"\n Missing log level\n");
78 }
else if (optopt ==
'p') {
79 fprintf(stderr,
"\n Missing port\n");
80 }
else if (optopt !=
's') {
81 fprintf(stderr,
"\n Unknow missing option %c\n", optopt);
95int main(
int argc,
char** argv) {
102 n_log(
LOG_INFO,
"created stack of 16 elements at %p", stack);
104 for (
int it = 0; it < 20; it++) {
105 int32_t nb = rand() % 10;
106 bool btest = rand() % 2;
112 for (
int it = 0; it < 20; it++) {
133 n_log(
LOG_ERR,
"error popping value ! status: %d", status);
150 double dval = 3.14159;
166 uint32_t u32val = 123456;
170 int data_value = 999;
171 void* pval = &data_value;
175 int32_t i32val = -789;
186 switch (peek_item->
v_type) {
217 n_log(
LOG_INFO,
"popped pointer: %p (value=%d)", pv, pv ? *(
int*)pv : 0);
void process_args(int argc, char **argv)
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_DEBUG
debug-level messages
#define LOG_ERR
error conditions
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL )
#define LOG_NOTICE
normal but significant condition
#define LOG_NULL
no log output
#define LOG_INFO
informational
size_t tail
position of tail
uint8_t v_type
type of the item
double stack_pop_d(STACK *stack, uint8_t *status)
helper to pop a double
bool stack_pop_b(STACK *stack, uint8_t *status)
helper to pop a bool
#define STACK_ITEM_UINT32
v_type value for a uint32_t
STACK_ITEM * stack_peek(STACK *stack, size_t position)
peek in the stack without removing the stack item
int8_t stack_pop_i8(STACK *stack, uint8_t *status)
helper to pop a int8_t
#define STACK_ITEM_INT8
v_type value for a int8_t
char stack_pop_c(STACK *stack, uint8_t *status)
helper to pop a char
bool stack_is_empty(const STACK *stack)
test if the stack is empty
float stack_pop_f(STACK *stack, uint8_t *status)
helper to pop a float
#define STACK_ITEM_PTR
v_type value for a void *pointer
uint8_t stack_pop_ui8(STACK *stack, uint8_t *status)
helper to pop a uint8_t
bool stack_is_full(const STACK *stack)
test if the stack is full
#define STACK_ITEM_INT32
v_type value for a int32_t
#define STACK_ITEM_CHAR
v_type value for a char
#define STACK_ITEM_OK
code for a successfully retrieved item
uint32_t stack_pop_ui32(STACK *stack, uint8_t *status)
helper to pop a uint32_t
#define STACK_ITEM_BOOL
v_type value for a bool
#define STACK_IS_UNDEFINED
code for a NULL stack state
#define STACK_ITEM_UINT8
v_type value for a uint8_t
int32_t stack_pop_i32(STACK *stack, uint8_t *status)
helper to pop a int32_t
#define stack_push(__STACK, __VAL)
#define STACK_ITEM_DOUBLE
v_type value for a double
bool delete_stack(STACK **stack)
delete a STACK *stack
#define STACK_ITEM_FLOAT
v_type value for a float
STACK * new_stack(size_t size)
allocate a new STACK
void * stack_pop_p(STACK *stack, uint8_t *status)
helper to pop a pointer
structure of a STACK item
Common headers and low-level functions & define.
Stack header definitions.
N_STR and string function declaration.