/** Preprocesses a Fortran file. Currently this just uses a local copy of X-Midas's xfpp
    to accomplish this.

    @author  J. Czechowski IV
    @since   NeXtMidas 2.5.0
    @version $Id: FortranPreprocessor.cc,v 1.3 2007/11/09 21:21:41 ntn Exp $
 */
#include "nxm_xbc_lib_FortranPreprocessor.h"

#define M_CHECKIN "call m$chkin(pMc,pMu) !XFPP" /* Replacement string for M$CHECKIN */
#define M_RETURN  "call m$return !XFPP"         /* Replacement string for M$RETURN  */

#include "xfpp.cc"

extern "C" JNIEXPORT jint JNICALL Java_nxm_xbc_lib_FortranPreprocessor_xfpp
  (JNIEnv *env, jclass clazz, jstring inFile, jstring outFile, jstring flags) {
  const char *fname_in    = env->GetStringUTFChars(inFile,  NULL);
  const char *fname_out   = env->GetStringUTFChars(outFile, NULL);
  const char *xfpp_flags  = env->GetStringUTFChars(flags,   NULL);
  jint status = ERROR;

  if (nxm_xbc_lib_FortranPreprocessor_DEBUG) {
    fprintf(stderr, "FortranPreprocessor.c: xfpp - fname_in   = '%s'\n", fname_in);
    fprintf(stderr, "FortranPreprocessor.c: xfpp - fname_out  = '%s'\n", fname_out);
    fprintf(stderr, "FortranPreprocessor.c: xfpp - xfpp_flags = '%s'\n", xfpp_flags);
  }
  status = xfpp(fname_in, fname_out, xfpp_flags);

  env->ReleaseStringUTFChars(inFile, fname_in);
  env->ReleaseStringUTFChars(outFile, fname_out);
  env->ReleaseStringUTFChars(flags, xfpp_flags);

  return status;
}
