diff --git a/lib/adapter/cmd.py b/lib/adapter/cmd.py index 7680998..7ecbdf3 100644 --- a/lib/adapter/cmd.py +++ b/lib/adapter/cmd.py @@ -130,10 +130,10 @@ class AdapterOeis(CommandAdapter): cmd[0] = _get_abspath(cmd[0]) # cut oeis/ off - # Replace all non (numeric, '-') chars with Spaces to delimit args to oeis.sh + # Replace all non (alphanumeric, '-') chars with Spaces to delimit args to oeis.sh if topic.startswith("oeis/"): topic = topic[5:] - topic = re.sub('[^0-9-]', ' ', topic) + topic = re.sub('[^a-zA-Z0-9-]', ' ', topic) return cmd + [topic] diff --git a/share/adapters/chmod.sh b/share/adapters/chmod.sh index 233cb4c..0ddfb89 100755 --- a/share/adapters/chmod.sh +++ b/share/adapters/chmod.sh @@ -16,15 +16,16 @@ chmod_calc(){ setuid=' ' setgid=' ' sticky=' ' - # If permission number is given calc string - if [[ $1 =~ ^-?[0-9]+$ && ${#1} -ge 2 && ${#1} -le 4 ]] + # If permission number is given -> calc string + if [[ $1 =~ ^-?[0-9]+$ && ${#1} -ge 1 && ${#1} -le 4 ]] then - p_n=$1 - for (( i=0; i<${#1}; i++ )) + p_n=$(printf "%04s\n" "$1" | tr ' ' '0') + echo $p_n | grep -q '[8-9]' && return 1 + for (( i=0; i<${#p_n}; i++ )) do - num=$(echo "obase=2;${1:$i:1}" | bc | xargs printf '%03d') - # If 4 digit input, process specials - if [[ ${#1} -eq 4 && $i -eq 0 ]] + num=$(echo "obase=2;${p_n:$i:1}" | bc | xargs printf '%03d') + # If 4 digit input -> process specials + if [ $i -eq 0 ] then [ ${num:0:1} -eq 1 ] && setuid='X' || setuid=' ' [ ${num:1:1} -eq 1 ] && setgid='X' || setgid=' ' @@ -52,8 +53,8 @@ chmod_calc(){ [ ${num:2:1} -eq 1 ] && X+=('X') || X+=(' ') fi done - # If permission string is given calc number - elif [[ ${#1} -le 9 && $(( ${#1} % 3 )) -eq 0 && $1 =~ ^[r,s,S,t,T,w,x,-]+$ ]] + # If permission string is given -> calc number + elif [[ ${#1} -eq 9 && $1 =~ ^[r,s,S,t,T,w,x,-]+$ ]] then p_s=$1 num=0 @@ -63,21 +64,30 @@ chmod_calc(){ [[ 'tT' =~ ${p_s:8:1} ]] && sticky='X' && num=$((num+1)) [ ${num} -gt 0 ] && p_n+="$num" # Calculate rest of p_n number while populating arrays for table - for (( i=0; i<${#1}; i+=0 )) + for (( i=0; i<${#p_s}; i+=0 )) do num=0 - [[ ${1:$i:1} == 'r' ]] && R+=('X') || R+=(' ') - [[ ${1:$((i++)):1} == 'r' ]] && let num++ + [[ "r-" =~ ${p_s:$i:1} ]] || return 1 + [[ ${p_s:$i:1} == 'r' ]] && R+=('X') || R+=(' ') + [[ ${p_s:$((i++)):1} == 'r' ]] && let num++ num=$(( num << 1 )) - [[ ${1:$i:1} == 'w' ]] && W+=('X') || W+=(' ') - [[ ${1:$((i++)):1} == 'w' ]] && let num++ + [[ "w-" =~ ${p_s:$i:1} ]] || return 1 + [[ ${p_s:$i:1} == 'w' ]] && W+=('X') || W+=(' ') + [[ ${p_s:$((i++)):1} == 'w' ]] && let num++ num=$(( num << 1 )) - [[ 'stx' =~ ${1:$i:1} ]] && X+=('X') || X+=(' ') - [[ 'stx' =~ ${1:$((i++)):1} ]] && let num++ + if [ $i -lt 6 ] + then + [[ "sSx-" =~ ${p_s:$i:1} ]] || return 1 + [[ "sx" =~ ${p_s:$i:1} ]] && X+=('X') || X+=(' ') + [[ "sx" =~ ${p_s:$((i++)):1} ]] && let num++ + else + [[ "tTx-" =~ ${p_s:$i:1} ]] || return 1 + [[ "tx" =~ ${p_s:$i:1} ]] && X+=('X') || X+=(' ') + [[ "tx" =~ ${p_s:$((i++)):1} ]] && let num++ + fi p_n+="$num" done else - printf "Invalid permissions string: $1" return 1 fi # Print Final results table @@ -95,3 +105,4 @@ Sticky bit [$sticky]\tExecute [${X[0]}]\tExecute [${X[1]}]\tExecute [${X[2]}] } chmod_calc $@ +[ $? -ne 0 ] && printf "Invalid permissions string: $@\n" diff --git a/share/adapters/oeis.sh b/share/adapters/oeis.sh index d57bf70..18c458e 100755 --- a/share/adapters/oeis.sh +++ b/share/adapters/oeis.sh @@ -51,15 +51,16 @@ oeis() ( # . oeis # . oeis # . oeis - if [ $# -lt 3 ] + isNum='^[0-9]+$' + if [ $# -lt 3 ] && [[ ${1:1} =~ $isNum || ${2:1} =~ $isNum || ${1} =~ $isNum || ${2} =~ $isNum ]] && ! echo $1 | grep -q '[0-9]' || ! echo $2 | grep -q '[0-9]' then # Arg-Parse ID, Generate URL if echo ${1^^} | grep -q '[B-Z]' then - ID=$2 + ID=${2^^} LANGUAGE=$1 else - ID=$1 + ID=${1^^} LANGUAGE=$2 fi [[ ${ID:0:1} == 'A' ]] && ID=${ID:1} @@ -103,7 +104,7 @@ oeis() ( # Search unknown sequence else # Build URL - URL+="/search?q=signed%3A$(echo $@ | grep -v [a-z] | grep -v [A-Z] | tr ' ' ',')" + URL+="/search?q=signed%3A$(echo $@ | tr -sc '[:digit:]-' ',')" curl $URL 2>/dev/null > $DOC # Sequence IDs grep -o '=id:.*&' $DOC \