
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>

#include "lutil_api.h"
#include "licor8xx-shared.h"
#include "cwg-shared.h"
#include "iowfile.h"

/// @fn void s_termination_handler (int signum)
/// @brief termination signal handler.
/// @param[in] signum signal number
/// @return none
static void s_termination_handler (int signum)
{
    switch (signum) {
#if ! defined(__WIN32) && ! defined(__WIN64)
        case SIGHUP:
#endif
        case SIGINT:
        case SIGTERM:
            fprintf(stderr,"\nsig received[%d]\n",signum);
            g_logutils_interrupt=true;
            break;
        default:
            fprintf(stderr,"\ns_termination_handler: sig not handled[%d]\n",signum);
            break;
    }
}
// End function termination_handler

int main(int argc, char **argv)
{
    int retval=-1;

#if defined(__WIN32) || defined(__WIN64)
    signal(SIGINT,s_termination_handler);
#else
    // configure signal handling
    // for main thread
    struct sigaction saStruct;

    sigemptyset(&saStruct.sa_mask);
    saStruct.sa_flags = 0;
    saStruct.sa_handler = s_termination_handler;
    sigaction(SIGINT, &saStruct, NULL);
#endif

#ifdef WITH_DQUTIL
    retval=( lutil_dqutil(argc,argv)==0 ? ERR_SUCCESS : ERR_FAILURE);
#else
    OUT_CTTY("%s - not implemented (compile using WITH_DQUTIL)\r\n",argv[0]);
#endif //WITH_DQUTIL

    return retval;
}
