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

showdir.c (1092B)


      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 #ifndef unitTest
     18 // Remove main when running the unit tests
     19 #define MAIN   main
     20 #endif
     21 int MAIN(int ARGC, char** ARGV) {
     22   char **list = NULL;
     23   char *path = NULL;
     24 
     25   argc = ARGC; argv = ARGV;;// Show file contents in a directory
     26   // Arg 1: path
     27 
     28   // Steps
     29   // check arguments
     30   // list files in path
     31   // print filenames in path
     32   // print file contents in path
     33 
     34   // check arguments
     35   if (argc < 2) {
     36     path = ".";
     37   }
     38   else {
     39     path = argv[1];
     40   }
     41 
     42   // list files in path
     43   list = walkDir(path);;
     44   exitFailure(list);
     45 
     46   // print filenames in path
     47   forEachCharP(list, e) {
     48     printf("%s\n", *e);
     49   }
     50 
     51   // print file contents in path
     52   forEachCharP(list, e) {
     53     char *c = catS("\n\x1B[1m\x1B[37m",*e,"\x1B[0m\n\n");
     54     printf("%s", c);
     55     free(c);
     56     char **text = readText(*e);
     57     pError0(listPrintS(text));
     58     listFreeS(text);
     59 }
     60   }