Skip to content
Myr

make_readme.c

This file

Path

tools/make_readme.c

65 lines · 2.5 KiB · C

Last changed by

Merge branch 'master' into workingSean Barrettbefore adoption6e9f34d

History of this file

Take it

The walk stopped after 200 commits: lines older than aeec66c point at it.

Merge branch 'randlong' of https://github.com/flibitijibibo/stb into workingSean Barrettbefore adoptionaeec66c

lines 1–11why, one step back
1#define STB_DEFINE
2#include "../stb.h"34int main(int argc, char **argv)5{6 int i;7 int hlen, flen, listlen, total_lines = 0;8 char *header = stb_file("README.header.md", &hlen); // stb_file - read file into malloc()ed buffer9 char *footer = stb_file("README.footer.md", &flen); // stb_file - read file into malloc()ed buffer10 char **list = stb_stringfile("README.list", &listlen); // stb_stringfile - read file lines into malloced array of strings11

fix readme linebreaksSean Barrettbefore adoptionb42009b

line 12why, one step back
12 FILE *f = fopen("../README.md", "wb");

Merge branch 'randlong' of https://github.com/flibitijibibo/stb into workingSean Barrettbefore adoptionaeec66c

line 13why, one step back
13

fix readme linebreaksSean Barrettbefore adoptionb42009b

line 14why, one step back
14 fprintf(f, "<!--- THIS FILE IS AUTOMATICALLY GENERATED, DO NOT CHANGE IT BY HAND --->\r\n\r\n");

Merge branch 'randlong' of https://github.com/flibitijibibo/stb into workingSean Barrettbefore adoptionaeec66c

lines 15–22why, one step back
15 fwrite(header, 1, hlen, f);
1617 for (i=0; i < listlen; ++i) {18 int num,j;19 char **tokens = stb_tokens_stripwhite(list[i], "|", &num); // stb_tokens -- tokenize string into malloced array of strings20 int num_lines;21 char **lines = stb_stringfile(stb_sprintf("../%s", tokens[0]), &num_lines);22 char *s1, *s2,*s3;

Merge branch 'master' into workingSean Barrettbefore adoption6e9f34d

line 23why, one step back
23 if (lines == NULL) stb_fatal("Couldn't open '%s'", tokens[0]);

Merge branch 'randlong' of https://github.com/flibitijibibo/stb into workingSean Barrettbefore adoptionaeec66c

lines 24–53why, one step back
24 s1 = strchr(lines[0], '-');
25 if (!s1) stb_fatal("Couldn't find '-' before version number in %s", tokens[0]); // stb_fatal -- print error message & exit26 s2 = strchr(s1+2, '-');27 if (!s2) stb_fatal("Couldn't find '-' after version number in %s", tokens[0]); // stb_fatal -- print error message & exit28 *s2 = 0;29 s1 += 1;30 s1 = stb_trimwhite(s1); // stb_trimwhite -- advance pointer to after whitespace & delete trailing whitespace31 if (*s1 == 'v') ++s1;32 s3 = tokens[0];33 stb_trimwhite(s3);34 fprintf(f, "**[");35 if (strlen(s3) < 21) {36 fprintf(f, "%s", tokens[0]);37 } else {38 char buffer[256];39 strncpy(buffer, s3, 18);40 buffer[18] = 0; 41 strcat(buffer, "...");42 fprintf(f, "%s", buffer);43 }44 fprintf(f, "](%s)**", tokens[0]);45 fprintf(f, " | %s", s1);46 s1 = stb_trimwhite(tokens[1]); // stb_trimwhite -- advance pointer to after whitespace & delete trailing whitespace47 s2 = stb_dupreplace(s1, " ", "&nbsp;"); // stb_dupreplace -- search & replace string and malloc result48 fprintf(f, " | %s", s2);49 free(s2);50 fprintf(f, " | %d", num_lines);51 total_lines += num_lines;52 for (j=2; j < num; ++j)53 fprintf(f, " | %s", tokens[j]);

fix readme linebreaksSean Barrettbefore adoptionb42009b

line 54why, one step back
54 fprintf(f, "\r\n");

Merge branch 'randlong' of https://github.com/flibitijibibo/stb into workingSean Barrettbefore adoptionaeec66c

lines 55–56why, one step back
55 }
56

fix readme linebreaksSean Barrettbefore adoptionb42009b

lines 57–59why, one step back
57 fprintf(f, "\r\n");
58 fprintf(f, "Total libraries: %d\r\n", listlen);59 fprintf(f, "Total lines of C code: %d\r\n\r\n", total_lines);

Merge branch 'randlong' of https://github.com/flibitijibibo/stb into workingSean Barrettbefore adoptionaeec66c

lines 60–65why, one step back
60
61 fwrite(footer, 1, flen, f);62 fclose(f);6364 return 0;65}