#ifndef TPTP_H
#define TPTP_H 
#include "fol.h"
#include "clause.h"
#include "string.h"
typedef enum {
  TPTP_PS_UNDEFINED=0,
  TPTP_PS_STORED_AS_STRING,
  TPTP_PS_SPASSCLAUSE
} TPTP_PS_TYPE;
typedef struct tptp_proofstep_struct {
  TPTP_PS_TYPE type;
  BOOL visited;
  intptr_t data;
} TPTP_PROOFSTEP_NODE, *TPTP_PROOFSTEP;
typedef struct tptp_formula_struct {
  const char *language;
  char *name;
  char *basename;
  const char *role;
  intptr_t data;
  char *filename;
  TPTP_PROOFSTEP proofstep;
} TPTP_FORMULA_NODE, *TPTP_FORMULA;
typedef struct tptpstate {
  MEMORY mem;
  FOLSTATE folstate;
  STRBUF strbuf;
  ARRAY proofsteps;
  ARRAY clauseIDtoPS;
  ARRAY clauseNames;
  char clauseStr[80];
  unsigned clausePrefixLen;
  char *problemName;
} TPTPSTATE_NODE, *TPTPSTATE;
extern const char *const TPTP_LangFOF;
extern const char *const TPTP_LangCNF;
extern const char *const TPTP_RoleAxiom;
extern const char *const TPTP_RoleHypothesis;
extern const char *const TPTP_RoleDefinition;
extern const char *const TPTP_RoleLemma;
extern const char *const TPTP_RoleTheorem;
extern const char *const TPTP_RoleCorollary;
extern const char *const TPTP_RolePlain;
extern const char *const TPTP_RoleConjecture;
extern const char *const TPTP_RoleNegatedConjecture;
TPTP_FORMULA tptp_AllocateFormula(MEMORY);
void tptp_FreeFormula(MEMORY, TPTP_FORMULA);
const char* tptp_GetLanguage(TPTP_FORMULA);
void tptp_SetLanguage(TPTP_FORMULA, const char*);
char* tptp_GetName(TPTP_FORMULA);
void tptp_SetName(TPTP_FORMULA, char*);
const char* tptp_GetRole(TPTP_FORMULA);
void tptp_SetRole(TPTP_FORMULA, const char*);
BOOL tptp_TrySettingRole(TPTP_FORMULA, char *Str, const char *Role);
TERM tptp_GetTerm(TPTP_FORMULA);
void tptp_SetTerm(TPTP_FORMULA, TERM);
CLAUSE tptp_GetClause(TPTP_FORMULA);
void tptp_SetClause(TPTP_FORMULA, CLAUSE);
char* tptp_GetFilename(TPTP_FORMULA);
void tptp_SetFilename(TPTP_FORMULA, char*);
char* tptp_GetBasename(TPTP_FORMULA);
void tptp_SetBasename(TPTP_FORMULA, char*);
TPTP_PROOFSTEP tptp_GetProofstep(TPTP_FORMULA);
void tptp_SetProofstep(TPTP_FORMULA, TPTP_PROOFSTEP);
TPTP_PROOFSTEP tptp_AllocateProofstep(MEMORY);
TPTP_PROOFSTEP tptp_CreateProofstep(TPTPSTATE);
TPTP_PROOFSTEP tptp_CreateProofstepStoreString(TPTPSTATE, char* AllocatedString);
TPTP_PROOFSTEP tptp_GetProofstepByClauseID(TPTPSTATE, unsigned ClauseID);
void tptp_SetProofstepByClauseID(TPTPSTATE, unsigned ClauseID, TPTP_PROOFSTEP);
void tptp_ResizeClauseIDtoPS(TPTPSTATE, unsigned MaxClauseID);
TPTP_PROOFSTEP tptp_CreateProofstepForClause(TPTPSTATE, CLAUSE, const char *ClauseMsg);
void tptp_ProofstepAddParent(MEMORY, TPTP_PROOFSTEP Proofstep, TPTP_PROOFSTEP Parent);
void tptp_FreeProofstep(MEMORY, TPTP_PROOFSTEP);
char* tptp_ProofstepGetString(TPTP_PROOFSTEP);
void tptp_ProofstepSetString(TPTP_PROOFSTEP, const char*);
TPTPSTATE tptp_Init(MEMORY, FOLSTATE);
MEMORY tptp_GetMemory(TPTPSTATE);
FOLSTATE tptp_GetFolstate(TPTPSTATE);
SYMBSTATE tptp_GetSymbstate(TPTPSTATE);
TERMSTATE tptp_GetTermstate(TPTPSTATE);
const char* tptp_GetProblemName(TPTPSTATE);
void tptp_SetProblemName(TPTPSTATE, const char*);
void tptp_Free(TPTPSTATE);
char* tptp_AllocateFormulaName(TPTPSTATE, const char*);
void tptp_FreeFormulaName(TPTPSTATE, char*);
void tptp_RegisterClauseName(TPTPSTATE, unsigned ClauseID, char*);
const char* tptp_GetClauseName(TPTPSTATE, unsigned ClauseID);
void tptp_DetermineGenericClauseNamePrefix(TPTPSTATE);
void tptp_FPrintFormulaContent(FILE*, FOLSTATE, TPTP_FORMULA);
void tptp_FPrintFormulaAnnotated(FILE*, FOLSTATE, TPTP_FORMULA);
void tptp_FPrintClauseName(FILE*, TPTPSTATE, unsigned ClauseID);
void tptp_FPrintSymbol(FILE*, SYMBSTATE, SYMBOL Symbol);
void tptp_FPrintAtom(FILE*, FOLSTATE, TERM Term);
void tptp_FPrintTerm(FILE*, FOLSTATE, TERM Term, unsigned Depth);
void tptp_FPrintLiteralArray(FILE*, FOLSTATE, ARRAY LiteralArr);
void tptp_FPrintClause(FILE*, FOLSTATE, CLAUSE Clause);
void tptp_FPrintFOF(FILE*, FOLSTATE, TERM Term,
                    const char *Name, const char *Role);
