home *** CD-ROM | disk | FTP | other *** search
- /*
- File: TestMathFSet.c
-
- Contains: MPW tool that will demonstrate how to use GetFunctionInfo.
-
- Copyright: © 1993 by Apple Computer, Inc., all rights reserved.
-
- */
-
-
- #ifndef __MATHFSET__
- #include "MathFSet.h"
- #endif
-
- #ifndef __LIBRARYMANAGERUTILITIES__
- #include <LibraryManagerUtilities.h>
- #endif
-
-
- int main()
- {
- OSErr err;
- TFunctionSetID id;
- MathFunction1ProcPtr func1;
- MathFunction2ProcPtr func2;
- TFunctionSetInfo* info;
-
- err = InitLibraryManager(0, kCurrentZone, kNormalMemory);
- if (err != kNoError)
- {
- printf("### ERROR: InitLibraryManager failed. errror=%d\n", err);
- return 1;
- }
-
- // Get the TFunctionSetInfo object we will use to iterate over all known function
- // sets that specified a interface of kMathFSetInterfaceID.
-
- info = GetFunctionSetInfo(kMathFSetInterfaceID, &err);
- if (info == NULL)
- {
- printf("### ERROR: #%d getting the TFunctionSetInfo object\n", err);
- return 1;
- }
-
- // Iterate over all the functions sets with an interface of kMathFSetInterfaceID,
- // calling the MathFunction1 and MathFunction2 functions for each one.
-
- while (id = FSInfoNext(info))
- {
- // At this point we could make calls like FSInfoGetLibraryFile,
- // FSInfoGetVersion, and FSInfoGetLibrary. FSInfoGetLibraryFile can
- // be useful for opening up the library file that the function set
- // is in and getting a resource that has a "user readable" name
- // for the function set that you can display for a user so he
- // can choose which function set he wants.
-
- printf("\nCalling functions for %s function set.\n", id);
-
- func1 = GetFunctionPointer(id, kMathFunctionName1, &err);
- if (err == kNoError)
- {
- int result = (*func1)(5,2);
- printf("MathFunction1(5,2) = %d.\n",result);
- }
- else
- printf("### ERROR: #%d getting MathFunction1\n", err);
-
- func2 = GetFunctionPointer(id, kMathFunctionName2, &err);
- if (err == kNoError)
- {
- int result = (*func2)(4,3,2);
- printf("MathFunction2(4,3,2) = %d.\n",result);
- }
- else
- printf("### ERROR: #%d getting MathFunction2\n", err);
- }
-
- // Free up the memory that the TFunctionSetInfo used up
- FreeFunctionSetInfo(info);
-
- CleanupLibraryManager();
-
- return 0;
- }
-