item->element in da
authorThomas Walker Lynch <thomas.lynch@reasoningtechnology.com>
Fri, 22 Mar 2019 16:33:17 +0000 (17:33 +0100)
committerThomas Walker Lynch <thomas.lynch@reasoningtechnology.com>
Fri, 22 Mar 2019 16:33:17 +0000 (17:33 +0100)
21 files changed:
makefile
src-0/1_tests/da.cli.h [deleted file]
src-da/0_makefile-flags
src-da/1_include/da.h
src-da/1_lib/libda.a [deleted file]
src-da/1_tests/0_makefile-flags
src-da/1_tests/test_da.lib.c
src-da/1_tmp/makefile_deps [deleted file]
src-da/da.lib.c
src-da/da.lib.h
src-da/da.lib.o [deleted file]
src-db/1_tmp/makefile_deps [deleted file]
src-db/dbprintf.lib.h [deleted file]
src-tranche/0_makefile-flags
src-tranche/1_doc/todo.txt [new file with mode: 0644]
src-tranche/1_tests/test.dat [new file with mode: 0644]
src-tranche/tranche.cli.c
stage/include/da.h
stage/lib/libda.a [deleted file]
tools/bin/make
tools/lib/makefile_cc

index f8e38f8..c8d9a4e 100755 (executable)
--- a/makefile
+++ b/makefile
@@ -1,19 +1,31 @@
-#subdirectories=$(shell /usr/bin/find . -maxdepth 1 -printf "%f " | sed y/\./\ /)
-subdirectories=$(wildcard src-*)
+SRCDIRS= $(wildcard src-*)
+MAKEABLE=$(shell \
+    find src-*\
+       -mindepth 1  \
+       \( -name '?_makefile' -o -name 'makefile' -o -name 'Makefile' \)\
+       -printf "%h\n"\
+    | grep -v deprecated | grep -v doc | sort -u | sed ':a;N;$!ba;s/\n/ /g' \
+)
 
 all :
