#!/bin/sh

if [ "$1" = "" -o "$1" = "--help" ]; then
  echo "description: convert any \; or \, seperated list to a space sepreated list"
  echo "             usable by scripting FOR IN loops (uses: sed)"
  echo
  echo "usage: $0 [--2nix|--2mnx] _string_"
  echo
  echo " --2nix   : print output from \"path2nix _result_\""
  echo " --2mnx   : print minixfs safe output from \"path2mnx _result_\""
  echo " _string_ : list of valid path formats seperated by \; or \,"
  echo
  echo
  echo "examples: $0 u:\\d\\path,"
  echo "            \"u:\\d\\path\" => \"/d/path\""
  echo "          $0 \$SLBPATH"
  echo "            \"C:\\MINT\SLB,U:\libs\slb" => \"C:\\MINT\\SLB U:\\libs\\slb\""
  exit 0
  echo "          $0 --2nix "\$PATH\""
  echo "            \"C:\\MINT;U:\bin\;D:\usr\bin\" => \"/c/mint /bin /d/usr/bin\""
  exit 0
fi

PASS_2_PATH2NIX="no"
PASS_2_PATH2MNX="no"
if [ "$1" = "--2nix" ]; then
  shift
  PASS_2_PATH2NIX="yes"
elif [ "$1" = "--2mnx" ]; then
  shift
  PASS_2_PATH2MNX="yes"
fi

ENV_PATHS="$1"

ENV_PATHS=`echo -E "$ENV_PATHS" | sed 's/\\:\\//;\\//g;s/\\;/ /g;s/,/ /g;s/  / /g;s/  / /g'`

if [ "$PASS_2_PATH2NIX" = "yes" ]; then
  ENV_PATHS=`echo -E "$ENV_PATHS" | sed 's/\\\\/\\//g;s/\\(.*\\)/\\L\\1/;s/u://g;s/\\([a-z]\\)\\(:\\)/\\/\\1/g'`
fi
if [ "$PASS_2_PATH2MNX" = "yes" ]; then
  ENV_PATHS=`echo -E "$ENV_PATHS" | sed 's/\\\\/\\//g;s/[uU]://g;s/\\([a-zA-Z]\\)\\(:\\)/\\/\\L\\1/g'`
fi

echo -E "$ENV_PATHS"

exit 0
