iacdouble.c

Go to the documentation of this file.
00001 
00002 /*  $Id: iacdouble.c 1198 2006-04-05 22:03:52Z karstenw $    */
00003 
00004 /* copyright 1991-96 UserLand Software, Inc. All Rights Reserved.*/
00005 
00006 
00007 #include "frontier.h"
00008 #include "standard.h"
00009 
00010 #include "iacinternal.h"
00011 
00012 
00013 /*
00014 7/25/94 dmb: updated for PowerPC, fp.h
00015 */
00016 
00017 /*  11/8/94 JWB Determine the size of C type double using compile-time tests.   */
00018 /*              It may be necessary to add tests to cover additional compilers. */
00019 
00020 #if defined(powerc) || defined(__powerc) || defined(applec) || defined(__SC__) || defined(__GNUC__)
00021 
00022     #define DOUBLE_BYTES 8
00023 
00024 #elif defined(THINK_C)
00025 
00026     #if __option(double_8)
00027 
00028         #define DOUBLE_BYTES 8
00029 
00030     #elif !__option(native_fp)
00031 
00032         #define DOUBLE_BYTES 12
00033 
00034     #elif defined(mc68881)
00035 
00036         #define DOUBLE_BYTES 12
00037 
00038     #else
00039 
00040         #define DOUBLE_BYTES 10
00041 
00042     #endif
00043 
00044 #elif defined(__MWERKS__)
00045 
00046     #if __IEEEdoubles__
00047 
00048         #define DOUBLE_BYTES 8
00049 
00050     #elif __MC68881__
00051 
00052         #define DOUBLE_BYTES 12
00053 
00054     #else
00055 
00056         #define DOUBLE_BYTES 10
00057 
00058     #endif
00059 #endif
00060 
00061 
00062 #if DOUBLE_BYTES == 12
00063 
00064 /* 11/8/94 JWB  To avoid dependencies on unknown libraries, the conversions between 10 and 12 */
00065 /*              byte formats are done here.  The conversion is done in a way suitable for the */
00066 /*              THINK C Universal format, which should not cause problems with the other      */
00067 /*              compilers.  */
00068 
00069 
00070 static void iacx96to80 (short * px96, short * px80) {
00071     *px80 = *px96++;     /* Skipping x96[1], the unused word */
00072 
00073     *++px80 = *++px96;
00074 
00075     *++px80 = *++px96;
00076 
00077     *++px80 = *++px96;
00078 
00079     *++px80 = *++px96;
00080     } /*xx80to96*/
00081 
00082 static void iacx80to96 (short * px80, short * px96) {
00083     *px96 = *px80--;      /* Arrange to copy x80[0] to both x96[0] and x96[1], in case the
00084                              THINK C "Universal" doubles are in use. */
00085 
00086     *++px96 = *++px80;
00087 
00088     *++px96 = *++px80;
00089 
00090     *++px96 = *++px80;
00091 
00092     *++px96 = *++px80;
00093 
00094     *++px96 = *++px80;
00095     } /*xx96to80*/
00096 #endif
00097 
00098 
00099 #if DOUBLE_BYTES == 8
00100 
00101 Boolean IACpushdoubleparam (double val, OSType keyword) {
00102     
00103     register OSErr ec;
00104     AEDesc valDesc = { typeNull, nil };
00105     
00106     ec = AECoercePtr (typeFloat, &val, sizeof (val), typeExtended, &valDesc);
00107     
00108     if (ec == noErr)
00109 
00110         ec = AEPutParamDesc (IACglobals.event, (AEKeyword) keyword, &valDesc);
00111 
00112     IACglobals.errorcode = ec;
00113     
00114     (void) AEDisposeDesc (&valDesc);
00115     
00116     return (ec == noErr);
00117     } /*IACpushdoubleparam*/
00118 
00119 
00120 Boolean IACreturndouble (double x) {
00121     
00122     register OSErr ec;
00123     AEDesc valDesc = { typeNull, nil };
00124     
00125     ec = AECoercePtr (typeFloat, &x, sizeof (x), typeExtended, &valDesc);
00126     
00127     if (ec == noErr)
00128 
00129         ec = AEPutParamDesc (IACglobals.reply, keyDirectObject, &valDesc);
00130 
00131     IACglobals.errorcode = ec;
00132     
00133     (void) AEDisposeDesc (&valDesc);
00134     
00135     return (ec == noErr);
00136     } /*IACreturndouble*/
00137 
00138 
00139 Boolean IACgetdoubleparam (OSType keyword, double *val) {
00140     
00141     register OSErr ec;
00142     DescType actualtype;
00143     Size actualsize;
00144 
00145     ec = AEGetParamPtr (
00146         
00147         IACglobals.event, (AEKeyword) keyword, typeFloat, 
00148         
00149         &actualtype, (Ptr) val, sizeof (double), &actualsize);
00150     
00151     IACglobals.errorcode = ec;
00152     
00153     if (ec != noErr) {
00154         
00155         IACparamerror (ec, "\pdouble", keyword);
00156         
00157         return (false);
00158         }
00159     
00160     IACglobals.nextparamoptional = false; /*must be reset for each param*/
00161 
00162     return (true);
00163     } /*IACgetdoubleparam*/
00164     
00165 
00166 Boolean IACgetdoubleitem (AEDescList *list, long n, double *val) {
00167     
00168     register OSErr ec;
00169     DescType key;
00170     DescType typeCode;
00171     Size actualSize;
00172 
00173     if ((*list).descriptorType == typeAERecord) {
00174         
00175         ec = AEGetKeyPtr (list, n, typeFloat, &typeCode, (Ptr) val, sizeof (double), &actualSize);
00176             
00177         if (ec != errAEDescNotFound)
00178             goto done;
00179         }
00180     
00181     ec = AEGetNthPtr (list, n, typeFloat, &key, &typeCode, (Ptr) val,
00182                         sizeof (double), &actualSize);
00183     
00184     done:
00185     
00186     IACglobals.errorcode = ec;
00187     
00188     return (ec == noErr);
00189     } /*IACgetdoubleitem*/
00190 
00191 
00192 Boolean IACpushdoubleitem (AEDescList *list, double val, long n) {
00193     
00194     register OSErr ec;
00195     AEDesc valDesc = {typeNull, nil};
00196     
00197     ec = AECoercePtr (typeFloat, (Ptr)&val, sizeof (val), typeExtended, &valDesc);
00198     
00199     if (ec == noErr)
00200     {
00201         // 2006-04-02 kw --- inserted braces for ambiguity warning
00202         if ((*list).descriptorType == typeAERecord)
00203             ec = AEPutKeyDesc (list, n, &valDesc);
00204         else
00205             ec = AEPutDesc (list, n, &valDesc);
00206     }
00207     
00208     IACglobals.errorcode = ec;
00209     
00210     (void)AEDisposeDesc (&valDesc);
00211     
00212     return (ec == noErr);
00213     } /*IACpushdoubleitem*/
00214 
00215 
00216 #elif DOUBLE_BYTES == 12
00217 
00218 Boolean IACpushdoubleparam (double val, OSType keyword) {
00219     
00220     register OSErr ec;
00221     short value[5];
00222     
00223     iacx96to80 ((short *)&val, value); /*convert from double to extended*/      
00224     
00225     ec = AEPutParamPtr (
00226         
00227         IACglobals.event, (AEKeyword) keyword, typeExtended, 
00228         
00229         (Ptr) &value, sizeof (value));
00230         
00231     IACglobals.errorcode = ec;
00232     
00233     return (ec == noErr);
00234     } /*IACpushdoubleparam*/
00235 
00236 
00237 Boolean IACreturndouble (double x) {
00238     
00239     register OSErr ec;
00240     short value[5];
00241     
00242     iacx96to80 ((short *)&x, value); /*convert from double to extended*/        
00243     
00244     ec = AEPutParamPtr (
00245         
00246         IACglobals.reply, keyDirectObject, typeExtended, (Ptr)&value, 
00247         
00248         (Size) sizeof (value));
00249         
00250     IACglobals.errorcode = ec;
00251     
00252     return (ec == noErr);
00253     } /*IACreturndouble*/
00254 
00255 
00256 Boolean IACgetdoubleparam (OSType keyword, double *val) {
00257     
00258     register OSErr ec;
00259     DescType actualtype;
00260     Size actualsize;
00261     short value[5];
00262     
00263     ec = AEGetParamPtr (
00264         
00265         IACglobals.event, (AEKeyword) keyword, typeExtended, 
00266         
00267         &actualtype, (Ptr) value, sizeof (value), &actualsize);
00268     
00269     IACglobals.errorcode = ec;
00270     
00271     if (ec != noErr) {
00272         
00273         IACparamerror (ec, "\pdouble", keyword);
00274         
00275         return (false);
00276         }
00277     
00278     IACglobals.nextparamoptional = false; /*must be reset for each param*/
00279     
00280     iacx80to96 (value, (short *)val);
00281 
00282     return (true);
00283     } /*IACgetdoubleparam*/
00284     
00285 
00286 Boolean IACgetdoubleitem (AEDescList *list, long n, double *val) {
00287     
00288     register OSErr ec;
00289     DescType key;
00290     DescType typeCode;
00291     Size actualSize;
00292     short value[5];
00293 
00294     if ((*list).descriptorType == typeAERecord) {
00295         
00296         ec = AEGetKeyPtr (list, n, typeExtended, &typeCode, (Ptr) value, sizeof (value), &actualSize);
00297             
00298         if (ec != errAEDescNotFound)
00299             goto done;
00300         }
00301     
00302     ec = AEGetNthPtr (list, n, typeExtended, &key, &typeCode, (Ptr) value, sizeof (value), &actualSize);
00303     
00304     done:
00305     
00306     IACglobals.errorcode = ec;
00307     
00308     iacx80to96 (value, (short *)val);
00309     
00310     return (ec == noErr);
00311     } /*IACgetdoubleitem*/
00312 
00313 
00314 Boolean IACpushdoubleitem (AEDescList *list, double val, long n) {
00315     
00316     register OSErr ec;
00317     short   value[5];
00318 
00319     iacx96to80 ((short *)&val, value); /*convert from double to extended*/      
00320     
00321     if ((*list).descriptorType == typeAERecord)
00322         ec = AEPutKeyPtr (list, n, typeExtended, (Ptr)value, sizeof (value));
00323     else
00324         ec = AEPutPtr (list, n, typeExtended, (Ptr)value, sizeof (value));
00325     
00326     IACglobals.errorcode = ec;
00327     
00328     return (ec == noErr);
00329     } /*IACpushdoubleitem*/
00330 
00331 
00332 #elif DOUBLE_BYTES == 10
00333 
00334 Boolean IACpushdoubleparam (double val, OSType keyword) {
00335     
00336     register OSErr ec;
00337     
00338     ec = AEPutParamPtr (
00339         
00340         IACglobals.event, (AEKeyword) keyword, typeExtended, 
00341         
00342         (Ptr) &val, sizeof (val));
00343         
00344     IACglobals.errorcode = ec;
00345     
00346     return (ec == noErr);
00347     } /*IACpushdoubleparam*/
00348 
00349 
00350 Boolean IACreturndouble (double x) {
00351     
00352     register OSErr ec;
00353     
00354     ec = AEPutParamPtr (
00355         
00356         IACglobals.reply, keyDirectObject, typeExtended, (Ptr)&x, 
00357         
00358         (Size) sizeof (x));
00359         
00360     IACglobals.errorcode = ec;
00361     
00362     return (ec == noErr);
00363     } /*IACreturndouble*/
00364 
00365 
00366 Boolean IACgetdoubleitem (AEDescList *list, long n, double *val) {
00367     
00368     register OSErr ec;
00369     DescType key;
00370     DescType typeCode;
00371     Size actualSize;
00372 
00373     if ((*list).descriptorType == typeAERecord) {
00374         
00375         ec = AEGetKeyPtr (list, n, typeExtended, &typeCode, (Ptr)val, sizeof (double), &actualSize);
00376             
00377         if (ec != errAEDescNotFound)
00378             goto done;
00379         }
00380     
00381     ec = AEGetNthPtr (list, n, typeExtended, &key, &typeCode, (Ptr)val, sizeof (double), &actualSize);
00382     
00383     done:
00384     
00385     IACglobals.errorcode = ec;
00386     
00387     return (ec == noErr);
00388     } /*IACgetdoubleitem*/
00389 
00390 
00391 Boolean IACgetdoubleparam (OSType keyword, double *val) {
00392     
00393     register OSErr ec;
00394     DescType typeCode;
00395     Size actualSize;
00396         
00397     ec = AEGetParamPtr (
00398         IACglobals.event, (AEKeyword) keyword, typeExtended,
00399 
00400         &typeCode, (Ptr)val, sizeof (double), &actualSize);
00401                 
00402     IACglobals.errorcode = ec;
00403     
00404     return (ec == noErr);
00405     } /*IACgetdoubleitem*/
00406 
00407 
00408 Boolean IACpushdoubleitem (AEDescList *list, double val, long n) {
00409     
00410     register OSErr ec;
00411 
00412     if ((*list).descriptorType == typeAERecord)
00413         ec = AEPutKeyPtr (list, n, typeExtended, (Ptr)&val, sizeof (double));
00414     else
00415         ec = AEPutPtr (list, n, typeExtended, (Ptr)&val, sizeof (double));
00416     
00417     IACglobals.errorcode = ec;
00418     
00419     return (ec == noErr);
00420     } /*IACpushdoubleitem*/
00421 
00422 
00423 #else
00424 
00425 #error Invalid value of DOUBLE_BYTES (see top of file)
00426 
00427 #endif
00428 
00429 

Generated on Wed May 31 18:19:48 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6