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

demoStatic.c (2001B)


      1 #include "../release/libsheepyObject.h"
      2 
      3 #ifndef unitTest
      4 // Remove main when running the unit tests
      5 #define MAIN   main
      6 #endif
      7 int MAIN(int ARGC, char** ARGV) {
      8   char **dummy UNUSED = NULL;
      9 
     10 #define internal static
     11 
     12 #include <stdlib.h>
     13 #include <stdio.h>
     14 
     15 #ifndef unitTest
     16 #endif
     17 int MAIN(int ARGC, char** ARGV);
     18 
     19 int argc; char **argv;
     20 
     21   argc = ARGC; argv = ARGV;
     22   printf("Steps");;
     23   printf("\n");
     24   printf("- execOut \"ls\"");
     25   printf("\n");
     26   printf("- push \"libsheepy\" at the end of list");
     27   printf("\n");
     28   printf("- push CLI argument");
     29   printf("\n");
     30   printf("- print list");
     31   printf("\n");
     32   printf("- ForEach print lines containing the words two or libsheepy");
     33   printf("\n");
     34   printf("- create new list");
     35   printf("\n");
     36   printf("- Enumerate list");
     37   printf("\n");
     38   put
     39 
     40   createAllocateSmallArray(list);
     41   // run ls and store result lines in list
     42 
     43   execG("ls -al ../src/dirTest.null/", list, NULL);
     44 
     45   // append "libsheepy" at the end of the list
     46   pushG(list, "  libsheepy  ");
     47 
     48   // if there is an argument, add it to the list
     49   if (argc > 1) {
     50     pushG(list, argv[1]);
     51   }
     52 
     53 
     54   // print list elements
     55   logG(list);
     56 
     57   printf("\nPrint lines with string \"two\" or \"libsheepy\":\n");
     58   printf("\n");
     59 
     60   // loop on list elements (lines from ls and "libsheepy")
     61   iter(list, element) {
     62     // split line with space
     63     castS(str, element);
     64     smallArrayt *splitElement = splitG(str, " ");;
     65     exitFailure(splitElement);
     66 
     67     smallStringt *lastStringInSplit = getG(splitElement, rtSmallStringt, -1);
     68 
     69     if (eqG(lastStringInSplit, "two") || eqG(lastStringInSplit, "libsheepy")) {
     70       trimG(str);
     71       putsG(str);
     72     }
     73     terminateO(splitElement);
     74     free(lastStringInSplit);
     75   }
     76 
     77 
     78   put
     79 
     80   terminateG(list);
     81   list = createSA("one", "two", "three");
     82 
     83   iter(list, e) {
     84     castS(s, e);
     85     printf("%ld - %s", iterIndexG(list)+1, ssGet(s));
     86     printf("\n");
     87   }
     88 
     89   printf("There are %zu elements in the list.", lenG(list));
     90   printf("\n");
     91 
     92   terminateG(list);
     93 }