main.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* STARTUP PROCEDURE FOR UNIX FORTRAN PROGRAMS */
  2. #include "stdio.h"
  3. #include "signal1.h"
  4. #ifndef SIGIOT
  5. #ifdef SIGABRT
  6. #define SIGIOT SIGABRT
  7. #endif
  8. #endif
  9. #ifndef KR_headers
  10. #undef VOID
  11. #include "stdlib.h"
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #endif
  16. #ifndef VOID
  17. #define VOID void
  18. #endif
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. #ifdef NO__STDC
  23. #define ONEXIT onexit
  24. extern VOID f_exit();
  25. #else
  26. #ifndef KR_headers
  27. extern void f_exit(void);
  28. #ifndef NO_ONEXIT
  29. #define ONEXIT atexit
  30. extern int atexit(void (*)(void));
  31. #endif
  32. #else
  33. #ifndef NO_ONEXIT
  34. #define ONEXIT onexit
  35. extern VOID f_exit();
  36. #endif
  37. #endif
  38. #endif
  39. #ifdef KR_headers
  40. extern VOID f_init(), sig_die();
  41. extern int MAIN__();
  42. #define Int /* int */
  43. #else
  44. extern void f_init(void), sig_die(const char*, int);
  45. extern int MAIN__(void);
  46. #define Int int
  47. #endif
  48. static VOID sigfdie(Sigarg)
  49. {
  50. Use_Sigarg;
  51. sig_die("Floating Exception", 1);
  52. }
  53. static VOID sigidie(Sigarg)
  54. {
  55. Use_Sigarg;
  56. sig_die("IOT Trap", 1);
  57. }
  58. #ifdef SIGQUIT
  59. static VOID sigqdie(Sigarg)
  60. {
  61. Use_Sigarg;
  62. sig_die("Quit signal", 1);
  63. }
  64. #endif
  65. static VOID sigindie(Sigarg)
  66. {
  67. Use_Sigarg;
  68. sig_die("Interrupt", 0);
  69. }
  70. static VOID sigtdie(Sigarg)
  71. {
  72. Use_Sigarg;
  73. sig_die("Killed", 0);
  74. }
  75. #ifdef SIGTRAP
  76. static VOID sigtrdie(Sigarg)
  77. {
  78. Use_Sigarg;
  79. sig_die("Trace trap", 1);
  80. }
  81. #endif
  82. int xargc;
  83. char **xargv;
  84. #ifdef __cplusplus
  85. }
  86. #endif
  87. int
  88. #ifdef KR_headers
  89. main(argc, argv) int argc; char **argv;
  90. #else
  91. main(int argc, char **argv)
  92. #endif
  93. {
  94. xargc = argc;
  95. xargv = argv;
  96. signal1(SIGFPE, sigfdie); /* ignore underflow, enable overflow */
  97. #ifdef SIGIOT
  98. signal1(SIGIOT, sigidie);
  99. #endif
  100. #ifdef SIGTRAP
  101. signal1(SIGTRAP, sigtrdie);
  102. #endif
  103. #ifdef SIGQUIT
  104. if(signal1(SIGQUIT,sigqdie) == SIG_IGN)
  105. signal1(SIGQUIT, SIG_IGN);
  106. #endif
  107. if(signal1(SIGINT, sigindie) == SIG_IGN)
  108. signal1(SIGINT, SIG_IGN);
  109. signal1(SIGTERM,sigtdie);
  110. #ifdef pdp11
  111. ldfps(01200); /* detect overflow as an exception */
  112. #endif
  113. f_init();
  114. #ifndef NO_ONEXIT
  115. ONEXIT(f_exit);
  116. #endif
  117. MAIN__();
  118. #ifdef NO_ONEXIT
  119. f_exit();
  120. #endif
  121. exit(0); /* exit(0) rather than return(0) to bypass Cray bug */
  122. return 0; /* For compilers that complain of missing return values; */
  123. /* others will complain that this is unreachable code. */
  124. }
  125. #ifdef __cplusplus
  126. }
  127. #endif