#!/bin/bash
# H0 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# H0 X
# H0 X   libAtoms+QUIP: atomistic simulation library
# H0 X
# H0 X   Portions of this code were written by
# H0 X     Albert Bartok-Partay, Silvia Cereda, Gabor Csanyi, James Kermode,
# H0 X     Ivan Solt, Wojciech Szlachta, Csilla Varnai, Steven Winfield.
# H0 X
# H0 X   Copyright 2006-2010.
# H0 X
# H0 X   These portions of the source code are released under the GNU General
# H0 X   Public License, version 2, http://www.gnu.org/copyleft/gpl.html
# H0 X
# H0 X   If you would like to license the source code under different terms,
# H0 X   please contact Gabor Csanyi, gabor@csanyi.net
# H0 X
# H0 X   Portions of this code were written by Noam Bernstein as part of
# H0 X   his employment for the U.S. Government, and are not subject
# H0 X   to copyright in the USA.
# H0 X
# H0 X
# H0 X   When using this software, please cite the following reference:
# H0 X
# H0 X   http://www.libatoms.org
# H0 X
# H0 X  Additional contributions by
# H0 X    Alessio Comisso, Chiara Gattinoni, and Gianpietro Moras
# H0 X
# H0 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

usage="process module name to appropriate module filename case and suffix
reads module names from stdin
Usage: $0 [ -lc | -uc ] [ -suffix .suf ]"

lc=0
uc=0
suffix=".mod"
uc_set=0
lc_set=0

while [[ $# > 0 ]]; do
  if [[ $1 == "-uc" ]]; then
    lc=0
    uc=1
    uc_set=1
  else
    if [[ $1 == "-lc" ]]; then
      lc=1
      uc=0
      lc_set=1
    else
      if [[ $1 == "-suffix" ]]; then
	shift
	suffix=$1
      else
	echo "$usage" 1>&2
	exit 1
      fi
    fi
  fi
  shift
done

if [[ $lc_set == 1 && $uc_set == 1 ]]; then
  echo "-lc and -uc conflict" 1>&2
  exit 1
fi

SED_ARGS="s/\$/$suffix/"
TR_ARGS="a a"
if [[ $lc == 1 ]]; then
  TR_ARGS="[A-Z] [a-z]"
fi
if [[ $uc == 1 ]]; then
  TR_ARGS="[a-z] [A-Z]"
fi

# echo "args $lc $uc $suffix" 1>&2
shift

for name in `cat`; do
  echo $name | tr $TR_ARGS | sed "${SED_ARGS}"
done
