<commit_before>/**************************************************************************
/* Readline.java -- Java wrapper of GNU readline
/*
/* Java Wrapper Copyright (c) 1998-2001 by <NAME> (<EMAIL>)
/*
/* This program is free software; you can redistribute it and/or modify
/* it under the terms of the GNU Library General Public License as published
/* by  the Free Software Foundation; either version 2 of the License or
/* (at your option) any later version.
/*
/* This program is distributed in the hope that it will be useful, but
/* WITHOUT ANY WARRANTY; without even the implied warranty of
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
/* GNU Library General Public License for more details.
/*
/* You should have received a copy of the GNU Library General Public License
/* along with this program; see the file COPYING.LIB.  If not, write to
/* the Free Software Foundation Inc., 59 Temple Place - Suite 330,
/* Boston, MA  02111-1307 USA
/**************************************************************************/

package org.gnu.readline;

import java.io.*;

/**
 This class implements basic functionality of the GNU-readline interface. It
 uses native method calls and might therefore not be portable to other 
 platforms.

 @version $Revision: 1.8 $
 @author  $Author: Bablokb $
*/

public class Readline {
  
  private static ReadlineCompleter iCompleter = null;

  static {
    System.loadLibrary("JavaReadline");
  }

  /**
     Initialize the GNU-Readline library. This will also set the
     application name, which can be used in the initialization files of
     Readline (usually /etc/inputrc and ~/.inputrc) to define application
     specific keys. See the file ReadlineTest.java int the test subdir of
     the distribution for an example.

     @param applicationName Name of application in initialization file
  */

  public native static void initReadline(String applicationName);

  /**
     Display a prompt on standard output and read a string from
     standard input. This method throws an EOFException on end-of-file (C-d).

     @param prompt Prompt to display
     @return The string the user entered
  */

  public native static String readline(String prompt)
                              throws EOFException, UnsupportedEncodingException;

  /**
     Read keybindings and variable assignments from a file. This method is a
     wrapper to rl_read_init_file(char *filename). Throws IOException if 
     something goes wrong.

     @param filename Name of file to read bindings from
     @return void
  */

  public native static void readInitFile(String filename) throws IOException;

  /**
     Parse argument string as if it had been read from `inputrc' file
     and perform key bindings and variable assignments found.

     @param line Simulated line from inputrc file
     @return boolean False in case of error
  */

  public native static boolean parseAndBind(String line);

  /**
     Reads a history file into memory
       @param filename Name of history file to read
     */

  public native static void readHistoryFile(String filename)
                              throws EOFException, UnsupportedEncodingException;

  /**
     Writes a history file to disc

     @param filename Name of history file to write
  */

  public native static void writeHistoryFile(String filename)
                              throws EOFException, UnsupportedEncodingException;

  /**
     Set your completer function.

     @param rlc An object implementing the ReadlineCompleter interface
  */
    
  public static void setCompleter(ReadlineCompleter rlc) {
    iCompleter = rlc;
    installCompleter(rlc);
  }

  /**
     Query current completer function.

     @return Current ReadlineCompleter object
  */
    
  public static ReadlineCompleter getCompleter() {
    return iCompleter;
  }

  /**
     Installs your completer function.

     @param readlinecompleter An object which implements the 
     ReadlineCompleter interface
  */
    
  private native static void installCompleter(ReadlineCompleter rlc);
    
  /**
     Query word break characters.
  */
    
  public native static String getWordBreakCharacters();

  /**
     Set word break characters.

     @param wordBreakCharacters A string of word break characters
  */
    
  public native static void 
    setWordBreakCharacters(String wordBreakCharacters)
                              throws UnsupportedEncodingException;

}<commit_msg>- made all native methods private and renamed to *Impl - implemented simple fallback solution<commit_after>/**************************************************************************
/* Readline.java -- Java wrapper of GNU readline
/*
/* Java Wrapper Copyright (c) 1998-2001 by <NAME> (<EMAIL>)
/*
/* This program is free software; you can redistribute it and/or modify
/* it under the terms of the GNU Library General Public License as published
/* by  the Free Software Foundation; either version 2 of the License or
/* (at your option) any later version.
/*
/* This program is distributed in the hope that it will be useful, but
/* WITHOUT ANY WARRANTY; without even the implied warranty of
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
/* GNU Library General Public License for more details.
/*
/* You should have received a copy of the GNU Library General Public License
/* along with this program; see the file COPYING.LIB.  If not, write to
/* the Free Software Foundation Inc., 59 Temple Place - Suite 330,
/* Boston, MA  02111-1307 USA
/**************************************************************************/

