Use @BAKE and @SHAKE, add dry run to @SHAKE

This commit is contained in:
Emil 2023-10-16 22:00:21 +00:00
parent b091fc60b2
commit ecc92f5fd9
No known key found for this signature in database
GPG Key ID: 5432DB986FDBCF8A
3 changed files with 22 additions and 21 deletions

3
README
View File

@ -43,7 +43,8 @@ is included under authorization of it's creator. It is not a replacement
for Bake, but it is platform independent in regards to its use of Bash.
Shake is limited in comparison to Bake, the first line including @COMPILECMD.
It supports $@, and $*. It does not support @STOP in any way.
It supports all Name/Arg Extensions, and all options. It does not support
@STOP in any way.
Bake is licensed under the GPLv3, See LICENSE.

22
bake.c
View File

@ -3,11 +3,8 @@
*
* Licensed under the GNU Public License version 3 only, see LICENSE.
*
* For Bake
* @EXEC cc $@ -o $* -std=gnu89 -O2 -Wall -Wextra -Wpedantic -pipe $CFLAGS @STOP
*
* For Shake
* @COMPILECMD cc $@ -o $* -std=gnu89 -O2 -Wall -Wextra -Wpedantic -pipe $CFLAGS
* @BAKE cc $@ -o $* -std=gnu89 -O2 -Wall -Wextra -Wpedantic -pipe $CFLAGS @STOP
* @SHAKE cc $@ -o $* -std=gnu89 -O2 -Wall -Wextra -Wpedantic -pipe $CFLAGS
*/
#include <assert.h>
@ -26,16 +23,14 @@
/* Require space after COMPILECMD/EXEC and before STOP (no space required around newline) */
#define REQUIRE_SPACE
/* May be be left undefined, comes second */
/* #define OTHER_START "@COMPILECMD" */
#define START "@EXEC"
#define START "@BAKE"
#define STOP "@STOP"
#define HELP \
"target-file [arguments ...]\n" \
"Use the format `@EXEC cmd ...' within the target-file, this will execute the\n" \
"Use the format `@BAKE cmd ...' within the target-file, this will execute the\n" \
"rest of line, or if found within the file, until the @STOP marker. You may use\n" \
"@COMPILECMD instead of @EXEC. Whitespace is required after and before both\n" \
"@COMPILECMD instead of @BAKE. Whitespace is required after and before both\n" \
"operators always.\n"
#define DESC \
@ -148,13 +143,6 @@ find_region(map_t m) {
char * buf = NULL;
char * start, * stop;
start = find(START, m.str, m.str + m.len);
#ifdef OTHER_START
if (!start) {
start = find(OTHER_START, m.str, m.str + m.len);
start = (char *) /* DON'T QUESTION IT */
((ptrdiff_t) (start - strlen(START) + strlen(OTHER_START)) * (start != 0));
}
#endif /* OTHER_START */
if (start) {
start += strlen(START);
#ifdef REQUIRE_SPACE

14
shake
View File

@ -7,7 +7,7 @@ GREEN='\033[32m'
BOLD='\033[1m'
NORMAL='\033[0m'
MARKNAME="@COMPILECMD"
MARKNAME="@SHAKE"
MARK="${MARKNAME} "
MARKSTR="${BLUE}${MARKNAME}${NORMAL}"
@ -35,6 +35,16 @@ if [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
exit 0
fi
run=1
if [[ $1 == "-n" ]] || [[ $1 == "--dry-run" ]]; then
if [[ $# -lt 2 ]]; then
usage
exit 1
fi
run=0
shift 1
fi
input_file=$1
shift 1
@ -51,8 +61,10 @@ line=${line//\$+/$@}
if [[ -n $line ]]; then
command="${line#*${MARK}}"
echo "Exec: $command"
if [[ $run -eq 1 ]]; then
echo "Output:"
eval "$command"
fi
else
echo -e "${MARKSTR} is not defined." >&2
fi