source: CIVL/examples/experimental/reverse_CIVL/ADFirstAidKit/adStack.c

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 18.8 KB
Line 
1static 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. */
14typedef 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: */
21static DoubleChainedBlock *curStack = NULL ;
22static char *curStackTop = NULL ;
23/* Globals that define the current LOOKing position in the stack: */
24static DoubleChainedBlock *lookStack = NULL ;
25static char *lookStackTop = NULL ;
26
27static long int mmctraffic = 0 ;
28static long int mmctrafficM = 0 ;
29#ifdef STACK_SIZE_TRACING
30long 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. */
37void 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. */
98void 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. */
133void 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
163void resetadlookstack_() {
164 lookStack=NULL ;
165}
166
167/****** Exported PUSH/POP/LOOK functions for ARRAYS: ******/
168/* --> Called from FORTRAN: */
169
170void pushcharacterarray_(char *x, unsigned int *n) {
171 pushNarray(x,*n) ;
172}
173void popcharacterarray_(char *x, unsigned int *n) {
174 popNarray(x,*n) ;
175}
176void lookcharacterarray_(char *x, unsigned int *n) {
177 lookNarray(x,*n) ;
178}
179
180void pushbooleanarray_(char *x, unsigned int *n) {
181 pushNarray(x,(*n*4)) ;
182}
183void popbooleanarray_(char *x, unsigned int *n) {
184 popNarray(x,(*n*4)) ;
185}
186void lookbooleanarray_(char *x, unsigned int *n) {
187 lookNarray(x,(*n*4)) ;
188}
189
190void pushinteger4array_(void *x, unsigned int *n) {
191 pushNarray((char *)x,(*n*4)) ;
192}
193void popinteger4array_(void *x, unsigned int *n) {
194 popNarray((char *)x,(*n*4)) ;
195}
196void lookinteger4array_(void *x, unsigned int *n) {
197 lookNarray((char *)x,(*n*4)) ;
198}
199
200void pushinteger8array_(void *x, unsigned int *n) {
201 pushNarray((char *)x,(*n*8)) ;
202}
203void popinteger8array_(void *x, unsigned int *n) {
204 popNarray((char *)x,(*n*8)) ;
205}
206void lookinteger8array_(void *x, unsigned int *n) {
207 lookNarray((char *)x,(*n*8)) ;
208}
209
210void pushinteger16array_(void *x, unsigned int *n) {
211 pushNarray((char *)x,(*n*16)) ;
212}
213void popinteger16array_(void *x, unsigned int *n) {
214 popNarray((char *)x,(*n*16)) ;
215}
216void lookinteger16array_(void *x, unsigned int *n) {
217 lookNarray((char *)x,(*n*16)) ;
218}
219
220void pushreal4array_(void *x, unsigned int *n) {
221 pushNarray((char *)x,(*n*4)) ;
222}
223void popreal4array_(void *x, unsigned int *n) {
224 popNarray((char *)x,(*n*4)) ;
225}
226void lookreal4array_(void *x, unsigned int *n) {
227 lookNarray((char *)x,(*n*4)) ;
228}
229
230void pushreal8array_(void *x, unsigned int *n) {
231 pushNarray((char *)x,(*n*8)) ;
232}
233void popreal8array_(void *x, unsigned int *n) {
234 popNarray((char *)x,(*n*8)) ;
235}
236void lookreal8array_(void *x, unsigned int *n) {
237 lookNarray((char *)x,(*n*8)) ;
238}
239
240void pushreal16array_(void *x, unsigned int *n) {
241 pushNarray((char *)x,(*n*16)) ;
242}
243void popreal16array_(void *x, unsigned int *n) {
244 popNarray((char *)x,(*n*16)) ;
245}
246void lookreal16array_(void *x, unsigned int *n) {
247 lookNarray((char *)x,(*n*16)) ;
248}
249
250void pushreal32array_(void *x, unsigned int *n) {
251 pushNarray((char *)x,(*n*32)) ;
252}
253void popreal32array_(void *x, unsigned int *n) {
254 popNarray((char *)x,(*n*32)) ;
255}
256void lookreal32array_(void *x, unsigned int *n) {
257 lookNarray((char *)x,(*n*32)) ;
258}
259
260void pushcomplex4array_(void *x, unsigned int *n) {
261 pushNarray((char *)x,(*n*4)) ;
262}
263void popcomplex4array_(void *x, unsigned int *n) {
264 popNarray((char *)x,(*n*4)) ;
265}
266void lookcomplex4array_(void *x, unsigned int *n) {
267 lookNarray((char *)x,(*n*4)) ;
268}
269
270void pushcomplex8array_(void *x, unsigned int *n) {
271 pushNarray((char *)x,(*n*8)) ;
272}
273void popcomplex8array_(void *x, unsigned int *n) {
274 popNarray((char *)x,(*n*8)) ;
275}
276void lookcomplex8array_(void *x, unsigned int *n) {
277 lookNarray((char *)x,(*n*8)) ;
278}
279
280void pushcomplex16array_(void *x, unsigned int *n) {
281 pushNarray((char *)x,(*n*16)) ;
282}
283void popcomplex16array_(void *x, unsigned int *n) {
284 popNarray((char *)x,(*n*16)) ;
285}
286void lookcomplex16array_(void *x, unsigned int *n) {
287 lookNarray((char *)x,(*n*16)) ;
288}
289
290void pushcomplex32array_(void *x, unsigned int *n) {
291 pushNarray((char *)x,(*n*32)) ;
292}
293void popcomplex32array_(void *x, unsigned int *n) {
294 popNarray((char *)x,(*n*32)) ;
295}
296void lookcomplex32array_(void *x, unsigned int *n) {
297 lookNarray((char *)x,(*n*32)) ;
298}
299
300/****** Exported PUSH/POP/LOOK functions for F95 POINTERS: ******/
301
302void pushpointer4_(void *ppp) {
303 pushNarray((char *)ppp, 4) ;
304}
305
306void lookpointer4_(void *ppp) {
307 lookNarray((char *)ppp, 4) ;
308}
309
310void poppointer4_(void *ppp) {
311 popNarray((char *)ppp, 4) ;
312}
313
314void pushpointer8_(void *ppp) {
315 pushNarray((char *)ppp, 8) ;
316}
317
318void lookpointer8_(void *ppp) {
319 lookNarray((char *)ppp, 8) ;
320}
321
322void poppointer8_(void *ppp) {
323 popNarray((char *)ppp, 8) ;
324}
325
326/* --> Called from C: */
327
328void pushcharacterarray(char *x, int n) {
329 pushNarray(x,(unsigned int)n) ;
330}
331void popcharacterarray(char *x, int n) {
332 popNarray(x,(unsigned int)n) ;
333}
334void lookcharacterarray(char *x, int n) {
335 lookNarray(x,(unsigned int)n) ;
336}
337
338void pushbooleanarray(char *x, int n) {
339 pushNarray(x,(unsigned int)(n*4)) ;
340}
341void popbooleanarray(char *x, int n) {
342 popNarray(x,(unsigned int)(n*4)) ;
343}
344void lookbooleanarray(char *x, int n) {
345 lookNarray(x,(unsigned int)(n*4)) ;
346}
347
348void pushinteger4array(int *x, int n) {
349 pushNarray((char *)x,(unsigned int)(n*4)) ;
350}
351void popinteger4array(int *x, int n) {
352 popNarray((char *)x,(unsigned int)(n*4)) ;
353}
354void lookinteger4array(int *x, int n) {
355 lookNarray((char *)x,(unsigned int)(n*4)) ;
356}
357
358void pushinteger8array(long int *x, int n) {
359 pushNarray((char *)x,(unsigned int)(n*8)) ;
360}
361void popinteger8array(long int *x, int n) {
362 popNarray((char *)x,(unsigned int)(n*8)) ;
363}
364void lookinteger8array(long int *x, int n) {
365 lookNarray((char *)x,(unsigned int)(n*8)) ;
366}
367
368void pushinteger16array(long long int *x, int n) {
369 pushNarray((char *)x,(unsigned int)(n*16)) ;
370}
371void popinteger16array(long long int *x, int n) {
372 popNarray((char *)x,(unsigned int)(n*16)) ;
373}
374void lookinteger16array(long long int *x, int n) {
375 lookNarray((char *)x,(unsigned int)(n*16)) ;
376}
377
378void pushreal4array(float *x, int n) {
379 pushNarray((char *)x, (unsigned int)(n*4)) ;
380}
381void popreal4array(float *x, int n) {
382 popNarray((char *)x, (unsigned int)(n*4)) ;
383}
384void lookreal4array(float *x, int n) {
385 lookNarray((char *)x, (unsigned int)(n*4)) ;
386}
387
388void pushreal8array(double *x, int n) {
389 pushNarray((char *)x,(unsigned int)(n*8)) ;
390}
391void popreal8array(double *x, int n) {
392 popNarray((char *)x,(unsigned int)(n*8)) ;
393}
394void lookreal8array(double *x, int n) {
395 lookNarray((char *)x,(unsigned int)(n*8)) ;
396}
397
398void pushreal16array(void *x, int n) {
399 pushNarray((char *)x,(unsigned int)(n*16)) ;
400}
401void popreal16array(void *x, int n) {
402 popNarray((char *)x,(unsigned int)(n*16)) ;
403}
404void lookreal16array(void *x, int n) {
405 lookNarray((char *)x,(unsigned int)(n*16)) ;
406}
407
408void pushreal32array(void *x, int n) {
409 pushNarray((char *)x,(unsigned int)(n*32)) ;
410}
411void popreal32array(void *x, int n) {
412 popNarray((char *)x,(unsigned int)(n*32)) ;
413}
414void lookreal32array(void *x, int n) {
415 lookNarray((char *)x,(unsigned int)(n*32)) ;
416}
417
418void pushcomplex4array(void *x, int n) {
419 pushNarray((char *)x,(unsigned int)(n*4)) ;
420}
421void popcomplex4array(void *x, int n) {
422 popNarray((char *)x,(unsigned int)(n*4)) ;
423}
424void lookcomplex4array(void *x, int n) {
425 lookNarray((char *)x,(unsigned int)(n*4)) ;
426}
427
428void pushcomplex8array(void *x, int n) {
429 pushNarray((char *)x,(unsigned int)(n*8)) ;
430}
431void popcomplex8array(void *x, int n) {
432 popNarray((char *)x,(unsigned int)(n*8)) ;
433}
434void lookcomplex8array(void *x, int n) {
435 lookNarray((char *)x,(unsigned int)(n*8)) ;
436}
437
438void pushcomplex16array(void *x, int n) {
439 pushNarray((char *)x,(unsigned int)(n*16)) ;
440}
441void popcomplex16array(void *x, int n) {
442 popNarray((char *)x,(unsigned int)(n*16)) ;
443}
444void lookcomplex16array(void *x, int n) {
445 lookNarray((char *)x,(unsigned int)(n*16)) ;
446}
447
448void pushcomplex32array(void *x, int n) {
449 pushNarray((char *)x,(unsigned int)(n*32)) ;
450}
451void popcomplex32array(void *x, int n) {
452 popNarray((char *)x,(unsigned int)(n*32)) ;
453}
454void lookcomplex32array(void *x, int n) {
455 lookNarray((char *)x,(unsigned int)(n*32)) ;
456}
457
458void pushpointer4array(void *x, int n) {
459 pushNarray((char *)x, (unsigned int)(n*4)) ;
460}
461void poppointer4array(void *x, int n) {
462 popNarray((char *)x, (unsigned int)(n*4)) ;
463}
464void lookpointer4array(void *x, int n) {
465 lookNarray((char *)x, (unsigned int)(n*4)) ;
466}
467
468void pushpointer8array(void *x, int n) {
469 pushNarray((char *)x,(unsigned int)(n*8)) ;
470}
471void poppointer8array(void *x, int n) {
472 popNarray((char *)x,(unsigned int)(n*8)) ;
473}
474void 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
480void 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
558void printctraffic_() {
559 printf(" C Traffic: ") ;
560 printbigbytes(mmctrafficM, 1000000, mmctraffic) ;
561 printf(" bytes\n") ;
562}
563
564void 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
570void 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
578void 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
592void 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
606void 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
626void 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
643void 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
677void 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. */
690void 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}
Note: See TracBrowser for help on using the repository browser.