package org.gnu.readline;

import java.io.*;

/**
 This class implements basic functionality of the GNU-readline interface. It
 uses native method calls if available, otherwise it defaults to normal
 I/O using a BufferedReader. 

 @version $Revision: 1.9 $
 @author  $Author: Bablokb $
*/

public class Readline {
  
  /**
     The currently defined ReadlineCompleter.
  */

  private static ReadlineCompleter iCompleter = null;


  /**
     The currently implementing backing library.
  */

  private static ReadlineLibrary iLib = ReadlineLibrary.PureJava;

  /**
     The BufferedReader for the fallback solution.
  */

  private static BufferedReader iReader = null;

  /////////////////////////////////////////////////////////////////////////////

  /**
     Load an implementing backing library.
  */

  public static final void load(ReadlineLibrary lib) {
    if (lib == iLib)     // ok, since objects are immutable
      return;
    if (lib == ReadlineLibrary.PureJava) {
      iLib = lib;
      return;
    }
    System.loadLibrary(lib.getName()); // might throw UnsatisfiedLinkError
    iLib = lib;
  }

  /////////////////////////////////////////////////////////////////////////////

  /**
     Initialize the GNU-Readline library. This will also set the
     application name, which can be used in the initialization files of
     Readline (usually /etc/inputrc and ~/.inputrc) to define application
     specific keys. See the file ReadlineTest.java int the test subdir of
     the distribution for an example.

     @param applicationName Name of application in initialization file
  */

  public static void initReadline(String applicationName) {
    if (iLib != ReadlineLibrary.PureJava)
      initReadlineImpl(applicationName);
  }

  /////////////////////////////////////////////////////////////////////////////

  /**
     Display a prompt on standard output and read a string from
     standard input. This method throws an EOFException on end-of-file (C-d).

     @param prompt Prompt to display
     @return The string the user entered
  */

  public static String readline(String prompt)
                            throws IOException, UnsupportedEncodingException {
    if (iLib != ReadlineLibrary.PureJava)
      return readlineImpl(prompt);
    else {
      System.out.print(prompt);
      if (iReader == null)
	iReader = new BufferedReader(new InputStreamReader(System.in));
      String line = iReader.readLine();
      return line;
    }
  }

  /////////////////////////////////////////////////////////////////////////////

  /**
     Read keybindings and variable assignments from a file. This method is a
     wrapper to rl_read_init_file(char *filename). Throws IOException if 
     something goes wrong.

     @param filename Name of file to read bindings from
     @return void
  */

  public static void readInitFile(String filename) throws IOException {
    if (iLib != ReadlineLibrary.PureJava)
      readInitFileImpl(filename);
  }

  /////////////////////////////////////////////////////////////////////////////

  /**
     Parse argument string as if it had been read from `inputrc' file
     and perform key bindings and variable assignments found.

     @param line Simulated line from inputrc file
     @return boolean False in case of error
  */

  public static boolean parseAndBind(String line) {
    if (iLib != ReadlineLibrary.PureJava)
      return parseAndBindImpl(line);
    else
      return true;
  }

  /////////////////////////////////////////////////////////////////////////////

  /**
     Reads a history file into memory
       @param filename Name of history file to read
     */

  public static void readHistoryFile(String filename)
                              throws EOFException, UnsupportedEncodingException {
    if (iLib != ReadlineLibrary.PureJava)
      readHistoryFileImpl(filename);
  }


  /////////////////////////////////////////////////////////////////////////////

  /**
     Writes a history file to disc

     @param filename Name of history file to write
  */

  public static void writeHistoryFile(String filename)
                              throws EOFException, UnsupportedEncodingException {
    if (iLib != ReadlineLibrary.PureJava)
      writeHistoryFileImpl(filename);
  }


