home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 March / CMCD0304.ISO / Software / Freeware / Programare / nullsoft / nsis20.exe / Contrib / Math / Source / MyMath.h < prev    next >
C/C++ Source or Header  |  2003-09-22  |  4KB  |  163 lines

  1. #pragma once
  2.  
  3. #define DEFAULT_ARRAY_SIZE  1024
  4.  
  5. #define ITEMTYPE        0xFF0000
  6. // items classes
  7. #define IT_CONST        0x000000
  8. #define IT_EXPRESSION   0x010000
  9. #define IT_OPERATOR     0x020000
  10. #define IT_VARIABLE     0x030000
  11. #define IT_LOGIC        0x040000    // flow control items
  12. #define IT_FUNCTION     0x050000
  13. #define IT_ARRAY        0x060000    // array operation
  14.  
  15. #define ITEMSUBTYPE 0x00FF00
  16. // const items
  17. #define ITC_STRING  0x000100
  18. #define ITC_FLOAT   0x000200
  19. #define ITC_INT     0x000400
  20. #define ITC_ARRAY   0x000800
  21. #define ITC_UNKNOWN 0x001000
  22.  
  23. // type function
  24. #define FTT_FLOATF  (ITC_UNKNOWN << 0)
  25. #define FTT_LEN     (ITC_UNKNOWN << 1)
  26. #define FTT_CHAR    (ITC_UNKNOWN << 2)
  27.  
  28. // additional option - for "ca" function
  29. #define ITFA_COPY   0x000001
  30.  
  31. // ops items
  32. #define ITO_MINUS   0x000100
  33. #define ITO_PLUS    0x000200
  34. #define ITO_SHL     0x000300
  35. #define ITO_SHR     0x000400
  36. #define ITO_MUL     0x000500
  37. #define ITO_DIV     0x000600
  38. #define ITO_SET     0x000700
  39. #define ITO_LAND    0x000800
  40. #define ITO_LOR     0x000900
  41. #define ITO_INC     0x000A00
  42. #define ITO_DEC     0x000B00
  43. #define ITO_LE      0x000C00
  44. #define ITO_GE      0x000D00
  45. #define ITO_NE      0x000E00
  46. #define ITO_EQ      0x000F00
  47. #define ITO_LS      0x001000
  48. #define ITO_GR      0x001100
  49. #define ITO_AND     0x001200
  50. #define ITO_MOD     0x001300
  51. #define ITO_OR      0x001400
  52. #define ITO_XOR     0x001500
  53. #define ITO_NOT     0x001600
  54. #define ITO_LNOT    0x001700
  55.  
  56. // variables sub-types
  57. #define ITV_NSIS    0x000100
  58. #define ITV_USER    0x000200
  59. #define ITV_ARRITEM 0x000400
  60. #define ITV_STACK   0x000800    // plugin specific stack
  61. #define ITV_NSTACK  0x001000    // nsis stack
  62.  
  63. // logic sub-types
  64. #define ITL_IF      0x000100
  65. #define ITL_WHILE   0x000200
  66.  
  67. // function sub-types
  68. #define ITF_MATH1   0x000100
  69. #define ITF_MATH2   0x000200
  70. #define ITF_TYPE    0x000300
  71. #define ITF_USER    0x000400
  72.  
  73. // array items sub-types
  74. #define ITA_ACCESS  0x000000
  75.  
  76. #define ITEMOPTIONS 0x0000FF
  77.  
  78. // 16 bytes structure
  79. typedef struct __ExpressionItem ExpressionItem;
  80. //#define EIPARAM int
  81. #define EIPARAM ExpressionItem*
  82. typedef struct __ExpressionItem
  83. {
  84.     int type;
  85.     EIPARAM param1;
  86.     EIPARAM param2;
  87.     ExpressionItem *next;
  88. } ExpressionItem;
  89.  
  90. typedef struct __ParseInfo
  91. {
  92.     int SetupNewRoot;
  93.     ExpressionItem *item;
  94.     ExpressionItem *OpsStack;
  95.     ExpressionItem *&place;
  96.     ExpressionItem **root;
  97. char valbuf[108];
  98. } ParseInfo;
  99.  
  100. #define OPERATOR_SET_PRECEDENCE 14
  101. typedef struct __OpStruct
  102. {
  103.     char name[3];
  104.     unsigned char precedence;
  105.     unsigned short int type;
  106. } OpStruct;
  107.  
  108. #define MAX_USER_VARS   256
  109. typedef struct __UserVar
  110. {
  111.     char name[28];
  112.     ExpressionItem *item;
  113. } UserVar;
  114.  
  115. #define MAX_USER_FUNCS  256
  116. typedef struct __UserFunc
  117. {
  118.     char name[20];
  119.     unsigned char vars[31];
  120.     unsigned char varsnum;
  121.     unsigned int varflags;
  122.     ExpressionItem *root;
  123. } UserFunc;
  124.  
  125. typedef struct __ArrayDesc
  126. {
  127.     ExpressionItem **array;
  128.     int size;   // size of allocated items pool
  129.     int count;  // max number of item accessed
  130.     int references; // array will be killed at CleanupItems only when references == 0
  131. } ArrayDesc;
  132.  
  133. typedef double (*Math1FuncPtr)(double arg);
  134. typedef double (*Math2FuncPtr)(double arg, double arg2);
  135. typedef double (*Math2iFuncPtr)(double arg, int *arg2);
  136. typedef double (*Math2dFuncPtr)(double arg, double *arg2);
  137.  
  138. typedef struct __MathFunction
  139. {
  140.     char name[3];
  141.     unsigned char type;
  142.     Math1FuncPtr fptr;
  143. } MathFunction;
  144.  
  145. #define STI_STRING   0x0100
  146. #define STI_FLOAT    0x0200
  147. #define STI_INT      0x0400
  148.  
  149. #define FF_DEFAULT   0x00     // uses default mode: if available noexp, else exp
  150. #define FF_NOEXP     0x10     // uses noexp mode
  151. #define FF_EXP       0x20     // uses exp mode (small e)
  152. #define FF_LEXP      0x40     // uses exp mode (large E)
  153.  
  154. // RunTree options
  155. #define RTO_NEEDCONST   0x0001
  156. #define RTO_PREFFEREDTYPE   0xFF00
  157. void RunTree(ExpressionItem *from, ExpressionItem* &result, int type);
  158.  
  159. void StringToItem(char *&sbuf, ExpressionItem *item, int options);
  160. void ItemToString(char *sbuf, ExpressionItem *item);
  161. void FloatFormat(char *sbuf, double value, int options);
  162. void itoa64(__int64 i, char *buffer);
  163. int lstrcmpn(char *s1, const char *s2, int chars);