/* 
 *      s i g i n i t
 *
 *  Routine used to initialise the signal handling system
 *
 *  AMENDMENT HISTORY
 *  ~~~~~~~~~~~~~~~~~
 *  25 Oct 95   DJW   - Merged in the 'checksig_c' file as part of structuring
 *                      routines so that a dummy version is called instead if
 *                      signal handling is suppressed by the programmer.
 *
 *  03 Jan 96   DJW   - Added error handling if signal handler absent.
 */

#define __LIBRARY__

#include <signal.h>
#include <sys/signal.h>
#include <sms.h>
#include <qdos.h>
#include <stdio.h>

extern  char *  _SPbase;

/*
 *  Signal handler initialisation
 */

void _Signals_Init _LIB_F0_ (void)
{
    _sigh.stackmin=_SPbase;
    _sigh.priority.prio=_defsigrp;

    _sigch = io_open("*SIGNAL_R",(long)&_sigh);

#ifdef DEBUG
    _sigdebugch=io_open("con_",0);
    sigprintf("handler address : %d, channel %d\n",&_sigh,_sigch);
#endif
    if (_sigch < 0) {
        (void) _SigNoImp(0);
        if (__SigNoCnt < -1) {
            (void) sms_frjb (-1,++__SigNoCnt);
        }
    }
    return;
}

/*
 *  Support routine used within signal implementation for C68
 */

int _CheckSig _LIB_F0_(void)
{
#ifdef DEBUG
   sigprintf("calling _CheckSig\n");
#endif
    return (*_sigh.sigvec)(_sigch,6);
}