  /////////////////////////////////////////////////////////////////////////////

  /**
     Set your completer function.

     @param rlc An object implementing the ReadlineCompleter interface
  */
    
  public static void setCompleter(ReadlineCompleter rlc) {
    if (iLib != ReadlineLibrary.PureJava) {
      iCompleter = rlc;
      setCompleterImpl(rlc);
    }
  }

  /////////////////////////////////////////////////////////////////////////////

  /**
     Query current completer function.

     @return Current ReadlineCompleter object
  */
    
  public static ReadlineCompleter getCompleter() {
    return iCompleter;
  }

  /////////////////////////////////////////////////////////////////////////////

  /**
     Query word break characters.
  */
    
  public static String getWordBreakCharacters() {
    if (iLib != ReadlineLibrary.PureJava)
      return getWordBreakCharactersImpl();
    else
      return null;
  }

  /////////////////////////////////////////////////////////////////////////////

  /**
     Set word break characters.

     @param wordBreakCharacters A string of word break characters
  */
    
  public static void 
    setWordBreakCharacters(String wordBreakCharacters)
                              throws UnsupportedEncodingException {
    if (iLib != ReadlineLibrary.PureJava)
      setWordBreakCharactersImpl(wordBreakCharacters);
  }

  /////////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////////

  /**
     Native implementation of initReadline()

     @see org.gnu.readline.Readline#initReadline(String applicationName)
  */

  private native static void initReadlineImpl(String applicationName);

  /////////////////////////////////////////////////////////////////////////////

  /**
     Native implementation of readline()

     @see org.gnu.readline.Readline#readline(String prompt)
  */

  private native static String readlineImpl(String prompt)
                              throws EOFException, UnsupportedEncodingException;

  /////////////////////////////////////////////////////////////////////////////

  /**
     Native implementation of readInitFile(String filename)

     @see org.gnu.readline.Readline#readInitFile(String filename)
  */

  private native static void readInitFileImpl(String filename)
                                                            throws IOException;

  /////////////////////////////////////////////////////////////////////////////

  /**
     Native implementation of parseAndBind(String line)

     @see org.gnu.readline.Readline#parseAndBind(String line)
  */

  private native static boolean parseAndBindImpl(String line);

  /////////////////////////////////////////////////////////////////////////////

  /**
     Native implementation of readHistoryFile(String filename)

     @see org.gnu.readline.Readline#readHistoryFile(String filename)
  */

  private native static void readHistoryFileImpl(String filename)
                              throws EOFException, UnsupportedEncodingException;

  /////////////////////////////////////////////////////////////////////////////

  /**
     Native implementation of writeHistoryFile(String filename)

     @see org.gnu.readline.Readline#writeHistoryFile(String filename)
  */

  private native static void writeHistoryFileImpl(String filename)
                              throws EOFException, UnsupportedEncodingException;

  /////////////////////////////////////////////////////////////////////////////

  /**
     Native implementation of setCompleter(ReadlineCompleter rlc)

     @see org.gnu.readline.Readline#setCompleter(ReadlineCompleter rlc)
  */
    
  private native static void setCompleterImpl(ReadlineCompleter rlc);
    
  /////////////////////////////////////////////////////////////////////////////

  /**
     Native implementation of getWordBreakCharacters()

     @see org.gnu.readline.Readline#getWordBreakCharacters()
  */

  private native static String getWordBreakCharactersImpl();

  /////////////////////////////////////////////////////////////////////////////

  /**
     Native implementation of setWordBreakCharacters()

     @see 
   org.gnu.readline.Readline#setWordBreakCharacters(String wordBreakCharacters)
  */

  private native static void 
    setWordBreakCharactersImpl(String wordBreakCharacters)
                              throws UnsupportedEncodingException;
}
{'fraction_non_alphanumeric': 0.19104498463257893, 'fraction_numerical': 0.003492595697122101, 'mean_word_length': 1.9501339377704512, 'pattern_counts': {'":': 0, '<': 7, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2996188', 'n_tokens_mistral': 3391, 'n_tokens_neox': 3208, 'n_words': 1206}