Move the sources to trunk
[opencv] / apps / Hawk / CVEiCL / EiC / src / reset.c
1 /* reset.c
2  *
3  *      (C) Copyright May  6 2000, Edmond J. Breen.
4  *                 ALL RIGHTS RESERVED.
5  * This code may be copied for personal, non-profit use only.
6  *
7  */
8
9 /* Modified by Intel OpenCV team. Added lines 53-56 in order to prevent 
10    the parser exceptions throwing in specific cases. The fix is consistent 
11    with the EiC Standard version. */
12
13
14 #include <stdio.h>
15 #include <stdlib.h>
16
17 #include "global.h"
18 #include "symbol.h"
19 #include "xalloc.h"
20 #include "error.h"
21
22 static size_t xalloc_bot, pp_bot, lut_bot, ENV_bot;
23 static size_t Ixalloc_bot, Ipp_bot, Ilut_bot, IENV_bot, Ibot_stab, Inincludes;
24
25 void EiC_pp_CleanUp(size_t bot);
26 void EiC_ENV_CleanUp(size_t bot);
27 size_t EiC_pp_NextEntryNum(void);
28 size_t EiC_ENV_NextEntryNum();
29
30 void EiCp_initiateReset(void)
31 {
32     ENV_bot = EiC_ENV_NextEntryNum();
33     lut_bot = EiC_lut_NextEntryNum();
34     pp_bot = EiC_pp_NextEntryNum();
35     xalloc_bot = EiC_xalloc_NextEntryNum();
36 }
37
38 void EiCp_Reset(int flag)
39 {
40     int errR = 0;
41     size_t xalloc_top = EiC_xalloc_NextEntryNum();
42
43     if(flag) EiC_messageDisplay("Error: clean up forced\n");
44     /* The while loop is a precaution against
45          * errors that occur during cleanup.
46          */
47     while(errR < 10) {
48         /*if(flag) {sprintf(buff,"%d,",errR); EiC_messageDisplay(buff);}*/
49         switch(errR++) {
50         case 0: EiC_lut_CleanUp(lut_bot); break;
51         case 1: EiC_ENV_CleanUp(ENV_bot); break;
52         case 2: EiC_pp_CleanUp(pp_bot); break;
53         case 3: /* Vic's change */
54             if(EiC_ENV->ARgar.n)
55             xmark(EiC_ENV->ARgar.val,eicstay); /*End Vic's change */
56             EiC_xalloc_CleanUp(xalloc_bot,xalloc_top); break;
57         default:
58             /*if(flag) EiC_messageDisplay("\n");*/
59             errR = 10;
60         }
61     }
62 }    
63
64 static AR_t *globals =NULL;
65 static unsigned ARsp;
66
67 void EiCp_setResetStart(void)
68 {
69     size_t EiC_get_EiC_bot_stab(void);
70     size_t EiC_get_EiC_PP_NINCLUDES(void);
71
72     ARsp = EiC_ENV->sp;
73     if(globals)
74         free(globals);
75     globals = (AR_t*)malloc(sizeof(AR_t)*ARsp);
76     if(globals) 
77         memcpy(globals,EiC_ENV->AR,sizeof(AR_t)*ARsp);
78
79     EiCp_initiateReset();
80     Ixalloc_bot = xalloc_bot;
81     Ipp_bot = pp_bot;
82     Ilut_bot = lut_bot;
83     IENV_bot = ENV_bot;
84
85     Inincludes = EiC_get_EiC_PP_NINCLUDES();
86     Ibot_stab =  EiC_get_EiC_bot_stab();
87 }
88
89 void EiCp_ResetStart(void)
90 {
91     void EiC_set_EiC_PPtoStart(int bot_stab, int include);
92     xalloc_bot = Ixalloc_bot;
93     pp_bot = Ipp_bot;
94     lut_bot = Ilut_bot;
95     ENV_bot = IENV_bot;
96
97     EiCp_Reset(0);
98     EiC_set_EiC_PPtoStart(Ibot_stab, Inincludes);
99
100     if(globals) {
101         memcpy(EiC_ENV->AR,globals,sizeof(AR_t)*ARsp);
102         EiC_ENV->sp = ARsp;
103     }
104 }
105
106
107
108
109
110
111
112
113