tranche development
authorThomas Walker Lynch <thomas.lynch@reasoningtechnology.com>
Fri, 29 Mar 2019 02:36:45 +0000 (03:36 +0100)
committerThomas Walker Lynch <thomas.lynch@reasoningtechnology.com>
Fri, 29 Mar 2019 02:36:45 +0000 (03:36 +0100)
47 files changed:
module/da/src/da.lib.c
module/da/src/da.lib.h
module/da/test/src/test_da.cli.c
module/da/test/src/test_da.lib.c
module/da/test/src/test_da.lib.h
module/share/lib/libda.a
module/tranche/src/tranche-dep.cli.c.keep [deleted file]
module/tranche/src/tranche-make.c [new file with mode: 0644]
module/tranche/test/test1.dat [deleted file]
module/tranche/test/test1.sh [deleted file]
module/tranche/test/test11.dat.expected [deleted file]
module/tranche/test/test12.dat.expected [deleted file]
module/tranche/test/test13.dat.expected [deleted file]
module/tranche/test/test14.dat.expected [deleted file]
module/tranche/test/test15.dat.expected [deleted file]
module/tranche/test/test1stdout.dat.expected [deleted file]
module/tranche/test/test2.c.expected [deleted file]
module/tranche/test/test2.h.expected [deleted file]
module/tranche/test/test2.sh [deleted file]
module/tranche/test/test2.trc.c [deleted file]
module/tranche/test/test2stdout.dat [deleted file]
module/tranche/test/test2stdout.dat.expected [deleted file]
module/tranche/test/test3.out.expected [deleted file]
module/tranche/test/test3.sh [deleted file]
module/tranche/test/test4.out [deleted file]
module/tranche/test/test4.sh [deleted file]
module/tranche/test/tranche [deleted symlink]
module/tranche/test/tranche-target [deleted symlink]
module/tranche/test/try/test1.dat [new file with mode: 0644]
module/tranche/test/try/test1.sh [new file with mode: 0644]
module/tranche/test/try/test11.dat.expected [new file with mode: 0644]
module/tranche/test/try/test12.dat.expected [new file with mode: 0644]
module/tranche/test/try/test13.dat.expected [new file with mode: 0644]
module/tranche/test/try/test14.dat.expected [new file with mode: 0644]
module/tranche/test/try/test15.dat.expected [new file with mode: 0644]
module/tranche/test/try/test1stdout.dat.expected [new file with mode: 0644]
module/tranche/test/try/test2.c.expected [new file with mode: 0644]
module/tranche/test/try/test2.h.expected [new file with mode: 0644]
module/tranche/test/try/test2.sh [new file with mode: 0644]
module/tranche/test/try/test2.trc.c [new file with mode: 0644]
module/tranche/test/try/test2stdout.dat.expected [new file with mode: 0644]
module/tranche/test/try/test3.out.expected [new file with mode: 0644]
module/tranche/test/try/test3.sh [new file with mode: 0644]
module/tranche/test/try/test4.out.expected [new file with mode: 0644]
module/tranche/test/try/test4.sh [new file with mode: 0644]
module/tranche/test/try/tranche [new symlink]
module/tranche/test/try/tranche-target [new symlink]

index 0956d7e..47558e0 100644 (file)
@@ -78,6 +78,28 @@ bool da_pop(Da *dap, void *element){
   return flag;
 }
 
