home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / DJGPP / DJDOC106.ZIP / DOCS / FUNCS.DOC < prev    next >
Encoding:
Text File  |  1991-07-21  |  132.0 KB  |  2,911 lines

  1. from: {A.Appleyard} (email: APPLEYARD@UK.AC.UMIST), Fri, 19 Jul 91 11:03:32 BST
  2. ======================================================================
  3. Here is my function info file. It has c.2900 lines. It contains tabulate chars.
  4. ======================================================================
  5. [Description of functions etc declared in the #include files of Gnu C]
  6.  
  7. Examples to show use of the functions etc. The single-letter variables are not
  8. part of the #include'd matter, but are inserted here as part of the examples.
  9. Some declared functions and struct fields have single-letter names. Some of
  10. these #include files #include other files, as stated. Arguments have exactly the
  11. right type and qualifiers unless stated otherwise. Each example's comment
  12. contains in {} the type returned, if not void. "def" = "default". "{boolean}" =
  13. "{int} = 0 if condition is not satisfied and nonzero (usually 1) otherwise".
  14. "random number" = "equal probability from 0 to 1" unless stated otherwise.
  15.   A few of these functions' bodies (including some that are C++ standard but
  16. can't be implemented on PC's, such as multi-user stuff and locking files and
  17. making files read-only) are not present in Gnu C (or I can't find their bodies
  18. in the source), although their names and parameter patterns are declared in one
  19. or other of these #include files. Such functions are marked "<missing>".
  20.   The accuracy of Gnu C's time routines depends on you setting your PC's
  21. internal clock when you switch it on.
  22.  
  23.   Some of these functions etc are written using C++ features. If you want to use
  24. these functions but otherwise stick to ordinary C and are not otherwise
  25. concerned with the intricacies of C++, you should note that C++ can declare:-
  26. (1)  Classes, which are like structs but can contain hidden members and other
  27.      special features. Hereinafter I use "Gridref" as an example of a class.
  28.      Warning: set up new store for class variables by e.g. 'Gridref()' (which
  29.      returns a new Gridref (or a null pointer if it can't get the store)).
  30.      Do <not> use e.g. '(Gridref*)malloc(sizeof(Gridref))', as this will not
  31.      set up the Gridref's internal tables and pointers.
  32. (2)  New uses of operators.
  33. (3)  2 or more functions with the same name but distinguishable in use by their
  34.      argument patterns.
  35. (4)  Function arguments-by-pointer in the usual way; and also in a special way
  36.      so <in those cases> you don't put '&' before the argument.
  37.      This could be called an argument-by-lvalue.
  38. (5)  Functions with zero or more arguments in the usual place, and also with a
  39.      special 'pre-first' argument of a class type which is put before the
  40.      function name with a fullstop between.
  41. (6)  Constructors, i.e. functions with the same name as a class. E.g. a function
  42.      named Gridref would set aside space for a Gridref, then set it up for use.
  43.      A constructor (e.g.) Gridref() with no arguments is automatically obeyed
  44.      when a Gridref variable is declared.
  45. (7)  Special uses of the operator = for particular pairs of arguments.
  46.      If the left and right arg types are the same, it overrides the default use.
  47. (8)  What to do if an (e.g.) Gridref is implicitly converted (by casting or
  48.      allocation etc) to some other mode, and vice versa.
  49. (9)  What to do if an (e.g.) Gridref is subscripted as if it was an array.
  50. (10) What to do if an (e.g.) Gridref is called as if it was a function.
  51. (11) Destructors, i.e. a function called (e.g.) ~Gridref() (with tilde). It is
  52.      called automatically when a Gridref variable is destroyed, e.g. at the end
  53.      of the block that it is declared in.
  54. (12) Default arguments, i.e. if a function is called with too few arguments,
  55.      what to treat the missing trailing arguments as being equal to.
  56. (13) A type 'void*' (distinguish from 'void'), which can be implicitly converted
  57.      to and from any pointer mode (except pointer to function).
  58.  
  59. For io_mode and access_mode and state_value in input/output, see FMODES.H
  60.  
  61. ======================================== ABS.H
  62. #include <builtin.h>, which see
  63.  
  64. ======================================== ACG.H
  65. [ADDITIVE RANDOM NUMBERS]
  66. #include <_Random.h>, which see
  67.  
  68. int i,j;
  69. ACG x;        /* declare x to hold the working of a running series of
  70.         additive random numbers, size=55, seed=0 */
  71. ACG()        /* a new {ACG} with seed=0, size=55 */    
  72. ACG(i)        /* a new {ACG} with seed=i, size=55 */    
  73. ACG(i,j)    /* a new {ACG} with seed=i, size=j */    
  74. i        /* used as an {ACG}, same as ACG(i) */
  75. x.reset()    /* reinitialize x */
  76. x.asLong()    /* new 32-bit additive random number */
  77.  
  78. ======================================== ALLOCRIN.H
  79. [ALLOCATION RINGS]
  80.  
  81. int i; void* p;
  82. AllocRing x;    /* declare x to hold a ring of pointers to malloc'ed strings */
  83. AllocRing(i)    /* a new {AllocRing} of i pointers */
  84. i        /* used as an {AllocRing}: ditto */
  85. x.alloc(i)    /* {void*} pointer to malloc'ed string of i bytes. The pointers
  86.         in x are used in rotation, so the oldest mallocs held by x may
  87.         be evicted to make room for new mallocs */
  88. x.free(p)    /* delete the malloc p if it is in x */
  89. x.contains(p)    /* {boolean} if p is in x */
  90. x.clear()    /* delete all mallocs in x */
  91.  
  92. ======================================== AOUT.H
  93. /* machine dependent matter used by input & output */
  94.  
  95. ======================================== AR.H
  96. struct ar_hdr {char ar_name[16], ar_date[12], ar_uid[6], ar_gid[6], ar_mode[8],
  97.     ar_size[10], ar_fmag[2]; };
  98.  
  99. ======================================== ASSERT.H
  100. [A DEBUGGING AID]
  101. /* These are macros:- */
  102. #if NDEBUG
  103. assert(x)    /* ignored */
  104. assertval(x)    /* compiled as (x) */
  105. #else
  106. assert(x)    /* if (x)==0 then error abort else returns 1 */
  107. assertval(x)    /* if (x)==0 then error abort else returns x */
  108. #endif
  109.  
  110. ======================================== ATEXIT.H
  111. struct atexit {
  112.     struct atexit *next;        /* next in list */
  113.     int ind;            /* next index in this table */
  114.     void (*fns[ATEXIT_SIZE])();    /* the table itself */ };
  115. struct atexit *__atexit;    /* points to head of LIFO stack */
  116. /* LIFO = "last in, first out" */
  117.  
  118. ======================================== BINOMIAL.H
  119. [BINOMIAL RANDOM NUMBERS]
  120. #include <_Random.h>, which see
  121.  
  122. int i,j; double x; RNG g;
  123. Binomial b;    /* declare b to hold the working of a running series of binomial
  124.         random numbers. Has hidden members: int pN; double pU; */
  125.         /* b contains a RNG and can be used as a RNG, and also:- */
  126. Binomial(i,j,*g)    /* a new Binomial with pN=n, pU=u, using RNG g */
  127. b.n()        /* {int} = b.pN */
  128. b.u()        /* {double} = b.pU */
  129. b.n(i)        /* b.pN = i; return {int} = old b.pN */
  130. b.u(x)        /* b.pU = x; return {double} = old b.pU */
  131. b()        /* generate b.pN random numbers;
  132.         return {double} = how many of them < b.pU */
  133.  
  134. ======================================== BITSET.H
  135. [ARRAYS OF BITS, OF INDEFINITE LENGTH]
  136.  
  137. BitSet b;    /* declare b to hold a bit pattern which is treated as extending
  138.         to right to infinity. The bits are numbered from 0 up. */
  139. BitSet c,d; int i,j,k; char t,f,a,*s; short y; long z;
  140. BitSet()    /* a new empty {BitSet} */
  141. BitSet(b)    /* a copy of b. Everything is copied, not only pointers */
  142. c = b        /* b is copied into c. (Everything, not only pointers) */
  143. b == c        /* {boolean} = if b has all bits same as c */
  144. b != c        /* {boolean} = if b has any bits not same as c */
  145. b <= c    c >= b    /* {boolean} = if b does not have any 1 where c has 0 */
  146. b < c    c > b    /* {boolean} = ditto, but also returns 0 if b==c */
  147. b | c        /* {BitSet} logical or */
  148. b & c        /* {BitSet} logical and */
  149. b - c        /* {BitSet} logical: 1-bit wherever the shorter arg has 1 where
  150.         the other has 0 */
  151. b ^ c        /* {BitSet} logical nonequivalence */
  152. ~ b        /* {BitSet} b with sign of every bit changed */
  153. b &= c        /* {void} b = b & c */
  154. b |= c        /* {void} b = b | c */
  155. b ^= c        /* {void} b = b ^ c */
  156. b -= c        /* {void} b = b - c */
  157.     /* NOTE the destination arg is the <first> arg, unlike in BITSTRIN.H */
  158. and(b,c,d)    /* {void} b = c & d */
  159. or(b,c,d)    /* {void} b = c | d */
  160. xor(b,c,d)    /* {void} b = c ^ d */
  161. diff(b,c,d)    /* {void} b = c - d */
  162. complement(b,c) /* {void} b = ~ c */
  163. b.complement()    /* {void} b = ~ b */
  164. b.virtual_bit() /* {boolean} = if b has 1's rather than 0's extending right
  165.         to infinity */
  166.  
  167. int k;        /* in these functions is taken as 0 or 1. Other values mean 1 */
  168.     /* Bits are indexed 0 etseq; index as argument < 0 causes error */
  169.     /* Index as result = -1 for 'not found' or 'infinity' */
  170.     /* In the next 5 functions, k = 1 if the k argument is missing */
  171. b.first(k)    /* {int} index of leftmost bit which is k */
  172. b.last(k)    /* {int} index of rightmost bit which is k */
  173. b.next(i,k)    /* {int} lowest j for j>=i and jth bit of b == k */
  174. b.previous(i,k) /* {int} highest j for j<=i and jth bit of b == k */
  175. b.count(k)    /* {int} how many k-bits in b (-1 = infinity) */
  176. b.test(i)    /* {boolean} = ith bit of b. Error if i < 0 */
  177. b.empty()    /* {boolean} if b is all 0's */
  178.     /* these functions error if i<0 or i>j */
  179. b.set()     /* set b to all 1's */
  180. b.set(i)    /* set ith bit of b = 1 */
  181. b.set(i,j)    /* set ith to jth bits of b = all 1's */
  182. b.clear()    /* set b to all 0's */
  183. b.clear(i)    /* set ith bit of b = 0 */
  184. b.clear(i,j)    /* set ith to jth bits of b = all 0's */
  185. b.invert(i)    /* reverse ith bit of b */
  186. b.invert(i,j)    /* reverse ith to jth bits of b */
  187. BitSettoa(b)    /* {char*} = bits of x: '1' for 1, '0' for 0, '*' at end.
  188.         The bit before the '*' is taken as repeated to infinity */
  189. BitSettoa(b,f)        /* ditto but char f instead of '0' */
  190. BitSettoa(b,f,t)    /* ditto but char t instead of '1' */
  191. BitSettoa(b,f,t,a)    /* ditto but char a instead of '*' */
  192. shorttoBitSet(y)    /* y as a {BitSet} */
  193. longtoBitSet(z)     /* z as a {BitSet} */
  194. atoBitSet(s)    /* {BitSet}: reverse of BitSettoa(b).
  195.         Illegal character or '*' terminates the string */
  196. atoBitSet(s,f)        /* ditto but char f instead of '0' */
  197. atoBitSet(s,f,t)    /* ditto but char t instead of '1' */
  198. atoBitSet(s,f,t,a)    /* ditto but char a instead of '*' */
  199. b.OK()        /* {int} check b for internal faults. If any found, error exit.
  200.         Else return nonzero value */
  201. ostream S;
  202. S << b        /* {ostream} same as   S << BitSettoa(b) */
  203.  
  204. BitSetBit p;    /* declare p as a 'pointer' to a bit of a BitSet */
  205. BitSetBit(p)    /* copy of p. Everything is copied, not just pointers */
  206. BitSetBit(*b,i) /* {BitSetBit} 'pointer' to ith bit of b */
  207. p        /* used as {boolean}: the bit that p points at */
  208. p = k        /* {void} set (bit that p points at) = k */
  209. p == k        /* {boolean} if (bit that p points at} == k */
  210. p != k        /* {boolean} if (bit that p points at} != k */
  211. b[i]        /* {BitSetBit} pointing to ith bit of b. Error if i<0 */
  212.  
  213. ======================================== BITSTRIN.H
  214. [ARRAYS OF BITS]
  215. BitString s,t;    /* declare s and t, each to hold a bit string */
  216. BitPattern p;    /* declare p. It has 2 public elements: BitString pattern, mask;
  217.         BitPatterns are used as args of search routines. Where p.mask
  218.         has a 1-bit, the string being searched must match p.pattern,
  219.         else that bit of the searched string doesn't matter */
  220. BitStrBit b;    /* declare b to point to a bit in a BitString */
  221. BitSubString S; /* declare S to point to a substring */
  222.  
  223. unsigned short y; unsigned long z; unsigned int x; int i,j;
  224. BitString()        /* a new empty {BitString} */
  225. BitString(p)        /* a new {BitString} = a copy of p */
  226. BitString(S)        /* a new {BitString) = a copy of S */
  227. S            /* used as a {BitString}: ditto */
  228. shorttoBitString(y)    /* y as a {BitString} */
  229. longtoBitString(z)    /* z as a {BitString} */
  230. t = s            /* {void} complete copy, not only the pointers */
  231. s = x            /* {void} copy x as a {BitString} */
  232. s = S            /* {void} copy S as a {BitString} */
  233. BitPattern(s,t)     /* a new {BitPattern} with pattern s and mask t */
  234. BitPattern(p)        /* a new {BitPattern} = a copy of p */
  235.  
  236.     /* NOTE that unlike in BITSET.H, the <last> arg is the result arg */
  237. and(s,t,u)        /* {void}: u = s & t */
  238. or(s,t,u)        /* {void}: u = s | t */
  239. xor(s,t,u)        /* {void}: u = s ^ t */
  240. diff(s,t,u)        /* {void}: u = s - t */
  241. cat(s,t,u)        /* {void}: u = s + t */
  242. cat(s,z,u)        /* {void}: u = s + z */
  243. rshift(s,i,u)        /* {void}: u = s >> i */
  244. lshift(s,i,u)        /* {void}: u = s << i */
  245. complement(s,u)     /* {void}: u = ~ i */
  246.  
  247. s &= t        /* {void} s = s & t */
  248. s |= t        /* {void} s = s | t */
  249. s ^= t        /* {void} s = s ^ t */
  250. s -= t        /* {void} s = s - t */
  251. s += t        /* {void} s = s + t */
  252. s += z        /* {void} s = s + z */
  253. s <<= i     /* {void} s = s << i */
  254. s >>= i     /* {void} s = s >> i */
  255. s.complement()    /* {void} s = ~ s */
  256.  
  257. s & t        /* {BitString} logical and */
  258. s | t        /* {BitString} logical or */
  259. s ^ t        /* {BitString} logical nonequivalence */
  260. s << i        /* {BitString} s left shifted by i positions */
  261. s >> i        /* {BitString} s right shifted by i positions */
  262. s - t        /* {BitString} logical 'difference' */
  263.             /* 1 where longer arg has 0 where other arg has 1 */
  264. s + t        /* {BitString} s and t concatenated */
  265. s + x        /* {BitString} s and x (as BitString) concatenated */
  266. ~ s        /* {BitString} s with all bits 0 instead of 1 or vice versa */
  267.  
  268. s.length()    /* {int} length of s */
  269. s.empty()    /* {boolean} s has length zero */
  270.     /* -1 for 'not found' in these functions:- */
  271. s.index(t)    /* look in s for t. Returns {int} = place */
  272. s.index(t,i)    /* ditto, but ignore first i bits of s */
  273.     /* also the same two uses with a BitSubString or a BitPattern instead
  274.     of a BitString */
  275. s.contains(...) /* {boolean} same uses as s.index, but return 0 for 'not found',
  276.         nonzero for 'found' */
  277. s.matches(...)    /* {boolean} same uses as s.index, but return 0 unless t is
  278.         found starting at i-th bit of s (i omitted = 0) */
  279. S.length()    /* {int} length of S */
  280. S.empty()    /* {boolean} if length of S == 0 */
  281. s == t        /* {boolean} if s has all bits same as t */
  282. s != t        /* {boolean} if s has any bits different from t */
  283. s <= t    t >= s    /* {boolean} if s has no 1-bit where t has a 0-bit */
  284. s < t    t > s    /* {boolean} ditto, but also false if s == t */
  285. int k;    /* any value other than 0 or 1 is taken as 1 */
  286. s.first(k)    /* {int} index of leftmost k-bit in s */
  287. s.first()    /* {int} index of leftmost 1-bit in s */
  288. s.last(k)    /* {int} index of rightmost k-bit in s */
  289. s.last()    /* {int} index of rightmost 1-bit in s */
  290. s.index(i,k)    /* {int} if i>=0, lowest j for j>=i and jth bit of s = k;
  291.         if i<0, highest j for j<=(ith from end) and jth bit of s = k */
  292. s.index(i)    /* ditto, k=1 */
  293. s.right_trim(k) /* {BitString} = s with all trailing k-bits removed */
  294. s.left_trim(k)    /* {BitString} = s with all leading k-bits removed */
  295. s.test(i)    /* {boolean} = ith bit of s */
  296.  
  297. s[i]        /* {BitStrBit} pointing to the ith bit of s */
  298. b        /* used as {boolean}: the bit pointed to */
  299. b = k        /* {boolean}: set bit b to k; return its <new> value */
  300. b == k        /* {boolean} if bit b == k */
  301. b != k        /* {boolean} if bit b != k */
  302.  
  303. BitSubString(S)     /* a new {BitSubString} = a copy of S */
  304. BitSubString(s,i,j)    /* a {BitSubString} = bits p to (l+p-1) of s */
  305. s._substr(i,j)    /* {BitSubString} = j bits of s, starting at ith bit.
  306.         Returns null substring if array-out-of-bounds */
  307. s.count(k)    /* {int} how many k-bits in s */
  308. s.count()    /* {int} how many 1-bits in s */
  309. s.set(i)    /* {void} set ith bit of s to 1 */
  310. s.clear(i)    /* {void} set ith bit of s to 0 */
  311. s.assign(i,k)    /* {void} set ith bit of s to k */
  312. s.set()     /* {void} set all bits of s to 1 */
  313. s.clear()    /* {void} set all bits of s to 0 */
  314. s.invert(i)    /* {void} reverse ith bit of s */
  315.     /* In the next 4 functions, error if i<0 or i>j */
  316. s.set(i,j)    /* {void} set ith to jth bits of s to 1 */
  317. s.clear(i,j)    /* {void} set ith to jth bits of s to 0 */
  318. s.invert(i,j)    /* {void} reverse ith to jth bits of s */
  319. s.test(i,j)    /* {boolean} if any 1's in ith to jth bits of s ((I think)) */
  320. s.next(i,k)    /* {int} least j for j>=i & jth bit of s == k. -1 = not found */
  321. s.next(i)    /* {int} least j for j>=i & jth bit of s == 1. -1 = not found */
  322. s.previous(i,k) /* {int} last j for j<=i & jth bit of s == k. -1 = not found */
  323. s.previous(i)    /* {int} last j for j<=i & jth bit of s == 1. -1 = not found */
  324. S = s        /* {void} full copy */
  325. S = T        /* {void} full copy */
  326.  
  327. s.at(i,j)    /* {BitSubString} = j bits starting at ith bit of s */
  328. s.before(i)    /* {BitSubString} = 0th to (i-1) bits of s */
  329. s.after(i)    /* {BitSubString} = (i+1)th to last bits of s */
  330. s.at(t,i)    /* j = s.index(t,i); {BitSubString} = jth to last bits of s */
  331. s.before(t,i)    /* j = s.index(t,i); {BitSubString} = 0th to(j-1)th bits of s */
  332. s.after(t,i)    /* j = s.index(t,i);
  333.         {BitSubString} = (j + length of t)th to last bits of s */
  334.     /* in the last three functions, omitted 'i' argument = 0 */
  335.     /* also the same three with a BitSubString as first arg */
  336.     /* also the same three with a BitPattern as first arg */
  337.  
  338. common_prefix(s,t)    /* {BitString} = from the 0th bit of s to the bit before
  339.             the first bit that is not the same in t */
  340. common_prefix(s,t,i)    /* ditto but start at the ith bit of a and b */
  341. common_suffix(s,t,i)    /* {BitString} = consecutive bits that re same in s and
  342.             in t, ending at ith bit */
  343. common_suffix(s,t)    /* {BitString}, but seems to return without a value */
  344. reverse(s)        /* {BitString} s with the bits all in reverse order */
  345.  
  346. char *w,u,v,m;
  347. atoBitString(w)     /* w read as a {BitString}, '0' == 0-bit, '1' = 1-bit,
  348.             any other char terminates */
  349. atoBitString(w,u)    /* ditto, but char u instead of '0' */
  350. atoBitString(w,u,v)    /* ditto, but char v instead of '1' */
  351. atoBitPattern(w)    /* w as {BitPattern}, '0' = must be 0-bit, '1' = must be
  352.             1-bit, 'X' = doesn't matter, other char terminates */
  353. atoBitPattern(w,u)    /* ditto, but char u instead of '0' */
  354. atoBitPattern(w,u,v)    /* ditto, but char v instead of '1' */
  355. atoBitPattern(w,u,v,m)    /* ditto, but char m instead of 'X' */
  356. BitStringtoa(s)     /* (char*) reverse of atoBitString */
  357.         /* likewise with one or two char args */
  358. BitPatterntoa(S)    /* (char*) reverse of atoBitPattern */
  359.         /* likewise with one or two or three char args */
  360. ostream F;
  361. F << s            /* {ostream} same as  F << BitStringtoa(s) */
  362. F << S            /* {ostream} same as  F << BitPatterntoa(S) */
  363.         /* these check the arg for internal errors. If any found,
  364.         they error-exit, else {boolean} nonzero value */
  365. s.OK()        /* check a BitString */
  366. S.OK()        /* check a BitSubString */
  367. p.OK()        /* check a BitPattern */
  368.  
  369. ======================================== BOOL.H
  370. enum bool { FALSE = 0, TRUE = 1 };
  371.  
  372. ======================================== BSTRING.H
  373. #include <std.h>, which see
  374.  
  375. ======================================== BUILTIN.H
  376. [SIMPLE PRINTING; POWER; MISC]
  377. #include <stddef.h>, which see
  378. #include <std.h>,    which see
  379. #include <math.h>,   which see
  380.  
  381. long m,n; double x,y; int i,j,k; char c,*f,*s;
  382. gcd(m,n)    /* {long} highest +ve number that is a factor of m and of n */
  383. lg(n)        /* {long} how many bits in n, except leading 0-bits */
  384. pow(x,n)    /* {double} power */
  385. pow(m,n)    /* {long} power */
  386. start_timer()    /* {double}
  387. return_elapsed_time(n)    /* {long} n is 'last time' */
  388. itoa(n)     /* {char*} n as decimal string. The argument can be long or
  389.         long long or unsigned long or unsigned long long */
  390. itoa(n,i)    /* ditto, radix = i */
  391. itoa(n,i,j)    /* ditto, string will be at least j chars long */
  392. dtoa(x)     /* {char*} x as decimal string, floating point if necessary,
  393.         with 6 significant figures */
  394. dtoa(x,'g')    /* ditto */
  395. dtoa(x,'f')    /* ditto but always floating point */
  396. dtoa(x,c)    /* if c is not 'f' or 'g', ditto but never floating point */
  397. dtoa(x,c,i)    /* ditto, the string will be at least i chars long */
  398. dtoa(x,c,i,j)    /* ditto, with j significant figures */
  399. hex(n)        /* {char*) n as hexadecimal */
  400. hex(n,i)    /* ditto, at least i chars */
  401. oct(n)        /* {char*) n as octal */
  402. oct(n,i)    /* ditto, at least i chars */
  403. dec(n)        /* {char*) n as decimal */
  404. dec(n,i)    /* ditto, at least i chars */
  405. form(f,...)    /* {char*} the rest of the args printed by the format f */
  406. chr(c)        /* {char*} the character c */
  407. chr(c,i)    /* ditto, left filled to i chars */
  408. str(s)        /* {char*} a copy of the string s */
  409. str(s,i)    /* ditto, left filled to at least i chars */
  410. hashpjw(s)        /* {unsigned int} the string s hashed */
  411. multiplicativehash(i)    /* {unsigned int} i hashed */
  412. foldhash(x)        /* {unsigned int} x hashed */
  413. abs(x)    /* with double or float or short or long arg, returning same type */
  414. sign(x) /* with double or long arg. {int} = -1 or 0 or 1, sign of x */
  415. sqr(x)    /* with long or double arg, returning same type (x*x) (NOT sqrt!!) */
  416. even(n)     /* {boolean} if the last bit of n == 1 */
  417. odd(n)        /* {boolean} if the last bit of n == 0 */
  418. lcm(m,n)    /* {long} m / gcd(m,n) * n */
  419. setbit(m,n)    /* {void} set 'pow(2,n-1)' bit of m to 1 */
  420. clearbit(m,n)    /* {void} set 'pow(2,n-1)' bit of m to 0 */
  421. testbit(m,n)    /* {boolean} if 'pow(2,n-1)' bit of m == 1 */
  422.  
  423. ======================================== COMPARE.H
  424. [<0 IF X<Y; 0 IF X==Y; >0 IF X>Y]
  425.  
  426. compare(x,y)    /* args must be same type; returns {int} */
  427.         /* if args are int or short or char or float or double,
  428.             returns x-y */
  429.         /* if args are unsigned long or unsigned short or unsigned int
  430.             or unsigned char, returns sign(a-b) */
  431.         /* if args are char*, returns strcmp(x,y) */
  432.  
  433. ======================================== COMPLEX.H
  434. [COMPLEX ARITHMETIC]
  435.  
  436. double x,y; long n;
  437. Complex c,d,e;    /* declare complex variables. They have members: double re,im;
  438.         which may or may not be accessible */
  439. c.real()    /* {double} real part of c */
  440. c.imag()    /* {double} imaginary part of c */
  441. Complex()    /* {Complex} with both parts = 0 */
  442. Complex(c)    /* {Complex} = a copy of c */
  443. Complex(x)    /* {Complex}, real part = x, imag part = 0 */
  444. x        /* used as {Complex}: ditto */
  445. Complex(x,y)    /* {Complex}, real part = x, imag part = y */
  446. c = d        /* usual meaning, returns {Complex} */
  447. + - * / += -= *= /= == !=    /* but not % %= < > <= >= << >> <<= >>= */
  448.     /* with all Complex arg(s) have the expected mathematical meanings */
  449.     /* += -= *= /= can also have left arg Complex and right arg double */
  450.     /* + - * / can also have either arg Complex and the other arg double */
  451. cos(c)        /* {Complex} cosine */
  452.     /* likewise sin, cosh, sinh, exp, log, sqrt */
  453. pow(c,n)    /* {Complex} power */
  454. pow(c,x)    /* {Complex} power */
  455. pow(c,d)    /* {Complex} power */
  456. conj(c)     /* {Complex} c with sign of imaginary part changed */
  457. norm(c)     /* {double} real part squared + imag part squared */
  458. abs(c)        /* {double} sqrt(norm(c)) */
  459. polar(x,y)    /* Complex(x*cos(y). y*sin(y)) */
  460. polar(x)    /* Complex(x,0.0) */
  461.  
  462. ======================================== CTYPE.H
  463. [WHAT SORT OF CHARACTER]
  464.  
  465. /* these are all macros */
  466. char c; /* results unpredictable unless c is 0 to 127 */
  467.     /* "letter" does not include '_' or '$' or PC accented letters */
  468. isalpha(c)    /* {boolean} if c is letter */
  469. isupper(c)    /* {boolean} if c is uppercase letter */
  470. islower(c)    /* {boolean} if c is lowercase letter */
  471. isdigit(c)    /* {boolean} if c is one of 0 1 2 3 4 5 6 7 8 9 */
  472. isxdigit(c)    /* {boolean} if c is one of 0123456789abcdefABCDEF */
  473. isspace(c)    /* {boolean} if c is space or ctrl-J to ctrl-M */
  474. ispunct(c)    /* {boolean} if c is printing char, not space/letter/number */
  475. isalnum(c)    /* {boolean} if c is letter or number */
  476. isprint(c)    /* {boolean} if c is printable char or space */
  477. isgraph(c)    /* {boolean} if c is printable char but not space */
  478. iscntrl(c)    /* {boolean} if c is control char or DEL (char 127) */
  479. isascii(c)    /* {boolean} if c is 0 to 127 */
  480. toupper(c)    /* {char} if islower(c) then uppercase for c, else c */
  481. tolower(c)    /* {char} if isupper(c) then lowercase for c, else c */
  482. toascii(c)    /* {char} on PC, ((c)&127) */
  483. ======================================== CURSES.H
  484. /* matter used by CURSESW.H & CURSESWI.H, which see */
  485.  
  486. ======================================== CURSESW.H
  487. /* same as CURSESWI.H but without these two functions:- */
  488. w.touchline(j,sx,ex)    /* {int} screen control (args are int) */
  489. w.touchoverlap(u)    /* {int} screen control (defined if DGUX) */
  490.  
  491. ======================================== CURSESWI.H
  492. [A GRAPHICS PACKAGE CALLED 'CURSES']
  493.  
  494. /* Sorry, I can't find fully what these functions do; and according to the file
  495. <wherever your Gnu C is>\DOCS\LIBC.DOC, Gnu C does not contain the bodies of
  496. these functions, although this #include file declares them. */
  497.  
  498. #include <curses.h> int i,j,x,y; char c,*s;
  499. CursesWindow u,w;    /* declare windows for Curses */
  500. WINDOW W;        /* declare a standard window */
  501. CursesWindow(W)     /* W as a {CursesWindow}, useful only for stdscr */
  502. W            /* used as a {CursesWindow}: ditto */
  503. CursesWindow(j,i,y,x)    /* a {CursesWindow} of j lines & i columns,
  504.             starting at line y & column x */
  505. CursesWindow(w,j,i,y,x,'a')    /* ditto, parent window = w */
  506. CursesWindow(w,j,i,y,x,'r')    /* ditto, y & x relative to parent window */
  507. w.lines()        /* {int} number of lines on terminal, *not* window */
  508. w.cols()        /* {int} number of cols  on terminal, *not* window */
  509. w.height()        /* {int} number of lines in this window */
  510. w.width()        /* {int} number of cols in this window */
  511. w.begx()        /* {int} smallest x coord in window */
  512. w.begy()        /* {int} smallest y coord in window */
  513. w.maxx()        /* {int} largest  x coord in window */
  514. w.maxy()        /* {int} largest  x coord in window */
  515. w.move(y,x)        /* {int} window positioning */
  516. w.getyx(y,x)        /* coordinate positioning */
  517. w.mvcur(sy,ey,sx,ex)    /* {int} move cursor? (args are int) */
  518. w.getch()        /* {int} read a character */
  519. w.getstr(s)        /* {int} get string */
  520. w.scanw(s, ...)     /* {int} formatted read from window, s is format */
  521. w.mvgetch(j,i)        /* {int} go to line j,col i; read a character */
  522. w.mvgetstr(j,i,s)    /* {int} go to line j,col i; get string */
  523. w.mvscanw(j,i,s, ...)    /* {int} go to line j,col i;
  524.             formatted read from window, s is format */
  525. w.addch(c)        /* {int} output */
  526. w.addstr(s)        /* {int} output */
  527. w.printw(s, ...)    /* {int} output */
  528. w.inch()        /* {int} output */
  529. w.insch(c)        /* {int} output */
  530. w.insertln()        /* {int} output */
  531. w.mvaddch(j,i,c)    /* {int} go to line j, col i; output */
  532. w.mvaddstr(j,i,s)    /* {int} go to line j, col i; output */
  533. w.mvprintw(j,i,*s,...)    /* {int} go to line j, col i; output. s = format */
  534. w.mvinch(j,i)        /* {int} go to line j, col i; output */
  535. w.mvinsch(j,i,c)    /* {int} go to line j, col i; output */
  536. char v,h; char b; /* b is always (char)0 or (char)1, a char used as boolean */
  537. w.box(v,h)        /* {int} borders. v = vert, h = horiz */
  538. w.erase()        /* {int} erasure */
  539. w.clear()        /* {int} erasure */
  540. w.clearok(b)        /* {int} erasure */
  541. w.clrtobot()        /* {int} erasure */
  542. w.clrtoeol()        /* {int} erasure */
  543. w.delch()        /* {int} erasure */
  544. w.mvdelch(j,i)        /* {int} go to line j, col i; erasure */
  545. w.deleteln()        /* {int} erasure */
  546. w.scroll()        /* {int} screen control */
  547. w.scrollok(b)        /* {int} screen control */
  548. w.touchwin()        /* {int} screen control */
  549. w.touchline(j,sx,ex)    /* {int} screen control (args are int) */
  550. w.touchoverlap(u)    /* {int} screen control (defined if DGUX != 0) */
  551. w.refresh()        /* {int} screen control */
  552. w.leaveok(b)        /* {int} screen control */
  553. w.flushok(b)        /* {int} screen control */
  554. w.standout()        /* {int} screen control */
  555. w.standend()        /* {int} screen control */
  556. w.overlay(u)        /* {int} multiple window control */
  557. w.overwrite(u)        /* {int} multiple window control */
  558. w.child()        /* {CursesWindow} window that w is parent of */
  559. w.sibling()        /* {CursesWindow} traversal support */
  560. w.parent()        /* {CursesWindow} w's parent */
  561. w.overlay(u)        /* {int} multiple window control */
  562. w.overwrite(u)        /* {int} multiple window control */
  563. w.child()        /* {CursesWindow} window that w is parent of */
  564. w.sibling()        /* {CursesWindow} traversal support */
  565. w.parent()        /* {CursesWindow} w's parent */
  566.  
  567. ======================================== DIR.H
  568. [READING MSDOS DIRECTORIES]
  569.  
  570. struct ffblk {    /* type declared to decipher a directory entry */
  571.   char ff_reserved[21], ff_attrib; short ff_ftime, ff_fdate, ff_filler;
  572.   long ff_fsize; char ff_name[16]; };
  573.  
  574. /* bits of n:- */
  575. #define FA_RDONLY    1
  576. #define FA_HIDDEN    2
  577. #define FA_SYSTEM    4
  578. #define FA_LABEL    8
  579. #define FA_DIREC    16
  580. #define FA_ARCH     32
  581.  
  582. char *s, struct ffblk F; int n;
  583. findfirst(s,&F,n)    /* {int} read into F the first entry of directory named
  584.             s, according to bits set in n */
  585. findnext(&F)        /* {int} read next entry of directory according to F.
  586.             return 0 if end of directory */
  587.  
  588. ======================================== DIRENT.H
  589. [READING MSDOS DIRECTORIES]
  590.  
  591. #include <sys/dirent.h>, which is:-
  592. struct dirent {unsigned short d_namlen;  char d_name[14]; };
  593. typedef struct {int num_read; char *name; struct ffblk ff; struct dirent de; }
  594.   DIR;
  595. DIR *opendir(char *name);    /* create a DIR to read the directory named */
  596. struct dirent *readdir(DIR *dir);    /* read next entry of directory dir */
  597. long telldir(DIR *dir);     /* return how far I am down directory dir */
  598. void seekdir(DIR *dir, long i); /* go to ith entry of directory dir */
  599. void rewinddir(DIR *dir);    /* go to start of directory dir */
  600. int closedir(DIR *dir);     /* stop reading directory dir */
  601.  
  602. ======================================== DISCRETE.H
  603. /*** same as DISCUNIF.H, which see */
  604.  
  605. ======================================== DISCUNIF.H
  606. [UNIFORM RANDOM NUMBERS]
  607.  
  608. #include <_Random.h> /* which see */
  609. long i,j; RNG g;
  610. DiscreteUniform d;    /* declare d to hold the working of a running series of
  611.             integer random numbers within a range 'low' (inclusive)
  612.             to 'high' (not inclusive) */
  613.     /* d contains and can be used as a Random see RANDOM.H) , and also:- */
  614. DiscreteUniform(i,j,&g) /* a new DiscreteUniform, range i to j, using RNG g */
  615. d.low()         /* {long} lower limit of d */
  616. d.low(i)        /* set lower limit of d to i, return {long} old value */
  617. d.high()        /* {long} upper limit of d */
  618. d.high(j)        /* set upper limit of d to j, return {long} old value */
  619. d()            /* {double} next value in d's random series */
  620.  
  621. ======================================== DOS.H
  622. [REGISTER INTERFACE BUFFER TYPES; DOS SYSTEM CALLS]
  623.  
  624. union REGS {
  625.   struct {unsigned long ax, bx, cx, dx, si, di, cflag, flags; } x;
  626.   struct {unsigned char al, ah; unsigned short upper_ax;
  627.       unsigned char bl, bh; unsigned short upper_bx;
  628.       unsigned char cl, ch; unsigned short upper_cx;
  629.       unsigned char dl, dh; unsigned short upper_dx; } h;  };
  630. struct SREGS {unsigned short cs, ds, es, fs, gs, ss; };
  631.  
  632. /* system calls */
  633. union REGS r,s;    /* declare r etc for interrupts to read the PC registers from
  634.             and/or put them back into */
  635. int f; unsigned i,j; void* p; struct SREGS t;
  636. bdos(f,i,j)    /* {int}: registers: DS = i, AL = j; call DOS function f */
  637. bdos(f,p,j)    /* ditto but registers DS & AL = pointer p */
  638. int86(f,&r,&s)    /* {int}: registers = r; call 80x86 interrupt f; s = regs */
  639. int86x(f,&r,&s,&t)    /* {int} ditto, but t = results */
  640. intdos(&r,&s)    /* {int}: registers = r; call 80x86 interrupt 21hex; s = regs */
  641. intdosx(&r,&s,&t)    /* {int} ditto, but t = results */
  642.  
  643. ======================================== ERLANG.H
  644. [A SORT OF RANDOM NUMBER]
  645.  
  646. #include <_Random.h> /* which see */
  647. Erlang e;    /* declare e to hold the workings of an 'erlang' type runinng
  648.         series of random numbers */
  649.         /* contains and can be used as a RNG, and also:- */
  650. double m,v; RNG g;
  651. Erlang(m,v,*g)    /* new Erlang, mean=m, variance=v, using RNG g */
  652. e.mean()    /* {double} mean of e */
  653. e.mean(m)    /* mean of e = m; return {double} old mean */
  654. e.variance()    /* {double} variance of e */
  655. e.variance(v)    /* variance of e = v; return {double} old variance */
  656. e()        /* k = nearest integer to e.mean() * e.mean() / e.variance();
  657.         x = product of k (at least one) random numbers;
  658.         return {double} -log(x) * e.mean / k */
  659.  
  660. ======================================== ERRNO.H
  661. [ERROR NUMBERS RETURNED BY FUNCTIONS THAT CALL MS-DOS]
  662.  
  663. /* 1 = OK */
  664. #define ENOENT     2        /* No such file or directory    */
  665. #define ENOTDIR  3        /* No path            */
  666. #define EMFILE     4        /* Too many open files        */
  667. #define EACCES     5        /* Permission denied        */
  668. #define EBADF     6        /* Bad file number        */
  669. #define EARENA     7        /* Arena trashed        */
  670. #define ENOMEM     8        /* Not enough core        */
  671. #define ESEGV     9        /* invalid memory address    */
  672. #define EBADENV 10        /* invalid environment        */
  673. #define ENODEV    15        /* No such device        */
  674. #define EINVAL    19        /* Invalid argument        */
  675. #define E2BIG    20        /* Arg list too long        */
  676. #define ENOEXEC 21        /* Exec format error        */
  677. #define EXDEV    22        /* Cross-device link        */
  678. #define EDOM    33        /* Math argument        */
  679. #define ERANGE    34        /* Result too large        */
  680. #define EEXIST    35        /* File already exists        */
  681.  
  682. ======================================== FCNTL.H
  683. [MODE ARGUMENTS USED BY SOME FILE-OPENING FUNCTIONS]
  684.  
  685. #define O_RDONLY    0x0001 /* read only */
  686. #define    O_WRONLY    0x0002 /* write only */
  687. #define    O_RDWR        0x0004 /* read and write */
  688. #define    O_CREAT        0x0100 /* create file if it does not exist */
  689. #define    O_TRUNC        0x0200 /* throw away existing contents of file */
  690. #define O_EXCL        0x0400 /* if O_CREAT set, error if file exists */
  691. #define O_APPEND    0x0800 /* open at end of file */
  692. #define O_TEXT        0x4000 /* open file in text = translated mode */
  693. #define O_BINARY    0x8000 /* open file in binary = untranslated mode */
  694. /* these values can be or'ed, except those with contradictory meanings */
  695.  
  696. ======================================== FILE.H and _FILE.H
  697. [NEW-STYLE FILE VARIABLES FOR C++]
  698.  
  699. File f;     /* declare f to hold file info, with these hidden fields:-
  700.         FILE *fp;    pointer to old C-type FILE structure
  701.         char *nm;    file name
  702.         long stat;    value returned by last call of various reading
  703.                 and writing functions that in old-style C FILE's
  704.                 return an int value
  705.         (etc). The File will be correctly set up as an unopened File */
  706.         Special values of f.nm:-
  707.         from keyboard        "(stdin)"
  708.         to screen        "(stdout)"
  709.         to error channel    "(stderr)"
  710.         to/from a string    "(string)"
  711.  
  712. char c, *f, *s, *n, *m, *a; FILE *F; int i, j;
  713. state_value v; int i,j; char c; void *p; long n;
  714. /* state_value is int that can = 0 for 'all is well', 1 for 'end of file', 2 for
  715.  'logical or physical input/output error', 4 for 'file unopened or corrupted' */
  716.  
  717. /* All functions in FILE.H and _FILE.H return {File} = the value of the File
  718.    argument, unless stated otherwise */
  719.  
  720. /* Values of some int arguments for open etc:-
  721. io_mode:- 0 = read only; 1 = write only; 2 = read & write; 3 = append only;
  722.     4 = append and read.
  723. (old C fopen equivalents are:- 0 = "r", 1 = "w", 2 = "r+", 3 = "a", 4 = "a+")
  724. access_mode:- 0 = create (fail if exists already); 1 = truncate (create if does
  725.     not exist); 2 = fail if doesn't exist; 3 = create if desn't exist.
  726. state_value:- 0 = OK; 1 = at end of file; 2 = logical or physical input/output
  727.     error; 4 = unopened or corrupted. */
  728.  
  729. File()        /* a new unopened {File} info table correctly set up */
  730. File(n,m,a)    /* {File}: as File(), then call f.open(n,m,a) on it */
  731. File(n,m)    /* {File}: as File(), then call f.open(n,m) on it */
  732. File(i,m)    /* {File}: as File(), then call f.open(i,m) on it */
  733. File(F)     /* {File}: as File(), then call f.open(F) on it */
  734. F        /* used as a {File}: ditto */
  735. File(i,m,0)    /* a new {File} open to read from the string m of length i */
  736. File(i,m,1)    /* a new {File} open to write to  the string m of length i */
  737. File(i,m,j)    /* error if j != 0 and j != 1 */
  738. ~File()     /* Destructor: close the file. Called automatically at end of
  739.         block that the File is declared in */
  740. f.open(n,m,a)    /* open f as file named n with io_mode m, access_mode a */
  741. f.open(n,m)    /* open f as file named n, args as in old-style fopen */
  742. f.open(F)    /* {File} connect f with the old-style FILE *F */
  743. f.open(i,j)    /* {File} = file number i opened in io_mode j */
  744. f.close()    /* {void} close the file */
  745. f.remove()    /* {void} close & delete the file */
  746. f.setname(n)    /* tell C's File system that file f is now named n.
  747.         But the file is not renamed in MSDOS */
  748.     /* all uses of f.setbuf(...) return {File) f */
  749. f.setbuf(4)    /* set f to unbuffered */
  750. f.setbuf(128)    /* setlinebuf(f.fp) */
  751. f.setbuf(0)    /* set f to unbuffered and 'read till buffer full' mode */
  752. f.setbuf(i)    /* set f to unbuffered and 'read to end of line' mode,
  753.             if i is not 0 or 4 or 128 */
  754.     /* in some sytems the last two cases may not work */
  755. f.setbuf(i,s)    /* set f to use buffer s size i */
  756. f.error()    /* put f into failed mode */
  757. f.check_state() /* error if f.fp & f don't agree about whether file is at eof */
  758. f.put(s)    /* write the string s */
  759.     /* In the next 4 functions, if the last argument is missing, c = '\n' */
  760. f.get(s,i,c)    /* read into s i chars but stop at char c (do not read the c) */
  761. f.getline(s,i,c)/* ditto but read the terminator if found */
  762. f.readline(i,c) /* {char*} called by f.gets */
  763. f.gets(&s,c)    /* read chars until c found. s = pointer to new string
  764.         containing chars read. (Terminator c is read but forgotten.)
  765.         s = NULL is end of file met. No length limit. */
  766. f.scan(f,...)    /* formatted read.  f.stat = how many values read */
  767. f.form(f,...)    /* formatted write. f.stat = how many values read */
  768. f.filedesc()    /* {int} fileno(f.fp), i.e. FILE number */
  769. f.name()    /* {char*} file name */
  770. f.iocount()    /* {int} value returned by last read/write/etc on this file */
  771. f.clear(v)    /* {void} set file's state to v */
  772. f.clear()    /* {void} set file's state to 'OK' */
  773. f.set(v)    /* {void} set file state bits set in v */
  774. f.unset(v)    /* {void} unset file state bits set in v */
  775. f.readable()    /* {bool} if file readable from and not at end of file or bad */
  776. f.writable()    /* {bool} if file writable to and not bad */
  777. f.is_open()    /* {bool} file is open */
  778. f.raw()     /* {void} set f to unbuffered mode */
  779. f.failif(i)    /* if i!=0, set f's 'failed' pointer */
  780. f.get(c)    /* read a character from file into c */
  781. f.put(c)    /* put the character c */
  782. f.unget(c)    /* put char c back in f's input buffer */
  783. f.putback(c)    /* put char c back in f's input buffer */
  784. f.read(p,i,j)    /* read from f j items of i bytes each.
  785.             f.stat = how many items successfully read. */
  786. f.write(p,i,j)    /* write to  f j items of i bytes each.
  787.             f.stat = how many items successfully read. */
  788. f.flush()    /* if write, write f's buffer, else empty it. */
  789. f.flush(c)    /* ditto, then put c into the emptied buffer ? */
  790. f.fill()    /* fill buffer from file and return {int} = first char ? */
  791.     /* f.seek returns {int} = 0 for success, nonzero for failed */
  792. f.seek(n,0)    /* go to nth byte in file */
  793. f.seek(n,1)    /* move n bytes forward in file */
  794. f.seek(n,2)    /* go to nth byte after (-ve = before) end of file */
  795. f.tell()    /* {long} value returned by the last fread etc */
  796. f.rdstate()    /* f.check_state(); {int} = the result */
  797. f        /* if used as a {void*}: return some state info */
  798. f.eof()     /* {boolean} if file is in end of file condition */
  799. f.fail()    /* {boolean} if file is in failed condition */
  800. f.bad()     /* {boolean} if file is in 'bad' condition */
  801. f.good()    /* {boolean} if file is not at and of file or bad or failed */
  802.  
  803. ======================================== FILEBUF.H
  804. [ANOTHER WAY OF ACCESSING FILES]
  805. #include <streambuf.h>, which see
  806.  
  807. int i,j; char *s,*n;
  808. filebuf f;    /* declare f to hold a way of accessing file numbered fd,
  809.         using a streambuf as buffer */
  810.     /* it has accessible menbers: int fd; char opened;
  811.     /* f contains a streambuf, and can be used as a streambuf */
  812. filebuf()    /* a new {filebuf} with fd=-1, opened=0, with no buffer */
  813. filebuf(i)    /* a new {filebuf} with fd=i,  opened=1, with no buffer */
  814. i        /* used as a {filebuf}: ditto */
  815. filebuf(i,s,j)    /* a new {filebuf} with fd=i,  opened=1, buffer s (length j) */
  816. f.is_open()    /* {int} f.opened */
  817. f.close()    /* if f.opened, close file numbered f.fd; f.opened=0;
  818.         return {int} old value of f.opened */
  819.     /* f.open returns {streambuf*} a pointer to f's contained streambuf */
  820. f.open(n,0)    /* open f for reading file named n */
  821. f.open(n,1)    /* open f for writing file named n */
  822. f.open(n,2)    /* open f for appending file named n */
  823.     /* the next 4 uses do nothing & return NULL {streambuf*} value */
  824. f.open(n,i,j)    /* i is io_mode, j is access_mode, see FILE.H */
  825. f.open(n,s)    /* s probably = "r" etc as in old-style fopen() */
  826. f.open(i,s)    /* ditto, and i = file number? */
  827. f.open(F)    /* F is an old-style FILE* pointer */
  828. f.underflow()    /* give f a buffer if it hasn't got one; read a bufferful of
  829.         text from file fd; return {int} char at get-pointer */
  830.         /* automatically called by many streambuf.functions when used as
  831.         filebuf.functions, when the filebuf runs out of chars on read */
  832. f.overflow(EOF) /* give f a buffer if it hasn't got one; write buffer contents
  833.         to file fd; return {int} EOF if fault, else 0 */
  834.         /* automatically called by many streambuf.functions when used as
  835.         filebuf.functions, when the filebuf gets full on write */
  836. f.overflow(i)    /* if i!=EOF, f.sputc(i); then as ditto */
  837. ~filebuf()    /* Destructor: close filebuf at end of block that declared in */
  838.  
  839. ======================================== FIX.H
  840. [MULTI-LENGTH FIXED-POINT REAL ARITHMETIC WITH abs(value) < 1]
  841. #include <Integer.h>, which see
  842.  
  843. Fix f;    /* declare f to hold a variable length fixed point number */
  844. Fix e,f,g,h; int i; double x;
  845. f.unique()    /* make sure that f does not share info with other Fix'es */
  846. Fix(i)        /* a new {Fix} with length i */
  847. i        /* used as {Fix}: ditto */
  848. Fix(x)        /* a new {Fix} with value x */
  849. x        /* used as {Fix}: ditto */
  850. Fix(f)        /* copy of pointers of f.
  851.         f is marked to say that its info is now pointed to twice */
  852.         /* called automatically when a Fix is copied or allocated etc */
  853. Fix(i,f)    /* a new {Fix} = f but with length i */
  854. Fix(i,x)    /* a new {Fix} with length i, value x */
  855. ~Fix()        /* Destructor. Keeps track of multiple pointers to info part */
  856. f = g        /* If f & g have same length, copy pointers to info.
  857.         Else complete copy. Returns {Fix} = f */
  858. f = x        /* set value of f = x. Returns {Fix} = f */
  859. + - * / % += -= *= /= %= == != < > <= >= << >> <<= >>=
  860.         /* with Fix argument(s) have usual mathematical meaning */
  861. f * i    i * f    f *= i    /* ditto */
  862.     /* These next 2 operators only #ifdef __GNUG__ :- */
  863. f <? g        /* {Fix} = smaller of f and g */
  864. f >? g        /* {Fix} = larger  of f and g */
  865.     /* note order of args in these functions! */
  866. negate(f,e)    /* {void} e = - f */
  867. add(f,g,e)    /* {void} e = f + g */
  868. subtract(f,g,e) /* {void} e = f - g */
  869. multiply(f,g,e) /* {void} e = f * g */
  870. divide(f,g,e,h) /* {void} e = f / g; h = remainder */
  871. shift(f,i,e)    /* {void} e = f << i */
  872. abs(f)        /* {Fix} = absolute value of f */
  873. sgn(f)        /* {Fix} = -1 or 0 or +1 as sign of f */
  874. length(f)    /* length of f */
  875. ostream F; istream G;
  876. F << f        /* {ostream}: as  F << Ftoa(f) */
  877. G >> f        /* {istream}: read f from file, as usual */
  878. atoF(s)     /* as atoF(s,Fix_default_length) */
  879. Ftoa(f)     /* as Ftoa(s,Fix_default_print_width) */
  880. atoF(s,i)    /* as Fix(i,atof(s)) */
  881. Ftoa(f,i)    /* {char*} = value of f, printed as at least i chars.
  882.         *** value of f printed is shortened to double if longer */
  883. show(f)     /* print to screen f's internal info */
  884.  
  885. ======================================== FIX16.H
  886. [16-BIT & 32-BIT FIXED-POINT REAL ARITHMETIC WITH abs(value) < 1]
  887.  
  888. Fix16 f;    /* declare f to hold a real number which can vary from
  889.         -1 to +1-pow(0.5,15) by steps of pow(0.5,15) */
  890. Fix32 F;    /* declare f to hold a real number which can vary from
  891.         -1 to +1-pow(0.5,31) by steps of pow(0.5,31) */
  892. /* run time error results if calculation generates out of range value */
  893.  
  894. Fix16 f; Fix32 F; double x; short n; long N;
  895.  
  896.     /* conversions allowed implicitly or by casting:-
  897.         int or short to Fix16 by dividing by pow(2,15)
  898.         int or long  to Fix32 by dividing by pow(2,31)
  899.         Fix16 and Fix32 and double to each other */
  900.  
  901. f.round(x)    /* returns {short} = nearest integer to x. f not affected */
  902. F.round(x)    /* returns {long} = nearest integer to x. F not affected */
  903. Fix16()     /* {Fix16} with value = 0 */
  904. Fix32()     /* {Fix32} with value = 0 */
  905. mantissa(f)    /* {short} (value of f) * pow(2,15) */
  906.     /* can be used as lvalue: effect is f = (value allocated)/pow(2,15) */
  907. mantissa(F)    /* {long} (value of F) * pow(2,31) */
  908.     /* can be used as lvalue: effect is F = (value allocated)/pow(2,31) */
  909. value(f)    /* {double} value of f */
  910. value(F)    /* {double} value of F */
  911. f.assign(x)    /* f = x; return {short} mantissa(x) */
  912.  
  913. + - * / << >> += -= *= /= <<= >>= == != < > <= >=
  914.         /* with Fix16 arguments have usual effect */
  915. << and >> as I/O operators can have right arg Fix16. Printed as double.
  916. f * i    i * f    f *= i    /* usual effect */
  917.  
  918. + - * / << >> += -= *= /= <<= >>= == != < > <= >=
  919.         /* with Fix32 arguments have usual effect */
  920. << and >> as I/O operators can have right arg Fix32. Printed as double.
  921. F * i    i * F    F *= i    /* usual effect */
  922.  
  923. ======================================== FIX24.H
  924. [24-BIT & 48-BIT FIXED-POINT REAL ARITHMETIC WITH abs(value) < 1]
  925.  
  926. Fix24 f;    /* declare f to hold a real number which can vary from
  927.         -1 to +1-pow(0.5,23) by steps of pow(0.5,23) */
  928.         /* Stored in 4 bytes but only uses 3 of them */
  929. Fix48 F;    /* declare f to hold a real number which can vary from
  930.         -1 to +1-pow(0.5,47) by steps of pow(0.5,47) */
  931.         /* Stored in 8 bytes but only uses 6 of them */
  932.     /* run time error if calculation produces out of range value */
  933.  
  934. Fix24 f; Fix48 F; int i; long n; double x;
  935.  
  936.     /* conversions allowed implicitly or by casting:-
  937.         int or long to Fix24 by dividing by pow(2,23)
  938.         int or long to Fix48 by dividing by pow(2,47)
  939.         Fix24 and Fix48 and double to each other */
  940.  
  941. Fix24()     /* new {Fix24} = 0 */
  942. mantissa(f)    /* {long} (value of f) * pow(2,23) */
  943.     /* can be used as lvalue: effect is f = (value allocated)/pow(2,23) */
  944. value(f)    /* {double} value of f */
  945.  
  946. typedef struct {long u; unsigned long l; } twolongs;
  947. /* 1 bit sign; 23 bits data; 8 bits wasted; 24 bits data; 8 bits wasted */
  948. twolongs t;
  949. /* value of t = t.u / pow(2.0,31) + sign(t.u) * t.l / pow(2.0,55) */
  950.  
  951. Fix48()     /* a new {Fix48} = 0 */
  952. mantissa(F)    /* {twolongs} (value of F) * pow(2,47) */
  953.     /* can be used as lvalue: effect is F = (value allocated)/pow(2,47) */
  954. value(F)    /* {double} value of F */
  955.  
  956. + - * / << >> += -= *= /= <<= >>= == != < > <= >=
  957.         /* with Fix24 arguments have usual effect */
  958. << and >> as I/O operators can have right arg Fix24. Printed as double.
  959. f * i    i * f    f *= i    /* usual effect */
  960.  
  961. + - * / << >> += -= *= /= <<= >>= == != < > <= >=
  962.         /* with Fix24 arguments have usual effect */
  963. << and >> as I/O operators can have right arg Fix48. Printed as double.
  964. F * i    i * F    F *= i    /* usual effect */
  965.  
  966. ======================================== FMODES.H
  967. /* some #defines used by input/output functions :- */
  968. enum io_mode { /* known unix file IO modes */
  969.   io_readonly    = 0, io_writeonly  = 1, io_readwrite  = 2, io_appendonly = 3,
  970.   io_append    = 4, /* append, plus allow reads */ };
  971. enum access_mode { /* ways to open a file */
  972.   a_createonly    = 0, /* create, fail if file exists */
  973.   a_create    = 1, /* create if doesn't exist, else truncate */
  974.   a_useonly    = 2, /* use (no truncate)  fail if doesn't exist */
  975.   a_use     = 3, /* use (no truncate), create if doesn't exist */ };
  976. enum state_value { /* File states */
  977.   _good     = 0, /* all is well */
  978.   _eof        = 1, /* at eof */
  979.   _fail     = 2, /* logical or physical input/output error */
  980.   _bad        = 4} /* unopened/corrupted */
  981.  
  982. ======================================== GENERIC.H
  983. /* See the CPP manual, argument prescan section for explanation */
  984. /* These macros can only occur inside macro definitions */
  985.  
  986. b,c,d,e        must be arguments of the macro definition that these macros
  987.         are called inside.
  988.     They are replaced by the args of that macro's call.
  989.     Within these constructions, tags that meet at joins are concatenated.
  990.     (e.g. after    #define joined(x,y) x name(a,b) y
  991.     joined(cat call)   compiles as    x catcall y      )
  992.  
  993. name2(b,c)        b c
  994. gEnErIc2(b,c)         b c
  995. name3(b,c,d)         b c d
  996. gEnErIc3(b,c,d)         b c d
  997. name4(b,c,d,e)         b c d e
  998. gEnErIc4(b,c,d,e)    b c d e
  999. GENERIC_STRING(b)    "b" as string, and inside b adjust '\' etc accordingly
  1000. gEnErIcStRiNg(b)    "b" as string, and inside b adjust '\' etc accordingly
  1001. declare(b,c)        b declare (c)
  1002. declare2(b,c,d)        b declare2 (c,d)
  1003. implement(b,t)        b implement (t)
  1004. implement2(b,c,d)    b implement2 (c,d)
  1005. set_handler(b,c,d)    set_ c b _handler (d)
  1006. errorhandler(b,c)    c b handler
  1007. callerror(b,c,d,e)    (*c b handler)(d,e)
  1008.  
  1009. extern genericerror(int,char*);
  1010. typedef int (*GPT)(int,char*);
  1011.  
  1012. ======================================== GEOM.H
  1013. [GEOMETRIC RANDOM NUMBERS]
  1014.  
  1015. #include <_Random.h>, which see
  1016. Geometric g;    /* declare g to hold workings of a running series of Geometric
  1017.         random numbers.
  1018.         Contains and can be used as an RNG, and also:- */
  1019. double x; RNG r;
  1020. Geometric(x,&r) /* a new {Geometric} with mean x, using r */
  1021. g.mean()    /* {double} mean of x */
  1022. g.mean(x)    /* set g's mean = x; return {double} = old mean *?
  1023. g()        /* add random numbers until their sum > g's mean.
  1024.         return {double} = how many random numbers needed */
  1025.  
  1026. ======================================== GEOMETRI.H
  1027. /* same as GEOM.H */
  1028.  
  1029. ======================================== GETOPT.H
  1030. [EXAMINING TABLES OF PARAMETERS HELD IN ARRAYS OF STRINGS]
  1031.  
  1032. /* This version appears to the user like standard Unix getopt, but it behaves
  1033. differently, since it lets the user mix the options with the other arguments. As
  1034. getopt works, it permutes the elements of argv so that, when it is done, all the
  1035. options precede everything else. This lets all application programs handle
  1036. flexible argument order. Setting the environment variable _POSIX_OPTION_ORDER
  1037. disables permutation. Then the behavior is completely standard. GNU application
  1038. programs can use a third alternative mode in which they can distinguish the
  1039. relative order of options and other arguments. */
  1040.  
  1041. int n; char **t /* array of strings */; char *s;
  1042.  
  1043. GetOpt g;    /* declare g to hold a table of call arguments and info re
  1044.         scanning it for options. It has these accessible members:- */
  1045. g.optarg    /* {char*} used to return arguments of options */
  1046. g.optind    /* {int} index in ARGV of the next element to be scanned */
  1047. g.opterr    /* {int} callers store 0 here to inhibit the error message for
  1048.             unrecognized options */
  1049. g.nargc        /* {int} how many elements in nargv */
  1050. g.nargv        /* {char**} array of string arguments */
  1051. g.noptstring    /* {char*) option string */
  1052.  
  1053. GetOpt(n,t,s)    /* a new {GetOpt} with its members set thus:- g.nargc = n;
  1054.         g.nargv = t; g.noptstring = s; g.optind = 1;
  1055.         t is a table of string arguments in t[1] to t[n-1].
  1056.         s is an option string.
  1057.         If s[0]=='-', g is set up in RETURN_IN_ORDER mode, else
  1058.         if environment variable POSIX_OPTION_ORDER is set nonzero,
  1059.         then in REQUIRE_ORDER mode, else in PERMUTE mode */
  1060.  
  1061. g()    /* returns {int} :-
  1062.    Scans array elements t[i] (as set by GetOpt(n,t,s)) (i = between 1 and n-1):-
  1063.    Scan t[i]'s for option characters given in s.
  1064.    If t[i][0] == '-', and t[i] is not exactly "-" or "--", then t[i] is an
  1065. option element, and t[i]'s characters (except the initial '-') are option chars.
  1066.    If g() is called repeatedly, it returns successively each option character
  1067. >from each option element.
  1068.    If there are no more option characters, g() returns 'EOF', and t[g.optind] is
  1069. the first t[i] that is not an option. The user must scan the t[i]'s from
  1070. t[g.optind] onwards himself. The t[i]'s will have been permuted so that those
  1071. that are not options now come last.
  1072.    If s[j] == ':', s[j-1] is an option that wants an argument. The rest of t[i],
  1073. or the whole of t[i+1], is the required argument, and g.optarg now points to it.
  1074.    If an option character is seen that is not in s, g() prints an error message
  1075. and returns '?'. If you set g.opterr = 0, the error message is suppressed but
  1076. g() still returns '?'.
  1077.    If also s[j+1] == ':', s[j-1] is an option that wants an optional argument,
  1078. which is the the rest of t[i] if there is any of t[i] unscanned.
  1079.    If s[0] == '-', g() handles the non-option t[i]'s differently. See below.
  1080.    In PERMUTE mode (the default), g() permutes the t[i]'s as it scans, as above,
  1081. so that eventually all the options are at the end. This allows options to be
  1082. given in any order, even with programs that were not written to expect this.
  1083.    In REQUIRE_ORDER mode, g() stops when it finds the first t[i] that is not an
  1084. option. This is what Unix does.
  1085.    In RETURN_IN_ORDER mode, the t[i]'s are not permuted, and g() treats each
  1086. non-option t[i] as the argument of an option = (char)0. Using '-' as the first
  1087. character of the list of option characters requests this mode of operation.
  1088.    If any t[i] is the special argument "--", scanning for options ends there
  1089. whether or not the t[i]'s are being permuted. In RETURN_IN_ORDER mode, only "--"
  1090. can cause g() to return EOF with g.optind != g.argc */
  1091.  
  1092. ======================================== GETPAGES.H
  1093. /* #define's re page size */
  1094.  
  1095. ======================================== GRAPHICS.H
  1096. [GRAPHICS]
  1097. You should also #include <mouse.h>
  1098. Also read file <wherever your Gnu C is kept>\DOCS\LIBGR.DOC
  1099.  
  1100. GrRegion g;    /* set up g to hold details of a graphical region on screen.
  1101.         It has these accessible members:-
  1102. g.flags        /* {int} re mouse?
  1103. g.color        /* {int} color where not drawn on
  1104. g.parent    /* {GrRegion*} pointer to GrRegion that it is a subregion of
  1105. g.rel_x, g.rel_y    /* {int} coords ref g's origin (units are pixels)
  1106. g.abs_x, g.abs_y    /* {int} coords ref screen (units are pixels)
  1107. g.width        /* {int} width in pixels
  1108. g.height    /* {int} height in pixels
  1109. g.row_scale    /* {int} pixels per row
  1110. g.data    /* {unsigned_char*} for read/write operations *EXCEPT* bcopy/memcpy
  1111. g.rdata        /* {unsigned char*) for read via bcopy/memcpy
  1112. g.wdata        /* {unsigned char*) for write via bcopy/memcpy
  1113.  
  1114. [GRAPHIC MODES]
  1115.  
  1116. These plot routines have modes 0 to 8, which differ from the ordinary CGA /
  1117. EGA / VGA modes with the same numbers. They are:-
  1118. typedef enum {
  1119.   GR_80_25_text = 0,
  1120.   GR_default_text = 1,
  1121.   GR_width_height_text = 2,
  1122.   GR_biggest_text = 3,
  1123.   GR_320_200_graphics = 4,
  1124.   GR_default_graphics = 5,
  1125.   GR_width_height_graphics = 6,
  1126.   GR_biggest_noninterlaced_graphics = 7,
  1127.   GR_biggest_graphics = 8
  1128.   } GR_graphics_modes;
  1129. GR_graphics_modes i; int x,y;
  1130. GrSetMode(i,x,y)    /* set graphics to mode i.
  1131.             width=x and height=y in modes 2 and 6;
  1132.             x and y arguments treated as 0 if omitted */
  1133.  
  1134. [COPYING AREAS OF SCREEN]
  1135. GrRegion g,G; int x,y,i,j,k,X,Y;
  1136. Blit(*g,i,j, *G,f)        /* as Blit(*g,0,0,i,j, *G,0,0,f) */
  1137. Blit(*g,x,y,i,j, *G,X,Y,0)    /* copy an area i wide & j high from g (origin
  1138.                 = (x,y) to G (origin = (X,Y) */
  1139. Blit(*g,x,y,i,j, *G,X,Y,2)    /* ditto, but neqv each pixel copied */
  1140. Blit(*g,x,y,i,j, *G,X,Y,1)    /* do nothing */
  1141.  
  1142. [ORGANIZING PALETTE WITH 256 PLACES]
  1143. extern int _GrCurMode;
  1144. typedef struct {unsigned char n,state,r,g,b; } Color;
  1145.     /* n = how many brushes in this palette place */
  1146.     /* state: 0=free, 1=shared, 2=writable */
  1147.     /* r,g,b = how much red/green/blue (0 = none, 255 = most) */
  1148. Color color[256];    /* the palette */
  1149.  
  1150. int r,g,b; /* how much red/green/blue */
  1151. int i,j,n,f;
  1152.  
  1153.     /* At start of many functions, this function is called if necessary:- */
  1154. init_colormap() /* wash palette out;
  1155.         make black in place 0, and white in place 1 */
  1156. GrBlack()        /* {int} 0 */
  1157. GrWhite()        /* {int} 1 */
  1158. GrAllocColor(r,g,b)    /* if this mixture not made already, make it.
  1159.             {int} = index of palette place */
  1160. GrAllocCell()        /* {int} = index of a spare palette place */
  1161. GrSetColor(n,r,g,b)    /* {void} make mixture in place n; tell the system */
  1162. GrQueryColor(n,&r,&g,&b)    /* {void} find what nth mixture is */
  1163. GrFreeColor(n)        /* {void} throw away mixture n */
  1164. GrRefreshColors()    /* on some systems, tell the system again about all the
  1165.             color mixtures */
  1166.  
  1167. [SCREEN]
  1168. unsigned _GrMaxX; /* current screen width */    unsigned _GrSizeX;
  1169. unsigned _GrMaxY; /* current screen height */    unsigned _GrSizeY;
  1170.  
  1171. /* the screen seems to be a byte array (1 per pixel) by rows starting at address
  1172. hex D0000000 = 13 * pow(2,28). Not > pow(2,20) screen positions */
  1173. int x,y,X,Y,c;
  1174.     /* plot off screen has no effect */
  1175. GrPlot(x,y,c)    /* if c > 63, screen[x][y] is neqv'ed with c */
  1176.         /* else screen[x][y] = c */
  1177.         /* screen[x][y] may be the number of the color mixture there */
  1178. GrPixel(x,y)    /* {int} screen[x][y] (0 if off screen) */
  1179. GrPlot3d(x,y,c) /* if c > screen[x][y], or c < 96, screen[x][y] = c */
  1180. GrMaxX()    /* {int} _GrMaxX = maximum screen width */
  1181. GrMaxY()    /* {int} _GrMaxY = maximum screen height */
  1182. GrSizeX()    /* {int} _GrSizeX; */
  1183. GrSizeY()    /* {int} _GrSizeY; */
  1184.  
  1185. [DRAW A LINE]
  1186. GrLine(x,y,X,Y,c)    /* draw a line of color c from (x,y) to (X,Y) */
  1187.  
  1188. [MOUSE]
  1189. [mouse flags:-]
  1190. #define M_LEFT_DOWN    0x001    #define M_LEFT_UP    0x002
  1191. #define M_MIDDLE_DOWN    0x004    #define M_MIDDLE_UP    0x008
  1192. #define M_RIGHT_DOWN    0x010    #define M_RIGHT_UP    0x020
  1193. #define M_MOTION    0x040    #define M_KEYPRESS    0x080
  1194. #define M_POLL        0x100    #define M_NOPAINT    0x200
  1195. #define M_BUTTON_DOWN    (M_LEFT_DOWN | M_MIDDLE_DOWN | M_RIGHT_DOWN)
  1196. #define M_BUTTON_UP    (M_LEFT_UP | M_MIDDLE_UP | M_RIGHT_UP)
  1197.  
  1198. typedef struct {int flags, x, y, buttons, key; } MouseEvent; MouseEvent e;
  1199. (x,y) = where mouse was last;
  1200. (e.buttons & 1) != 0 if left   buttom down;
  1201. (e.buttons & 2) != 0 if middle buttom down;
  1202. (e.buttons & 4) != 0 if left   buttom down;
  1203. (e.flags &   1) != 0 if left   button pressed
  1204. (e.flags &   2) != 0 if left   button released
  1205. (e.flags &   4) != 0 if middle button pressed
  1206. (e.flags &   8) != 0 if middle button released
  1207. (e.flags &  16) != 0 if right  button pressed
  1208. (e.flags &  32) != 0 if right  button released
  1209. (e.flags &  21) != 0 if any    button pressed
  1210. (e.flags &  42) != 0 if any    button released
  1211. (e.flags &  64) != 0 if mouse moves
  1212. (e.flags & 128) != 0 if a keyboard key pressed
  1213. (e.flags & 256) != 0 if MouseGetEvent has used this MouseEvent variable
  1214. e.key = raw code number (not (char) value) of last (if any) keyboard key pressed
  1215.     while MouseGetEvent was using e
  1216.  
  1217. MouseSetColors(f,b)    /* set mouse symbol foreground & background colors */
  1218. paint_mouse(x, y)    /* draw a mouse-symbol at (x,y) */
  1219. unpaint_mouse()     /* remove mouse-symbol */
  1220. MouseSetSpeed(i)    /* set mouse speed to i (by int33 with ax=15) */
  1221. MouseWarp(x,y)        /* move mouse pointer to (x,y) */
  1222. MouseGetEvent(n,*e)    /* keep track of the mouse until a mouse event as listed
  1223.             above happens, and record the result in e; but ignore
  1224.             events whose bits are not also set in n; but always keep
  1225.             track of mouse movements in e.x and e.y .
  1226.             If (n&512) != 0, mouse symbol does not move with mouse.
  1227.  
  1228. [REGIONS]
  1229. GrScreenRegion()    /* {GrRegion*} = a GrRegion covering all the screen */
  1230. GrRegion()    /* a new {GrRegion} with size = 0 both ways */
  1231. GrRegion(i,j)    /* a new {GrRegion} i wide and j high */
  1232. g.SubRegion(x,y,i,j)    /* a new {GrRegion} within g, origin at (x,y),
  1233.             i wide, j high. NULL if can't be created.
  1234.             An empty {GrRegion} if size goes out of size of g */
  1235. g.MaxX()    /* {int} g.width-1 */
  1236. g.MaxY()    /* {int} g.height-1 */
  1237. g.SizeX()    /* {int} g.width */
  1238. g.SizeY()    /* {int} g.height */}
  1239.         /* in these functions, if c&64!=0, each point neqv'ed by c */
  1240.  
  1241. g.Plot(x,y,c)        /* draw dot at (x,y), color = c */
  1242. g.Line(x,y,X,Y,c)    /* draw line, color = c */
  1243. g.HLine(x,X,y,c)    /* draw horizontal line, color = c */
  1244. g.VLine(x,y,Y,c)    /* draw vertical line, color = c */
  1245. g.Rectangle(x,y,X,Y,c)    /* draw hollow rectangle, color = c */
  1246. g.Box(x,y,X,Y,c)    /* draw solid rectangle, color = c */
  1247. char *s;
  1248. g.Text(x,y,s,f,b)    /* draw text s starting at (x,y),
  1249.                 foreground color = f, background color = b */
  1250. g.Text(x,y,s,f,-1)    /* ditto, background = what was there before */
  1251. g.Point(x,y)        /* {int} = color at point (x,y) */
  1252. GrTextXY(x,y,s,f,b)    /* draw text s starting at (x,y),
  1253.                 foreground color = f, background color = b */
  1254.  
  1255. ======================================== GRP.H
  1256. /* #define's, perhaps re graphics? */
  1257.  
  1258. ======================================== HYPERGEO.H
  1259. [HYPERGEOMETRIC RANDOM NUMBERS]
  1260.  
  1261. #include <_Random.h>, which see
  1262. double x,m,v; RNG r;
  1263. HyperGeometric g;    /* declare g to hold workings of s running series of
  1264.             hypergeometric random numbers */
  1265. HyperGeometric(m,v,&r)    /* a new {HyperGeometric} with mean=m, variance=v,
  1266.             using r */
  1267. g.mean()        /* {double) = mean of g */
  1268. g.mean(m)        /* mean of g = m; {double} = previous mean */
  1269. g.variance()        /* {double) = variance of g */
  1270. g.variance(v)        /* variance of g = v; {double} = previous variance */
  1271. g()        /* x = (variance - mean*mean) / (variance + mean*mean);
  1272.            x = (1-sqrt(x))/2; if (random number) > x then x = 1 - x;
  1273.            {double) = log((another random number)/2/x) */
  1274.  
  1275. ======================================== HYPGEOM.H
  1276. /* same as HYPERGEO.H */
  1277.  
  1278. ======================================== INCREMEN.H
  1279. /* for a user initializer file? */
  1280.  
  1281. ======================================== INTEGER.H
  1282. [MULTI-LENGTH INTEGER ARITHMETIC]
  1283.  
  1284. Integer x,y,z;    /* declare multi-length integer variables */
  1285. int i,j,k;
  1286.     /* there is automatic conversion between Integer and long int */
  1287.     /* fault if value is too big on conversion */
  1288. x.initialized()     /* {boolean} = if x has been given a value */
  1289. x.fits_in_long()    /* {boolean} = if value of x will fit into long int */
  1290. x.fits_in_double()    /* {boolean} = if value of x will fit into double */
  1291.     /* the next two functions can also have either argument long int */
  1292. compare(x,y)        /* {int) < 0 if x < y, == 0 if x == y, > 0 if x > y */
  1293. ucompare(x,y)        /* {int} compare(abs(x),abs(y)) */
  1294. + - * / % += -= *= /= %= == != < > <= >= << >> <<= >>= ++ -- & &= | |= ^ ^= ~
  1295.     /* with Integer argument(s) have their usual meanings */
  1296.     /* but not ++ -- to <right> of their argument? */
  1297.     /* these next two function uses only if #ifdef __GNUG__ :- */
  1298. x <? y        /* {Integer} minumum */
  1299. x >? y        /* {Integer} maximum */
  1300. abs(x)        /* {Integer} absolute value of x */
  1301. sign(x)     /* {int} = -1 if x < 0, 0 if x == 0, +1 if x > 0 */
  1302. odd(x)        /* {boolean} = if x is odd number */
  1303. even(x)     /* {boolean} = if x is even number */
  1304. lg(x)        /* {long int}
  1305. sqr(x)        /* {Integer} x * x  (<not> sqrt!) */
  1306. Integer r; long int I,J,K,R; char *s;
  1307. pow(x,y)    /* {Integer} power */
  1308. pow(x,I)    /* {Integer} power */
  1309. Ipow(I,J)    /* {Integer} power */
  1310. gcd(x,y)    /* {Integer} biggest number > 0 that is factor of x and of y */
  1311. ratio(x,y)    /* {double} x/y */
  1312. divide(x,y,z,r) /* {void} z = y / y, r = remainder */
  1313. divide(x,J,z,R) /* {void) z = x / J, R = remainder */
  1314. setbit(x,K)    /* set '1 << K' bit of x = 1. Lengthen x if necessary */
  1315. clearbit(x,K)    /* set '1 << K' bit of x = 0. Lengthen x if necessary */
  1316. testbit(x,K)    /* {boolean} = the '1 << K' bit of x */
  1317. sqrt(x)     /* {Integer} square root of x */
  1318. lcm(x,y)    /* {Integer} x * y / gcd(x,y) */
  1319. Itoa(x)     /* {char*} x printed */
  1320. Itoa(x,i)    /* {char*} x printed to radix i */
  1321. Itoa(x,i,j)    /* {char*} x printed to radix i as >= j chars */
  1322. atoI(s)     /* s read as an {Integer} */
  1323. atoI(s,i)    /* s read as an {Integer} to radix i */
  1324. <<  >>        /* as input/output operators can be used with Integer */
  1325. dec(x,j)    /* {char*} x printed as <= j chars */
  1326. oct(x,j)    /* {char*} x printed octal as <= j chars */
  1327. hex(x,j)    /* {char*} x printed hexadecimal as <= j chars */
  1328. x.OK()        /* {boolean} if x's internal workings are correct */
  1329.  
  1330. ======================================== IO.H
  1331. /* this #include file is empty */
  1332.  
  1333. ======================================== ISTREAM.H
  1334. [ANOTHER WAY TO ACCESS INPUT FILES]
  1335. /* and see OSTREAM.H */
  1336.  
  1337. #include <_File.h>, which see
  1338. #include <streambuf.h>, which see
  1339. #include <filebuf.h>, which see
  1340. #include <_Filebuf.h>, which see
  1341.  
  1342. istream F;    /* declare an input channel */
  1343. ostream G;    /* declare an output channel */ /* see OSTREAM.H */
  1344.     /* these have a hidden int member F.state or G.state, which = 0 for OK,
  1345.     1 for end-of-file, 2 for input/output failure, 4 for bad */
  1346.     /* F has a hidden char member F.skipws: if F.skipws != 0, at start of
  1347.     any reads, the istream's pointer skips over any succession of spaces or
  1348.     ctrl-J to ctrl-M's at pointer */
  1349.     /* An ostream can be tied to an istream; on any reads on the istream,
  1350.     its tied ostream's buffer contents are sent to file */
  1351.  
  1352. class whitespace {char filler; }
  1353.     /* a class used only to input and discard white space characters */
  1354. int i,j,k; char c,*s,*t; double x; FILE *f; streambuf S; whitespace w;
  1355. istream cin;    /* predeclared to mean stdin, i.e. usually the keyboard */
  1356.     /* These functions etc return {istream} = F, unless stated otherwise */
  1357.     /* all uses of istream(..) return a new {istream}, tied to ostream G,
  1358.     with skipws = k, and the rest of the arguments as follows:- */
  1359.     /* If k omitted, it = 1. If G omitted, it = 0, i.e. no tied ostream */
  1360. istream(s,k,G)        /* buffer = s */
  1361. s            /* used as an {istream}: ditto */
  1362. istream(i,s,k,G)    /* buffer = s, buffer length = i bytes */
  1363. istream(i,0,k,G)    /* with new buffer i bytes long */
  1364. istream(s,i,j,k,G)    /* internal name s, io_mode = i, access_mode = j */
  1365.             /* see FMODES.H for values of i and j */
  1366. istream(s,t,k,G)    /* t = opening mode as old-style C fopen */
  1367. istream(i,j,k,G)    /* opened on file numbered i, open_mode j */
  1368. istream(f,k,G)        /* opened on old-style C FILE *f */
  1369. f            /* used as an {istream}: ditto */
  1370. istream(i,k,G)        /* opened on file numbered i */
  1371. i            /* used as an {istream}: ditto */
  1372. istream(i,s,j,k,G)    /* ditto, buffer = s, buffer length = i */
  1373. istream(S,k,G)        /* using streambuf S */
  1374. S            /* used as an {istream}: ditto */
  1375.  
  1376.     /* F.open() returns {istream} F, but NULL if the opening failed */
  1377. F.open(s,i,j)    /* open F, name s, io_mode i, access_mode j */
  1378. F.open(s,t)    /* ditto but t = opening mode as old-style C fopen() */
  1379. F.open(i,j)    /* open F on file numbered i, io_mode j */
  1380. F.open(f)    /* open F on old-style C FILE f */
  1381. F.open(s,i)    /* open F, name s, open_mode = m */
  1382. F.clear()    /* {void} F.state = 0 (== OK) */
  1383. F.clear(i)    /* {void} F.state = i */
  1384. F.set(i)    /* {void} set to 1 the bits of F.state which are set in i */
  1385. F.unset(i)    /* {void} set to 0 the bits of F.state which are set in i */
  1386. F.rdstate()    /* {int} F.state */
  1387. F.good()    /* {boolean} F.state == 0 (== OK) */
  1388. F.eof()     /* {boolean} the 'end of file' bit is set in F.state */
  1389. F.fail()    /* {boolean} the 'failed'      bit is set in F.state */
  1390. F.bad()     /* {boolean} the 'bad channel' bit is set in F.state */
  1391. F        /* {coerced to void*}: if F.good(), a pointer to F, else 0 */
  1392. !F        /* {boolean} if F.state != 0, i.e. if fault bit is set in F */
  1393. F.failif(i)    /* if(i!=0) F.fail() */
  1394. F.is_open()    /* {boolean} if F is open */
  1395. F.readable()    /* {boolean} if F is open and can be read from */
  1396. F.writable()    /* {boolean} false */
  1397. F.bufptr()    /* {char*} pointer to F's buffer */
  1398. F.close()    /* close F */
  1399. F.skipws(i)    /* F.skipws= i; {int} previous value of F.skipws */
  1400. F.unget(c)    /* put char c into input buffer, as sputbackc(c) in FILEBUF.H */
  1401.         /* Fails if pointer is already at start of buffer */
  1402. F.putback(c)    /* ditto */
  1403. eatwhite(F)    /* send to file the buffer contents of any ostream tied to F;
  1404.         skip F's pointer over spaces and ctrl-J to ctrl-M */
  1405. F.get(c)    /* read char from F into c */
  1406. F >> w        /* send to file the buffer contents of any ostream tied to F;
  1407.         skip F's pointer over spaces and ctrl-J to ctrl-M */
  1408. F >> c        /* read a character from F into c */
  1409. F >> s        /* read chars into s. Stop at but not including any
  1410.         space or ctrl-J to ctrl-M met */
  1411.     /* In the next 3 function uses, if the c arg is omitted, it = '\n' */
  1412. F.get(s,i,c)    /* read into s i characters but stop at (not including) any
  1413.         character == c met */
  1414. F.getline(s,i,c)    /* read into s i characters but stop at <and lose> any
  1415.         character == c met */
  1416. F.gets(&s,c)    /* read characters into s until a character == c is met.
  1417.         Loses the terminator. May alter the pointer s */
  1418. F >> i        /* read i from F; return {istream} = F */
  1419.     /* right arg can be long, unsigned long, int, unsigned int, short,
  1420.     unsigned int, float, or double */
  1421. F.name()    /* {char*} F's name */
  1422. F.error()    /* {void} make an error on F */
  1423. F.tie(G)    /* tie ostream G to F; return te previous {ostream} tied to F */
  1424. F.flush()    /* {void} send to file the buffer contents of any ostream tied
  1425.         to F */
  1426.  
  1427. ======================================== LIBC.H
  1428. #include <builtin.h>, which see
  1429.  
  1430. ======================================== LIMITS.H
  1431. #define LONG_MAX (0x7fffffff)        #define LONG_MIN (0x80000000)
  1432. #define ULONG_MAX (0xffffffff)        #define ULONG_MIN (0x00000000)
  1433.  
  1434. ======================================== LOGNORM.H
  1435. [LOGNORMAL RANDOM NUMBERS]
  1436.  
  1437. #include "Normal.h", which see
  1438. LogNormal x;    /* declare x to hold workings of a running series of lognormal
  1439.         random numbers */
  1440.         /* x contains and can be used as a Normal, and also:- */
  1441.         /* but altering the contained Normal's mean or variance directly
  1442.         will foul the workings of the LogNormal */
  1443. double m,v; RNG r;
  1444. LogNormal(m,v,&r)    /* a new {LogNormal} with mean m, variance v,
  1445.             using generator r */
  1446. x.mean()    /* {double} mean of x */
  1447. x.mean(m)    /* mean of x = m; returns {double} previous mean of x */
  1448. x.variance()    /* {double} variance of x */
  1449. x.variance(v)    /* variance of x = v; returns {double} previous variance of x */
  1450. x()    /* {double} generate & return a new log-of-normal random number */
  1451.  
  1452. ======================================== LOGNORMA.H
  1453. /* same as LOGNORM.H */
  1454.  
  1455. ======================================== MALLOC.H
  1456. [ALLOCATING MORE STORE AT RUN TIME]
  1457.  
  1458. #include <std.h>, which see for the declarations */
  1459. /* the start of (wherever you put your Gnu C)\LIBSRC\C\GPP\MALLOC.C contains a
  1460. useful description of how this malloc() etc works */
  1461.  
  1462. int i,n; void *p,*q;
  1463. malloc(n)    /* allocates n bytes, and returns {void*} pointer to them */
  1464.         /* also uses 8 more bytes per malloc, for links etc */
  1465. free(p)     /* free the space that p points to. p must point to the <start>
  1466.         of a store area allocated by malloc. Writing to a free()'d area
  1467.         may make malloc() or free() crash when either is called again.
  1468.         free() may crash if called with a wrong value of p */
  1469. cfree(p,i,n)    /* ditto */
  1470. calloc(i,n)    /* {void*} malloc(i * n), the store allocated is set to zeros */
  1471. realloc(p,n)    /* effect of: q = malloc(n); copy malloc block p into malloc
  1472.         block q, or as much as will fit; free(p); return {void*} q */
  1473. malloc_stats()    /* print malloc statistics to screen */
  1474.  
  1475. ======================================== MATH.H
  1476. [SOME MATHEMATICAL FUNCTIONS]
  1477.  
  1478. double x,y; int i;
  1479. acosh(x)    /* {double} arccosh(x) */
  1480. asinh(x)    /* {double} arcsinh(x) */
  1481. cbrt(x)     /* {double} cube root of x? */
  1482. copysign(x,y)    /* {double} x with sign of y? y with sign of x? */
  1483. erf(x)        /* {double} error function */
  1484. erfc(x)     /* {double} 1 - erf(x) */
  1485. finite(x)    /* {double} what??? */
  1486. gamma(x)    /* {double} gamma function(x) */
  1487. hypot(x,x)    /* {double} sqrt(x*x + y*y)(x) */
  1488. infnan(i)    /* {boolean} x is machine infinity or illegal value (??) */
  1489. isinf(x)    /* {boolean} x is machine infinity */
  1490. isnan(x)    /* {boolean} x != x, i.e. x is some sort of illegal value */
  1491. j0(x)        /* {double} Bessel functions? */
  1492. j1(x)        /* {double}
  1493. jn(i, x)    /* {double}
  1494. lgamma(x)    /* {double}
  1495. y0(x)        /* {double}
  1496. y1(x)        /* {double}
  1497. yn(i,x)     /* {double}
  1498.     /* I am guessing that these 4 functions mean the same as in Fortran */
  1499. aint(x)     /* {double} x rounded to integer: towards 0 or -infinity?? */
  1500. anint(x)    /* {double} nearest integer to x */
  1501. irint(x)    /* {int} x rounded to integer: towards 0 or -infinity?? */
  1502. nint(x)     /* {int} nearest integer to x */
  1503.  
  1504. #define M_E        2.7182818284590452354    exp(1)
  1505. #define M_LOG2E     1.4426950408889634074    log(e) to base 2
  1506. #define M_LOG10E    0.43429448190325182765    log(e) to base 10
  1507. #define M_LN2        0.69314718055994530942    log(2) to base e
  1508. #define M_LN10        2.30258509299404568402    log(10) to base e
  1509. #define M_PI        3.14159265358979323846    pi
  1510. #define M_PI_2        1.57079632679489661923    pi/2
  1511. #define M_1_PI        0.31830988618379067154    1/pi
  1512. #define M_PI_4        0.78539816339744830962    pi/4
  1513. #define M_2_PI        0.63661977236758134308    2*pi
  1514. #define M_2_SQRTPI  1.12837916709551257390
  1515. #define M_SQRT2     1.41421356237309504880    sqrt(2)
  1516. #define M_SQRT1_2   0.70710678118654752440    1/sqrt(2)
  1517. #define PI  M_PI
  1518. #define PI2  M_PI_2
  1519.  
  1520. ======================================== MAX.H
  1521. #include <builtin.h>, which see
  1522.  
  1523. ======================================== MEMORY.H
  1524. #include <std.h>, which see
  1525.  
  1526. ======================================== MIN.H
  1527. #include <builtin.h>, which see
  1528.  
  1529. ======================================== MINMAX.H
  1530. #include <builtin.h>, which see
  1531.  
  1532. ======================================== MLCG.H
  1533. [MULTIPLICATIVE LINEAR CONGRUENTIAL GENERATOR OF RANDOM NUMBERS]
  1534.  
  1535. #include <RNG.h>, which see
  1536. long int i,j,k;
  1537. MLCG m;     /* declare m to hold the workings of a running series of that
  1538.         sort of random numbers */
  1539.     /* m includes and can be used as a RNG, and also:- */
  1540.     /* m has accessible members:
  1541.     long int initialSeedOne, initialSeedTwo, seedOne, seedTwo; */
  1542.  
  1543. m.seed1()    /* {long} m.seedOne */
  1544. m.seed1(i)    /* {void} m.seedOne = i */
  1545. m.seed2()    /* {long} m.seedTwo */
  1546. m.seed2(i)    /* {void} m.seedTwo = i */
  1547. m.reseed(i,j)    /* {void} m.initialSeedOne = s1;
  1548.               m.initialSeedTwo = s2; reset(); */
  1549. MLCG(i,j)    /* a new {MLCG}, and call m.reseed(i,j) on it */
  1550. MLCG(i)        /* as MLCG(i,1) */
  1551. i        /* used as an {MLCG}: ditto */
  1552. MLCG()        /* as MLCG(0,1) */
  1553. m.reset()    /* m.seedOne = m.initialSeedOne;
  1554.            m.seedTwo = m.initialSeedTwo;
  1555.         change m.seedOne & m.seedTwo if they naven't got enough bits; */
  1556. m.asLong()    /* generate an {unsigned long} random number thus:-
  1557.     long k = m.seedOne % 53668;
  1558.     m.seedOne = 40014 * (m.seedOne-k * 53668) - k * 12211;
  1559.     if (m.seedOne < 0) m.seedOne += 2147483563; k = m.seedTwo % 52774;
  1560.     m.seedTwo = 40692 * (m.seedTwo - k * 52774) - k * 3791;
  1561.     if (m.seedTwo < 0) m.seedTwo += 2147483399;
  1562.     long z = m.seedOne - m.seedTwo; if (z < 1) z += 2147483562;
  1563.     return (unsigned long) z; */
  1564.  
  1565. ======================================== MOUSE.H
  1566. [MOUSE]
  1567. /* described under GRAPHICS.H in [MOUSE] subsection */
  1568.  
  1569. ======================================== NEGATIVE.H
  1570. /* same as NEGEXP.H */
  1571.  
  1572. ======================================== NEGEXP.H
  1573. [NEGATIVE EXPONENTIAL RANDOM NUMBERS]
  1574. #include <_Random.h>, which see
  1575.  
  1576. double m; RNG r;
  1577. NegativeExpntl z;    /* declare z to hold the workings of a running series of
  1578.             negative exponential random numbers */
  1579.     /* z includes a Random, which it can be used as, and also:- */
  1580. NegativeExpntl(x,&r)    /* a new {NegativeExpntl} with mean = x, using r */
  1581. z.mean()        /* {double} mean of z */
  1582. z.mean(x)        /* mean of z = m; return {double} previous mean of z */
  1583. z()            /* {double} = (mean of z) * log(random number) */
  1584.  
  1585. ======================================== NEW.H
  1586. [THE C++ STORE ALLOCATION OPERATOR new]
  1587. /* see MALLOC.H */
  1588.  
  1589. int i,n; void* p;
  1590. new(n,p)    /* {void*} merely return p !! */
  1591. new(n,p,i)    /* {void*} realloc(p, n*i) */
  1592. new(n)        /* {void*} malloc(n) */
  1593.  
  1594. ======================================== NORMAL.H
  1595. [RANDOM NUMBERS BY THE NORMAL-DISTRIBUTION]
  1596. #include <_Random.h>, which see
  1597.  
  1598. double m,v,s; RNG r;
  1599. Normal x;    /* declare x to hold the workings of a running series of normal
  1600.         random numbers */
  1601.     /n includes a Random, which it can be used as, and also:- */
  1602.     /* n has these accessible members:-
  1603.         char haveCachedNormal; double cachedNormal;
  1604.     and these hidden members: double pMean, pVariance, pStdDev;
  1605.     (x.pStdDeV = standard deviation, it is kept = sqrt(x.Variance)) */
  1606.  
  1607. Normal(m,v,&r)    /* a new {Normal} with mean = m, variance = v, using r */
  1608. x.mean()    /* {double} mean of x */
  1609. x.mean(m)    /* mean of x = m; returns {double} previous mean of x */
  1610. x.variance()    /* {double} variance of x */
  1611. x.variance(v)    /* variance of x = v; returns {double} previous variance of x */
  1612. x()        /* {double} generate a normal random number thus:-
  1613.     double w,y,z;        /* This is the "polar" method */
  1614.     if(x.haveCachedNormal == 1) {
  1615.     x.haveCachedNormal = 0; return x.cachedNormal * x.pStdDev + x.pMean; }
  1616.     else:-
  1617.     y & z = uniform random numbers between -1 and +1; w = y*y + z*z;
  1618.     repeat last line until w <= 1;
  1619.     w = sqrt(-2 * log(w) / w); haveCachedNormal = 1; y *= w; z *= w;
  1620.     cachedNormal = z; return y * x.pStdDev + x.pMean; */
  1621.  
  1622. ======================================== OBSTACK.H
  1623. [OBJECT STACK MACROS]
  1624.  
  1625. #include <_obstack.h>, which I describe here.
  1626. Obstack x;    /* declare x to hold a stack of objects. The object on top of
  1627.         the stack can be appended to */
  1628.  
  1629. /* The start of (wherever you keep your Gnu C)\INCLUDE\OBSTACK.H contains a long
  1630. description of how Obstacks are organized */
  1631.  
  1632. /*** These functions are inline, i.e. the body is written out in full at every
  1633. call like with macros. Arguments of these functions must not have side-effects
  1634. (e.g. '*p++' or 'xyz[++i]' or 'get_next_character(file)'), as they may be obeyed
  1635. many times per call of each of these functions. ***/
  1636.  
  1637. int i,n; char c,*s; void *p,*q;
  1638. /* p and q are pointers to objects in the stack x */
  1639.  
  1640. Obstack()    /* as Obstack(4080,4) */
  1641. Obstack(n)    /* as Obstack(n,4) */
  1642. n        /* used as an Obstack: ditto */
  1643. Obstack(n,i)    /* a new {Obstack} with its 'chunk size' = n and its
  1644.         'alignmentmask' = i-1 */
  1645. x.base()    /* {void*} base of stack */
  1646. x.next_free()    /* {void*} next free address on stack */
  1647. x.alignment_mask()    /* {int} */
  1648. x.chunk_size()    /* {int} */
  1649. x.size()    /* {int} x.next_free() - x.base() */
  1650. x.room()    /* {int} how much free space left in x */
  1651.     /* All appends are to the object on top of the stack */
  1652. x.grow(p,n)    /* {void} append as copy of (n bytes starting at p)
  1653. x.grow(p,n,c)    /* {void} ditto, and then append char c as terminator */
  1654. x.grow(s)    /* {void} append a copy of object s, including trailing zero */
  1655. x.grow(c)    /* {void} append char c */
  1656. x.blank(n)    /* {void} append n bytes, not set to anything in particular */
  1657. x.finish()    /* finish the object on top of the stack; return {void*} =
  1658.         address of a new empty object on top of the stack */
  1659. x.finish(c)    /* x.grow(c);      {void*} x.finish(); */
  1660. x.copy(p,n)    /* x.grow(p,n);   {void*} x.finish(); */
  1661. x.copy(p,n,c)    /* x.grow(p,n,c); {void*} x.finish(); */
  1662. x.copy(s)    /* x.grow(s);      {void*} x.finish(); */
  1663. x.copy(c)    /* x.grow(c);      {void*} x.finish(); */
  1664. x.alloc(n)    /* x.blank(n);      {void*} x.finish(); */
  1665. x.free(p)    /* {void} throw away the object p */
  1666. x.grow_fast(c)    /* {void} as x.grow(c)    but no stack array overflow check */
  1667. x.blank_fast(n) /* {void} as x.blank(n) but no stack array overflow check */
  1668. x.shrink()    /* as x.shrink(1) */
  1669. x.shrink(n)    /* {void} remove the top n bytes from the object on top of the
  1670.         stack. If not >=n bytes in that object, do nothing */
  1671. x.newchunk(n)    /* {void} give x n more bytes for growing objects */
  1672. x.contains(p)    /* {boolean} if object p is in x */
  1673. x.OK()        /* {boolean} if x's internal details are OK */
  1674.  
  1675. ======================================== OSFCN.H
  1676. #include <std.h>, which see
  1677. #include <time.h>, which see
  1678. #include <sys/resource.h>, which is:-
  1679. #include <sys/time.h>, which see
  1680.  
  1681. #define RUSAGE_SELF    0        /* calling process */
  1682. #define RUSAGE_CHILDREN -1        /* terminated child processes */
  1683. int n; struct rusage r;
  1684.  
  1685. getrusage(n,&r) /* {int} get resource usage info into struct r */
  1686.         /* n <might> mean: 0 = usage of self, -1 = usage of a 'child
  1687.         process' which has finished */
  1688.         /* I don't know what the value returned is */
  1689. struct rusage {
  1690.     struct timeval ru_utime;    /* user time used */
  1691.     struct timeval ru_stime;    /* system time used */
  1692.     long ru_maxrss;         /* integral max resident set size */
  1693.     long ru_ixrss;            /* integral shared text memory size */
  1694.     long ru_idrss;            /* integral unshared data size */
  1695.     long ru_isrss;            /* integral unshared stack size */
  1696.     long ru_minflt;         /* page reclaims */
  1697.     long ru_majflt;         /* page faults */
  1698.     long ru_nswap;            /* swaps */
  1699.     long ru_inblock;        /* block input operations */
  1700.     long ru_oublock;        /* block output operations */
  1701.     long ru_msgsnd;         /* messages sent */
  1702.     long ru_msgrcv;         /* messages received */
  1703.     long ru_nsignals;        /* signals received */
  1704.     long ru_nvcsw;            /* voluntary context switches */
  1705.     long ru_nivcsw;         /* involuntary context switches */ };
  1706.  
  1707. struct timeval {  long tv_sec;    long tv_usec; };
  1708. struct timezone {  int tz_minuteswest;    int tz_dsttime; };
  1709.  
  1710. ======================================== OSTREAM.H
  1711. #include <_File.h>, which see
  1712. #include <streambuf.h>, which see
  1713. #include <filebuf.h>, which see
  1714. #include <_Filebuf.h>, which see
  1715.  
  1716. istream F;    /* declare an input channel */ /* see ISTREAM.H */
  1717. ostream G;    /* declare an output channel */
  1718.     /* they use a streambuf as buffer */
  1719.     /* these have a hidden int member F.state or G.state, which = 0 for OK,
  1720.     1 for end-of-file, 2 for input/output failure, 4 for bad */
  1721.     /* An ostream can be tied to an istream; on any reads on the istream,
  1722.     its tied ostream's buffer contents are sent to file */
  1723.  
  1724.     /* declared automatically:- */
  1725. extern ostream    cout;         /* stdout, usually screen */
  1726. extern ostream    cerr;         /* stderr, usually screen */
  1727.  
  1728. int i,j,k; double x; char c,*s,*t; streambuf S; FILE *f;
  1729. ostream(S)    /* new {ostream} using streambuf S */
  1730. S        /* used as an {ostream}: ditto */
  1731. ostream(i,s)    /* new {ostream} with name s, buffer size i */
  1732. ostream(s,i,j)    /* new {ostream} opened with name s, io_mode i, access_mode j */
  1733. ostream(s,t)    /* new {ostream} opened with name s, old-style C fopen mode t */
  1734. ostream(j,i)    /* new {ostream} opened with file numbered j, io_mode i */
  1735. ostream(f)    /* new {ostream} opened using old-style C FILE f */
  1736. f        /* used as an {ostream}: ditto */
  1737. ostream(j)    /* new {ostream} opened with file numbered j */
  1738. j        /* used as an {ostream}: ditto */
  1739. ostream(j,s,i)    /* new {ostream} opened, file numbered j, buffer s (length i) */
  1740. G.open(s,i,j)    /* {ostream} open G with name s, io_mode i, access_mode j */
  1741. G.open(s,t)    /* {ostream} open G with name s, old-style C fopen mode t */
  1742. G.open(j,i)    /* {ostream} open G with file numbered j, io_mode i */
  1743. G.open(f)    /* new {ostream} opened using old-style C FILE f */
  1744. G.open(s,t)    /* new {ostream} opened with name s, old-style C fopen mode t */
  1745. G.open(s,t)    /* {ostream} open G with name s, old-style C fopen mode t */
  1746. G.clear()    /* as G.clear(0) */
  1747. G.clear(i)    /* {void} G.state = i; */
  1748. G.set(i)    /* {void} set in G.state bits set in i */
  1749. G.unset(i)    /* {void} clear in G.state bits set in i */
  1750. G.rdstate()    /* {int} G.state */
  1751. G.good()    /* {boolean} if G.state == 0 i.e. 'OK' */
  1752. G.eof()     /* {boolean} if G.state & 1 == 1, i.e. 'end of file' */
  1753. G.fail()    /* {boolean} if G.state & 2 == 2, i.e. 'input/output failure' */
  1754. G.bad()     /* {boolean} if G.state & 4 == 4, i.e. 'bad ostream' */
  1755. G        /* coerced to {void*}: if G.good(), a pointer to G, else 0 */
  1756. !G        /* {boolean} if G.good() */
  1757.     /* If these functions return {ostream}, that means G */
  1758. G.failif(i)    /* {ostream} if i!=0 set G.state to 'fail' */
  1759. G.is_open()    /* {boolean} G is open */
  1760. G.readable()    /* {boolean} 0 */
  1761. G.writable()    /* {boolean} G has a buffer and is good */
  1762. G.bufptr()    /* {char*} G's buffer */
  1763. G.flush()    /* {ostream} send buffer contents to file */
  1764. G.close()    /* {ostream} ditto, then close G */
  1765.     /* These functions return 0 if they failed */
  1766. G.put(c)    /* {ostream} send c to file */
  1767. G << c        /* {ostream} send c to file */
  1768. G.put(s)    /* {ostream} send string s to file */
  1769. G.put(s,i)    /* {ostream} ditto, left padded to >= n chars */
  1770. G << s        /* {ostream} send string s to file */
  1771. G.form(s,...)    /* {ostream} formatted print on file G using format s */
  1772. g << i        /* print i on file */
  1773.     /* right arg can be short, long, int, unsigned short, unsigned long,
  1774.     unsigned int, (on some implementations long long. unsigned long long,)
  1775.     float, double, char, char* */
  1776.     /* If right arg is a pointer (not char* or pointer to function),
  1777.     prints '0x' and pointer address as hexadecimal */
  1778. G.name()    /* {char*} name of G */
  1779. G.error()    /* {void} error routine */
  1780.  
  1781. ======================================== PC.H
  1782. [PRIMARY READ/WRITE TO/FROM PORTS]
  1783.  
  1784. unsigned short p;    /* address of port */
  1785. unsigned char s,*S; unsigned short i,*I; unsigned long j,*J; unsigned int n;
  1786. inportb(p)        /* {unsigned char}  read  1 byte  from port p */
  1787. inportw(p)        /* {unsigned short} read  2 bytes from port p */
  1788. inportl(p)        /* {unsigned long}  read  4 bytes from port p */
  1789.     /* The next 3 functions probably return their second argument */
  1790. inportsb(p,S,n)     /* {unsigned char}  read  n bytes from port p to S */
  1791. inportsw(p,I,n)     /* {unsigned short} read 2n bytes from port p to I */
  1792. inportsl(p,J,n)     /* {unsigned long}  read 4n bytes from port p to J */
  1793. outportb(p,s)        /* {void}  send  1 byte  to port p from s */
  1794. outportw(p,i)        /* {void} send    2 bytes to port p from i */
  1795. outportl(p,j)        /* {void}  send  4 bytes to port p from j */
  1796. outportsb(p,S,n)    /* {void}  send  n bytes to port p from S */
  1797. outportsw(p,I,n)    /* {void} send 2n bytes to port p from I */
  1798. outportsl(p,J,n)    /* {void}  send 4n bytes to port p from J */
  1799. kbhit()     /* {boolean} if any keys pressed and waiting to be read */
  1800. getkey()    /* {int} raw code (not ASCII!) for keyboard hit */
  1801. sound(i)    /* {void} make a sound (i = frequency) */
  1802.  
  1803. extern short ScreenPrimary[];
  1804. extern short ScreenSecondary[];
  1805. int x,y,i,j;
  1806. ScreenRows()    /* {int}   byte  (0-255)    at hex address e0000484 */
  1807. ScreenCols()    /* {int} 2 bytes (unsigned) at hex address e000044a */
  1808. ScreenPutChar(i,j,x,y)    /* {void} put (((i & 255) << 8) + (j & 255)) at hex
  1809.         address e00b8000 + 2 * (x + y * ScreenCols()), i.e. column x,
  1810.         line y, numbered from 0; if x and y are on screen */
  1811. ScreenSetCursor(x,y)    /* {void} */
  1812. ScreenGetCursor(&x,&y)    /* {void} */
  1813. ScreenClear()    /* {void} */
  1814.  
  1815. ======================================== PIX.H
  1816. typedef void* Pix;
  1817.  
  1818. ======================================== PLOTFILE.H
  1819. [CREATING UNIX "plot" FORMAT PLOTTER FILES]
  1820.  
  1821. /* See corresponding unix manual pages for more details */
  1822. #include <_File.h>, <which see>
  1823.  
  1824. PlotFile p;    /* declare p as a file interface to write that sort of file */
  1825.     /* p contains and can be used as a File, and also:- */
  1826. PlotFile(...)    /* same as File(...), but creates a {PlotFile} */
  1827. /* functions that return {PlotFile} return p unless stated otherwise */
  1828.  
  1829.     /* These functions return {PlotFile} = p */
  1830.     /* undeclared arguments are int */
  1831. p.arc(xi,yi,x0,y0,x1,y1)
  1832. p.box(x0,y0,x1,y1)
  1833. p.circle(x, y, r)
  1834. p.cont(xi, yi)
  1835. p.dot(xi, yi, dx, n, pat)    /* pat is int*, it means pat[0] to pat[n-1] */
  1836. p.erase()
  1837. p.label(s)    /* s is char* */
  1838. p.line(x0, y0, x1, y1)
  1839. p.linemod(s)    /* s is char* */
  1840. p.move(xi, yi)
  1841. p.point(xi, yi)
  1842. p.space(x0, y0, x1, y1)
  1843.  
  1844. ======================================== POISSON.H
  1845. [POISSON RANDOM NUMBERS]
  1846. #include <_Random.h>, which see
  1847.  
  1848. double m; int i; RNG r;
  1849. Poisson p;    /* declare p to hold workings of a running series of Poisson
  1850.         random numbers */
  1851.     /* has a hidden field p.pMean == mean of P */
  1852. Poisson(m,&r)    /* a new {Poisson} with mean = m, using r */
  1853. p.mean()    /* {double} mean of p */
  1854. p.mean(m)    /* mean of p = m; return {double} previous mean of p */
  1855. p()        /* multiply random numbers until product < exp(-p.pMean);
  1856.         return {double} = (how many random numbers) - 1 */
  1857.  
  1858. ======================================== PWD.H
  1859. [PASSWORD HANDLING?]
  1860. /* Sorry, this is all the info I have. All probably <missing>. */
  1861. extern struct passwd* getpwent();
  1862. extern struct passwd* getpwuid(int);
  1863. extern struct passwd* getpwnam(char*);
  1864. extern int          setpwent();
  1865. extern int          endpwent();
  1866.  
  1867. ======================================== RANDOM.H
  1868. #include <std.h>, which see
  1869.  
  1870. ======================================== RANDOMIN.H
  1871. [RANDOM INTEGERS]
  1872. #include "RNG.h", which see
  1873.  
  1874. RandomInteger r;    /*declare r to hold the workings of a running series
  1875.             of random integers */
  1876.             /* r has these hidden fields: long int p.pLow, pHigh; */
  1877. long i,j; RNG g;
  1878. r.RandomInteger(i,j,&g) /* a new {RandomInteger} with range i to j, using g */
  1879. r.RandomInteger(j,&g)    /* a new {RandomInteger} with range 0 to j, using g */
  1880. r.RandomInteger(&g)    /* a new {RandomInteger} with range 0 to 1, using g */
  1881. &g            /* used as a {RandomInteger}: ditto */
  1882. r.generator()    /* {RNG*} the RNG that r uses (don't write to this pointer) */
  1883. r.generator(&g) /* r's generator = g; return {RNG*} r's previous generator */
  1884. r.low()     /* {long} lower limit of p (inclusive) */
  1885. r.low(i)    /* r's lower limit = i; return {long} previous lower limit */
  1886. r.high()    /* {long} upper limit of p (not inclusive) */
  1887. r.high(j)    /* r's upper limit = j; return {long} previous upper limit */
  1888.     /* all these limits are inclusive:- */
  1889. r.asLong()    /* {long} random integer within r's current limits */
  1890. r()        /* {long} ditto */
  1891. r.asInt()    /* {int}  ditto */
  1892. r.asLong(j)    /* {long} random integer from r's lower limit to j */
  1893. r(j)        /* {long} ditto */
  1894. r.asLong(i,j)    /* {long} random integer from i to j */
  1895. r(i,j)        /* {long} ditto */
  1896.  
  1897. ======================================== RANDOMRA.H
  1898. [RANDOM RANGES]
  1899.  
  1900. RandomRange r;    /* declare r to hold the workings of a running series of random
  1901.         ranges */
  1902. RandomRange(x,y,&g)    /* a new {RandomRange} with lower limit = x, upper
  1903.             limit = x, using generator g */
  1904.             /* the limits are swopped if x > y */
  1905. r.low()     /* {long} lower limit of p */
  1906. r.low(x)    /* r's lower limit = x; return {long} previous lower limit */
  1907. r.high()    /* {long} upper limit of p */
  1908. r.high(y)    /* r's upper limit = y; return {long} previous upper limit */
  1909. r()        /* {double} generate a random range, but I can't find the source
  1910.         form, to find what it does. */
  1911.  
  1912. ======================================== RATIONAL.H
  1913. [RATIONAL NUMBER ARITHMETIC]
  1914.  
  1915. #include <Integer.h>, which see
  1916. Integer i,j; double x;
  1917. Rational r,s,t; /* declare rational numbers.
  1918.     Each has hidden members Integer num,den; = numerator & denominator */
  1919. Rational(s)    /* {Rational} = copy of s */
  1920. Rational(i)    /* {Rational} with num = i, den = 1, i.e. its value = i */
  1921. i        /* used as a {Rational}: ditto */
  1922.     /* {Rational} values are always normalized after being calculated, i.e.
  1923.     kept with the denom > 0, and num & denom divided by any common factor */
  1924. Rational(i,j)    /* {Rational} with num = i, den = j, i.e. its value = i/j */
  1925.     /* ditto with both arguments long int */
  1926. Rational(x)    /* x as a {Rational}, which is always possible with floating
  1927.         point numbers held to computer accuracy */
  1928. x        /* used as a {Rational}: ditto */
  1929. + - * / == != < > <= >= between Rationals have their usual meaning */
  1930. add(r,s,t)    /* {void} t = r + s */
  1931. sub(r,s,t) and mul(r,s,t) and div(r,s,t) likewise.
  1932. sign(r) /* {int} -1 or 0 or +1 according to sign of r */
  1933. r.negate()    /* {void} change sign of r */
  1934. += -= *= /= between Rationals have their usual meaning but deliver {void}.
  1935. r.numerator()    /* {Integer} numerator of r */
  1936. r.denominator()    /* {Integer} deniminator of r */
  1937.     /* These next 2 functions may not be defined in some implementations */
  1938. r <? s        /* {Rational} minimum of s and t */
  1939. r >? s        /* {Rational} maximum of s and t */
  1940. r.error()    /* {void} error handler */
  1941. r.invert()    /* {void} swop numerator and denominator of r */
  1942. compare(r,s)    /* {int} < 0 if r<s, = 0 if r=s, >0 if r>s */
  1943. trunc(r)    /* {Integer} integer divide numerator / demininator */
  1944. pow(r,i)    /* {Rational} power *//* 2nd arg can be Integer or long int */
  1945. abs(r)        /* {Rational} absolute value of r */
  1946. sqr(r)        /* {Rational} r * r (NOT sqrt!) */
  1947. floor(r)    /* {Integer} truncate towards minus infinity */
  1948. ceil(r)        /* {Integer} truncate towards plus  infinity */
  1949. round(r)    /* {Integer} nearest integer */
  1950.  
  1951. istream F; ostream G;
  1952. G << r        /* {ostream} printed as two integers with '/' between, if
  1953.         denominator of r != 1 */
  1954. F >> r        /* {istream} read numerator; if next char (perhaps after
  1955.         space) is '/', read denominator, else take denominator as 1 */
  1956. r.OK()    /* {boolean} if internal details of r are OK */
  1957.  
  1958. ======================================== REGEX.H
  1959. [REGULAR EXPRESSION SEARCH]
  1960.  
  1961. Regex r;    /* declare r to hold a pattern used for special searching */
  1962. /*** THE DECLARATION OF 'class Regex' AND THE FUNCTIONS WHICH ARE MEMBERS OF IT,
  1963. ARE MISSING IN MY COPY OF REGEX.H ***/
  1964.  
  1965. /* Defines a type Regex used for expression searching */
  1966.  
  1967. Generalized searching by a string with special characters in, thus:-
  1968. (This information may be inaccurate, as I got it by examining the source code)
  1969. "word" here means "any sequence of alphanumeric characters in the target".
  1970. The special characters are $^+?*.[]()\ and some 2-char sequences starting \
  1971. In string        In target
  1972. \w            letter or number (not PC accented letter!)
  1973. \W            not letter and not number
  1974. \<            must be at start of word
  1975. \>            must be at end of word
  1976. \b            must be at start or end of word
  1977. \B            must not be at start or end of word
  1978. \`            must be at start of target (?)
  1979. \\            must be at end of target (?)
  1980. \ and a digit        If the digit is n, if there have been >=n ( ) substrings
  1981.             remembered, match the nth of those substrings;
  1982.             else match the digit literally
  1983. \ and any other char    that character literally, even if it is ( etc
  1984. .            any character except newline
  1985. [         ]        any one of the chars between the [  ];
  1986.             if - occurs between two chars inside the [  ], it means
  1987.             'either one of those two chars or one of those between
  1988.             them in ASCII order'
  1989. [^         ]        any one character not between the [  ] ; if - occurs
  1990.             between two chars inside the [  ], it means 'not those
  1991.             two chars and none of those between them in ASCII order'
  1992. (       )        match the characters inside the (  ) as usual;
  1993.             also remember the contents of the (   )
  1994. chars1|chars2        a match to chars1 or a match to chars2
  1995. newline            means same as |
  1996. chars?            zero or one repetitions of the chars
  1997. chars*            zero or more repetitions of the chars
  1998. chars+            one or more repetitions of the chars
  1999. $   at end of string    end of line in match
  2000. $|  or  $)        same as |  or  )   but must be at end of line in match
  2001. ^            start of line in match
  2002. (^  or  |^        same as (  or  |   but must be at start of line in match
  2003.         (It is not clear how to search for the \ character.)
  2004.  
  2005. If the search string is in a C "string", then of course each \ therein must be
  2006. represented as \\, so e.g. "must be at start of word" becomes \\<
  2007.  
  2008. ======================================== RNDINT.H
  2009. /* same as RANDOMIN.H */
  2010.  
  2011. ======================================== RNG.H
  2012. [RANDOM NUMBER GENERATORS]
  2013. /* used by several random number packages */
  2014.  
  2015. RNG g;        /* declare g to hold the workings of a running series of random
  2016.         numbers */
  2017. g.asLong()    /* {unsigned long} not defined */
  2018. g.reset()    /* {void}          not defined */
  2019. g.asFloat()    /* return a random {Float}  between 0 and 1 */
  2020. g.asDouble()    /* return a random {Double} between 0 and 1 */
  2021. RNG()        /* a new initialized {RNG} */
  2022.  
  2023. ======================================== SAMPLEHI.H
  2024. /* same as SMPLHIST.H */
  2025.  
  2026. ======================================== SAMPLEST.H
  2027. /* same as SMPLTEST.H */
  2028.  
  2029. ======================================== SETJMP.H
  2030. [STORING BLOCK LEVEL INFO FOR USER JUMPS OUT OF BLOCKS]
  2031. typedef struct {unsigned long eax,ebx,ecx,edx,esi,edi,ebp,esp,eip;} jmp_buf[1];
  2032. typeof(jmp_buf[1]) J;    /* to store environment info in */
  2033. int n;
  2034. setjmp(J)    /* store environment info in J; return {int} 0 */
  2035. longjmp(J,n)    /* {void} go to the setjmp(J) call where the environment info
  2036.         in J was stored; go out of the end of that call, returning n */
  2037.  
  2038. ======================================== SFILE.H
  2039. [STRUCTURED BINARY INPUT/OUTPUT]
  2040. #include <_File.h>, which see
  2041.  
  2042. int i,j,k; char *s,*t; FILE *F; void *p;
  2043. SFile S;    /* declare S to hold info to use a file as structured binary */
  2044.         /* It has a hidden member int sz = unit size */
  2045.         /* It includes and can be used as a File, and also:- */
  2046. SFile(s,k,i,j)    /* new {SFile} with filename s, io_mode i, access_mode j,
  2047.             its .sz member = k */
  2048. SFile(s,k,t)    /* ditto but with old-style C fopen() mode t */
  2049. SFile(j,k,i)    /* new {SFile} with file number j, .sz member = k, io_mode i */
  2050. SFile(F,k)    /* new {SFile) using old-style C FILE F, .sz member = k */
  2051. S.size()    /* {int} S.sz */
  2052. S.setsize(int s)    /* S.sz = i; return {int} = previous S.sz */
  2053. S.get(p)    /* read  S.sz bytes into *p etseq; return {SFile} S */
  2054. S.put(p)    /* write S.sz bytes from *p etseq; return {SFile} S */
  2055. S[i]        /* set file to i*S.sz bytes from its start; return {SFile} S */
  2056.  
  2057. ======================================== SIGNAL.H
  2058. [SIGNALS]
  2059.  
  2060. /* I can't find what these functions do */
  2061. typedef void (*SignalHandler) ();
  2062. extern SignalHandler signal(int sig, SignalHandler action);
  2063. extern SignalHandler sigset(int sig, SignalHandler action);
  2064. extern SignalHandler ssignal(int sig, SignalHandler action);
  2065. extern int           gsignal (int sig);
  2066. extern int           kill (int pid, int sig);
  2067. #ifndef hpux /* Interviews folks claim that hpux doesn't like these */
  2068. struct sigvec;
  2069. extern int           sigsetmask(int mask);
  2070. extern int           sigblock(int mask);
  2071. extern int           sigpause(int mask);
  2072. extern int           sigvec(int sig, struct sigvec* v, struct sigvec* prev);
  2073. #endif
  2074. #define SignalBad ((SignalHandler)-1)
  2075. #define SignalDefault ((SignalHandler)0)
  2076. #define SignalIgnore ((SignalHandler)1)
  2077.  
  2078. ======================================== SMPLHIST.H
  2079. [SAMPLE HISTOGRAMS]
  2080.  
  2081. int i; double x,y,w; ostream G;
  2082.         /* buckets = subdivisions of the range */
  2083. S.buckets()        /* {int} = how many buckets */
  2084. S.bucketThreshold(i)    /* {double} = lower boundary of ith bucket */
  2085. S.inBucket(i)    /* {int} = how many items in bucket i (numbered from 0) */
  2086. SampleHistogram(x,y,w)    /* a new empty {SampleHistogram} with limits x to y,
  2087.                 width of each bucket = w */
  2088. SampleHistogram(x,y,-1.0)    /* ditto, with 10 buckets */
  2089. SampleHistogram(x,y)        /* ditto */
  2090. S += x            /* {void} add x to the appropriate bucket */
  2091. S.similarSamples(x)    /* {int} = how many samples in same bucket as x */
  2092. S.printBuckets(G)    /* {void} print what is in each bucket */
  2093. S.reset()        /* {void} rezero everything in S */
  2094.  
  2095. ======================================== SMPLSTAT.H
  2096. [SAMPLE STATISTICS]
  2097.  
  2098. char *s; int i,n; double x;
  2099. SampleStatistic S;    /* declare S to hold a sample statistic */
  2100.     /* It has these hidden fields:- int n; double x,x2,minValue,maxValue; */
  2101.  
  2102. SampleStatistic()    /* a new {SampleStatistic} whic has been reset */
  2103. S.samples()    /* {int} S.n */
  2104. S.min()        /* {double} S.minValue */
  2105. S.max()        /* {double} S.maxValue */
  2106. S.error(s)    /* {void} error message s */
  2107. S.reset()    /* {void} re-initialize everything in S */
  2108. S += x        /* {void} S.n+=1; S.x+=x; S.x2+=x*x;
  2109.     if(minValue>value) minValue=value; if(maxValue<value) maxValue=value; */
  2110. S.mean()    /* {double} = if S.n>0 then S.x/S.n else 0 */
  2111. S.var()        /* {double} = if n>1 then x2-(x*x/n)/(n-1) else 0 */
  2112. S.stdDev()    /* {double} sqrt(S.var())  (0 if n<=1 or S.var()<=0) */
  2113. S.confidence(i)    /* {double} = S.confidence(i * 0.01) */
  2114. S.confidence(x)    /* {double} = tval((1+x)/2,S,n-1) * S.stdDev() / sqrt(S.n+.0) */
  2115. /* on some systems this function is not directly callable:- */
  2116. tval(x,n)  /* {double} = t-distribution, if p-value = x, n degrees of freedom */
  2117.  
  2118. ======================================== STD.H
  2119. [MISCELLANEOUS]
  2120.  
  2121. "###" = "I can't find what this function does; its source is in assembler".
  2122. "<missing>" = "I can't find what this function does; it may not exist on PC.".
  2123.    Some of these missing functions seem to be only for multi-user systems.
  2124. /* "->" = "points to" */
  2125.  
  2126. char *s,*t,*u; int i,j,k,l,m,n; unsigned I,J; unsigned long L,M; void *p,*q;
  2127. short S; double x;
  2128.  
  2129. _exit(i)    /* {void} exit without flushing file buffers.
  2130.         send value of i to MS-DOS as 'error mode' */
  2131. abort()        /* {void} print error message; _exit(3); */
  2132. abs(i)        /* {int} absolute value of i */
  2133. access(s, 0)    /* {boolean} if file named s exists */
  2134. access(s, 2)    /* {boolean} if file named s exists and can be written to */
  2135. access(s, 4)    /* {boolean} if file named s exists and can be read from */
  2136. access(s, 6)    /* {boolean} if file named s exists and can be written & read */
  2137. acct(s)        /* {int} ### */
  2138. alarm(I)    /* {unsigned} ### */
  2139. atof(s)        /* string s read as a {double}. Illegal char ends number */
  2140. atoi(s)        /* string s read as an {int} */
  2141. atol(s)        /* string s read as a {long int} */
  2142. bind(i, p, j)    /* {int} ### */
  2143. brk(p)        /* set program's data segment to end at last byte before address
  2144.         p. {int} 0 for OK, -1 for "I can't do it". Best use sbrk() */
  2145. bsearch(p,q,L,M,c)    /* q -> sorted array of L elements of M bytes each.
  2146.         p -> a pattern in same format as one element of array p.
  2147.         c(P,Q) is some function returning {int} <0 or 0 or >0 as whether
  2148.         P should be to left of, or same as, or to right of, Q, if P & Q
  2149.         are in format of elements of array at p. bsearch returns {void*}
  2150.         -> first occurence of *q in array p (NULL if not found) */
  2151. bcmp(p,q,j)    /* {int} same as memcmp */
  2152. bcopy(p,q,j)    /* {void} same as memcpy */
  2153. _bcopy(p,q,i)    /* {void} same as bcopy, but doesn't use movsb */
  2154. bzero(p,i)    /* {void} write 0 into i bytes at p etseq */
  2155. calloc(I, J)    /* {void*} as malloc(I * J) */
  2156. cfree(p)    /* {void} as free(p) */
  2157. chdir(s)    /* change current directory to s. {int} 0 = OK, -1 = failed */
  2158. chmod(s, 0)    /* set file named s to read only. {int} 0 = OK, -1 = failed */
  2159. chmod(s, 1)    /* set file named s to write only. {int} 0 = OK, -1 = failed */
  2160. chmod(s, 2)    /* ditto, since MS-DOS can't set files write-only */
  2161. chown(s, i, j)    /* {int} ### */
  2162. clock()        /* {long} time in ticks used by this process (-1 = can't find)*/
  2163. close(i)    /* close file numbered i. {int} 0 = OK, -1 = failed */
  2164. creat(s, L)    /* if file named s exists, truncate it here, else create it.
  2165.         Then as chmod(s,L); {int} 0 = OK, -1 = failed */
  2166. crypt(s, t)    /* {char*} <missing> */
  2167. ctermid(s)    /* {char*} <missing> */
  2168. cuserid(s)    /* {char*} <missing> */
  2169. drand48()    /* {double} <missing> */
  2170. dup(i)        /* {int} ### */
  2171. dup2(i,j)    /* {int} ### */
  2172. dysize(i)    /* {int} <missing> (size of directory?? */
  2173. ecvt(x,i,&j,&k)    /* {char*} x printed as i digits in system area. After call, jth
  2174.         char is '.', kth char is sign. Next call of ecvt overwrites */
  2175. encrypt(s, i)    /* {char*} <missing> */
  2176. erand(&S)    /* {double} <missing> */
  2177.     /* 'xxx' is one or more char* args, followed by a NULL pointer arg */
  2178.     char **a; /* points to array of arguments. NULL after pointer to last */
  2179.     char **e; /* points to array of environment strings, each is in format
  2180.         'NAME=value'. NULL after pointer to last of these strings */
  2181. execl(s,xxx)    /* {int} stop this program; call program named s with arguments
  2182.         listed in xxx. This is a "child process". The current process is
  2183.         destroyed and can't be returned to. */
  2184. execle(s,xxx,e)    /* {int} ditto, with environment strings e */
  2185. execlp(s,xxx)    /* {int} as execl(), but use environment variable PATH to find
  2186.         directory to lookin for s, as specified in COMMAND.COM */
  2187. exect(s,&t,&u)    /* {int} <missing> */
  2188. execv(s,a)    /* {int} as execl(), but the args of s are the elements of a */
  2189. execve(s,a,e)    /* {int} as execle(), but the args of s are the elements of a */
  2190. execvp(s,a)    /* {int} as execlp(), but the args of s are the elements of a */
  2191. exit(i)        /* {void} flush file buffers; close files; exit from program */
  2192. fchmod(i,j)    /* {int} print "not implemented" & return.
  2193.         (should be as chmod() but with file numbered i ?) */
  2194. fchown(i,j,k)    /* {int} as chown() but with file numbered i ? */
  2195. fcntl(i,j,...)    /* {int} <missing> */
  2196. fcvt(x,i,&j,&k)    /* {char*} as ecvt() */
  2197. ffs(i)        /* {int} <missing> */
  2198. flock(i,j)    /* {int} <missing> (lock file numbered i?) */
  2199. fork()        /* {int} <missing> */
  2200. free(p)        /* {void} release the malloc'ed area p. See MALLOC.H */
  2201. fsync(i)    /* {int} ### */
  2202. ftok(s,i)    /* {long} <missing> */
  2203. ftruncate(i,I)    /* {int} fseek(i,I,0); write(i,0,0); if file i is then closed
  2204.         at once, it is truncated there */
  2205. gcvt(x,i,s)    /* {char*} <missing> */
  2206. getcwd(s,i)    /* put current directory name in s. i = how many chars
  2207.             in s can be used. Returns {char*} = s (NULL if error) */
  2208. getcwd(NULL,i)    /* put current directory name in an area which getcwd() provides
  2209.         by malloc() and returns {char*} = its address (NULL if error) */
  2210. getdomainname(s,i)    /* {int} <missing> */
  2211. getdtablesize()    /* {int} = 50 (= how many files can be open at once ??) */
  2212. getegid()    /* {int} <missing> */
  2213. getenv(s)    /* {char*} <missing> */
  2214. geteuid()    /* {int} <missing> */
  2215. getgid()    /* {int} <missing> */
  2216. getgroups(i,&j)    /* {int} <missing> */
  2217. gethostid()    /* {long} <missing> */
  2218. gethostname(s,i)    /* {int} <missing> */
  2219. getlogin()    /* {char*} <missing> */
  2220. getopt(i,&s,t)    /* {int} <missing> */
  2221. getpagesize()    /* {int} <missing> */
  2222. getpass(s)    /* {char*} <missing> */
  2223. getpgrp()    /* {int} <missing> */
  2224. getpid()    /* {int} = 42 */
  2225. getppid()    /* {int} <missing> */
  2226. getpriority(i,j)    /* {int} <missing> */
  2227. getpw(i,s)    /* {int} <missing> */
  2228. getuid()    /* {unsigned} <missing> */
  2229. getwd(s)    /* {char*} ### */
  2230. index(s,i)    /* {char*} same as strchr */
  2231. initstate(I,s,i)    /* {char*}
  2232. ioctl(i,j,s)    /* {int} <missing> */
  2233. isatty(i)    /* {boolean} if file numbered i is console/screen/serial port */
  2234. jrand48(&S)    /* {long} <missing> */
  2235. kill(i,j)    /* {int} <missing> */
  2236. killpg(i,j)    /* {int} <missing> */
  2237. lcong48(&S)    /* {void} <missing> */
  2238. link(s,t)    /* {int} ### */
  2239. listen(i,j)    /* {int} <missing> */
  2240. lrand48()    /* {long} <missing> */
  2241. lseek(i,I,j)    /* {long} ### (look for something in file numbered i ??) */
  2242. malloc(I)    /* {void*} provide new space of I bytes, see MALLOC.H */
  2243. malloc_usable_size(p)    /* {unsigned int} <missing> */
  2244.  
  2245.     /* mem-- functions may not work OK if source and destination overlap */
  2246. memalign(I,J)    /* {void*}
  2247. memccpy(p,q,i,j)/* copy i bytes from q etseq to p etseq; returns {void*} NULL;
  2248.         but if it meets a char == j, it copies that char & exits,
  2249.         returning {void*} -> place in array p next after that char */
  2250. memchr(p,i,j)    /* look at i chars starting at p for char == j. If found,
  2251.         returns {void*} pointer to it; else returns {void*} NULL */
  2252. memcmp(p,q,i)    /* {int} as strncmp(p,q,i), but don't stop at null chars */
  2253. memcpy(p,q,i)    /* copy i bytes from q etseq to p etseq; returns {void*} p */
  2254. _memcpy(p,q,i)    /* {void*} ditto, but don't use movsb */
  2255. memset(p,i,j)    /* set i bytes starting at p, to j; return {void*} = p */
  2256.  
  2257. mkdir(s,i)    /* {int} make directory named s. Use of i not known */
  2258. mknod(s,i,j)    /* {int} <missing> */
  2259. mkstemp(s)    /* {int} <missing> */
  2260. mktemp(s)    /* s must be 1 to 6 chars followed by 6 uppercase X's. Returns
  2261.         {char*} unique new filename with XXXXXX replaced by 2 chars,
  2262.         then '.', then 3 chars */
  2263. mrand48()    /* {long} <missing> */
  2264. nice(i)        /* {int} <missing> */
  2265. nrand48(&S)    /* {long} <missing> */
  2266. open(s,i)    /* open file named s, in mode i as in FCNTL.H . Returns {int}
  2267.         = file number (-1 if error) */
  2268. open(s,i,j)    /* ditto, for read only if j==0, for write also if j == 1 or 2*/
  2269. pause()        /* {void} <missing> */
  2270. perror(s)    /* {void} <missing> */
  2271. pipe(&i)    /* {int} <missing> */
  2272. profil(s,i,j,k)    /* {int} <missing> */
  2273. psignal(I,s)    /* {int} <missing> */
  2274. ptrace(i,j,k,l)    /* {int} <missing> */
  2275. putenv(s)    /* {int} <missing> */
  2276. qsort(p,i,I,c)    /* {void} p -> array of i elements of I bytes each.
  2277.         Sort array p according to function c, for which see bsearch() */
  2278. rand()        /* {int} <missing> (random integer 0 to 32767?) */
  2279. random()    /* {long int} <missing> (random integer 0 to pow(2,31-1)??) */
  2280. read(i,p,I)    /* on file numbered i, read I bytes to p etseq. Returns {int}
  2281.         = how many bytes actually read (-1 if error).
  2282.         If file was opened in text mode, CR LF is replaced by '\n'.
  2283.         Ctrl-Z is treated as end of file.
  2284.         (Negative value may mean 'that value + pow(2,16)) */
  2285. readlink(s,t,i)    /* {int} <missing> */
  2286. realloc(p,I)    /* {void*} see MALLOC.H */
  2287. rename(s,t)    /* rename file s as t; return {int} 0 = OK, -1 = error */
  2288. rindex(s,i)    /* {char*} same as strrchr */
  2289. rmdir(s)    /* remove directory s; return {int} 0 = OK, -1 = error */
  2290. sbrk(i)        /* add (-ve = remove) i bytes to top end of program's data area.
  2291.         Returns {void*} -> first of those new bytes */
  2292. seed48(short*)    /* {short*} <missing> (ref random numbers?) */
  2293. send(i,s,j,k)    /* {int} <missing> */
  2294.  
  2295. setgid(i)    /* {int} <missing> */
  2296. sethostname(s,i)    /* {int} <missing> */
  2297. setkey(s)    /* {int} <missing> */
  2298. setpgrp()    /* {int} <missing> */
  2299. setpriority(i,j,k)    /* {int} <missing> */
  2300. setregid(i,j)    /* {int} <missing> */
  2301. setreuid(i,j)    /* {int} <missing> */
  2302. setstate(s)    /* {char*} <missing> */
  2303. setuid(i)    /* {int} <missing> */
  2304.  
  2305. sigblock(i)    /* {int} <missing> */
  2306. siginterrupt(i,j)    /* {int} <missing> */
  2307. sigpause(i)    /* {int} <missing> */
  2308. sigsetmask(i)    /* {int} <missing> */
  2309.  
  2310. sleep(I)    /* {unsigned} wait I seconds */
  2311. socket(i,j,k)    /* {int} <missing> */
  2312. srand(i)    /* {void} <missing> */
  2313. srand48(I)    /* {void} <missing> */
  2314. srandom(i)    /* {void} <missing> */
  2315. stime(&I)    /* set system time to I seconds after midnight GMT at start of
  2316.         1 Jan 1970; returns {int} 0 */
  2317.  
  2318.     /* String functions. Strings terminated by zero char if not earlier by
  2319.     count. Return {char*} = s unless stated otherwise. s,t,u are strings */
  2320. strcat(s,t)    /* {char*} append t to s, in space after s in store */
  2321. strchr(s,i)    /* {char*} -> first char which == i in s (NULL if not found) */
  2322. strcmp(s,t)    /* {int} <0 or 0 or >0 as s is before / same as / after t in
  2323.             character order (case sensitive) */
  2324. strcpy(s,t)    /* {char*} copy t into s
  2325. strcspn(s,t)    /* {int} = index in s of first char matching any char in t
  2326.             (strlen(s) if none found) */
  2327. strdup(s)    /* {char*} -> a new malloc'ed copy of string s */
  2328. strlen(s)    /* {int} = how many chars in s (except terminating null) */
  2329. strncat(s,t,i)    /* {char*} append to s the first i chars in t */
  2330. strncmp(s,t,i)    /* {int} as strcmp() but first i chars only */
  2331. strncpy(s,t,i)    /* {char*} j=strlen(t); overwrite first i chars in s with first
  2332.         i chars in t; if j>i append j-i nulls, else append NO nulls */
  2333. strpbrk(s,t)    /* {char*} -> first char matching any char in t
  2334.             (NULL if none found) */
  2335. strrchr(s,i)    /* {char*} -> last char in s which == i {NULL if not found) */
  2336. strspn(s,t)    /* {int} = index in s of first char not matching any char in t
  2337.             (strlen(s) if none found) */
  2338. strtod(s,&t)    /* {double} <missing> */
  2339. strtok(s,t)    /* replace by 0 any leading chars in s that match any char in t,
  2340.         and the first such char found after the first nonmatching char.
  2341.         Return {char*} -> first nonmatching char in s */
  2342. strtok(NULL,t)    /* as ditto, using s from previous call, and starting search not
  2343.         at start of s but at last matching char found before */
  2344. strtol(s,&t,i)    /* {long} <missing> */
  2345.  
  2346. swab(p,q,i)    /* {void} swop i bytes at p etseq with i bytes at q etseq */
  2347. symlink(s,t)    /* {int} <missing> */
  2348. syscall(i,...)    /* {int} <missing> */
  2349. system(s)    /* call the MSDOS command s. Return {int} 0 = OK, -1 = failed */
  2350. system(NULL)    /* {boolean} if COMMAND.COM can be found */
  2351. tempnam(s,t)    /* {char*} <missing> */
  2352. tgetent(s,t)    /* {int} <missing> */
  2353. tgetnum(s)    /* {int} <missing> */
  2354. tgetflag(s)    /* {int} <missing> */
  2355. tgetstr(s,&t)    /* {char*} <missing> */
  2356. tgoto(s,i,j)    /* {char*} <missing> */
  2357. time(&L)    /* {unsigned long}
  2358. tmpnam(s)    /* put unique temporary file name in s; return {char*} = s */
  2359. tmpnam(NULL)    /* ditto, but return it in a new malloc'ed string */
  2360. tputs(s,i,int (*)())    /* {int} <missing> */
  2361. truncate(s,L)    /* {int} truncate file named s after L btHytes; close it */
  2362. ttyname(i)    /* {char*} <missing> ('filename' given to keyboard?) */
  2363. ttyslot()    /* {int} <missing> ('file number' given to keyboard?) */
  2364. ualarm(I,J)    /* {unsigned} <missing> */
  2365. ulimit(i,long)    /* {long} <missing> */
  2366. umask(i)    /* {int} from now on, open files as specified by i as the
  2367.         S_-- constants in SYS\TYPES.H */
  2368. unlink(s)    /* {int} <<delete file named s>> */
  2369. usleep(I)    /* {unsigned} sleep I microseconds */
  2370. vadvise(i)    /* {int} <missing> */
  2371. valloc(I)    /* {void*} as malloc() ? */
  2372. vfork()        /* {int} <missing> */
  2373. vhangup()    /* {int} <missing> */
  2374. wait(&i)    /* {int} <missing> */
  2375. write(i,p,I)    /* on file numbered i, write I bytes from p etseq. Returns {int}
  2376.         = how many bytes actually written (-1 if error).
  2377.         If file was opened in text mode, '\n' is replaced by CR LF.
  2378.         Ctrl-Z is treated as end of file.
  2379.         (Negative value may mean 'that value + pow(2,16)) */
  2380.  
  2381.     /* STD.H also declares these external globals:- */
  2382. extern char**    environ;
  2383. extern volatile int errno;    /* for system error number */
  2384. extern char*    sys_errlist[];
  2385. extern int    sys_nerr;    
  2386. extern char*    optarg;
  2387. extern int    opterr;
  2388. extern int    optind;
  2389.  
  2390. ======================================== STDARG.H
  2391. /* declarations used in argument list processing */
  2392.  
  2393. ======================================== STDDEF.H
  2394. /* oddments used by input/output functions, and:- */
  2395. #define NULL 0
  2396.  
  2397. ======================================== STDIO.H
  2398. [OLD-STYLE C INPUT AND OUTPUT]
  2399.  
  2400. FILE *F;    /* declare F as a pointer to a structure which holds the details
  2401.         of interface with a file */
  2402. /* the FILE structures themselves are set up by the system as an array _iob */
  2403.  
  2404. #define EOF       (-1)
  2405. #define NULL      0
  2406. #define stdin     (&_iob[0])    /* standard input, usually the keyboard */
  2407. #define stdout    (&_iob[1])    /* standard output, usually the screen */
  2408. #define stderr    (&_iob[2])    /* standard error output, usually the screen */
  2409.  
  2410. long int I; int i,j,k; char c,*s,*t,*f; void* p;
  2411.     /* These 8 'functions' are macros:- */
  2412. getc(F)        /* {int} get a character from file F */
  2413. putc(i,F)    /* put a character = i to file F; return {int} the character */
  2414. clearerr(F)    /* clear F's end of file & error flags */
  2415. getchar()    /* same as getc(stdin) */
  2416. putchar(i)    /* same as putc(i,stdout) */
  2417. feof(F)        /* {boolean} if F's end of file flag is set */
  2418. ferror(F)    /* {boolean} if F's error flag is set */
  2419. fileno(F)    /* {int} F's file number */
  2420.  
  2421.     /* Hereinunder:-
  2422.     argument F = file read from or written to;
  2423.     argument t = access mode:-
  2424.         "r"  = read, file must exist.
  2425.         "w"  = write, file is wiped if it existed before.
  2426.         "a"  = append, file is created if it doesn't exist.
  2427.         "r+" = read and write, file must exist.
  2428.         "w+" = read and write, file is wiped if it existed before.
  2429.         "a+" = read and append, file is created if it doesn't exist.
  2430. fclose(F)    /* {int} close file F */
  2431. fdopen(i,t)    /* {FILE*} = file numbered i opened in mode t */
  2432. fflush(F)    /* empty file F's buffer. If writing, write it.
  2433.             Returns {int}  0 = OK, else EOF */
  2434. fgets(s,i,F)    /* read up to & including next '\n', but not more than i chars.
  2435.         Returns {char*} = s (NULL if error) */
  2436. fopen(s,t)    /* {FILE*} = file named s opened in mode t */
  2437. fprintf(F,f,...)    /* print by format f.
  2438.             Returns {int} = how many chars printed */
  2439. fputs(s,F)    /* print string s. {int} = last char printed (EOF if error) */
  2440. fread(p,i,j,F)    /* read j items each i bytes long.
  2441.             Returns {int} = how many items read */
  2442. freopen(s,t,F)    /* close file F and reopen it as file named s in mode t. Returns
  2443.         {FILE*} F. (stdin & stdout & stderr can be diverted thus) */
  2444. fscanf(F,f,...)    /* formatted input by format f.
  2445.         Returns {int} = how many items read (EOF if hit end of file) */
  2446. fseek(F,I,0)    /* {int} go to Ith byte in file */
  2447. fseek(F,I,1)    /* {int} move I bytes forward in file */
  2448. fseek(F,I,2)    /* {int} go to Ith byte after (-ve = before) end of file */
  2449. ftell(F)    /* {long} = position in bytes from start of file.
  2450.          (in text mode, CR LF is counted as one char) */
  2451. fwrite(p,i,j,F)    /* write j items each i bytes long.
  2452.             Returns {int}  = how many items read */
  2453. gets(s)        /* read into s a line from stdin, lose the final '\n'.
  2454.             Returns {char*} s (NULL if error) */
  2455. getw(F)        /* {int} = two bytes read from F */
  2456. pclose(F)    /* {int} <missing> */
  2457. popen(s,t)    /* {FILE*} <missing> */
  2458. printf(s,...)    /* formatted write to stdout. {int} as fprint() */
  2459. puts(s)        /* print string s, and a '\n', to stdout.
  2460.             Returns {int} last char written (EOF if error) */
  2461. putw(i,F)    /* write i as 2 bytes {int}
  2462. rewind(F)    /* put pointer to start of file. {int}
  2463. scanf(f,...)    /* formatted read from stdin. {int} as fscanf() */
  2464. setbuf(F,s)    /* {int} set F's buffer to be s, BUFSIZ bytes long */
  2465. setbuf(F,NULL)    /* {int} set F to be unbuffered */
  2466. setbuffer(F,s,i)    /* {int} ditto, i bytes long */
  2467. setlinebuf(F)        /* {int} <missing> */
  2468. setvbuf(F,t,_IOFBF,i)    /* {int} as setbuffer, buffer filled on reading to it */
  2469. setvbuf(F,t,_IOLBF,i)    /* {int} ditto but read to buffer stops at '\n' */
  2470. setvbuf(F,t,_IOFBF,i)    /* {int} unbuffered */
  2471. sprintf(s,f,...)    /* {int} formatted write to string */
  2472. sscanf(s,f,...)        /* {int} formatted read from string */
  2473. tmpfile()        /* open and return {FILE*} = a temporary file */
  2474. ungetc(i,F)    /* put char i into F's buffer. {int} = i (EOF if error) */
  2475. vfprintf(F,f,p)        /* {int} like fprintf but p -> list of arguments */
  2476. vprintf(f,p )        /* {int} as vfprintf(stdout,f,p) */
  2477. vsprintf(s,f,p)        /* {int} like sprintf but p -> list of arguments */
  2478.  
  2479. #define L_ctermid    9
  2480. #define L_cuserid    9
  2481. #define    P_tmpdir    "/tmp/"
  2482. #define    L_tmpnam    (sizeof(P_tmpdir) + 15)
  2483.  
  2484. ======================================== STDLIB.H
  2485. #include <std.h>
  2486. #define RAND_MAX 65536
  2487. typedef struct {int quot; int rem; } div_t;
  2488. typedef struct {long quot;long rem;} ldiv_t;
  2489.  
  2490. ======================================== STRCLASS.H
  2491. #include <_String.h>, which see.
  2492. typedef class String string;
  2493.  
  2494. ======================================== STREAM.H
  2495. #include <ostream.h>, which see
  2496. #include <istream.h>, which see
  2497.  
  2498. ======================================== STREAMBU.H
  2499. [A WAY OF ACCESSING FILES]
  2500.  
  2501. int i,j; char c,*s,*n;
  2502. streambuf b;    /* open b as a table relating to a way of accessing files */
  2503.     /* It has these accessible members:-
  2504.     char*       base;          start of buffer
  2505.     char*       pptr;          put-pointer (and gptr fence)
  2506.     char*       gptr;          get-pointer
  2507.     char*       eptr;          last valid addr in buffer
  2508.     char        alloc;         true if it owns freestore alloced buffer */
  2509. b.must_overflow(c)    /* {boolean} if put-pointer off end of buffer */
  2510.         /* on some systems also true if c == '\n' */
  2511. b.allocate()    /* {int} if base!=0 then 0 else b.doallocate() */
  2512.     /* the next 2 functions return chars as (int)(unsigned char) :- */
  2513.     /* Some of these functions return EOF if get-pointer or put-pointer
  2514.     are out of the buffer, or if he tries to write EOF to the buffer,
  2515.     or if put-pointer >= get-pointer */
  2516. b.sgetc()    /* {int} = char that get-pointer pointing at */
  2517. b,snextc()    /* add 1 to get-pointer, then as ditto */
  2518. b.stossc()    /* if get-pointer is in range, add 1 to get-pointer */
  2519. b.putbackc(i)    /* move get-pointer back 1; put i there as char; return {int} c.
  2520.         Returns EOF if that would push get-pointer out of the buffer */
  2521. b.sputc(i)    /* put i as char at put-pointer; add 1 to put-pointer;
  2522.         return {int} c */
  2523. b.sputc()    /* b.sputc(EOF); return {int} EOF */
  2524. streambuf()    /* a new {streambuf} with all internal info = 0 */
  2525. streambuf(s,i)    /* a new {streambuf} using buffer s (length i) */
  2526. b.doallocate()    /* give b a new buffer of standard size (here 1024 bytes);
  2527.         set pointers accordingly; return {int} = size of new buffer */
  2528. b.setbuf(s,i)    /* as setbuf(s,i,0) */
  2529. b.setbuf(s,i,j)    /* set string s to be b's buffer (length i); put-pointer =
  2530.         address of buffer's jth char; return {streambuf} b */
  2531. b.name()    /* {char*} NULL */
  2532. b.overflow()    /* {int} EOF */
  2533. b.overflow(EOF)    /* {int} EOF */
  2534. b.overflow(i)    /* as p.sputc, but return EOF if i==EOF or if bad pointers */
  2535. b.underflow()    /* {int} EOF */
  2536. b.sputs(s)    /* b.sputs(each char of s in turn);
  2537.          return {int} EOF if string won't fit in buffer, else 0 */
  2538. b.sputsn(s,i)    /* ditto for first i chars of s.
  2539.         No check for zero char in s! */
  2540. b.is_open()    /* {int) 1 */
  2541. b.close()    /* do nothing; {int} 1 */
  2542. b.error()    /* abort() */
  2543.  
  2544. ======================================== STRING.H
  2545. #include <std.h>, which see
  2546.  
  2547. ======================================== STRINGS.H
  2548. #include <string.h>, which see
  2549.  
  2550. ======================================== SWAP.H
  2551. #define swap(a,b) ({ typeof(a) temp = (a); (a) = (b); (b) = temp; })
  2552.  
  2553. ======================================== SYS\DIR.H
  2554. #include <dirent.h>, which see
  2555.  
  2556. ======================================== SYS\DIRENT.H
  2557. /* #include'd by DIRENT.H, which see */
  2558.  
  2559. ======================================== SYS\FCNTL.H
  2560. #include <fcntl.h>, which see
  2561.  
  2562. ======================================== SYS\FILE.H
  2563. #include <fcntl.h>, which see
  2564. #define L_SET  0
  2565. #define L_CURR 1
  2566. #define L_XTND 2
  2567.  
  2568. ======================================== SYS\PARAM.H
  2569. #define MAXPATHLEN 80
  2570.  
  2571. ======================================== SYS\REGISTER.H
  2572. typedef struct {unsigned ax, bx, cx, dx, si, di, bp, f;    } REGISTERS;
  2573.  
  2574. ======================================== SYS\RESOURCE.H
  2575. /* #include'd by OSFCN.H, which see */
  2576.  
  2577. ======================================== SYS\SIGNAL.H
  2578. #define SIG_DFL ((void (*)(int))(-1))
  2579. #define SIG_IGN ((void (*)(int))(-2))
  2580. typedef enum {SIGINT, SIGKILL, SIGPIPE, SIGFPE, SIGHUP, SIGTERM, SIGSEGV,
  2581.     SIGTSTP, SIGQUIT} SIGnals;
  2582.  
  2583. ======================================== SYS\STAT.H
  2584. [USED BY SOME READ/WRITE FUNCTIONS]
  2585. struct    stat {
  2586.     short st_dev, st_ino;
  2587.     unsigned short st_mode;
  2588.     short st_nlink, st_uid, st_gid, st_rdev, st_align_for_word32;
  2589.     long  st_size,  st_atime,  st_mtime,  st_ctime,  st_blksize; };
  2590.  
  2591. #define S_IFMT    0xF000    /* file type mask */
  2592. #define S_IFDIR    0x4000    /* directory */
  2593. #define S_IFIFO    0x1000    /* FIFO special */
  2594. #define S_IFCHR    0x2000    /* character special */
  2595. #define S_IFBLK    0x3000    /* block special */
  2596. #define S_IFREG    0x8000    /* or just 0x0000, regular */
  2597. #define S_IREAD    0x0100    /* owner may read */
  2598. #define S_IWRITE 0x0080    /* owner may write */
  2599. #define S_IEXEC    0x0040    /* owner may execute <directory search> */
  2600.  
  2601. int stat(const char *, struct stat *);
  2602. int fstat(int, struct stat *);
  2603.  
  2604. ======================================== SYS\STDC.H
  2605. #include <sys/types.h>, which see
  2606.  
  2607. ======================================== SYS\TIME.H
  2608. struct timeval {long tv_sec;  long tv_usec; };
  2609. struct timezone {  int tz_minuteswest;  int tz_dsttime; };
  2610.  
  2611. ======================================== SYS\TIMES.H
  2612. struct tms {long tms_utime, tms_utime2, tms_stime, tms_stime2; };
  2613. #define HZ 100
  2614.  
  2615. ======================================== SYS\TYPES.H
  2616. /* special names for some simple types, used by some library routines */
  2617.  
  2618. ======================================== SYS\UIO.H
  2619. struct iovec {void *iov_base; unsigned long iov_len; };
  2620.  
  2621. ======================================== TIME.H
  2622. [TIME]
  2623.  
  2624. struct tm {
  2625.     int    tm_sec;        /* seconds after the minute [0-60] */
  2626.     int    tm_min;        /* minutes after the hour [0-59] */
  2627.     int    tm_hour;    /* hours since midnight [0-23] */
  2628.     int    tm_mday;    /* day of the month [1-31] */
  2629.     int    tm_mon;        /* months since January [0-11] */
  2630.     int    tm_year;    /* years since 1900 */
  2631.     int    tm_wday;    /* days since Sunday [0-6] */
  2632.     int    tm_yday;    /* days since January 1 [0-365] */
  2633.     int    tm_isdst;    /* Daylight Savings Time flag */
  2634.     long    tm_gmtoff;    /* offset from CUT in seconds */
  2635.     char    *tm_zone;    /* timezone abbreviation */ };
  2636.  
  2637. int i,j; struct tm T;
  2638. unsigned long int I,J; /* time in seconds since start of yeat 1970 */
  2639.     /* The next 2 functions return in same place, & next call overwrites,
  2640.     so take a copy at once; and they don't understand years < 1980 */
  2641. localtime(&I)    /* {struct tm *} address of I converted to struct tm */
  2642. gmtime(&I)    /* {struct tm *} ditto corrected to GMT */
  2643. mktime(&T)    /* {unsigned long} T as seconds since start of 1970 ?? */
  2644. time(&I)    /* {unsigned long} seconds since start of year 1970 */
  2645. difftime(I,J)    /* {double} J - I */
  2646.     /* The next 3 functions return in same place, & next call overwrites,
  2647.     so take at once a copy of the result */
  2648. asctime(&T)    /* {char *} T as string, e.g. "Thu Nov 26 17:02:37 1987\n" */
  2649. ctime(&I)    /* {char *} I as string, e.g. "Thu Nov 26 17:02:37 1987\n" */
  2650. timezone(i,j)    /* {char *} <missing> */
  2651. tzset()        /* {void} set time zone info from environment variable TZ */
  2652. tzsetwall()    /* {void} <missing> */
  2653.  
  2654. ======================================== TZFILE.H
  2655. (1) "Information about time zone files", but I can't find these files in my
  2656.     copy of Gnu C.
  2657.  
  2658. (2) Defines these constants:-
  2659. TM_SUNDAY    0  TM_MONDAY    1  TM_TUESDAY    2  TM_WEDNESDAY    3
  2660. TM_THURSDAY    4  TM_FRIDAY    5  TM_SATURDAY    6
  2661. TM_JANUARY    0  TM_FEBRUARY    1  TM_MARCH    2  TM_APRIL    3
  2662. TM_MAY        4  TM_JUNE    5  TM_JULY    6  TM_AUGUST    7
  2663. TM_SEPTEMBER    8  TM_OCTOBER    9  TM_NOVEMBER    10 TM_DECEMBER    11
  2664.  
  2665. #define isleap(y) (((y) % 4) == 0 && ((y) % 100) != 0 || ((y) % 400) == 0)
  2666.  
  2667. ======================================== UNIFORM.H
  2668. [UNIFORM RANDOM NUMBERS]
  2669.  
  2670. #include <_Random.h>, which see
  2671.  
  2672. double x,y; RND g;
  2673. Uniform u;    /* declare u to hold workings of a running series of uniform
  2674.         random numbers between u.pLow and u.pHigh.
  2675.         u has the hidden members double u.pLow, u.pHigh;
  2676.         u contains and can be used as a Random, and also:- */
  2677.         
  2678. u.low()     /* {double} lower limit of p */
  2679. u.low(x)    /* u's lower limit = x; return {double} previous lower limit */
  2680. u.high()    /* {double} upper limit of p */
  2681. u.high(y)    /* u's upper limit = y; return {double} previous upper limit */
  2682. Uniform(x,y,&g)    /* a new {Uniform} with range x to y, using generator g */
  2683. u()        /* a random {double} uniformly between u's limits */
  2684.  
  2685. ======================================== UNISTD.H
  2686. /* assorted #define'd constants re input and output */
  2687.  
  2688. ======================================== VALUES.H
  2689. /* How many bits per each basic type */
  2690. /* Maximum and minimum values of arithmetic types */
  2691. #define BITSPERBYTE 8
  2692. #define BITS(type)  (BITSPERBYTE * (int)sizeof(type))
  2693.     /* The next two seem accurate for my PC */
  2694. #define MAXDOUBLE   1.79769313486231470e+308
  2695. #define MINDOUBLE   4.94065645841246544e-324
  2696. #define MAXFLOAT    ((float)3.40282346638528860e+38)
  2697. #define MINFLOAT    ((float)1.40129846432481707e-45)
  2698.  
  2699. ======================================== VARARGS.H
  2700. #include <stdarg.h>, which see
  2701.  
  2702. ======================================== WEIBULL.H
  2703. ['WEIBULL' RANDOM NUMBERS]
  2704. #include <_Random.h>, which see
  2705.  
  2706. double x,y; RNG g;
  2707. Weibull w;    /* declare w to hold workings of a running series of that sort
  2708.         of random number */
  2709.         w has two parameters: alpha and beta */
  2710.         w contains and can be used as a Random, and also:- */
  2711. w.alpha()     /* {double} alpha of p */
  2712. w.alpha(x)    /* w's alpha = x; return {double} previous alpha */
  2713. w.beta()    /* {double} beta of p */
  2714. w.beta(y)    /* w's beta = y; return {double} previous beta */
  2715. Weibull(x,y,&g)    /* new {Weibull} with alpha = x, beta = y, using generator g */
  2716. /* See Simulation, Modelling & Analysis by Law & Kelton, pp259 */
  2717. /* This is the 'polar' method */
  2718. w()        /* a {double} expression which seems to simplify to
  2719.         pow(beta, (1/(1-(random number)) + 1/alpha)) */
  2720.         /* '1-random' to stop 1/0 from happening */
  2721.  
  2722. ======================================== _FILE.H
  2723. /* #include'd by FILE.H, which see */
  2724.  
  2725. ======================================== _FILEBUF.H
  2726. [A WAY TO ACCESS FILES]
  2727. #include <_File.h>, which see
  2728. #include <streambuf.h>, which see
  2729.  
  2730. /* Notice the case difference between Filebuf and filebuf */
  2731. char *s,*t; int i,j; FILE *f;
  2732. Filebuf F;    /* declare a file access buffer */
  2733.     /* F includes and can be used as a streambuf, and also:- */
  2734. Filebuf()    /* new {Filebuf} with everything null */
  2735. Filebuf(s,i,j)    /* new {Filebuf} opened with name s, io_mode i, access_mode j */
  2736. Filebuf(s,t)    /* ditto, but t = opening mode as in old C fopen() */
  2737. Filebuf(i,j)    /* new {Filebuf} opened on file numbered i, io_mode j */
  2738. Filebuf(f)    /* new {Filebuf) connected with old-style C FILE *f */
  2739. F.open(s,i,j)    /* open F with name n, io_mode i, access_mode j    (see FMODES.H).
  2740. F.open(s,t)    /* ditto, but t = opening mode as in old C fopen() */
  2741. F.open(s,i)    /* ditto, but (?) i= 0 read only, 1 write only, 2 append only */
  2742. F.open(i,j)    /* open file numbered i, with io_mode j */
  2743. F.open(f)    /* connect F with old-style C FILE *f */
  2744. F.fp        /* {File*} pointer to the File that F uses */
  2745. F.init_streambuf_ptrs() /* {void} initialize F's internal pointers */
  2746. F.is_open()        /* {boolean} F is open */
  2747.     /* all uses of F.open(...) return {streambuf*} = pointer to F's
  2748.      component streambuf */
  2749. F.close()    /* close F; {boolean} = if F was open */
  2750. F.underflow()    /* {int}, diverts F's contained streambuf's "attempt to read
  2751.         from empty buffer" routine to refill the buffer from file.
  2752.     Returns EOF if end of file. Do not call this function yourself. */
  2753. F.overflow()    /* {int}, diverts F's contained streambuf's "attempt to write
  2754.         to full buffer" routine to send buffer contents to file.
  2755.         Do not call this function yourself. */
  2756. F.name()    /* {char*} F's name */
  2757. F.setbuf(s,i,0)    /* set F's buffer to char* s, its length = i */
  2758.  
  2759. ======================================== _OBSTACK.H
  2760. /* #included by source form of functions called by OBSTACK.H, which see */
  2761.  
  2762. ======================================== _RANDOM.H
  2763. #include "RNG.h", which see
  2764.  
  2765. RNG g;
  2766. Random r;    /* declare r to hold workings of a running series of uniform
  2767.         random numbers between 0 and 1 */
  2768.         /* r includes and can be used as a RNG, and also:- */
  2769. Random(&g)    /* a new {Random} using generator g */
  2770. r.generator()    /* {RNG*} a pointer to the RNG that r uses */
  2771. r.generator(&g)    /* set r to use generator g;
  2772.         return {RNG*} a pointer to r's previous generator */
  2773. r()        /* {double} random number between 0 and 1 */
  2774.  
  2775. ======================================== _RANDOMI.H
  2776. /* Seems to be same as RANDOMRA.H,
  2777. except that it has RandomInterval everywhere instead of RandomRange */
  2778.  
  2779. ======================================== _REGEX.H
  2780. /* constants for use when using REGEX.H, which see */
  2781.  
  2782. ======================================== _STRING.H
  2783. [SPECIAL STRING HANDLING]
  2784. #include <_Regex.h>, which see
  2785.  
  2786.     /* <not> the same as an ordinary string which is a char* pointing to
  2787.     characters terminated by a null character! */
  2788. String S,T,U,V;        /* declare S etc to hold strings */
  2789. SubString X,Y,Z;    /* declare X etc to hold info pointing to a substring
  2790.             of a String */
  2791. Regex R;        /* a Regex type expression, see REGEX.H */
  2792. char c,*s,*t; int i,n; istream F; ostream G;
  2793.  
  2794. W    /* this arg can be String or SubString or char* or char*   */
  2795.  
  2796. X.contains(W)    /* {boolean} if W is in X */
  2797. X.contains(R)    /* {boolean} if R is in X */
  2798. X.matches(R)    /* {boolean} if R matches all of X */
  2799. X.length()    /* {int} length of text of X */
  2800. X.empty()    /* {boolean} if X has zero amount of text */
  2801. X.OK()        /* {boolean} if X's internal details are OK */
  2802.  
  2803. String()    /* a new {String} with null text */
  2804. String(s,i)    /* a new {String} containing the first i characters of X */
  2805. /* SubString & char* & char convert automatically to String when necessary,
  2806.         e.g. when cast by (String) or String(..), or on right of = */
  2807. =        /* with a String as left argument: copies, and returns {void} */
  2808.     /* right arg of next 2 can also be SubString or char* or char */
  2809. S += T        /* {void} concatenate T to end of S.
  2810. S.prepend(T)    /* {void} concatenate T to beginning of S.
  2811.     /* In cat(), S and T and U can also be SubString */
  2812.     /* In cat(), S and T can also be char*   */
  2813. cat(T,U,V)    /* {void} set V to T and U concatenated in that order */
  2814. cat(S,T,U,V)    /* {void} set V to S and T and U concatenated in that order */
  2815.     /* in the next 7 functions, W can also be a Regex */
  2816. S.index(W)    /* {int} first index in S of text of W (-1 for 'not found') */
  2817. S.index(W,i)    /* {int} ditto, but ignore first i chars of S */
  2818. S.contains(W)    /* {boolean} if text of W occurs anywhere in S */
  2819. S.contains(W,i)    /* {boolean} ditto, but ignore first i chars of S */
  2820. S.matches(W)    /* {boolean} if text of W occurs at start of S */
  2821. S.matches(W,i)    /* {boolean} if text of W occurs i chars after start of S */
  2822. S.freq(W)    /* {int} how many occurences of W in S */
  2823.  
  2824. G << S        /* {ostream} print text of S */
  2825. G << X        /* {ostream} print text of X */
  2826. F >> S        /* {istream} read S, same way as char*. Error if zero length */
  2827. readline(F,S)    /* read text into S, up to '\n', discard the '\n',
  2828.             return {int} = length of text of S */
  2829. readline(F,S,c)    /* ditto, but terminate at char c instead of '\n' */
  2830. readline(F,S,c,i)    /* ditto, if i != 0 */
  2831. readline(F,S,c,0)    /* ditto, but append the terminator to the text of S */
  2832. S.error(s)    /* {void} error exit with message s */
  2833. S.length()    /* {int} length of text in S */
  2834. S.empty()    /* {boolean} if no text in S */
  2835. S.chars()    /* {char*) text of S */
  2836. S.allocation()    /* {int} how many bytes allocated to S */
  2837. S.alloc(i)    /* {void} allocate i bytes to S? <Don't call this yourself!> */
  2838. reverse(S)    /* {String} = S reversed */
  2839. upcase(S)    /* {String} = S uppercased */
  2840. downcase(S)    /* {String} = S lowercased */
  2841. capitalize(S)    /* {String} = S with all words initial-capitalized */
  2842.     /* In the next two, S can also be a SubString */
  2843. S + W        /* {String} = S and W concatenated */
  2844. s + S        /* {String} = s and S concatenated */
  2845. S.prepend(W)    /* {void} concatenate W to start of S */
  2846. S.reverse()    /* {void) reverse S */
  2847. S.upcase()    /* {void) uppercase S */
  2848. S.downcase()    /* {void) lowercase S */
  2849. S.capitalize()    /* {void) initial-capitalize all words in S */
  2850.  
  2851. S[i]        /* {char} i-th character in S (counting from 0) */
  2852. S.elem(i)    /* {char} ditto */
  2853. S.firstchar()    /* {char} first char in S */
  2854. S.lastchar()    /* {char} last char in S */
  2855.  
  2856. S        /* used as {char*}: text of S */
  2857. S.chars()    /* {char*} text of S */
  2858. == != < > <= >=    /* {boolean} string compare, with left arg String or Substring,
  2859.             and right arg String or Substring or char*  */
  2860. compare(S,T)    /* {int} compare, returns -1 or 0 or +1 like strcmp();
  2861.         /* types of arguments as for == etc */
  2862. fcompare(S,T)    /* {int} compare, ignoring case */
  2863.  
  2864. /* SubString extraction. You can't take a SubString of a const String, else you
  2865. would be able to indirectly modify the String through the SubString */
  2866.  
  2867. S.at(i,j)    /* {SubString} = j chars starting at i-th char of S */
  2868. S(i,j)        /* {SubString} ditto */
  2869. S.before(i)    /* {SubString} the 0th to (i-1)th chars of S */
  2870. S.through(i)    /* {SubString} the 0th to i-th chars of S */
  2871. S.after(i)    /* {SubString} the i-th to last chars of S */
  2872. S.from(i)    /* {SubString} the (i+1)th to last chars of S */
  2873.     /* In the next 5 functions: i taken as 0 if second arg is omitted;
  2874.     the result is an empty substring if W is not found in S;
  2875.     W can be a Regex */
  2876. S.at(W,i)    /* {SubString} the part of S that matches W */
  2877. S.before(W,i)    /* {SubString} the part of S before the part that matches W */
  2878. S.through(W,i)    /* {SubString} ditto plus the part of S that matches W */
  2879. S.after(W,i)    /* {SubString} the part of S after the part that matches W */
  2880. S.from(W,i)    /* {SubString} the part of S that matches S, plus ditto */
  2881. X.length()    /* {int} length of text in X */
  2882. X.empty()    /* {boolean} if no text in X */
  2883. X.chars()    /* {char*) text of X (and of the rest of the string that X is a
  2884.         substring of) */
  2885.  
  2886. S.del(i,j)    /* {void} delete j chars starting at i-th char of S */
  2887.     /* in the next 3 uses, W can also be a Regex */
  2888. S.del(W)    /* {void} delete first occurence of W in S */
  2889. S.del(W,i)    /* {void} ditto, but start looking at i-th char of S */
  2890. S.gsub(W,U)    /* {int} replace all occurences of W by U */
  2891.         /* in gsub, W can't be a char  */
  2892. S.gsub(s,t)    /* ditto */
  2893.  
  2894. String A[];    /* array of Strings */
  2895. split(S,A,n,T)    /* take copy of S; in that copy wipe out all parts that match T;
  2896.         copy the remaining detached parts into A[0] A[1] etseq, but not
  2897.         more than n parts; return {int} = how many parts found */
  2898. split(S,A,n,R)    /* ditto */
  2899. join(A,n,S)    /* {String} = the strings A[0] to A[n-1] concatenated in that
  2900.         order with a copy of S put between at each join */
  2901. common_prefix(S,T)    /* {String} whatever consecutive chars are the same
  2902.             starting at the beginning of S and of T */
  2903. common_prefix(S,T,i)    /* ditto, ignoring the first i chars in S and T */
  2904. common_suffix(S,T)    /* {String} whatever consecutive chars are the same
  2905.             ending at the ends of S and of T */
  2906. common_suffix(S,T,i)    /* ditto, ignoring the last (1-i) chars in S and T */
  2907.  
  2908. ======================================== [END OF FILE]
  2909.  
  2910.  
  2911.