mirror of
https://git.lain.church/bake/bake.git
synced 2025-06-08 23:06:43 +00:00
Awake! Documented!
This commit is contained in:
parent
ece6d124cd
commit
51e1803bc3
13
README
Normal file → Executable file
13
README
Normal file → Executable file
@ -54,6 +54,8 @@ bootstrapper. The modified version includes all features of Bake with
|
|||||||
the exceptions of multi-line commands. It is not a general
|
the exceptions of multi-line commands. It is not a general
|
||||||
replacement for Bake.
|
replacement for Bake.
|
||||||
|
|
||||||
|
Shake doesn't support multi-line commands.
|
||||||
|
|
||||||
Changelog
|
Changelog
|
||||||
|
|
||||||
Bake was created on 2023/09/13, and complete as of 2024/03/02.
|
Bake was created on 2023/09/13, and complete as of 2024/03/02.
|
||||||
@ -62,3 +64,14 @@ Bake was created on 2023/09/13, and complete as of 2024/03/02.
|
|||||||
|
|
||||||
Lex. As adviced by the original creator, I learned and implemented a
|
Lex. As adviced by the original creator, I learned and implemented a
|
||||||
Bake with lex. It's fully featured, and has new stuff.
|
Bake with lex. It's fully featured, and has new stuff.
|
||||||
|
|
||||||
|
2024-10-24 - Awake
|
||||||
|
|
||||||
|
Egor (some dead guy) made a AWK implementation of Bake, it's POSIX.
|
||||||
|
It doesn't support multi-line, expunge, parses options after filename,
|
||||||
|
or changing directory to file's directory - it's compatible with Bake
|
||||||
|
otherwise.
|
||||||
|
|
||||||
|
cd /dir/of/file; awake file
|
||||||
|
|
||||||
|
See ./awake --help
|
||||||
|
15
awake
15
awake
@ -1,7 +1,8 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# vim:set ft=awk:
|
# vim:set ft=awk:
|
||||||
|
# Written by Egor, modified for compatibility by Emil.
|
||||||
# SPDX-License-Identifier: Unlicense
|
# SPDX-License-Identifier: Unlicense
|
||||||
"exec" "${AWK:-awk}" "-f" "$0" "--" "$@" && 0
|
"exec" "${AWK:-awk}" "-f" "$(basename $0)" "--" "$@" && 0
|
||||||
function usage() {
|
function usage() {
|
||||||
print "awake: usage: awake [-nl] [-s num] filename [args...]"
|
print "awake: usage: awake [-nl] [-s num] filename [args...]"
|
||||||
exit
|
exit
|
||||||
@ -68,13 +69,15 @@ BEGIN {
|
|||||||
if (list) {
|
if (list) {
|
||||||
print bakenum": "$0
|
print bakenum": "$0
|
||||||
} else if (select == bakenum) {
|
} else if (select == bakenum) {
|
||||||
gsub(/@FILENAME/, filename)
|
gsub(/\$@|@(FILE|FILENAME|NAME)/, filename)
|
||||||
gsub(/@NAME/, filename)
|
gsub(/\$\*|@SHORT/, shortname)
|
||||||
gsub(/@SHORT/, shortname)
|
gsub(/\$\+|@ARGS/, extraargs)
|
||||||
gsub(/@ARGS/, extraargs)
|
gsub(/@RECURS/, ARGV[0])
|
||||||
print
|
print "Awake: " $0
|
||||||
|
printf "Output: "
|
||||||
if (!dryrun) {
|
if (!dryrun) {
|
||||||
system($0)
|
system($0)
|
||||||
|
print ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
41
bake.l
Normal file → Executable file
41
bake.l
Normal file → Executable file
@ -1,5 +1,4 @@
|
|||||||
/* cbake.l @BAKE flex @FILE && cc -Wall -Wextra -std=c99 -D_GNU_SOURCE -o @SHORT lex.yy.c @ARGS @STOP */
|
/* @BAKE flex @FILE && cc -Wall -Wextra -Wwrite-strings -std=c99 -D_GNU_SOURCE -o @SHORT lex.yy.c @ARGS @STOP */
|
||||||
/* expunge @BAKE flex @FILE && cc -Wall -Wextra -std=c99 -D_GNU_SOURCE -o @{@SHORT} lex.yy.c @ARGS @STOP */
|
|
||||||
/* Licensed under the public domain. */
|
/* Licensed under the public domain. */
|
||||||
|
|
||||||
%{
|
%{
|
||||||
@ -25,7 +24,6 @@ int line = 1, expunge_depth, first_nl, tmpline;
|
|||||||
extern void root(char * filename);
|
extern void root(char * filename);
|
||||||
extern void args(int n, int rest);
|
extern void args(int n, int rest);
|
||||||
extern void shorten(char * filename, int n);
|
extern void shorten(char * filename, int n);
|
||||||
extern void pipeopen(char * filename, char * mode);
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
SPACE [ \t\r\v\f]
|
SPACE [ \t\r\v\f]
|
||||||
@ -99,6 +97,7 @@ MACROS ({CMD}|@STOP|{FILENAME}|@SHORT|@ARGS|@LINE|@RECURS|$@|$*|$+|@\{)
|
|||||||
%%
|
%%
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
# define RED "\033[91m"
|
# define RED "\033[91m"
|
||||||
# define GREEN "\033[92m"
|
# define GREEN "\033[92m"
|
||||||
@ -125,19 +124,33 @@ void shorten(char * filename, int n) {
|
|||||||
char * end = filename + strlen(filename);
|
char * end = filename + strlen(filename);
|
||||||
while (n && (end = memrchr(filename, '.', end - filename))) { --n; }
|
while (n && (end = memrchr(filename, '.', end - filename))) { --n; }
|
||||||
if (!end) {
|
if (!end) {
|
||||||
fprintf(stderr, "<SHORTEN> context error: Argument out of range.\n");
|
fprintf(stderr, "%s: Cannot shorten '%s' any further, aborting due to paranoia\n", av0, filename);
|
||||||
/* Ensures consistency. @SHORT will always return *something* that isn't filename */
|
abort();
|
||||||
STRING("idiot");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
FWRITE(filename, end - filename);
|
FWRITE(filename, end - filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
void help(void) { fprintf(stderr, g_color ? BOLD "%s" RESET : "%s", "see bake(1) - \"Buy high. Sell low.\"\n"); }
|
void help(void) { fprintf(stderr, g_color ? BOLD "%s" RESET : "%s", "see bake(1) - \"Buy high. Sell low.\"\n"); }
|
||||||
|
|
||||||
void pipeopen(char * filename, char * mode) {
|
FILE * pipeopen(char * filename, char * mode) {
|
||||||
g_pipe = popen(filename, mode);
|
FILE * pipe = popen(filename, mode);
|
||||||
if (!g_pipe) { fprintf(stderr, "%s: <g_pipe> %s\n", av0, strerror(errno)); exit(1); }
|
if (!pipe) { fprintf(stderr, "%s: <pipeopen> %s\n", av0, strerror(errno)); exit(1); }
|
||||||
|
return pipe;
|
||||||
|
}
|
||||||
|
|
||||||
|
void print(FILE * fp, char * color_prefix, char * format, ...) {
|
||||||
|
va_list ap;
|
||||||
|
size_t len = strlen(format);
|
||||||
|
g_color ? fprintf(fp, "%s%s: ", color_prefix, av0)
|
||||||
|
: fprintf(fp, "%s: ", av0);
|
||||||
|
va_start(ap, format);
|
||||||
|
for (size_t i = 0, f = 0; i < len; ++i) {
|
||||||
|
if (!(format[i] ^ '\033')) {
|
||||||
|
while (format[i] && format[i] != 'm') ++i;
|
||||||
|
} else format[f++] = format[i];
|
||||||
|
}
|
||||||
|
vfprintf(fp, format, ap);
|
||||||
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int ac, char ** av) {
|
int main (int ac, char ** av) {
|
||||||
@ -202,7 +215,8 @@ int main (int ac, char ** av) {
|
|||||||
/* setup pipe and output */
|
/* setup pipe and output */
|
||||||
|
|
||||||
if (run) {
|
if (run) {
|
||||||
pipeopen("/bin/sh -e /dev/stdin", "w");
|
#define pipeopen(a,b) pipeopen((char*)(a), (char*)(b))
|
||||||
|
g_pipe = pipeopen("/bin/sh -e /dev/stdin", "w");
|
||||||
}
|
}
|
||||||
if (g_rm) {
|
if (g_rm) {
|
||||||
g_restore = stdout;
|
g_restore = stdout;
|
||||||
@ -215,7 +229,7 @@ int main (int ac, char ** av) {
|
|||||||
yylex(); fflush(stdout);
|
yylex(); fflush(stdout);
|
||||||
|
|
||||||
if (g_rm) {
|
if (g_rm) {
|
||||||
fputs("\n", g_restore);
|
fputc('\n', g_restore);
|
||||||
stdout = g_restore;
|
stdout = g_restore;
|
||||||
g_pipe = g_expunge;
|
g_pipe = g_expunge;
|
||||||
}
|
}
|
||||||
@ -229,7 +243,8 @@ int main (int ac, char ** av) {
|
|||||||
|
|
||||||
run = pclose(g_pipe); /* repurposed run */
|
run = pclose(g_pipe); /* repurposed run */
|
||||||
if (!g_rm) { putchar('\n'); }
|
if (!g_rm) { putchar('\n'); }
|
||||||
if (run) { fprintf(stderr, "%s: Exit code %d\n", av0, run); }
|
if (run < 0) { fprintf(stderr, "%s: Exit failure\n", av0); }
|
||||||
|
if (run > 0) { fprintf(stderr, "%s: Exit code %d\n", av0, run); }
|
||||||
return run;
|
return run;
|
||||||
out_of_range: fprintf(stderr, "%s: <%d> Out of range\n", av0, g_select); return 1;
|
out_of_range: fprintf(stderr, "%s: <%d> Out of range\n", av0, g_select); return 1;
|
||||||
}
|
}
|
||||||
|
41
install.sh
41
install.sh
@ -1,13 +1,40 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# source install
|
# source install
|
||||||
|
|
||||||
TARGET=${TARGET:-/usr/local}
|
TARGET="${TARGET:-/usr/local}"
|
||||||
INSTALL=${INSTALL:-bake}
|
INSTALL="bake"
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "compiles and installs Bake into /usr/local (or TARGET) in bin/"
|
||||||
|
echo ""
|
||||||
|
echo "--alternatives Includes awake and shake into the build"
|
||||||
|
echo "--target=DIRECTORY Target directory like /usr or /usr/local"
|
||||||
|
echo ""
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
while [ ! -z $1 ]; do
|
||||||
|
case $(echo "$1" | cut -d= -f1) in
|
||||||
|
"--target")
|
||||||
|
TARGET=$(echo "$1" | cut -d= -f2)
|
||||||
|
;;
|
||||||
|
"--alternatives")
|
||||||
|
INSTALL="bake shake awake"
|
||||||
|
;;
|
||||||
|
"--help")
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown option: " $1
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
cd "$(dirname "$(readlink -f $0)")"
|
cd "$(dirname "$(readlink -f $0)")"
|
||||||
|
|
||||||
./shake bake.l -s $@ && \
|
./awake bake.l
|
||||||
mkdir $TARGET/bin $TARGET/man/man1 -p && \
|
mkdir -p "$TARGET/bin" "$TARGET/man/man1"
|
||||||
install -m 755 $INSTALL $TARGET/bin
|
install -m 755 $INSTALL "$TARGET/bin"
|
||||||
|
gzip -c bake.1 > "$TARGET/man/man1/bake.1.gz"
|
||||||
gzip -c bake.1 > $TARGET/man/man1/bake.1.gz
|
|
||||||
|
6
shake
6
shake
@ -1,8 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Originally written by Anon, modified by Emil to better match Bake functionality
|
# Originally written by Anon, modified by Emil to better match Bake.
|
||||||
|
# Please don't use this to compile Bake, use Awake instead.
|
||||||
# Issues: sloooow, fails to handle multi-line statements
|
# Licensed under the public domain.
|
||||||
|
|
||||||
VERSION="20240408"
|
VERSION="20240408"
|
||||||
|
|
||||||
|
0
test.a.txt
Normal file → Executable file
0
test.a.txt
Normal file → Executable file
Loading…
x
Reference in New Issue
Block a user