1
0
mirror of https://github.com/gophernicus/gophernicus.git synced 2024-06-16 06:25:23 +00:00

Generate FILETYPES with AWK

It's better suited than the shell for this task.
This commit is contained in:
Augustin Fabre 2020-02-23 19:12:34 +01:00
parent 8bb9a7cf50
commit 8b8a2f75c8
No known key found for this signature in database
GPG Key ID: 99A01AA293FDA435
3 changed files with 15 additions and 23 deletions

View File

@ -65,8 +65,8 @@ src/$(BINARY): $(OBJECTS)
.c.o:
$(CC) -c $(CFLAGS) -DVERSION="\"$(VERSION)\"" -DCODENAME="\"$(CODENAME)\"" -DDEFAULT_ROOT="\"$(ROOT)\"" $< -o $@
src/filetypes.h: src/filetypes.conf
sh src/filetypes.sh < src/filetypes.conf > $@
src/filetypes.h: src/filetypes.conf src/filetypes.awk
awk -f src/filetypes.awk < src/filetypes.conf > $@
src/bin2c: src/bin2c.c
$(CC) src/bin2c.c -o $@

13
src/filetypes.awk Normal file
View File

@ -0,0 +1,13 @@
# Convert filetypes.conf to filetypes.h.
BEGIN {
print "#define FILETYPES \\"
}
/^[^#]/ {
for (i = 2; i <= NF; ++i) {
printf "\t\"%s\", \"%s\", \\\n", $i, $1
}
}
END {
printf "\tNULL, NULL\n"
}

View File

@ -1,21 +0,0 @@
#!/bin/sh
# script for conversion of filetypes.conf into filetypes.h
# (called by Makefile before compilation)
# (2020-1-16 // HB9KNS)
cat <<EOH
/* $outp autogenerated on `date -u` by $0 */
#define FILETYPES \\
EOH
# slurp $inpt and get gopher type and list of extensions
while read gtype exts
do if ! test "$gtype" = "" -o "$gtype" = "#"
# process extensions, removing trailing SPC,
# prepending '"' and appending '","gophertype",' to each,
# and prepending TAB and appending ' \'
then echo $exts | sed -e "s/\([^ ][^ ]*\) */\"\1\",\"$gtype\",/g;s/^/ /;s/\$/ \\\\/"
fi
done
cat <<EOF
NULL, NULL
EOF