home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / FUNNEL_S / SOURCES / MACHIN.H < prev    next >
C/C++ Source or Header  |  1992-05-27  |  14KB  |  301 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. /*                                    MACHIN.H                                */
  40. /******************************************************************************/
  41. /*                                                                            */
  42. /* WARNING: DO NOT ADD ANY PROGRAM DEPENDENT DEFINITIONS.                     */
  43. /*                                                                            */
  44. /* This module (machin.h and machin.c) contains definitions and objects       */
  45. /* whose values depends directly on the compilation and execution             */
  46. /* environment, but are otherwise independent from any particular computer    */
  47. /* program.                                                                   */
  48. /*                                                                            */
  49. /* The only difference between the purpose of this module and the "environ"   */
  50. /* module is that the "environ" module contains the "essentials" whereas this */
  51. /* module contains extra machine specific definitions and objects that will   */
  52. /* not be required by most user modules.                                      */
  53. /*                                                                            */
  54. /******************************************************************************/
  55.  
  56. /* Ensure that the body of this header file is included at most once.         */
  57. #ifndef DONE_FWMACHIN
  58. #define DONE_FWMACHIN
  59.  
  60. /******************************************************************************/
  61.  
  62. #include <time.h>
  63. #include "style.h"
  64.  
  65. /******************************************************************************/
  66.  
  67. /* Machine Alignment Constraints                                              */
  68. /* -----------------------------                                              */
  69. /* Some machines require that objects of particular lengths be aligned in     */
  70. /* memory. For example, the 68000 will trap any attempt to access a word      */
  71. /* (16 bits or an int in THINK C) at an odd address. It is important that C   */
  72. /* programs that deal with memory at a low level be aware of such             */
  73. /* constraints. As the constraints are always at a power of two, we defined   */
  74. /* ALIGN_POWER to be the minimum power of two at which it is both safe and    */
  75. /* efficient to operate.                                                      */
  76.  
  77. /* The Macintosh requires words and longs to be aligned on word boundaries.   */
  78. /* The PC is not fussy about alignment, but operates more efficiently at word */
  79. /* boundaries.                                                                */
  80. #if MAC | PC
  81. #define ALIGN_POWER (1L)
  82. #endif
  83.  
  84. /* The Sun requires objects to be aligned on longword boundaries (=2^2).      */
  85. /* The VMS VAX doesn't care about alignment, but operates more efficiently on */
  86. /* longword boundaries.                                                       */
  87. #if SUN | VMS
  88. #define ALIGN_POWER (2L)
  89. #endif
  90.  
  91. /******************************************************************************/
  92.  
  93. /* Filenames                                                                  */
  94. /* ---------                                                                  */
  95. /* The length and structure of filenames varies from machine to machine. The  */
  96. /* differences addressed here are:                                            */
  97. /*    1) The character used to separate directory specs from filenames.       */
  98. /*    2) The maximum length of a filename.                                    */
  99.  
  100. /* FN_DELIM must contain the character that separates directory specs from    */
  101. /* filenames. Notice that in the VMS case, it is "]", not "."                 */
  102.  
  103. #if MAC
  104. #define FN_DELIM ':'
  105. #endif
  106.  
  107. #if SUN
  108. #define FN_DELIM '/'
  109. #endif
  110.  
  111. #if VAX
  112. #define FN_DELIM ']'
  113. #endif
  114.  
  115. #if PC
  116. #define FN_DELIM '\\'
  117. #endif
  118.  
  119. /* The rest of this section shouldn't have to be changed, unless you          */
  120. /* encounter a funny with your system's definition of FILENAME_MAX.           */
  121.  
  122. /* FILENAME_MAX tells the maximum number of characters allowed in a filename  */
  123. /* on the target machine. This symbol is supposed to be defined in stdio.h    */
  124. /* (ANSI S7.9.1) so we don't want to override that. However, if it isn't, we  */
  125. /* need to define a safe default length.                                      */
  126. #ifndef FILENAME_MAX
  127. #define FILENAME_MAX 300
  128. #endif
  129.  
  130. /* Some VAX compilers define FILENAME_MAX to be 39, which is the maximum      */
  131. /* length of the NAME part of a VMS filename. This is not appropriate, so we  */
  132. /* override it.                                                               */
  133. #if VMS
  134. #undef FILENAME_MAX
  135. #define FILENAME_MAX 255        /* Should really be NAM$C_MAXRSS              */
  136. #endif
  137.  
  138. /* Now we can use the constant to define a filename type.                     */
  139. /* Note: For a while I defined "typedef fn_t *p_fn_t". However, this is a     */
  140. /* pointer to an array rather than (char *) and it caused no end of problems. */
  141. typedef char fn_t[FILENAME_MAX+1];
  142. typedef char *p_fn_t;
  143.  
  144. /******************************************************************************/
  145.  
  146. /* Command Lines                                                              */
  147. /* -------------                                                              */
  148. /* The maximum length of command line varies from machine to machine and we   */
  149. /* define symbols to reflect this. The reason why we don't just set this to a */
  150. /* high value and forget about it is that FunnelWeb sometimes places          */
  151. /* command line variables on the stack, and some machines (e.g. MAC under     */
  152. /* THINK-C don't provide much stack space. So we have to minimize this        */
  153. /* variable on those machines.                                                */
  154.  
  155. /* We choose a small maximum command line on the Macintosh so as to avoid     */
  156. /* chewing up stack space when command lines have to be pushed.               */
  157. #if MAC
  158. #define COMLINE_MAX 300
  159. #endif
  160.  
  161. /* On the Sun, 1024 is a normal command line and 2048 is safe. */
  162. #if SUN
  163. #define COMLINE_MAX 2048
  164. #endif
  165.  
  166. /* On the VMS, 1024 is usually adequate. */
  167. #if VMS
  168. #define COMLINE_MAX 1024
  169. #endif
  170.  
  171. /* On a PC, we assume this is enough. */
  172. #if PC
  173. #define COMLINE_MAX 300
  174. #endif
  175.  
  176. /* Make sure that the value is not too low. */
  177. /* The value 300 is guaranteed by the command interpreter. */
  178. #if COMLINE_MAX < 300
  179.    #error COMLINE_MAX must be at least 300.
  180. #endif
  181.  
  182. /* Now define a type for command lines.                                       */
  183. /* Note: For a while I defined "typedef cl_t *p_cl_t". However, this is a     */
  184. /* pointer to an array rather than (char *) and it caused no end of problems. */
  185. typedef char cl_t[COMLINE_MAX+1];
  186. typedef char *p_cl_t;
  187.  
  188. /******************************************************************************/
  189.  
  190. /* Line Termination                                                           */
  191. /* ----------------                                                           */
  192.  
  193. /* FunnelWeb has special-case code to make reading input files faster on      */
  194. /* machines where the format of text files corresponds to the internal C      */
  195. /* text stream model. The UNIX_EOL #define should be activated if and only    */
  196. /* the host environment has text files consisting of a stream of bytes with   */
  197. /* a single LF (ASCII,decimal-10,hex-0A) character being used to terminate    */
  198. /* each line, and no special character to indicate end of file.               */
  199. /* This is the same format as is used in the Unix operating system.           */
  200. /* If you are in doubt about this, play it safe and define your environment   */
  201. /* to be non-Unix, as non-Unix will work on ALL systems (including Unix).     */
  202.  
  203. #if MAC | VMS | PC
  204. /* These systems do NOT use Unix EOLs. */
  205. #define UNIX_EOL 0
  206. #endif
  207.  
  208. #if SUN
  209. /* This should really be 1 on a SUN, but I haven't got around to debugging    */
  210. /* FunnelWeb with UNIX_EOL==1.                                                */
  211. #define UNIX_EOL 0
  212. #endif
  213.  
  214. /******************************************************************************/
  215.  
  216. /* MIssing Prototypes                                                         */
  217. /* ----------------                                                           */
  218. /* Compilers that are fussy about prototypes sometimes complain about calls   */
  219. /* to the standard libraries. These declarations solve this problem.          */
  220.  
  221. #if SUN
  222. int     fclose  P_((FILE *stream));
  223. int     fputs   P_((const char *s, FILE *stream));
  224. int     fputc   P_((int c, FILE *stream));
  225. int     fflush  P_((FILE *stream));
  226. int     remove  P_((const char *filename));
  227. int     rename  P_((const char *oldname, const char *newname));
  228. int     toupper P_((int));
  229. int     sscanf  P_(());
  230. int     fprintf P_(());
  231. int     _filbuf P_(());
  232. void    *memcpy P_((void *s1, void *s2, size_t n));
  233. void    *memset P_((void *s,     int c, size_t n));
  234. int     memcmp  P_((void *s1, void *s2, size_t n));
  235. size_t  fread   P_((void *ptr, size_t size, size_t nobj, FILE *stream));
  236. size_t  fwrite  P_((const void *ptr, size_t size, size_t nobj, FILE *stream));
  237. clock_t clock   P_((void));
  238. time_t  time    P_((time_t *tp));
  239. int     printf  P_(());
  240. #endif
  241.  
  242. /******************************************************************************/
  243.  
  244. EXPORT void fn_ins P_((p_fn_t,char *));
  245. /* - The name stands for FileName INSert.                                     */
  246. /* - The first argument must be a pointer to an object of type fn_t           */
  247. /*   (containing an ordinary C character string).                             */
  248. /* - The second argument must be a pointer to an ordinary C character string. */
  249. /* - Both arguments must contain a full, partial, or empty filename spec.     */
  250. /* - We will refer to the arguments as f1 and f2.                             */
  251. /* - If there is a syntax error in either spec, fn_ins does nothing.          */
  252. /* - Otherwise, it:                                                           */
  253. /*      1. Analyses the two filename specifications into filename field .     */
  254. /*      2. Replaces each field in f1 by the corresponding field in f2, but    */
  255. /*         only if the corresponding field in f2 is non-empty.                */
  256. /*      3. Optionally [concession to VMS] it may then replace blank fields    */
  257. /*         in the resulting file spec in f1 by fields from the current        */
  258. /*         global "default" directory spec.                                   */
  259. /* The structure and fields of filenames will vary from machine to machine    */
  260. /* and so this is not important. However, every implementation must structure */
  261. /* the filename so that it will at least RECOGNISE a file extension           */
  262. /* (e.g. ".lis") field.                                                       */
  263.  
  264. /******************************************************************************/
  265.  
  266. EXPORT void getcline P_((int,char **,char *));
  267. /* Operating system environments vary a lot in the way in which their command */
  268. /* language interfaces are set up. The approach taken in FunnelWeb is to      */
  269. /* define a "standard" Unix-like command line syntax and then insist that     */
  270. /* other environments deliver such a command line as a single string.         */
  271. /* This function getcline must extract such a standard command line from its  */
  272. /* environment and copy it as a single string of not more than COMLINE_MAX    */
  273. /* characters into its third argument. A description of the "standard"        */
  274. /* command line can be found in the options package.                          */
  275. /* The first  argument is given to getcline and is argc from main().          */
  276. /* The second argument is given to getcline and is argv from main().          */
  277. /* These two arguments are given in case getcline needs them to assemble the  */
  278. /* command line (as opposed to calling e.g. VMS CLI routines).                */
  279. /* The third argument is the string into which the result should be placed.   */
  280.  
  281. /******************************************************************************/
  282.  
  283. EXPORT float tim_real P_((void));
  284. /* Returns the number of seconds between the present and an unspecified, but  */
  285. /* statically fixed time in the past.                                         */
  286. /* Returns 0.0 if this information is unavailable                             */
  287.  
  288. EXPORT float tim_cpu P_((void));
  289. /* Returns the number of CPU seconds consumed between the present and an      */
  290. /* unspecified, but statically fixed time in the past.                        */
  291. /* Returns 0.0 if this information is unavailable                             */
  292.  
  293. /******************************************************************************/
  294.  
  295. /* For #ifndef preventing multiple inclusion of the body of this header file. */
  296. #endif
  297.  
  298. /******************************************************************************/
  299. /*                                End of MACHIN.H                             */
  300. /******************************************************************************/
  301.