<commit_before>var fs = require('fs');

var semver = require('semver');

var FFI = require('ffi');
var ref = require('ref');

var types = require('./libvlc_types');
var MediaStatsPtr = types.MediaStatsPtr;
var ModuleDescriptionPtr = types.ModuleDescriptionPtr;
var TrackDescriptionPtr = types.TrackDescriptionPtr;

var check_library = function(p) {
  var l, v;

  try {
    l = new FFI.Library(p, {libvlc_get_version:['string',[]],});
    v = l.libvlc_get_version().split(' ')[0];
    if (semver.satisfies(v, '>= 2.0.1'))
      return l;
  } catch (e) {
    l = undefined;
  }

  return l;
};

exports.initialize = function(paths) {
  var i, p, l, v;

  for (i = 0; i < paths.length; i++) {
    p = paths[i];
    if (fs.existsSync(p)) {
      l = check_library(p);
      if (l)
        break;
    }
  }

  if (!l) {
    p = 'libvlc'
    check_library(p);
  }

  if (!l)
    throw new Error("Failed to find LibVLC >= 2.0.1, make sure it's installed and that you have set LIBRARY_PATHS");

  module.exports = new FFI.Library(p, {
    libvlc_errmsg: ['string', []],
    libvlc_clearerr: ['void', []],
    libvlc_vprinterr: ['string', ['string', 'pointer']],
    libvlc_printerr: ['string', ['string']],
    libvlc_new: ['pointer', ['int32', 'pointer']],
    libvlc_release: ['void', ['pointer']],
    libvlc_retain: ['void', ['pointer']],
    libvlc_add_intf: ['int32', ['pointer', 'string']],
    libvlc_set_exit_handler: ['void', ['pointer', 'pointer', 'pointer']],
    libvlc_wait: ['void', ['pointer']],
    libvlc_set_user_agent: ['void', ['pointer', 'string', 'string']],
    libvlc_get_version: ['string', []],
    libvlc_get_compiler: ['string', []],
    libvlc_get_changeset: ['string', []],
    libvlc_free: ['void', ['pointer']],
    libvlc_event_attach: ['int32', ['pointer', 'int32', 'pointer', ref.types.Object]],
    libvlc_event_detach: ['void', ['pointer', 'int32', 'pointer', ref.types.Object]],
    libvlc_event_type_name: ['string', ['int32']],
    libvlc_module_description_list_release: ['void', [ModuleDescriptionPtr]],<commit_msg>replaced ref.types.Object by 'pointer' to make lib work on event handler<commit_after>var fs = require('fs');

var semver = require('semver');

var FFI = require('ffi');
var ref = require('ref');

var types = require('./libvlc_types');
var MediaStatsPtr = types.MediaStatsPtr;
var ModuleDescriptionPtr = types.ModuleDescriptionPtr;
var TrackDescriptionPtr = types.TrackDescriptionPtr;

var check_library = function(p) {
  var l, v;

  try {
    l = new FFI.Library(p, {libvlc_get_version:['string',[]],});
    v = l.libvlc_get_version().split(' ')[0];
    if (semver.satisfies(v, '>= 2.0.1'))
      return l;
  } catch (e) {
    l = undefined;
  }

  return l;
};

exports.initialize = function(paths) {
  var i, p, l, v;

  for (i = 0; i < paths.length; i++) {
    p = paths[i];
    if (fs.existsSync(p)) {
      l = check_library(p);
      if (l)
        break;
    }
  }

  if (!l) {
    p = 'libvlc'
    check_library(p);
  }

  if (!l)
    throw new Error("Failed to find LibVLC >= 2.0.1, make sure it's installed and that you have set LIBRARY_PATHS");

  module.exports = new FFI.Library(p, {
    libvlc_errmsg: ['string', []],
    libvlc_clearerr: ['void', []],
    libvlc_vprinterr: ['string', ['string', 'pointer']],
    libvlc_printerr: ['string', ['string']],
    libvlc_new: ['pointer', ['int32', 'pointer']],
    libvlc_release: ['void', ['pointer']],
    libvlc_retain: ['void', ['pointer']],
    libvlc_add_intf: ['int32', ['pointer', 'string']],
    libvlc_set_exit_handler: ['void', ['pointer', 'pointer', 'pointer']],
    libvlc_wait: ['void', ['pointer']],
    libvlc_set_user_agent: ['void', ['pointer', 'string', 'string']],
    libvlc_get_version: ['string', []],
    libvlc_get_compiler: ['string', []],
    libvlc_get_changeset: ['string', []],
    libvlc_free: ['void', ['pointer']],
    libvlc_event_attach: ['int32', ['pointer', 'int32', 'pointer', 'pointer']],
    libvlc_event_detach: ['void', ['pointer', 'int32', 'pointer', 'pointer']],
    libvlc_event_type_name: ['string', ['int32']],
    libvlc_module_description_list_release: ['void', [ModuleDescriptionPtr]],
{'fraction_non_alphanumeric': 0.19773330118157703, 'fraction_numerical': 0.009645526886906198, 'mean_word_length': 4.114673242909988, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2793252', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1511, 'n_words': 335}