--- /dev/null
+this is a test
+ends without a newline
+(setq mode-require-final-newline nil)
\ No newline at end of file
.PHONY: all
all: version deps lib exec
+.PHONY: lib
+lib:
+ $(MAKE) $@
+
+.PHONY: exec
+exec:
+ $(MAKE) $@
+
%::
$(MAKE) $@
+++ /dev/null
-./test_da.lib.o: test_da.lib.c ../include/da.h test_da.lib.h
-./test_da.cli.o: test_da.cli.c test_da.lib.h
-
-./test_da : ./test_da.cli.o ./libtest.a
- gcc -o ./test_da ./test_da.cli.o -L. -L../lib -ltest -lda
# directories used by this makefile, these could all be set to dot for
# the simplest source directory structure
-
-#LIDBIR, EXECSDIR, HDIR hold the make results that might later be shared
-#$(PWD) is the directory that make was called from, this is already build in
-#set to dot to use the same directory as the source code
-#leave blank to ommit
-DEPRDIR=
-DOCDIR=
-EXECDIR=.
-INCDIR=.
-LIBDIR=.
-SRCDIR=.
TESTDIR=
-TMPDIR=.
-TOOLDIR=$(realpath $(PROJECT_SUBU)/tool)
-TRYDIR=
# compiler and flags
C=gcc
CFLAGS=-std=gnu11 -fPIC -I../include -ggdb -Werror -DDEBUG -DDEBUGDB
#CFLAGS=-std=gnu11 -fPIC -I../include -Werror
-LINKFLAGS=-L. -L../lib -ltest -lda
+LINKFLAGS= -Llib -L../lib -ltest -lda
MAKE=/usr/bin/make --no-print-directory -f $(PROJECT_SUBU)/tool/lib/makefile_cc
#MAKE=/usr/bin/make -f $(PROJECT_SUBU)/tool/lib/makefile_cc
--- /dev/null
+
+#include <stdio.h>
+#include <stdbool.h>
+#include "test_da.lib.h"
+
+int main(){
+ bool da_0_passed = test_da_0();
+
+ unsigned int passed = 0;
+ unsigned int failed = 0;
+
+ // 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};
+
+ // call tests
+ test_fun *tfp = tests;
+ char **tnp = test_names;
+ while(*tfp){
+ if( !(*tfp)() ){
+ failed++;
+ if(*tnp)
+ printf("%s failed\n", *tnp);
+ else
+ fprintf(stderr, "internal error, no test_names[] entry for test\n");
+ }else
+ passed++;
+ tfp++;
+ tnp++;
+ }
+
+ // summarize results
+
+ if( passed == 0 && failed == 0)
+ printf("no tests ran\n");
+ else if( passed == 0 )
+ printf("failed all %u tests\n", failed);
+ else if( failed == 0 )
+ printf("passed all %u tests\n", passed);
+ else
+ printf("failed %u of %u tests\n", failed, passed + failed);
+
+ if( passed == 0 || failed != 0 ) return 1;
+ return 0;
+}
--- /dev/null
+/*
+Tests for Da.
+
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+#include <da.h>
+
+#include "test_da.lib.h"
+
+// tests push
+bool test_da_0(){
+ Da da;
+ da_alloc(&da, sizeof(int)); // leaves room for 4 ints
+ int i = 0;
+ int *pt = (int *)da.base;
+ // will double, 4 -> 8, then double 8 -> 16
+ while( i < 10 ){
+ da_push(&da, &i);
+ i++;
+ pt++;
+ }
+
+ bool f0 = da.size == sizeof(int) * 16;
+ bool f1 = 10 == (da.end - da.base) / sizeof(int);
+ bool f2 = true;
+ pt = (int *)da.base;
+ i = 0;
+ while( i < 10 ){
+ f2 = f2 && *pt == i && !da_endq(&da, pt);
+ i++;
+ pt++;
+ }
+ bool f3 = da_endq(&da, pt);
+
+ return f0 && f1 && f2 && f3;
+}
+
+// tests manual expansion
+bool test_da_1(){
+ Da da;
+ da_alloc(&da, sizeof(int)); // leaves room for 4 ints
+ int i = 0;
+ int *pt = (int *)da.base;
+ // will double, 4 -> 8, then double 8 -> 16
+ while( i < 10 ){
+ da.end += da.element_size;
+ if( da_boundq(&da) ){
+ char *old_base = da_expand(&da);
+ da_rebase(&da, old_base, &pt);
+ }
+ *pt = i;
+ i++;
+ pt++;
+ }
+
+ bool f0 = da.size == sizeof(int) * 16;
+ bool f1 = 10 == (da.end - da.base) / sizeof(int);
+ bool f2 = true;
+ pt = (int *)da.base;
+ i = 0;
+ while( i < 10 ){
+ f2 = f2 && *pt == i && !da_endq(&da, pt);
+ i++;
+ pt++;
+ }
+ bool f3 = da_endq(&da, pt);
+
+ return f0 && f1 && f2 && f3;
+}
+
+// da_fgets
+bool test_da_2(){
+
+ char *data_file_name = "../lib/test.dat";
+ FILE *file = fopen(data_file_name,"r");
+ if(!file){
+ fprintf(stderr,"test_da_2, could not open data file %s for reading\n", data_file_name);
+ return false;
+ }
+
+ Da da;
+ da_alloc(&da, sizeof(char));
+
+ da_fgets(&da, file);
+ bool f0 = !strcmp(da.base, "this is a test");
+
+ char *old_base;
+ da_pop(&da, NULL); // pop the prior null terminator
+ char *s1 = da.end;
+ old_base = da_fgets(&da,file);
+ da_rebase(&da, old_base, &s1);
+ bool f1 = !strcmp(s1, "ends without a newline");
+
+ da_pop(&da, NULL); // pop the prior null terminator
+ char *s2 = da.end;
+ old_base = da_fgets(&da,file);
+ da_rebase(&da, old_base, &s2);
+ bool f2 = !strcmp(s2, "(setq mode-require-final-newline nil)");
+
+ bool f3 = !strcmp(da.base, "this is a testends without a newline(setq mode-require-final-newline nil)");
+
+ fclose(file);
+ return f0 && f1 && f2 && f3;
+}
+
+// da_fgets
+bool test_da_3(){
+
+ Da da;
+ da_alloc(&da, sizeof(int));
+
+ int i = 5;
+ da_push(&da, &i);
+ i++;
+ da_push(&da, &i);
+ i++;
+ da_push(&da, &i);
+
+ int j;
+ bool f0 = da_pop(&da, &j) && j == 7;
+ bool f1 = da_pop(&da, &j) && j == 6;
+ bool f2 = da_pop(&da, NULL);
+ bool f3 = !da_pop(&da, &j);
+
+ return f0 && f1 && f2 && f3;
+}
+
+
+
+
--- /dev/null
+#ifndef DA_LIB_H
+#define DA_LIB_H
+
+bool test_da_0();
+bool test_da_1();
+bool test_da_2();
+bool test_da_3();
+
+#endif
+++ /dev/null
-this is a test
-ends without a newline
-(setq mode-require-final-newline nil)
\ No newline at end of file
+++ /dev/null
-
-#include <stdio.h>
-#include <stdbool.h>
-#include "test_da.lib.h"
-
-int main(){
- bool da_0_passed = test_da_0();
-
- unsigned int passed = 0;
- unsigned int failed = 0;
-
- // 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};
-
- // call tests
- test_fun *tfp = tests;
- char **tnp = test_names;
- while(*tfp){
- if( !(*tfp)() ){
- failed++;
- if(*tnp)
- printf("%s failed\n", *tnp);
- else
- fprintf(stderr, "internal error, no test_names[] entry for test\n");
- }else
- passed++;
- tfp++;
- tnp++;
- }
-
- // summarize results
-
- if( passed == 0 && failed == 0)
- printf("no tests ran\n");
- else if( passed == 0 )
- printf("failed all %u tests\n", failed);
- else if( failed == 0 )
- printf("passed all %u tests\n", passed);
- else
- printf("failed %u of %u tests\n", failed, passed + failed);
-
- if( passed == 0 || failed != 0 ) return 1;
- return 0;
-}
+++ /dev/null
-/*
-Tests for Da.
-
-*/
-
-#include <stdio.h>
-#include <string.h>
-#include <stdbool.h>
-#include <da.h>
-
-#include "test_da.lib.h"
-
-// tests push
-bool test_da_0(){
- Da da;
- da_alloc(&da, sizeof(int)); // leaves room for 4 ints
- int i = 0;
- int *pt = (int *)da.base;
- // will double, 4 -> 8, then double 8 -> 16
- while( i < 10 ){
- da_push(&da, &i);
- i++;
- pt++;
- }
-
- bool f0 = da.size == sizeof(int) * 16;
- bool f1 = 10 == (da.end - da.base) / sizeof(int);
- bool f2 = true;
- pt = (int *)da.base;
- i = 0;
- while( i < 10 ){
- f2 = f2 && *pt == i && !da_endq(&da, pt);
- i++;
- pt++;
- }
- bool f3 = da_endq(&da, pt);
-
- return f0 && f1 && f2 && f3;
-}
-
-// tests manual expansion
-bool test_da_1(){
- Da da;
- da_alloc(&da, sizeof(int)); // leaves room for 4 ints
- int i = 0;
- int *pt = (int *)da.base;
- // will double, 4 -> 8, then double 8 -> 16
- while( i < 10 ){
- da.end += da.element_size;
- if( da_boundq(&da) ){
- char *old_base = da_expand(&da);
- da_rebase(&da, old_base, &pt);
- }
- *pt = i;
- i++;
- pt++;
- }
-
- bool f0 = da.size == sizeof(int) * 16;
- bool f1 = 10 == (da.end - da.base) / sizeof(int);
- bool f2 = true;
- pt = (int *)da.base;
- i = 0;
- while( i < 10 ){
- f2 = f2 && *pt == i && !da_endq(&da, pt);
- i++;
- pt++;
- }
- bool f3 = da_endq(&da, pt);
-
- return f0 && f1 && f2 && f3;
-}
-
-// da_fgets
-bool test_da_2(){
-
- FILE *fd = fopen("test.dat","r");
-
- Da da;
- da_alloc(&da, sizeof(char));
-
- da_fgets(&da, fd);
- bool f0 = !strcmp(da.base, "this is a test");
-
- char *old_base;
- da_pop(&da, NULL); // pop the prior null terminator
- char *s1 = da.end;
- old_base = da_fgets(&da,fd);
- da_rebase(&da, old_base, &s1);
- bool f1 = !strcmp(s1, "ends without a newline");
-
- da_pop(&da, NULL); // pop the prior null terminator
- char *s2 = da.end;
- old_base = da_fgets(&da,fd);
- da_rebase(&da, old_base, &s2);
- bool f2 = !strcmp(s2, "(setq mode-require-final-newline nil)");
-
- bool f3 = !strcmp(da.base, "this is a testends without a newline(setq mode-require-final-newline nil)");
-
- fclose(fd);
- return f0 && f1 && f2 && f3;
-}
-
-// da_fgets
-bool test_da_3(){
-
- FILE *fd = fopen("test.dat","r");
-
- Da da;
- da_alloc(&da, sizeof(int));
-
- int i = 5;
- da_push(&da, &i);
- i++;
- da_push(&da, &i);
- i++;
- da_push(&da, &i);
-
- int j;
- bool f0 = da_pop(&da, &j) && j == 7;
- bool f1 = da_pop(&da, &j) && j == 6;
- bool f2 = da_pop(&da, NULL);
- bool f3 = !da_pop(&da, &j);
-
- return f0 && f1 && f2 && f3;
-}
-
-
-
-
+++ /dev/null
-#ifndef DA_LIB_H
-#define DA_LIB_H
-
-bool test_da_0();
-bool test_da_1();
-bool test_da_2();
-bool test_da_3();
-
-#endif
#ifndef TRANCHE_LIB_H
#define TRANCHE_LIB_H
-int tranche_send(FILE *src, Da *arg_fds);
+#define TRANCHE_ERR_ARGC 1
+#define TRANCHE_ERR_SRC_OPEN 2
+#define TRANCHE_ERR_DEP_OPEN 4
+int tranche_send(FILE *src, Da *arg_fds);
+int tranche_target(FILE *src, Da *targets);
#endif
--- /dev/null
+/*
+Scans a tranche and lists the named target files.
+
+stdout is not explicitly named. Would be intersting if stdout
+were also listed if anything is sent to stdout. Might distinguish
+between blank lines being sent and text being sent to stdout.
+
+*/
+
+#include <stdio.h>
+#include <unistd.h>
+#include <da.h>
+#include "tranche.lib.h"
+
+#define ERR_ARGC 1
+#define ERR_SRC_OPEN 2
+
+
+int main(int argc, char **argv, char **envp){
+ if(argc != 2){
+ fprintf(stderr, "usage: %s <source>\n",argv[0]);
+ return ERR_ARGC;
+ }
+ char *src_file_name = argv[1];
+
+ int dep_fd;
+ FILE *src_file = fopen(src_file_name, "r");
+ 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(err) return err;
+
+ Da target_arr;
+ Da *target_arrp = &target_arr;
+ da_alloc(target_arrp, sizeof(char *));
+ tranche_target(src_file, target_arrp);
+ da_strings_puts(target_arrp);
+ da_free_elements(target_arrp);
+ fclose(src_file);
+ return 0;
+}
+++ /dev/null
-/*
-Scans a tranche and lists the named target files.
-
-stdout is not explicitly named. Would be intersting if stdout
-were also listed if anything is sent to stdout. Might distinguish
-between blank lines being sent and text being sent to stdout.
-
-*/
-
-#include <stdio.h>
-#include <unistd.h>
-#include <da.h>
-#include "tranche.lib.h"
-
-#define ERR_ARGC 1
-#define ERR_SRC_OPEN 2
-
-
-int main(int argc, char **argv, char **envp){
- if(argc != 2){
- fprintf(stderr, "usage: %s <source>\n",argv[0]);
- return ERR_ARGC;
- }
- char *src_file_name = argv[1];
-
- int dep_fd;
- FILE *src_file = fopen(src_file_name, "r");
- 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(err) return err;
-
- Da targets;
- da_alloc(&targets, sizeof(char *));
- tranche_targets(src_file, &targets);
- da_strings_puts(&targets);
- fclose(src_file);
- return 0;
-}
char *string_element = *(char **)sp;
string_state *ss = (string_state *)closure;
if( ss->found ) return;
- char *test_string = ss->string;
- ss->found = !strcmp(string_element, test_string);
+ ss->found = !strcmp(string_element, ss->string);
return;
}
-static bool exists(Da *strings, char *test_string){
+static bool exists(Da *string_arrp, char *test_string){
string_state ss;
ss.string = test_string;
ss.found = false;
- da_map(strings, string_equal, &ss);
+ da_map(string_arrp, string_equal, &ss);
return ss.found;
}
// only inserts the string if it is not already in the array
-static void insert_if_unique(Da *strings, char *proffered_string){
- if( exists( strings, proffered_string)){ // then throw it away, we don't need it
+static void insert_if_unique(Da *string_arrp, char *proffered_string){
+ if( exists( string_arrp, proffered_string)){ // then throw it away, we don't need it
free(proffered_string);
return;
}
- da_push(strings, proffered_string);
+ da_push(string_arrp, &proffered_string);
}
// dissolves proffered array into the existing array
static void combine_one(void *psp, void *closure){
- char *proffered_string = (char *)psp;
- Da *strings = (Da *)closure;
- insert_if_unique(strings, proffered_string);
+ char *proffered_string = *(char **)psp;
+ Da *string_arrp = (Da *)closure;
+ insert_if_unique(string_arrp, proffered_string);
}
-static void combine(Da *strings, Da *proffered_strings){
- da_map(proffered_strings, combine_one, strings);
+static void combine(Da *string_arrp, Da *proffered_string_arrp){
+ da_map(proffered_string_arrp, combine_one, string_arrp);
return;
}
-int tranche_targets(FILE *src, Da *targets){
+int tranche_target(FILE *src, Da *target_arrp){
char *pt;
Da line; // buffer holding the characters from a line
Da file_name_arr;// an array of file name parameters parsed from a #tranche line
pt = is_tranche_begin(line.base);
if(pt){ // then this line is the start of a nested tranche block
parse_file_list(&file_name_arr, pt);
- combine(targets, &file_name_arr); // frees strings that are not inserted
+ combine(target_arrp, &file_name_arr); // frees strings that are not inserted
+ da_rewind(&file_name_arr);
+ tranche_target(src, target_arrp);
}
da_rewind(&line);
}
#define TRANCHE_ERR_DEP_OPEN 4
int tranche_send(FILE *src, Da *arg_fds);
-int tranche_targets(FILE *src, Da *targets);
+int tranche_target(FILE *src, Da *targets);
#endif
--- /dev/null
+#!/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
+
+
--- /dev/null
+test11.dat
+test12.dat
+test13.dat
+test14.dat
+test15.dat
--- /dev/null
+#!/bin/bash -x
+./tranche-target test1.dat > test3.out
+diff test3.out test3.out.expected
+rm test3.out
+
+
--- /dev/null
+test2.c
+test2.h
--- /dev/null
+#!/bin/bash -x
+./tranche-target test2.trc.c > test4.out
+diff test4.out test4.out.expected
+rm test4.out
+
+
-../1_execs/tranche
\ No newline at end of file
+../exec/tranche
\ No newline at end of file
--- /dev/null
+../exec/tranche-target
\ No newline at end of file
TOOLDIR=$(realpath $(PROJECT_SUBU)/tool)
TRYDIR=try
-DEPFILE=$(TMPDIR)/makefile-dep
-LIBFILE=$(LIBDIR)/lib$(MODULE).a
-INCFILE=$(INCDIR)/$(MODULE).h
-
# a single space literal, for example if you wanted to subsitute commas to
# spaces: $(subst $(space),;,$(string))
blank :=
-include makefile-flags
+DEPFILE=$(TMPDIR)/makefile-dep
+LIBFILE=$(LIBDIR)/lib$(MODULE).a
+INCFILE=$(INCDIR)/$(MODULE).h
+
#--------------------------------------------------------------------------------
# targets
.PHONY: share
share:
- if [ -f $(LIBFILE) ];then cp $(LIBFILE) $(SHAREDIR)/lib; fi
- if [ -f $(INCFILE) ];then cp $(INCFILE) $(SHAREDIR)/include; fi
- if [ $(shell ls -A $(EXECDIR)) ];then cp $(EXECDIR)/* $(SHAREDIR)/bin; fi
+ if [ ! -z "$(wildcard $(LIBDIR)/*)" ]; then cp $(LIBDIR)/* $(SHAREDIR)/lib; fi
+ if [ ! -z "$(wildcard $(INCDIR)/*)" ]; then cp $(INCDIR)/* $(SHAREDIR)/include; fi
+ if [ ! -z "$(wildcard $(EXECDIR)/*)" ]; then cp $(EXECDIR)/* $(SHAREDIR)/bin; fi
.PHONY: clean
clean: