Skip to content
This repository was archived by the owner on May 20, 2024. It is now read-only.

Commit d409941

Browse files
CodingMarkusCodingMarkus
authored andcommitted
Simplify double include protection
1 parent e790a2b commit d409941

18 files changed

+98
-83
lines changed

lib/psst/basic.inc.sh

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,12 @@
22

33
# Double include protection
44
case "${INCLUDE_SEEN_PSST-}" in
5-
*_basic.inc.sh_*)
6-
return
7-
;;
5+
*_basic_*) return
86
esac
9-
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-} _basic.inc.sh_"
10-
7+
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-}_basic_"
118

129
# Ensure INCLUDE_PSST is set
13-
if [ -z "${INCLUDE_PSST-}" ]
14-
then
15-
echo "INCLUDE_PSST not set!" >&2
16-
exit 1
17-
fi
10+
[ -n "${INCLUDE_PSST-}" ] || { echo "INCLUDE_PSST not set!" >&2 ; exit 1 ; }
1811

1912

2013
# shellcheck source=basic/assert.inc.sh

lib/psst/basic/assert.inc.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
# Double include protection
44
case "${INCLUDE_SEEN_PSST-}" in
5-
*_assert.inc.sh_*)
6-
return
7-
;;
5+
*_assert_*) return
86
esac
9-
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-} _assert.inc.sh_"
7+
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-}_assert_"
108

119

1210
##

lib/psst/basic/chkcmd.inc.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
# Double include protection
44
case "${INCLUDE_SEEN_PSST-}" in
5-
*_chkcmd.inc.sh_*)
6-
return
7-
;;
5+
*_chkcmd_*) return
86
esac
9-
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-} _chkcmd.inc.sh_"
7+
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-}_chkcmd_"
8+
9+
# Ensure INCLUDE_PSST is set
10+
[ -n "${INCLUDE_PSST-}" ] || { echo "INCLUDE_PSST not set!" >&2 ; exit 1 ; }
1011

1112

1213
# shellcheck source=assert.inc.sh

lib/psst/basic/const.inc.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
# Double include protection
44
case "${INCLUDE_SEEN_PSST-}" in
5-
*_const.inc.sh_*)
6-
return
7-
;;
5+
*_const_*) return
86
esac
9-
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-} _const.inc.sh_"
7+
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-}_const_"
108

119

1210
##

lib/psst/basic/conv.inc.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22

33
# Double include protection
44
case "${INCLUDE_SEEN_PSST-}" in
5-
*_conv.inc.sh_*)
6-
return
7-
;;
5+
*_conv_*) return
86
esac
9-
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-} _conv.inc.sh_"
7+
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-}_conv_"
8+
9+
# Ensure INCLUDE_PSST is set
10+
[ -n "${INCLUDE_PSST-}" ] || { echo "INCLUDE_PSST not set!" >&2 ; exit 1 ; }
1011

1112

1213
# shellcheck source=test.inc.sh
1314
. "$INCLUDE_PSST/basic/test.inc.sh"
1415

1516

17+
1618
##
1719
# SUBPROCESS
1820
# conv_chr_psst <charCode> [<charCode>] [<charCode>] ...

lib/psst/basic/esc.inc.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
# Double include protection
44
case "${INCLUDE_SEEN_PSST-}" in
5-
*_esc.inc.sh_*)
6-
return
7-
;;
5+
*_esc_*) return
86
esac
9-
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-} _esc.inc.sh_"
7+
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-}_esc_"
8+
9+
# Ensure INCLUDE_PSST is set
10+
[ -n "${INCLUDE_PSST-}" ] || { echo "INCLUDE_PSST not set!" >&2 ; exit 1 ; }
1011

1112

1213
# shellcheck source=assert.inc.sh

lib/psst/basic/global.inc.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
# Double include protection
44
case "${INCLUDE_SEEN_PSST-}" in
5-
*_global.inc.sh_*)
6-
return
7-
;;
5+
*_global_*) return
86
esac
9-
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-} _global.inc.sh_"
7+
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-}_global_"
108

119

1210
##

lib/psst/basic/ifs.inc.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
# Double include protection
44
case "${INCLUDE_SEEN_PSST-}" in
5-
*_ifs.inc.sh_*)
6-
return
7-
;;
5+
*_ifs_*) return
86
esac
9-
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-} _ifs.inc.sh_"
7+
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-}_ifs_"
8+
9+
# Ensure INCLUDE_PSST is set
10+
[ -n "${INCLUDE_PSST-}" ] || { echo "INCLUDE_PSST not set!" >&2 ; exit 1 ; }
1011

1112

1213
# shellcheck source=assert.inc.sh
@@ -16,6 +17,7 @@ INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-} _ifs.inc.sh_"
1617
. "$INCLUDE_PSST/basic/stack.inc.sh"
1718

