All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.xp_framework.runners.unix.cgen Maven / Gradle / Ivy

There is a newer version: 3.3.4
Show newest version
#!/bin/sh






PATHSEP=':'
DIRSEP='/'


if [ -L "$0" ] ; then
  link="$(readlink "$0")"
  case "$link" in
    /*) DIRNAME=$(dirname "$link") ;;                 # Absolute
    *) DIRNAME=$(dirname "$(dirname "$0")/$link") ;;  # Relative
  esac
else
  DIRNAME=$(dirname "$0")
fi

translate_path() {
  base="$1"
  path="$2"
  
  case "$path" in
    ?:*) ;;                                # C:\xp
    \\*) ;;                                # \\filesrv\shares
    /*) ;;                                 # /usr/local/lib */
    ~*) path=$HOME$DIRSEP${path#"~"} ;; # ~/lib
    *) path=$base$DIRSEP$path ;; # lib, ../lib, ./classes
  esac




  echo $path

}

translate_paths() {
  base="$1"
  path="$2"

  translated=""
  IFS="$PATHSEP"
  for i in $path ; do
    translated="$translated$PATHSEP"$(translate_path "$base" "$i")
  done
  echo "${translated#$PATHSEP}"
}

locate() {
  path="$1"
  file="$2"
  expect=$3

  IFS="$PATHSEP"
  for i in $path ; do
    qualified="$i/$file"
    if [ -e "$qualified" ] ; then
      echo "$qualified"
      if [ $expect = 1 ] ; then return ; fi
    fi
  done
  if [ $expect = 1 ] ; then echo "*** Failed to locate $file in $path" >&2 ; fi
  echo ""
}
base="$DIRNAME" RUNNER="class" INCLUDE="." xppath="$DIRNAME" ARGS=xp.codegen.Runner IFS="|";
ifs="|"
if [ "" = "$USE_XP" ] ; then
  unset USE_XP
else
  USE_XP=$(translate_paths "." "$USE_XP")
fi
RT_ARG=""
dkeys=""
vkeys=""
for i in "." "$HOME/.xp" "$base" ; do
  if [ -e "$i/xp.ini" ] ; then
    section=default
    while read line || [ -n "$line" ] ; do
      case "$section.$line" in
        default.use=*)
          USE_XP=${USE_XP-$(translate_paths "$i" "${line#*=}")}
        ;;
        default.rt=*)
          XP_RT=${XP_RT-${line#*=}}
        ;;
        *.\;*)
          ;;
        *.\[*\])
          section=${line#\[}
          section=${section%]}
        ;;
        runtime.extension=*|runtime@$XP_RT.extension=*)
          RT_ARG="$RT_ARG${ifs}-dextension=${line#*=}"
        ;;
        runtime.*=*)
          key=${line%=*}
          key=$(echo $key | sed 's/\./__/g')
          dkeys="$dkeys${ifs}$key"
          eval "d$key"=${line#*=}
        ;;
        runtime@$XP_RT.*=*)
          key=${line%=*}
          key=$(echo $key | sed 's/\./__/g')
          vkeys="$vkeys${ifs}$key"
          eval "v$key"=${line#*=}
        ;;
      esac
    done < "$i/xp.ini"
  fi
done
for k in $vkeys ; do
  eval "d$k=\$v$k"
  dkeys="$dkeys${ifs}$k"
done
for k in $dkeys ; do
  if [ $k ] ; then
    eval "v=\$d$k"
    if [ default = $k ] ; then
      XP_EXE=${XP_EXE-$v}
    else
      RT_ARG="$RT_ARG${ifs}-d$(echo $k | sed 's/__/./g')=\"$v\""
    fi
  fi
done
XP_EXE=${XP_EXE-php}
if [ "" = "$USE_XP" ] ; then
  echo "*** Cannot determine use_xp setting from [ ENV $HOME/.xp/xp.ini $base/xp.ini ]" >&2
  exit 255
fi
args="-C${ifs}-q${ifs}-dinclude_path=\".$PATHSEP$USE_XP$PATHSEP$PATHSEP$INCLUDE\"${ifs}-dmagic_quotes_gpc=0$RT_ARG"
tool=$(locate "$USE_XP" "tools/"${RUNNER}".php" 1)
export XP_EXE
IFS="|"
${XP_EXE}${ifs}${args}${ifs}$tool ${ARGS} "$@"




© 2015 - 2025 Weber Informatics LLC | Privacy Policy