996
|
1 #!/usr/bin/env bash
|
|
2 # -*- coding: utf-8 -*-
|
|
3 ###########################################################################
|
|
4 # #
|
|
5 # cfunge - A standard-conforming Befunge93/98/109 interpreter in C. #
|
|
6 # Copyright (C) 2008-2009 Arvid Norlander #
|
|
7 # #
|
|
8 # This program is free software: you can redistribute it and/or modify #
|
|
9 # it under the terms of the GNU General Public License as published by #
|
|
10 # the Free Software Foundation, either version 3 of the License, or #
|
|
11 # (at the proxy's option) any later version. Arvid Norlander is a #
|
|
12 # proxy who can decide which future versions of the GNU General Public #
|
|
13 # License can be used. #
|
|
14 # #
|
|
15 # This program is distributed in the hope that it will be useful, #
|
|
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
|
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
|
18 # GNU General Public License for more details. #
|
|
19 # #
|
|
20 # You should have received a copy of the GNU General Public License #
|
|
21 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
|
22 # #
|
|
23 ###########################################################################
|
|
24
|
|
25 # Generate the fingerprint list
|
|
26 # This must be run from top source directory.
|
|
27
|
|
28 # Error to fail with for old bash.
|
|
29 fail_old_bash() {
|
|
30 echo "Sorry your bash version is too old!"
|
|
31 echo "You need at least version 3.2.10 of bash"
|
|
32 echo "Please install a newer version:"
|
|
33 echo " * Either use your distro's packages"
|
|
34 echo " * Or see http://www.gnu.org/software/bash/"
|
|
35 exit 2
|
|
36 }
|
|
37
|
|
38 # Check bash version. We need at least 3.2.10
|
|
39 # Lets not use anything like =~ here because
|
|
40 # that may not work on old bash versions.
|
|
41 if [[ "${BASH_VERSINFO[0]}${BASH_VERSINFO[1]}" -lt 32 ]]; then
|
|
42 fail_old_bash
|
|
43 elif [[ "${BASH_VERSINFO[0]}${BASH_VERSINFO[1]}" -eq 32 && "${BASH_VERSINFO[2]}" -lt 10 ]]; then
|
|
44 fail_old_bash
|
|
45 fi
|
|
46
|
|
47 if [[ ! -d src/fingerprints ]]; then
|
|
48 echo "ERROR: Run from top source directory please." >&2
|
|
49 exit 1
|
|
50 fi
|
|
51
|
|
52 set -e
|
|
53
|
|
54 if [[ ! -f tools/fprint_funcs.sh ]]; then
|
|
55 echo "ERROR: Couldn't find tools/fprint_funcs.sh." >&2
|
|
56 exit 1
|
|
57 fi
|
|
58 source tools/fprint_funcs.sh
|
|
59 if [[ $? -ne 0 ]]; then
|
|
60 echo "ERROR: Couldn't load tools/fprint_funcs.sh." >&2
|
|
61 exit 1
|
|
62 fi
|
|
63
|
|
64 addtolist() {
|
|
65 echo "$1" >> "fingerprints.h"
|
|
66 }
|
|
67 addtoman() {
|
|
68 echo "$1" >> "doc/cfunge-man-fingerprints.in"
|
|
69 }
|
|
70
|
|
71 GENERATE_MAN=
|
|
72
|
|
73 # This is used internally to generate a list for man page.
|
|
74 if [[ $# -gt 0 ]]; then
|
|
75 case $1 in
|
|
76 "-man")
|
|
77 GENERATE_MAN=yes
|
|
78 ;;
|
|
79 *)
|
|
80 die "Invalid cmd line parameter, normally don't use any."
|
|
81 ;;
|
|
82 esac
|
|
83 fi
|
|
84
|
|
85 # This is to allow sorted list even with aliases...
|
|
86 # I hate aliases...
|
|
87 ENTRIES=()
|
|
88 if [[ $GENERATE_MAN ]]; then
|
|
89 MANENTRY1=()
|
|
90 MANENTRY2=()
|
|
91 else
|
|
92 ENTRYL1_cond=()
|
|
93 ENTRYL2=()
|
|
94 ENTRYL3=()
|
|
95 ENTRYL4=()
|
|
96 ENTRYL5_cond=()
|
|
97 fi
|
|
98
|
|
99 # $1 = fprint name
|
|
100 genfprintinfo() {
|
|
101 local FPRINT="$1"
|
|
102
|
|
103 # Variables
|
|
104 local fp_URL fp_SAFE fp_OPCODES fp_DESCRIPTION
|
|
105 local fp_F109_URI fp_CONDITION
|
|
106 local fp_ALIASES
|
|
107 local fp_OPCODE_NAMES fp_OPCODE_DESC
|
|
108
|
|
109 progress "Processing $FPRINT"
|
|
110
|
|
111 checkfprint "$FPRINT"
|
|
112
|
|
113 if [[ ! -e $FPRINT ]]; then
|
|
114 die "A fingerprint called $FPRINT is not yet generated!"
|
|
115 fi
|
|
116
|
|
117 progresslvl2 "Looking for spec file"
|
|
118
|
|
119 if [[ -f "${FPRINT}.spec" ]]; then
|
|
120 statuslvl2 "Good, spec file found."
|
|
121 else
|
|
122 die "Sorry you need a spec file for the fingerprint. It should be placed at src/fingerprints/${FPRINT}.spec"
|
|
123 fi
|
|
124 parse_spec "${FPRINT}"
|
|
125
|
|
126 progresslvl2 "Generating data for list"
|
|
127 local FPRINTHEX='0x'
|
|
128 for (( i = 0; i < ${#FPRINT}; i++ )); do
|
|
129 printf -v hex '%x' "'${FPRINT:$i:1}"
|
|
130 FPRINTHEX+="$hex"
|
|
131 done
|
|
132 ENTRIES+=( "$FPRINTHEX" )
|
|
133
|
|
134 if [[ $GENERATE_MAN ]]; then
|
|
135 MANENTRY1[$FPRINTHEX]="${FPRINT}"
|
|
136 # Fix this if we need to escape anything else.
|
|
137 MANENTRY2[$FPRINTHEX]="${fp_DESCRIPTION}"
|
|
138 if [[ "${fp_SAFE}" == "false" ]]; then
|
|
139 MANENTRY2[$FPRINTHEX]+=" (not available in sandbox mode)"
|
|
140 fi
|
|
141 else
|
|
142 [[ "$fp_CONDITION" ]] && ENTRYL1_cond[$FPRINTHEX]="#if $fp_CONDITION"
|
|
143 ENTRYL2[$FPRINTHEX]=" // ${FPRINT} - ${fp_DESCRIPTION}"
|
|
144 ENTRYL3[$FPRINTHEX]=" { .fprint = ${FPRINTHEX}, .uri = ${fp_F109_URI}, .loader = &finger_${FPRINT}_load, .opcodes = \"${fp_OPCODES}\","
|
|
145 ENTRYL4[$FPRINTHEX]=" .url = \"${fp_URL}\", .safe = ${fp_SAFE} },"
|
|
146 [[ "$fp_CONDITION" ]] && ENTRYL5_cond[$FPRINTHEX]="#endif"
|
|
147 statuslvl2 "Done"
|
|
148 if [[ ${!fp_ALIASES[*]} ]]; then
|
|
149 progresslvl2 "Generating aliases..."
|
|
150 local myalias
|
|
151 for myalias in "${fp_ALIASES[@]}"; do
|
|
152 checkfprint "$myalias"
|
|
153 local ALIASHEX='0x'
|
|
154 for (( i = 0; i < ${#myalias}; i++ )); do
|
|
155 printf -v hex '%x' "'${myalias:$i:1}"
|
|
156 ALIASHEX+="$hex"
|
|
157 done
|
|
158 ENTRIES+=("$ALIASHEX")
|
|
159 [[ "$fp_CONDITION" ]] && ENTRYL1_cond[$ALIASHEX]="#if $fp_CONDITION"
|
|
160 ENTRYL2[$ALIASHEX]=" // ${myalias} - Alias for ${FPRINT} - ${fp_DESCRIPTION}"
|
|
161 ENTRYL3[$ALIASHEX]=" { .fprint = ${ALIASHEX}, .uri = ${fp_F109_URI}, .loader = &finger_${myalias}_load, .opcodes = \"${fp_OPCODES}\","
|
|
162 ENTRYL4[$ALIASHEX]=" .url = \"${fp_URL}\", .safe = ${fp_SAFE} },"
|
|
163 [[ "$fp_CONDITION" ]] && ENTRYL5_cond[$ALIASHEX]="#endif"
|
|
164 done
|
|
165 fi
|
|
166 fi
|
|
167 }
|
|
168
|
|
169 cd "src/fingerprints/" || die "change directory failed"
|
|
170
|
|
171 progress "Finding fingerprint list"
|
|
172 SPECS=( *.spec )
|
|
173
|
|
174 FPRINTS=()
|
|
175
|
|
176 for spec in "${SPECS[@]}"; do
|
|
177 FPRINTS+=( ${spec%.spec} )
|
|
178 done
|
|
179
|
|
180 if [[ $GENERATE_MAN ]]; then
|
|
181 for fprint in "${FPRINTS[@]}"; do
|
|
182 genfprintinfo "$fprint"
|
|
183 done
|
|
184 cd ../.. || die "change directory to top src dir failed."
|
|
185 echo "[FINGERPRINTS]" > doc/cfunge-man-fingerprints.in
|
|
186 addtoman "Short descriptions of implemented fingerprints:"
|
|
187 # I really hate aliases...
|
|
188 SORTEDENTRIES=( $(IFS=$'\n'; echo "${ENTRIES[*]}" | sort -n) )
|
|
189 for entry in "${SORTEDENTRIES[@]}"; do
|
|
190 addtoman ".TP"
|
|
191 addtoman "${MANENTRY1[$entry]}"
|
|
192 addtoman "${MANENTRY2[$entry]}"
|
|
193 done
|
|
194 addtoman ".LP"
|
|
195 addtoman "For more details please see the specs for each fingerprint."
|
|
196 addtoman "In cases of undefined behaviour in fingerprints, cfunge mostly tries to do the"
|
|
197 addtoman "same thing as CCBI."
|
|
198
|
|
199 status "Man page generated"
|
|
200 exit 0
|
|
201 fi
|
|
202
|
|
203 progress "Creating list file"
|
|
204 cat > "fingerprints.h" << EOF
|
|
205 /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
|
|
206 *
|
|
207 * cfunge - A standard-conforming Befunge93/98/109 interpreter in C.
|
|
208 * Copyright (C) 2008-2009 Arvid Norlander <anmaster AT tele2 DOT se>
|
|
209 *
|
|
210 * This program is free software: you can redistribute it and/or modify
|
|
211 * it under the terms of the GNU General Public License as published by
|
|
212 * the Free Software Foundation, either version 3 of the License, or
|
|
213 * (at the proxy's option) any later version. Arvid Norlander is a
|
|
214 * proxy who can decide which future versions of the GNU General Public
|
|
215 * License can be used.
|
|
216 *
|
|
217 * This program is distributed in the hope that it will be useful,
|
|
218 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
219 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
220 * GNU General Public License for more details.
|
|
221 *
|
|
222 * You should have received a copy of the GNU General Public License
|
|
223 * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
224 */
|
|
225 // WARNING THIS FILE IS AUTO GENERATED DON'T CHANGE
|
|
226 // It was generated by tools/gen_fprint_list.sh
|
|
227 // Rerun the tool to update this list
|
|
228 #ifndef MANAGER_INTERNAL
|
|
229 # error "This is for use in manager.c only"
|
|
230 #endif
|
|
231
|
|
232 #ifndef FUNGE_HAD_SRC_FINGERPRINTS_FINGERPRINTS_H
|
|
233 #define FUNGE_HAD_SRC_FINGERPRINTS_FINGERPRINTS_H
|
|
234
|
|
235 #include "../global.h"
|
|
236
|
|
237 #include <stdbool.h>
|
|
238 #include <stdint.h>
|
|
239
|
|
240 EOF
|
|
241
|
|
242 for fprint in "${FPRINTS[@]}"; do
|
|
243 addtolist "#include \"${fprint}/${fprint}.h\""
|
|
244 done
|
|
245
|
|
246 cat >> "fingerprints.h" << EOF
|
|
247
|
|
248 typedef struct s_ImplementedFingerprintEntry {
|
|
249 const funge_cell fprint; /**< Fingerprint. */
|
|
250 const char * uri; /**< URI, used for Funge-109. */
|
|
251 const fingerprintLoader loader; /**< Loader function pointer. */
|
|
252 const char * opcodes; /**< Sorted string with all implemented opcodes. */
|
|
253 const char * url; /**< URL, used to show links for more info about fingerprints. */
|
|
254 const bool safe; /**< If true, this fingerprint is safe in sandbox mode. */
|
|
255 } ImplementedFingerprintEntry;
|
|
256
|
|
257 // Implemented fingerprints
|
|
258 // NOTE: Keep sorted!
|
|
259 // Also note that this table is processed by scripts, so keep the .loader and
|
|
260 // .opcodes entries on the same line! As well as in current format.
|
|
261 static const ImplementedFingerprintEntry ImplementedFingerprints[] = {
|
|
262 EOF
|
|
263
|
|
264 for fprint in "${FPRINTS[@]}"; do
|
|
265 genfprintinfo "$fprint"
|
|
266 done
|
|
267 # I really hate aliases...
|
|
268 SORTEDENTRIES=( $(IFS=$'\n'; echo "${ENTRIES[*]}" | sort -n) )
|
|
269 for entry in "${SORTEDENTRIES[@]}"; do
|
|
270 [[ ${ENTRYL1_cond[$entry]} ]] && addtolist "${ENTRYL1_cond[$entry]}"
|
|
271 addtolist "${ENTRYL2[$entry]}"
|
|
272 addtolist "${ENTRYL3[$entry]}"
|
|
273 addtolist "${ENTRYL4[$entry]}"
|
|
274 [[ ${ENTRYL5_cond[$entry]} ]] && addtolist "${ENTRYL5_cond[$entry]}"
|
|
275 done
|
|
276
|
|
277
|
|
278 cat >> "fingerprints.h" << EOF
|
|
279 };
|
|
280
|
|
281 #endif
|
|
282 EOF
|
|
283
|
|
284 status "Done"
|