1819

20+
1921
##
2022
# FUNCTION
2123
# ifs_set_psst [<newValue>]

lib/psst/basic/onexit.inc.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
# Double include protection
44
case "${INCLUDE_SEEN_PSST-}" in
5-
*_onexit.inc.sh_*)
6-
return
7-
;;
5+
*_onexit_*) return
86
esac
9-
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-} _onexit.inc.sh_"
7+
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-}_onexit_"
8+
9+
# Ensure INCLUDE_PSST is set
10+
[ -n "${INCLUDE_PSST-}" ] || { echo "INCLUDE_PSST not set!" >&2 ; exit 1 ; }
1011

1112

1213
# shellcheck source=stack.inc.sh

lib/psst/basic/perror.inc.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
# Double include protection
44
case "${INCLUDE_SEEN_PSST-}" in
5-
*_perror.inc.sh_*)
6-
return
7-
;;
5+
*_perror_*) return
86
esac
9-
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-} _perror.inc.sh_"
7+
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-}_perror_"
8+
9+
# Ensure INCLUDE_PSST is set
10+
[ -n "${INCLUDE_PSST-}" ] || { echo "INCLUDE_PSST not set!" >&2 ; exit 1 ; }
1011

1112

1213
# shellcheck source=print.inc.sh

lib/psst/basic/print.inc.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22

33
# Double include protection
44
case "${INCLUDE_SEEN_PSST-}" in
5-
*_print.inc.sh_*)
6-
return
7-
;;
5+
*_print_*) return
86
esac
9-
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-} _print.inc.sh_"
7+
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-}_print_"
8+
9+
# Ensure INCLUDE_PSST is set
10+
[ -n "${INCLUDE_PSST-}" ] || { echo "INCLUDE_PSST not set!" >&2 ; exit 1 ; }
1011

1112

1213
# shellcheck source=global.inc.sh
1314
. "$INCLUDE_PSST/basic/global.inc.sh"
1415

1516

17+
1618
##
1719
# SUBPROCESS
1820
# perror_psst [<arg>] [<arg>] [<arg>] ...

lib/psst/basic/stack.inc.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22

33
# Double include protection
44
case "${INCLUDE_SEEN_PSST-}" in
5-
*_stack.inc.sh_*)
6-
return
7-
;;
5+
*_stack_*) return
86
esac
9-
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-} _stack.inc.sh_"
7+
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-}_stack_"
8+
9+
# Ensure INCLUDE_PSST is set
10+
[ -n "${INCLUDE_PSST-}" ] || { echo "INCLUDE_PSST not set!" >&2 ; exit 1 ; }
11+
12+
13+
# shellcheck source=assert.inc.sh
14+
. "$INCLUDE_PSST/basic/assert.inc.sh"
15+
1016

1117

1218
##
@@ -47,7 +53,7 @@ stack_push_psst()
4753
eval "$_itemName_stack_psst=\"\$1\""
4854
eval "$_countName_stack_psst=$_count_stack_psst"
4955

50-
unset _stackName_psst
56+
unset _stackName_stack_psst
5157
unset _countName_stack_psst
5258
unset _count_stack_psst
5359
unset _itemName_stack_psst

lib/psst/basic/test.inc.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
# Double include protection
44
case "${INCLUDE_SEEN_PSST-}" in
5-
*_test.inc.sh_*)
6-
return
7-
;;
5+
*_test_*) return
86
esac
9-
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-} _test.inc.sh_"
7+
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-}_test_"
108

119

1210
# shellcheck source=assert.inc.sh

lib/psst/basic/tmpdir.inc.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22

33
# Double include protection
44
case "${INCLUDE_SEEN_PSST-}" in
5-
*_tempdir.inc_*)
6-
return
7-
;;
5+
*_tempdir_*) return
86
esac
9-
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-} _tempdir.inc_"
7+
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-}_tempdir_"
8+
9+
# Ensure INCLUDE_PSST is set
10+
[ -n "${INCLUDE_PSST-}" ] || { echo "INCLUDE_PSST not set!" >&2 ; exit 1 ; }
1011

1112

1213
# shellcheck source=../basic/onexit.inc.sh
1314
. "$INCLUDE_PSST/basic/onexit.inc.sh"
1415

1516

17+
1618
##
1719
# FUNCTION
1820
# tmpdir_psst <resultVarName>

lib/psst/file.inc.sh

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,20 @@
22

33
# Double include protection
44
case "${INCLUDE_SEEN_PSST-}" in
5-
*_file.inc.sh_*)
6-
return
7-
;;
5+
*_file_*) return
86
esac
9-
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-} _file.inc.sh_"
10-
7+
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-}_file_"
118

