<commit_before>/* ptmatlab.cc - Java Native Interface to the matlab engine API

 Copyright (c) 1998-2005 The Regents of the University of California and
 Research in Motion Limited.
 All rights reserved.
 Permission is hereby granted, without written agreement and without
 license or royalty fees, to use, copy, modify, and distribute this
 software and its documentation for any purpose, provided that the above
 copyright notice and the following two paragraphs appear in all copies
 of this software.

 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA OR RESEARCH IN MOTION
 LIMITED BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
 INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
 SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA
 OR RESEARCH IN MOTION LIMITED HAVE BEEN ADVISED OF THE POSSIBILITY OF
 SUCH DAMAGE.

 THE UNIVERSITY OF CALIFORNIA AND RESEARCH IN MOTION LIMITED
 SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
 BASIS, AND THE UNIVERSITY OF CALIFORNIA AND RESEARCH IN MOTION
 LIMITED HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
 ENHANCEMENTS, OR MODIFICATIONS.

                                        PT_COPYRIGHT_VERSION_2
                                        COPYRIGHTENDKEY

Authors: <NAME> and <NAME>, Research in Motion Limited
Version $Id: ptmatlab.cc,v 1.10 2005/03/24 02:21:30 cxh Exp $
*/

// jni assumes MSVC and __int64
#ifdef __GNUC__
typedef long long __int64;
#endif

// V5_COMPAT allows matlab version 5 compatible (obsolete in 6.5 and
// beyond) functions (like mxGetArray()...) in the source yielding one
// shared ptmatlab library. The alternative would be to have two source
// files depending on the matlab version or define our own mxGet wrapper
// macros that select the right one... Either way, Ptolemy would have to
// build and jar two versions of the DLL for webstart and
// ptolemy.matlab.Engine would have to know (via a java property?) which
// version of the ptmatlab shared library to load...
#define V5_COMPAT

#include <jni.h>
#include "ptmatlab.h"
#include "engine.h"

// The following test is a kludge for a missing #define in the matlab
// include files that would allow engine interface C code to test which
// matlab version it is dealing with... This is a test for an earlier
// matlab version (than 6p5 or later). NOTE that this test may be broken
// by subsequent matlab versions so we will need a ./configure - time
// matlab version determination eventually.
#if !defined(mxArray_DEFINED)
// Starting with matlab 6p5, logical variables (mxArrays) are using an
// mxLogical type and their class string returns "logical". However
// mxLogical is not defined in earlier matlab versions, so we define it
// here...
#define mxLogical char
#define mxGetLogicals(ma) mxGetPr(ma)
#endif

// Declare an integer type that correctly casts a pointer
typedef int ptrint;
typedef int mwSize;
typedef int mwIndex;

#include <stdio.h>
#include <stdlib.h>

extern "C"
{
  JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
    return JNI_VERSION_1_2;
  }

  static char ptmatlabGetDebug
  (JNIEnv *jni,
   jobject obj)
  {
    jfieldID debug = jni->GetFieldID(jni->GetObjectClass(obj), "debug", "B");
    return jni->GetByteField(obj, debug);
  }

  JNIEXPORT jlong JNICALL Java_ptolemy_matlab_Engine_ptmatlabEngOpen
  (JNIEnv *jni,
   jobject obj,
   jstring cmdString)
  {
    const char *cmd = NULL;
    jlong retval = 0;
    if (cmdString != NULL) cmd = jni->GetStringUTFChars(cmdString, 0);
    Engine *ep = engOpen(cmd); <commit_msg>define type only if not defined by matlab<commit_after>/* ptmatlab.cc - Java Native Interface to the matlab engine API

 Copyright (c) 1998-2005 The Regents of the University of California and
 Research in Motion Limited.
 All rights reserved.
 Permission is hereby granted, without written agreement and without
 license or royalty fees, to use, copy, modify, and distribute this
 software and its documentation for any purpose, provided that the above
 copyright notice and the following two paragraphs appear in all copies
 of this software.

 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA OR RESEARCH IN MOTION
 LIMITED BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
 INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
 SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA
 OR RESEARCH IN MOTION LIMITED HAVE BEEN ADVISED OF THE POSSIBILITY OF
 SUCH DAMAGE.

 THE UNIVERSITY OF CALIFORNIA AND RESEARCH IN MOTION LIMITED
 SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
 BASIS, AND THE UNIVERSITY OF CALIFORNIA AND RESEARCH IN MOTION
 LIMITED HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
 ENHANCEMENTS, OR MODIFICATIONS.

                                        PT_COPYRIGHT_VERSION_2
                                        COPYRIGHTENDKEY

Authors: <NAME> and <NAME>, Research in Motion Limited
Version $Id: ptmatlab.cc,v 1.10 2005/03/24 02:21:30 cxh Exp $
*/

// jni assumes MSVC and __int64
#ifdef __GNUC__
typedef long long __int64;
#endif

// V5_COMPAT allows matlab version 5 compatible (obsolete in 6.5 and
// beyond) functions (like mxGetArray()...) in the source yielding one
// shared ptmatlab library. The alternative would be to have two source
// files depending on the matlab version or define our own mxGet wrapper
// macros that select the right one... Either way, Ptolemy would have to
// build and jar two versions of the DLL for webstart and
// ptolemy.matlab.Engine would have to know (via a java property?) which
// version of the ptmatlab shared library to load...
#define V5_COMPAT

#include <jni.h>
#include "ptmatlab.h"
#include "engine.h"

// The following test is a kludge for a missing #define in the matlab
// include files that would allow engine interface C code to test which
// matlab version it is dealing with... This is a test for an earlier
// matlab version (than 6p5 or later). NOTE that this test may be broken
// by subsequent matlab versions so we will need a ./configure - time
// matlab version determination eventually.
#if !defined(mxArray_DEFINED)
// Starting with matlab 6p5, logical variables (mxArrays) are using an
// mxLogical type and their class string returns "logical". However
// mxLogical is not defined in earlier matlab versions, so we define it
// here...
#define mxLogical char
#define mxGetLogicals(ma) mxGetPr(ma)
#endif

// Declare an integer type that correctly casts a pointer
typedef int ptrint;

#ifndef tmwtypes_h
typedef int mwSize;
typedef int mwIndex;
#endif

#include <stdio.h>
#include <stdlib.h>

extern "C"
{
  JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
    return JNI_VERSION_1_2;
  }

  static char ptmatlabGetDebug
  (JNIEnv *jni,
   jobject obj)
  {
    jfieldID debug = jni->GetFieldID(jni->GetObjectClass(obj), "debug", "B");
    return jni->GetByteField(obj, debug);
  }

  JNIEXPORT jlong JNICALL Java_ptolemy_matlab_Engine_ptmatlabEngOpen
  (JNIEnv *jni,
   jobject obj,
   jstring cmdString)
  {
    const char *cmd = NULL;
    jlong retval = 0;
    if (cmdString != NULL) cmd = jni->GetStringUTFChars(cmdString, 0);
    Engine *ep = engOpen(cmd); 
{'fraction_non_alphanumeric': 0.06521448616864894, 'fraction_numerical': 0.011492716824802886, 'mean_word_length': 3.7187894073139973, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '340229', 'n_tokens_mistral': 2322, 'n_tokens_neox': 2153, 'n_words': 994}