home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / C / APMTEST / APM.H < prev    next >
Text File  |  1993-12-01  |  14KB  |  362 lines

  1. /******************************************************************************
  2.  
  3.     Arbitrary Precision Math Library General Public License
  4.             (Written October 5, 1988)
  5.  
  6.  Copyright (C) 1988 Lloyd Zusman, Master Byte Software, Los
  7.  Gatos, California.  Everyone is permitted to copy and distribute
  8.  verbatim copies of this license, but changing it is not allowed.
  9.  You can also use this wording to make the terms for other programs.
  10.  
  11.  The wording of this license is based on that of the
  12.  "GNU EMACS GENERAL PUBLIC LICENSE" by Richard Stallman,
  13.  Copyright (C) 1985, 1987, 1988, version of February 11, 1988,
  14.  but since some of the text has been changed, please be sure to
  15.  READ THIS CAREFULLY!
  16.  
  17.   This general public license is intended to give everyone the right
  18. to share the Arbitrary Precision Math Library (hereinafter referred to
  19. as the "APM Library").  To make sure that you get the rights we want
  20. you to have, I need to make restrictions that forbid anyone to deny
  21. you these rights or to ask you to surrender the rights.
  22.  
  23.   Specifically, we want to make sure that you have the right to give
  24. away copies of the APM Library, that you receive source code or else
  25. can get it if you want it, that you can change the APM Library or use
  26. pieces of it in new programs, and that you know you can do these
  27. things.
  28.  
  29.   To make sure that everyone has such rights, we have to forbid you to
  30. deprive anyone else of these rights.  For example, if you distribute
  31. copies of the APM Library, you must give the recipients all the
  32. rights that you have.  You must make sure that they, too, receive or
  33. can get the source code.  And you must tell them their rights.
  34.  
  35.   Also, for our own protection, we must make certain that everyone
  36. finds out that there is no warranty for the APM Library.  If the APM
  37. Library is modified by someone else and passed on, we want its
  38. recipients to know that what they have is not what we distributed, so
  39. that any problems introduced by others will not reflect on our
  40. reputation.
  41.  
  42.   Therefore we (Lloyd Zusman and Master Byte Software) make the
  43. following terms which say what you must do to be allowed to
  44. distribute or change the APM Library.
  45.  
  46.             COPYING POLICIES
  47.  
  48. 1. You may copy and distribute verbatim copies of the APM Library
  49. source code as you receive it, in any medium, provided that you
  50. conspicuously and appropriately publish on each copy a valid copyright
  51. notice "Copyright (C) 1988 Lloyd Zusman, Master Byte Software, Los
  52. Gatos, California" (or with whatever year is appropriate); keep intact
  53. the notices on all files that refer to this License Agreement and to
  54. the absence of any warranty; and give any other recipients of the the
  55. APM Library program a copy of this License Agreement along with the
  56. program.  You may charge a distribution fee for the physical act of
  57. transferring a copy.
  58.  
  59.   2. You may modify your copy or copies of the APM Library source code or
  60. any portion of it, and copy and distribute such modifications under
  61. the terms of Paragraph 1 above, provided that you also do the following:
  62.  
  63.     a) cause the modified files to carry prominent notices stating
  64.     that you changed the files and the date of any change; and
  65.  
  66.     b) cause the whole of any work that you distribute or publish, that in
  67.     whole or in part contains or is a derivative of the APM Library or any
  68.     part thereof, to be licensed to all third parties on terms identical
  69.     to those contained in this License Agreement (except that you may
  70.     choose to grant more extensive warranty protection to some or all
  71.     third parties, at your option).
  72.  
  73.     c) You may charge a distribution fee for the physical act of
  74.     transferring a copy, and you may at your option offer warranty
  75.     protection in exchange for a fee.
  76.  
  77.     d) You may not charge a license fee for the whole of any work that
  78.     you distribute or publish, that in whole or in part contains or is
  79.     a derivative of the APM library or any part thereof, without the
  80.     express written permission of Lloyd Zusman and Master Byte Software;
  81.     whether this permission is granted for free or in return for goods
  82.     services, royalties, or other compensation will be determined
  83.     solely by Lloyd Zusman and Master Byte Software.
  84.  
  85. Mere aggregation of another unrelated program with this program (or its
  86. derivative) on a volume of a storage or distribution medium does not bring
  87. the other program under the scope of these terms.
  88.  
  89.   3. You may copy and distribute the APM Library (or a portion or
  90. derivative of it, under Paragraph 2) in object code or executable form
  91. under all the terms of Paragraphs 1 and 2 above provided that you also
  92. do one of the following:
  93.  
  94.     a) accompany it with the complete corresponding machine-readable
  95.     source code, which must be distributed under the terms of
  96.     Paragraphs 1 and 2 above; or,
  97.  
  98.     b) accompany it with a written offer, valid for at least three
  99.     years, to give any third party free (except for a nominal
  100.     shipping charge) a complete machine-readable copy of the
  101.     corresponding source code, to be distributed under the terms of
  102.     Paragraphs 1 and 2 above; or,
  103.  
  104.     c) accompany it with the information you received as to where the
  105.     corresponding source code may be obtained.  (This alternative is
  106.     allowed only for noncommercial distribution and only if you
  107.     received the program in object code or executable form alone.)
  108.  
  109. For an executable file, complete source code means all the source code
  110. for all modules it contains; but, as a special exception, it need not
  111. include source code for modules which are standard libraries that
  112. accompany the operating system on which the executable file runs.
  113.  
  114.   4. You may not copy, sublicense, distribute or transfer the APM
  115. Library except as expressly provided under this License Agreement.
  116. Any attempt otherwise to copy, sublicense, distribute or transfer the
  117. APM Library is void and your rights to use the APM Library under this
  118. License agreement shall be automatically terminated.  However, parties
  119. who have received computer software programs from you with this
  120. License Agreement will not have their licenses terminated so long as
  121. such parties remain in full compliance.
  122.  
  123.   5. If you wish to incorporate parts of the APM Library into other
  124. programs whose distribution conditions are different, write to Lloyd
  125. Zusman at Master Byte Software.  We have not yet worked out a simple
  126. rule that can be stated here, but we will often permit this.  We will
  127. be guided by the goals of (1) preserving the free status of all
  128. derivatives of our free software; of (2) promoting the sharing and
  129. reuse of software; and of (3) not allowing anyone to profit from the
  130. use of our software without us also having the opportunity to share
  131. in these profits.
  132.  
  133. Your comments and suggestions about our licensing policies and our
  134. software are welcome!  Please contact Lloyd Zusman, Master Byte
  135. Software, 127 Wilder Ave., Los Gatos, California 95030, or call
  136. (408) 395-5693.
  137.  
  138.                NO WARRANTY
  139.  
  140.   BECAUSE THE APM LIBRARY IS LICENSED FREE OF CHARGE, WE PROVIDE
  141. ABSOLUTELY NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE
  142. LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING, MASTER BYTE SOFTWARE,
  143. LLOYD ZUSMAN AND/OR OTHER PARTIES PROVIDE THE APM LIBRARY "AS IS"
  144. WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
  145. BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  146. FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
  147. AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE THE APM
  148. LIBRARY PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
  149. SERVICING, REPAIR OR CORRECTION.
  150.  
  151.   IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL MASTER BYTE
  152. SOFTWARE, LLOYD ZUSMAN, AND/OR ANY OTHER PARTY WHO MAY MODIFY AND
  153. REDISTRIBUTE THE APM LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR
  154. DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR OTHER SPECIAL,
  155. INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
  156. INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA
  157. BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A
  158. FAILURE OF THE PROGRAM TO OPERATE WITH PROGRAMS NOT DISTRIBUTED BY
  159. MASTER BYTE SOFTWARE) THE PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF
  160. THE POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  161.  
  162. ******************************************************************************/
  163.  
  164.  
  165. /*
  166.  * Exported header file for the APM library.
  167.  *
  168.  * $Log:    apm.h,v $
  169.  * Revision 1.0  88/10/05  12:38:09  ljz
  170.  * Initial release.
  171.  * 
  172.  */
  173.  
  174. #ifndef APM_H_INCLUDED
  175. #define APM_H_INCLUDED
  176.  
  177. /*
  178.  * Defining MSC implies MSDOS.
  179.  * Defining TURBOC implies MSDOS.
  180.  * Defining MSDOS alone implies unknown MSDOS C compiler.
  181.  * Defining MSC undefines TURBOC.
  182.  * Defining TURBOC undefines MSC.
  183.  * MSDOS undefined implies Unix.
  184.  */
  185.  
  186. #ifdef MSC
  187. # ifndef MSDOS
  188. #  define MSDOS
  189. # endif /* ! MSDOS */
  190. # ifdef TURBOC
  191. #  undef TURBOC
  192. # endif /* TURBOC */
  193. #endif /* MSC */
  194.  
  195. #ifdef TURBOC
  196. # ifndef MSDOS
  197. #  define MSDOS
  198. # endif /* ! MSDOS */
  199. # ifdef MSC
  200. #  undef MSC
  201. # endif /* MSC */
  202. #endif /* TURBOC */
  203.  
  204. #ifdef MSC
  205. # include <malloc.h>
  206. #endif /* MSC */
  207.  
  208. struct apm_struct {
  209.     unsigned long magic;
  210.     int alloclen;
  211.     int length;
  212.     int dp;
  213.     short sign;
  214.     short base;
  215.     short *data;
  216. };
  217.  
  218. typedef struct apm_struct *APM;
  219.  
  220. extern int apm_errno;
  221.  
  222. extern int APM_line;
  223. extern char *APM_file;
  224. extern char *APM_func_name;
  225.  
  226. extern APM apm_init();
  227. extern int apm_dispose();
  228. extern int apm_add();
  229. extern int apm_subtract();
  230. extern int apm_multiply();
  231. extern int apm_divide();
  232. extern int apm_compare();
  233. extern int apm_compare_long();
  234. extern int apm_sign();
  235. extern int apm_absolute_value();
  236. extern int apm_negate();
  237. extern int apm_reciprocal();
  238. extern int apm_scale();
  239. extern int apm_round();
  240. extern int apm_validate();
  241. extern int apm_assign();
  242. extern int apm_assign_long();
  243. extern int apm_assign_string();
  244. extern int apm_convert();
  245. extern int apm_garbage_collect();
  246. extern FILE *apm_debug_file();
  247. extern int (*apm_error_func())();
  248. extern int apm_calc();
  249. extern APM apm_op_alloc();
  250. extern int apm_get_register();
  251. extern int apm_set_register();
  252.  
  253. /*
  254.  * Calculator operation codes.
  255.  */
  256. #define APM_CALC_ABS    (-1)
  257. #define APM_CALC_NEG    (-2)
  258. #define APM_CALC_RECIP    (-3)
  259. #define APM_CALC_ADD    (-4)
  260. #define APM_CALC_SUB    (-5)
  261. #define APM_CALC_MUL    (-6)
  262. #define APM_CALC_DIV    (-7)
  263. #define APM_CALC_CLEAR    (-8)
  264. #define APM_CALC_DUP    (-9)
  265. #define APM_CALC_SWAP    (-10)
  266. #define APM_CALC_SCALE    (-11)
  267. #define APM_CALC_PUSH    (-12)
  268. #define APM_CALC_POP    (-13)
  269.  
  270. /*
  271.  * Macros
  272.  */
  273.  
  274. #define APM_FUNC_INFO_(X)    (APM_file = __FILE__, APM_line = __LINE__, APM_func_name = (X))
  275.  
  276. #define apmInit(X,Y,Z)        (APM_FUNC_INFO_("apmInit"),\
  277.                  apm_init((X),(Y),(Z)))
  278. #define apmNew(X)        (APM_FUNC_INFO_("apmNew"),\
  279.                  apm_init(0L, 0, (X)))
  280. #define apmDispose(X)        (APM_FUNC_INFO_("apmDispose"),\
  281.                  apm_dispose((X)))
  282. #define apmAdd(X,Y,Z)        (APM_FUNC_INFO_("apmAdd"),\
  283.                  apm_add((X),(Y),(Z)))
  284. #define apmSubtract(X,Y,Z)    (APM_FUNC_INFO_("apmSubtract"),\
  285.                  apm_subtract((X),(Y),(Z)))
  286. #define apmMultiply(X,Y,Z)    (APM_FUNC_INFO_("apmMultiply"),\
  287.                  apm_multiply((X),(Y),(Z)))
  288. #define apmDivide(V,W,X,Y,Z)    (APM_FUNC_INFO_("apmDivide"),\
  289.                  apm_divide((V),(W),(X),(Y),(Z)))
  290. #define apmCompare(X,Y)        (APM_FUNC_INFO_("apmCompare"),\
  291.                  apm_compare((X),(Y)))
  292. #define apmCompareLong(W,X,Y,Z)    (APM_FUNC_INFO_("apmCompareLong"),\
  293.                  apm_compare_long((W),(X),(Y),(Z)))
  294. #define apmSign(X)        (APM_FUNC_INFO_("apmSign"),\
  295.                  apm_sign((X)))
  296. #define apmAbsoluteValue(X,Y)    (APM_FUNC_INFO_("apmAbsoluteValue"),\
  297.                  apm_absolute_value((X),(Y)))
  298. #define apmNegate(X,Y)        (APM_FUNC_INFO_("apmNegate"),\
  299.                  apm_negate((X),(Y)))
  300. #define apmReciprocal(X,Y,Z)    (APM_FUNC_INFO_("apmReciprocal"),\
  301.                  apm_reciprocal((X),(Y),(Z)))
  302. #define apmScale(X,Y,Z)        (APM_FUNC_INFO_("apmScale"),\
  303.                  apm_scale((X),(Y),(Z)))
  304. #define apmRound(X,Y,Z)        (APM_FUNC_INFO_("apmRound"),\
  305.                  apm_round((X),(Y),(Z)))
  306. #define apmValidate(X)        (APM_FUNC_INFO_("apmValidate"),\
  307.                  apm_validate((X)))
  308. #define apmAssign(X,Y)        (APM_FUNC_INFO_("apmAssign"),\
  309.                  apm_assign((X),(Y)))
  310. #define apmAssignLong(W,X,Y,Z)    (APM_FUNC_INFO_("apmAssignLong"),\
  311.                  apm_assign_long((W),(X),(Y),(Z)))
  312. #define apmAssignString(X,Y,Z)    (APM_FUNC_INFO_("apmAssignString"),\
  313.                  apm_assign_string((X),(Y),(Z)))
  314. #define apmConvert(U,V,W,X,Y,Z)    (APM_FUNC_INFO_("apmConvert"),\
  315.                  apm_convert((U),(V),(W),(X),(Y),(Z)))
  316. #define apmGarbageCollect()    (APM_FUNC_INFO_("apmGarbageCollect"),\
  317.                  apm_garbage_collect())
  318. #define apmGetRegister(X,Y)    (APM_FUNC_INFO_("apmGetRegister"),\
  319.                  apm_get_register((X),(Y)))
  320. #define apmSetRegister(X,Y,Z)    (APM_FUNC_INFO_("apmSetRegister"),\
  321.                  apm_set_register((X),(Y),(Z)))
  322.  
  323. #define apmErrorFunc(X)        apm_error_func(X)
  324. #define apmDebugFile(X)        apm_debug_file(X)
  325. #define apmCalc            apm_calc
  326.  
  327. #define APM_ABS            apm_op_alloc(APM_CALC_ABS, 0)
  328. #define APM_NEG            apm_op_alloc(APM_CALC_NEG, 0)
  329. #define APM_RECIP(N)        apm_op_alloc(APM_CALC_RECIP,(N))
  330. #define APM_ADD            apm_op_alloc(APM_CALC_ADD, 0)
  331. #define APM_SUB            apm_op_alloc(APM_CALC_SUB, 0)
  332. #define APM_MUL            apm_op_alloc(APM_CALC_MUL, 0)
  333. #define APM_DIV(N)        apm_op_alloc(APM_CALC_DIV, (N))
  334. #define APM_CLEAR        apm_op_alloc(APM_CALC_CLEAR, 0)
  335. #define APM_DUP            apm_op_alloc(APM_CALC_DUP, 0)
  336. #define APM_SWAP        apm_op_alloc(APM_CALC_SWAP, 0)
  337. #define APM_SCALE(N)        apm_op_alloc(APM_CALC_SCALE, (N))
  338. #define APM_PUSH(N)        apm_op_alloc(APM_CALC_PUSH, (N))
  339. #define APM_POP(N)        apm_op_alloc(APM_CALC_POP, (N))
  340.  
  341. /*
  342.  * APM error codes (for apm_errno):  errors are < 0, warnings are > 0.
  343.  */
  344. #define APM_OK        0    /* no error */
  345.  
  346. #define APM_WNULL    1    /* one or more arguments are null */
  347. #define APM_WDIVBYZERO    2    /* division by zero (yields 0) */
  348. #define APM_WTRUNC    3    /* result truncated */
  349. #define APM_WNOALLOC    4    /* attempt to free unallocated apm value */
  350.  
  351. #define APM_ENOMEM    (-1)    /* no memory (allocation failed) */
  352. #define APM_EPARM    (-2)    /* invalid parameter passed to function */
  353. #define APM_ENULL    (-3)    /* null APM value */
  354. #define APM_EBADVAL    (-4)    /* APM points to bad data */
  355. #define APM_ENULLVAL    (-5)    /* null (non-APM) value */
  356. #define APM_EFMT    (-6)    /* string is of invalid format */
  357. #define APM_EBASE    (-7)    /* invalid base */
  358. #define APM_ESIZE    (-8)    /* size of destination is too low */
  359. #define APM_EOVERLAP    (-9)    /* result overlaps one or more operands */
  360.  
  361. #endif /* ! APM_H_INCLUDED */
  362.