129
# Ensure INCLUDE_PSST is set
13-
if [ -z "${INCLUDE_PSST-}" ]
14-
then
15-
echo "INCLUDE_PSST not set!" >&2
16-
exit 1
17-
fi
10+
[ -n "${INCLUDE_PSST-}" ] || { echo "INCLUDE_PSST not set!" >&2 ; exit 1 ; }
11+
1812

1913

2014
# shellcheck source=basic.inc.sh
2115
. "$INCLUDE_PSST/basic.inc.sh"
2216

2317

18+
2419
# shellcheck source=file/abspath.inc.sh
2520
. "$INCLUDE_PSST/file/abspath.inc.sh"
2621

lib/psst/file/abspath.inc.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22

33
# Double include protection
44
case "${INCLUDE_SEEN_PSST-}" in
5-
*_abspath.inc.sh_*)
6-
return
7-
;;
5+
*_abspath_*) return
86
esac
9-
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-} _abspath.inc.sh_"
7+
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-}_abspath_"
8+
9+
# Ensure INCLUDE_PSST is set
10+
[ -n "${INCLUDE_PSST-}" ] || { echo "INCLUDE_PSST not set!" >&2 ; exit 1 ; }
1011

1112

1213
# shellcheck source=../basic/assert.inc.sh
1314
. "$INCLUDE_PSST/basic/assert.inc.sh"
1415

1516

17+
1618
##
1719
# SUBPROCESS
1820
# abspath_psst <path>

lib/psst/file/glob.inc.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
# Double include protection
44
case "${INCLUDE_SEEN_PSST-}" in
5-
*_glob.inc.sh_*)
6-
return
7-
;;
5+
*_glob_*) return
86
esac
9-
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-} _glob.inc.sh_"
7+
INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-}_glob_"
8+
9+
# Ensure INCLUDE_PSST is set
10+
[ -n "${INCLUDE_PSST-}" ] || { echo "INCLUDE_PSST not set!" >&2 ; exit 1 ; }
1011

1112

1213
# shellcheck source=../basic/assert.inc.sh
@@ -19,6 +20,7 @@ INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-} _glob.inc.sh_"
1920
. "$INCLUDE_PSST/basic/ifs.inc.sh"
2021

2122

23+
2224
##
2325
# SUBPROCESS
2426
# glob_psst <filter> [<filter>] [<filter>] ...

test/basic/bin/test_stack.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,18 @@ set -e
5555

5656
# Test push creates and pops destroys
5757
! stack_exists_psst "stack" || test_fail_psst $LINENO
58+
# Verify that the gloabl namespace has not been polluted
59+
! ( set | grep "^_.*_psst" ) || test_fail_psst $LINENO
5860

5961
stack_push_psst "1" "stack" || test_fail_psst $LINENO
6062
stack_exists_psst "stack" || test_fail_psst $LINENO
63+
# Verify that the gloabl namespace has not been polluted
64+
! ( set | grep "^_.*_psst" ) || test_fail_psst $LINENO
6165

6266
stack_pop_psst "stack" unused || test_fail_psst $LINENO
6367
! stack_exists_psst "stack" || test_fail_psst $LINENO
64-
68+
# Verify that the gloabl namespace has not been polluted
69+
! ( set | grep "^_.*_psst" ) || test_fail_psst $LINENO
6570

6671
# Test only destroyed if empty
6772
! stack_exists_psst "stack" || test_fail_psst $LINENO
@@ -88,9 +93,13 @@ test "$test1Res" = "a" || test_fail_psst $LINENO
8893
test2Res=
8994
stack_push_psst "a" test2 || test_fail_psst $LINENO
9095
stack_push_psst "b" test2 || test_fail_psst $LINENO
96+
# Verify that the gloabl namespace has not been polluted
97+
! ( set | grep "^_.*_psst" ) || test_fail_psst $LINENO
9198

9299
stack_pop_psst test2 test2Res || test_fail_psst $LINENO
93100
test "$test2Res" = "b" || test_fail_psst $LINENO
101+
# Verify that the gloabl namespace has not been polluted
102+
! ( set | grep "^_.*_psst" ) || test_fail_psst $LINENO
94103

95104
stack_pop_psst test2 test2Res || test_fail_psst $LINENO
96105
test "$test2Res" = "a" || test_fail_psst $LINENO
@@ -116,4 +125,8 @@ test "$test3Res" = "a" || test_fail_psst $LINENO
116125
# Cannot pop from non-existing stack
117126
test4Res=
118127
! stack_pop_psst test4 test4Res || test_fail_psst $LINENO
119-
test -z "$test4Res" || test_fail_psst $LINENO
128+
test -z "$test4Res" || test_fail_psst $LINENO
129+
130+
131+
# Verify that the gloabl namespace has not been polluted
132+
! ( set | grep "^_.*_psst" ) || test_fail_psst $LINENO

0 commit comments

Comments
 (0)