<commit_before>/////////////////////////////////////////////////////////////////////////
// $Id: term.cc,v 1.35 2006/03/05 10:24:29 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
//  Copyright (C) 2000  MandrakeSoft S.A.
//
//    MandrakeSoft S.A.
//    43, rue d'Aboukir
//    75002 Paris - France
//    http://www.linux-mandrake.com/
//    http://www.mandrakesoft.com/
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser 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
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA



// Define BX_PLUGGABLE in files that can be compiled into plugins.  For
// platforms that require a special tag on exported symbols, BX_PLUGGABLE 
// is used to know when we are exporting symbols and when we are importing.
#define BX_PLUGGABLE

#include "bochs.h"
#include "iodev.h"
#if BX_WITH_TERM

#include "icon_bochs.h"

extern "C" {
#include <curses.h>
#include <signal.h>
};

class bx_term_gui_c : public bx_gui_c {
public:
  bx_term_gui_c (void) {}
  DECLARE_GUI_VIRTUAL_METHODS()
#if BX_USE_IDLE_HACK
  virtual void sim_is_idle(void);
#endif

  virtual Bit32u get_sighandler_mask ();
  // called when registered signal arrives
  virtual void sighandler (int sig);
};

// declare one instance of the gui object and call macro to insert the
// plugin code
static bx_term_gui_c *theGui = NULL;
IMPLEMENT_GUI_PLUGIN_CODE(term)

#define LOG_THIS theGui->

bx_bool initialized = 0;
static unsigned int text_cols = 80, text_rows = 25;

static short curses_color[8] = {
  /* 0 */ COLOR_BLACK,
  /* 1 */ COLOR_BLUE,
  /* 2 */ COLOR_GREEN,
  /* 3 */ COLOR_CYAN,
  /* 4 */ COLOR_RED,
  /* 5 */ COLOR_MAGENTA,
  /* 6 */ COLOR_YELLOW,
  /* 7 */ COLOR_WHITE
};

static chtype vga_to_term[128] = {
  0xc7, 0xfc, 0xe9, 0xe2, 0xe4, 0xe0, 0xe5, 0xe7,
  0xea, 0xeb, 0xe8, 0xef, 0xee, 0xec, 0xc4, 0xc5,
  0xc9, 0xe6, 0xc6, 0xf4, 0xf6, 0xf2, 0xfb, 0xf9,
  0xff, 0xd6, 0xdc, 0xe7, 0xa3, 0xa5, ' ',  ' ',
  0xe1, 0xed, 0xf3, 0xfa, 0xf1, 0xd1, 0xaa, 0xba,
  0xbf, ' ',  0xac, ' ',  ' ',  0xa1, 0xab, 0xbb,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, ' ',  ' ',  ' ',  ' ',
  ' ',  ' ',  ' ',  ' ',  ' ',  ' ',  0xb5, ' ',
  ' ',  ' ',  ' ',  ' ',  ' ',  ' ',  ' ',  ' ',
  ' ',  0xb1, ' ',  ' ',  ' ',  ' ',  0xf7, ' ',
  0xb0, ' ',  ' ',  ' ',  ' ',  0xb2, ' ',  ' '
};

static void
do_scan(int key_event, int shift, int ctrl, int alt)
{
	/* XXX At some point, cache alt/ctrl/shift so only when the state
		 changes do we simulate a press or release, to cut down on
		 keyboard input to the simulated machine */

	BX_DEBUG(("key_event %d/0x%x %s%s%s",
		  key_event,key_event,
		  shift?"(shift)":"",
		  ctrl?"(ctrl)":"",
		  alt?"(alt)":""));
	if(shift)
		DEV_kbd_gen_scancode(BX_KEY_SHIFT_L);
	if(ctrl)
		DEV_kbd_gen_scancode(BX_KEY_CTRL_L);
	if(alt)
		DEV_kbd_gen_scancode(BX_KEY_ALT_L);
	DEV_kbd_gen_scancode(key_event);
	key_event |= BX_KEY_RELEASED;

	DEV_kbd_gen_scancode(key_event);
	if(alt)
		DEV_kbd_gen_scancode(BX_KEY_ALT_L|BX_KEY_RELEASED);
	if(ctrl)
		DEV_kbd_gen_scancode(BX_KEY_CTRL_L|BX_KEY_RELEASED);
	if(shift)
		DEV_kbd_gen_scancode(BX_KEY_SHIFT_L|BX_KEY_RELEASED);
}

