tools

various tools
git clone git://deadbeef.fr/tools.git
Log | Files | Refs | README | LICENSE

commit e08a3cbcabb074a6e028dc58ea8c25779c87f4f2
parent b53cec676f9ad7b944e4d692cb6a11670e56bbdd
Author: Morel BĂ©renger <berengermorel76@gmail.com>
Date:   Sun,  3 Jan 2021 11:18:25 +0100

add a rough template system (ninja/cpp)

Diffstat:
Asubproject.sh | 16++++++++++++++++
Atemplate/_.cpp | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atemplate/_.ninja | 12++++++++++++
3 files changed, 93 insertions(+), 0 deletions(-)

diff --git a/subproject.sh b/subproject.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +die() +{ + echo $@ + exit +} + +NAME="${1:?"subproject's name must be provided on 1st arg"}" +test -e "$NAME" && die "$NAME already exists" + +mkdir -p "$NAME/src" "$NAME/doc" +echo "subninja $NAME/$NAME.ninja" >> build.ninja + +sed '/^PROJECT/ s!NAME!'"$NAME"'!g' template/_.ninja > "$NAME/$NAME.ninja" +cp template/_.cpp "$NAME/src/$NAME.cpp" diff --git a/template/_.cpp b/template/_.cpp @@ -0,0 +1,65 @@ +#include <stdlib.h> +#include <stdio.h> +#include <errno.h> +#include <string.h> +#include <assert.h> + +#include <iterator> + +#include <vector.hpp> +#include <optparser.hpp> + +void print_help( char const* pgm, FILE* target, opt_desc_t const* start, opt_desc_t const* end ); + +int main( int argc, char** argv ) +{ + opt_desc_t opts[] = + { + STD_HELP, + {}, + }; + + auto b_opts = std::begin( opts ); + auto e_opts = std::end( opts ); + char **arg = &argv[1]; + assert( argc > 0 ); + for( int iarg = 1; iarg != argc; ++iarg, ++arg ) + { + auto error = parse_cmd_opt( *arg, b_opts, e_opts ); + switch( error ) + { + case MAX_COUNT: + arg_warning( *arg, error ); + break; + case NONE: + case IGNORED: + break; + case SET_NO_VAL: + case SET_VAL_IGN: + case SET_FAIL: + case BAD_ARGS: + case BAD_SETTER: + print_help( argv[0], stderr, b_opts, e_opts ); + arg_error( *arg, error ); + return EXIT_FAILURE; + } + } + if( opts[0].count ) + { + print_help( argv[0], stdout, b_opts, e_opts ); + return EXIT_SUCCESS; + } + + return EXIT_SUCCESS; +} + +void print_help( char const* pgm, FILE* target, opt_desc_t const* start, opt_desc_t const* end ) +{ + fputs( "Usage: ", target ); + fputs( pgm, target ); + fputs( " [OPTIONS]\n" + "Description:\n" + "Options:\n" + , target ); + print_opts( target, start, end ); +} diff --git a/template/_.ninja b/template/_.ninja @@ -0,0 +1,12 @@ +PROJECT = NAME +CXXFLAGS = $$CXXFLAGS -fcolor-diagnostics + +SRC = ./$PROJECT/src +DST = ./build/$PROJECT/src + +BTL_LIB = ./build/btl/ +BTL_INC = ./btl/src/ +CXXFLAGS = $CXXFLAGS -I$BTL_INC -DFILE_PTR=FILE* + +build $DST/$PROJECT.cpp.o: cxx $SRC/$PROJECT.cpp +build $DST/../$PROJECT: ld $DST/$PROJECT.cpp.o $BTL_LIB/btl.a