💾 Archived View for gmi.noulin.net › gitRepositories › simpleTemplates › file › simpleTemplates.c.gm… captured on 2024-08-18 at 18:52:13. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
simpleTemplates.c (1457B)
1 #include "libsheepyObject.h" 2 3 bool simpleTemplatesInsertFiles(char *templ, char *dst, smallDictt *keyFiles) { 4 if (!fileExists(templ)) { 5 return false; 6 } 7 8 // load templates 9 createAllocateSmallArray(template); 10 readFileG(template, templ); 11 //logVarG(template); 12 13 forEachSmallDict(keyFiles, k, V) { 14 castS(v, V); 15 smallStringt *path = dupG(v); 16 expandHomeG(path); 17 if (!fileExistsG(path)) { 18 printf("File for key %s not found: %s\n", k, ssGet(v)); 19 return false; 20 } 21 createAllocateSmallString(s); 22 readFileG(s, ssGet(path)); 23 terminateG(path); 24 if (getG(s, unusedV , -1) == '\n') { 25 setG(s, -1, 0); 26 } 27 setG(keyFiles, k, s); 28 finishG(v); 29 } 30 listFreeS(libsheepyInternalKeys); 31 32 char **keys = keysG(keyFiles); 33 34 enumerateSmallArray(template, L, i) { 35 castS(l, L); 36 forEachS(keys, k) { 37 smallStringt *s = getG(keyFiles, rtSmallStringt, k); 38 replaceSO_max(l, k, ssGet(s)); 39 finishG(s); 40 } 41 setPG(template, i, l); 42 finishG(l); 43 } 44 freeG(keys); 45 46 //logVarG(template); 47 48 writeFileG(template, dst); 49 50 terminateG(template); 51 return true; 52 } 53 54 55 56 57 bool simpleTemplatesReplaceKeysWithValues(smallArrayt *index, smallDictt *pageValues) { 58 iter(index, L) { 59 castS(l, L); 60 iterK(pageValues, k) { 61 replaceG(l, k, getG(pageValues, rtChar, k), 0); 62 } 63 setPG(index, iterIndexG(index), l); 64 } 65 } 66 67 68 69 70 71 bool checkLibsheepyVersionSimpleTemplates(const char *currentLibsheepyVersion) { 72 return eqG(currentLibsheepyVersion, LIBSHEEPY_VERSION); 73 }