-#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
+
+
+++ /dev/null
-/* \aThis file was automatically generated. Do not edit! */
-#undef INTERFACE
-int test_da_0();
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
+
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);
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
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);
+++ /dev/null
-da.lib.o: da.lib.c da.lib.h
// 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;
}
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;
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;
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;
}
}
// 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);
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);
+++ /dev/null
-dbprintf.lib.o: dbprintf.lib.c dbprintf.lib.h
+++ /dev/null
-/* \aThis file was automatically generated. Do not edit! */
-#undef INTERFACE
-int dbprintf(const char *format,...);
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
--- /dev/null
+
+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 ' '.
+
--- /dev/null
+
+#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
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);
}
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);
mf=( ?_makefile )
if [ -f "$mf" ]; then
- /usr/bin/make -f ?_makefile "$@"
+ /usr/bin/make -f "$mf" "$@"
else
/usr/bin/make "$@"
fi
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)