functions.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * PROGRAM: InterBase Access Method
  3. * MODULE: functions.c
  4. * DESCRIPTION: External entrypoint definitions
  5. *
  6. * The contents of this file are subject to the Interbase Public
  7. * License Version 1.0 (the "License"); you may not use this file
  8. * except in compliance with the License. You may obtain a copy
  9. * of the License at http://www.Inprise.com/IPL.html
  10. *
  11. * Software distributed under the License is distributed on an
  12. * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
  13. * or implied. See the License for the specific language governing
  14. * rights and limitations under the License.
  15. *
  16. * The Original Code was created by Inprise Corporation
  17. * and its predecessors. Portions created by Inprise Corporation are
  18. * Copyright (C) Inprise Corporation.
  19. *
  20. * All Rights Reserved.
  21. * Contributor(s): ______________________________________.
  22. */
  23. typedef int (*FUN_PTR)();
  24. typedef struct {
  25. char *fn_module;
  26. char *fn_entrypoint;
  27. FUN_PTR fn_function;
  28. } FN;
  29. static test();
  30. extern char *fn_lower_c();
  31. extern char *fn_strcat();
  32. extern char *fn_substr();
  33. extern char *fn_trim();
  34. extern char *fn_trunc();
  35. extern int fn_doy();
  36. extern short *fn_moy();
  37. extern char *fn_dow();
  38. extern char *fn_sysdate();
  39. extern int fn_add2();
  40. extern double fn_mul();
  41. extern double fn_fact();
  42. extern double fn_abs();
  43. extern double fn_max();
  44. extern double fn_sqrt();
  45. extern int fn_blob_linecount();
  46. extern int fn_blob_bytecount();
  47. extern char *fn_blob_substr();
  48. static FN isc_functions [] = {
  49. "test_module", "test_function", test,
  50. "FUNCLIB", "fn_lower_c", (FUN_PTR) fn_lower_c,
  51. "FUNCLIB", "fn_strcat", (FUN_PTR) fn_strcat,
  52. "FUNCLIB", "fn_substr", (FUN_PTR) fn_substr,
  53. "FUNCLIB", "fn_trim", (FUN_PTR) fn_trim,
  54. "FUNCLIB", "fn_trunc", (FUN_PTR) fn_trunc,
  55. "FUNCLIB", "fn_doy", (FUN_PTR) fn_doy,
  56. "FUNCLIB", "fn_moy", (FUN_PTR) fn_moy,
  57. "FUNCLIB", "fn_dow", (FUN_PTR) fn_dow,
  58. "FUNCLIB", "fn_sysdate", (FUN_PTR) fn_sysdate,
  59. "FUNCLIB", "fn_add2", (FUN_PTR) fn_add2,
  60. "FUNCLIB", "fn_mul", (FUN_PTR) fn_mul,
  61. "FUNCLIB", "fn_fact", (FUN_PTR) fn_fact,
  62. "FUNCLIB", "fn_abs", (FUN_PTR) fn_abs,
  63. "FUNCLIB", "fn_max", (FUN_PTR) fn_max,
  64. "FUNCLIB", "fn_sqrt", (FUN_PTR) fn_sqrt,
  65. "FUNCLIB", "fn_blob_linecount", (FUN_PTR) fn_blob_linecount,
  66. "FUNCLIB", "fn_blob_bytecount", (FUN_PTR) fn_blob_bytecount,
  67. "FUNCLIB", "fn_blob_substr", (FUN_PTR) fn_blob_substr,
  68. 0, 0, 0};
  69. #ifdef SHLIB_DEFS
  70. #define strcmp (*_libfun_strcmp)
  71. #define sprintf (*_libfun_sprintf)
  72. extern int strcmp();
  73. extern int sprintf();
  74. #endif
  75. FUN_PTR FUNCTIONS_entrypoint (module, entrypoint)
  76. char *module;
  77. char *entrypoint;
  78. {
  79. /**************************************
  80. *
  81. * F U N C T I O N S _ e n t r y p o i n t
  82. *
  83. **************************************
  84. *
  85. * Functional description
  86. * Lookup function in hardcoded table. The module and
  87. * entrypoint names are null terminated, but may contain
  88. * insignificant trailing blanks.
  89. *
  90. **************************************/
  91. FN *function;
  92. char *p, temp [64], *ep;
  93. p = temp;
  94. while (*module && *module != ' ')
  95. *p++ = *module++;
  96. *p++ = 0;
  97. ep = p;
  98. while (*entrypoint && *entrypoint != ' ')
  99. *p++ = *entrypoint++;
  100. *p = 0;
  101. for (function = isc_functions; function->fn_module; ++function)
  102. if (!strcmp (temp, function->fn_module) && !strcmp (ep, function->fn_entrypoint))
  103. return function->fn_function;
  104. return 0;
  105. }
  106. static test (n, result)
  107. int n;
  108. char *result;
  109. {
  110. /**************************************
  111. *
  112. * t e s t
  113. *
  114. **************************************
  115. *
  116. * Functional description
  117. * Sample extern function. Defined in database by:
  118. *
  119. * define function test module_name "test_module" entry_point "test_function"
  120. * long by value,
  121. * char [20] by reference return_argument;
  122. *
  123. **************************************/
  124. char *end;
  125. sprintf (result, "%d is a number", n);
  126. end = result + 20;
  127. while (*result)
  128. result++;
  129. while (result < end)
  130. *result++ = ' ';
  131. }