<commit_before>/*
    Simple Console input
    Copyright (C) 1998-2000 by <NAME>

    This library 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 library 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 library; if not, write to the Free
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "cssysdef.h"
#include "csconin.h"
#include "csutil/util.h"
#include "ivaria/conout.h"
#include "isys/system.h"
#include "isys/event.h"

IMPLEMENT_IBASE (csConsoleInput)
  IMPLEMENTS_INTERFACE (iConsoleInput)
  IMPLEMENTS_EMBEDDED_INTERFACE (iPlugIn)
IMPLEMENT_IBASE_END

IMPLEMENT_EMBEDDED_IBASE (csConsoleInput::eiPlugIn)
  IMPLEMENTS_INTERFACE (iPlugIn)
IMPLEMENT_EMBEDDED_IBASE_END

IMPLEMENT_FACTORY (csConsoleInput)

EXPORT_CLASS_TABLE (csconin)
  EXPORT_CLASS (csConsoleInput, "crystalspace.console.input.standard",
    "Crystal Space standard input console")
EXPORT_CLASS_TABLE_END

csConsoleInput::csConsoleInput (iBase *iParent) : History (16, 16)
{
  CONSTRUCT_IBASE (iParent);
  CONSTRUCT_EMBEDDED_IBASE(scfiPlugIn);
  Callback = NULL;
  Console = NULL;
  Prompt = NULL;
  CursorPos = 0;
  Prompt = strnew ("# ");
  PromptLen = strlen(Prompt);
  HistoryPos = 0;
  History.Push (strnew (""));
  line = new char [linemax = 80];
  InsertMode = true;
  MaxLines = 50;
}

csConsoleInput::~csConsoleInput ()
{
  delete [] Prompt;
  if (Console)
  {
    Console->DecRef ();
    Console->RegisterPlugin (NULL);
  }
}

bool csConsoleInput::Initialize (iSystem *iSys)
{
  // It is not necessary to call System->CallOnEvents since application
  // will usually pass events to us directly.
  (void)iSys;
  return true;
}

bool csConsoleInput::HandleEvent (iEvent &Event)
{
  switch (Event.Type)
  {
    case csevBroadcast:
      if (Event.Command.Code == cscmdConsoleStatusChange)
        Refresh ();
      return true;
    case csevKeyDown:
      switch (Event.Key.Code)
      {<commit_msg>Fixed runtime memory reference error under windows.<commit_after>/*
    Simple Console input
    Copyright (C) 1998-2000 by <NAME>

    This library 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 library 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 library; if not, write to the Free
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "cssysdef.h"
#include "csconin.h"
#include "csutil/util.h"
#include "ivaria/conout.h"
#include "isys/system.h"
#include "isys/event.h"

IMPLEMENT_IBASE (csConsoleInput)
  IMPLEMENTS_INTERFACE (iConsoleInput)
  IMPLEMENTS_EMBEDDED_INTERFACE (iPlugIn)
IMPLEMENT_IBASE_END

IMPLEMENT_EMBEDDED_IBASE (csConsoleInput::eiPlugIn)
  IMPLEMENTS_INTERFACE (iPlugIn)
IMPLEMENT_EMBEDDED_IBASE_END

IMPLEMENT_FACTORY (csConsoleInput)

EXPORT_CLASS_TABLE (csconin)
  EXPORT_CLASS (csConsoleInput, "crystalspace.console.input.standard",
    "Crystal Space standard input console")
EXPORT_CLASS_TABLE_END

csConsoleInput::csConsoleInput (iBase *iParent) : History (16, 16)
{
  CONSTRUCT_IBASE (iParent);
  CONSTRUCT_EMBEDDED_IBASE(scfiPlugIn);
  Callback = NULL;
  Console = NULL;
  Prompt = NULL;
  CursorPos = 0;
  Prompt = strnew ("# ");
  PromptLen = strlen(Prompt);
  HistoryPos = 0;
  History.Push (strnew (""));
  line = new char [linemax = 80];
  InsertMode = true;
  MaxLines = 50;
}

csConsoleInput::~csConsoleInput ()
{
  delete [] Prompt;

  if (Console)
  {
    Console->DecRef ();
  }
}

bool csConsoleInput::Initialize (iSystem *iSys)
{
  // It is not necessary to call System->CallOnEvents since application
  // will usually pass events to us directly.
  (void)iSys;
  return true;
}

bool csConsoleInput::HandleEvent (iEvent &Event)
{
  switch (Event.Type)
  {
    case csevBroadcast:
      if (Event.Command.Code == cscmdConsoleStatusChange)
        Refresh ();
      return true;
    case csevKeyDown:
      switch (Event.Key.Code)
      {
{'fraction_non_alphanumeric': 0.08656036446469248, 'fraction_numerical': 0.011182439428453097, 'mean_word_length': 3.989669421487603, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '3736917', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1533, 'n_words': 490}