Bit32u 
bx_term_gui_c::get_sighandler_mask ()
{
  return 
    (1<<SIGHUP)
    | (1<<SIGINT)
    | (1<<SIGQUIT)
#ifdef SIGSTOP
    | (1<<SIGSTOP)
#endif
#ifdef SIGTSTP
    | (1<<SIGTSTP)
#endif
    | (1<<SIGTERM);
}

void
bx_term_gui_c::sighandler(int signo)
{
	switch(signo) {
	case SIGINT:
		do_scan(BX_KEY_C,0,1,0);
		break;
#ifdef SIGSTOP
	case SIGSTOP:
		do_scan(BX_KEY_S,0,1,0);
		break;
#endif
#ifdef SIGTSTP
	case SIGTSTP:
		do_scan(BX_KEY_Z,0,1,0);
		break;
#endif
	default:
		BX_INFO(("sig %d caught",signo));
		break;
	}
}

// ::SPECIFIC_INIT()
//
// Called from gui.cc, once upon program startup, to allow for the
// specific GUI code (X11, BeOS, ...) to be initialized.
//
// argc, argv: not used right now, but the intention is to pass native GUI
//     specific options from the command line.  (X11 options, BeOS options,...)
//
// tilewidth, tileheight: for optimization, graphics_tile_update() passes
//     only updated regions of the screen to the gui code to be redrawn.
//     These define the dimensions of a region (tile).
// headerbar_y:  A headerbar (toolbar) is display on the top of the
//     VGA window, showing floppy status, and other information.  It
//     always assumes the width of the current VGA mode width, but
//     it's height is defined by this parameter.

	void
bx_term_gui_c::specific_init(int argc, char **argv, unsigned tilewidth, unsigned tileheight,
	unsigned headerbar_y)<commit_msg>- Bochs with 'term' gui now quits when the terminal is closed (SIGHUP)<commit_after>/////////////////////////////////////////////////////////////////////////
// $Id: term.cc,v 1.36 2006/08/30 18:16:36 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
//  Copyright (C) 2000  MandrakeSoft S.A.
//
//    MandrakeSoft S.A.
//    43, rue d'Aboukir
//    75002 Paris - France
//    http://www.linux-mandrake.com/
//    http://www.mandrakesoft.com/
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser 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
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA



// Define BX_PLUGGABLE in files that can be compiled into plugins.  For
// platforms that require a special tag on exported symbols, BX_PLUGGABLE 
// is used to know when we are exporting symbols and when we are importing.
#define BX_PLUGGABLE

#include "bochs.h"
#include "iodev.h"
#if BX_WITH_TERM

#include "icon_bochs.h"

extern "C" {
#include <curses.h>
#include <signal.h>
};

class bx_term_gui_c : public bx_gui_c {
public:
  bx_term_gui_c (void) {}
  DECLARE_GUI_VIRTUAL_METHODS()
#if BX_USE_IDLE_HACK
  virtual void sim_is_idle(void);
#endif

  virtual Bit32u get_sighandler_mask ();
  // called when registered signal arrives
  virtual void sighandler (int sig);
};

// declare one instance of the gui object and call macro to insert the
// plugin code
static bx_term_gui_c *theGui = NULL;
IMPLEMENT_GUI_PLUGIN_CODE(term)

#define LOG_THIS theGui->

bx_bool initialized = 0;
static unsigned int text_cols = 80, text_rows = 25;

static short curses_color[8] = {
  /* 0 */ COLOR_BLACK,
  /* 1 */ COLOR_BLUE,
  /* 2 */ COLOR_GREEN,
  /* 3 */ COLOR_CYAN,
  /* 4 */ COLOR_RED,
  /* 5 */ COLOR_MAGENTA,
  /* 6 */ COLOR_YELLOW,
  /* 7 */ COLOR_WHITE
};

