#!/bin/csh
#----Names files to their syntactic name of syntactic=semantic name

#----Check which type of name is required
switch ($1)
    case syntactic
        set InputType=syntactic
        breaksw
    case semantic
        set InputType=semantic
        breaksw
    default:
        echo "Usage : tptp_naming syntactic|semantic <list of files>"
        exit
        breaksw
    endsw
shift

foreach FilePath ($*)
#----Axiom files may not be renamed for now
    if ({ grep -s "% Axioms" $FilePath }) then
        echo $FilePath ": Axiom files may not be renamed. Exiting"
        exit
    else
        set Directory=`dirname $FilePath`
        set FileName=`basename $FilePath`
        set Extension=`expr match $FileName ".*\(\..*\)"`
        set SyntacticName=`sed -n -e "/% File/s/.*: \(.*\)\=.*/\1/p" $FilePath`
        set SemanticName=`sed -n -e "/% File/s/.*=\(.*\)\-.*/\1/p" $FilePath`
        set VersionNumber=`sed -n -e "/% File/s/.*\-\(.*\) :.*/\1/p" $FilePath`
        if ($InputType == syntactic) then
            set NewFileBaseName=$SyntacticName-$VersionNumber
        else
            set NewFileBaseName=$SyntacticName=$SemanticName-$VersionNumber
        endif
        set NewFilePath="$Directory"/"$NewFileBaseName""$Extension"
        mv $FilePath $NewFilePath
        echo $FilePath renames to $NewFilePath
        endif
    end

