# Eggshell Compiler entry point # # Copyright (C) 2016 Patrick "P. J." McDermott # # This file is part of the Eggshell Compiler. # # The Eggshell Compiler 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 3 of # the License, or (at your option) any later version. # # The Eggshell Compiler 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 the Eggshell Compiler. If not, see # . set -u usage() { printf 'Usage: %s [-o ] ...\n' "${0}" } version() { cat <. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. EOF } err() { local fmt="${1}" shift 1 printf "eshtrans: Error: ${fmt}\n" "${@}" } main() { local opt= local input= local output= output='' unset OPTARG while getopts 'V:o:' opt; do case "${opt}" in 'V') version exit ;; 'o') output="${OPTARG}" ;; '?') usage >&2 return 1 ;; esac unset OPTARG done shift $(($OPTIND - 1)) if [ ${#} -eq 0 ]; then err 'No input files' return 1 fi if [ "x${output}" = 'x' ]; then for input in "${@}"; do output="${input%.esh}.sh" contents="$(cat "${input}"; printf '.')" contents="${contents%.}" sh_codegen "$(esh_parse "${input}" "${contents}")" \ >"${output}" done else if [ ${#} -gt 1 ]; then err 'Cannot specify -o with multiple input files' return 1 fi input="${1}" if [ "x${output}" = 'x-' ]; then contents="$(cat "${input}"; printf '.')" contents="${contents%.}" sh_codegen "$(esh_parse "${input}" "${contents}")" else contents="$(cat "${input}"; printf '.')" contents="${contents%.}" sh_codegen "$(esh_parse "${input}" "${contents}")" \ >"${output}" fi fi }