home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p024 / 12.img / ADS1.LIB / CALMNGF.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-26  |  5.0 KB  |  168 lines

  1. /*****************************************************************************
  2.       CALMNGF.C
  3.       (C) ¬⌐┼v 1988-1992  Autodesk ñ╜Ñq
  4.  
  5.       Ñ╗╡{ªíñwÑ╤ Autodesk ñ╜Ñq╡∙ÑU¬⌐┼v, ╢╚⌐≤ñU¡z▒í¬pñUÑi▒┬╗P▒zíu│\ÑiívíC
  6.       ╗╒ñUñú▒oÑHÑ⌠ª≤º╬ªí╡oªµ⌐╬ÑX¬⌐ª╣╡{ªí¬║íu¡∞⌐l╜Xív; ª²ñ╣│\▒zªb»S⌐w¡lÑ═
  7.       ¬║ñuº@ñW╡▓ªXª╣╡{ªí¬║íuÑ╪¬║╜Xív¿╧Ñ╬íCª│├÷│o├■¡lÑ═ñuº@¬║▒°Ñ≤ªpñU:
  8.  
  9.       ( i)  │]¡pñW╗Pñuº@ñW¼╥»┬║Θ░w╣∩ Autodesk ñ╜Ñq¬║▓ú½~íC
  10.       (ii)  ╕ⁿª│íu¬⌐┼v  (C) 1988-1992  Autodesk ñ╜Ñqív¬║¬⌐┼v│qºiíC
  11.  
  12.  
  13.  
  14.       AUTODESKñ╜Ñq┤ú¿╤ª╣╡{ªí╢╚¿╤º@íu├■ªⁿív¬║░╤ª╥, ª╙ÑBñú▒╞░úª│Ñ⌠ª≤┐∙╗~¬║
  15.       Ñi»αíCAUTODESKñ╜Ñq»Sª╣º_╗{Ñ⌠ª≤»S⌐wÑ╬│~ñº╛A║┘⌐╩, ÑHñ╬░╙╖~╛P░Γ⌐╥┴⌠ºt
  16.       ÑX¿π¬║½O├╥íCAUTODESKñ╜ÑqªP«╔ÑτñúÑX¿πª╣╡{ªí░⌡ªµ«╔ñ@⌐wñú╖|íuññ┬_ív⌐╬
  17.       íuº╣Ñ■╡L╗~ív¬║½O├╥íC
  18.  
  19.  
  20.   Description: Management of the table of calculator functions.
  21.  
  22. *****************************************************************************/
  23.  
  24.  
  25. /****************************************************************************/
  26. /*  INCLUDES                                                                */
  27. /****************************************************************************/
  28.  
  29. #include "cal.h"
  30.  
  31.  
  32. /****************************************************************************/
  33. /*  EXPORTED VARIABLES                                                      */
  34. /****************************************************************************/
  35.  
  36. cft cal_funcs_table;                  /* Table of calculator functions  */
  37. int cal_funcs_number = 0;             /* Number of calculator functions */
  38.  
  39. /* Variables for passing actual parameters to calculator functions
  40.    and returning the value from the function:
  41.  
  42.    Before a calculator function is called, its acutal parameters must
  43.    be stored in global array 'params[]'. The function returns its result
  44.    in global variable 'result'. See functions in module 'calstdf.c'.
  45. */
  46.  
  47. int             no_of_params;
  48. vector_real_int params[MAX_FUNC_PARAM];
  49. vector_real_int result;
  50.  
  51.  
  52. /****************************************************************************/
  53. /*.doc cal_register_function(external)*/
  54. /*+
  55.   Function registers new calculator function. 'func_name' is the
  56.   name of the function which will be used to refer to this function
  57.   in arithmetic expressions, 'func_ptr' is a pointer to the function
  58.   definition. If the function fails, it prints an error message
  59.   and terminates the ADS application.
  60. -*/
  61. /****************************************************************************/
  62.  
  63.  
  64. void
  65. /*FCN*/cal_register_function(func_name, func_ptr)
  66.  
  67.   char *func_name;
  68.   void (*func_ptr)();
  69. {
  70.     int  i;
  71.     char name[MAX_SYMBOL_LENGTH+1];
  72.     int  len;
  73.  
  74.     if (cal_err)
  75.         return;
  76.  
  77.     /* Do initial checking */
  78.  
  79.     if (cal_funcs_number >= MAX_CAL_FUNC) {
  80.         error(44, NULL);
  81.         return;
  82.     }
  83.  
  84.     if (func_name == NULL) {
  85.         error(46, NULL);
  86.         return;
  87.     }
  88.  
  89.     len = strlen(func_name);
  90.  
  91.     if (len > MAX_SYMBOL_LENGTH) {
  92.         error(47, func_name);
  93.         return;
  94.     }
  95.  
  96.     /* Check whether the function name is an identifier */
  97.  
  98.     strcpy(name, func_name);
  99.  
  100.     if (!ads_isalpha(name[0])) {
  101.         error(42, func_name);
  102.         return;
  103.     }
  104.     for (i = 0; i < len; i++) {
  105.         name[i] = ads_toupper(name[i]);
  106.         if (!ads_isalnum(name[i]) && (name[i] != '_')) {
  107.             error(42, func_name);
  108.             return;
  109.         }
  110.     }
  111.  
  112.     /* Check whether function of this name wasn't already registered */
  113.  
  114.     for (i = 0; i < cal_funcs_number; i++) {
  115.         if (strcmp(cal_funcs_table[i].name, name) == 0) {
  116.             error(60, func_name);
  117.             return;
  118.         }
  119.     }
  120.  
  121.     /* Insert the new calculator function at the end of the table */
  122.  
  123.     strcpy(cal_funcs_table[cal_funcs_number].name, name);
  124.     cal_funcs_table[cal_funcs_number].func = func_ptr;
  125.     cal_funcs_number++;
  126.  
  127. } /*cal_register_function*/
  128.  
  129.  
  130. /****************************************************************************/
  131. /*.doc cal_invoke_function(external)*/
  132. /*+
  133.   Invoke calculator function whose name is 'func_name'.
  134.  
  135.   Before a function is invoked, the function parameters must be stored in
  136.   array'params[]', the number of actual parameters in 'no_of_params'. The
  137.   invoked function returns its result in 'result'.
  138.  
  139.   Function returns TRUE if function 'func_name' was successfully invoked
  140.   and the invoked function succeeded, otherwise FALSE is returned. You can
  141.   use 'cal_err' variable to check the reason why the invocation failed.
  142. -*/
  143. /****************************************************************************/
  144.  
  145.  
  146. int
  147. /*FCN*/cal_invoke_function(func_name)
  148.  
  149.   char *func_name;
  150. {
  151.     int i;
  152.  
  153.     if (cal_err)
  154.         return(FALSE);
  155.  
  156.     for (i = 0; i < cal_funcs_number; i++) {
  157.         if (strcmp(func_name, cal_funcs_table[i].name) == 0) {
  158.             (*cal_funcs_table[i].func)();
  159.             return(cal_err == 0);
  160.         }
  161.     } /*for*/
  162.  
  163.     error(52, func_name);
  164.     return(FALSE);
  165. } /*cal_invoke_function*/
  166.  
  167.  
  168.