blob: 84a1afd4a442e36d5ee1cf36661ac4be49a0584c [file] [log] [blame]
Joey Armstrong9cbbf7f2024-08-14 17:05:18 -04001#!/bin/bash
2## -----------------------------------------------------------------------
3## -----------------------------------------------------------------------
4
5## -----------------------------------------------------------------------
6## Intent: Set state flags for parsing based on detection of switch modifiers
7## -----------------------------------------------------------------------
8function getopt_detect_modifiers()
9{
10 local arg="$1"; shift
11
12 local -a patterns=()
13 patterns+=('and' 'or')
14 patterns+=('excl' 'incl')
15 patterns+=('in' 'not')
16 patterns+=('is-empty')
17
18 unset getopt_argv_AND
19 unset getopt_argv_EXCL
20 unset getopt_argv_INCL
21 unset getopt_argv_IN
22 unset getopt_argv_IS_EMPTY
23 unset getopt_argv_NOT
24 unset getopt_argv_OR
25
26 local pattern
27 for pattern in "${patterns[@]}";
28 do
29 # echo "** ${FUNCNAME} pattern=[$pattern], arg=[$arg]"
30 case "$pattern" in
31 'and')
32 case "$arg" in
33 *'-'[aA][nN][dD]*) declare -g -i getopt_argv_AND=1 ;;
34 esac
35 ;;
36
37 'or')
38 case "$arg" in
39 *'-'[oO][rR]*)
40 declare -g -i getopt_argv_OR=1
41 ;;
42 esac
43 ;;
44
45 'excl')
46 case "$arg" in
47 *'-'[eE][xX][cC][lL]*) declare -g -i getopt_argv_EXCL=1 ;;
48 esac
49 ;;
50
51 'incl')
52 case "$arg" in
53 *'-'[iI][nN][cC][lL]*) declare -g -i getopt_argv_INCL=1 ;;
54 esac
55 ;;
56
57 'in')
58 if [[ ! -v getopt_argv_INCL ]]; then
59 case "$arg" in
60 *'-'[iI][nN]*) declare -g -i getopt_argv_IN=1 ;;
61 esac
62 fi
63 ;;
64
65 'is-empty')
66 case "$arg" in
67 *'-'[iI][sS]-[eE][mM][pP][tT][yY]) declare -g -i getopt_argv_IS_EMPTY=1 ;;
68 esac
69 ;;
70
71 'not')
72 case "$arg" in
73 *'-'[nN][oO][tT]*) declare -g -i getopt_argv_NOT=1 ;;
74 esac
75 ;;
76
77 esac
78
79 done
80
81 if false; then
82 [[ -v getopt_argv_AND ]] && { declare -p getopt_argv_AND; }
83 [[ -v getopt_argv_EXCL ]] && { declare -p getopt_argv_EXCL; }
84 [[ -v getopt_argv_INCL ]] && { declare -p getopt_argv_INCL; }
85 [[ -v getopt_argv_IN ]] && { declare -p getopt_argv_IN; }
86 [[ -v getopt_argv_IS_EMPTY ]] && { declare -p getopt_argv_IS_EMPTY; }
87 [[ -v getopt_argv_NOT ]] && { declare -p getopt_argv_NOT; }
88 [[ -v getopt_argv_OR ]] && { declare -p getopt_argv_OR; }
89 fi
90
91 : # return $?==0
92 return
93}
94
95# [EOF]