static chtype vga_to_term[128] = {
  0xc7, 0xfc, 0xe9, 0xe2, 0xe4, 0xe0, 0xe5, 0xe7,
  0xea, 0xeb, 0xe8, 0xef, 0xee, 0xec, 0xc4, 0xc5,
  0xc9, 0xe6, 0xc6, 0xf4, 0xf6, 0xf2, 0xfb, 0xf9,
  0xff, 0xd6, 0xdc, 0xe7, 0xa3, 0xa5, ' ',  ' ',
  0xe1, 0xed, 0xf3, 0xfa, 0xf1, 0xd1, 0xaa, 0xba,
  0xbf, ' ',  0xac, ' ',  ' ',  0xa1, 0xab, 0xbb,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, ' ',  ' ',  ' ',  ' ',
  ' ',  ' ',  ' ',  ' ',  ' ',  ' ',  0xb5, ' ',
  ' ',  ' ',  ' ',  ' ',  ' ',  ' ',  ' ',  ' ',
  ' ',  0xb1, ' ',  ' ',  ' ',  ' ',  0xf7, ' ',
  0xb0, ' ',  ' ',  ' ',  ' ',  0xb2, ' ',  ' '
};

static void
do_scan(int key_event, int shift, int ctrl, int alt)
{
	/* XXX At some point, cache alt/ctrl/shift so only when the state
		 changes do we simulate a press or release, to cut down on
		 keyboard input to the simulated machine */

	BX_DEBUG(("key_event %d/0x%x %s%s%s",
		  key_event,key_event,
		  shift?"(shift)":"",
		  ctrl?"(ctrl)":"",
		  alt?"(alt)":""));
	if(shift)
		DEV_kbd_gen_scancode(BX_KEY_SHIFT_L);
	if(ctrl)
		DEV_kbd_gen_scancode(BX_KEY_CTRL_L);
	if(alt)
		DEV_kbd_gen_scancode(BX_KEY_ALT_L);
	DEV_kbd_gen_scancode(key_event);
	key_event |= BX_KEY_RELEASED;

	DEV_kbd_gen_scancode(key_event);
	if(alt)
		DEV_kbd_gen_scancode(BX_KEY_ALT_L|BX_KEY_RELEASED);
	if(ctrl)
		DEV_kbd_gen_scancode(BX_KEY_CTRL_L|BX_KEY_RELEASED);
	if(shift)
		DEV_kbd_gen_scancode(BX_KEY_SHIFT_L|BX_KEY_RELEASED);
}

Bit32u 
bx_term_gui_c::get_sighandler_mask ()
{
  return 
    (1<<SIGHUP)
    | (1<<SIGINT)
    | (1<<SIGQUIT)
#ifdef SIGSTOP
    | (1<<SIGSTOP)
#endif
#ifdef SIGTSTP
    | (1<<SIGTSTP)
#endif
    | (1<<SIGTERM);
}

void
bx_term_gui_c::sighandler(int signo)
{
  switch(signo) {
    case SIGINT:
      do_scan(BX_KEY_C,0,1,0);
      break;
#ifdef SIGSTOP
    case SIGSTOP:
      do_scan(BX_KEY_S,0,1,0);
      break;
#endif
#ifdef SIGTSTP
    case SIGTSTP:
      do_scan(BX_KEY_Z,0,1,0);
      break;
#endif
    case SIGHUP:
      BX_PANIC(("Received SIGHUP: quit simulation"));
      break;
    default:
      BX_INFO(("sig %d caught",signo));
      break;
  }
}

// ::SPECIFIC_INIT()
//
// Called from gui.cc, once upon program startup, to allow for the
// specific GUI code (X11, BeOS, ...) to be initialized.
//
// argc, argv: not used right now, but the intention is to pass native GUI
//     specific options from the command line.  (X11 options, BeOS options,...)
//
// tilewidth, tileheight: for optimization, graphics_tile_update() passes
//     only updated regions of the screen to the gui code to be redrawn.
//     These define the dimensions of a region (tile).
// headerbar_y:  A headerbar (toolbar) is display on the top of the
//     VGA window, showing floppy status, and other information.  It
//     always assumes the width of the current VGA mode width, but
//     it's height is defined by this parameter.

	void
bx_term_gui_c::specific_init(int argc, char **argv, unsigned tilewidth, unsigned tileheight,
	unsigned headerbar_y)
{'fraction_non_alphanumeric': 0.15537776161469224, 'fraction_numerical': 0.05364124011273752, 'mean_word_length': 3.0248810830589097, 'pattern_counts': {'":': 6, '<': 31, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '3454570', 'n_tokens_mistral': 4797, 'n_tokens_neox': 4353, 'n_words': 1194}