home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / program / funnel / style.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-23  |  13.2 KB  |  259 lines

  1. /*##############################################################################
  2.  
  3. FUNNNELWEB COPYRIGHT
  4. ====================
  5. FunnelWeb is a literate-programming macro preprocessor.
  6.  
  7. Copyright (C) 1992 Ross N. Williams.
  8.  
  9.    Ross N. Williams
  10.    ross@spam.adelaide.edu.au
  11.    16 Lerwick Avenue, Hazelwood Park 5066, Australia.
  12.  
  13. This program is free software; you can redistribute it and/or modify
  14. it under the terms of Version 2 of the GNU General Public License as
  15. published by the Free Software Foundation.
  16.  
  17. This program is distributed WITHOUT ANY WARRANTY; without even the implied
  18. warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  19. See Version 2 of the GNU General Public License for more details.
  20.  
  21. You should have received a copy of Version 2 of the GNU General Public
  22. License along with this program. If not, you can FTP the license from
  23. prep.ai.mit.edu/pub/gnu/COPYING-2 or write to the Free Software
  24. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  25.  
  26. Section 2a of the license requires that all changes to this file be
  27. recorded prominently in this file. Please record all changes here.
  28.  
  29. Programmers:
  30.    RNW  Ross N. Williams  ross@spam.adelaide.edu.au
  31.  
  32. Changes:
  33.    07-May-1992  RNW  Program prepared for release under GNU GPL V2.
  34.  
  35. ##############################################################################*/
  36.  
  37.  
  38. /******************************************************************************/
  39. /*                                    STYLE.H                                 */
  40. /******************************************************************************/
  41. /*                                                                            */
  42. /* WARNING: DO NOT ADD ANY MACHINE OR PROGRAM DEPENDENT DEFINITIONS.          */
  43. /*                                                                            */
  44. /* This style.h file contains program-independent, machine-independent        */
  45. /* definitions that assist C programming in general. Nothing in this file     */
  46. /* should require modification if this file is moved to a new machine or used */
  47. /* in a new computer program. However, it may use abstracted second-order     */
  48. /* definitions from the machine-dependent, program independent module         */
  49. /* "environ".                                                                 */
  50. /*                                                                            */
  51. /******************************************************************************/
  52.  
  53. /* Ensure that the body of this header file is included at most once.         */
  54. #ifndef DONE_STYLE
  55. #define DONE_STYLE
  56.  
  57. /******************************************************************************/
  58.  
  59. /* System File Inclusions                                                     */
  60. /* ----------------------                                                     */
  61. /* In order to support a readable programming style, symbols such as TRUE and */
  62. /* NULL are essential. However, environments differ as to whether and where   */
  63. /* these symbols are defined. This can lead to multiple definition errors     */
  64. /* where (say) this style.h file is included in a .C file before <stdlib.h>.  */
  65. /* I did a quick survey of all the .C FunnelWeb modules and found the         */
  66. /* following:                                                                 */
  67. /*                                                                            */
  68. /*    Total files     = 54                                                    */
  69. /*    Number .C files = 22                                                    */
  70. /*    Number .H files = 32                                                    */
  71. /*    Used <stdlib.h> = 19                                                    */
  72. /*    Used <stdio.h>  = 16                                                    */
  73. /*    Used <string.h> = 12                                                    */
  74. /*    Used <ctype.h>  =  6                                                    */
  75. /*    Used <stddef.h> =  4                                                    */
  76. /*    Used <limits.h> =  2                                                    */
  77. /*    Used <setjmp.h> =  1                                                    */
  78. /*                                                                            */
  79. /* Most of these inclusions were in the .C files.                             */
  80. /* It therefore seemed sensible to include some very commonly used system     */
  81. /* header files here and header files that cause problems if not included     */
  82. /* before style.h (<stddef.h>).                                               */
  83.  
  84. #include <stdio.h>
  85. #include <stdlib.h>
  86. #include <string.h>
  87. #include <stddef.h>
  88.  
  89. /******************************************************************************/
  90.  
  91. /* Although this file is machine independent, it still needs some generic     */
  92. /* definitions whose values vary from machine to machine (see above).         */
  93. #include "environ.h"
  94.  
  95. /******************************************************************************/
  96.  
  97. /* The following types provide a clear and consistent collection of names for */
  98. /* C's arithmetic types. Each name describes only the portable range that the */
  99. /* underlying type supports. As in C, there are no guarantees about the       */
  100. /* MAXIMUM size of each underlying type and these types can provide no        */
  101. /* guarantees either. In the normal case, they translate to the most speed    */
  102. /* efficient type that will support the specified range. However, to support  */
  103. /* the situations where space efficiency is required, types ending in         */
  104. /* underscores have been defined that strive to conserve memory.              */
  105. /* Note: The signedness of a type does not change when an _ is added.         */
  106. /*                                                                            */
  107. /* The following terminology may be a touch vaxcentric, but it works for me.  */
  108. /*    A BYTE is an  8 bit quantity.                                           */
  109. /*    A WORD is a  16 bit quantity.                                           */
  110. /*    A LONG is a  32 bit quantity.                                           */
  111.  
  112. typedef unsigned        ubyte  ; /* Unsigned, [0,255].                        */
  113. typedef unsigned char   ubyte_ ; /* Unsigned, [0,255].         Space first.   */
  114. typedef int             word   ; /* Signed  , [-32767,+32767].                */
  115. typedef short           word_  ; /* Signed  , [-32767,+32767]. Space first.   */
  116. typedef unsigned        uword  ; /* Unsigned, [0,65535].                      */
  117. typedef unsigned short  uword_ ; /* Unsigned, [0,+65535].      Space first.   */
  118. typedef unsigned long   ulong  ; /* Unsigned, [0,(2^32)-1].                   */
  119.  
  120. typedef unsigned        bool   ; /* Unsigned, [0,1].                          */
  121. typedef unsigned char   bool_  ; /* Unsigned, [0,1].           Space first.   */
  122.  
  123. typedef int             sign   ; /* Signed  , [-1,0,1].                       */
  124.  
  125. /******************************************************************************/
  126.  
  127. /* C overloads the attribute keyword "static" horribly giving it meaning on   */
  128. /* both the scoping and lifetime dimensions.  This section gives definitions  */
  129. /* that clarify its use. If these macros are used, there should be no need    */
  130. /* for the keyword "static" in programs using this style file.                */
  131.  
  132. /* The following macros assist in making the scope of functions clearer. In   */
  133. /* deciding on the names of these macros, I chose from the following lists:   */
  134. /*    file    scope: PRIVATE, LOCAL, HIDDEN.                                  */
  135. /*    program scope: EXPORT, PUBLIC, GLOBAL.                                  */
  136. /* In the end I chose LOCAL and EXPORT. Note: I didn't want to allow more     */
  137. /* than one form as that would have created too much confusion.               */
  138. #define LOCAL  static
  139. #define EXPORT
  140.  
  141. /* It is desirable to use separate keywords for variables. This makes it      */
  142. /* easier to search for them without stopping at every function. There are    */
  143. /* four classes of variable that we wish to tag, along the two dimensions     */
  144. /* scope:(local,global) and lifetime:(permanent,temporary). In C, all         */
  145. /* variables declared outside of functions have permanent lifetime and so     */
  146. /* the following two names (which should be used only to tag variables not    */
  147. /* declared within a function) have been designed to emphasise the scope      */
  148. /* dimension which is the principal concern for these variables.              */
  149. #define LOCVAR static
  150. #define GLOVAR
  151.  
  152. /* Variables local to functions always have local scope and so the dimension  */
  153. /* to emphasise is the lifetime. Automatic variables are the most common in   */
  154. /* C and it would be messy to declare them all using a keyword. Far better    */
  155. /* just to tag static local variables, emphasising their lifetime (STAtic).   */
  156. #define STAVAR static
  157.  
  158. /******************************************************************************/
  159.  
  160. /* The following definitions are useful for dealing with void.                */
  161. /* The typedefed definition "p_void" should always be used instead of         */
  162. /* "void *" so as to improve portability.                                     */
  163. /* The definition of "void" and "p_void" come from environ.h                  */
  164. typedef p_void *p_p_void;
  165. #define PV     (p_void)
  166. #define PPV    (p_p_void)
  167.  
  168. /******************************************************************************/
  169.  
  170. /* The following symbols are more mnemonic than character escape sequences.   */
  171. #define EOS '\0'
  172. #define EOL '\n'
  173.  
  174. /******************************************************************************/
  175.  
  176. /* The ANSI library functions use many different techniques for returning     */
  177. /* status information. For example, fopen returns NULL upon failure, but      */
  178. /* fclose returns EOF upon failure. The result is that it is hard to          */
  179. /* proofread calls to these routines without constantly referring to the      */
  180. /* library manual. To avoid this problem, we define symbols with helpful      */
  181. /* names for the different values returned. This makes the code obvious.      */
  182.  
  183. /* 07-Feb-1992: During porting I ran into a problem here with FPUTS_S. I had  */
  184. /* defined it to be zero, as stated in the THINK C V4 ANSI library guide.     */
  185. /* However, it turned out that fputs() returns EOF (-1) on failure and the    */
  186. /* value that it returns on success is non negative! (See ANSI (7.9.7.4)).    */
  187. /* Caught by an overspecification by the THINK C people! The lesson is that   */
  188. /* it is very important to make sure that each function's status check symbol */
  189. /* is defined on the "right" side (success or failure) - that is, the side    */
  190. /* for which a single value for that status is guaranteed portably.           */
  191. /* The following values have all been checked for this.                       */
  192.  
  193. /* Note: _F=Failure, _S=Success, _FE=Failure or End of File.                  */
  194.  
  195. #define FOPEN_F  (NULL)
  196. #define FSEEK_S     (0)
  197. #define FTELL_F   (-1L)
  198. #define FGETC_FE  (EOF)
  199. #define FGETS_FE (NULL)
  200. #define FPUTC_F   (EOF)
  201. #define FPUTS_F   (EOF)
  202. #define FFLUSH_S    (0)
  203. #define FCLOSE_F  (EOF)
  204. #define REMOVE_S    (0)
  205. #define RENAME_S    (0)
  206. #define MALLOC_F (NULL)
  207.  
  208. /******************************************************************************/
  209.  
  210. /* The following macro functions are handy. However, be sure not to hand them */
  211. /* an argument with a non-idempotent side effect!!! (e.g. MAX(a++,b)).        */
  212. #define MIN(A,B) ((A)<(B) ? (A) : (B))
  213. #define MAX(A,B) ((A)>(B) ? (A) : (B))
  214.  
  215. /******************************************************************************/
  216.  
  217. /* Some environments don't define some stuff we need so we do it here.        */
  218. /* Cautiously!                                                                */
  219.  
  220. #ifndef FALSE
  221. #define FALSE (0)
  222. #endif
  223.  
  224. #ifndef TRUE
  225. #define TRUE (1)
  226. #endif
  227.  
  228. #ifndef EXIT_FAILURE
  229. #define EXIT_FAILURE (-1)
  230. #endif
  231.  
  232. #ifndef EXIT_SUCCESS
  233. #define EXIT_SUCCESS (0)
  234. #endif
  235.  
  236. /******************************************************************************/
  237.  
  238. /* The standard library macro/function "isprint" can be too loose in some     */
  239. /* circumstances on some machines and it is convenient to define a macro      */
  240. /* that provides a more strict 7-bit ASCII definition of "printable".         */
  241. #define isascprn(ch) ((' '<=ch) && (ch<='~'))
  242.  
  243. /******************************************************************************/
  244.  
  245. /* Some compilers (GCC at least) complain about characters as a type in a     */
  246. /* function argument. The following typedef is a quick hack that lets me say  */
  247. /* that I really wanted the function argument to be a character, while        */
  248. /* actually supplying an integer.                                             */
  249. typedef int intchar;
  250.  
  251. /******************************************************************************/
  252. /* For #ifndef preventing multiple inclusion of the body of this header file. */
  253. #endif
  254.  
  255. /******************************************************************************/
  256. /*                                End of STYLE.H                              */
  257. /******************************************************************************/
  258.  
  259.