--- /dev/null
+
+
+filename.tag.extension
+
+extension:
+ .c for C source
+ .cc for C++ source
+ .h for C header file
+ .hh for C++ header file
+ .o an object file
+
+tag:
+ .lib. The resulting .o file to be placed in release library and is part of the
+ programming interface.
+ .aux. The resulting.o file not directly part of the programming interface, but
+ it might be called by functions that are.
+ .cli. The source file has a main call and is to be relased as part of the command line interface
+ .loc. file has a main call to be made into a local uitlity function
+
+We carry the source file tag and extension to the .o file. We do not put tags
+nor extensions on command line executables.
+
+local_common.h should be included in all source files
--- /dev/null
+
+ src-da a simple doubling size expanding array in C
+ src-tranche splits source code into multiple files. A poor man's 'makeheaders'.
+src-dispatch runs a function or shell command as a separate process
+ src-db sqlite schema and interface for subu
+ src-0 The layer 0 commands for subu. Some are setuid root programs.
+ src-py The application layer
+
+
#subdirectories=$(shell /usr/bin/find . -maxdepth 1 -printf "%f " | sed y/\./\ /)
-subdirectories=src
+subdirectories=$(wildcard src-*)
all :
# $(foreach dir, $(subdirectories), \
# if [ -f $(dir)/0_makefile ]; then \
-# make -C $(dir) all && make -C $(dir) install; \
+# make -C $(dir) all && make -C $(dir) stage; \
# fi;\
# )
#CFLAGS=-std=gnu11 -fPIC -I. -Werror
LINKFLAGS=-L1_lib -lsubu -lsqlite3
-LIB_FILE=$(LIBDIR)/libsubu.a
+LIBFILE=$(LIBDIR)/libsubu.a
+++ /dev/null
-
-
-filename.tag.extension
-
-extension:
- .c for C source
- .cc for C++ source
- .h for C header file
- .hh for C++ header file
- .o an object file
-
-tag:
- .lib. The resulting .o file to be placed in release library and is part of the
- programming interface.
- .aux. The resulting.o file not directly part of the programming interface, but
- it might be called by functions that are.
- .cli. The source file has a main call and is to be relased as part of the command line interface
- .loc. file has a main call to be made into a local uitlity function
-
-We carry the source file tag and extension to the .o file. We do not put tags
-nor extensions on command line executables.
-
-local_common.h should be included in all source files
+++ /dev/null
-these are the comments from my RT makefile:
-
-#
-# 2010 11 20 TWL Created
-# 2011 05 26 TWL Modified to generalize
-# 2012 02 23 NLS Add ECHO variable to use on different environnement
-# corrected setup macro --> add include directory in the path to copy
-# corrected install macro --> change the name of installed library : lib$(LIB)$(LIBSUFFIX)
-# changed DOC_DIR directory name to 5_documents
-# 2012 02 23 TWL removed LIB variable which is now set from the command line so
-# so that all source dirs can use the same makefile
-# 2012 02 23 TWL added target make dist_clean which also deletes the 2_makefile_deps file
-# 2012 04 11 AWW added creation of temporary disk before each test is run
-# 2012 06 05 TWL moved tests and try .cc files to directories. caused rtmake tests to
-# dist_clean and make deps
-#
-#
-#----------------------------------------------------------------------------
-# use this makefile to compile and test the code:
-#
-# for a first time run, or for regression use the following:
-#
-# $ make setup # makes the directories, though should already exist
-# $ make regress
-#
-# the usual development workflow makes use of these:
-#
-# $ make deps # only when needed, for example if headers includes change or new files introduced
-# $ cd tests; make deps # only when needed
-# $ make lib # this makes the local library
-# $ make tests # this updates tests and compiles
-# $ make clean # deletes the .o files and library to force a recompile
-# $ cd 1_tests; make clean
-#
-# for a release of a component
-#
-# $ make regress
-# $ make install # this will only work if all the tests in 1_tests are passing
-#
-# before a checkin
-#
-# $ make dist_clean # will also clean the tests and try directories
-#
-# .lib.cc c++ files taken as source of object files for local build library
-# .exl.cc c++ files taken to have main calls and are linked against local build libary
-# .ex.cc c++ files taken to have main calls and are not linked against the local build library
-# there are no rules for other files in this makefile
-#
-# about dependencies
-# The makefile has no way of knowing if an edit changed the dependencies. Often they do not
-# and it would be unwieldy to make the deps every time. Hence *the programmer* must delete
-# the deps file if he has made any changes that change the dependencies.
-#
-# The makefile will make the 2_makefile_deps if the file is missing.
-#
-#
-# about testing
-#
-# the name of the directory you run make in is taken to also be: the name of the library,
-# the name of the main include file (with a .h added), and the name of the include directory
-# where the individual headers are found. It is called LIB
-#
-# test programs are kept in a subdirectory called 1_tests, and are either .exl.cc, ex.cc,
-# .sh files. When 'make tests' target is invoked they are all run. Test executables return 0
-# if the test fails, non-zero otherwise.
-#
-# to remove a test from the pool move it into the subdirectory in 1_tests, 9_broken,
-# 5_more_tests of 5_scratch. broken tests are things that are known but must be fixed
-# before a release. 5_more_tests are tests being worked on. 5_scratch is stuff that is
-# probably going to be deleted. if there is a 5_deprecated, that is for good stuff but it
-# is no longer used for some reason or other.
-#
-# There is a standard source code template and a
-# messaging convention. Also, the names, by convention,are test_xxxx_ where xxx is a
-# hexadecimal series nummber. If all the test executables pass the file 1_TESTS_PASSED is
-# left in the directory. Otherwise the file 1_TESTS_FAILED is left in the directory.
-#
-# about release directory
-#
-# this is set in the ApplicationBase variable by rt_init
-#
-# after the tests pass stuff might be copied to the release directory using
-#
-# make install
-#
-# the release directory must have these subdirectories:
-#
-# bin documents include src
-#
-#
-#
+++ /dev/null
-
-This worked to force the include to be part of the interface:
-
-#if INTERFACE
-#include <sqlite3.h>
-#endif
-
-But this did not:
-
-#if INTERFACE
- #include <sqlite3.h>
-#endif
-
-makeheaders looks to be sensitive to indentation
-
-
+++ /dev/null
-
-1.
- This sql:
-
- char *sql =
- "BEGIN TRANSACTION;"
- "UPDATE Key_Int SET value = value + 1 WHERE key = 'max_subu_number';"
- "SELECT value FROM Key_Int WHERE key = 'max_subu_number';"
- "COMMIT;"
- ;
-
- with sqlite_exec, the call back is called with the data from the select.
-
- with sqlite_prepare_v2, sqlite_step just returns SQLITE_DONE, and we never
- get to see our data from the select.
#CFLAGS=-std=gnu11 -fPIC -I. -Werror
LINKFLAGS=-L$(PROJECT_SUBU)/src/$(LIBDIR) -L. -lsubu -lsqlite3 -lsubutests
-LIB_FILE=$(LIBDIR)/libtests.a
+LIBFILE=$(LIBDIR)/libtests.a
-include 0_makefile-flags
-MAKE=/usr/bin/make -f $(PROJECT_SUBU)/tools/lib/makefile_cc
-
all: version deps lib execs
lib:
TOOLSDIR=$(realpath $(PROJECT_SUBU)/tools)
TRYDIR=1_try
-
# compiler and flags
CC=gcc
CFLAGS=-std=gnu11 -fPIC -I. -ggdb -Werror -DDEBUG -DDEBUGDB
#CFLAGS=-std=gnu11 -fPIC -I. -Werror
LINKFLAGS=-L1_lib -lda
-LIB_FILE=libda.a
-INC_FILE=da.h
+LIBFILE=libda.a
+INCFILE=da.h
+
+MAKE=/usr/bin/make --no-print-directory -f $(PROJECT_SUBU)/tools/lib/makefile_cc
{ da_map(dap, da_free, NULL); return r; }
void da_alloc(Da *dap, size_t item_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_map(Da *dap, void f(void *, void *), void *closure);
-void da_free(void *pt, void *closure);
+void da_free_elements(Da *dap);
+char *da_fgets(Da *dap, FILE *fd);
#endif
-include 0_makefile-flags
-MAKE=/usr/bin/make -f $(PROJECT_SUBU)/tools/lib/makefile_cc
-
all: version deps lib execs
%::
#CFLAGS=-std=gnu11 -fPIC -I. -I../1_include -Werror
LINKFLAGS=-L. -L../1_lib -ltests -lda
-LIB_FILE=libtests.a
+LIBFILE=libtests.a
+MAKE=/usr/bin/make --no-print-directory -f $(PROJECT_SUBU)/tools/lib/makefile_cc
+
-passed all 2 tests
+passed all 4 tests
--- /dev/null
+this is a test
+ends without a newline
+(setq mode-require-final-newline nil)
\ No newline at end of file
unsigned int passed = 0;
unsigned int failed = 0;
- if( !test_da_0() ){
- failed++;
- printf("test_da_0 failed\n");
- }else
- passed++;
-
- if( !test_da_1() ){
- failed++;
- printf("test_da_1 failed\n");
- }else
- passed++;
+ // 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");
*/
+#include <stdio.h>
+#include <string.h>
#include <stdbool.h>
#include <da.h>
#include "test_da.lib.h"
-
-int test_da_0(){
+// tests push
+bool test_da_0(){
Da da;
da_alloc(&da, sizeof(int)); // leaves room for 4 ints
int i = 0;
return f0 && f1 && f2 && f3;
}
-int test_da_1(){
+// tests manual expansion
+bool test_da_1(){
Da da;
da_alloc(&da, sizeof(int)); // leaves room for 4 ints
int i = 0;
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;
+}
+
+
+
#ifndef DA_LIB_H
#define DA_LIB_H
-int test_da_0();
-int test_da_1();
+bool test_da_0();
+bool test_da_1();
+bool test_da_2();
+bool test_da_3();
#endif
--- /dev/null
+da.lib.o: da.lib.c da.lib.h
dap->base = malloc(dap->size);
dap->end = dap->base;
}
+void da_free(Da *dap){
+ free(dap->base);
+ dap->size = 0;
+}
+void da_rewind(Da *dap){
+ dap->end = dap->base;
+}
+
+bool da_empty(Da *dap){
+ return dap->end == dap->base;
+}
// Doubles size of of da. Returns old base, so that existing pointers into the
// array can be moved to the new array
dap->end += dap->item_size;
}
+bool da_pop(Da *dap, void *item){
+ bool flag = dap->end >= dap->base + dap->item_size;
+ if( flag ){
+ dap->end -= dap->item_size;
+ if(item) memcpy(item, dap->end, dap->item_size);
+ }
+ return flag;
+}
+
// passed in f(item_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.
}
// da_lists are sometimes used as resource managers
-void da_free(void *pt, void *closure){
+static void da_free_element(void *pt, void *closure){
free(pt);
}
+void da_free_elements(Da *dap){
+ da_map(dap, da_free_element, NULL);
+ da_rewind(dap);
+}
+
+
// Puts text from a line into buffer *dap. Does not push EOF or '\n' into the
-// buffer. Returns the line terminator, which will either be EOF or '\n'. This
-// will not work very well if the line gets very long, as da doubles in size at
-// buffer overrun. items_size for dap must be sizeof(char).
-int da_fgets(Da *dap, FILE *fd){
+// 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 *old_base = dap->base;
int c = fgetc(fd);
while( c != EOF && c != '\n' ){
da_push(dap, &c);
}
int terminator = 0;
da_push(dap, &terminator);
- return c;
+ return old_base;
}
{ da_map(dap, da_free, NULL); return r; }
void da_alloc(Da *dap, size_t item_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_map(Da *dap, void f(void *, void *), void *closure);
-void da_free(void *pt, void *closure);
+void da_free_elements(Da *dap);
+char *da_fgets(Da *dap, FILE *fd);
#endif
#CFLAGS=-std=gnu11 -fPIC -I. -Werror
LINKFLAGS=-L1_lib -lsubu -lsqlite3
-LIB_FILE=$(LIBDIR)/libsubu.a
+LIBFILE=$(LIBDIR)/libsubu.a
--- /dev/null
+
+1.
+ This sql:
+
+ char *sql =
+ "BEGIN TRANSACTION;"
+ "UPDATE Key_Int SET value = value + 1 WHERE key = 'max_subu_number';"
+ "SELECT value FROM Key_Int WHERE key = 'max_subu_number';"
+ "COMMIT;"
+ ;
+
+ with sqlite_exec, the call back is called with the data from the select.
+
+ with sqlite_prepare_v2, sqlite_step just returns SQLITE_DONE, and we never
+ get to see our data from the select.
-# src/0_makefile
+# src-da/0_makefile
SHELL=/bin/bash
--include 0_makefile_flags
-
-SUID_TOOL=$(TOOLSDIR)/bin/setuid_root.sh
-MAKE=/usr/bin/make -f $(PROJECT_SUBU)/tools/lib/makefile_cc
-
-SOURCES=$(wildcard *.c)
-HFILES=$(wildcard *.h)
+-include 0_makefile-flags
all: version deps lib execs
-version:
- $(MAKE) $@
- @echo "SUID_TOOL: " $(SUID_TOOL)
-
-deps:
- makeheaders $(SOURCES) $(HFILES)
- sed -i '/^ *int *main *(.*)/d' *.h
- $(MAKE) $@
-
-execs:
- $(MAKE) $@
- @echo "-> $(SUID_TOOL) $(EXECSDIR)/subu-mk-0 $(EXECSDIR)/subu-rm-0 $(EXECSDIR)/subu-bind-all"
- cat $(SUID_TOOL)
- @echo -n "Are you sure? [y/N] " && read ans && [ $${ans:-N} == y ]
- sudo $(SUID_TOOL) $(EXECSDIR)/subu-mk-0 $(EXECSDIR)/subu-rm-0 $(EXECSDIR)/subu-bind-all
-
-clean:
- $(MAKE) $@
- for i in $(HFILES); do rm $$i; done
-
%::
$(MAKE) $@
DEPRDIR=1_deprecated
DOCDIR=1_doc
EXECSDIR=1_execs
-HDIR=1_headers
+INCDIR=1_include
LIBDIR=1_lib
TESTDIR=1_tests
TMPDIR=1_tmp
TOOLSDIR=$(realpath $(PROJECT_SUBU)/tools)
TRYDIR=1_try
-
# compiler and flags
CC=gcc
-CFLAGS=-std=gnu11 -fPIC -I. -ggdb -Werror -DDEBUG -DDEBUGDB
+CFLAGS=-std=gnu11 -fPIC -I. -I$(PROJECT_SUBU)/stage/include -ggdb -Werror -DDEBUG -DDEBUGDB
#CFLAGS=-std=gnu11 -fPIC -I. -Werror
-LINKFLAGS=-L1_lib -lsubu -lsqlite3
+LINKFLAGS=-L1_lib -lda
-LIB_FILE=$(LIBDIR)/libsubu.a
+LIBFILE=libtranche.a
+INCFILE=tranche.h
+MAKE=/usr/bin/make --no-print-directory -f $(PROJECT_SUBU)/tools/lib/makefile_cc
--- /dev/null
+# src/0_makefile
+
+SHELL=/bin/bash
+
+-include 0_makefile_flags
+
+SUID_TOOL=$(TOOLSDIR)/bin/setuid_root.sh
+MAKE=/usr/bin/make -f $(PROJECT_SUBU)/tools/lib/makefile_cc
+
+SOURCES=$(wildcard *.c)
+HFILES=$(wildcard *.h)
+
+all: version deps lib execs
+
+version:
+ $(MAKE) $@
+ @echo "SUID_TOOL: " $(SUID_TOOL)
+
+deps:
+ makeheaders $(SOURCES) $(HFILES)
+ sed -i '/^ *int *main *(.*)/d' *.h
+ $(MAKE) $@
+
+execs:
+ $(MAKE) $@
+ @echo "-> $(SUID_TOOL) $(EXECSDIR)/subu-mk-0 $(EXECSDIR)/subu-rm-0 $(EXECSDIR)/subu-bind-all"
+ cat $(SUID_TOOL)
+ @echo -n "Are you sure? [y/N] " && read ans && [ $${ans:-N} == y ]
+ sudo $(SUID_TOOL) $(EXECSDIR)/subu-mk-0 $(EXECSDIR)/subu-rm-0 $(EXECSDIR)/subu-bind-all
+
+clean:
+ $(MAKE) $@
+ for i in $(HFILES); do rm $$i; done
+
+%::
+ $(MAKE) $@
+
+
+
+
--- /dev/null
+
+# some versions of Linux need a -e option others complain if there is a -e .. and it isn't the binary for echo ..
+ECHO= echo
+#ECHO= echo -e
+
+# 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 staged
+#$(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=1_deprecated
+DOCDIR=1_doc
+EXECSDIR=1_execs
+HDIR=1_headers
+LIBDIR=1_lib
+TESTDIR=1_tests
+TMPDIR=1_tmp
+TOOLSDIR=$(realpath $(PROJECT_SUBU)/tools)
+TRYDIR=1_try
+
+
+# compiler and flags
+CC=gcc
+CFLAGS=-std=gnu11 -fPIC -I. -ggdb -Werror -DDEBUG -DDEBUGDB
+#CFLAGS=-std=gnu11 -fPIC -I. -Werror
+LINKFLAGS=-L1_lib -lsubu -lsqlite3
+
+LIBFILE=$(LIBDIR)/libsubu.a
+
--- /dev/null
+# src-da/1_tests/0_makefile
+
+SHELL=/bin/bash
+
+-include 0_makefile-flags
+
+all: version deps lib execs
+
+%::
+ $(MAKE) $@
+
+
+
+
--- /dev/null
+
+# some versions of Linux need a -e option others complain if there is a -e .. and it isn't the binary for echo ..
+ECHO= echo
+#ECHO= echo -e
+
+# 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 staged
+#$(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=
+EXECSDIR=.
+INCDIR=.
+LIBDIR=.
+TESTDIR=.
+TMPDIR=1_tmp
+TOOLSDIR=$(realpath $(PROJECT_SUBU)/tools)
+TRYDIR=
+
+
+# compiler and flags
+CC=gcc
+CFLAGS=-std=gnu11 -fPIC -I. -I../1_include -ggdb -Werror -DDEBUG -DDEBUGDB
+#CFLAGS=-std=gnu11 -fPIC -I. -I../1_include -Werror
+LINKFLAGS=-L. -L../1_lib -ltests -lda
+
+LIBFILE=libtranche.a
+MAKE=/usr/bin/make --no-print-directory -f $(PROJECT_SUBU)/tools/lib/makefile_cc
+
+
+++ /dev/null
-/*
-The purpose of this tools is to facilitate putting prototypes (declarations) next
-to implementations (definitions) in a single source file of a C/C++ programs.
-
-Splits a single source file into multiple files. Scans through the single
-source file looking for lines of the form:
-
- #tranche filename ...
-
-With the # mandatory at column 1 (like the old C preprocessor). Upon finding
-such a line, copies all following lines into the listed files, until reaching the
-end marker:
-
- #endtranche
-
-A next improvement of this file would be to support variables to be passed in,
-as per a make file.
-
-*/
-
-
-void tranche(FILE *file){
-
-
-
-}
--- /dev/null
+
+
+int main(int argc, char **argv, char **envp){
+
+
+}
--- /dev/null
+/*
+The purpose of this tools is to facilitate putting prototypes (declarations) next
+to implementations (definitions) in a single source file of a C/C++ programs.
+
+Splits a single source file into multiple files. Scans through the single
+source file looking for lines of the form:
+
+ #tranche filename ...
+
+With the # as the first non-space character on the line, and only filename
+following the tag. Upon finding such a line, copies all following lines into the
+listed files, until reaching the end marker:
+
+ #endtranche
+
+A next improvement of this file would be to support variables to be passed in
+for the file names. As it stands, changing the file name requires editing
+the source file.
+
+*/
+
+#include <da.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+//--------------------------------------------------------------------------------
+// parsing
+
+char tranche_begin_tag[] = "#tranche";
+size_t tranche_begin_tag_len = 8;
+
+char tranche_end_tag[] = "#endtranche";
+size_t tranche_end_tag_len = 11;
+
+// given a line
+// returns beginning of file name list
+static char *is_tranche_begin(char *pt){
+ while( *pt && isspace(*pt) ) pt++;
+ if(!*pt) return NULL;
+ if( strncmp(pt, tranche_begin_tag, tranche_begin_tag_len) ) return NULL;
+ return pt + tranche_begin_tag_len;
+}
+
+static char *is_tranche_end(char *pt){
+ while( *pt && isspace(*pt) ) pt++;
+ if(!*pt) return NULL;
+ if( strncmp(pt, tranche_end_tag, tranche_end_tag_len) ) return NULL;
+ return pt + tranche_end_tag_len;
+}
+
+static bool parse_file_list(Da *file_names, char *pt0){
+ char *pt1;
+ while( *pt0 && isspace(*pt0) ) pt0++;
+ while( *pt0 ){
+ pt1 = pt0;
+ while( *pt1 && !isspace(pt1) ) pt1++;
+ char *file_name = strndup(pt0, pt1 - pt0);
+ da_push(file_names, file_name);
+ pt0 = pt1;
+ while( *pt0 && isspace(*pt0) ) pt0++;
+ }
+}
+
+
+
+//--------------------------------------------------------------------------------
+// da_map calls
+
+static void tranche_open_fd(void *fn, void *closure){
+ char *file_name = (char *)fn;
+ Da *fds = (Da *)closure;
+ int fd = open(fn, O_CREAT | O_APPEND);
+ if(fd == -1){
+ fprintf(stderr, "Could not open file %s\n", file_name);
+ return;
+ }
+ da_push(fds, &fd);
+ return;
+}
+static void tranche_open_fds(Da *fns, Da *fds){
+ da_map(fns, tranche_open_fd, fds);
+}
+
+static void tranche_close_fd(void *fd, void *closure){
+ close(*(int *)fd);
+}
+static void tranche_close_fds(Da *fds){
+ da_map(fds, tranche_close_fd, NULL);
+}
+
+static void tranche_puts(void *fd, void *string){
+ write(*(int *)fd, string, strlen(string));
+}
+static void tranche_puts_all(Da *fds, char *string){
+ da_map(fds, tranche_puts, string);
+}
+
+//--------------------------------------------------------------------------------
+//
+
+int tranche_send(FILE *src, Da *arg_fds){
+ char *pt;
+ Da line;
+ Da file_names;
+ Da fds;
+ da_alloc(&line, sizeof(char));
+ da_alloc(&file_names, sizeof(char *));
+ da_alloc(&fds, sizeof(int));
+
+ da_fgets(&line, src);
+ while( !feof(src) && !is_tranche_end(line.base) ){
+ pt = is_tranche_begin(line.base);
+ if(pt){ // then this line is the start of a nested tranche block
+ parse_file_list(&file_names, pt);
+ tranche_open_fds(&file_names, &fds);
+ da_free_elements(&file_names);
+ tranche_send(src, &fds);
+ tranche_close_fds(&fds);
+ }else{
+ tranche_puts_all(arg_fds, line.base);
+ da_rewind(&line);
+ da_fgets(&line, src);
+ }
+ }
+
+ da_free(&line);
+ da_free(&file_names);
+ da_free(&fds);
+ return 0;
+}
--- /dev/null
+#ifndef TRANCHE_LIB_H
+#define TRANCHE_LIB_H
+
+int tranche_send(FILE *src, Da *arg_fds);
+
+
+
+#endif
{ da_map(dap, da_free, NULL); return r; }
void da_alloc(Da *dap, size_t item_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_map(Da *dap, void f(void *, void *), void *closure);
-void da_free(void *pt, void *closure);
+void da_free_elements(Da *dap);
+char *da_fgets(Da *dap, FILE *fd);
#endif
--- /dev/null
+these are the comments from my RT makefile:
+
+#
+# 2010 11 20 TWL Created
+# 2011 05 26 TWL Modified to generalize
+# 2012 02 23 NLS Add ECHO variable to use on different environnement
+# corrected setup macro --> add include directory in the path to copy
+# corrected install macro --> change the name of installed library : lib$(LIB)$(LIBSUFFIX)
+# changed DOC_DIR directory name to 5_documents
+# 2012 02 23 TWL removed LIB variable which is now set from the command line so
+# so that all source dirs can use the same makefile
+# 2012 02 23 TWL added target make dist_clean which also deletes the 2_makefile_deps file
+# 2012 04 11 AWW added creation of temporary disk before each test is run
+# 2012 06 05 TWL moved tests and try .cc files to directories. caused rtmake tests to
+# dist_clean and make deps
+#
+#
+#----------------------------------------------------------------------------
+# use this makefile to compile and test the code:
+#
+# for a first time run, or for regression use the following:
+#
+# $ make setup # makes the directories, though should already exist
+# $ make regress
+#
+# the usual development workflow makes use of these:
+#
+# $ make deps # only when needed, for example if headers includes change or new files introduced
+# $ cd tests; make deps # only when needed
+# $ make lib # this makes the local library
+# $ make tests # this updates tests and compiles
+# $ make clean # deletes the .o files and library to force a recompile
+# $ cd 1_tests; make clean
+#
+# for a release of a component
+#
+# $ make regress
+# $ make install # this will only work if all the tests in 1_tests are passing
+#
+# before a checkin
+#
+# $ make dist_clean # will also clean the tests and try directories
+#
+# .lib.cc c++ files taken as source of object files for local build library
+# .exl.cc c++ files taken to have main calls and are linked against local build libary
+# .ex.cc c++ files taken to have main calls and are not linked against the local build library
+# there are no rules for other files in this makefile
+#
+# about dependencies
+# The makefile has no way of knowing if an edit changed the dependencies. Often they do not
+# and it would be unwieldy to make the deps every time. Hence *the programmer* must delete
+# the deps file if he has made any changes that change the dependencies.
+#
+# The makefile will make the 2_makefile_deps if the file is missing.
+#
+#
+# about testing
+#
+# the name of the directory you run make in is taken to also be: the name of the library,
+# the name of the main include file (with a .h added), and the name of the include directory
+# where the individual headers are found. It is called LIB
+#
+# test programs are kept in a subdirectory called 1_tests, and are either .exl.cc, ex.cc,
+# .sh files. When 'make tests' target is invoked they are all run. Test executables return 0
+# if the test fails, non-zero otherwise.
+#
+# to remove a test from the pool move it into the subdirectory in 1_tests, 9_broken,
+# 5_more_tests of 5_scratch. broken tests are things that are known but must be fixed
+# before a release. 5_more_tests are tests being worked on. 5_scratch is stuff that is
+# probably going to be deleted. if there is a 5_deprecated, that is for good stuff but it
+# is no longer used for some reason or other.
+#
+# There is a standard source code template and a
+# messaging convention. Also, the names, by convention,are test_xxxx_ where xxx is a
+# hexadecimal series nummber. If all the test executables pass the file 1_TESTS_PASSED is
+# left in the directory. Otherwise the file 1_TESTS_FAILED is left in the directory.
+#
+# about release directory
+#
+# this is set in the ApplicationBase variable by rt_init
+#
+# after the tests pass stuff might be copied to the release directory using
+#
+# make install
+#
+# the release directory must have these subdirectories:
+#
+# bin documents include src
+#
+#
+#
--- /dev/null
+
+This worked to force the include to be part of the interface:
+
+#if INTERFACE
+#include <sqlite3.h>
+#endif
+
+But this did not:
+
+#if INTERFACE
+ #include <sqlite3.h>
+#endif
+
+makeheaders looks to be sensitive to indentation
+
+
-include 0_makefile-flags
-DEPS_FILE=$(TMPDIR)/makefile_deps
+DEPSFILE=$(TMPDIR)/makefile_deps
# a single space literal, for example if you wanted to subsitute commas to
# spaces: $(subst $(space),;,$(string)) we ran into this out of a need to send
all: version deps lib execs
version:
- @echo '---- make $@:------------------------------------------------------------'
@echo makefile version 3.0
@echo "PWD: " $(PWD)
@echo "MAKEFILE_LIST: " $(MAKEFILE_LIST)
@echo "CC: " $(CC)
@echo "CFLAGS: " $(CFLAGS)
@echo "LINKFLAGS: " $(LINKFLAGS)
- @echo '______end make $@_____'
info:
- @echo '---- make $@:------------------------------------------------------------'
@echo "DEPDIR: " $(DEPDIR)
@echo "DOCDIR: " $(DOCDIR)
@echo "EXECSDIR: " $(EXECSDIR)
@echo "TMPDIR: " $(TMPDIR)
@echo "TOOLSDIR: " $(TOOLSDIR)
@echo "TRYDIR: " $(TRYDIR)
- @echo "DEPS_FILE: " $(DEPS_FILE)
- @echo "LIB_FILE: " $(LIB_FILE)
+ @echo "DEPSFILE: " $(DEPSFILE)
+ @echo "LIBFILE: " $(LIBFILE)
@echo "SOURCES_LIB: " $(SOURCES_LIB)
@echo "SOURCES_CLI: " $(SOURCES_CLI)
@echo "SOURCES: " $(SOURCES)
@echo "OBJECTS_CLI: " $(OBJECTS_CLI)
@echo "OBJECTS: " $(OBJECTS)
@echo "EXECS: " $(EXECS)
- @echo '______end make $@_____'
# should be safe to run this in an already setup or partially setup directory
setup:
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
if [ ! -e $(DEPRDIR) ]; then mkdir $(DEPRDIR); fi
if [ ! -e $(DOCDIR) ]; then mkdir $(DOCDIR); fi
if [ ! -e $(EXECSDIR) ]; then mkdir $(EXECSDIR); fi
if [ ! -e $(TESTDIR) ]; then mkdir $(TESTDIR); fi
if [ ! -e $(TMPDIR) ]; then mkdir $(TMPDIR); fi
if [ ! -e $(TRYDIR) ]; then mkdir $(TRYDIR); fi
- @echo '______end make $@_____'
deps:
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
- $(CC) $(CFLAGS) -MM $(SOURCES) 1> $(DEPS_FILE)
+ $(CC) $(CFLAGS) -MM $(SOURCES) 1> $(DEPSFILE)
for i in $(EXECS) ; do\
- $(ECHO) >> $(DEPS_FILE);\
- $(ECHO) "$(EXECSDIR)/$$i : $$i.cli.o $(LIBDIR)/$(LIB_FILE)" >> $(DEPS_FILE);\
- $(ECHO) " $(CC) -o $(EXECSDIR)/$$i $$i.cli.o $(LINKFLAGS)" >> $(DEPS_FILE);\
+ $(ECHO) >> $(DEPSFILE);\
+ $(ECHO) "$(EXECSDIR)/$$i : $$i.cli.o $(LIBDIR)/$(LIBFILE)" >> $(DEPSFILE);\
+ $(ECHO) " $(CC) -o $(EXECSDIR)/$$i $$i.cli.o $(LINKFLAGS)" >> $(DEPSFILE);\
done
- @echo '______end make $@_____'
lib:
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
- if [ ! -e $(DEPS_FILE) ]; then make deps; fi
+ if [ ! -e $(DEPSFILE) ]; then make deps; fi
make sub_lib
- @echo '______end make $@_____'
-sub_lib: $(LIBDIR)/$(LIB_FILE)
+sub_lib: $(LIBDIR)/$(LIBFILE)
-execs: $(LIBDIR)/$(LIB_FILE)
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
- if [ ! -e $(DEPS_FILE) ]; then make deps; fi
+execs: $(LIBDIR)/$(LIBFILE)
+ if [ ! -e $(DEPSFILE) ]; then make deps; fi
make sub_execs
- @echo '______end make $@_____'
sub_execs: $(patsubst %, $(EXECSDIR)/%, $(EXECS))
stage:
- if [ -f $(LBIDIR)/$(LIBFILE) ]; then cp $(LIBDIR)/$(LIBFILE) $(PROJECT_SUBU)/stage/lib; fi
- if [ -f $(INCDIR)/$(INC_FILE) ]; then cp $(INCDIR)/$(INC_FILE) $(PROJECT_SUBU)/stage/include; fi
+ if [ -f $(LIBDIR)/$(LIBFILE) ]; then cp $(LIBDIR)/$(LIBFILE) $(PROJECT_SUBU)/stage/lib; fi
+ if [ -f $(INCDIR)/$(INCFILE) ]; then cp $(INCDIR)/$(INCFILE) $(PROJECT_SUBU)/stage/include; fi
clean:
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
for i in $(wildcard *~); do mv $$i $(TMPDIR); done
for i in $(wildcard *.lib.o) $(wildcard *.cli.o); do rm $$i; done
for i in $(EXECS); do if [ -e $(EXECSDIR)/$$i ]; then rm $(EXECSDIR)/$$i; fi; done
- if [ -f $(LIBDIR)/$(LIB_FILE) ]; then rm $(LIBDIR)/$(LIB_FILE); fi
- if [ -f $(DEPS_FILE) ]; then rm $(DEPS_FILE); fi
- @echo '______end make $@_____'
+ if [ -f $(LIBDIR)/$(LIBFILE) ]; then rm $(LIBDIR)/$(LIBFILE); fi
+ if [ -f $(DEPSFILE) ]; then rm $(DEPSFILE); fi
dist-clean:
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
make clean
- if [ -d $(TESTDIR) ]; then cd $(TESTDIR); make dist_clean; fi
- if [ -d $(TRYDIR) ] ; then cd $(TRYDIR); make dist_clean; fi
- @echo '______end make $@_____'
+ if [ -d $(TESTDIR) ]; then cd $(TESTDIR); make dist-clean; fi
+ if [ -d $(TRYDIR) ] ; then cd $(TRYDIR); make dist-clean; fi
#
-$(LIBDIR)/$(LIB_FILE) : $(OBJECTS_LIB)
- ar rcs $(LIBDIR)/$(LIB_FILE) $(OBJECTS_LIB)
+$(LIBDIR)/$(LIBFILE) : $(OBJECTS_LIB)
+ ar rcs $(LIBDIR)/$(LIBFILE) $(OBJECTS_LIB)
--include $(DEPS_FILE)
+-include $(DEPSFILE)
# recipe for making object files:
#