+void da_cat(Da *dap0, Da *dap1){
+  if(dap1->base == dap1->end) return;
+  size_t dap0_size = dap0->end - dap0->base;
+  size_t dap1_size = dap1->end - dap1->base; // size of the active portion
+  dap0->end += dap1_size;
+  while( dap0->end >= dap0->base + dap0->size ) da_expand(dap0);
+  memcpy(dap0->base + dap0_size, dap1->base, dap1_size);
+}
+
+// If dap0 has had a terminatating zero added, that must be popped off before
+// the call.  Similarly if a terminating zero is desired, it should be pushed
+// after the call.
+void da_push_string(Da *dap0, char *string){
+  if(!*string) return;
+  size_t dap0_size = dap0->end - dap0->base;
+  size_t string_size = strlen(string);
+  dap0->end += string_size;
+  while( dap0->end >= dap0->base + dap0->size ) da_expand(dap0);
+  memcpy(dap0->base + dap0_size, string, string_size);
+}
+
+
 char *da_index(Da *dap, size_t i){
   size_t offset = i * dap->element_size;
   char *pt = dap->base + offset;
@@ -108,12 +130,22 @@ void da_free_elements(Da *dap){
 // for the case of an array of strings
 void da_strings_puts(Da *dap){
   char *pt = dap->base;
-  while( pt != dap->end ){
+  while( pt < dap->end ){
     puts(*(char **)pt);
   pt += dap->element_size;
   }
 }
 
+// would like to pass in the printf format to make a general print
+// but can't get *pt on the stack for the printf call .. hmmm
+void da_ints_print(Da *dap){
+  char *pt = dap->base;
+  while( pt < dap->end ){
+    printf("%u\n", *(int *)pt);
+  pt += dap->element_size;
+  }
+}
+
 
 // Puts text from a line into buffer *dap. Does not push EOF or '\n' into the
 // buffer.  Returns the old_base so that external pointers can be rebased.
index 6d3c43b..d480d8c 100644 (file)
@@ -23,10 +23,12 @@ bool da_endq(Da *dap, void *pt);
 bool da_boundq(Da *dap);
 void da_push(Da *dap, void *element);
 bool da_pop(Da *dap, void *element);
+void da_cat(Da *dap_base, Da *dap_cat);
 char *da_index(Da *dap, size_t i);
 void da_map(Da *dap, void f(void *, void *), void *closure);
 void da_free_elements(Da *dap);
 void da_strings_puts(Da *dap);
+void da_ints_print(Da *dap);
 char *da_fgets(Da *dap, FILE *fd);
 
 #endif
index bee5a6c..07282dc 100644 (file)
@@ -11,8 +11,8 @@ int main(){
 
   // enumeration of tests
   typedef bool (*test_fun)();
-  test_fun tests[] = {test_da_0, test_da_1, test_da_2, test_da_3, NULL};
-  char *test_names[] = {"test_da_0", "test_da_1", "test_da_2", "test_da_3", NULL};
+  test_fun tests[] = {test_da_0, test_da_1, test_da_2, test_da_3, test_da_4, NULL};
+  char *test_names[] = {"test_da_0", "test_da_1", "test_da_2", "test_da_3", "test_da_4", NULL};
 
   // call tests
   test_fun *tfp = tests;
index 0ab06c8..f16be66 100644 (file)
@@ -128,6 +128,43 @@ bool test_da_3(){
   return f0 && f1 && f2 && f3;
 }
 
+// da_cat
+bool test_da_4(){
+
+  Da da0, da1;
+  da_alloc(&da0, sizeof(int));
+  da_alloc(&da1, sizeof(int));
+
+  int i = 5;
+  while(i < 8){
+    da_push(&da0, &i);
+  i++;
+  }
+  while(i < 11){
+    da_push(&da1, &i);
+  i++;
+  }
+
+  da_cat(&da0, &da1);
+
+  bool f[6];
+  int j;
+  int k = 0;
+  while(k < 6){
+    f[k] = da_pop(&da0, &j) && (j == 10 - k);
+  k++;
+  }
+
+  bool result = f[0];
+  k = 1;
+  while(result && k < 6){
+    result = f[k];
+  k++;
+  }
+
+  return result;
+}
+
 
 
 
index 686b0d0..432fecd 100644 (file)
@@ -5,5 +5,6 @@ bool test_da_0();
 bool test_da_1();
 bool test_da_2();
 bool test_da_3();
+bool test_da_4();
 
 #endif
index a7b5b79..ba48a6e 100644 (file)
Binary files a/module/share/lib/libda.a and b/module/share/lib/libda.a differ
diff --git a/module/tranche/src/tranche-dep.cli.c.keep b/module/tranche/src/tranche-dep.cli.c.keep
deleted file mode 100644 (file)
index 3365573..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
-Scans a tranche file and outputs a dep line suitable for make.
-
-The dep file is opened for append. If the depfile is not present stdout is used.
-
-If the given source file name has a directory prefix, the targets in 
-the dep line are given the same prefix.
-*/
-  
-#include <stdio.h>
-#include <unistd.h>
-#include <da.h>
-#include "tranche.lib.h"
-
-#define ERR_ARGC 1
-#define ERR_SRC_OPEN 2
-#define ERR_DEP_OPEN 4
-
-
-int main(int argc, char **argv, char **envp){
-  if(argc < 2 || argc > 3){
-    fprintf(stderr, "usage: %s <source> [<dep-file>]\n",argv[0]);
-    return ERR_ARGC;
-  }
-  char *src_file_name = argv[1];
-  char *dep_file_name = argv[2];
-
-  int dep_fd;
-  FILE *src_file = fopen(src_file_name, "r");
-  if(argc < 3)
-    dep_fd = 1;
-  else{
-    dep_fd = open(file_name, O_WRONLY | O_APPEND | O_CREAT, 0666);
-  }
-  unsigned int err = 0;
-  if(!src_file){
-    fprintf(stderr,"could not open tranche source file %s\n", src_file_name);
-    err+= ERR_SRC_OPEN;
-  }
-  if(dep_fd == -1){
-    fprintf(stderr, "Could not open the dep file %s\n", dep_file_name);
-    err+= ERR_DEP_OPEN;
-  }
-  if(err) return err;
-
-  tranche_deps(src_file, dep_fd);
-  fclose(file);
-  close(dep_fd);
-  return 0;
-}
diff --git a/module/tranche/src/tranche-make.c b/module/tranche/src/tranche-make.c
new file mode 100644 (file)
index 0000000..2f84d0f
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+Scans a tranche file and outputs a make rule for makefile-deps, of the form:
+
+<target>...  : <src>
+      tranche $@
+
+ file is opened for append. If the depfile is not present stdout is used.
+
+If the given source file name has a directory prefix, the targets in 
+the dep line are given the same prefix.
+*/
+  
+#include <stdio.h>
+#include <unistd.h>
+#include <da.h>
+#include "tranche.lib.h"
+
+#define ERR_ARGC 1
+#define ERR_SRC_OPEN 2
+#define ERR_DEP_OPEN 4
+
+
+int main(int argc, char **argv, char **envp){
+  if(argc < 2 || argc > 3){
+    fprintf(stderr, "usage: %s <source> [<dep-file>]\n",argv[0]);
+    return ERR_ARGC;
+  }
+  char *src_file_name = argv[1];
+  char *dep_file_name = argv[2];
+
+  int dep_fd;
+  FILE *src_file = fopen(src_file_name, "r");
+  if(argc < 3)
+    dep_fd = 1;
+  else{
+    dep_fd = open(file_name, O_WRONLY | O_APPEND | O_CREAT, 0666);
+  }
+  unsigned int err = 0;
+  if(!src_file){
+    fprintf(stderr,"could not open tranche source file %s\n", src_file_name);
+    err+= ERR_SRC_OPEN;
+  }
+  if(dep_fd == -1){
+    fprintf(stderr, "Could not open the dep file %s\n", dep_file_name);
+    err+= ERR_DEP_OPEN;
+  }
+  if(err) return err;
+
+  tranche_deps(src_file, dep_fd);
+  fclose(file);
+  close(dep_fd);
+  return 0;
+}
diff --git a/module/tranche/test/test1.dat b/module/tranche/test/test1.dat
deleted file mode 100644 (file)
index b03df3f..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-
-#tranche test11.dat test12.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!
-#tranche test13.dat
-apple banana pear
-kiwi
-#tranche-end
-cows
-and cats
-#tranche-end
-
-the between space
-
-#tranche test14.dat
-int float if while
-do
-function
-#tranche-end
-
-#tranche test15.dat
-#tranche-end
\ No newline at end of file
diff --git a/module/tranche/test/test1.sh b/module/tranche/test/test1.sh
deleted file mode 100644 (file)
index c1140ca..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/bash -x
-./tranche test1.dat >test1stdout.dat
-diff test11.dat test11.dat.expected
-diff test12.dat test12.dat.expected
-diff test13.dat test13.dat.expected
-diff test14.dat test14.dat.expected
-diff test15.dat test15.dat.expected
-diff test1stdout.dat test1stdout.dat.expected
-rm test11.dat test12.dat test13.dat test14.dat test15.dat test1stdout.dat
-
diff --git a/module/tranche/test/test11.dat.expected b/module/tranche/test/test11.dat.expected
deleted file mode 100644 (file)
index 2c2904a..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-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!
-cows
-and cats
diff --git a/module/tranche/test/test12.dat.expected b/module/tranche/test/test12.dat.expected
deleted file mode 100644 (file)
index 2c2904a..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-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!
-cows
-and cats
diff --git a/module/tranche/test/test13.dat.expected b/module/tranche/test/test13.dat.expected
deleted file mode 100644 (file)
index 81fb20c..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-apple banana pear
-kiwi
diff --git a/module/tranche/test/test14.dat.expected b/module/tranche/test/test14.dat.expected
deleted file mode 100644 (file)
index 0d8b89b..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-int float if while
-do
-function
diff --git a/module/tranche/test/test15.dat.expected b/module/tranche/test/test15.dat.expected
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/module/tranche/test/test1stdout.dat.expected b/module/tranche/test/test1stdout.dat.expected
deleted file mode 100644 (file)
index 4e519ff..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-the between space
-
-
diff --git a/module/tranche/test/test2.c.expected b/module/tranche/test/test2.c.expected
deleted file mode 100644 (file)
index a4876a1..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-#include "test2.h"
-
-
-int f(int x){
-  return x;
-}
-
-
diff --git a/module/tranche/test/test2.h.expected b/module/tranche/test/test2.h.expected
deleted file mode 100644 (file)
index fdc4d72..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-#ifndef TEST2_H
-#define TEST2_H
-int f(int x);
-#endif
diff --git a/module/tranche/test/test2.sh b/module/tranche/test/test2.sh
deleted file mode 100644 (file)
index 1a4cf28..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/bash -x
-./tranche test2.trc.c >test2stdout.dat
-diff test2.c test2.c.expected
-diff test2.h test2.h.expected
-diff test2stdout.dat test2stdout.dat.expected
-rm test2.c test2.h
-
-
diff --git a/module/tranche/test/test2.trc.c b/module/tranche/test/test2.trc.c
deleted file mode 100644 (file)
index ff7d696..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-
-#tranche test2.c
-
-#tranche test2.h
-#ifndef TEST2_H
-#define TEST2_H
-#tranche-end
-
-#include "test2.h"
-
-#tranche test2.h
-int f(int x);
-#tranche-end
-
-int f(int x){
-  return x;
-}
-
-#tranche test2.h
-#endif
-#tranche-end
-
-#tranche-end
diff --git a/module/tranche/test/test2stdout.dat b/module/tranche/test/test2stdout.dat
deleted file mode 100644 (file)
index 139597f..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
diff --git a/module/tranche/test/test2stdout.dat.expected b/module/tranche/test/test2stdout.dat.expected
deleted file mode 100644 (file)
index 139597f..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
diff --git a/module/tranche/test/test3.out.expected b/module/tranche/test/test3.out.expected
deleted file mode 100644 (file)
index 8294b86..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-test11.dat
-test12.dat
-test13.dat
-test14.dat
-test15.dat
diff --git a/module/tranche/test/test3.sh b/module/tranche/test/test3.sh
deleted file mode 100644 (file)
index e655682..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/bash -x
-./tranche-target test1.dat > test3.out
-diff test3.out test3.out.expected
-rm test3.out
-
-
diff --git a/module/tranche/test/test4.out b/module/tranche/test/test4.out
deleted file mode 100644 (file)
index 05de4b1..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-test2.c
-test2.h
diff --git a/module/tranche/test/test4.sh b/module/tranche/test/test4.sh
deleted file mode 100644 (file)
index 49c7c4b..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/bash -x
-./tranche-target test2.trc.c > test4.out
-diff test4.out test4.out.expected
-rm test4.out
-
-
diff --git a/module/tranche/test/tranche b/module/tranche/test/tranche
deleted file mode 120000 (symlink)
index 701f193..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../exec/tranche
\ No newline at end of file
diff --git a/module/tranche/test/tranche-target b/module/tranche/test/tranche-target
deleted file mode 120000 (symlink)
index 51e3cfa..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../exec/tranche-target
\ No newline at end of file
diff --git a/module/tranche/test/try/test1.dat b/module/tranche/test/try/test1.dat
new file mode 100644 (file)
index 0000000..b03df3f
--- /dev/null
@@ -0,0 +1,23 @@
+
+#tranche test11.dat test12.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!
+#tranche test13.dat
+apple banana pear
+kiwi
+#tranche-end
+cows
+and cats
+#tranche-end
+
+the between space
+
+#tranche test14.dat
+int float if while
+do
+function
+#tranche-end
+
+#tranche test15.dat
+#tranche-end
\ No newline at end of file
diff --git a/module/tranche/test/try/test1.sh b/module/tranche/test/try/test1.sh
new file mode 100644 (file)
index 0000000..c1140ca
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/bash -x
+./tranche test1.dat >test1stdout.dat
+diff test11.dat test11.dat.expected
+diff test12.dat test12.dat.expected
+diff test13.dat test13.dat.expected
+diff test14.dat test14.dat.expected
+diff test15.dat test15.dat.expected
+diff test1stdout.dat test1stdout.dat.expected
+rm test11.dat test12.dat test13.dat test14.dat test15.dat test1stdout.dat
+
diff --git a/module/tranche/test/try/test11.dat.expected b/module/tranche/test/try/test11.dat.expected
new file mode 100644 (file)
index 0000000..2c2904a
--- /dev/null
@@ -0,0 +1,5 @@
+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!
+cows
+and cats
diff --git a/module/tranche/test/try/test12.dat.expected b/module/tranche/test/try/test12.dat.expected
new file mode 100644 (file)
index 0000000..2c2904a
--- /dev/null
@@ -0,0 +1,5 @@
+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!
+cows
+and cats
diff --git a/module/tranche/test/try/test13.dat.expected b/module/tranche/test/try/test13.dat.expected
new file mode 100644 (file)
index 0000000..81fb20c
--- /dev/null
@@ -0,0 +1,2 @@
+apple banana pear
+kiwi
diff --git a/module/tranche/test/try/test14.dat.expected b/module/tranche/test/try/test14.dat.expected
new file mode 100644 (file)
index 0000000..0d8b89b
--- /dev/null
@@ -0,0 +1,3 @@
+int float if while
+do
+function
diff --git a/module/tranche/test/try/test15.dat.expected b/module/tranche/test/try/test15.dat.expected
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/module/tranche/test/try/test1stdout.dat.expected b/module/tranche/test/try/test1stdout.dat.expected
new file mode 100644 (file)
index 0000000..4e519ff
--- /dev/null
@@ -0,0 +1,5 @@
+
+
+the between space
+
+
diff --git a/module/tranche/test/try/test2.c.expected b/module/tranche/test/try/test2.c.expected
new file mode 100644 (file)
index 0000000..a4876a1
--- /dev/null
@@ -0,0 +1,10 @@
+
+
+#include "test2.h"
+
+
+int f(int x){
+  return x;
+}
+
+
diff --git a/module/tranche/test/try/test2.h.expected b/module/tranche/test/try/test2.h.expected
new file mode 100644 (file)
index 0000000..fdc4d72
--- /dev/null
@@ -0,0 +1,4 @@
+#ifndef TEST2_H
+#define TEST2_H
+int f(int x);
+#endif
diff --git a/module/tranche/test/try/test2.sh b/module/tranche/test/try/test2.sh
new file mode 100644 (file)
index 0000000..1a4cf28
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/bash -x
+./tranche test2.trc.c >test2stdout.dat
+diff test2.c test2.c.expected
+diff test2.h test2.h.expected
+diff test2stdout.dat test2stdout.dat.expected
+rm test2.c test2.h
+
+
diff --git a/module/tranche/test/try/test2.trc.c b/module/tranche/test/try/test2.trc.c
new file mode 100644 (file)
index 0000000..ff7d696
--- /dev/null
@@ -0,0 +1,23 @@
+
+#tranche test2.c
+
+#tranche test2.h
+#ifndef TEST2_H
+#define TEST2_H
+#tranche-end
+
+#include "test2.h"
+
+#tranche test2.h
+int f(int x);
+#tranche-end
+
+int f(int x){
+  return x;
+}
+
+#tranche test2.h
+#endif
+#tranche-end
+
+#tranche-end
diff --git a/module/tranche/test/try/test2stdout.dat.expected b/module/tranche/test/try/test2stdout.dat.expected
new file mode 100644 (file)
index 0000000..139597f
--- /dev/null
@@ -0,0 +1,2 @@
+
+
diff --git a/module/tranche/test/try/test3.out.expected b/module/tranche/test/try/test3.out.expected
new file mode 100644 (file)
index 0000000..8294b86
--- /dev/null
@@ -0,0 +1,5 @@
+test11.dat
+test12.dat
+test13.dat
+test14.dat
+test15.dat
diff --git a/module/tranche/test/try/test3.sh b/module/tranche/test/try/test3.sh
new file mode 100644 (file)
index 0000000..e655682
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/bash -x
+./tranche-target test1.dat > test3.out
+diff test3.out test3.out.expected
+rm test3.out
+
+
diff --git a/module/tranche/test/try/test4.out.expected b/module/tranche/test/try/test4.out.expected
new file mode 100644 (file)
index 0000000..05de4b1
--- /dev/null
@@ -0,0 +1,2 @@
+test2.c
+test2.h
diff --git a/module/tranche/test/try/test4.sh b/module/tranche/test/try/test4.sh
new file mode 100644 (file)
index 0000000..49c7c4b
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/bash -x
+./tranche-target test2.trc.c > test4.out
+diff test4.out test4.out.expected
+rm test4.out
+
+
diff --git a/module/tranche/test/try/tranche b/module/tranche/test/try/tranche
new file mode 120000 (symlink)
index 0000000..982210d
--- /dev/null
@@ -0,0 +1 @@
+../../exec/tranche
\ No newline at end of file
diff --git a/module/tranche/test/try/tranche-target b/module/tranche/test/try/tranche-target
new file mode 120000 (symlink)
index 0000000..07d6f40
--- /dev/null
@@ -0,0 +1 @@
+../../exec/tranche-target
\ No newline at end of file