readme.c (2809B)
1 //: generator/pp comment config 2 //:not cScript 3 #include "../release/libsheepy.h" 4 //:end 5 6 #define internal static 7 8 #include <stdlib.h> 9 #include <stdio.h> 10 11 #ifndef unitTest 12 #endif 13 int MAIN(int ARGC, char** ARGV); 14 15 int argc; char **argv; 16 17 enum {START, FUNCTIONS, DESCRIPTION, PROTOTYPE}; 18 19 #ifndef unitTest 20 // Remove main when running the unit tests 21 #define MAIN main 22 #endif 23 int MAIN(int ARGC, char** ARGV) { 24 char **list = NULL; 25 char **functionPrototypes = NULL; 26 char **libsheepyC = NULL; 27 char **descriptions = NULL; 28 char **template = NULL; 29 char **readmeResult = NULL; 30 31 argc = ARGC; argv = ARGV;;// generate readme.md at the root of this git 32 33 // Steps 34 // get function list from libsheepy.h 35 // get function descriptions 36 // read template 37 // process template 38 // save result 39 40 // get function list from libsheepy.h 41 list = readText("../src/libsheepy.h"); 42 43 int status = START;; 44 forEachCharP(list, e) { 45 if (status == FUNCTIONS) { 46 char *s; 47 s = trimS(*e); 48 if (!isEmptyS(s) && !findS(*e, "// _libsheepyH")) 49 pErrorNULL(listPushS(&functionPrototypes, *e)); 50 free(s); 51 } 52 if (findS(*e, "libsheepy API Header file _libsheepyH")) { 53 status = FUNCTIONS; 54 } 55 } 56 57 //listPrintS(functionPrototypes); 58 59 // get function descriptions 60 libsheepyC = readText("../src/libsheepy.c"); 61 62 status = START; 63 int funcStatus = START;; 64 forEachCharP(libsheepyC, e) { 65 if (status == FUNCTIONS) { 66 char *s; 67 s = sliceS(*e, 0, 3); 68 69 if (strEq(s, "/**")) 70 funcStatus = PROTOTYPE; 71 if (funcStatus == PROTOTYPE) { 72 pErrorNULL(listPushS(&descriptions, *e)); 73 } 74 if (funcStatus == DESCRIPTION) { 75 free(s); 76 s = replaceS(*e, " {", "", 0); 77 pErrorNULL(listPushS(&descriptions, s)); 78 pErrorNULL(listPushS(&descriptions, "\n")); 79 funcStatus = START; 80 } 81 if (findS(s, "*/") && (funcStatus == PROTOTYPE)) { 82 funcStatus = DESCRIPTION; 83 } 84 free(s); 85 } 86 if (findS(*e, "__libsheepy")) { 87 status = FUNCTIONS; 88 } 89 } 90 91 //listPrintS(descriptions); 92 93 // read template 94 template = readText("README.template"); 95 96 // process template 97 forEachCharP(template, e) { 98 if (findS(*e, "__functionPrototypes")) { 99 pErrorNULL(listAppendS(&readmeResult, functionPrototypes)); 100 } 101 else if (findS(*e, "__functionDescriptions")) { 102 pErrorNULL(listAppendS(&readmeResult, descriptions)); 103 } 104 else { 105 pErrorNULL(listPushS(&readmeResult, *e)); 106 } 107 } 108 109 // save result 110 pError0(writeText("../README.md", readmeResult)); 111 112 listFreeS(readmeResult); 113 listFreeS(template); 114 listFreeS(descriptions); 115 listFreeS(libsheepyC); 116 listFreeS(functionPrototypes); 117 listFreeS(list); 118 119 //---------------------------------------------- 120 }