home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / Programming Stuff / Documentation / develop / develop Issue 12 / develop 12 code / Components / MoMathComponent.c < prev    next >
Encoding:
Text File  |  1992-10-16  |  3.7 KB  |  170 lines  |  [TEXT/KAHL]

  1. /*
  2.     File:        MoMathComponent.c
  3.  
  4.     Contains:    Extended math component routines.
  5.  
  6.     Written by:    Gary Woodcock
  7.  
  8.     Copyright:    © 1992 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12. */
  13.  
  14. //-----------------------------------------------------------------------
  15. // Includes
  16.  
  17. #include "MathComponent.h"
  18. #include "MathComponentPrivate.h"
  19. #include "MathComponentCommon.h"
  20. #include "MoMathComponent.h"
  21. #include "MoMathComponentPrivate.h"
  22. #include <Errors.h>
  23.  
  24. //-----------------------------------------------------------------------
  25.  
  26. #ifdef DEBUG_IT
  27.  
  28. // Use this declaration when we're running linked (for debugging)
  29. pascal    ComponentResult    MoMathDispatcher    (ComponentParameters    *params,
  30.                                              Handle                    storage)
  31.                                              
  32. #else
  33.  
  34. // Use this declaration when we're a standalone component
  35. pascal    ComponentResult    main    (ComponentParameters    *params,
  36.                                  Handle                    storage)
  37.  
  38. #endif DEBUG_IT
  39.  
  40. {
  41.     // This routine is the main dispatcher for the MoMath component
  42.     
  43.     ComponentResult    result = noErr;
  44.     
  45.     // Did we get a Component Manager request code (< 0)?
  46.     if (params->what < 0)
  47.     {
  48.         switch (params->what)
  49.         {
  50.             case kComponentOpenSelect:        // Open request
  51.             {
  52.                 result = CallComponentFunctionWithStorage (storage, params,
  53.                     (ComponentFunction) _MathOpen);
  54.                 break;
  55.             }
  56.             case kComponentCloseSelect:        // Close request
  57.             {
  58.                 result = CallComponentFunctionWithStorage (storage, params,
  59.                     (ComponentFunction) _MathClose);
  60.                 break;
  61.             }
  62.             case kComponentCanDoSelect:        // Can Do request
  63.             {
  64.                 result = CallComponentFunction (params, 
  65.                     (ComponentFunction) _MoMathCanDo);
  66.                 break;
  67.             }
  68.             case kComponentVersionSelect:    // Version request
  69.             {
  70.                 result = CallComponentFunction (params,
  71.                     (ComponentFunction) _MathVersion);
  72.                 break;
  73.             }
  74.             case kComponentTargetSelect:    // Target request
  75.             {
  76.                 result = CallComponentFunctionWithStorage (storage, params,
  77.                     (ComponentFunction) _MathTarget);
  78.                 break;
  79.             }
  80.             case kComponentRegisterSelect:    // Register request not supported
  81.             default:                        // Unknown request
  82.             {
  83.                 result = paramErr;
  84.                 break;
  85.             }
  86.         }
  87.     }
  88.     else    // Was it one of our request codes?
  89.     {
  90.         switch (params->what)
  91.         {
  92.             // math component selectors
  93.             case kDoDivideSelect:            // Divide request
  94.             {
  95.                 result = CallComponentFunction (params, 
  96.                     (ComponentFunction) _MathDoDivide);
  97.                 break;
  98.             }
  99.             
  100.             case kDoMultiplySelect:            // Multiply request
  101.             {
  102.                 result = CallComponentFunction (params, 
  103.                     (ComponentFunction) _MathDoMultiply);
  104.                 break;
  105.             }
  106.             
  107.             case kDoAddSelect:                // Add request
  108.             {
  109.                 result = CallComponentFunction (params,
  110.                     (ComponentFunction) _MoMathDoAdd);
  111.                 break;
  112.             }
  113.             
  114.             default:                        // Unknown request
  115.             {
  116.                 result = paramErr;
  117.                 break;
  118.             }
  119.         }
  120.     }
  121.     return (result);
  122. }
  123.                                              
  124. //-----------------------------------------------------------------------
  125.  
  126. pascal    ComponentResult    _MoMathCanDo    (short    selector)
  127. {
  128.     switch (selector)
  129.     {
  130.         // Component Manager request codes
  131.         case kComponentOpenSelect:
  132.         case kComponentCloseSelect:
  133.         case kComponentCanDoSelect:
  134.         case kComponentVersionSelect:
  135.         case kComponentTargetSelect:
  136.         
  137.         // Math component request codes
  138.         case kDoDivideSelect:
  139.         case kDoMultiplySelect:
  140.     
  141.         // MoMath component request codes
  142.         case kDoAddSelect:
  143.         {
  144.             return (true);
  145.         }
  146.         case kComponentRegisterSelect:    // Register request not supported
  147.         default:                        // Not a request code we recognize
  148.         {
  149.             return (false);
  150.         }
  151.     }
  152. }
  153.  
  154. //-----------------------------------------------------------------------
  155.  
  156. pascal    ComponentResult    _MoMathDoAdd    (short    firstNum,
  157.                                          short    secondNum,
  158.                                          short    *additionResult)
  159. {
  160.     ComponentResult    result = noErr;
  161.     
  162.     *additionResult = firstNum + secondNum;
  163.  
  164.     return (result);
  165. }
  166.  
  167. //-----------------------------------------------------------------------
  168.  
  169.  
  170.