ljz@fxgrp.UUCP (Lloyd Zusman) (10/07/88)
Posting-number: Volume 4, Issue 115 Submitted-by: "Lloyd Zusman" <ljz@fxgrp.UUCP> Archive-name: apml/Part5 Enclosed you will find the Arbitrary Precision Math Library (5 of 5) Please post this to the comp.sources.misc newsgroup. I finally got this into good enough shape to send out to the net. To use, just unshar the 5 pieces, read the README file, possibly alter the makefiles to conform to your system's conventions, and then type 'make test'. Good luck! -- Lloyd Zusman Internet: ljz@fx.com Master Byte Software or ljz%fx.com@ames.arc.nasa.gov Los Gatos, California or fxgrp!ljz@ames.arc.nasa.gov "We take things well in hand." uucp: ...!ames!fxgrp!ljz [ our Internet connection is down: use uucp or mail to the entry above it ] #--------------------------Cut Here-------------------------- #! /bin/sh # This is a shell archive. Remove anything before the "#! /bin/sh" line, # then unpack it by saving it in a file and typing "sh file." # # Wrapped by Lloyd Zusman (ljz) at fxgrp on Wed Oct 5 12:41:51 1988 # # unpacks with default permissions # # Contents : apm.h apmlocal.h test/Makefile test/makefile.msc # test/apmtest.c # if `test ! -s apm.h` then echo "x - apm.h" sed 's/^X//' > apm.h << '@\END_OF_FILE_apm.h' X/****************************************************************************** X X Arbitrary Precision Math Library General Public License X (Written October 5, 1988) X X Copyright (C) 1988 Lloyd Zusman, Master Byte Software, Los X Gatos, California. Everyone is permitted to copy and distribute X verbatim copies of this license, but changing it is not allowed. X You can also use this wording to make the terms for other programs. X X The wording of this license is based on that of the X "GNU EMACS GENERAL PUBLIC LICENSE" by Richard Stallman, X Copyright (C) 1985, 1987, 1988, version of February 11, 1988, X but since some of the text has been changed, please be sure to X READ THIS CAREFULLY! X X This general public license is intended to give everyone the right Xto share the Arbitrary Precision Math Library (hereinafter referred to Xas the "APM Library"). To make sure that you get the rights we want Xyou to have, I need to make restrictions that forbid anyone to deny Xyou these rights or to ask you to surrender the rights. X X Specifically, we want to make sure that you have the right to give Xaway copies of the APM Library, that you receive source code or else Xcan get it if you want it, that you can change the APM Library or use Xpieces of it in new programs, and that you know you can do these Xthings. X X To make sure that everyone has such rights, we have to forbid you to Xdeprive anyone else of these rights. For example, if you distribute Xcopies of the APM Library, you must give the recipients all the Xrights that you have. You must make sure that they, too, receive or Xcan get the source code. And you must tell them their rights. X X Also, for our own protection, we must make certain that everyone Xfinds out that there is no warranty for the APM Library. If the APM XLibrary is modified by someone else and passed on, we want its Xrecipients to know that what they have is not what we distributed, so Xthat any problems introduced by others will not reflect on our Xreputation. X X Therefore we (Lloyd Zusman and Master Byte Software) make the Xfollowing terms which say what you must do to be allowed to Xdistribute or change the APM Library. X X COPYING POLICIES X X1. You may copy and distribute verbatim copies of the APM Library Xsource code as you receive it, in any medium, provided that you Xconspicuously and appropriately publish on each copy a valid copyright Xnotice "Copyright (C) 1988 Lloyd Zusman, Master Byte Software, Los XGatos, California" (or with whatever year is appropriate); keep intact Xthe notices on all files that refer to this License Agreement and to Xthe absence of any warranty; and give any other recipients of the the XAPM Library program a copy of this License Agreement along with the Xprogram. You may charge a distribution fee for the physical act of Xtransferring a copy. X X 2. You may modify your copy or copies of the APM Library source code or Xany portion of it, and copy and distribute such modifications under Xthe terms of Paragraph 1 above, provided that you also do the following: X X a) cause the modified files to carry prominent notices stating X that you changed the files and the date of any change; and X X b) cause the whole of any work that you distribute or publish, that in X whole or in part contains or is a derivative of the APM Library or any X part thereof, to be licensed to all third parties on terms identical X to those contained in this License Agreement (except that you may X choose to grant more extensive warranty protection to some or all X third parties, at your option). X X c) You may charge a distribution fee for the physical act of X transferring a copy, and you may at your option offer warranty X protection in exchange for a fee. X X d) You may not charge a license fee for the whole of any work that X you distribute or publish, that in whole or in part contains or is X a derivative of the APM library or any part thereof, without the X express written permission of Lloyd Zusman and Master Byte Software; X whether this permission is granted for free or in return for goods X services, royalties, or other compensation will be determined X solely by Lloyd Zusman and Master Byte Software. X XMere aggregation of another unrelated program with this program (or its Xderivative) on a volume of a storage or distribution medium does not bring Xthe other program under the scope of these terms. X X 3. You may copy and distribute the APM Library (or a portion or Xderivative of it, under Paragraph 2) in object code or executable form Xunder all the terms of Paragraphs 1 and 2 above provided that you also Xdo one of the following: X X a) accompany it with the complete corresponding machine-readable X source code, which must be distributed under the terms of X Paragraphs 1 and 2 above; or, X X b) accompany it with a written offer, valid for at least three X years, to give any third party free (except for a nominal X shipping charge) a complete machine-readable copy of the X corresponding source code, to be distributed under the terms of X Paragraphs 1 and 2 above; or, X X c) accompany it with the information you received as to where the X corresponding source code may be obtained. (This alternative is X allowed only for noncommercial distribution and only if you X received the program in object code or executable form alone.) X XFor an executable file, complete source code means all the source code Xfor all modules it contains; but, as a special exception, it need not Xinclude source code for modules which are standard libraries that Xaccompany the operating system on which the executable file runs. X X 4. You may not copy, sublicense, distribute or transfer the APM XLibrary except as expressly provided under this License Agreement. XAny attempt otherwise to copy, sublicense, distribute or transfer the XAPM Library is void and your rights to use the APM Library under this XLicense agreement shall be automatically terminated. However, parties Xwho have received computer software programs from you with this XLicense Agreement will not have their licenses terminated so long as Xsuch parties remain in full compliance. X X 5. If you wish to incorporate parts of the APM Library into other Xprograms whose distribution conditions are different, write to Lloyd XZusman at Master Byte Software. We have not yet worked out a simple Xrule that can be stated here, but we will often permit this. We will Xbe guided by the goals of (1) preserving the free status of all Xderivatives of our free software; of (2) promoting the sharing and Xreuse of software; and of (3) not allowing anyone to profit from the Xuse of our software without us also having the opportunity to share Xin these profits. X XYour comments and suggestions about our licensing policies and our Xsoftware are welcome! Please contact Lloyd Zusman, Master Byte XSoftware, 127 Wilder Ave., Los Gatos, California 95030, or call X(408) 395-5693. X X NO WARRANTY X X BECAUSE THE APM LIBRARY IS LICENSED FREE OF CHARGE, WE PROVIDE XABSOLUTELY NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE XLAW. EXCEPT WHEN OTHERWISE STATED IN WRITING, MASTER BYTE SOFTWARE, XLLOYD ZUSMAN AND/OR OTHER PARTIES PROVIDE THE APM LIBRARY "AS IS" XWITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, XBUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND XFITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY XAND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE THE APM XLIBRARY PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY XSERVICING, REPAIR OR CORRECTION. X X IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL MASTER BYTE XSOFTWARE, LLOYD ZUSMAN, AND/OR ANY OTHER PARTY WHO MAY MODIFY AND XREDISTRIBUTE THE APM LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR XDAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR OTHER SPECIAL, XINCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR XINABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA XBEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A XFAILURE OF THE PROGRAM TO OPERATE WITH PROGRAMS NOT DISTRIBUTED BY XMASTER BYTE SOFTWARE) THE PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF XTHE POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. X X******************************************************************************/ X X X/* X * Exported header file for the APM library. X * X * $Log: apm.h,v $ X * Revision 1.0 88/10/05 12:38:09 ljz X * Initial release. X * X */ X X#ifndef APM_H_INCLUDED X#define APM_H_INCLUDED X X/* X * Defining MSC implies MSDOS. X * Defining TURBOC implies MSDOS. X * Defining MSDOS alone implies unknown MSDOS C compiler. X * Defining MSC undefines TURBOC. X * Defining TURBOC undefines MSC. X * MSDOS undefined implies Unix. X */ X X#ifdef MSC X# ifndef MSDOS X# define MSDOS X# endif /* ! MSDOS */ X# ifdef TURBOC X# undef TURBOC X# endif /* TURBOC */ X#endif /* MSC */ X X#ifdef TURBOC X# ifndef MSDOS X# define MSDOS X# endif /* ! MSDOS */ X# ifdef MSC X# undef MSC X# endif /* MSC */ X#endif /* TURBOC */ X X#ifdef MSC X# include <malloc.h> X#endif /* MSC */ X Xstruct apm_struct { X unsigned long magic; X int alloclen; X int length; X int dp; X short sign; X short base; X short *data; X}; X Xtypedef struct apm_struct *APM; X Xextern int apm_errno; X Xextern int APM_line; Xextern char *APM_file; Xextern char *APM_func_name; X Xextern APM apm_init(); Xextern int apm_dispose(); Xextern int apm_add(); Xextern int apm_subtract(); Xextern int apm_multiply(); Xextern int apm_divide(); Xextern int apm_compare(); Xextern int apm_compare_long(); Xextern int apm_sign(); Xextern int apm_absolute_value(); Xextern int apm_negate(); Xextern int apm_reciprocal(); Xextern int apm_scale(); Xextern int apm_round(); Xextern int apm_validate(); Xextern int apm_assign(); Xextern int apm_assign_long(); Xextern int apm_assign_string(); Xextern int apm_convert(); Xextern int apm_garbage_collect(); Xextern FILE *apm_debug_file(); Xextern int (*apm_error_func())(); Xextern int apm_calc(); Xextern APM apm_op_alloc(); Xextern int apm_get_register(); Xextern int apm_set_register(); X X/* X * Calculator operation codes. X */ X#define APM_CALC_ABS (-1) X#define APM_CALC_NEG (-2) X#define APM_CALC_RECIP (-3) X#define APM_CALC_ADD (-4) X#define APM_CALC_SUB (-5) X#define APM_CALC_MUL (-6) X#define APM_CALC_DIV (-7) X#define APM_CALC_CLEAR (-8) X#define APM_CALC_DUP (-9) X#define APM_CALC_SWAP (-10) X#define APM_CALC_SCALE (-11) X#define APM_CALC_PUSH (-12) X#define APM_CALC_POP (-13) X X/* X * Macros X */ X X#define APM_FUNC_INFO_(X) (APM_file = __FILE__, APM_line = __LINE__, APM_func_name = (X)) X X#define apmInit(X,Y,Z) (APM_FUNC_INFO_("apmInit"),\ X apm_init((X),(Y),(Z))) X#define apmNew(X) (APM_FUNC_INFO_("apmNew"),\ X apm_init(0L, 0, (X))) X#define apmDispose(X) (APM_FUNC_INFO_("apmDispose"),\ X apm_dispose((X))) X#define apmAdd(X,Y,Z) (APM_FUNC_INFO_("apmAdd"),\ X apm_add((X),(Y),(Z))) X#define apmSubtract(X,Y,Z) (APM_FUNC_INFO_("apmSubtract"),\ X apm_subtract((X),(Y),(Z))) X#define apmMultiply(X,Y,Z) (APM_FUNC_INFO_("apmMultiply"),\ X apm_multiply((X),(Y),(Z))) X#define apmDivide(V,W,X,Y,Z) (APM_FUNC_INFO_("apmDivide"),\ X apm_divide((V),(W),(X),(Y),(Z))) X#define apmCompare(X,Y) (APM_FUNC_INFO_("apmCompare"),\ X apm_compare((X),(Y))) X#define apmCompareLong(W,X,Y,Z) (APM_FUNC_INFO_("apmCompareLong"),\ X apm_compare_long((W),(X),(Y),(Z))) X#define apmSign(X) (APM_FUNC_INFO_("apmSign"),\ X apm_sign((X))) X#define apmAbsoluteValue(X,Y) (APM_FUNC_INFO_("apmAbsoluteValue"),\ X apm_absolute_value((X),(Y))) X#define apmNegate(X,Y) (APM_FUNC_INFO_("apmNegate"),\ X apm_negate((X),(Y))) X#define apmReciprocal(X,Y,Z) (APM_FUNC_INFO_("apmReciprocal"),\ X apm_reciprocal((X),(Y),(Z))) X#define apmScale(X,Y,Z) (APM_FUNC_INFO_("apmScale"),\ X apm_scale((X),(Y),(Z))) X#define apmRound(X,Y,Z) (APM_FUNC_INFO_("apmRound"),\ X apm_round((X),(Y),(Z))) X#define apmValidate(X) (APM_FUNC_INFO_("apmValidate"),\ X apm_validate((X))) X#define apmAssign(X,Y) (APM_FUNC_INFO_("apmAssign"),\ X apm_assign((X),(Y))) X#define apmAssignLong(W,X,Y,Z) (APM_FUNC_INFO_("apmAssignLong"),\ X apm_assign_long((W),(X),(Y),(Z))) X#define apmAssignString(X,Y,Z) (APM_FUNC_INFO_("apmAssignString"),\ X apm_assign_string((X),(Y),(Z))) X#define apmConvert(U,V,W,X,Y,Z) (APM_FUNC_INFO_("apmConvert"),\ X apm_convert((U),(V),(W),(X),(Y),(Z))) X#define apmGarbageCollect() (APM_FUNC_INFO_("apmGarbageCollect"),\ X apm_garbage_collect()) X#define apmGetRegister(X,Y) (APM_FUNC_INFO_("apmGetRegister"),\ X apm_get_register((X),(Y))) X#define apmSetRegister(X,Y,Z) (APM_FUNC_INFO_("apmSetRegister"),\ X apm_set_register((X),(Y),(Z))) X X#define apmErrorFunc(X) apm_error_func(X) X#define apmDebugFile(X) apm_debug_file(X) X#define apmCalc apm_calc X X#define APM_ABS apm_op_alloc(APM_CALC_ABS, 0) X#define APM_NEG apm_op_alloc(APM_CALC_NEG, 0) X#define APM_RECIP(N) apm_op_alloc(APM_CALC_RECIP,(N)) X#define APM_ADD apm_op_alloc(APM_CALC_ADD, 0) X#define APM_SUB apm_op_alloc(APM_CALC_SUB, 0) X#define APM_MUL apm_op_alloc(APM_CALC_MUL, 0) X#define APM_DIV(N) apm_op_alloc(APM_CALC_DIV, (N)) X#define APM_CLEAR apm_op_alloc(APM_CALC_CLEAR, 0) X#define APM_DUP apm_op_alloc(APM_CALC_DUP, 0) X#define APM_SWAP apm_op_alloc(APM_CALC_SWAP, 0) X#define APM_SCALE(N) apm_op_alloc(APM_CALC_SCALE, (N)) X#define APM_PUSH(N) apm_op_alloc(APM_CALC_PUSH, (N)) X#define APM_POP(N) apm_op_alloc(APM_CALC_POP, (N)) X X/* X * APM error codes (for apm_errno): errors are < 0, warnings are > 0. X */ X#define APM_OK 0 /* no error */ X X#define APM_WNULL 1 /* one or more arguments are null */ X#define APM_WDIVBYZERO 2 /* division by zero (yields 0) */ X#define APM_WTRUNC 3 /* result truncated */ X#define APM_WNOALLOC 4 /* attempt to free unallocated apm value */ X X#define APM_ENOMEM (-1) /* no memory (allocation failed) */ X#define APM_EPARM (-2) /* invalid parameter passed to function */ X#define APM_ENULL (-3) /* null APM value */ X#define APM_EBADVAL (-4) /* APM points to bad data */ X#define APM_ENULLVAL (-5) /* null (non-APM) value */ X#define APM_EFMT (-6) /* string is of invalid format */ X#define APM_EBASE (-7) /* invalid base */ X#define APM_ESIZE (-8) /* size of destination is too low */ X#define APM_EOVERLAP (-9) /* result overlaps one or more operands */ X X#endif /* ! APM_H_INCLUDED */ @\END_OF_FILE_apm.h else echo "shar: Will not over write apm.h" fi if `test ! -s apmlocal.h` then echo "x - apmlocal.h" sed 's/^X//' > apmlocal.h << '@\END_OF_FILE_apmlocal.h' X/****************************************************************************** X X Arbitrary Precision Math Library General Public License X (Written October 5, 1988) X X Copyright (C) 1988 Lloyd Zusman, Master Byte Software, Los X Gatos, California. Everyone is permitted to copy and distribute X verbatim copies of this license, but changing it is not allowed. X You can also use this wording to make the terms for other programs. X X The wording of this license is based on that of the X "GNU EMACS GENERAL PUBLIC LICENSE" by Richard Stallman, X Copyright (C) 1985, 1987, 1988, version of February 11, 1988, X but since some of the text has been changed, please be sure to X READ THIS CAREFULLY! X X This general public license is intended to give everyone the right Xto share the Arbitrary Precision Math Library (hereinafter referred to Xas the "APM Library"). To make sure that you get the rights we want Xyou to have, I need to make restrictions that forbid anyone to deny Xyou these rights or to ask you to surrender the rights. X X Specifically, we want to make sure that you have the right to give Xaway copies of the APM Library, that you receive source code or else Xcan get it if you want it, that you can change the APM Library or use Xpieces of it in new programs, and that you know you can do these Xthings. X X To make sure that everyone has such rights, we have to forbid you to Xdeprive anyone else of these rights. For example, if you distribute Xcopies of the APM Library, you must give the recipients all the Xrights that you have. You must make sure that they, too, receive or Xcan get the source code. And you must tell them their rights. X X Also, for our own protection, we must make certain that everyone Xfinds out that there is no warranty for the APM Library. If the APM XLibrary is modified by someone else and passed on, we want its Xrecipients to know that what they have is not what we distributed, so Xthat any problems introduced by others will not reflect on our Xreputation. X X Therefore we (Lloyd Zusman and Master Byte Software) make the Xfollowing terms which say what you must do to be allowed to Xdistribute or change the APM Library. X X COPYING POLICIES X X1. You may copy and distribute verbatim copies of the APM Library Xsource code as you receive it, in any medium, provided that you Xconspicuously and appropriately publish on each copy a valid copyright Xnotice "Copyright (C) 1988 Lloyd Zusman, Master Byte Software, Los XGatos, California" (or with whatever year is appropriate); keep intact Xthe notices on all files that refer to this License Agreement and to Xthe absence of any warranty; and give any other recipients of the the XAPM Library program a copy of this License Agreement along with the Xprogram. You may charge a distribution fee for the physical act of Xtransferring a copy. X X 2. You may modify your copy or copies of the APM Library source code or Xany portion of it, and copy and distribute such modifications under Xthe terms of Paragraph 1 above, provided that you also do the following: X X a) cause the modified files to carry prominent notices stating X that you changed the files and the date of any change; and X X b) cause the whole of any work that you distribute or publish, that in X whole or in part contains or is a derivative of the APM Library or any X part thereof, to be licensed to all third parties on terms identical X to those contained in this License Agreement (except that you may X choose to grant more extensive warranty protection to some or all X third parties, at your option). X X c) You may charge a distribution fee for the physical act of X transferring a copy, and you may at your option offer warranty X protection in exchange for a fee. X X d) You may not charge a license fee for the whole of any work that X you distribute or publish, that in whole or in part contains or is X a derivative of the APM library or any part thereof, without the X express written permission of Lloyd Zusman and Master Byte Software; X whether this permission is granted for free or in return for goods X services, royalties, or other compensation will be determined X solely by Lloyd Zusman and Master Byte Software. X XMere aggregation of another unrelated program with this program (or its Xderivative) on a volume of a storage or distribution medium does not bring Xthe other program under the scope of these terms. X X 3. You may copy and distribute the APM Library (or a portion or Xderivative of it, under Paragraph 2) in object code or executable form Xunder all the terms of Paragraphs 1 and 2 above provided that you also Xdo one of the following: X X a) accompany it with the complete corresponding machine-readable X source code, which must be distributed under the terms of X Paragraphs 1 and 2 above; or, X X b) accompany it with a written offer, valid for at least three X years, to give any third party free (except for a nominal X shipping charge) a complete machine-readable copy of the X corresponding source code, to be distributed under the terms of X Paragraphs 1 and 2 above; or, X X c) accompany it with the information you received as to where the X corresponding source code may be obtained. (This alternative is X allowed only for noncommercial distribution and only if you X received the program in object code or executable form alone.) X XFor an executable file, complete source code means all the source code Xfor all modules it contains; but, as a special exception, it need not Xinclude source code for modules which are standard libraries that Xaccompany the operating system on which the executable file runs. X X 4. You may not copy, sublicense, distribute or transfer the APM XLibrary except as expressly provided under this License Agreement. XAny attempt otherwise to copy, sublicense, distribute or transfer the XAPM Library is void and your rights to use the APM Library under this XLicense agreement shall be automatically terminated. However, parties Xwho have received computer software programs from you with this XLicense Agreement will not have their licenses terminated so long as Xsuch parties remain in full compliance. X X 5. If you wish to incorporate parts of the APM Library into other Xprograms whose distribution conditions are different, write to Lloyd XZusman at Master Byte Software. We have not yet worked out a simple Xrule that can be stated here, but we will often permit this. We will Xbe guided by the goals of (1) preserving the free status of all Xderivatives of our free software; of (2) promoting the sharing and Xreuse of software; and of (3) not allowing anyone to profit from the Xuse of our software without us also having the opportunity to share Xin these profits. X XYour comments and suggestions about our licensing policies and our Xsoftware are welcome! Please contact Lloyd Zusman, Master Byte XSoftware, 127 Wilder Ave., Los Gatos, California 95030, or call X(408) 395-5693. X X NO WARRANTY X X BECAUSE THE APM LIBRARY IS LICENSED FREE OF CHARGE, WE PROVIDE XABSOLUTELY NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE XLAW. EXCEPT WHEN OTHERWISE STATED IN WRITING, MASTER BYTE SOFTWARE, XLLOYD ZUSMAN AND/OR OTHER PARTIES PROVIDE THE APM LIBRARY "AS IS" XWITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, XBUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND XFITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY XAND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE THE APM XLIBRARY PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY XSERVICING, REPAIR OR CORRECTION. X X IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL MASTER BYTE XSOFTWARE, LLOYD ZUSMAN, AND/OR ANY OTHER PARTY WHO MAY MODIFY AND XREDISTRIBUTE THE APM LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR XDAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR OTHER SPECIAL, XINCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR XINABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA XBEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A XFAILURE OF THE PROGRAM TO OPERATE WITH PROGRAMS NOT DISTRIBUTED BY XMASTER BYTE SOFTWARE) THE PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF XTHE POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. X X******************************************************************************/ X X X/* X * Non-exported header file for the APM library. X * X * $Log: apmlocal.h,v $ X * Revision 1.0 88/10/05 12:38:10 ljz X * Initial release. X * X */ X X#ifndef APMLOCAL_H_INCLUDED X#define APMLOCAL_H_INCLUDED X X#define APM_MAGIC 0xdeafc0de X#define OP_MAGIC 0xcacaface X X#define SPECIAL_BASE 10000 X#define SPECIAL_SCALE 4 X X#define SIGNOF(X) ((X) < 0 ? -1 : 1) X X#ifdef MSDOS X# define TABINCR 8 X#else X# define TABINCR 32 X#endif /* MSDOS */ X X#define APM_STACK_SIZE 16 X#define APM_NUM_REGISTERS 16 X X#define ERR_RETURN(X) {int Q=(X);if(Q<APM_OK)return(APM_error(Q));} X#define APM_ASSERT(X) if(!(X)){fprintf(stderr, "%s: %d: assertion failed: X\n", __FILE__, __LINE__);abort();} X Xextern int (*APM_error_func)(); X Xextern int APM_calc_op(); Xextern int APM_calc_unop(); Xextern int APM_calc_binop(); Xextern int APM_calc_misc(); Xextern int APM_push(); Xextern int APM_pop(); X Xextern short APM_array_add(); Xextern short APM_array_sub(); Xextern short APM_scalar_mul(); Xextern int APM_scalar_div(); Xextern int APM_error(); Xextern char *APM_alloc_mem(); Xextern int APM_free_mem(); Xextern char *APM_trim_string(); Xextern char *APM_left_justify(); Xextern int APM_val_format(); Xextern int APM_val_base(); Xextern short APM_get_digit(); Xextern int APM_radix_pos(); Xextern int APM_trim(); Xextern int APM_trimlead(); Xextern int APM_trimtrail(); Xextern int APM_setdp(); Xextern int APM_normalize(); Xextern int APM_scale(); Xextern APM APM_alloc(); Xextern APM APM_do_alloc(); Xextern int APM_free(); Xextern int APM_do_free(); Xextern int APM_norm_to_spec(); Xextern int APM_spec_to_norm(); Xextern int APM_size(); Xextern int APM_parse_string(); Xextern char *APM_build_string(); Xextern int APM_parse_long(); Xextern int APM_garbage_collect(); Xextern int APM_copy_bytes(); Xextern int APM_zero_bytes(); Xextern int APM_copy_shorts(); Xextern int APM_zero_shorts(); Xextern char *APM_index(); Xextern void APM_debug(); Xextern void APM_calc_init(); Xextern int APM_get_reg(); Xextern int APM_set_reg(); Xextern int APM_set_errno(); X X#endif /* ! APMLOCAL_H_INCLUDED */ @\END_OF_FILE_apmlocal.h else echo "shar: Will not over write apmlocal.h" fi if `test ! -d test` then mkdir test echo "mkdir test" fi if `test ! -s test/Makefile` then echo "x - test/Makefile" sed 's/^X//' > test/Makefile << '@\END_OF_FILE_test/Makefile' XINCLUDES = -I.. X XCFLAGS = -O $(INCLUDES) X XLDFLAGS = X XLIBS = ../libapm.a X XLINKER = cc X XOBJS = apmtest.o X XPROGRAM = apmtest X XSRCS = apmtest.c X Xall: $(PROGRAM) X X$(PROGRAM): $(OBJS) $(LIBS) X $(LINKER) $(LDFLAGS) $(OBJS) $(LIBS) -o $(PROGRAM) X Xclean: X rm -f $(OBJS) X X# The 'depend' production assumes the use of a program called 'makedepend'. X# Change your 'depend' line accordingly. X Xdepend: X makedepend $(INCLUDES) $(SRCS) X X# DO NOT DELETE THIS LINE -- makedepend uses it. X# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. X Xapmtest.o: apmtest.c /usr/include/stdio.h /usr/include/setjmp.h ../apm.h X X# IF YOU PUT ANYTHING HERE IT WILL GO AWAY @\END_OF_FILE_test/Makefile else echo "shar: Will not over write test/Makefile" fi if `test ! -s test/makefile.msc` then echo "x - test/makefile.msc" sed 's/^X//' > test/makefile.msc << '@\END_OF_FILE_test/makefile.msc' XM = S X XCFLAGS = -A$(M) -DMSC -I.. -Ox X XLDFLAGS = /noe/noi c:\ms\lib\arg$(M)+ X XLIBS = ..\apm.lib X XLINKER = link X XSTACK = 0800 X XMINALLOC = 0200 X XMAKEFILE = makefile X XPROGRAM = apmtest.exe X XRESPFILE = apmtest.arf X X X XSRCS = apmtest.c X XOBJS = apmtest.obj X X.c.obj: X cl $(CFLAGS) -c $*.c X Xall: $(PROGRAM) X X$(PROGRAM): $(OBJS) $(LIBS) X $(LINKER) $(LDFLAGS) @$(RESPFILE), $(PROGRAM), nul, $(LIBS); X exemod $(PROGRAM) /stack $(STACK) /min $(MINALLOC) X Xclean: X rm -f $(OBJS) X Xinstall: $(PROGRAM) X cp $(PROGRAM) $(DEST) X X### Xapmtest.obj: c:/ms/include/stdio.h c:/ms/include/setjmp.h ../apm.h \ X c:/ms/include/malloc.h @\END_OF_FILE_test/makefile.msc else echo "shar: Will not over write test/makefile.msc" fi if `test ! -s test/apmtest.c` then echo "x - test/apmtest.c" sed 's/^X//' > test/apmtest.c << '@\END_OF_FILE_test/apmtest.c' X#include <stdio.h> X#include <setjmp.h> X#include "apm.h" X Xextern void exit(); Xextern long strtol(); Xextern long time(); X X#ifndef MSC Xextern char *malloc(); Xextern char *realloc(); Xextern void free(); X#endif /* ! MSC */ X X#ifdef MSDOS X# define STRING_SIZE 512 X#else X# define STRING_SIZE 8192 X#endif /* MSDOS */ X Xjmp_buf here; X X/* X * System-independent replacement for index() and strchr(). X */ Xchar * Xsindex(s, ch) Xchar *s; Xint ch; X{ X if (s != NULL) { X for (; *s != '\0'; ++s) { X if (*s == (char)ch) { X return (s); X } X } X } X return (NULL); X} X Xint XerrorHandler(error, message, file, line, func) Xint error; Xchar *message; Xchar *file; Xint line; Xchar *func; X{ X fprintf(stderr, "\"%s\": line %d: %s: %s %d: %s\n", X file, line, func, error < 0 ? "error" : "warning", X error, message); X if (error < 0) { X longjmp(here, 1); X } X else { X return (error); X } X} X Xvoid Xusage() X{ X fprintf(stderr, "usage: apm [base]\n"); X exit(1); X} X Xmain(argc, argv) Xint argc; Xchar **argv; X{ X APM apm; X APM other; X APM result; X APM remainder; X char *cp; X char *x; X int ercode; X int scaleFactor; X int n; X int outLen; X int outDp; X int leftjust = 0; X int columnlist = 0; X short base = -1; X X for (--argc, ++argv; argc > 0; --argc, ++argv) { X if (base > -1) { X usage(); X } X base = (short)strtol(*argv, &cp, 10); X } X X if (argc > 0) { X usage(); X } X X if (base == -1) { X base = 0; X } X X apmDebugFile(stderr); X (void)apmErrorFunc(errorHandler); X X if (setjmp(here) != 0) { X exit (1); X } X X x = malloc(STRING_SIZE + 1); X X if (x == NULL) { X fprintf(stderr, "not enough memory\n"); X exit(1); X } X X apm = apmNew(0); X other = apmNew(0); X result = apmNew(0); X remainder = apmNew(0); X X for (;;) { X setjmp(here); X/*** X apmGarbageCollect(); X***/ X fprintf(stderr, "\nEnter first number:\t"); X fflush(stderr); X if (fgets(x, STRING_SIZE, stdin) == NULL) { X break; X } X cp = sindex(x, '\n'); X if (cp != NULL) { X *cp = '\0'; X } X if (x[0] == '\0') { X apmAssign(apm, result); X } X else { X apmAssignString(apm, x, base); X } X X fprintf(stderr, "Enter second number:\t"); X fflush(stderr); X if (fgets(x, STRING_SIZE, stdin) == NULL) { X break; X } X cp = sindex(x, '\n'); X if (cp != NULL) { X *cp = '\0'; X } X if (x[0] == '\0') { X apmAssign(other, result); X } X else { X apmAssignString(other, x, base); X } X X fprintf(stderr, "Enter scale factor:\t"); X fflush(stderr); X if(fgets(x, STRING_SIZE, stdin) == NULL) { X break; X } X cp = sindex(x, '\n'); X if (cp != NULL) { X *cp = '\0'; X } X scaleFactor = (int)strtol(x, &cp, 10); X if (cp == x) { X scaleFactor = 0; X } X X fprintf(stderr, "Enter field width:\t"); X fflush(stderr); X if(fgets(x, STRING_SIZE, stdin) == NULL) { X break; X } X cp = sindex(x, '\n'); X if (cp != NULL) { X *cp = '\0'; X } X outLen = (int)strtol(x, &cp, 10); X if (cp == x) { X outLen = 32; X } X X fprintf(stderr, "Enter number of DP's:\t"); X fflush(stderr); X if(fgets(x, STRING_SIZE, stdin) == NULL) { X break; X } X cp = sindex(x, '\n'); X if (cp != NULL) { X *cp = '\0'; X } X outDp = (int)strtol(x, &cp, 10); X if (cp == x) { X outDp = 10; X } X X n = apmCompare(apm, other); X if (n < 0) { X cp = "<"; X } X else if (n > 0) { X cp = ">"; X } X else { X cp = "=="; X } X fprintf(stderr, " Comparison:\t\tfirst %s second\n", cp); X X/* X apmNegate(result, apm); X*/ X apmCalc(result, apm, APM_NEG, NULL); X apmConvert(x, outLen + 1, outDp, 0, leftjust, result); X if (columnlist) { X fprintf(stderr, "\t\t\t12345678901234567890123456789012345678901234567890123456789012345678901234567890\n"); X } X fprintf(stderr, " Negation of first:\t%s\n", x); X X cp = NULL; X/* X apmReciprocal(result, outDp, other); X*/ X apmCalc(result, other, APM_RECIP(outDp), NULL); X if (apm_errno == APM_WDIVBYZERO) { X cp = " (division by zero)"; X } X apmConvert(x, outLen + 1, outDp, 0, leftjust, result); X fprintf(stderr, " Reciprocal of second:\t%s%s\n", x, X cp == NULL ? "" : cp); X X/* X apmAdd(result, apm, other); X*/ X apmCalc(result, apm, other, APM_ADD, NULL); X apmConvert(x, outLen + 1, outDp, 0, leftjust, result); X fprintf(stderr, " Sum:\t\t\t%s\n", x); X X/* X apmSubtract(result, apm, other); X*/ X apmCalc(result, apm, other, APM_SUB, NULL); X apmConvert(x, outLen + 1, outDp, 0, leftjust, result); X fprintf(stderr, " Difference:\t\t%s\n", x); X X/* X apmMultiply(result, apm, other); X*/ X apmCalc(result, apm, other, APM_MUL, NULL); X apmConvert(x, outLen + 1, outDp, 0, leftjust, result); X fprintf(stderr, " Product:\t\t%s\n", x); X X cp = NULL; X/* X apmDivide(result, outDp, remainder, apm, other); X*/ X apmCalc(result, apm, other, APM_DIV(outDp), NULL); X apmGetRegister(remainder, 0); X if (apm_errno == APM_WDIVBYZERO) { X cp = " (division by zero)"; X } X apmConvert(x, outLen + 1, outDp, 0, leftjust, result); X fprintf(stderr, " Quotient:\t\t%s%s\n", x, X cp ? cp : ""); X apmConvert(x, outLen + 1, outDp, 0, leftjust, remainder); X fprintf(stderr, " Remainder:\t\t%s\n", x); X X/* X apmScale(apm, result, scaleFactor); X*/ X apmCalc(apm, apm, APM_POP(1), result, APM_SCALE(scaleFactor), X NULL); X apmConvert(x, outLen + 1, outDp, 0, leftjust, apm); X fprintf(stderr, " Scaled quotient:\t%s\n", x); X X apmCalc(result, APM_PUSH(1), APM_DUP, APM_ADD, APM_DUP, X other, APM_MUL, APM_SUB, NULL); X apmConvert(x, outLen + 1, outDp, 0, leftjust, result); X fprintf(stderr, " Calc test:\t\t%s\n", x); X X } X putchar('\n'); X} @\END_OF_FILE_test/apmtest.c else echo "shar: Will not over write test/apmtest.c" fi echo "Finished archive 5 of 5" # to concatenate archives, remove anything after this line exit 0