home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / lib / mntc6846.zoo / patch / stackerr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-17  |  1.1 KB  |  53 lines

  1. /*
  2.  *    _ s t a c k e r r
  3.  *
  4.  *  This file contains the routines that are called from the
  5.  *  C68 internal routine for stack checking.
  6.  *
  7.  *    _stack_error    When a failure occurs
  8.  *    _stack_newmax    When a new maximum value is reached
  9.  */
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <osbind.h>
  14.  
  15. long _stackmax;        /* the maximum space needed on stack */
  16. long _act_sp;        /* actual stack pointer value */
  17. static long stacksz;    /* used to hold stack size during maximum */
  18.  
  19. extern long _stksize;
  20. extern long _spbase;
  21.  
  22.  
  23. static void statistics( void )
  24. {
  25.     fflush( stdout );    /* clean up */
  26.  
  27.     fprintf( stderr, "\n*** Stack statistics:  Size = %lu,"
  28.         "  Max used = %lu ***\n", stacksz, _stackmax );
  29. }
  30.  
  31. void _stack_error( long new )
  32. {
  33.     fprintf( stderr, "\n** STACK CHECK ERROR **\n"
  34.                "size:\t%lu\tbytes\n"
  35.                "used:\t%lu\tbytes\n"
  36.                "needed:\t%lu\tbytes\n"
  37.                "*** PROGRAM ABORTED ***\n",
  38.         _stksize, _spbase - _act_sp, new );
  39.  
  40.     Pterm( 127 );  /* Better not use abort() here!!! */
  41. }
  42.  
  43. void _stack_newmax( void )
  44. {    static int once = 0;
  45.  
  46.     stacksz = _stksize;    /* _stksize might change! */
  47.  
  48.     if ( !once )
  49.     {    atexit( statistics );
  50.         once = 1;
  51.     }
  52. }
  53.