home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / fweb153.zip / fweb-1.53 / web / os.web < prev    next >
Text File  |  1995-09-23  |  7KB  |  249 lines

  1. @z --- os.web ---
  2.  
  3. FWEB version 1.53 (September 23, 1995)
  4.  
  5. Based on version 0.5 of S. Levy's CWEB [copyright (C) 1987 Princeton University]
  6.  
  7. @x-----------------------------------------------------------------------------
  8.  
  9. \Title{OS.WEB}
  10.  
  11. @c
  12.  
  13. @ This header file takes care of operating system/machine-dependent
  14. details, since not all (virtually none?) compilers are fully ANSI. Here,
  15. and elsewhere, macro commands that customize for a particular machine have
  16. a comment line that include the phrase ``\.{Machine-dependent}:''; search
  17. for that with an editor.
  18.  
  19. @A
  20. @<Beginning of \.{os.h}@>@;
  21. @<Operating system-specific macros@>@;
  22. @<End of \.{os.h}@>@;
  23.  
  24. @ The next two sections ensure that \.{os.h} is loaded only once.
  25. @<Beginning of \.{os.h}@>=
  26.  
  27. #ifndef OS_H_
  28. #define OS_H_
  29.  
  30. #ifdef HAVE_CONFIG_H
  31.     #include "config.h" /* \.{config.h} is generated by \.{./configure}. */
  32. #endif /* |HAVE_CONFIG_H| */
  33.  
  34. @
  35. @<End of \.{os.h}@>=
  36.  
  37. #endif // |OS_H_|
  38.  
  39. @i sfile.hweb
  40.  
  41. @ Here we read the customization file \.{custom.h} and an extra macro file
  42. \.{strmac.h}. 
  43.  
  44. @<Operating system-specific macros@>=
  45.  
  46. #include SFILE(custom.h) /* Macros defined by the user. */
  47.  
  48. @I proto.hweb
  49. @i includes.hweb
  50.  
  51. @ Some things might not be defined by the user, but they need values.
  52. @<Operating sys...@>=
  53.  
  54. #ifndef THE_SYSTEM
  55.     #define THE_SYSTEM "UNKNOWN"
  56. #endif
  57.  
  58. #ifndef LOCAL_BANNER
  59.     #define LOCAL_BANNER ""
  60. #endif
  61.  
  62. #ifndef NULL_FILE_NAME
  63.     #define NULL_FILE_NAME "null"
  64. #endif
  65.  
  66. #ifndef C_EXT
  67.     #define C_EXT "c"
  68. #endif
  69.  
  70. #ifndef M_EXT
  71.     #define M_EXT "mk"
  72. #endif
  73.  
  74. #ifndef X_EXT
  75.     #define X_EXT "sty"
  76. #endif
  77.  
  78. #ifndef Cpp_EXT 
  79.     #define Cpp_EXT "c++"
  80. #endif
  81.  
  82. #ifndef R_EXT
  83.     #define R_EXT "r"
  84. #endif
  85.  
  86. #ifndef R90_EXT
  87.     #define R90_EXT "r90"
  88. #endif
  89.  
  90. #ifndef N_EXT
  91.     #define N_EXT "f"
  92. #endif
  93.  
  94. #ifndef N90_EXT
  95.     #define N90_EXT "f90"
  96. #endif
  97.  
  98. #ifndef VARIABLE_ARGUMENTS
  99.     #define VARIABLE_ARGUMENTS 0
  100. #endif
  101.  
  102. #if VARIABLE_ARGUMENTS
  103.     #ifndef NUM_VA_ARGS
  104.         #define NUM_VA_ARGS 2
  105.     #endif
  106. #endif
  107.  
  108. #ifndef PREFIX_END_CHAR
  109.     #define PREFIX_END_CHAR '/'
  110. #endif
  111.  
  112.  
  113. @
  114. @<Operating sys...@>=
  115.  
  116. #ifndef _strmac_
  117.    #include SFILE(strmac.h) /* Macros for casting calls to string routines. */
  118. #endif /* |_strmac_| */
  119.  
  120. @  To get rid of warning messages about unused variables, it is convenient
  121. to include a macro that generates a dummy usage. One wants to retain some
  122. of these variables for future use in debugging; the dummy usage should
  123. presumable be optimized away so it doesn't affect execution speed.
  124.  
  125. @<Operating sys...@>=
  126.  
  127. #define UNUSED(var) var
  128.  
  129. @ For personal computers, we must worry about small vs.\ large memory
  130. models. The \FWEB\ processors must be compiled with the |HUGE| memory
  131. model. Among other things, that means that pointer arithmetic is done on
  132. the full \.{segment}:\.{offset} combination. However, in some cases, such
  133. as the Borland compiler, to ensure that the pointers are uniquely
  134. normalized we have to declare them explicitly to be |HUGE|.
  135.  
  136. @f HUGE huge
  137. @f HUGE_FCN_PTR huge
  138.  
  139. @<Operating sys...@>=
  140.  
  141. #define HUGE_FCN_PTR
  142.  
  143. #ifndef _POSIX_SOURCE
  144.     #define _POSIX_SOURCE // Otherwise, the Sun gets hopelessly confused.
  145. #endif
  146.  
  147. #include <math.h> // ANSI: Declarations of mathematics functions such as |pow|.
  148. #ifdef HUGE
  149.     #undef HUGE // The Sun's annoying.
  150. #endif
  151.  
  152. #if HUGE_POINTERS // \.{Machine-dependent}: Force full pointer arithmetic.
  153.     #define HUGE huge /* \It{Normalized} far pointer. */
  154. #else
  155.     #define HUGE // Null def'n for everything except personal computers.
  156. #endif // |HUGE_POINTERS|
  157.  
  158. @ Here we deal with various foibles of the individual compilers. For
  159. example, in ANSI |sprintf| returns the number of characters written, and
  160. that fact is used in a variety of places in the code; however, this value
  161. is not made available on the Sun. Also, the ellipsis is only available with
  162. function prototyping under \.{gcc}. Note that, as much as possible, we use
  163. C~macros, as this generally makes the output file more readable. (The
  164. ellipsis is an exception.)  We use \.{FWEB} macros only when they provide a
  165. feature not available from the C~preprocessor.
  166.  
  167. We also use the \.{FWEB} |$ASSERT| feature and the ANSI \.{\#error} feature
  168. to help ensure that the machine flags are consistent. The |$ASSERT| won't
  169. be expanded until \.{FTANGLE} starts writing the output file, but better late
  170. than never. Similarly, the \.{\#error} tests won't be recognized until one
  171. actually compiles.
  172.  
  173.  
  174. @ Not all the compilers recognize the ANSI unary plus sign. We don't really
  175. need it; we just use it occasionally for emphasis. Therefore, we just
  176. define it to be null.
  177.  
  178. @f PLUS $UNOP_
  179.  
  180. @<Operating sys...@>=
  181.  
  182. #define PLUS
  183.  
  184. @ Here we handle some deficiencies of the Aztec compiler on the Mac.
  185.  
  186. @<Operating sys...@>=
  187.  
  188. #define CAST(type,var) var
  189. #define _Xx(fmt) fmt
  190.  
  191. @#if 0 /* \.{Machine-dependent}: Idiosyncracies. */
  192.     @m CAST(type,var) ((type)var)
  193.     @m _Xx(fmt) $STRING($TRANSLIT(fmt,"X","x")) /* |printf| doesn't
  194. understand |"%X"|. */ 
  195. @#endif /* Idiosyncracies. */
  196.  
  197. @ Here we try to ensure that the machine-specific flags have been set up
  198. consistently, to save you some grief in working with a new machine.
  199.  
  200. @m INCOMPATIBLE(machine) `_P`##error "! INCOMPATIBLE compiler flags.\
  201. Is " machine " defined from the compiler's command line?"
  202.  
  203. @#if 0
  204.  
  205. $ASSERT(ANSI || APOLLO || DSU || IBMPC || MAC || MISC || SGI || SUN || VAX)@; 
  206.     /* \.{Machine-dependent}: Consistency check. */
  207.  
  208. /* \.{Machine-dependent}: It's assumed that the compiler, or the compiler's
  209. command line, defines a lower-case macro identifying the system/machine. */
  210. #if HAVE_ERROR
  211.     @#if VAX
  212.         #if !defined vax || defined sun || defined mac\
  213.                  || defined ibmpc || defined sgi
  214.             INCOMPATIBLE(vax)
  215.         #endif
  216.     @#elif SUN_GCC
  217.         #if !defined sun || defined vax || defined mac\
  218.                  || defined ibmpc || defined sgi
  219.             INCOMPATIBLE(sun)
  220.         #endif
  221.     @#elif IBMPC
  222.         #if !defined ibmpc || defined vax || defined sun\
  223.                  || defined mac || defined sgi
  224.             INCOMPATIBLE(ibmpc)
  225.         #elif !defined tcc && !defined mcc
  226. #error "You must define either `mcc' or `tcc' from the compiler's cmd line."
  227.         #elif defined tcc && defined mcc
  228. #error "You may define only one of `mcc' or `tcc', not both."
  229.         #endif
  230.     @#endif /* Individual machine checks. */
  231.  
  232. #endif // |HAVE_ERROR|
  233.  
  234. @#endif
  235.  
  236. @ Here are more checks for specific machine-dependent compiler flags that
  237. \It{must} be defined. 
  238.  
  239. @<Operating sys...@>=
  240.  
  241. @#if 0 // Sun-cc doesn't like \.{\#error}.
  242. #ifdef ibmpc
  243.     #if defined tcc && !defined(__HUGE__) /* Borland! */
  244.         #error "! You must compile all modules with the HUGE model!"
  245.     #endif /* |tcc| */
  246. #endif /* |IBMPC| */
  247. @#endif
  248.  
  249.