author | Olivier Brunel
<jjk@jjacky.com> 2023-04-06 11:33:46 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2023-04-06 11:33:46 UTC |
parent | 9300d7c6fcf6f3e805646c8433f476daee25584b |
init | +1 | -55 |
initprj | +174 | -0 |
initrepo | +57 | -0 |
mkdoc | +2 | -1 |
src/doc/include/author.md | +3 | -0 |
src/doc/include/autoopt_debug.md | +6 | -0 |
src/doc/include/autoopt_log.md | +6 | -0 |
src/doc/include/autoopt_logdbg_level.md | +6 | -0 |
src/doc/include/autoopt_quiet.md | +1 | -0 |
src/doc/include/autoopt_verbose.md | +1 | -0 |
src/doc/include/bugs.md | +6 | -0 |
src/doc/include/opt_help.md | +2 | -0 |
src/doc/include/opt_version.md | +2 | -0 |
diff --git a/init b/init index 6c7f0c4..ff930ab 100755 --- a/init +++ b/init @@ -1,57 +1,3 @@ #!/bin/sh -if test -d meta; then - echo "Directory 'meta' already exist" >&2 - exit 2 -fi - -name=$(basename "$(pwd)") -mkdir meta -echo $name > meta/name -echo 0.0.0 > meta/version - -. "$(dirname $0)"/libcomain - -if test ! -d comain; then - error 2 "Directory 'comain' not found" -fi - -run cp -n comain/Makefile Makefile -run cp -n comain/project.mk.tpl project.mk -run mkdir src -run cp -n comain/meta/README.git meta -run echo https://lila.oss/$name > meta/site -run echo git://lila.oss/$name.git > meta/git -run echo https://lila.oss/doc/$name > meta/doc -run echo https://lila.oss/code/$name > meta/code -run cp -n comain/meta/COPYING meta -run cp -n comain/meta/LICENSE meta -run cp -n comain/meta/AUTHORS.tpl meta/AUTHORS -run mkdir meta/deps -run mkdir meta/deps/comain -run touch meta/deps/comain/cpnt -run cp -n comain/meta/version meta/deps/comain/version -run cp -n comain/meta/git meta/deps/comain/git -run mkdir meta/options -for opt in comain/meta/options/*; do - run ln -s ../../$opt meta/options -done -run ln -sf meta/README.git README -run ln -sf meta/AUTHORS -run ln -sf meta/COPYING -run ln -sf meta/HISTORY -if test -e .gitignore; then error 2 "File '.gitignore' already exists"; fi -run cat > .gitignore <<EOF -/comain -/configure -/common.mk -/config.mk -/src/include/config.h -/build -EOF -if test -e .git; then error 2 "Already a git repo (.git exist)"; fi -git init . -git add . .gitignore -git commit --message="Initial commit: just init the (empty) repo" - -echo "done." +"$(dirname $0)"/initrepo && "$(dirname $0)"/initprj diff --git a/initprj b/initprj new file mode 100755 index 0000000..ddd4240 --- /dev/null +++ b/initprj @@ -0,0 +1,174 @@ +#!/bin/sh + +if ! test -d meta; then + echo "Directory 'meta' not found" >&2 + exit 2 +fi + +if ! test -d .git; then + echo "Repo (.git) not found -- use 'initrepo' first" >&2 + exit 2 +fi + +name=$(cat meta/name) + +. "$(dirname $0)"/libcomain + +if test ! -d comain; then + error 2 "Directory 'comain' not found" +fi + +site=$(cat meta/site) +sp=$((52 - ${#name} - ${#site})) +sp="$(printf "%${sp}s")" +prefix=$(sanitize $name) +year=$(date +%Y) + +run cp -a comain/meta/deps.tpl/skalibs meta/deps +run cp -a comain/meta/deps.tpl/limb meta/deps + +run mkdir src/$name +run touch src/$name/+skalibs +run touch src/$name/+limb +run cat > src/$name/$name.c <<EOF +/* This file is part of $name$sp$site + * Copyright (C) 2023 Olivier Brunel jjk@jjacky.com */ +/* SPDX-License-Identifier: GPL-2.0-only */ +#include <limb/autoopt.h> +#include <limb/exitcode.h> +#include <limb/loadopt.h> +#include <limb/output.h> +#include "config.h" + +const char *PROG = "$name"; + +enum { + OPTID_DEBUG = OPTID_FIRST, + OPTID_VERSION, +}; + +static void +parse_cmdline(int argc, const char *argv[], const char *file, const char *section) +{ + const char usage[] = "[-h] [OPTION..]"; + const struct option options[] = { + OPTION_ARG_OPT( 0 , "debug", 0, OPTID_DEBUG), + OPTION_ARG_NONE('h', "help", OPT_SKIP, OPTID_SHORTOPT), + OPTION_ARG_REQ( 'O', "log-file", 0, OPTID_SHORTOPT), + OPTION_ARG_NONE('q', "quiet", 0, OPTID_SHORTOPT), + OPTION_ARG_NONE('v', "verbose", 0, OPTID_SHORTOPT), + OPTION_ARG_NONE( 0 , "version", 0, OPTID_VERSION), + LOADOPT_DONE + }; + struct loadopt lo = { 0 }; + + int c; + while ((c = loadopt(argc, argv, options, file, section, 0, &lo))) switch (c) { + case OPTID_DEBUG: + if (!autoopt_debug(&options[lo.idx], lo.arg)) + dieusage(EX_USAGE, usage); + break; + case 'h': + diehelp(0, usage, +" --debug [[@[level]:]+FD|FILE] Enable debug output (to FD|FILE)\n" +" -O, --output [@[level]:]+FD|FILE Set output log to FD|FILE\n" +"\n" +" -q, --quiet Enable quiet mode\n" +" -v, --verbose Enable verbose mode\n" +"\n" +" -h, --help Show this help screen and exit\n" +" --version Show version information and exit\n" +); + case 'O': + if (!autoopt_log(&options[lo.idx], lo.arg)) + dieusage(EX_USAGE, usage); + break; + case 'q': + autoopt_quiet(&options[lo.idx], lo.arg); + break; + case 'v': + autoopt_verbose(&options[lo.idx], lo.arg); + break; + case OPTID_VERSION: + dieversion(${prefix}_VERSION, "$year", ${prefix}_CURYEAR, ${prefix}_AUTHOR, ${prefix}_URL, NULL); + case -1: + dieusage(EX_USAGE, usage); + default: + die(EX_SOFTWARE, "unexpected return value ", PUTMSG_INT(c), " from loadopt"); + }; +} + +int +main(int argc, const char *argv[]) +{ + const char config[] = "/etc/$name.conf"; + parse_cmdline(argc, argv, config, NULL); + + out("done."); + return 0; +} +EOF + +run cat > project.mk <<EOF +BINS = $name +EOF + +run mkdir src/doc +run cat > src/doc/$name.1.md <<EOF +% $name +% $name(1) + +# NAME + +$name - $(head -1 meta/desc) + +# SYNOPSIS + +*$name* [*-q*] [*-v*] [*--debug* [[@[\`level\`]:]+\`FD\`|\`FILE\`]] [*-O* [@[\`level\`]:]+\`FD\`|\`FILE\`] + +# OPTIONS + +: *--debug* [[@[\`level\`]:]+\`FD\`|\`FILE\`] +<inc autoopt_debug.md> +<inc autoopt_logdbg_level.md> + +<inc opt_help.md> + +: *-O*, *--log-file* [@[\`level\`]:]+\`FD\`|\`FILE\` +<inc autoopt_log.md> +<inc autoopt_logdbg_level.md> + +: *-q*, *--quiet* +<inc autoopt_quiet.md> + +: *-v*, *--verbose* +<inc autoopt_verbose.md> + +<inc opt_version.md> + +# DESCRIPTION + +*$name* is... + +<inc bugs.md> + +# REPOSITORY + +You can find the latest about *$name* from its official site at $(cat meta/site) +Latest source code can be browsed online at $(cat meta/code); or you can close +its [git](1) repo from $(cat meta/git) + +<inc author.md> +EOF + +run cat >> .gitignore <<EOF +/limb +/$name +EOF +git add . .gitignore +git commit --message="First commit" + +make +./configure + +echo "done." diff --git a/initrepo b/initrepo new file mode 100755 index 0000000..08bab3d --- /dev/null +++ b/initrepo @@ -0,0 +1,57 @@ +#!/bin/sh + +if test -d meta; then + echo "Directory 'meta' already exists" >&2 + exit 2 +fi + +name=$(basename "$(pwd)") +mkdir meta +echo $name > meta/name +echo 0.0.0 > meta/version + +. "$(dirname $0)"/libcomain + +if test ! -d comain; then + error 2 "Directory 'comain' not found" +fi + +run cp -n comain/Makefile Makefile +run cp -n comain/project.mk.tpl project.mk +run mkdir src +run cp -n comain/meta/README.git meta +run echo https://lila.oss/$name > meta/site +run echo git://lila.oss/$name.git > meta/git +run echo https://lila.oss/doc/$name > meta/doc +run echo https://lila.oss/code/$name > meta/code +run cp -n comain/meta/COPYING meta +run cp -n comain/meta/LICENSE meta +run cp -n comain/meta/AUTHORS.tpl meta/AUTHORS +run mkdir meta/deps +run mkdir meta/deps/comain +run touch meta/deps/comain/cpnt +run cp -n comain/meta/version meta/deps/comain/version +run cp -n comain/meta/git meta/deps/comain/git +run mkdir meta/options +for opt in comain/meta/options/*; do + run ln -s ../../$opt meta/options +done +run ln -sf meta/README.git README +run ln -sf meta/AUTHORS +run ln -sf meta/COPYING +run ln -sf meta/HISTORY +if test -e .gitignore; then error 2 "File '.gitignore' already exists"; fi +run cat > .gitignore <<EOF +/comain +/configure +/common.mk +/config.mk +/src/include/config.h +/build +EOF +if test -e .git; then error 2 "Already a git repo (.git exist)"; fi +git init . +git add . .gitignore +git commit --message="Initial commit: just init the (empty) repo" + +echo "done." diff --git a/mkdoc b/mkdoc index 15d8d2d..1b23a8c 100755 --- a/mkdoc +++ b/mkdoc @@ -4,5 +4,6 @@ src="$1" dst="$2" awk 'BEGIN { FS="[ >]" } -{ if ($0 ~ /^<inc (.+)>$/) { system("cat src/doc/include/"$2) } +{ if ($0 ~ /^<inc (.+)>$/) { system("test -e src/doc/include/"$2" \ + && cat src/doc/include/"$2" || cat comain/src/doc/include/"$2) } else { print } } ' "$src" > "$dst" diff --git a/src/doc/include/author.md b/src/doc/include/author.md new file mode 100644 index 0000000..99249d3 --- /dev/null +++ b/src/doc/include/author.md @@ -0,0 +1,3 @@ +# AUTHOR + +Olivier Brunel <jjk@jjacky.com> diff --git a/src/doc/include/autoopt_debug.md b/src/doc/include/autoopt_debug.md new file mode 100644 index 0000000..3007873 --- /dev/null +++ b/src/doc/include/autoopt_debug.md @@ -0,0 +1,6 @@ +:: Enable debug output or, when an argument is specified, set up debug output +:: to the specified file, which will be opened in append mode, or file +:: descriptor if prefixed with a plus sign (`+`). In such a case, it must be a +:: valid file descriptor opened for writing. +:: To use a file whose name begins with a plus sign, simply use 2 plus signs at +:: the beginning. diff --git a/src/doc/include/autoopt_log.md b/src/doc/include/autoopt_log.md new file mode 100644 index 0000000..b6dec28 --- /dev/null +++ b/src/doc/include/autoopt_log.md @@ -0,0 +1,6 @@ +:: Duplicate all output (everything written to *stdout* and *stderr*) to the +:: specified file, which will be opened in append mode, or file descriptor if +:: prefixed with a plus sign (`+`). In such a case, it must be a valid file +:: descriptor opened for writing. +:: To use a file whose name begins with a plus sign, simply use 2 plus signs at +:: the beginning. diff --git a/src/doc/include/autoopt_logdbg_level.md b/src/doc/include/autoopt_logdbg_level.md new file mode 100644 index 0000000..5f26c5b --- /dev/null +++ b/src/doc/include/autoopt_logdbg_level.md @@ -0,0 +1,6 @@ +:: +:: Additionally, you can set the output's level by prefixing the argument with +:: at at-sign (`@`), a level name, and a colon (`:`). Leaving out the level +:: name (i.e. using `@:` as prefix) will bump up the default level. +:: Valid level names are: *silent*, *quiet*, *normal*, *verbose*, *debug*, and +:: *maximum*, and partial names are accepted. diff --git a/src/doc/include/autoopt_quiet.md b/src/doc/include/autoopt_quiet.md new file mode 100644 index 0000000..0f567b3 --- /dev/null +++ b/src/doc/include/autoopt_quiet.md @@ -0,0 +1 @@ +:: Bump output level down by one level (unless it is already *silent*). diff --git a/src/doc/include/autoopt_verbose.md b/src/doc/include/autoopt_verbose.md new file mode 100644 index 0000000..87b73da --- /dev/null +++ b/src/doc/include/autoopt_verbose.md @@ -0,0 +1 @@ +:: Raise output level up by one level (unless it is already *maximum*). diff --git a/src/doc/include/bugs.md b/src/doc/include/bugs.md new file mode 100644 index 0000000..1d5a815 --- /dev/null +++ b/src/doc/include/bugs.md @@ -0,0 +1,6 @@ +# BUGS + +They're probably crawling somewhere in there... if you happen to catch one, (or +more) report it and I'll do my best to squash it. Patches welcome! ;-) + +Such reports (and patches) can simply be sent by email directly. diff --git a/src/doc/include/opt_help.md b/src/doc/include/opt_help.md new file mode 100644 index 0000000..2fa4ba3 --- /dev/null +++ b/src/doc/include/opt_help.md @@ -0,0 +1,2 @@ +: *-h*, *--help* +:: Show help screen and exit. diff --git a/src/doc/include/opt_version.md b/src/doc/include/opt_version.md new file mode 100644 index 0000000..a5ea86e --- /dev/null +++ b/src/doc/include/opt_version.md @@ -0,0 +1,2 @@ +: *--version* +:: Show version information and exit.