commit 7855b314aea050e6d7351209c71fa0710211ced2 parent 84ae234c3f9e211979d8bcb19407deed799d5036 Author: Anders Damsgaard <anders@adamsgaard.dk> Date: Thu, 12 Nov 2020 14:31:55 +0100 add sisterfile script to switch between header and source Diffstat:
A | .local/bin/sisterfile | | | 50 | ++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 50 insertions(+), 0 deletions(-)
diff --git a/.local/bin/sisterfile b/.local/bin/sisterfile @@ -0,0 +1,50 @@ +#!/bin/sh +# return header file name for source files, and vice versa + +die() +{ + printf '%s: error: %s\n' "${0##*/}" "$1" >&2 + exit 1 +} + +print_if_file() +{ + if test -e "$1"; then + printf '%s\n' "$1" + exit + fi +} + +case "$1" in + *.hh) + print_if_file "${1%.hh}.cc" + print_if_file "${1%.hh}.cpp" + print_if_file "${1%.hh}.cxx" + print_if_file "${1%.hh}.c" + ;; + *.cc) + print_if_file "${1%.cc}.hh" + print_if_file "${1%.cc}.hpp" + print_if_file "${1%.cc}.hxx" + print_if_file "${1%.cc}.h" + ;; + *.cpp) + print_if_file "${1%.cpp}.hpp" + print_if_file "${1%.cpp}.hh" + print_if_file "${1%.cpp}.hxx" + print_if_file "${1%.cpp}.h" + ;; + *.cxx) + print_if_file "${1%.cxx}.hxx" + print_if_file "${1%.cxx}.hh" + print_if_file "${1%.cxx}.hpp" + print_if_file "${1%.cxx}.h" + ;; + *.h) + print_if_file "${1%.h}.c";; + *.c) + print_if_file "${1%.c}.h";; + *) + die "file ending for $1 not supported";; +esac +exit 1