4 int main(int argc
, char **argv
)
7 int hlen
, flen
, listlen
, total_lines
= 0;
8 char *header
= stb_file("README.header.md", &hlen
); // stb_file - read file into malloc()ed buffer
9 char *footer
= stb_file("README.footer.md", &flen
); // stb_file - read file into malloc()ed buffer
10 char **list
= stb_stringfile("README.list", &listlen
); // stb_stringfile - read file lines into malloced array of strings
12 FILE *f
= fopen("../README.md", "wb");
14 fprintf(f
, "<!--- THIS FILE IS AUTOMATICALLY GENERATED, DO NOT CHANGE IT BY HAND --->\n\n");
15 fwrite(header
, 1, hlen
, f
);
17 for (i
=0; i
< listlen
; ++i
) {
19 char **tokens
= stb_tokens_stripwhite(list
[i
], "|", &num
); // stb_tokens -- tokenize string into malloced array of strings
21 char **lines
= stb_stringfile(stb_sprintf("../%s", tokens
[0]), &num_lines
);
23 s1
= strchr(lines
[0], '-');
24 if (!s1
) stb_fatal("Couldn't find '-' before version number in %s", tokens
[0]); // stb_fatal -- print error message & exit
25 s2
= strchr(s1
+2, '-');
26 if (!s2
) stb_fatal("Couldn't find '-' after version number in %s", tokens
[0]); // stb_fatal -- print error message & exit
29 s1
= stb_trimwhite(s1
); // stb_trimwhite -- advance pointer to after whitespace & delete trailing whitespace
34 if (strlen(s3
) < 21) {
35 fprintf(f
, "%s", tokens
[0]);
38 strncpy(buffer
, s3
, 18);
40 strcat(buffer
, "...");
41 fprintf(f
, "%s", buffer
);
43 fprintf(f
, "](%s)**", tokens
[0]);
44 fprintf(f
, " | %s", s1
);
45 s1
= stb_trimwhite(tokens
[1]); // stb_trimwhite -- advance pointer to after whitespace & delete trailing whitespace
46 s2
= stb_dupreplace(s1
, " ", " "); // stb_dupreplace -- search & replace string and malloc result
47 fprintf(f
, " | %s", s2
);
49 fprintf(f
, " | %d", num_lines
);
50 total_lines
+= num_lines
;
51 for (j
=2; j
< num
; ++j
)
52 fprintf(f
, " | %s", tokens
[j
]);
57 fprintf(f
, "Total libraries: %d \n", listlen
);
58 fprintf(f
, "Total lines of C code: %d\n\n", total_lines
);
60 fwrite(footer
, 1, flen
, f
);