Update the changelog
[opencv] / apps / Hawk / eicio.cpp
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 //  By downloading, copying, installing or using the software you agree to this license.
6 //  If you do not agree to this license, do not download, install,
7 //  copy or use the software.
8 //
9 //
10 //                        Intel License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 //   * Redistribution's of source code must retain the above copyright notice,
20 //     this list of conditions and the following disclaimer.
21 //
22 //   * Redistribution's in binary form must reproduce the above copyright notice,
23 //     this list of conditions and the following disclaimer in the documentation
24 //     and/or other materials provided with the distribution.
25 //
26 //   * The name of Intel Corporation may not be used to endorse or promote products
27 //     derived from this software without specific prior written permission.
28 //
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
39 //
40 //M*/#include "stdafx.h"
41
42 #include "Hawk.h"
43 #include <stdarg.h>
44 #include "eicio.h"
45 #include <stdio.h>
46
47 #include <stdio.h>
48 #include <ctype.h>
49 #include <string.h>
50 #include <stdlib.h>
51 #include <math.h>
52 #include <stdarg.h>
53 #include <signal.h>
54
55 //#include "..\..\..\src\eicio.h"
56
57 #pragma warning(disable:4273)
58
59 #include "..\module\stdClib\src\stdliblocal.h"
60 #include "hawkwrap.h"
61
62 static errlevel_t errlevel = unsafe;
63 static jmp_buf* errmark = NULL;
64
65 void set_eic_errlevel(errlevel_t level)
66 {
67     errlevel = level;
68 }
69
70 void set_eic_mark(jmp_buf* mark)
71 {
72     errmark = mark;
73 }
74
75 extern "C"
76 {
77 extern unsigned int EiC_CurrentLine;
78 extern char *EiC_CurrentFile;
79 }
80
81 void raiseio(int sig)
82 {
83     char buf[1024];
84     sprintf(buf, "Signal with code %d has been raised by EiC in %s, line %d.\nAborting script execution...", 
85         sig, EiC_CurrentFile, EiC_CurrentLine);
86     init_signal_handlers();
87 #ifdef HAWK_TEST
88     WRAP_THROW_MESSAGE(errmark, buf);
89 #else
90     // Redirect the signal to EiC
91     switch(sig)
92     {
93     case SIGABRT:
94     case SIGFPE:
95     case SIGSEGV:
96     case SIGINT:
97         {
98             CHawkApp* app = (CHawkApp*)AfxGetApp();
99             HAWK_SIGFUNC func;
100             if(app->m_eicSigFuncs.Lookup(sig, func))
101             {
102                 func(sig);
103             }
104         }
105
106     default:
107         WRAP_THROW_MESSAGE(errmark, buf);
108     }
109 #endif /* HAWK_TEST */
110 }
111
112 void init_signal_handlers()
113 {
114     CHawkApp* app = (CHawkApp*)AfxGetApp();
115     app->m_eicSigFuncs.SetAt(SIGABRT, signal(SIGABRT, raiseio));
116     app->m_eicSigFuncs.SetAt(SIGFPE, signal(SIGFPE, raiseio));
117     app->m_eicSigFuncs.SetAt(SIGILL, signal(SIGILL, raiseio));
118     app->m_eicSigFuncs.SetAt(SIGINT, signal(SIGINT, raiseio));
119     app->m_eicSigFuncs.SetAt(SIGSEGV, signal(SIGSEGV, raiseio));
120     app->m_eicSigFuncs.SetAt(SIGTERM, signal(SIGTERM, raiseio));
121 }