#ifndef _SIGNAL_H
#define _SIGNAL_H

/*
 * The <signal.h> header defines all the ANSI and POSIX signals.
 *
 * Some additional signals are also supported.
 *
 * AMENDMENT HISTORY
 * ~~~~~~~~~~~~~~~~~
 *  24 Jan 94   DJW   - Small changes made as required for the first real
 *                      implementation of signal support in C68.
 *
 *  24 Aug 95   DJW   - Incorporated changes required to support Richard
 *                      Zlidlicky signal routines.
 *                      In particular you can now define _OLDSIGNALDEF if you
 *                      want the old definitions, but otherwise the new
 *                      (more Unix SVR4 like) definitions are used.
 *
 *  20 Sep 95   DJW   - Moved routines that were previously in section that
 *                      was protected by __LIBRARY__ into the sys/signal.h 
 *                      header file instead.
 */

#ifndef _SYS_TYPES_H
#include <sys/types.h>
#endif

#ifndef NULL
#define NULL ((void *)0)
#endif

#ifdef __STDC__
#define _P_(params) params
#else
#define _P_(params)
#endif

/*
 *  Here are types that are closely associated with signal handling.
 */
typedef int sig_atomic_t;
#ifndef _SIGSET_T
#define _SIGSET_T
typedef unsigned long sigset_t;
#endif


#ifdef _OLDSIGNALDEF
/*
 *  Old definitions used before full signal support was
 *  provided by the C68 libraries.  Retained (temporarily)
 *  to help with any transition activities.
 */
#define SIGABRT            1    /* IOT instruction */
#define SIGALRM            2    /* alarm clock */
#define SIGFPE             3    /* floating point exception */
#define SIGHUP             4    /* hangup */
#define SIGILL             5    /* illegal instruction */
#define SIGINT             6    /* terminal interrupt (DEL) */
#define SIGKILL            7    /* kill (cannot be caught or ignored) */
#define SIGPIPE            8    /* write on a pipe with no one to read it */
#define SIGQUIT            9    /* quit (ASCII FS) */
#define SIGSEGV           10    /* segmentation violation */
#define SIGTERM           11    /* software termination signal from kill */
#define SIGUSR1           12    /* user defined signal # 1 */
#define SIGUSR2           13    /* user defined signal # 2 */

#define _NSIG             13    /* number of signals used */
#endif /* _OLDSIGNALDEF */

#ifndef _OLDSIGNALDEF
#define SIGHUP             1    /* hangup */
#define SIGINT             2    /* terminal interrupt (DEL) */
#define SIGQUIT            3    /* quit (ASCII FS) */
#define SIGILL             4    /* illegal instruction */
#define SIGPIPE            5    /* write on a pipe with no one to read it */
#define SIGSEGV            6    /* segement violation / illegal address */
#define SIGBUS             7    /* misaligned */
#define SIGFPE             8    /* floating point exception */
#define SIGKILL            9    /* kill (cannot be caught or ignored) */
#define SIGALRM           10    /* alarm clock */
#define SIGABRT           11    /* IOT instruction */
#define SIGTRACE          12
#define SIGWINCHD         13    /* window definition changed */
#define SIGWMREQ          14    /* wman callback */
#define SIGTERM           15    /* software termination signal from kill */
#define SIGUSR1           16    /* user defined signal # 1 */
#define SIGUSR2           17    /* user defined signal # 2 */

#define _NSIG             17    /* number of signals used */

#endif /* ! _OLDSIGNALDEF */

#define NSIG _NSIG

/*
 * POSIX requires the following signals to be defined, even if they are
 * not supported.  Here are the definitions, but they are not supported.
 */
#define SIGCHLD            0    /* child process terminated or stopped */
#define SIGCONT            0    /* continue if stopped */
#define SIGSTOP            0    /* stop signal */
#define SIGTSTP            0    /* interactive stop signal */
#define SIGTTIN            0    /* background process wants to read */
#define SIGTTOU            0    /* background process wants to write */

/*
 *  The following are signals that are not on the list defined by POSIX,
 *  but that some systems may try and use.  The constants are recognised,
 *  but they are not supported, and will have no effect.
 */
#ifndef _POSIX_SOURCE
#define SIGIOT             1    /* SIGABRT for people who speak PDP-11 */
#define SIGUNUSED          0    /* spare code */
#define SIGSTKFLT          0    /* used by kernel to indicate stack fault */
#define SIGTRAP            SIGTRACE    /* trace trap (not reset when caught) */
#define SIGEMT             0    /* obsolete */
#endif /* _POSIX_SOURCE */


#ifdef _POSIX_SOURCE
#define SA_NOCLDSTOP       1    /* signal parent if child stops */
#endif /* _POSIX_SOURCE */

/*
 *  POSIX requires these values for use on system calls involving signals.
 */
#define SIG_BLOCK          0    /* for blocking signals */
#define SIG_UNBLOCK        1    /* for unblocking signals */
#define SIG_SETMASK        2    /* for setting the signal mask */

/*
 *  Macros used as function pointers
 */

#define SIG_IGN     ((void (*)(int))0)  /* ignore signal */
#define SIG_DFL     ((void (*)(int))1)  /* default signal handling */
#define SIG_HOLD    ((void (*)(int))2) 
#define SIG_ERR     ((void (*)(int))-1)


struct sigaction {
  void (*sa_handler)_P_((int)); /* SIG_DFL, SIG_IGN, or pointer to function */
  sigset_t sa_mask;             /* signals to be blocked during handler */
  int sa_flags;                 /* special flags */
};
/* sigaction sa_flags:  */
#define SA_RESETHAND       0x1      /* reset to SIG_DFL while handling */

typedef char * caddr_t;

typedef struct {
    int     si_signo;           /* signal number */
    int     si_errno;           /* error number */
    int     si_code;            /* signal code */
    pid_t   si_pid;             /* sending process ID */
    uid_t   si_uid;             /* sending user ID */
    int     si_status;
    long    si_band;
    caddr_t si_addr;
    } siginfo_t;

/*
 *  Function Prototypes for POSIX defined routines
 */
int kill            _P_((pid_t, int));
int raise           _P_((int));
int sigaction       _P_((int, struct sigaction *,struct sigaction *));
int sigaddset       _P_((sigset_t *, int));
int sigdelset       _P_((sigset_t *, int));
int sigemptyset     _P_((sigset_t *));
int sigfillset      _P_((sigset_t *));
int sigismember     _P_((sigset_t *, int));
void (*signal       _P_((int, void (*)_P_((int)))))_P_((int));
int sigpending      _P_((sigset_t *));
int sigprocmask     _P_((int, sigset_t *, sigset_t *));
int sigsuspend      _P_((sigset_t *));
/*
 *  Function prototypes for Unix SVR4 routines
 */
void psignal        _P_((int, const char *));
void psiginfo       _P_((siginfo_t *, const char *));
int  sighold        _P_((int));
int  sigrelse       _P_((int));
int  sigignore      _P_((int));
int  sigpause       _P_((int));
void (*sigset       _P_((int , void (*)_P_((int)))))_P_((int));
/*
 *  Function prototypes of other signal related routines
 */
int fraise          _P_((int,int));
int raiseu          _P_((int,int));          /* takes extra uval arg */
int sigcleanup      _P_((void));

#undef _P_

#endif /* _SIGNAL_H */

