#!/bin/sh
#
# Midnight Commander, External File System script for 
# mtools.
#
# (C) 1995 The Free Software Foundation
# Written by Miguel de Icaza.
#
disk_drive=`basename $0`:

dosdir ()
{
    mdir $disk_drive | awk -v uid={$UID-0} '
/\(s\)/ {print_ok=0}
/^$/ { print_ok=1 }
{ if (!print_ok) next;
  if (NF == 5){
      name = $1 "." $2;
      size = $3;
      date = $4;
      time = $5;
  } else if (NF == 4){ 
     name = $1;
     size = $2;
     date = $3;
     time = $4;
  } else next;

  split (time, a, /:/);
  if (a [3] ~ /p/)
     hour = a[1] + 12;
  else
     hour = a[1];
  time = sprintf ("%02d:%02d", hour, a [2]);
  split (date, b, /-/);
  date = sprintf ("%02d-%02d-%02d", b[1], b[2], b[3]);
  if (size ~ /DIR/)
    printf "drwxr-xr-x   1 %-8d %-8d %8d %s %s %s\n", uid, 0, 0, date, time, tolower(name)
  else
    printf "-rw-r--r--   1 %-8d %-8d %8d %s %s %s\n", uid, 0, size, date,time,tolower(name)
}
'
}

case "$1" in
  list)    dosdir; exit 0 ;;
  copyout) rm -f $4; mcopy ${disk_drive}$3 $4; exit 0 ;;
esac

# If we reach this place, then we do not know about the command:
exit 1;
