#! /bin/sh

# This script generates copies of the hslib libraries suitable for
# use with Hugs.  Note that some of the libraries require extensions
# to Haskell 98 and have to be run with the -98 flag.
#
# Usage:
#
#   ./convert_hslibs  <directory where hslibs lives>
#
# To test the result for syntactic errors, do this:
#
#    hugs -98 -P"../../lib:../../lib/hugs:../../lib/exts" ../../lib/exts/*.{hs,lhs}
#

src=$1/hslibs
dst=../../lib/exts

if [ ! -d $src ]; then
  echo "Can't find hslibs in directory '$1'"
  exit 1
fi

if [ ! -d $dst ]; then
  echo "Creating directory '$dst'"
  mkdir $dst
fi

cvt() {

  echo "Converting $1/$2"
  gcc -P -E -traditional -xc -D__HUGS__ -D__HASKELL98__ $3 $src/$1/$2 > $dst/$2

}

#cvt concurrent CVar.lhs
#cvt concurrent Chan.lhs
#cvt concurrent Channel.lhs
#cvt concurrent ChannelVar.lhs
#cvt concurrent Concurrent.lhs
#cvt concurrent MVar.lhs
#cvt concurrent Merge.lhs
#cvt concurrent Parallel.lhs
#cvt concurrent QSem.lhs
#cvt concurrent QSemN.lhs
#cvt concurrent SampleVar.lhs
#cvt concurrent Semaphore.lhs
# cvt concurrent Strategies.lhs

#cvt data FiniteMap.lhs      
#cvt data Set.lhs

cp $src/data/edison/COPYRIGHT $dst/COPYRIGHT.edison
cvt data/edison/Assoc Assoc.hs
cvt data/edison/Assoc AssocDefaults.hs
cvt data/edison/Assoc AssocList.hs
cvt data/edison/Assoc PatriciaLoMap.hs

cvt data/edison/Coll Collection.hs
cvt data/edison/Coll CollectionDefaults.hs
cvt data/edison/Coll CollectionUtils.hs
cvt data/edison/Coll LazyPairingHeap.hs
cvt data/edison/Coll LeftistHeap.hs
cvt data/edison/Coll MinHeap.hs
cvt data/edison/Coll SkewHeap.hs
cvt data/edison/Coll SplayHeap.hs
cvt data/edison/Coll TestOrdBag.hs
cvt data/edison/Coll TestOrdSet.hs
cvt data/edison/Coll UnbalancedSet.hs

cvt data/edison/Seq BankersQueue.hs
cvt data/edison/Seq BinaryRandList.hs
cvt data/edison/Seq BraunSeq.hs
cvt data/edison/Seq JoinList.hs
cvt data/edison/Seq ListSeq.hs
cvt data/edison/Seq MyersStack.hs
cvt data/edison/Seq RandList.hs
cvt data/edison/Seq RevSeq.hs
cvt data/edison/Seq Sequence.hs
cvt data/edison/Seq SequenceDefaults.hs
cvt data/edison/Seq SimpleQueue.hs
cvt data/edison/Seq SizedSeq.hs
cvt data/edison/Seq TestSeq.hs

cvt data/edison EdisonPrelude.hs

# HsParser should be built using --target hugs (or whatever)
# cvt hssource HsLexer.lhs
# cvt hssource HsParseMonad.lhs
# cvt hssource HsParseUtils.lhs
# cvt hssource HsParser.hs
# cvt hssource HsPretty.hs
# cvt hssource HsSyn.lhs

# No longer useable; use or own.
#cvt lang ShowFunctions.lhs

# cvt lang NumExts.lhs
# it'd be really good to have this but it looks like a lot of work
# cvt lang GlaExts.lhs

# No longer useable; use or own.
#cvt lang IORef.lhs

# Hugs already has versions of the following - check export lists
# cvt lang Addr.lhs
# cvt lang ArrayBase.hs
# cvt lang Bits.lhs
# cvt lang Dynamic.lhs
# cvt lang Exception.lhs
# cvt lang IOExts.lhs
# cvt lang Int.lhs
# cvt lang LazyST.lhs
# cvt lang ST.lhs
# cvt lang Word.lhs

