Skip to content

Instantly share code, notes, and snippets.

@zsteva
Last active October 29, 2023 14:12
Show Gist options
  • Select an option

  • Save zsteva/ea48ce3ebab487a5fc660ea0c54e793d to your computer and use it in GitHub Desktop.

Select an option

Save zsteva/ea48ce3ebab487a5fc660ea0c54e793d to your computer and use it in GitHub Desktop.
DSM-11 %HELP extractor
#!/bin/bash
#
# depending: bash 4+, socat
#
#
# Copyright (C) 2023 Zeljko Stevanovic <zsteva@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
PAC_ACCOUNT="MGR:PAC"
DSM_HOST="localhost"
DSM_PORT="4000"
if [ -z "$1" ]; then
echo "usage: $0 <output_file>" >&2
exit 99
fi
OUTPUT_FILE="$1"
coproc DSM {
socat - tcp:${DSM_HOST}:${DSM_PORT}
}
echoDSM() {
echo -en "$@\r" >&${DSM[1]}
}
readDSM() {
IFS='' read -r -s -t 2 "$1" <&${DSM[0]}
}
DBG=""
while true; do
readDSM LINE
$DBG echo "::::[$?] $LINE"
if [[ $LINE =~ PDP-11 ]]; then
echoDSM ""
sleep 0.2
fi
if [[ $LINE =~ UCI: ]]; then
echoDSM "${PAC_ACCOUNT}"
sleep 1
break
fi
if [[ $LINE =~ Exit ]]; then
echoDSM ""
sleep 0.2
fi
if [[ $LINE =~ ">" ]]; then
$DBG echo "halt.."
echoDSM ""
echoDSM "H"
#sleep 2
fi
done
### logged as PAC
echo ":::: logged"
### paint prompt
waitPrompt() {
local PROMPT="${1:->}"
while true; do
readDSM LINE
echo ":::: $LINE"
if [[ "$LINE" =~ "Press <RETURN> to continue" ]]; then
echoDSM ""
continue
fi
if [ -n "$OUTPUT_FILE" ]; then
echo "$LINE" >> "${OUTPUT_FILE}"
fi
if [[ "$LINE" =~ "Device >" ]]; then
echoDSM ""
continue
fi
if [[ "$LINE" =~ "Devicetype >" ]]; then
echoDSM ""
continue
fi
if [[ "$LINE" =~ "Device type >" ]]; then
echoDSM ""
continue
fi
if [[ "$LINE" =~ "Special WRITE >" ]]; then
echoDSM ""
continue
fi
if [[ "$LINE" =~ "$PROMPT" ]]; then
break;
fi
done
}
waitPrompt ">"
echo -n "" > "${OUTPUT_FILE}"
PROMPT1="DSM help >"
echoDSM "DO ^%HELP"
waitPrompt "$PROMPT1"
LEVEL1="COMMANDS"
PROMPT2="DSM command >"
echoDSM $LEVEL1
waitPrompt "$PROMPT2"
# COMMANDS FUNCTIONS OPERATORS VARIABLES "^%EDI EDITOR"
### COMMANDS
for LEVEL2 in \
BREAK CLOSE DO ELSE FOR \
GOTO HALT HANG IF JOB \
KILL LOCK NEW OPEN QUIT \
READ SET USE VIEW WRITE \
XECUTE ZALLOCATE ZBREAK ZDEALLOCATE ZGO \
ZINSERT ZLOAD ZPRINT ZQUIT ZREMOVE \
ZSAVE ZTRAP ZUSE ZWRITE
do
echoDSM $LEVEL2
waitPrompt "$PROMPT2"
done
echoDSM ""
waitPrompt
LEVEL1="FUNCTIONS"
PROMPT2="DSM function >"
echoDSM "$LEVEL1"
waitPrompt "$PROMPT2"
### FUNCTIONS
for LEVEL2 in \
\$ASCII \$CHARACTER \$DATA \$EXTRACT \$FIND \
\$JUSTIFY \$LENGTH \$NEXT \$ORDER \$PIECE \
\$RANDOM \$SELECT \$TEXT \$VIEW \$ZCALL \
\$ZORDER \$ZSORT \$ZUCI
do
# $ZORDER doesnt work
if [ "$LEVEL2" = "\$ZORDER" ]; then
continue
fi
echoDSM $LEVEL2
waitPrompt "$PROMPT2"
done
echoDSM ""
waitPrompt
echoDSM "^%EDI EDITOR"
waitPrompt "$PROMPT1"
echoDSM ""
waitPrompt
echo ":::: logout"
echoDSM "H"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment