From af2756ee01fa6b1921c6bcb581817e64c30beb48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Tue, 27 Sep 2022 17:13:45 +0200 Subject: Add a rudimentary CMake script parser --- tools/cmake-dump.awk | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tools/cmake-dump.awk (limited to 'tools/cmake-dump.awk') diff --git a/tools/cmake-dump.awk b/tools/cmake-dump.awk new file mode 100644 index 0000000..d0b68b9 --- /dev/null +++ b/tools/cmake-dump.awk @@ -0,0 +1,24 @@ +# cmake-dump.awk: dump parsed CMake scripts as tables +# +# Copyright (c) 2022, Přemysl Eric Janouch +# SPDX-License-Identifier: 0BSD +# +# Parsed scripts are output in a table, with commands separated using ASCII +# Record Separators, and arguments using Unit Separators. +# +# Example usage: awk -f cmake-parser.awk -f cmake-dump.awk CMakeLists.txt \ +# | sed 'y/\x1F\x1E\t\n/\t\n /' \ +# | sed -n '/^project\t\([^\t]*\).*\tVERSION\t\([^\t]*\).*/{s//\1 \2/p;q;}' + +function sanitize(s) { + if (s ~ /[\x1E\x1F]/) + fatal("conflicting ASCII control characters found in source") + return s +} + +Command { + out = sanitize(Command) + for (i in Args) + out = out "\x1F" sanitize(Args[i]) + printf "%s\x1E", out +} -- cgit v1.2.3