-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen-dict
More file actions
executable file
·111 lines (96 loc) · 2.01 KB
/
gen-dict
File metadata and controls
executable file
·111 lines (96 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/sh
# Copyright 2019, by J. Richard Barnette. All Rights Reserved.
cd $(dirname $0)
MODE=gen
FILE=bootstrap/initdict.c
META=meta
usage() {
cat <<END >&2
usage: $(basename $0) [ options ] target-type
available options:
-l list the file-order on stdout
-s list the input source files on stdout
-g (default) write generated output to stdout
-b generate new $FILE and rebuild bootstrap/forth
-t test changes; diff generated output against current file
-n generate no output; allow errors to show
-r reset $FILE from git, rebuild, then regenerate
-f specify name of the output file; default is $FILE
END
exit 1
}
# option -l
# list the file-order on stdout
list() {
for f in "$@"
do
echo $f
done
}
# option -g (default)
# generate initdict.c stdout
gen() {
cat <<END_HEAD
/*
* Copyright $(date +%Y), by J. Richard Barnette. All Rights Reserved.
*/
/* This file was automatically generated by "${GENCMD}" */
END_HEAD
cat "$@" | bootstrap/forth
}
# option -b
# generate new initdict.c and rebuild bootstrap/forth
build() {
gen "$@" >$FILE
cd bootstrap
make
}
# option -t
# test changes; diff generated output against current file
changes() {
gen "$@" | diff $FILE -
}
# option -n
# generate no output; allow errors to show
dry_run() {
gen "$@" >/dev/null
}
# option -r
# rebuild bootstrap/forth using original initdict.c, then regenerate
regen() {
cd bootstrap
git checkout initdict.c
make
cd ..
gen "$@" >$FILE
}
while getopts gbtlnsrf: opt
do
case $opt in
l) MODE=list ;;
s) MODE=cat ;;
g) MODE=gen ;;
b) MODE=build ;;
t) MODE=changes ;;
n) MODE=dry_run ;;
r) MODE=regen ;;
f) FILE=$OPTARG ;;
\?) usage ;;
esac
done
shift $(( OPTIND - 1 ))
if [ $# -eq 1 ]
then
META="$1"
elif [ $# -gt 1 ]
then
usage
fi
GENCMD="$(basename $0) $META"
FILEORDER="forth/$META/file-order"
if [ ! -f $FILEORDER ]
then
echo "$FILEORDER: no file" >&2
usage
fi
$MODE $(sed 's/#.*//' $FILEORDER)