diff --git a/lib/adapter/cmd.py b/lib/adapter/cmd.py
index 5d2ffa6..9d01e22 100644
--- a/lib/adapter/cmd.py
+++ b/lib/adapter/cmd.py
@@ -130,9 +130,10 @@ class AdapterOeis(CommandAdapter):
cmd[0] = _get_abspath(cmd[0])
# cut oeis/ off
- # Space delimiter for args to oeis.sh
+ # Replace all non (numeric, '-') chars with Spaces to delimit args to oeis.sh
if topic.startswith("oeis/"):
- topic = topic[5:].replace('+',' ')
+ topic = topic[5:]
+ topic = re.sub('[^0-9-]', ' ', topic)
return cmd + [topic]
@@ -154,10 +155,13 @@ class AdapterChmod(CommandAdapter):
cmd = self._command[:]
# cut chmod/ off
+ # remove all non (alphanumeric, '-') chars
if topic.startswith("chmod/"):
topic = topic[6:]
+ topic = re.sub('[^a-z^A-Z^0-9-]', '', topic)
+
return cmd + [topic]
def is_found(self, topic):
- return True
+ return True
diff --git a/share/adapters/oeis.sh b/share/adapters/oeis.sh
index b727384..d57bf70 100755
--- a/share/adapters/oeis.sh
+++ b/share/adapters/oeis.sh
@@ -13,14 +13,17 @@ oeis() (
local DOC=/tmp/oeis/doc.html
local MAX_TERMS=10
mkdir -p $TMP
- # Get short description of a sequence
+ # -- get_desc --
+ # @return print description of OEIS sequence
get_desc() {
grep -A 1 '
' $DOC \
| sed '/ | /d; /--/d; s/^[ \t]*//; s/<[^>]*>//g;' \
| sed 's/ / /g; s/\&/\&/g; s/>/>/g; s/</.*, .*[0-9]' $DOC \
@@ -30,7 +33,9 @@ oeis() (
| cut -d ',' -f 1-${MAX_TERMS}
return $?
}
- # Sample code parser INPUT arg: is grep regex
+ # -- parse_code --
+ # @param GREP_REGEX
+ # @return Code snippet that corresponds to GREP_REGEX
parse_code() {
local GREP_REGEX="${1}"
cat $DOC \
@@ -41,27 +46,35 @@ oeis() (
| sed 's/ / /g; s/\&/\&/g; s/>/>/g; s/</
+ # . oeis
+ # . oeis
if [ $# -lt 3 ]
then
# Arg-Parse ID, Generate URL
- echo $1 | grep -q -e [a-z] -e [B-Z] && ID=$2 || ID=$1
- echo $1 | grep -q -e [a-z] -e [B-Z] && LANG=$1 || LANG=$2
+ if echo ${1^^} | grep -q '[B-Z]'
+ then
+ ID=$2
+ LANGUAGE=$1
+ else
+ ID=$1
+ LANGUAGE=$2
+ fi
[[ ${ID:0:1} == 'A' ]] && ID=${ID:1}
ID=$(bc <<< "$ID")
ID="A$(printf '%06d' ${ID})"
URL+="/${ID}"
curl $URL 2>/dev/null > $DOC
- # Print ID
+ # Print ID, description, and sequence
printf "ID: ${ID}\n"
- # Print Description
get_desc
printf "\n"
- # Print Sequence sample limited by $MAX_TERMS
get_seq ${MAX_TERMS}
printf "\n"
# Print Code Sample
- if [[ ${LANG^^} == 'MAPLE' ]] && grep -q 'MAPLE' $DOC
+ if [[ ${LANGUAGE^^} == 'MAPLE' ]] && grep -q 'MAPLE' $DOC
then
GREP_REGEX='MAPLE.*CROSSREFS'
grep -q 'PROG' $DOC && GREP_REGEX='MAPLE.*PROG'
@@ -69,7 +82,7 @@ oeis() (
parse_code "${GREP_REGEX}" \
| sed 's/MAPLE/(MAPLE)/; /MATHEMATICA/d; /PROG/d; /CROSSREFS/d'
fi
- if [[ ${LANG^^} == 'MATHEMATICA' ]] && grep -q 'MATHEMATICA' $DOC
+ if [[ ${LANGUAGE^^} == 'MATHEMATICA' ]] && grep -q 'MATHEMATICA' $DOC
then
GREP_REGEX='MATHEMATICA.*CROSSREFS'
grep -q 'PROG' $DOC && GREP_REGEX='MATHEMATICA.*PROG'
@@ -81,11 +94,11 @@ oeis() (
| sed '/PROG/d; /CROSSREFS/d' > ${TMP}/prog
# Print out code sample for specified language
rm -f ${TMP}/code_snippet
- awk -v tgt="${LANG^^}" -F'[()]' '/^\(/{f=(tgt==$2)} f' ${TMP}/prog > ${TMP}/code_snippet
- L="${LANG:0:1}"
- LANG="${LANG:1}"
- LANG="${L^^}${LANG,,}"
- [ $(wc -c < $TMP/code_snippet) -eq 0 ] && awk -v tgt="${LANG}" -F'[()]' '/^\(/{f=(tgt==$2)} f' ${TMP}/prog > ${TMP}/code_snippet
+ awk -v tgt="${LANGUAGE^^}" -F'[()]' '/^\(/{f=(tgt==$2)} f' ${TMP}/prog > ${TMP}/code_snippet
+ L="${LANGUAGE:0:1}"
+ LANGUAGE="${LANGUAGE:1}"
+ LANGUAGE="${L^^}${LANGUAGE,,}"
+ [ $(wc -c < $TMP/code_snippet) -eq 0 ] && awk -v tgt="${LANGUAGE}" -F'[()]' '/^\(/{f=(tgt==$2)} f' ${TMP}/prog > ${TMP}/code_snippet
cat ${TMP}/code_snippet
# Search unknown sequence
else
|