| [4d61ad0] | 1 | static char adSid[]="$Id: adStack.c 5951 2016-02-09 12:22:02Z llh $";
|
|---|
| 2 |
|
|---|
| 3 | #include <stdlib.h>
|
|---|
| 4 | #include <stdio.h>
|
|---|
| 5 | #include <string.h>
|
|---|
| 6 |
|
|---|
| 7 | /* The size of a BLOCK in characters */
|
|---|
| 8 | #define ONE_BLOCK_SIZE 16384
|
|---|
| 9 | #ifndef STACK_SIZE_TRACING
|
|---|
| 10 | #define STACK_SIZE_TRACING 1
|
|---|
| 11 | #endif
|
|---|
| 12 | /* The main stack is a double-chain of DoubleChainedBlock objects.
|
|---|
| 13 | * Each DoubleChainedBlock holds an array[ONE_BLOCK_SIZE] of char. */
|
|---|
| 14 | typedef struct _doubleChainedBlock{
|
|---|
| 15 | struct _doubleChainedBlock *prev ;
|
|---|
| 16 | char *contents ;
|
|---|
| 17 | struct _doubleChainedBlock *next ;
|
|---|
| 18 | } DoubleChainedBlock ;
|
|---|
| 19 |
|
|---|
| 20 | /* Globals that define the current position in the stack: */
|
|---|
| 21 | static DoubleChainedBlock *curStack = NULL ;
|
|---|
| 22 | static char *curStackTop = NULL ;
|
|---|
| 23 | /* Globals that define the current LOOKing position in the stack: */
|
|---|
| 24 | static DoubleChainedBlock *lookStack = NULL ;
|
|---|
| 25 | static char *lookStackTop = NULL ;
|
|---|
| 26 |
|
|---|
| 27 | static long int mmctraffic = 0 ;
|
|---|
| 28 | static long int mmctrafficM = 0 ;
|
|---|
| 29 | #ifdef STACK_SIZE_TRACING
|
|---|
| 30 | long int bigStackSize = 0;
|
|---|
| 31 | #endif
|
|---|
| 32 |
|
|---|
| 33 | /* PUSHes "nbChars" consecutive chars from a location starting at address "x".
|
|---|
| 34 | * Resets the LOOKing position if it was active.
|
|---|
| 35 | * Checks that there is enough space left to hold "nbChars" chars.
|
|---|
| 36 | * Otherwise, allocates the necessary space. */
|
|---|
| 37 | void pushNarray(char *x, unsigned int nbChars) {
|
|---|
| 38 | unsigned int nbmax = (curStack)?ONE_BLOCK_SIZE-(curStackTop-(curStack->contents)):0 ;
|
|---|
| 39 | #ifdef STACK_SIZE_TRACING
|
|---|
| 40 | bigStackSize += nbChars;
|
|---|
| 41 | #endif
|
|---|
| 42 |
|
|---|
| 43 | mmctraffic += nbChars ;
|
|---|
| 44 | while (mmctraffic >= 1000000) {
|
|---|
| 45 | mmctraffic -= 1000000 ;
|
|---|
| 46 | mmctrafficM++ ;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | lookStack = NULL ;
|
|---|
| 50 | if (nbChars <= nbmax) {
|
|---|
| 51 | memcpy(curStackTop,x,nbChars) ;
|
|---|
| 52 | curStackTop+=nbChars ;
|
|---|
| 53 | } else {
|
|---|
| 54 | char *inx = x+(nbChars-nbmax) ;
|
|---|
| 55 | if (nbmax>0) memcpy(curStackTop,inx,nbmax) ;
|
|---|
| 56 | while (inx>x) {
|
|---|
| 57 | if ((curStack == NULL) || (curStack->next == NULL)) {
|
|---|
| 58 | /* Create new block: */
|
|---|
| 59 | DoubleChainedBlock *newStack ;
|
|---|
| 60 | char *contents = (char *)malloc(ONE_BLOCK_SIZE*sizeof(char)) ;
|
|---|
| 61 | newStack = (DoubleChainedBlock*)malloc(sizeof(DoubleChainedBlock)) ;
|
|---|
| 62 | if ((contents == NULL) || (newStack == NULL)) {
|
|---|
| 63 | DoubleChainedBlock *stack = curStack ;
|
|---|
| 64 | int nbBlocks = (stack?-1:0) ;
|
|---|
| 65 | while(stack) {
|
|---|
| 66 | stack = stack->prev ;
|
|---|
| 67 | nbBlocks++ ;
|
|---|
| 68 | }
|
|---|
| 69 | printf("Out of memory (allocated %i blocks of %i bytes)\n",
|
|---|
| 70 | nbBlocks, ONE_BLOCK_SIZE) ;
|
|---|
| 71 | exit(0);
|
|---|
| 72 | }
|
|---|
| 73 | if (curStack != NULL) curStack->next = newStack ;
|
|---|
| 74 | newStack->prev = curStack ;
|
|---|
| 75 | newStack->next = NULL ;
|
|---|
| 76 | newStack->contents = contents ;
|
|---|
| 77 | curStack = newStack ;
|
|---|
| 78 | /* new block created! */
|
|---|
| 79 | } else
|
|---|
| 80 | curStack = curStack->next ;
|
|---|
| 81 | inx -= ONE_BLOCK_SIZE ;
|
|---|
| 82 | if(inx>x)
|
|---|
| 83 | memcpy(curStack->contents,inx,ONE_BLOCK_SIZE) ;
|
|---|
| 84 | else {
|
|---|
| 85 | unsigned int nbhead = (inx-x)+ONE_BLOCK_SIZE ;
|
|---|
| 86 | curStackTop = curStack->contents ;
|
|---|
| 87 | memcpy(curStackTop,x,nbhead) ;
|
|---|
| 88 | curStackTop += nbhead ;
|
|---|
| 89 | }
|
|---|
| 90 | }
|
|---|
| 91 | }
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | /* POPs "nbChars" consecutive chars to a location starting at address "x".
|
|---|
| 95 | * Resets the LOOKing position if it was active.
|
|---|
| 96 | * Checks that there is enough data to fill "nbChars" chars.
|
|---|
| 97 | * Otherwise, pops as many blocks as necessary. */
|
|---|
| 98 | void popNarray(char *x, unsigned int nbChars) {
|
|---|
| 99 | unsigned int nbmax = curStackTop-(curStack->contents) ;
|
|---|
| 100 | #ifdef STACK_SIZE_TRACING
|
|---|
| 101 | bigStackSize -= nbChars;
|
|---|
| 102 | #endif
|
|---|
| 103 | lookStack = NULL ;
|
|---|
| 104 | if (nbChars <= nbmax) {
|
|---|
| 105 | curStackTop-=nbChars ;
|
|---|
| 106 | memcpy(x,curStackTop,nbChars);
|
|---|
| 107 | } else {
|
|---|
| 108 | char *tlx = x+nbChars ;
|
|---|
| 109 | if (nbmax>0) memcpy(x,curStack->contents,nbmax) ;
|
|---|
| 110 | x+=nbmax ;
|
|---|
| 111 | while (x<tlx) {
|
|---|
| 112 | curStack = curStack->prev ;
|
|---|
| 113 | if (curStack==NULL) printf("Popping from an empty stack!!!\n") ;
|
|---|
| 114 | if (x+ONE_BLOCK_SIZE<tlx) {
|
|---|
| 115 | memcpy(x,curStack->contents,ONE_BLOCK_SIZE) ;
|
|---|
| 116 | x += ONE_BLOCK_SIZE ;
|
|---|
| 117 | } else {
|
|---|
| 118 | unsigned int nbtail = tlx-x ;
|
|---|
| 119 | curStackTop=(curStack->contents)+ONE_BLOCK_SIZE-nbtail ;
|
|---|
| 120 | memcpy(x,curStackTop,nbtail) ;
|
|---|
| 121 | x = tlx ;
|
|---|
| 122 | }
|
|---|
| 123 | }
|
|---|
| 124 | }
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | /* LOOKs "nbChars" consecutive chars to a location starting at address "x".
|
|---|
| 128 | * Activates the LOOKing position if it was reset.
|
|---|
| 129 | * LOOKing is just like POPping, except that the main pointer
|
|---|
| 130 | * remains in place, so that the value is not POPped.
|
|---|
| 131 | * Further PUSHs or POPs will start from the same place as if
|
|---|
| 132 | * no LOOK had been made. */
|
|---|
| 133 | void lookNarray(char *x, unsigned int nbChars) {
|
|---|
| 134 | unsigned int nbmax ;
|
|---|
| 135 | if (lookStack == NULL) {
|
|---|
| 136 | lookStack = curStack ;
|
|---|
| 137 | lookStackTop = curStackTop ;
|
|---|
| 138 | }
|
|---|
| 139 | nbmax = lookStackTop-(lookStack->contents) ;
|
|---|
| 140 | if (nbChars <= nbmax) {
|
|---|
| 141 | lookStackTop-=nbChars ;
|
|---|
| 142 | memcpy(x,lookStackTop,nbChars);
|
|---|
| 143 | } else {
|
|---|
| 144 | char *tlx = x+nbChars ;
|
|---|
| 145 | if (nbmax>0) memcpy(x,lookStack->contents,nbmax) ;
|
|---|
| 146 | x+=nbmax ;
|
|---|
| 147 | while (x<tlx) {
|
|---|
| 148 | lookStack = lookStack->prev ;
|
|---|
| 149 | if (lookStack==NULL) printf("Looking into an empty stack!!!") ;
|
|---|
| 150 | if (x+ONE_BLOCK_SIZE<tlx) {
|
|---|
| 151 | memcpy(x,lookStack->contents,ONE_BLOCK_SIZE) ;
|
|---|
| 152 | x += ONE_BLOCK_SIZE ;
|
|---|
| 153 | } else {
|
|---|
| 154 | unsigned int nbtail = tlx-x ;
|
|---|
| 155 | lookStackTop=(lookStack->contents)+ONE_BLOCK_SIZE-nbtail ;
|
|---|
| 156 | memcpy(x,lookStackTop,nbtail) ;
|
|---|
| 157 | x = tlx ;
|
|---|
| 158 | }
|
|---|
| 159 | }
|
|---|
| 160 | }
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | void resetadlookstack_() {
|
|---|
| 164 | lookStack=NULL ;
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | /****** Exported PUSH/POP/LOOK functions for ARRAYS: ******/
|
|---|
| 168 | /* --> Called from FORTRAN: */
|
|---|
| 169 |
|
|---|
| 170 | void pushcharacterarray_(char *x, unsigned int *n) {
|
|---|
| 171 | pushNarray(x,*n) ;
|
|---|
| 172 | }
|
|---|
| 173 | void popcharacterarray_(char *x, unsigned int *n) {
|
|---|
| 174 | popNarray(x,*n) ;
|
|---|
| 175 | }
|
|---|
| 176 | void lookcharacterarray_(char *x, unsigned int *n) {
|
|---|
| 177 | lookNarray(x,*n) ;
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | void pushbooleanarray_(char *x, unsigned int *n) {
|
|---|
| 181 | pushNarray(x,(*n*4)) ;
|
|---|
| 182 | }
|
|---|
| 183 | void popbooleanarray_(char *x, unsigned int *n) {
|
|---|
| 184 | popNarray(x,(*n*4)) ;
|
|---|
| 185 | }
|
|---|
| 186 | void lookbooleanarray_(char *x, unsigned int *n) {
|
|---|
| 187 | lookNarray(x,(*n*4)) ;
|
|---|
| 188 | }
|
|---|
| 189 |
|
|---|
| 190 | void pushinteger4array_(void *x, unsigned int *n) {
|
|---|
| 191 | pushNarray((char *)x,(*n*4)) ;
|
|---|
| 192 | }
|
|---|
| 193 | void popinteger4array_(void *x, unsigned int *n) {
|
|---|
| 194 | popNarray((char *)x,(*n*4)) ;
|
|---|
| 195 | }
|
|---|
| 196 | void lookinteger4array_(void *x, unsigned int *n) {
|
|---|
| 197 | lookNarray((char *)x,(*n*4)) ;
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | void pushinteger8array_(void *x, unsigned int *n) {
|
|---|
| 201 | pushNarray((char *)x,(*n*8)) ;
|
|---|
| 202 | }
|
|---|
| 203 | void popinteger8array_(void *x, unsigned int *n) {
|
|---|
| 204 | popNarray((char *)x,(*n*8)) ;
|
|---|
| 205 | }
|
|---|
| 206 | void lookinteger8array_(void *x, unsigned int *n) {
|
|---|
| 207 | lookNarray((char *)x,(*n*8)) ;
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 | void pushinteger16array_(void *x, unsigned int *n) {
|
|---|
| 211 | pushNarray((char *)x,(*n*16)) ;
|
|---|
| 212 | }
|
|---|
| 213 | void popinteger16array_(void *x, unsigned int *n) {
|
|---|
| 214 | popNarray((char *)x,(*n*16)) ;
|
|---|
| 215 | }
|
|---|
| 216 | void lookinteger16array_(void *x, unsigned int *n) {
|
|---|
| 217 | lookNarray((char *)x,(*n*16)) ;
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | void pushreal4array_(void *x, unsigned int *n) {
|
|---|
| 221 | pushNarray((char *)x,(*n*4)) ;
|
|---|
| 222 | }
|
|---|
| 223 | void popreal4array_(void *x, unsigned int *n) {
|
|---|
| 224 | popNarray((char *)x,(*n*4)) ;
|
|---|
| 225 | }
|
|---|
| 226 | void lookreal4array_(void *x, unsigned int *n) {
|
|---|
| 227 | lookNarray((char *)x,(*n*4)) ;
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | void pushreal8array_(void *x, unsigned int *n) {
|
|---|
| 231 | pushNarray((char *)x,(*n*8)) ;
|
|---|
| 232 | }
|
|---|
| 233 | void popreal8array_(void *x, unsigned int *n) {
|
|---|
| 234 | popNarray((char *)x,(*n*8)) ;
|
|---|
| 235 | }
|
|---|
| 236 | void lookreal8array_(void *x, unsigned int *n) {
|
|---|
| 237 | lookNarray((char *)x,(*n*8)) ;
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | void pushreal16array_(void *x, unsigned int *n) {
|
|---|
| 241 | pushNarray((char *)x,(*n*16)) ;
|
|---|
| 242 | }
|
|---|
| 243 | void popreal16array_(void *x, unsigned int *n) {
|
|---|
| 244 | popNarray((char *)x,(*n*16)) ;
|
|---|
| 245 | }
|
|---|
| 246 | void lookreal16array_(void *x, unsigned int *n) {
|
|---|
| 247 | lookNarray((char *)x,(*n*16)) ;
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|
| 250 | void pushreal32array_(void *x, unsigned int *n) {
|
|---|
| 251 | pushNarray((char *)x,(*n*32)) ;
|
|---|
| 252 | }
|
|---|
| 253 | void popreal32array_(void *x, unsigned int *n) {
|
|---|
| 254 | popNarray((char *)x,(*n*32)) ;
|
|---|
| 255 | }
|
|---|
| 256 | void lookreal32array_(void *x, unsigned int *n) {
|
|---|
| 257 | lookNarray((char *)x,(*n*32)) ;
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 | void pushcomplex4array_(void *x, unsigned int *n) {
|
|---|
| 261 | pushNarray((char *)x,(*n*4)) ;
|
|---|
| 262 | }
|
|---|
| 263 | void popcomplex4array_(void *x, unsigned int *n) {
|
|---|
| 264 | popNarray((char *)x,(*n*4)) ;
|
|---|
| 265 | }
|
|---|
| 266 | void lookcomplex4array_(void *x, unsigned int *n) {
|
|---|
| 267 | lookNarray((char *)x,(*n*4)) ;
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | void pushcomplex8array_(void *x, unsigned int *n) {
|
|---|
| 271 | pushNarray((char *)x,(*n*8)) ;
|
|---|
| 272 | }
|
|---|
| 273 | void popcomplex8array_(void *x, unsigned int *n) {
|
|---|
| 274 | popNarray((char *)x,(*n*8)) ;
|
|---|
| 275 | }
|
|---|
| 276 | void lookcomplex8array_(void *x, unsigned int *n) {
|
|---|
| 277 | lookNarray((char *)x,(*n*8)) ;
|
|---|
| 278 | }
|
|---|
| 279 |
|
|---|
| 280 | void pushcomplex16array_(void *x, unsigned int *n) {
|
|---|
| 281 | pushNarray((char *)x,(*n*16)) ;
|
|---|
| 282 | }
|
|---|
| 283 | void popcomplex16array_(void *x, unsigned int *n) {
|
|---|
| 284 | popNarray((char *)x,(*n*16)) ;
|
|---|
| 285 | }
|
|---|
| 286 | void lookcomplex16array_(void *x, unsigned int *n) {
|
|---|
| 287 | lookNarray((char *)x,(*n*16)) ;
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 | void pushcomplex32array_(void *x, unsigned int *n) {
|
|---|
| 291 | pushNarray((char *)x,(*n*32)) ;
|
|---|
| 292 | }
|
|---|
| 293 | void popcomplex32array_(void *x, unsigned int *n) {
|
|---|
| 294 | popNarray((char *)x,(*n*32)) ;
|
|---|
| 295 | }
|
|---|
| 296 | void lookcomplex32array_(void *x, unsigned int *n) {
|
|---|
| 297 | lookNarray((char *)x,(*n*32)) ;
|
|---|
| 298 | }
|
|---|
| 299 |
|
|---|
| 300 | /****** Exported PUSH/POP/LOOK functions for F95 POINTERS: ******/
|
|---|
| 301 |
|
|---|
| 302 | void pushpointer4_(void *ppp) {
|
|---|
| 303 | pushNarray((char *)ppp, 4) ;
|
|---|
| 304 | }
|
|---|
| 305 |
|
|---|
| 306 | void lookpointer4_(void *ppp) {
|
|---|
| 307 | lookNarray((char *)ppp, 4) ;
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|
| 310 | void poppointer4_(void *ppp) {
|
|---|
| 311 | popNarray((char *)ppp, 4) ;
|
|---|
| 312 | }
|
|---|
| 313 |
|
|---|
| 314 | void pushpointer8_(void *ppp) {
|
|---|
| 315 | pushNarray((char *)ppp, 8) ;
|
|---|
| 316 | }
|
|---|
| 317 |
|
|---|
| 318 | void lookpointer8_(void *ppp) {
|
|---|
| 319 | lookNarray((char *)ppp, 8) ;
|
|---|
| 320 | }
|
|---|
| 321 |
|
|---|
| 322 | void poppointer8_(void *ppp) {
|
|---|
| 323 | popNarray((char *)ppp, 8) ;
|
|---|
| 324 | }
|
|---|
| 325 |
|
|---|
| 326 | /* --> Called from C: */
|
|---|
| 327 |
|
|---|
| 328 | void pushcharacterarray(char *x, int n) {
|
|---|
| 329 | pushNarray(x,(unsigned int)n) ;
|
|---|
| 330 | }
|
|---|
| 331 | void popcharacterarray(char *x, int n) {
|
|---|
| 332 | popNarray(x,(unsigned int)n) ;
|
|---|
| 333 | }
|
|---|
| 334 | void lookcharacterarray(char *x, int n) {
|
|---|
| 335 | lookNarray(x,(unsigned int)n) ;
|
|---|
| 336 | }
|
|---|
| 337 |
|
|---|
| 338 | void pushbooleanarray(char *x, int n) {
|
|---|
| 339 | pushNarray(x,(unsigned int)(n*4)) ;
|
|---|
| 340 | }
|
|---|
| 341 | void popbooleanarray(char *x, int n) {
|
|---|
| 342 | popNarray(x,(unsigned int)(n*4)) ;
|
|---|
| 343 | }
|
|---|
| 344 | void lookbooleanarray(char *x, int n) {
|
|---|
| 345 | lookNarray(x,(unsigned int)(n*4)) ;
|
|---|
| 346 | }
|
|---|
| 347 |
|
|---|
| 348 | void pushinteger4array(int *x, int n) {
|
|---|
| 349 | pushNarray((char *)x,(unsigned int)(n*4)) ;
|
|---|
| 350 | }
|
|---|
| 351 | void popinteger4array(int *x, int n) {
|
|---|
| 352 | popNarray((char *)x,(unsigned int)(n*4)) ;
|
|---|
| 353 | }
|
|---|
| 354 | void lookinteger4array(int *x, int n) {
|
|---|
| 355 | lookNarray((char *)x,(unsigned int)(n*4)) ;
|
|---|
| 356 | }
|
|---|
| 357 |
|
|---|
| 358 | void pushinteger8array(long int *x, int n) {
|
|---|
| 359 | pushNarray((char *)x,(unsigned int)(n*8)) ;
|
|---|
| 360 | }
|
|---|
| 361 | void popinteger8array(long int *x, int n) {
|
|---|
| 362 | popNarray((char *)x,(unsigned int)(n*8)) ;
|
|---|
| 363 | }
|
|---|
| 364 | void lookinteger8array(long int *x, int n) {
|
|---|
| 365 | lookNarray((char *)x,(unsigned int)(n*8)) ;
|
|---|
| 366 | }
|
|---|
| 367 |
|
|---|
| 368 | void pushinteger16array(long long int *x, int n) {
|
|---|
| 369 | pushNarray((char *)x,(unsigned int)(n*16)) ;
|
|---|
| 370 | }
|
|---|
| 371 | void popinteger16array(long long int *x, int n) {
|
|---|
| 372 | popNarray((char *)x,(unsigned int)(n*16)) ;
|
|---|
| 373 | }
|
|---|
| 374 | void lookinteger16array(long long int *x, int n) {
|
|---|
| 375 | lookNarray((char *)x,(unsigned int)(n*16)) ;
|
|---|
| 376 | }
|
|---|
| 377 |
|
|---|
| 378 | void pushreal4array(float *x, int n) {
|
|---|
| 379 | pushNarray((char *)x, (unsigned int)(n*4)) ;
|
|---|
| 380 | }
|
|---|
| 381 | void popreal4array(float *x, int n) {
|
|---|
| 382 | popNarray((char *)x, (unsigned int)(n*4)) ;
|
|---|
| 383 | }
|
|---|
| 384 | void lookreal4array(float *x, int n) {
|
|---|
| 385 | lookNarray((char *)x, (unsigned int)(n*4)) ;
|
|---|
| 386 | }
|
|---|
| 387 |
|
|---|
| 388 | void pushreal8array(double *x, int n) {
|
|---|
| 389 | pushNarray((char *)x,(unsigned int)(n*8)) ;
|
|---|
| 390 | }
|
|---|
| 391 | void popreal8array(double *x, int n) {
|
|---|
| 392 | popNarray((char *)x,(unsigned int)(n*8)) ;
|
|---|
| 393 | }
|
|---|
| 394 | void lookreal8array(double *x, int n) {
|
|---|
| 395 | lookNarray((char *)x,(unsigned int)(n*8)) ;
|
|---|
| 396 | }
|
|---|
| 397 |
|
|---|
| 398 | void pushreal16array(void *x, int n) {
|
|---|
| 399 | pushNarray((char *)x,(unsigned int)(n*16)) ;
|
|---|
| 400 | }
|
|---|
| 401 | void popreal16array(void *x, int n) {
|
|---|
| 402 | popNarray((char *)x,(unsigned int)(n*16)) ;
|
|---|
| 403 | }
|
|---|
| 404 | void lookreal16array(void *x, int n) {
|
|---|
| 405 | lookNarray((char *)x,(unsigned int)(n*16)) ;
|
|---|
| 406 | }
|
|---|
| 407 |
|
|---|
| 408 | void pushreal32array(void *x, int n) {
|
|---|
| 409 | pushNarray((char *)x,(unsigned int)(n*32)) ;
|
|---|
| 410 | }
|
|---|
| 411 | void popreal32array(void *x, int n) {
|
|---|
| 412 | popNarray((char *)x,(unsigned int)(n*32)) ;
|
|---|
| 413 | }
|
|---|
| 414 | void lookreal32array(void *x, int n) {
|
|---|
| 415 | lookNarray((char *)x,(unsigned int)(n*32)) ;
|
|---|
| 416 | }
|
|---|
| 417 |
|
|---|
| 418 | void pushcomplex4array(void *x, int n) {
|
|---|
| 419 | pushNarray((char *)x,(unsigned int)(n*4)) ;
|
|---|
| 420 | }
|
|---|
| 421 | void popcomplex4array(void *x, int n) {
|
|---|
| 422 | popNarray((char *)x,(unsigned int)(n*4)) ;
|
|---|
| 423 | }
|
|---|
| 424 | void lookcomplex4array(void *x, int n) {
|
|---|
| 425 | lookNarray((char *)x,(unsigned int)(n*4)) ;
|
|---|
| 426 | }
|
|---|
| 427 |
|
|---|
| 428 | void pushcomplex8array(void *x, int n) {
|
|---|
| 429 | pushNarray((char *)x,(unsigned int)(n*8)) ;
|
|---|
| 430 | }
|
|---|
| 431 | void popcomplex8array(void *x, int n) {
|
|---|
| 432 | popNarray((char *)x,(unsigned int)(n*8)) ;
|
|---|
| 433 | }
|
|---|
| 434 | void lookcomplex8array(void *x, int n) {
|
|---|
| 435 | lookNarray((char *)x,(unsigned int)(n*8)) ;
|
|---|
| 436 | }
|
|---|
| 437 |
|
|---|
| 438 | void pushcomplex16array(void *x, int n) {
|
|---|
| 439 | pushNarray((char *)x,(unsigned int)(n*16)) ;
|
|---|
| 440 | }
|
|---|
| 441 | void popcomplex16array(void *x, int n) {
|
|---|
| 442 | popNarray((char *)x,(unsigned int)(n*16)) ;
|
|---|
| 443 | }
|
|---|
| 444 | void lookcomplex16array(void *x, int n) {
|
|---|
| 445 | lookNarray((char *)x,(unsigned int)(n*16)) ;
|
|---|
| 446 | }
|
|---|
| 447 |
|
|---|
| 448 | void pushcomplex32array(void *x, int n) {
|
|---|
| 449 | pushNarray((char *)x,(unsigned int)(n*32)) ;
|
|---|
| 450 | }
|
|---|
| 451 | void popcomplex32array(void *x, int n) {
|
|---|
| 452 | popNarray((char *)x,(unsigned int)(n*32)) ;
|
|---|
| 453 | }
|
|---|
| 454 | void lookcomplex32array(void *x, int n) {
|
|---|
| 455 | lookNarray((char *)x,(unsigned int)(n*32)) ;
|
|---|
| 456 | }
|
|---|
| 457 |
|
|---|
| 458 | void pushpointer4array(void *x, int n) {
|
|---|
| 459 | pushNarray((char *)x, (unsigned int)(n*4)) ;
|
|---|
| 460 | }
|
|---|
| 461 | void poppointer4array(void *x, int n) {
|
|---|
| 462 | popNarray((char *)x, (unsigned int)(n*4)) ;
|
|---|
| 463 | }
|
|---|
| 464 | void lookpointer4array(void *x, int n) {
|
|---|
| 465 | lookNarray((char *)x, (unsigned int)(n*4)) ;
|
|---|
| 466 | }
|
|---|
| 467 |
|
|---|
| 468 | void pushpointer8array(void *x, int n) {
|
|---|
| 469 | pushNarray((char *)x,(unsigned int)(n*8)) ;
|
|---|
| 470 | }
|
|---|
| 471 | void poppointer8array(void *x, int n) {
|
|---|
| 472 | popNarray((char *)x,(unsigned int)(n*8)) ;
|
|---|
| 473 | }
|
|---|
| 474 | void lookpointer8array(void *x, int n) {
|
|---|
| 475 | lookNarray((char *)x,(unsigned int)(n*8)) ;
|
|---|
| 476 | }
|
|---|
| 477 |
|
|---|
| 478 | /************* Debug displays of the state of the stack: ***********/
|
|---|
| 479 |
|
|---|
| 480 | void printbigbytes(long int nbblocks, long int blocksz, long int nbunits) {
|
|---|
| 481 | long int a3, b3, res3, res6, res9, res12 ;
|
|---|
| 482 | int a0, b0, res0 ;
|
|---|
| 483 | int printzeros = 0 ;
|
|---|
| 484 | a0 = (int)nbblocks%1000 ;
|
|---|
| 485 | a3 = nbblocks/1000 ;
|
|---|
| 486 | b0 = (int)blocksz%1000 ;
|
|---|
| 487 | b3 = blocksz/1000 ;
|
|---|
| 488 | res0 = ((int)(nbunits%1000)) + a0*b0 ;
|
|---|
| 489 | res3 = nbunits/1000 + a3*b0 + a0*b3 ;
|
|---|
| 490 | res6 = a3*b3 ;
|
|---|
| 491 | res3 += ((long int)(res0/1000)) ;
|
|---|
| 492 | res0 = res0%1000 ;
|
|---|
| 493 | res6 += res3/1000 ;
|
|---|
| 494 | res3 = res3%1000 ;
|
|---|
| 495 | res9 = res6/1000 ;
|
|---|
| 496 | res6 = res6%1000 ;
|
|---|
| 497 | res12 = res9/1000 ;
|
|---|
| 498 | res9 = res9%1000 ;
|
|---|
| 499 | if (res12>0) {
|
|---|
| 500 | printf("%li ", res12) ;
|
|---|
| 501 | printzeros = 1 ;
|
|---|
| 502 | }
|
|---|
| 503 | if ((res9/100)>0 || printzeros) {
|
|---|
| 504 | printf("%li",res9/100) ;
|
|---|
| 505 | printzeros = 1 ;
|
|---|
| 506 | res9 = res9%100 ;
|
|---|
| 507 | }
|
|---|
| 508 | if ((res9/10)>0 || printzeros) {
|
|---|
| 509 | printf("%li",res9/10) ;
|
|---|
| 510 | printzeros = 1 ;
|
|---|
| 511 | res9 = res9%10 ;
|
|---|
| 512 | }
|
|---|
| 513 | if (res9>0 || printzeros) {
|
|---|
| 514 | printf("%li ",res9) ;
|
|---|
| 515 | printzeros = 1 ;
|
|---|
| 516 | }
|
|---|
| 517 | if ((res6/100)>0 || printzeros) {
|
|---|
| 518 | printf("%li",res6/100) ;
|
|---|
| 519 | printzeros = 1 ;
|
|---|
| 520 | res6 = res6%100 ;
|
|---|
| 521 | }
|
|---|
| 522 | if ((res6/10)>0 || printzeros) {
|
|---|
| 523 | printf("%li",res6/10) ;
|
|---|
| 524 | printzeros = 1 ;
|
|---|
| 525 | res6 = res6%10 ;
|
|---|
| 526 | }
|
|---|
| 527 | if (res6>0 || printzeros) {
|
|---|
| 528 | printf("%li ",res6) ;
|
|---|
| 529 | printzeros = 1 ;
|
|---|
| 530 | }
|
|---|
| 531 | if ((res3/100)>0 || printzeros) {
|
|---|
| 532 | printf("%li",res3/100) ;
|
|---|
| 533 | printzeros = 1 ;
|
|---|
| 534 | res3 = res3%100 ;
|
|---|
| 535 | }
|
|---|
| 536 | if ((res3/10)>0 || printzeros) {
|
|---|
| 537 | printf("%li",res3/10) ;
|
|---|
| 538 | printzeros = 1 ;
|
|---|
| 539 | res3 = res3%10 ;
|
|---|
| 540 | }
|
|---|
| 541 | if (res3>0 || printzeros) {
|
|---|
| 542 | printf("%li ",res3) ;
|
|---|
| 543 | printzeros = 1 ;
|
|---|
| 544 | }
|
|---|
| 545 | if ((res0/100)>0 || printzeros) {
|
|---|
| 546 | printf("%i",res0/100) ;
|
|---|
| 547 | printzeros = 1 ;
|
|---|
| 548 | res0 = res0%100 ;
|
|---|
| 549 | }
|
|---|
| 550 | if ((res0/10)>0 || printzeros) {
|
|---|
| 551 | printf("%i",res0/10) ;
|
|---|
| 552 | printzeros = 1 ;
|
|---|
| 553 | res0 = res0%10 ;
|
|---|
| 554 | }
|
|---|
| 555 | printf("%i",res0) ;
|
|---|
| 556 | }
|
|---|
| 557 |
|
|---|
| 558 | void printctraffic_() {
|
|---|
| 559 | printf(" C Traffic: ") ;
|
|---|
| 560 | printbigbytes(mmctrafficM, 1000000, mmctraffic) ;
|
|---|
| 561 | printf(" bytes\n") ;
|
|---|
| 562 | }
|
|---|
| 563 |
|
|---|
| 564 | void printftrafficinc_(long int *mmfM, int *mmfsz, int *mmf) {
|
|---|
| 565 | printf(" F Traffic: ") ;
|
|---|
| 566 | printbigbytes(*mmfM, (long int)*mmfsz, (long int)*mmf) ;
|
|---|
| 567 | printf(" bytes\n") ;
|
|---|
| 568 | }
|
|---|
| 569 |
|
|---|
| 570 | void printtotaltraffic_(long int *mmfM, int *mmfsz, int *mmf) {
|
|---|
| 571 | printf(" C+F Traffic: ") ;
|
|---|
| 572 | printbigbytes(mmctrafficM, 1000000, mmctraffic) ;
|
|---|
| 573 | printf(" + ");
|
|---|
| 574 | printbigbytes(*mmfM, (long int)*mmfsz, (long int)*mmf) ;
|
|---|
| 575 | printf(" bytes\n") ;
|
|---|
| 576 | }
|
|---|
| 577 |
|
|---|
| 578 | void printtopplace_() {
|
|---|
| 579 | DoubleChainedBlock *stack = curStack ;
|
|---|
| 580 | int nbBlocks = (stack?-1:0) ;
|
|---|
| 581 | int remainder = 0;
|
|---|
| 582 | while(stack) {
|
|---|
| 583 | stack = stack->prev ;
|
|---|
| 584 | nbBlocks++ ;
|
|---|
| 585 | }
|
|---|
| 586 | if (curStack && curStackTop) remainder = curStackTop-(curStack->contents) ;
|
|---|
| 587 | printf(" Stack size: ") ;
|
|---|
| 588 | printbigbytes((long int)nbBlocks, ONE_BLOCK_SIZE, (long int)remainder) ;
|
|---|
| 589 | printf(" bytes\n") ;
|
|---|
| 590 | }
|
|---|
| 591 |
|
|---|
| 592 | void printtopplacenum_(int *n) {
|
|---|
| 593 | DoubleChainedBlock *stack = curStack ;
|
|---|
| 594 | int nbBlocks = (stack?-1:0) ;
|
|---|
| 595 | int remainder = 0;
|
|---|
| 596 | while(stack) {
|
|---|
| 597 | stack = stack->prev ;
|
|---|
| 598 | nbBlocks++ ;
|
|---|
| 599 | }
|
|---|
| 600 | if (curStack && curStackTop) remainder = curStackTop-(curStack->contents) ;
|
|---|
| 601 | printf(" Stack size at location %i : ", *n) ;
|
|---|
| 602 | printbigbytes((long int)nbBlocks, ONE_BLOCK_SIZE, (long int)remainder) ;
|
|---|
| 603 | printf(" bytes\n") ;
|
|---|
| 604 | }
|
|---|
| 605 |
|
|---|
| 606 | void printstackmax_() {
|
|---|
| 607 | DoubleChainedBlock *stack = curStack ;
|
|---|
| 608 | int nbBlocks = (stack?-2:0) ;
|
|---|
| 609 | int remainder = 0;
|
|---|
| 610 | long int totalsz ;
|
|---|
| 611 | while(stack) {
|
|---|
| 612 | stack = stack->prev ;
|
|---|
| 613 | nbBlocks++ ;
|
|---|
| 614 | }
|
|---|
| 615 | stack = curStack ;
|
|---|
| 616 | while(stack) {
|
|---|
| 617 | stack = stack->next ;
|
|---|
| 618 | nbBlocks++ ;
|
|---|
| 619 | }
|
|---|
| 620 |
|
|---|
| 621 | printf(" Max Stack size (%i blocks): ", nbBlocks) ;
|
|---|
| 622 | printbigbytes((long int)nbBlocks, ONE_BLOCK_SIZE, (long int)0) ;
|
|---|
| 623 | printf(" bytes\n") ;
|
|---|
| 624 | }
|
|---|
| 625 |
|
|---|
| 626 | void printlookingplace_() {
|
|---|
| 627 | if (lookStack == NULL)
|
|---|
| 628 | printtopplace_() ;
|
|---|
| 629 | else {
|
|---|
| 630 | DoubleChainedBlock *stack = lookStack ;
|
|---|
| 631 | int nbBlocks = (stack?-1:0) ;
|
|---|
| 632 | while(stack) {
|
|---|
| 633 | stack = stack->prev ;
|
|---|
| 634 | nbBlocks++ ;
|
|---|
| 635 | }
|
|---|
| 636 | printf(" Stack look at: ") ;
|
|---|
| 637 | printbigbytes((long int)nbBlocks, ONE_BLOCK_SIZE,
|
|---|
| 638 | ((long int)(lookStackTop-(lookStack->contents)))) ;
|
|---|
| 639 | printf(" bytes\n") ;
|
|---|
| 640 | }
|
|---|
| 641 | }
|
|---|
| 642 |
|
|---|
| 643 | void showrecentcstack_() {
|
|---|
| 644 | if (curStack && curStackTop) {
|
|---|
| 645 | int totalNumChars = 60 ;
|
|---|
| 646 | DoubleChainedBlock *stack = curStack ;
|
|---|
| 647 | char *stackTop = curStackTop ;
|
|---|
| 648 | unsigned short int *st1 ;
|
|---|
| 649 | printf("TOP OF C STACK : ") ;
|
|---|
| 650 | while (totalNumChars>0 && stackTop>(stack->contents)) {
|
|---|
| 651 | stackTop-- ;
|
|---|
| 652 | /* ATTENTION!! en 64 bits, unsigned short int fait 2 octets, donc ce print est un peu faux */
|
|---|
| 653 | st1 = (unsigned short int *)stackTop ;
|
|---|
| 654 | printf("%02X,",*st1%256) ;
|
|---|
| 655 | totalNumChars-- ;
|
|---|
| 656 | }
|
|---|
| 657 | while (totalNumChars>0 && stack->prev) {
|
|---|
| 658 | printf(" || ") ;
|
|---|
| 659 | stack = stack->prev ;
|
|---|
| 660 | stackTop = (stack->contents)+ONE_BLOCK_SIZE ;
|
|---|
| 661 | while (totalNumChars>0 && stackTop>(stack->contents)) {
|
|---|
| 662 | stackTop-- ;
|
|---|
| 663 | st1 = (unsigned short int *)stackTop ;
|
|---|
| 664 | printf("%02X,",*st1%256) ;
|
|---|
| 665 | totalNumChars-- ;
|
|---|
| 666 | }
|
|---|
| 667 | }
|
|---|
| 668 | if (stack->prev || stackTop>(stack->contents))
|
|---|
| 669 | printf(" ...\n") ;
|
|---|
| 670 | else
|
|---|
| 671 | printf(" || BOTTOM\n") ;
|
|---|
| 672 | } else {
|
|---|
| 673 | printf("NOTHING IN C STACK.\n") ;
|
|---|
| 674 | }
|
|---|
| 675 | }
|
|---|
| 676 |
|
|---|
| 677 | void getnbblocksinstack_(int *nbblocks) {
|
|---|
| 678 | DoubleChainedBlock *stack = curStack ;
|
|---|
| 679 | *nbblocks = 0 ;
|
|---|
| 680 | while(stack) {
|
|---|
| 681 | stack = stack->prev ;
|
|---|
| 682 | (*nbblocks)++ ;
|
|---|
| 683 | }
|
|---|
| 684 | }
|
|---|
| 685 |
|
|---|
| 686 | /* Computes (and returns into its args) the number of blocks below the current
|
|---|
| 687 | * stack top (resp. look) position, and the number of bytes below
|
|---|
| 688 | * the current top (resp. look) position in the topmost block of the current
|
|---|
| 689 | * top (resp. look) position. */
|
|---|
| 690 | void getbigcsizes_(int *nbblocks, int *remainder, int *nbblockslook, int *lookremainder) {
|
|---|
| 691 | DoubleChainedBlock *stack ;
|
|---|
| 692 |
|
|---|
| 693 | stack = curStack ;
|
|---|
| 694 | *nbblocks = (stack?-1:0) ;
|
|---|
| 695 | while(stack) {
|
|---|
| 696 | stack = stack->prev ;
|
|---|
| 697 | (*nbblocks)++ ;
|
|---|
| 698 | }
|
|---|
| 699 | if (curStack && curStackTop)
|
|---|
| 700 | *remainder = curStackTop-(curStack->contents) ;
|
|---|
| 701 | else
|
|---|
| 702 | *remainder = 0 ;
|
|---|
| 703 |
|
|---|
| 704 | if (lookStack == NULL) {
|
|---|
| 705 | *nbblockslook = -999 ;
|
|---|
| 706 | *lookremainder = -999 ;
|
|---|
| 707 | } else {
|
|---|
| 708 | stack = lookStack ;
|
|---|
| 709 | *nbblockslook = (stack?-1:0) ;
|
|---|
| 710 | while(stack) {
|
|---|
| 711 | stack = stack->prev ;
|
|---|
| 712 | (*nbblockslook)++ ;
|
|---|
| 713 | }
|
|---|
| 714 | *lookremainder = lookStackTop-(lookStack->contents) ;
|
|---|
| 715 | }
|
|---|
| 716 | }
|
|---|