# Hugs doesn't have these:
# cvt lang ByteArray.lhs
# cvt lang CCall.lhs
# cvt lang CError.lhs
# cvt lang CForeign.lhs
# cvt lang CString.lhs
# cvt lang CTypes.lhs
# cvt lang CTypesISO.lhs
# cvt lang DiffArray.hs
# cvt lang Foreign.lhs
# cvt lang ForeignObj.lhs  # deprecated
# cvt lang ForeignPtr.lhs
# cvt lang Generics.lhs 
# cvt lang GlaExts.lhs
# cvt lang IArray.hs
# cvt lang MArray.hs
# cvt lang MarshalAlloc.lhs
# cvt lang MarshalArray.lhs
# cvt lang MarshalError.lhs
# cvt lang MarshalUtils.lhs
# cvt lang MutableArray.lhs
# cvt lang NativeInfo.lhs
# cvt lang PackedString.lhs
# cvt lang Ptr.lhs
# cvt lang Stable.lhs       # deprecated
# cvt lang StableName.lhs
# cvt lang StablePtr.lhs
# cvt lang Storable.lhs
# cvt lang StorableArray.hs
# cvt lang TimeExts.lhs
# cvt lang Weak.lhs

#cvt lang/monads MonadCont.lhs
#cvt lang/monads MonadEither.lhs
#cvt lang/monads MonadError.lhs
#cvt lang/monads MonadFix.lhs
#cvt lang/monads MonadIdentity.lhs
#cvt lang/monads MonadList.lhs
#cvt lang/monads MonadRWS.lhs
#cvt lang/monads MonadReader.lhs
#cvt lang/monads MonadState.lhs
#cvt lang/monads MonadTrans.lhs
#cvt lang/monads MonadWriter.lhs
#cvt lang/monads Monoid.lhs

# needs converted from ccall to ffi
# cvt net BSD.lhs
# cvt net CGI.lhs
# cvt net Socket.lhs
# cvt net SocketPrim.lhs
# cvt net URI.hs

# I think not
# cvt object-io *.{hs,lhs}

# needs converted from ccall to ffi
# cvt posix Posix.lhs
# cvt posix PosixDB.lhs
# cvt posix PosixErr.lhs
# cvt posix PosixFiles.lhs
# cvt posix PosixIO.lhs
# cvt posix PosixProcEnv.lhs
# cvt posix PosixProcPrim.lhs
# cvt posix PosixTTY.lhs
# cvt posix PosixUtil.lhs

# cvt text Pretty.lhs

#cvt text/html Html.lhs
#cvt text/html HtmlBlockTable.lhs

# cvt text/parsec Parsec.hs
# cvt text/parsec ParsecChar.hs
# cvt text/parsec ParsecCombinator.hs
# cvt text/parsec ParsecError.hs
# cvt text/parsec ParsecExpr.hs
# cvt text/parsec ParsecLanguage.hs
# cvt text/parsec ParsecPerm.hs
# cvt text/parsec ParsecPos.hs
# cvt text/parsec ParsecPrim.hs
# cvt text/parsec ParsecToken.hs

# cvt tools/DrIFT ChaseImports.hs
# cvt tools/DrIFT CommandP.hs
# cvt tools/DrIFT DataP.lhs
# cvt tools/DrIFT DigitToInt.hs
# cvt tools/DrIFT DrIFT.lhs
# cvt tools/DrIFT Literate.lhs
# cvt tools/DrIFT ParseLib2.hs
# cvt tools/DrIFT PreludData.hs
# cvt tools/DrIFT Pretty.lhs
# cvt tools/DrIFT RuleUtils.hs
# cvt tools/DrIFT StandardRules.lhs
# cvt tools/DrIFT UserRuleBinary.hs
# cvt tools/DrIFT UserRuleXml.hs
# cvt tools/DrIFT UserRules.hs

# cvt tools/DtdToHaskell DtdToHaskell.hs
# cvt tools/DtdToHaskell DtdToTypeDefPP.hs

# One of these defines module Main and Hugs won't let us have 2
# cvt tools/Xtract Xtract.hs
# cvt tools/Xtract XtractCombinators.hs
# cvt tools/Xtract XtractLex.hs
# cvt tools/Xtract XtractParse.hs
# cvt tools/Xtract XtractParseNew.hs

# cvt util GetOpt.lhs
# cvt util MD5.lhs
# cvt util Memo.lhs
# cvt util Select.lhs
# cvt util Unique.lhs

# quickcheck - required by edison
# cvt util/check QuickCheck.hs
# Relies on preemptive concurrency: cvt util/check QuickCheckBatch.hs
# cvt util/check QuickCheckPoly.hs
# cvt util/check QuickCheckUtils.hs

exit 0


