home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / Magazine / HomeAutomation / Apache / include / php / Zend / zend_operators.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-18  |  8.4 KB  |  226 lines

  1. /*
  2.    +----------------------------------------------------------------------+
  3.    | Zend Engine                                                          |
  4.    +----------------------------------------------------------------------+
  5.    | Copyright (c) 1998-2000 Zend Technologies Ltd. (http://www.zend.com) |
  6.    +----------------------------------------------------------------------+
  7.    | This source file is subject to version 0.92 of the Zend license,     |
  8.    | that is bundled with this package in the file LICENSE, and is        | 
  9.    | available at through the world-wide-web at                           |
  10.    | http://www.zend.com/license/0_92.txt.                                |
  11.    | If you did not receive a copy of the Zend license and are unable to  |
  12.    | obtain it through the world-wide-web, please send a note to          |
  13.    | license@zend.com so we can mail you a copy immediately.              |
  14.    +----------------------------------------------------------------------+
  15.    | Authors: Andi Gutmans <andi@zend.com>                                |
  16.    |          Zeev Suraski <zeev@zend.com>                                |
  17.    +----------------------------------------------------------------------+
  18. */
  19.  
  20.  
  21. #ifndef _OPERATORS_H
  22. #define _OPERATORS_H
  23.  
  24. #include <errno.h>
  25. #include <math.h>
  26.  
  27. #ifdef HAVE_IEEEFP_H
  28. #include <ieeefp.h>
  29. #endif
  30.  
  31. #if WITH_BCMATH
  32. #include "ext/bcmath/number.h"
  33. #endif
  34.  
  35. #define MAX_LENGTH_OF_LONG 18
  36. #define MAX_LENGTH_OF_DOUBLE 32
  37.  
  38. ZEND_API int add_function(zval *result, zval *op1, zval *op2);
  39. ZEND_API int sub_function(zval *result, zval *op1, zval *op2);
  40. ZEND_API int mul_function(zval *result, zval *op1, zval *op2);
  41. ZEND_API int div_function(zval *result, zval *op1, zval *op2);
  42. ZEND_API int mod_function(zval *result, zval *op1, zval *op2);
  43. ZEND_API int boolean_or_function(zval *result, zval *op1, zval *op2);
  44. ZEND_API int boolean_xor_function(zval *result, zval *op1, zval *op2);
  45. ZEND_API int boolean_and_function(zval *result, zval *op1, zval *op2);
  46. ZEND_API int boolean_not_function(zval *result, zval *op1);
  47. ZEND_API int bitwise_not_function(zval *result, zval *op1);
  48. ZEND_API int bitwise_or_function(zval *result, zval *op1, zval *op2);
  49. ZEND_API int bitwise_and_function(zval *result, zval *op1, zval *op2);
  50. ZEND_API int bitwise_xor_function(zval *result, zval *op1, zval *op2);
  51. ZEND_API int shift_left_function(zval *result, zval *op1, zval *op2);
  52. ZEND_API int shift_right_function(zval *result, zval *op1, zval *op2);
  53. ZEND_API int concat_function(zval *result, zval *op1, zval *op2);
  54.  
  55. ZEND_API int is_equal_function(zval *result, zval *op1, zval *op2);
  56. ZEND_API int is_identical_function(zval *result, zval *op1, zval *op2);
  57. ZEND_API int is_not_identical_function(zval *result, zval *op1, zval *op2);
  58. ZEND_API int is_not_equal_function(zval *result, zval *op1, zval *op2);
  59. ZEND_API int is_smaller_function(zval *result, zval *op1, zval *op2);
  60. ZEND_API int is_smaller_or_equal_function(zval *result, zval *op1, zval *op2);
  61. ZEND_API inline int is_numeric_string(char *str, int length, long *lval, double *dval)
  62. #if defined(C9X_INLINE_SEMANTICS)
  63. {
  64.     long local_lval;
  65.     double local_dval;
  66.     char *end_ptr;
  67.  
  68.     if (!length) {
  69.         return 0;
  70.     }
  71.     
  72.     errno=0;
  73.     local_lval = strtol(str, &end_ptr, 10);
  74.     if (errno!=ERANGE && end_ptr == str+length) { /* integer string */
  75.         if (lval) {
  76.             *lval = local_lval;
  77.         }
  78.         return IS_LONG;
  79.     }
  80.  
  81.     errno=0;
  82.     local_dval = strtod(str, &end_ptr);
  83.     if (errno!=ERANGE && end_ptr == str+length) { /* floating point string */
  84.         if (! zend_finite(local_dval)) {
  85.             /* "inf","nan" and maybe other weird ones */
  86.             return 0;
  87.         }
  88.  
  89.         if (dval) {
  90.             *dval = local_dval;
  91.         }
  92. #if WITH_BCMATH
  93.         if (length>16) {
  94.             register char *ptr=str, *end=str+length;
  95.             
  96.             while(ptr<end) {
  97.                 switch(*ptr++) {
  98.                     case 'e':
  99.                     case 'E':
  100.                         /* scientific notation, not handled by the BC library */
  101.                         return IS_DOUBLE;
  102.                         break;
  103.                     default:
  104.                         break;
  105.                 }
  106.             }
  107.             return FLAG_IS_BC;
  108.         } else {
  109.             return IS_DOUBLE;
  110.         }
  111. #else
  112.         return IS_DOUBLE;
  113. #endif
  114.     }
  115.     
  116.     return 0;
  117. }
  118. #else
  119. ;
  120. #endif
  121.  
  122. ZEND_API int increment_function(zval *op1);
  123. ZEND_API int decrement_function(zval *op2);
  124.  
  125. BEGIN_EXTERN_C()
  126. ZEND_API void convert_scalar_to_number(zval *op);
  127. ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC);
  128. ZEND_API void convert_to_long(zval *op);
  129. ZEND_API void convert_to_double(zval *op);
  130. ZEND_API void convert_to_long_base(zval *op, int base);
  131. ZEND_API void convert_to_null(zval *op);
  132. ZEND_API void convert_to_boolean(zval *op);
  133. ZEND_API void convert_to_array(zval *op);
  134. ZEND_API void convert_to_object(zval *op);
  135. ZEND_API int add_char_to_string(zval *result, zval *op1, zval *op2);
  136. ZEND_API int add_string_to_string(zval *result, zval *op1, zval *op2);
  137. #define convert_to_string(op)            _convert_to_string((op) ZEND_FILE_LINE_CC)
  138.  
  139. ZEND_API double zend_string_to_double(const char *number, zend_uint length);
  140. END_EXTERN_C()
  141.  
  142. ZEND_API int zval_is_true(zval *op);
  143. ZEND_API int compare_function(zval *result, zval *op1, zval *op2);
  144. ZEND_API int numeric_compare_function(zval *result, zval *op1, zval *op2);
  145. ZEND_API int string_compare_function(zval *result, zval *op1, zval *op2);
  146.  
  147. ZEND_API void zend_str_tolower(char *str, unsigned int length);
  148. ZEND_API int zend_binary_zval_strcmp(zval *s1, zval *s2);
  149. ZEND_API int zend_binary_zval_strncmp(zval *s1, zval *s2, zval *s3);
  150. ZEND_API int zend_binary_zval_strcasecmp(zval *s1, zval *s2);
  151. ZEND_API int zend_binary_strcmp(char *s1, uint len1, char *s2, uint len2);
  152. ZEND_API int zend_binary_strncmp(char *s1, uint len1, char *s2, uint len2, uint length);
  153. ZEND_API int zend_binary_strcasecmp(char *s1, uint len1, char *s2, uint len2);
  154.  
  155. ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2);
  156. ZEND_API void zend_compare_symbol_tables(zval *result, HashTable *ht1, HashTable *ht2);
  157. ZEND_API void zend_compare_arrays(zval *result, zval *a1, zval *a2);
  158. ZEND_API void zend_compare_objects(zval *result, zval *o1, zval *o2);
  159.  
  160.  
  161. #define convert_to_ex_master(ppzv, lower_type, upper_type)    \
  162.     if ((*ppzv)->type!=IS_##upper_type) {                    \
  163.         if (!(*ppzv)->is_ref) {                                \
  164.             SEPARATE_ZVAL(ppzv);                            \
  165.         }                                                    \
  166.         convert_to_##lower_type(*ppzv);                        \
  167.     }
  168.  
  169. #define convert_to_writable_ex_master(ppzv, lower_type, upper_type)    \
  170.     if ((*ppzv)->type!=IS_##upper_type) {                            \
  171.         SEPARATE_ZVAL(ppzv);                                        \
  172.         convert_to_##lower_type(*ppzv);                                \
  173.     }
  174.  
  175.  
  176. #define convert_to_boolean_ex(ppzv)    convert_to_ex_master(ppzv, boolean, BOOL)
  177. #define convert_to_long_ex(ppzv)    convert_to_ex_master(ppzv, long, LONG)
  178. #define convert_to_double_ex(ppzv)    convert_to_ex_master(ppzv, double, DOUBLE)
  179. #define convert_to_string_ex(ppzv)    convert_to_ex_master(ppzv, string, STRING)
  180. #define convert_to_array_ex(ppzv)    convert_to_ex_master(ppzv, array, ARRAY)
  181. #define convert_to_object_ex(ppzv)    convert_to_ex_master(ppzv, object, OBJECT)
  182. #define convert_to_null_ex(ppzv)    convert_to_ex_master(ppzv, null, NULL)
  183.  
  184. #define convert_to_writable_boolean_ex(ppzv)    convert_to_writable_ex_master(ppzv, boolean, BOOL)
  185. #define convert_to_writable_long_ex(ppzv)        convert_to_writable_ex_master(ppzv, long, LONG)
  186. #define convert_to_writable_double_ex(ppzv)        convert_to_writable_ex_master(ppzv, double, DOUBLE)
  187. #define convert_to_writable_string_ex(ppzv)        convert_to_writable_ex_master(ppzv, string, STRING)
  188. #define convert_to_writable_array_ex(ppzv)        convert_to_writable_ex_master(ppzv, array, ARRAY)
  189. #define convert_to_writable_object_ex(ppzv)        convert_to_writable_ex_master(ppzv, object, OBJECT)
  190. #define convert_to_writable_null_ex(ppzv)        convert_to_writable_ex_master(ppzv, null, NULL)
  191.  
  192.  
  193. #define convert_scalar_to_number_ex(ppzv)                            \
  194.     if ((*ppzv)->type!=IS_LONG && (*ppzv)->type!=IS_DOUBLE) {        \
  195.         if (!(*ppzv)->is_ref) {                                        \
  196.             SEPARATE_ZVAL(ppzv);                                    \
  197.         }                                                            \
  198.         convert_scalar_to_number(*ppzv);                            \
  199.     }
  200.  
  201.  
  202.  
  203. #define Z_LVAL(zval)        (zval).value.lval
  204. #define Z_DVAL(zval)        (zval).value.dval
  205. #define Z_STRVAL(zval)        (zval).value.str.val
  206. #define Z_STRLEN(zval)        (zval).value.str.len
  207. #define Z_ARRVAL(zval)        (zval).value.ht
  208.  
  209. #define Z_LVAL_P(zval_p)        Z_LVAL(*zval_p)
  210. #define Z_DVAL_P(zval_p)        Z_DVAL(*zval_p)
  211. #define Z_STRVAL_P(zval_p)        Z_STRVAL(*zval_p)
  212. #define Z_STRLEN_P(zval_p)        Z_STRLEN(*zval_p)
  213. #define Z_ARRVAL_P(zval_p)        Z_ARRVAL(*zval_p)
  214.  
  215. #define Z_LVAL_PP(zval_pp)        Z_LVAL(**zval_pp)
  216. #define Z_DVAL_PP(zval_pp)        Z_DVAL(**zval_pp)
  217. #define Z_STRVAL_PP(zval_pp)    Z_STRVAL(**zval_pp)
  218. #define Z_STRLEN_PP(zval_pp)    Z_STRLEN(**zval_pp)
  219. #define Z_ARRVAL_PP(zval_pp)    Z_ARRVAL(**zval_pp)
  220.  
  221. #define Z_TYPE(zval)        (zval).type
  222. #define Z_TYPE_P(zval_p)    Z_TYPE(*zval_p)
  223. #define Z_TYPE_PP(zval_pp)    Z_TYPE(**zval_pp)
  224.  
  225. #endif
  226.