/
mld.c
63 lines (54 loc) · 2.19 KB
/
mld.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
#include <stdlib.h>
#include "mld.h"
#include "css.h"
char *DATA_TYPE[] = {"UINT8", "UINT32", "INT32",
"CHAR", "OBJ_PTR", "FLOAT",
"DOUBLE", "OBJ_STRUCT"};
/* Dumping Function */
void
print_structure_rec(struct_db_rec_t *struct_rec){
if(!struct_rec) return;
int j = 0;
field_info_t *field = NULL;
printf(ANSI_COLOR_CYAN "|------------------------------------------------------|\n" ANSI_COLOR_RESET);
printf(ANSI_COLOR_YELLOW "| %-20s | size = %-8d | #flds = %-3d |\n" ANSI_COLOR_RESET, struct_rec->struct_name, struct_rec->ds_size, struct_rec->n_fields);
printf(ANSI_COLOR_CYAN "|------------------------------------------------------|------------------------------------------------------------------------------------------|\n" ANSI_COLOR_RESET);
for(j = 0; j < struct_rec->n_fields; j++){
field = &struct_rec->fields[j];
printf(" %-20s |", "");
printf("%-3d %-20s | dtype = %-15s | size = %-5d | offset = %-6d| nstructname = %-20s |\n",
j, field->fname, DATA_TYPE[field->dtype], field->size, field->offset, field->nested_str_name);
printf(" %-20s |", "");
printf(ANSI_COLOR_CYAN "--------------------------------------------------------------------------------------------------------------------------|\n" ANSI_COLOR_RESET);
}
}
void
print_structure_db(struct_db_t *struct_db){
if(!struct_db) return;
printf("printing structure db\n");
int i = 0;
struct_db_rec_t *struct_rec = NULL;
struct_rec = struct_db->head;
printf("No of Structures Registered = %d\n", struct_db->count);
while(struct_rec){
printf("structure No : %d (%p)\n", i++, struct_rec);
print_structure_rec(struct_rec);
struct_rec = struct_rec->next;
}
}
int
add_structure_to_struct_db(struct_db_t *struct_db,
struct_db_rec_t *struct_rec){
struct_db_rec_t *head = struct_db->head;
if(!head){
struct_db->head = struct_rec;
struct_rec->next = NULL;
struct_db->count++;
return 0;
}
struct_rec->next = head;
struct_db->head = struct_rec;
struct_db->count++;
return 0;
}