void tptp_FPrintCNF(FILE*, FOLSTATE, CLAUSE Clause,
                    const char *Name, const char *Role);
void tptp_FPrintCNFArrArrLit(FILE*, FOLSTATE, ARRAY Cnf);
void tptp_FFofSimpleInference(FILE*, FOLSTATE, TPTP_FORMULA, TERM NewTerm,
                              const char *Rule, BOOL RenamedVariables);
void tptp_FPrintFileRecord(FILE*, TPTPSTATE, FOLSTATE, TPTP_FORMULA);
void tptp_FPrintNegateConjectureIfNecessary(FILE*, TPTPSTATE, FOLSTATE, TPTP_FORMULA);
TPTP_FORMULA tptp_FPrintIntroduceRenaming(FILE*, FOLSTATE, char *Name, TERM, TPTP_FORMULA Parent);
void tptp_FPrintRenamingInference(FILE*, FOLSTATE, TPTP_FORMULA Orig, ARRAY Renamings);
void tptp_FPrintSkolemInference(FILE*, FOLSTATE, TPTP_FORMULA, TERM NewTerm);
void tptp_FPrintPushDisjInference(FILE*, TPTPSTATE, FOLSTATE, TPTP_FORMULA, CLAUSE);
void tptp_BPrintFormulaContent(STRBUF, FOLSTATE, TPTP_FORMULA);
void tptp_BPrintFormulaAnnotated(STRBUF, FOLSTATE, TPTP_FORMULA);
void tptp_BPrintClauseName(STRBUF, TPTPSTATE, unsigned ClauseID);
void tptp_BPrintSymbol(STRBUF, SYMBSTATE, SYMBOL Symbol);
void tptp_BPrintAtom(STRBUF, FOLSTATE, TERM Term);
void tptp_BPrintTerm(STRBUF, FOLSTATE, TERM Term, unsigned Depth);
void tptp_BPrintLiteralArray(STRBUF, FOLSTATE, ARRAY LiteralArr);
void tptp_BPrintClause(STRBUF, FOLSTATE, CLAUSE Clause);
void tptp_BPrintFOF(STRBUF, FOLSTATE, TERM Term,
                    const char *Name, const char *Role);
void tptp_BPrintCNF(STRBUF, FOLSTATE, CLAUSE Clause,
                    const char *Name, const char *Role);
void tptp_BPrintCNFArrArrLit(STRBUF, FOLSTATE, ARRAY Cnf);
void tptp_StoreFileRecord(TPTPSTATE, TPTP_FORMULA);
void tptp_NegateConjectureIfNecessary(TPTPSTATE, TPTP_FORMULA);
void tptp_FofSimpleInference(TPTPSTATE, TPTP_FORMULA, TERM NewTerm,
                             const char *Rule, BOOL RenamedVariables);
TPTP_FORMULA tptp_IntroduceRenaming(TPTPSTATE, char *Name, TERM RenamingTerm, TPTP_FORMULA Parent);
void tptp_RenamingInference(TPTPSTATE, TPTP_FORMULA Formula, ARRAY Renamings);
void tptp_SkolemInferenceOLD(TPTPSTATE, TPTP_FORMULA, TERM NewTerm);
void tptp_SkolemInference(TPTPSTATE, TPTP_FORMULA, TERM NewTerm, ARRAY VarSkolem);
void tptp_PushDisjInference(TPTPSTATE, TPTP_FORMULA Parent, CLAUSE Clause);
void tptp_BPrintSPASSClauseResolution(STRBUF, TPTPSTATE, CLAUSE);
void tptp_FPrintSPASSClauseResolution(FILE*, TPTPSTATE, CLAUSE);
void tptp_RegisterClauses(TPTPSTATE, ARRAY Clauses, const char *ClauseMsg);
void tptp_FPrintDerivation(FILE*, TPTPSTATE, TPTP_PROOFSTEP Proofstep);
void tptp_PrintDerivationWrapper(TPTPSTATE, ARRAY Clauses, ARRAY RedClauses, CLAUSE EmptyClause);
#endif
