author | František Kučera <franta-hg@frantovo.cz> |
Tue, 22 Oct 2019 22:01:17 +0200 | |
branch | v_0 |
changeset 35 | eafffeea6a3e |
parent 29 | b3d1a671315b |
permissions | -rwxr-xr-x |
16
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
#!/bin/bash |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
|
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
# Relational pipes |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
# Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info) |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
# |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
# This program is free software: you can redistribute it and/or modify |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
# it under the terms of the GNU General Public License as published by |
35
eafffeea6a3e
fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
8 |
# the Free Software Foundation, version 3 of the License. |
16
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
# |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
# This program is distributed in the hope that it will be useful, |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
# GNU General Public License for more details. |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
# |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
# You should have received a copy of the GNU General Public License |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
|
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
|
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
# This is a simple helper script (/usr/bin/awk wrapper) for debugging the relpipe-tr-awk. |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
20 |
# Captures STDIO and ARGS to log files. |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
# Add this directory to the $PATH in order to use this wrapper script. |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
# |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
# Notes: |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
# - if multiple relations are processed, only the last one will stay in the log files (can be solved by adding PID to the log path). |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
# - if no relations are processed by the AWK sub-process, the logs will stay unchanged from the last run, although relpipe-tr-awk was executed |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
26 |
|
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
27 |
logDir="/tmp/relpipe-tr-awk/"; |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
28 |
|
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
29 |
mkdir -p "$logDir"; |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
|
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
formatArgsTxt() { |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
for a in "$@"; do |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
33 |
echo -e "\e[32m>>> arg >>>\e[39m"; # or use lolcat |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
34 |
echo "$a"; |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
35 |
echo -e "\e[32m<<< arg <<<\e[39m"; |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
36 |
done |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
37 |
} |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
|
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
39 |
formatArgsTabular() { |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
40 |
i=0; |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
41 |
for a in "$@"; do |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
42 |
echo "$a" | while read a; do |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
43 |
printf '%s\x0%s\x0' "$i" "$a"; |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
44 |
done; |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
45 |
((i++)); |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
46 |
done | relpipe-in-cli generate-from-stdin args 2 i integer value string | relpipe-out-tabular |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
47 |
} |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
48 |
|
27
86d8bbc99e7b
check exit codes of child processes
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
49 |
realAWK() { |
86d8bbc99e7b
check exit codes of child processes
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
50 |
/usr/bin/awk "$@" |
86d8bbc99e7b
check exit codes of child processes
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
51 |
echo "$?" > "$logDir/awk-status.log" |
86d8bbc99e7b
check exit codes of child processes
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
52 |
} |
86d8bbc99e7b
check exit codes of child processes
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
53 |
|
16
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
54 |
formatArgsTxt "$@" > "$logDir/awk-args.log"; |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
55 |
|
27
86d8bbc99e7b
check exit codes of child processes
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
56 |
tee "$logDir/awk-stdin.log" | realAWK "$@" 2> "$logDir/awk-stderr.log" | tee "$logDir/awk-stdout.log"; |
86d8bbc99e7b
check exit codes of child processes
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
57 |
|
86d8bbc99e7b
check exit codes of child processes
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
58 |
cat "$logDir/awk-stderr.log" >&2; |
86d8bbc99e7b
check exit codes of child processes
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
59 |
exit `cat "$logDir/awk-status.log"`; |
16
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
60 |
|
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
61 |
# Use e.g. GNU Screen with four windows to watch files: |
29
b3d1a671315b
AWK escaping and unescaping functions
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
62 |
# tabs 2 |
16
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
63 |
# watchFile() { while inotifywait "$1" &>/dev/null ; do clear; cat "$1" ; done; } |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
64 |
# watchFile "/tmp/relpipe-tr-awk/awk-args.log" |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
65 |
# watchFile "/tmp/relpipe-tr-awk/awk-stdin.log" |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
66 |
# watchFile "/tmp/relpipe-tr-awk/awk-stdout.log" |
4e8fe4cc70f0
awk wrapper script for debugging
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
67 |
# watchFile "/tmp/relpipe-tr-awk/awk-stderr.log" |