-#      $(foreach dir, $(subdirectories), \
-#              if [ -f $(dir)/0_makefile ]; then \
-#                      make -C $(dir) all && make -C $(dir) stage; \
-#              fi;\
-#      )
-
-dist-clean :
-       $(foreach dir, $(subdirectories), \
-               cd $(dir);\
-               make dist-clean;\
+       $(foreach dir, $(MAKEABLE), \
+         make -C $$dir
+         -make -C $$dir stage
        )
 
+info:
+       @echo "SRCDIRS:" $(SRCDIRS)
+       @echo "MAKEABLE:" $(MAKEABLE)
+
+clean :
+       for dir in $(MAKEABLE); do pushd $$dir; make clean; popd; done
+
+dist-clean : clean
+       for i in $(wildcard stage/lib/*); do rm $$i; done
+       for i in $(wildcard stage/inc/*); do rm $$i; done
+       for i in $(wildcard stage/bin/*); do rm $$i; done
+
+
 
 
 
diff --git a/src-0/1_tests/da.cli.h b/src-0/1_tests/da.cli.h
deleted file mode 100644 (file)
index 6ea42df..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-/* \aThis file was automatically generated.  Do not edit! */
-#undef INTERFACE
-int test_da_0();
index daa96bb..31435c3 100644 (file)
@@ -30,3 +30,5 @@ LIBFILE=libda.a
 INCFILE=da.h
 
 MAKE=/usr/bin/make --no-print-directory -f $(PROJECT_SUBU)/tools/lib/makefile_cc
+#MAKE=/usr/bin/make -f $(PROJECT_SUBU)/tools/lib/makefile_cc
+
index d5ba4db..d4e34de 100644 (file)
@@ -6,23 +6,23 @@
 
 typedef struct Da{
   char *base;
-  char *end; // one byte/one item off the end of the array
+  char *end; // one byte/one element off the end of the array
   size_t size; // size >= (end - base) + 1;
-  size_t item_size;
+  size_t element_size;
 } Da;
 
 #define RETURN(dap, r)                      \
   { da_map(dap, da_free, NULL); return r; }
 
-void da_alloc(Da *dap, size_t item_size);
+void da_alloc(Da *dap, size_t element_size);
 void da_free(Da *dap);
 void da_rewind(Da *dap);
 char *da_expand(Da *dap);
 void da_rebase(Da *dap, char *old_base, void *pta);
 bool da_endq(Da *dap, void *pt);
 bool da_boundq(Da *dap);
-void da_push(Da *dap, void *item);
-bool da_pop(Da *dap, void *item);
+void da_push(Da *dap, void *element);
+bool da_pop(Da *dap, void *element);
 void da_map(Da *dap, void f(void *, void *), void *closure);
 void da_free_elements(Da *dap);
 char *da_fgets(Da *dap, FILE *fd);
diff --git a/src-da/1_lib/libda.a b/src-da/1_lib/libda.a
deleted file mode 100644 (file)
index db52b0b..0000000
Binary files a/src-da/1_lib/libda.a and /dev/null differ
index 4b8fa2c..4661a67 100644 (file)
@@ -28,6 +28,7 @@ CFLAGS=-std=gnu11 -fPIC -I. -I../1_include -ggdb -Werror -DDEBUG -DDEBUGDB
 LINKFLAGS=-L. -L../1_lib -ltests -lda
 
 LIBFILE=libtests.a
-MAKE=/usr/bin/make --no-print-directory -f $(PROJECT_SUBU)/tools/lib/makefile_cc
 
+MAKE=/usr/bin/make --no-print-directory -f $(PROJECT_SUBU)/tools/lib/makefile_cc
+#MAKE=/usr/bin/make -f $(PROJECT_SUBU)/tools/lib/makefile_cc
 
index 4657c3d..88a94c7 100644 (file)
@@ -46,7 +46,7 @@ bool test_da_1(){
   int *pt = (int *)da.base;
   // will double, 4 -> 8, then double 8 -> 16
   while( i < 10 ){
-    da.end += da.item_size;
+    da.end += da.element_size;
     if( da_boundq(&da) ){
       char *old_base = da_expand(&da);
       da_rebase(&da, old_base, &pt);
diff --git a/src-da/1_tmp/makefile_deps b/src-da/1_tmp/makefile_deps
deleted file mode 100644 (file)
index 905b038..0000000
+++ /dev/null
@@ -1 +0,0 @@
-da.lib.o: da.lib.c da.lib.h
index 5e51d43..afa1e51 100644 (file)
@@ -14,9 +14,9 @@ Dynamic Array
 // We manipulate pointers to a smallest addressable unit. The sizeof operator
 // returns counts in these addressable units. Sizeof(char) is defined to be 1.
 
-void da_alloc(Da *dap, size_t item_size){
-  dap->item_size = item_size;
-  dap->size = 4 * item_size;
+void da_alloc(Da *dap, size_t element_size){
+  dap->element_size = element_size;
+  dap->size = 4 * element_size;
   dap->base = malloc(dap->size);
   dap->end = dap->base;
 }
@@ -32,14 +32,20 @@ bool da_empty(Da *dap){
   return dap->end == dap->base;
 }
 
+void da_rebase(Da *dap, char *old_base, void *pta){
+  char **pt = (char **)pta;
+  size_t offset = *pt - old_base;
+  *pt = dap->base + offset;
+}
+
 // Doubles size of of da.  Returns old base, so that existing pointers into the
 // array can be moved to the new array
 char *da_expand(Da *dap){
-  size_t end_offset = ((char *)dap->end - (char *)dap->base);
   char *old_base = dap->base;
+  size_t end_offset = dap->end - old_base;
   size_t new_size = dap->size << 1;
   char *new_base = malloc( new_size );
-  memcpy( new_base, old_base, end_offset + dap->item_size);
+  memcpy( new_base, old_base, end_offset + dap->element_size);
   free(old_base);
   dap->base = new_base;
   dap->end = new_base + end_offset;
@@ -47,12 +53,6 @@ char *da_expand(Da *dap){
   return old_base;
 }
 
-void da_rebase(Da *dap, char *old_base, void *pta){
-  char **pt = (char **)pta;
-  size_t offset = *pt - old_base;
-  *pt = dap->base + offset;
-}
-
 // true when pt has run off the end of the area currently allocated for the array
 bool da_endq(Da *dap, void *pt){
   return (char *)pt >= dap->end;
@@ -63,29 +63,29 @@ bool da_boundq(Da *dap){
   return dap->end >= dap->base + dap->size;
 }
 
-void da_push(Da *dap, void *item){
+void da_push(Da *dap, void *element){
   if( dap->end >= dap->base + dap->size ) da_expand(dap);
-  memcpy(dap->end, item, dap->item_size);
-  dap->end += dap->item_size;
+  memcpy(dap->end, element, dap->element_size);
+  dap->end += dap->element_size;
 }
 
-bool da_pop(Da *dap, void *item){
-  bool flag = dap->end >= dap->base + dap->item_size;
+bool da_pop(Da *dap, void *element){
+  bool flag = dap->end >= dap->base + dap->element_size;
   if( flag ){
-    dap->end -= dap->item_size;
-    if(item) memcpy(item, dap->end, dap->item_size);
+    dap->end -= dap->element_size;
+    if(element) memcpy(element, dap->end, dap->element_size);
   }
   return flag;
 }
 
-// passed in f(item_pt, arg_pt)
+// passed in f(element_pt, arg_pt)
 // We have no language support closures, so we pass in an argument for it.
 // The closure may be set to NULL if it is not needed.
 void da_map(Da *dap, void f(void *, void *), void *closure){
   char *pt = dap->base;
   while( pt != dap->end ){
     f(pt, closure);
-  pt += dap->item_size;
+  pt += dap->element_size;
   }
 }
 
@@ -104,12 +104,12 @@ void da_free_elements(Da *dap){
 // buffer.  Returns the old_base so that external pointers can be rebased.
 // It is possible that the the base hasn't changed. Use feof(FILE *stream) to
 // test for EOF;
-char *da_fgets(Da *dap, FILE *fd){
+char *da_fgets(Da *dap, FILE *file){
   char *old_base = dap->base;
-  int c = fgetc(fd);
+  int c = fgetc(file);
   while( c != EOF && c != '\n' ){
     da_push(dap, &c);
-  c = fgetc(fd);
+  c = fgetc(file);
   }
   int terminator = 0;
   da_push(dap, &terminator);
index d5ba4db..d4e34de 100644 (file)
@@ -6,23 +6,23 @@
 
 typedef struct Da{
   char *base;
-  char *end; // one byte/one item off the end of the array
+  char *end; // one byte/one element off the end of the array
   size_t size; // size >= (end - base) + 1;
-  size_t item_size;
+  size_t element_size;
 } Da;
 
 #define RETURN(dap, r)                      \
   { da_map(dap, da_free, NULL); return r; }
 
-void da_alloc(Da *dap, size_t item_size);
+void da_alloc(Da *dap, size_t element_size);
 void da_free(Da *dap);
 void da_rewind(Da *dap);
 char *da_expand(Da *dap);
 void da_rebase(Da *dap, char *old_base, void *pta);
 bool da_endq(Da *dap, void *pt);
 bool da_boundq(Da *dap);
-void da_push(Da *dap, void *item);
-bool da_pop(Da *dap, void *item);
+void da_push(Da *dap, void *element);
+bool da_pop(Da *dap, void *element);
 void da_map(Da *dap, void f(void *, void *), void *closure);
 void da_free_elements(Da *dap);
 char *da_fgets(Da *dap, FILE *fd);
diff --git a/src-da/da.lib.o b/src-da/da.lib.o
deleted file mode 100644 (file)
index 979ccb8..0000000
Binary files a/src-da/da.lib.o and /dev/null differ
diff --git a/src-db/1_tmp/makefile_deps b/src-db/1_tmp/makefile_deps
deleted file mode 100644 (file)
index 8fa09cf..0000000
+++ /dev/null
@@ -1 +0,0 @@
-dbprintf.lib.o: dbprintf.lib.c dbprintf.lib.h
diff --git a/src-db/dbprintf.lib.h b/src-db/dbprintf.lib.h
deleted file mode 100644 (file)
index 3056cf6..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-/* \aThis file was automatically generated.  Do not edit! */
-#undef INTERFACE
-int dbprintf(const char *format,...);
index 2c44f58..238137a 100644 (file)
@@ -24,7 +24,7 @@ TRYDIR=1_try
 CC=gcc
 CFLAGS=-std=gnu11 -fPIC -I. -I$(PROJECT_SUBU)/stage/include -ggdb -Werror -DDEBUG -DDEBUGDB 
 #CFLAGS=-std=gnu11 -fPIC -I. -Werror
-LINKFLAGS=-L1_lib -lda 
+LINKFLAGS=-L1_lib -L$(PROJECT_SUBU)/stage/lib -lda -ltranche
 
 LIBFILE=libtranche.a
 INCFILE=tranche.h
diff --git a/src-tranche/1_doc/todo.txt b/src-tranche/1_doc/todo.txt
new file mode 100644 (file)
index 0000000..1494e66
--- /dev/null
@@ -0,0 +1,11 @@
+
+2019-03-22T13:37:23Z
+1. indentation
+
+   the first non blank line after the #tranche keyword sets the indentation
+   level for the following text.  When echoing to the output file 
+   remove that many leading spaces.
+
+   Hmm,  or allow options among the tranche parameters,  -indent 3 or
+   -indent '  '.
+   
diff --git a/src-tranche/1_tests/test.dat b/src-tranche/1_tests/test.dat
new file mode 100644 (file)
index 0000000..455b725
--- /dev/null
@@ -0,0 +1,17 @@
+
+#tranche test1.dat test2.dat
+The little red hen said to Mick, no thank you not today sir.
+And then all the barnes animals shouted out in glee.
+No more misery!
+
+#endtranche
+
+#tranche apple.dat
+apple banana pear
+monkey ape bear
+#tranche apple.dat nectarine.dat
+nectarine orange
+never go there said the man
+but when you do, pick three
+#endtranche
+#endtranche
index eb0fa3e..cbad345 100644 (file)
@@ -2,5 +2,16 @@
 
 int main(int argc, char **argv, char **envp){
 
+  if(argc != 2){
+    fprintf(stderr, "usage: %s <source-file>\n",argv[0]);
+  }
+  FILE *file = fopen(argv[1], "r");
+
+  Da targets;
+  da_alloc(&targets, sizeof(int));
+  da_push(&da_targets, stdout);
+  tranche_send(file, &da_targets);
+  da_free(targets);
+  fclose(file);
 
 }
index d5ba4db..d4e34de 100644 (file)
@@ -6,23 +6,23 @@
 
 typedef struct Da{
   char *base;
-  char *end; // one byte/one item off the end of the array
+  char *end; // one byte/one element off the end of the array
   size_t size; // size >= (end - base) + 1;
-  size_t item_size;
+  size_t element_size;
 } Da;
 
 #define RETURN(dap, r)                      \
   { da_map(dap, da_free, NULL); return r; }
 
-void da_alloc(Da *dap, size_t item_size);
+void da_alloc(Da *dap, size_t element_size);
 void da_free(Da *dap);
 void da_rewind(Da *dap);
 char *da_expand(Da *dap);
 void da_rebase(Da *dap, char *old_base, void *pta);
 bool da_endq(Da *dap, void *pt);
 bool da_boundq(Da *dap);
-void da_push(Da *dap, void *item);
-bool da_pop(Da *dap, void *item);
+void da_push(Da *dap, void *element);
+bool da_pop(Da *dap, void *element);
 void da_map(Da *dap, void f(void *, void *), void *closure);
 void da_free_elements(Da *dap);
 char *da_fgets(Da *dap, FILE *fd);
diff --git a/stage/lib/libda.a b/stage/lib/libda.a
deleted file mode 100644 (file)
index db52b0b..0000000
Binary files a/stage/lib/libda.a and /dev/null differ
index d51fcb8..3345aba 100755 (executable)
@@ -2,7 +2,7 @@
 
 mf=( ?_makefile )
 if [ -f "$mf" ]; then
-   /usr/bin/make -f ?_makefile "$@"
+   /usr/bin/make -f "$mf" "$@"
 else 
    /usr/bin/make "$@"
 fi
index ac1f960..5cdfb39 100755 (executable)
@@ -98,11 +98,6 @@ clean:
        if [ -f $(LIBDIR)/$(LIBFILE) ]; then rm $(LIBDIR)/$(LIBFILE); fi
        if [ -f $(DEPSFILE) ]; then rm $(DEPSFILE); fi
 
-dist-clean:
-       make clean
-       if [ -d $(TESTDIR) ]; then cd $(TESTDIR); make dist-clean; fi
-       if [ -d $(TRYDIR) ] ; then cd $(TRYDIR); make dist-clean; fi
-
 #
 $(LIBDIR)/$(LIBFILE) : $(OBJECTS_LIB)
        ar rcs $(LIBDIR)/$(LIBFILE) $(OBJECTS_LIB)