TR-DOS virtual fs for Midnight Commander

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
utz
Microbot
Posts: 116
Joined: Wed Nov 15, 2017 9:04 am
Contact:

TR-DOS virtual fs for Midnight Commander

Post by utz »

I used to be able to view and edit .trd and .scl files with Midnight Commander (and also .tap, if memory serves correctly). Unfortunately, when I reinstalled my system a while back, I apparently forgot to copy over the required .trd extfs thingy - and now I'm unable to find it anywhere. Perhaps a kind soul on here could point me into the right direction?
User avatar
utz
Microbot
Posts: 116
Joined: Wed Nov 15, 2017 9:04 am
Contact:

Re: TR-DOS virtual fs for Midnight Commander

Post by utz »

Found it! However, seems it's quite basic, actually. Might try to code up a replacement if I can find some free time.
Anyway, in case somebody has a use for this, here's the code. Iirc it was originally posted on zx-pk.ru. It requires mctrd.

Code: Select all

#!/bin/bash

MCTRD=mctrd

umask 077

cmd="$1"

# supress space = 1 - "boot    .B" come to "boot.B", otherwise not
supress_space=1

trd_list()
{
    # Read line-2-line
    $MCTRD list "$1" | while read S; do
	name="${S:0:8}"
	A=( ${S:8} )
	ssize=${A[2]}
	seclen=${A[3]}
	sign=${A[1]}
	type=${A[0]}
	
	# check if it monobasic, or false size, use sector size instead of length size
	if [[ $(( seclen * 256 - 255 )) -gt $ssize ]] ; then
		ssize="$(( seclen * 256 ))"
	fi

	# check for header
	if [[ "$S" != "---------------------------" ]] ; then
		if [[ "$sign" != "Start" ]] ; then
			if [ $supress_space == 1 ] ; then
				name=`echo "$name" | sed "s/[ ]*$//"`
				sname=`echo "$name" | sed "s/  / /g"`
				# is it possible to supress without loose filename for mctrd?
				if [[ "$name" != "$sname" ]] ; then
					# no, use full name with spaces
					echo "-rw-rw-rw- 1 speccy speccy $ssize Jan 01 1981 $name.$type"
				else
					# yes, use shortname
					echo "-rw-rw-rw- 1 speccy speccy $ssize Jan 01 1980 "$name"."$type
				fi
			else
				# only full names with spaces
				echo "-rw-rw-rw- 1 speccy speccy $ssize Jan 01 1980 $name.$type"
			fi
		fi
	fi
    done
}

trd_copyout()
{
   _pwd=`pwd`
    cp -f "$1" "$MC_TMPDIR"/
    cd "$MC_TMPDIR"
    par1="`basename "$1"`"
    $MCTRD pop "$2" $par1 > /dev/null
# check if name seems like special, should cut off first 2 chars "./" from it
	if [ ! -e "$2" ] ; then
		par2="`echo "$2" | cut -c3-`"
		$MCTRD pop $par2 $par1
	fi
    par3="`basename "$3"`"
    mv -f -- "$2" $par3
    rm -rf $par1
    cd "$_pwd"
}

trd_copyin()
{
    _pwd=`pwd`
    $MCTRD add "$2" "$1"
    cd "$_pwd"
}

case "$cmd" in
  list) trd_list "$2" ;;
  copyout) trd_copyout "$2" "$3" "$4" ;;
  copyin) trd_copyin "$2" "$3" "$4" ;;
  *) exit 1 ;;
esac
exit 0
The above goes into $HOME/.local/share/mc/extfs.d as a file named trdfs. Then add the following to your mc.ext (usually to be found in $HOME/.config/mc):

Code: Select all

# trd
regex/\.[tT]([rR][dD])$
    Open=%cd %p/trdfs://
    View=%view{ascii} mctrd list %f

# scl
regex/\.[sS]([cC][lL])$
    Open=%cd %p/trdfs://
    View=%view{ascii} mctrd list %f
Post Reply