libsheepy

C lib for handling text files, strings and json like data structure with an object oriented system
git clone https://spartatek.se/git/libsheepy.git
Log | Files | Refs | README | LICENSE

commit cbfaffb72443c0af6d7e6a48b5f6800ccb746add
parent 3b512870c359ddc83e5495d7a2a618b3f4ae8ef8
Author: Remy Noulin <loader2x@gmail.com>
Date:   Fri, 28 May 2021 09:36:17 +0200

update examples

example/b2j.c          | 18 ++++++------------
example/b2y.c          | 18 ++++++------------
example/cpy.c          |  9 ++-------
example/forest.c       |  9 ++-------
example/here.c         |  8 ++------
example/json.c         |  3 +--
example/smallObjects.c | 39 ++++++++++++---------------------------
example/template.c     |  2 --
release/libsheepy.h    |  2 +-
9 files changed, 32 insertions(+), 76 deletions(-)

Diffstat:
Mexample/b2j.c | 18++++++------------
Mexample/b2y.c | 18++++++------------
Mexample/cpy.c | 9++-------
Mexample/forest.c | 9++-------
Mexample/here.c | 8++------
Mexample/json.c | 3+--
Mexample/smallObjects.c | 39++++++++++++---------------------------
Mexample/template.c | 2--
Mrelease/libsheepy.h | 2+-
9 files changed, 32 insertions(+), 76 deletions(-)

diff --git a/example/b2j.c b/example/b2j.c @@ -4,7 +4,6 @@ #define internal static -#include <stdlib.h> #ifndef unitTest #endif @@ -32,9 +31,9 @@ int MAIN(int ARGC, char** ARGV) { XFAILURE } - char *iFName = argv[1]; - char *oFName = dupG(iFName); - char *p = findG(oFName, "."); + char *iFName = argv[1]; + cleanCharP(oFName) = dupG(iFName); + char *p = findG(oFName, "."); if (p) { // remove extension *p = 0; @@ -42,10 +41,10 @@ int MAIN(int ARGC, char** ARGV) { appendG(&oFName, ".json"); // create json object - createAllocateSmallJson(json); + cleanAllocateSmallJson(json); // create bytes object - createAllocateSmallBytes(B); + cleanAllocateSmallBytes(B); readFileG(B, iFName); @@ -57,12 +56,7 @@ int MAIN(int ARGC, char** ARGV) { puts(BLD RED "Overwriting: " RST); puts(oFName); } - char *js = stringifyG(json,2); { + cleanCharP(js) = stringifyG(json,2); { writeFileG(js, oFName); - - free(js); - terminateO(B); - free(oFName); - terminateO(json); } } diff --git a/example/b2y.c b/example/b2y.c @@ -4,7 +4,6 @@ #define internal static -#include <stdlib.h> #ifndef unitTest #endif @@ -32,9 +31,9 @@ int MAIN(int ARGC, char** ARGV) { XFAILURE } - char *iFName = argv[1]; - char *oFName = dupG(iFName); - char *p = findG(oFName, "."); + char *iFName = argv[1]; + cleanCharP(oFName) = dupG(iFName); + char *p = findG(oFName, "."); if (p) { // remove extension *p = 0; @@ -42,10 +41,10 @@ int MAIN(int ARGC, char** ARGV) { appendG(&oFName, ".yml"); // create json object - createAllocateSmallJson(json); + cleanAllocateSmallJson(json); // create bytes object - createAllocateSmallBytes(B); + cleanAllocateSmallBytes(B); readFileG(B, iFName); @@ -57,11 +56,6 @@ int MAIN(int ARGC, char** ARGV) { puts(BLD RED "Overwriting: " RST); puts(oFName); } - char *yml = toYMLG(json,2); + cleanCharP(yml) = toYMLG(json,2); writeFileG(yml, oFName); - - free(yml); - terminateO(B); - free(oFName); - terminateO(json); } diff --git a/example/cpy.c b/example/cpy.c @@ -4,7 +4,6 @@ #define internal static -#include <stdlib.h> #ifndef unitTest #endif @@ -28,15 +27,11 @@ int MAIN(int ARGC, char** ARGV) { if (argc < 3) { // only one parameter - char *cmd = catS("cp -r ", argv[1], " ."); - puts(cmd); - systemNFree(cmd); + logSystemf("cp -r %s .", argv[1]); } else { rangeFrom(i, 1, argc-1) { - char *cmd = catS("cp -r ", argv[i], " ", argv[argc-1]); - puts(cmd); - systemNFree(cmd); + logSystemf("cp -r %s %s", argv[1], argv[argc-1]); } } } diff --git a/example/forest.c b/example/forest.c @@ -34,7 +34,7 @@ int MAIN(int ARGC, char** ARGV) { } // list folders in path 1 - smallArrayt *dirs = walkDirDirG(rtSmallArrayt, argv[1]);; + cleanSmallArrayP(dirs) = walkDirDirG(rtSmallArrayt, argv[1]);; //logG(dirs); @@ -46,17 +46,12 @@ int MAIN(int ARGC, char** ARGV) { sliceG(sSrc, len, 0); if (!isEmptyG(sSrc)) { // create path in argument 2 folder (destination) - smallStringt *dstPath = allocSmallString(argv[2]); + cleanSmallStringP(dstPath) = allocSmallString(argv[2]); pushG(dstPath, "/"); appendG(dstPath, sSrc); putsG(dstPath); // make dir in destination mkdirParentsG(dstPath); - terminateG(dstPath); } - terminateG(sSrc); } - - terminateG(dirs); - finalizeLibsheepy(); } diff --git a/example/here.c b/example/here.c @@ -32,11 +32,11 @@ int MAIN(int ARGC, char** ARGV) { } // copy arguments to array args - createAllocateSmallArray(args); + cleanAllocateSmallArray(args); fromArrayG(args, &argv[1], argc-1); // list files in current folder - smallArrayt *a = walkDirG(rtSmallArrayt, "."); + cleanSmallArrayP(a) = walkDirG(rtSmallArrayt, "."); // print path having any word given on the command line iter(a, l) { @@ -48,8 +48,4 @@ int MAIN(int ARGC, char** ARGV) { } } } - - terminateG(a); - terminateG(args); - finalizeLibsheepy(); } diff --git a/example/json.c b/example/json.c @@ -47,7 +47,7 @@ int MAIN(int ARGC, char** ARGV) { // load text to file array createAllocateSmallArray(file); readFileG(file, "file.json"); - smallStringt *jsonText = joinG(file, "\n"); + cleanSmallStringP(jsonText) = joinG(file, "\n"); // parse parseG(json, ssGet(jsonText)); @@ -85,7 +85,6 @@ int MAIN(int ARGC, char** ARGV) { freeG(json); freeG(file); - terminateG(jsonText); puts(BLD GRN "Loading YML file:" RST " fileA.yml"); diff --git a/example/smallObjects.c b/example/smallObjects.c @@ -32,16 +32,16 @@ int MAIN(int ARGC, char** ARGV) { // free all objects // create objects - smallBoolt *cBool = allocSmallBool(true); - smallContainert *container = allocSmallContainer(NULL); - smallDictt *dict = allocSmallDict(); - smallDoublet *cDouble = allocSmallDouble(10); - smallIntt *cInt = allocSmallInt(255); - smallJsont *json = allocSmallJson(); - smallStringt *string = allocSmallString("libsheepy"); - createAllocateSmallArray(strArray); - smallArrayt *tommy = allocSmallArray(); - undefinedt *undef = allocUndefined(); + cleanSmallBoolP(cBool) = allocSmallBool(true); + cleanSmallContainerP(container) = allocSmallContainer(NULL); + cleanSmallDictP(dict) = allocSmallDict(); + cleanSmallDoubleP(cDouble) = allocSmallDouble(10); + cleanSmallIntP(cInt) = allocSmallInt(255); + cleanSmallJsonP(json) = allocSmallJson(); + cleanSmallStringP(string) = allocSmallString("libsheepy"); + cleanAllocateSmallArray(strArray); + cleanSmallArrayP(tommy) = allocSmallArray(); + cleanUndefinedP(undef) = allocUndefined(); // add type string to stringArrayt strArray pushG(strArray, (char *)cBool->type); @@ -56,7 +56,7 @@ int MAIN(int ARGC, char** ARGV) { pushG(strArray, (char *)undef->type); // copy strArray to anotherStringArray - smallArrayt *anotherStringArray; + cleanSmallArrayP(anotherStringArray); anotherStringArray = duplicateG(strArray); @@ -86,23 +86,8 @@ int MAIN(int ARGC, char** ARGV) { // print anotherStringArray logG(anotherStringArray); - terminateG(anotherStringArray); - // print again types without effects puts(UDL "\nObject Types:" RST); logG(strArray); - - // free all objects - terminateG(cBool); - terminateG(container); - terminateG(dict); - terminateG(cDouble); - terminateG(cInt); - terminateG(json); - terminateG(string); - terminateG(tommy); - terminateG(undef); - terminateG(strArray); - - finalizeLibsheepy(); } + diff --git a/example/template.c b/example/template.c @@ -12,6 +12,4 @@ int main(int ARGC, char** ARGV) { puts("C template"); - finalizeLibsheepy(); - } diff --git a/release/libsheepy.h b/release/libsheepy.h @@ -98,7 +98,7 @@ // version accoring to the version package: Release.Major.minor.patch // https://noulin.net/version/file/README.md.html -#define LIBSHEEPY_VERSION "1.2.5" +#define LIBSHEEPY_VERSION "2.2.5.1" #ifndef SH_PREFIX #define SH_PREFIX(NAME) NAME