[comp.lang.modula2] JPI Modula-2 Bugs, and Exception Handling

toma@tekgvs.LABS.TEK.COM (Tom Almy) (10/24/90)

I received a letter acknoledging my bug report which I posted here recently.

As was obvious from looking at the code, it is possible to handle control-C
from within the program using the C language style signal facility that
is apparent from the library sources.

They sent an application note on how to do it. You need .DEF file that needs
to be cobbled from one in the Multi-Language Suppport Disk, but is repeated
in the note (the file needs to be renamed from the original, and seven
additional declarations are needed!).

I am including the copyrighted file here, since it is of no use to people
without TopSpeed Modula-2, and is available free for those with TopSpeed
Modula-2.


Tom Almy
toma@tekgvs.labs.tek.com
Standard Disclaimers Apply


file csignal.def:

(* Release 1.05 *)
(*--------------------------------------------------------------------------*
*                                                                           *
*  csignal.def - structure and function definitions for software signaling. *
*                                                                           *
*  COPYRIGHT (C) 1989, 1990 Jensen and Partners. All Rights Reserved        *
*                                                                           *
*---------------------------------------------------------------------------*)

DEFINITION MODULE csignal;

(*# call(o_a_size=>off, o_a_copy=>off, c_conv=>on, result_optional=>on) *)
(*# module(implementation=>off, init_code=>off) *)
(*# name(prefix=>c) *)

TYPE
    IntFunc = PROCEDURE(INTEGER);

CONST
    NSIG    = 23;  (* maximum signal number + 1 *)
    SIGINT  = 2;   (* interrupt - corresponds to DOS 3.x int 23H *)
    SIGILL  = 4;   (* illegal opcode *)
    SIGFPE  = 8;   (* floating point error *)
    SIGSEGV = 11;  (* segment violation *)
    SIGTERM = 15;  (* software termination signal from kill *)
    SIGUSR1 = 16;  (* user defined signal 1 *)
    SIGUSR2 = 17;  (* user defined signal 2 *)
    SIGUSR3 = 20;  (* user defined signal 3 *)
    SIGABRT = 22;  (* abnormal termination triggered by abort call *)

    (* signal action codes *)
    SIG_DFL = IntFunc(0);
    SIG_IGN = IntFunc(1);
    SIG_SGE = IntFunc(3);
    SIG_ACK = IntFunc(4);
    (* signal error value (returned by signal call on error) *)
    SIG_ERR = IntFunc(-1);

PROCEDURE raise(_sig: INTEGER);
PROCEDURE signal(_sig:INTEGER; func:IntFunc):IntFunc;

END csignal.



---------------------CUT HERE--------------------------


File exchand.mod (example program):


MODULE ExcHand;
  IMPORT IO, csignal;

  PROCEDURE Handler(sig:INTEGER);
    BEGIN
      IO.WrStr('Program reaches here if SIGINT raised or ctl C pressed');
      IO.WrLn;
      IO.WrStr('- Signal received was ');
      IO.WrInt(sig,0);
      IO.WrLn;
      HALT;
    END Handler;

  BEGIN
    IF csignal.signal(csignal.SIGINT,Handler) = csignal.SIG_ERR THEN
      IO.WrStr("Couldn't set SIGINT");
      IO.WrLn;
    END;
    IO.WrChar('?');
    IF CAP(IO.RdChar()) = 'S' THEN
      csignal.raise(csignal.SIGINT);
    END;
    IO.WrStr('Normal Termination');
    IO.WrLn;
  END ExcHand.