home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / LIBSRC.ZOO / libsrc / gpp / gnulib3.c < prev    next >
Text File  |  1991-12-31  |  2KB  |  98 lines

  1. typedef struct set_vector
  2. {
  3.   int length;
  4.   int vector[1];
  5.   /* struct set_vector *next; */
  6. } set_vector;
  7.  
  8. extern set_vector __CTOR_LIST__;
  9. extern set_vector __DTOR_LIST__;
  10. set_vector *__dlp;
  11. int __dli;
  12.  
  13. extern void exit ();
  14. extern void __do_global_init ();
  15. extern void __do_global_cleanup ();
  16. extern void on_exit(void*, void*);
  17.  
  18. #if defined(i386) && !defined(sequent)
  19. #define COFF
  20. #endif
  21.  
  22. #ifdef COFF_ENCAPSULATE
  23. #undef COFF
  24. #endif
  25.  
  26. #if defined(sun)
  27. #define ON_EXIT(PROCP, ARG) \
  28.   do { extern void PROCP (); on_exit (PROCP, ARG); } while (0)
  29. #endif
  30.  
  31. int
  32. __main ()
  33. {
  34.   /* Gross hack for GNU ld.  This is defined in `builtin.cc'
  35.      from libg++.  */
  36. #ifndef COFF
  37.   extern int __1xyzzy__;
  38. #endif
  39.  
  40. #ifdef ON_EXIT
  41.  
  42. #ifdef sun
  43.   ON_EXIT (_cleanup, 0);
  44. #endif
  45.  
  46. #ifdef OS2
  47.   ON_EXIT (__do_global_cleanup);
  48. #else
  49.   ON_EXIT (__do_global_cleanup, 0);
  50. #endif
  51.  
  52. #endif
  53.   __dli = __DTOR_LIST__.length;
  54.   __dlp = &__DTOR_LIST__;
  55. #ifndef COFF
  56.   __do_global_init (&__1xyzzy__);
  57. #else
  58.   __do_global_init ();
  59. #endif
  60. }
  61.  
  62. #ifndef ON_EXIT
  63. void
  64. exit (status)
  65.      int status;
  66. {
  67.   __do_global_cleanup ();
  68.   _cleanup ();
  69.   _exit (status);
  70. }
  71. #endif
  72.  
  73. void
  74. __do_global_init ()
  75. {
  76.   register int i, len;
  77.   register void (**ppf)() = (void (**)())__CTOR_LIST__.vector;
  78.  
  79.   len = __CTOR_LIST__.length;
  80.   for (i = 0; i < len; i++)
  81.     (*ppf[i])();
  82. }
  83.  
  84. void
  85. __do_global_cleanup ()
  86. {
  87.   while (__dlp)
  88.     {
  89.       while (--__dli >= 0)
  90.     {
  91.       void (*pf)() = (void (*)())__dlp->vector[__dli];
  92.       (*pf)();
  93.     }
  94.       __dlp = (struct set_vector *)__dlp->vector[__dlp->length];
  95.       if (__dlp) __dli = __dlp->length;
  96.     }
  97. }
  98.