Skip to content

Commit 7f1b9f3

Browse files
committed
Add 'bin-graph-all-modes.sh' script
1 parent f820073 commit 7f1b9f3

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

README.org

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ side-by-side with the ANSI-escaped output of =bin-graph=.
9898
# ...
9999
#+end_src
100100

101+
The [[file:scripts/bin-graph-all-modes.sh][bin-graph-all-modes.sh]] script generates all possible binary graphs from an
102+
input file by calling =bin-graph= with different =--mode= arguments.
103+
104+
#+begin_src bash
105+
./scripts/bin-graph-all-modes.sh INPUT
106+
# ...
107+
#+end_src
108+
101109
* Overview of the code
102110

103111
I tried to make each part of the program as modular and independent as possible,

scripts/bin-graph-all-modes.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright 2025 8dcc. All Rights Reserved.
4+
#
5+
# This file is part of bin-graph.
6+
#
7+
# This program is free software: you can redistribute it and/or modify it under
8+
# the terms of the GNU General Public License as published by the Free Software
9+
# Foundation, either version 3 of the License, or (at your option) any later
10+
# version.
11+
#
12+
# This program is distributed in the hope that it will be useful, but WITHOUT
13+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14+
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15+
# details.
16+
#
17+
# You should have received a copy of the GNU General Public License along with
18+
# this program. If not, see <https://www.gnu.org/licenses/>.
19+
#
20+
# -----------------------------------------------------------------------------
21+
#
22+
# Simple script for generating multiple binary graphs from the same file.
23+
set -e
24+
25+
BIN_GRAPH='bin-graph'
26+
27+
if [ $# -ne 1 ]; then
28+
echo "Usage: $(basename "$0") INPUT" 1>&2
29+
exit 1
30+
fi
31+
32+
assert_cmd() {
33+
if [ ! "$(command -v "$1")" ]; then
34+
echo "$(basename "$0"): The '$1' command is not installed." 1>&2
35+
exit 1
36+
fi
37+
}
38+
39+
assert_cmd "$BIN_GRAPH"
40+
41+
input_file="${*: -1}"
42+
43+
# Command-line options for each mode.
44+
"$BIN_GRAPH" --mode 'grayscale' "$input_file" "${input_file}.grayscale.png"
45+
"$BIN_GRAPH" --mode 'ascii' "$input_file" "${input_file}.ascii.png"
46+
"$BIN_GRAPH" --mode 'entropy' --transform-squares 16 "$input_file" "${input_file}.entropy.png"
47+
"$BIN_GRAPH" --mode 'histogram' "$input_file" "${input_file}.histogram.png"
48+
"$BIN_GRAPH" --mode 'bigrams' "$input_file" "${input_file}.bigrams.png"
49+
"$BIN_GRAPH" --mode 'dotplot' --offset-start 0 --offset-end 1000 "$input_file" "${input_file}.dotplot1.png"
50+
"$BIN_GRAPH" --mode 'dotplot' --offset-start 4000 --offset-end 5000 "$input_file" "${input_file}.dotplot2.png"
51+
"$BIN_GRAPH" --mode 'dotplot' --offset-start 10000 --offset-end 11000 "$input_file" "${input_file}.dotplot3.png"
52+
"$BIN_GRAPH" --mode 'dotplot' --offset-start 30000 --offset-end 31000 "$input_file" "${input_file}.dotplot4.png"

0 commit comments

Comments
 (0)