00001
00028
00029
00030
00031
00032
00033 #include "Global.h"
00034 #include "GrafKern.h"
00035 #include "Hilfs.h"
00036 #undef ACS_VERSION
00037
00038 char SeRiEnNuMmEr[] = { 4,3,70,2,11,61,
00039 127
00040 };
00041
00042
00043 static int the_character, is_valid;
00044
00045 int intern_fgetc( FILE *stream )
00046 {
00047 int zeichen;
00048
00049 if (is_valid) {
00050 is_valid = 0;
00051 DEBUGLOG2(other,_T("old character: %x"),the_character);
00052 return the_character;
00053 }
00054
00055 zeichen = fgetc(stream);
00056
00057 DEBUGLOG2(other,_T("new character: %x, EOF %d"),zeichen,feof(stream));
00058 return zeichen;
00059 }
00060
00061
00062 int intern_ungetc( int c, FILE *stream )
00063 {
00064 SeRiEnNuMmEr[0] = the_character;
00065 is_valid = 1;
00066 the_character = c;
00067 return 0;
00068 }
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 void * xalloca (size_t size)
00079 {
00080 #ifdef ACS_VERSION
00081 void * help = Ax_malloc (size);
00082 #else
00083 void * help = malloc (size);
00084 #endif
00085
00086 if (help == NULL) {
00087 DEBUGLOG2(other,_T("malloc(%d) failed."),size);
00088 fatal_error (MUT_ERR_MALLOC_FAILED);
00089 return NULL;
00090 }
00091
00092 return help;
00093 }
00094
00095 void xde_alloca (void * pointer)
00096
00097 {
00098 #ifdef ACS_VERSION
00099 Ax_ifree (pointer);
00100 #else
00101 free (pointer);
00102 #endif
00103 }
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 struct heap_element
00114 {
00115 char inhalt [HEAP_PORTION_SYNTAX] ;
00116 size_t anzahl_belegt;
00117
00118 struct heap_element * next;
00119 };
00120
00121 static struct heap_element * syntax_heap = NULL ;
00122
00123 static struct heap_element * heap_to_use_syntax = NULL;
00124
00125 #define OFFSET (sizeof(size_t))
00126
00127
00128
00129
00130
00131 void xfree (void * pointer)
00132 {
00133
00134
00135
00136 }
00137
00138
00139
00140 void * xmalloc (size_t size)
00141 {
00142 if (size + OFFSET > HEAP_PORTION_SYNTAX) {
00143 DEBUGLOG2(other,_T("Error: %d + %d > %d"),size,OFFSET, HEAP_PORTION_SYNTAX);
00144 fatal_error (4);
00145 return NULL;
00146 }
00147
00148 if (syntax_heap == NULL) {
00149 #ifdef ACS_VERSION
00150
00151 syntax_heap = Ax_malloc (sizeof (struct heap_element));
00152
00153 memset(syntax_heap,0,sizeof (struct heap_element));
00154 #else
00155
00156 syntax_heap = (heap_element*) calloc (1,sizeof (struct heap_element));
00157 #endif
00158
00159 if (syntax_heap == NULL) {
00160 DEBUGLOG2(other,_T("calloc(1,%d) failed"),
00161
00162 sizeof (struct heap_element));
00163 fatal_error (4);
00164 return NULL;
00165 }
00166
00167 heap_to_use_syntax = syntax_heap;
00168
00169 heap_to_use_syntax -> anzahl_belegt = 0;
00170 heap_to_use_syntax -> next = NULL;
00171 }
00172
00173
00174
00175 if (heap_to_use_syntax -> anzahl_belegt + size + OFFSET
00176 < HEAP_PORTION_SYNTAX) {
00177 void * help = & heap_to_use_syntax ->
00178 inhalt [ heap_to_use_syntax -> anzahl_belegt + OFFSET ] ;
00179 heap_to_use_syntax -> anzahl_belegt += size + OFFSET;
00180 ((size_t *)help) [ - 1 ] = size;
00181 return help;
00182 } else {
00183 #ifdef ACS_VERSION
00184
00185 heap_to_use_syntax -> next = Ax_malloc (sizeof (struct heap_element));
00186
00187 memset(heap_to_use_syntax -> next,0,sizeof (struct heap_element));
00188 #else
00189
00190 heap_to_use_syntax -> next = (heap_element*) calloc (1,sizeof (struct heap_element));
00191 #endif
00192
00193 if (heap_to_use_syntax -> next == NULL) {
00194 DEBUGLOG2(other,_T("heap_to_use_syntax -> nex == NULL"));
00195 fatal_error (4);
00196 return NULL;
00197 }
00198
00199 heap_to_use_syntax = heap_to_use_syntax -> next;
00200
00201 heap_to_use_syntax -> next = NULL;
00202 heap_to_use_syntax -> anzahl_belegt = size + OFFSET;
00203 *(size_t *)&(heap_to_use_syntax -> inhalt [ 0 ]) = size;
00204 return & heap_to_use_syntax -> inhalt [ OFFSET ] ;
00205 }
00206 }
00207
00208 void * xrealloc (void * block, size_t newsize)
00209
00210 {
00211 if ( ((size_t *)block) [ - 1 ] + (char*)block
00212 == & heap_to_use_syntax ->
00213 inhalt [heap_to_use_syntax -> anzahl_belegt]
00214 &&
00215 (char*)block + newsize <
00216 &(heap_to_use_syntax -> inhalt [ HEAP_PORTION_SYNTAX ])) {
00217
00218
00219
00220 heap_to_use_syntax -> anzahl_belegt +=
00221 newsize - ((size_t *)block) [ - 1 ] ;
00222 ((size_t *)block) [ - 1 ] = newsize;
00223 return block;
00224 } else {
00225 void * help = xmalloc (newsize);
00226
00227 if (help) {
00228 memmove (help, block, newsize);
00229 return help;
00230 } else {
00231 DEBUGLOG2(other,_T("xmalloc (%d) failed"),newsize);
00232 fatal_error (4);
00233 return NULL;
00234 }
00235 }
00236 }
00237
00238
00239 void * xcalloc (size_t anzahl, size_t size)
00240 {
00241 void * help = xmalloc (anzahl * size);
00242
00243 if (help) {
00244 memset (help, 0, anzahl * size);
00245 return help;
00246 } else {
00247 DEBUGLOG2(other,_T("xmalloc(%d * %d) failed"),anzahl,size);
00248 fatal_error (4);
00249 return NULL;
00250 }
00251 }
00252
00253 int loesche_syntax_speicher ( void )
00254 {
00255
00256 struct heap_element * lauf = syntax_heap;
00257
00258 while (lauf) {
00259
00260 struct heap_element * help = lauf->next;
00261 #ifdef ACS_VERSION
00262 Ax_ifree (lauf);
00263 #else
00264 free (lauf);
00265 #endif
00266 lauf = help;
00267 }
00268
00269 syntax_heap = NULL;
00270
00271 heap_to_use_syntax = NULL;
00272
00273 return 0;
00274 }
00275
00276 int init_syntax_speicher ( void )
00277 {
00278 return loesche_syntax_speicher ();
00279 }
00280
00281
00282
00283
00284
00285
00286
00287 struct mini_heap
00288 {
00289 void * pointer;
00290
00291 struct mini_heap * next;
00292 };
00293
00294 static struct mini_heap * laufzeit_heap = NULL;
00295
00296
00297 void yfree (void * pointer)
00298 {
00299
00300 }
00301
00302
00303
00304 void * ymalloc (size_t size)
00305 {
00306 #ifdef ACS_VERSION
00307 void * help1 = Ax_malloc (size);
00308 #else
00309 void * help1 = malloc (size);
00310 #endif
00311
00312 struct mini_heap * help2 = (mini_heap*) malloc (sizeof (struct mini_heap));
00313
00314 if (help1 == NULL || help2 == NULL) {
00315 DEBUGLOG2(other,_T("help1 == %x(%d) ; help2 == %x(%d)"),
00316
00317 help1,size,help2,sizeof(struct mini_heap));
00318 fatal_error (4);
00319 return NULL;
00320 }
00321
00322 help2 -> pointer = help1;
00323
00324 help2 -> next = laufzeit_heap;
00325 laufzeit_heap = help2;
00326
00327 return help1;
00328 }
00329
00330 void * yrealloc (void * block, size_t newsize)
00331
00332 {
00333 void * help = ymalloc (newsize);
00334 memmove (help, block, newsize);
00335 return help;
00336 }
00337
00338 void * ycalloc (size_t anzahl, size_t size)
00339 {
00340 void * help = ymalloc ( anzahl * size );
00341 memset (help, 0, anzahl * size);
00342 return help;
00343 }
00344
00345
00346
00347
00348 int init_laufzeit_speicher ( void )
00349 {
00350 return loesche_laufzeit_speicher ();
00351 }
00352
00353 int loesche_laufzeit_speicher ( void )
00354 {
00355
00356 struct mini_heap * lauf = laufzeit_heap;
00357
00358 while (lauf) {
00359
00360 struct mini_heap * help = lauf;
00361 #ifdef ACS_VERSION
00362 Ax_ifree (lauf -> pointer);
00363 #else
00364 free (lauf -> pointer);
00365 #endif
00366
00367 lauf = lauf -> next;
00368
00369 #ifdef ACS_VERSION
00370 Ax_ifree (help);
00371 #else
00372 free (help);
00373 #endif
00374
00375 }
00376
00377 laufzeit_heap = NULL;
00378
00379 return 0;
00380 }
00381
00382
00383