Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.5 KiB

  1. #define STB_DEFINE
  2. #include "../stb.h"
  3. int main(int argc, char **argv)
  4. {
  5. int i;
  6. int hlen, flen, listlen, total_lines = 0;
  7. char *header = stb_file("README.header.md", &hlen); // stb_file - read file into malloc()ed buffer
  8. char *footer = stb_file("README.footer.md", &flen); // stb_file - read file into malloc()ed buffer
  9. char **list = stb_stringfile("README.list", &listlen); // stb_stringfile - read file lines into malloced array of strings
  10. FILE *f = fopen("../README.md", "wb");
  11. fprintf(f, "<!--- THIS FILE IS AUTOMATICALLY GENERATED, DO NOT CHANGE IT BY HAND --->\n\n");
  12. fwrite(header, 1, hlen, f);
  13. for (i=0; i < listlen; ++i) {
  14. int num,j;
  15. char **tokens = stb_tokens_stripwhite(list[i], "|", &num); // stb_tokens -- tokenize string into malloced array of strings
  16. int num_lines;
  17. char **lines = stb_stringfile(stb_sprintf("../%s", tokens[0]), &num_lines);
  18. char *s1, *s2,*s3;
  19. s1 = strchr(lines[0], '-');
  20. if (!s1) stb_fatal("Couldn't find '-' before version number in %s", tokens[0]); // stb_fatal -- print error message & exit
  21. s2 = strchr(s1+2, '-');
  22. if (!s2) stb_fatal("Couldn't find '-' after version number in %s", tokens[0]); // stb_fatal -- print error message & exit
  23. *s2 = 0;
  24. s1 += 1;
  25. s1 = stb_trimwhite(s1); // stb_trimwhite -- advance pointer to after whitespace & delete trailing whitespace
  26. if (*s1 == 'v') ++s1;
  27. s3 = tokens[0];
  28. stb_trimwhite(s3);
  29. fprintf(f, "**[");
  30. if (strlen(s3) < 21) {
  31. fprintf(f, "%s", tokens[0]);
  32. } else {
  33. char buffer[256];
  34. strncpy(buffer, s3, 18);
  35. buffer[18] = 0;
  36. strcat(buffer, "...");
  37. fprintf(f, "%s", buffer);
  38. }
  39. fprintf(f, "](%s)**", tokens[0]);
  40. fprintf(f, " | %s", s1);
  41. s1 = stb_trimwhite(tokens[1]); // stb_trimwhite -- advance pointer to after whitespace & delete trailing whitespace
  42. s2 = stb_dupreplace(s1, " ", "&nbsp;"); // stb_dupreplace -- search & replace string and malloc result
  43. fprintf(f, " | %s", s2);
  44. free(s2);
  45. fprintf(f, " | %d", num_lines);
  46. total_lines += num_lines;
  47. for (j=2; j < num; ++j)
  48. fprintf(f, " | %s", tokens[j]);
  49. fprintf(f, "\n");
  50. }
  51. fprintf(f, "\n");
  52. fprintf(f, "Total libraries: %d \n", listlen);
  53. fprintf(f, "Total lines of C code: %d\n\n", total_lines);
  54. fwrite(footer, 1, flen, f);
  55. fclose(f);
  56. return 0;
  57. }