6 static size_t split(char ***strs, char *s, const char *delim)
9 *strs = malloc((1+i) * sizeof(char *));
11 char *tok = strtok(s, delim);
13 *strs = realloc(*strs, (1+i) * sizeof(char *));
15 tok = strtok(NULL, delim);
21 int main(__attribute((unused)) int argc, __attribute((unused)) char **argv)
23 FILE *fp = fopen("messages.dnet", "r");
26 memset(data, 0, sizeof data);
27 fread(data, sizeof *data, sizeof data, fp);
30 fp = fopen("messages.h", "w");
31 fprintf(fp, "#include <stdint.h>\n\n");
34 size_t msgs_len = split(&msgs, data, "\n");
37 for (size_t i = 0; i < msgs_len; i++) {
38 if (msgs[i][0] != '\t') {
40 fprintf(fp, "} %s;\n", msg);
43 fprintf(fp, "typedef struct {\n");
46 split(&tokens, msgs[i], " ");
49 if (strcmp(tokens[0], "\ts8") == 0)
50 strcpy(type, "int8_t ");
51 else if (strcmp(tokens[0], "\ts16") == 0)
52 strcpy(type, "int16_t ");
53 else if (strcmp(tokens[0], "\ts32") == 0)
54 strcpy(type, "int32_t ");
55 else if (strcmp(tokens[0], "\ts64") == 0)
56 strcpy(type, "int64_t ");
57 else if (strcmp(tokens[0], "\tu8") == 0)
58 strcpy(type, "uint8_t ");
59 else if (strcmp(tokens[0], "\tu16") == 0)
60 strcpy(type, "uint16_t ");
61 else if (strcmp(tokens[0], "\tu32") == 0)
62 strcpy(type, "uint32_t ");
63 else if (strcmp(tokens[0], "\tu64") == 0)
64 strcpy(type, "uint64_t ");
66 fprintf(fp, "\t%s%s;\n", type, tokens[1]);
71 fprintf(fp, "} %s;\n", msg);