delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/01/27/13:37:58

To: DJGPP List <djgpp AT sun DOT soe DOT clarkson DOT edu>
Subject: Re: suppressing ctrl-c
Reply-To: pgf AT Cayman DOT COM
Date: Thu, 27 Jan 94 12:50:08 EST
From: Paul Fox <pgf AT Cayman DOT COM>

 > 
 >    > but i still can't figure out how to suppress ctrl-c.
 > 
 > As I remember it there's even a c function, setcbrk (), that can be used;
 > anyway that's what I did for Emacs.
 > 
 > When you are setting the Break mode (or the stdout mode) you should take
 > care to restore them before exiting; otherwise the next program may act
 > a little funny.
 > 

well, setcbrk(0) certainly does what i asked -- i no longer get killed
when there's no read outstanding.

i'm not quite happy with this, however.  i'd rather be informed via a
callback that the user has entered ctrl-c, much the way i can be informed
of ctrl-break when i use _go32_want_ctrl_break()/_go32_was_ctrl_break_hit().

is there any reason in principle that the following code shouldn't work?
it doesn't seem to.  is there something basically different between the
way ctrl-c and ctrl-break handlers are invoked, that i'm missing here?

(this was copied/edited directly from the code for the want/was_ctrl_break
routines.)

paul fox, pgf AT cayman DOT com


    #include <sys/types.h>
    #include <go32.h>
    #include <dpmi.h>
    #include <dos.h>

    static _go32_dpmi_registers regs;
    static volatile u_long ctrl_c_count = 0;
    static int ctrl_c_hooked = 0;
    static _go32_dpmi_seginfo old_vector;
    static _go32_dpmi_seginfo new_vector;

    u_long was_ctrl_c_hit();
    void   want_ctrl_c(int yes); /* auto-yes if call above function */

    static void ctrl_c_isr(_go32_dpmi_registers *regs)
    {
      ctrl_c_count ++;
    }

    u_long was_ctrl_c_hit()
    {
      u_long cnt;
      want_ctrl_c(1);
      cnt = ctrl_c_count;
      ctrl_c_count = 0;
      return cnt;
    }

    void want_ctrl_c(int yes)
    {
      if (yes)
      {
	if (ctrl_c_hooked)
	  return;
	_go32_dpmi_get_real_mode_interrupt_vector(0x23, &old_vector);

	new_vector.pm_offset = (int)ctrl_c_isr;
	_go32_dpmi_allocate_real_mode_callback_iret(&new_vector, &regs);
	_go32_dpmi_set_real_mode_interrupt_vector(0x23, &new_vector);
	ctrl_c_count = 0;
	ctrl_c_hooked = 1;
      }
      else
      {
	if (!ctrl_c_hooked)
	  return;
	_go32_dpmi_set_real_mode_interrupt_vector(0x23, &old_vector);
	_go32_dpmi_free_real_mode_callback(&new_vector);
	ctrl_c_count = 0;
	ctrl_c_hooked = 0;
      }
    }

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019