Util.nsh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. ; ---------------------
  2. ; Util.nsh
  3. ; ---------------------
  4. ;
  5. ; Voodoo macros to make end-user usage easier. This may be documented someday.
  6. !verbose push 3
  7. !ifndef ___UTIL__NSH___
  8. !define ___UTIL__NSH___
  9. # CallArtificialFunction, see WinVer.nsh and *Func.nsh for usage examples
  10. !macro CallArtificialFunctionHelper TYPE NAME
  11. !verbose pop
  12. Call :.${NAME}${TYPE}
  13. !ifndef ${NAME}${TYPE}_DEFINED
  14. !verbose push 2
  15. Goto ${NAME}${TYPE}_DONE
  16. !define ${NAME}${TYPE}_DEFINED
  17. !verbose pop
  18. .${NAME}${TYPE}:
  19. !insertmacro ${NAME}
  20. Return
  21. ${NAME}${TYPE}_DONE:
  22. !endif
  23. !verbose push 2
  24. !macroend
  25. !macro CallArtificialFunction NAME
  26. !verbose push 2
  27. !ifdef __UNINSTALL__
  28. !insertmacro CallArtificialFunctionHelper uninst ${NAME}
  29. !else
  30. !insertmacro CallArtificialFunctionHelper inst ${NAME}
  31. !endif
  32. !verbose pop
  33. !macroend
  34. !define CallArtificialFunction `!insertmacro CallArtificialFunction`
  35. !macro CallArtificialFunction2 NAME ; Retained for v2.4x..v3.0b0 compatibility
  36. ${CallArtificialFunction} ${NAME}
  37. !macroend
  38. !define CallArtificialFunction2 `!insertmacro CallArtificialFunction`
  39. !define Int32Op '!insertmacro Int32Op '
  40. !define Int64Op '!insertmacro Int64Op '
  41. !define IntPtrOp '!insertmacro IntPtrOp '
  42. !macro Int32Op r a o b
  43. !if ${NSIS_PTR_SIZE} <= 4
  44. IntOp `${r}` `${a}` `${o}` ${b}
  45. !else
  46. !error "Int32Op not implemented"
  47. !endif
  48. !macroend
  49. !macro Int64Op r a o b
  50. !echo "Int64Op ${r}=${a}${o}${b}"
  51. !verbose push 2
  52. System::Int64Op `${a}` `${o}` ${b}
  53. Pop ${r}
  54. !verbose pop
  55. !macroend
  56. !macro IntPtrOp r a o b
  57. !if ${NSIS_PTR_SIZE} <= 4
  58. ${Int32Op} `${r}` `${a}` `${o}` `${b}`
  59. !else
  60. ${Int64Op} `${r}` `${a}` `${o}` `${b}`
  61. !endif
  62. !macroend
  63. !define Int32Cmp '!insertmacro Int32Cmp '
  64. !define Int64Cmp '!insertmacro Int64Cmp '
  65. !define IntPtrCmp '!insertmacro IntPtrCmp '
  66. !macro Int32Cmp a b jeek jles jgtr
  67. !if ${NSIS_PTR_SIZE} <= 4
  68. IntCmp `${a}` `${b}` `${jeek}` `${jles}` `${jgtr}`
  69. !else
  70. !error "Int32Cmp not implemented"
  71. !endif
  72. !macroend
  73. !macro Int64Cmp a b jeek jles jgtr
  74. !ifmacrondef _LOGICLIB_TEMP
  75. !include LogicLib.nsh
  76. !endif
  77. !echo "Int64Cmp ${a}:${b} =${jeek}, <${jles}, >${jgtr}"
  78. !verbose push 2
  79. ${IfThen} ${a} L= ${b} ${|} Goto ${jeek} ${|}
  80. !insertmacro _L< ${a} ${b} `${jles}` `${jgtr}`
  81. !verbose pop
  82. !macroend
  83. !macro IntPtrCmp a b jeek jles jgtr
  84. !if ${NSIS_PTR_SIZE} <= 4
  85. ${Int32Cmp} `${a}` `${b}` `${jeek}` `${jles}` `${jgtr}`
  86. !else
  87. ${Int64Cmp} `${a}` `${b}` `${jeek}` `${jles}` `${jgtr}`
  88. !endif
  89. !macroend
  90. !define Int32CmpU '!insertmacro Int32CmpU '
  91. !define Int64CmpU '!insertmacro Int64CmpU '
  92. !define IntPtrCmpU '!insertmacro IntPtrCmpU '
  93. !macro Int32CmpU a b jeek jles jgtr
  94. !if ${NSIS_PTR_SIZE} <= 4
  95. IntCmpU `${a}` `${b}` `${jeek}` `${jles}` `${jgtr}`
  96. !else
  97. !error "Int32CmpU not implemented"
  98. !endif
  99. !macroend
  100. !macro Int64CmpUHelper
  101. ; This macro performs "$_LOGICLIB_TEMP = a < b ? -1 : a > b ? 1 : 0" but System::Int64Op does not support unsigned operations so we have to perform multiple steps
  102. !ifmacrondef _LOGICLIB_TEMP
  103. !include LogicLib.nsh
  104. !endif
  105. !insertmacro _LOGICLIB_TEMP
  106. Exch $2 ; b
  107. Exch
  108. Exch $1 ; a
  109. ; if (a == b) return 0;
  110. ; if (a < 0)
  111. ; {
  112. ; if (b >= 0) return 1
  113. ; }
  114. ; else
  115. ; {
  116. ; if (b < 0) return -1
  117. ; }
  118. ; return a < b ? -1 : 1
  119. System::Int64Op $1 ^ $2 ; Using xor so $_LOGICLIB_TEMP ends up as 0 when they are equal
  120. Pop $_LOGICLIB_TEMP
  121. StrCmp $_LOGICLIB_TEMP 0 ret ; NOTE: Must use StrCmp, IntCmp fails on "0x8000000000000001 Z> 1"
  122. System::Int64Op $1 < 0
  123. Pop $_LOGICLIB_TEMP
  124. StrCmp $_LOGICLIB_TEMP 0 checkNegOther
  125. System::Int64Op $2 < 0 ; System::Int64Op does not support the >= operator so we invert the operation
  126. Pop $_LOGICLIB_TEMP
  127. StrCmp $_LOGICLIB_TEMP 0 retPos finalCmp
  128. retPos:
  129. StrCpy $_LOGICLIB_TEMP "1"
  130. Goto ret
  131. checkNegOther:
  132. System::Int64Op $2 < 0
  133. Pop $_LOGICLIB_TEMP
  134. StrCmp $_LOGICLIB_TEMP 0 finalCmp retNeg
  135. retNeg:
  136. StrCpy $_LOGICLIB_TEMP "-1"
  137. Goto ret
  138. finalCmp:
  139. System::Int64Op $1 < $2
  140. Pop $_LOGICLIB_TEMP
  141. StrCmp $_LOGICLIB_TEMP 0 retPos retNeg
  142. ret:
  143. Pop $1
  144. Pop $2
  145. !macroend
  146. !macro Int64CmpU a b jeek jles jgtr
  147. !echo "Int64CmpU ${a}:${b} =${jeek}, <${jles}, >${jgtr}"
  148. !verbose push 2
  149. Push `${a}`
  150. Push `${b}`
  151. !insertmacro CallArtificialFunction Int64CmpUHelper
  152. IntCmp $_LOGICLIB_TEMP 0 `${jeek}` `${jles}` `${jgtr}`
  153. !verbose pop
  154. !macroend
  155. !macro IntPtrCmpU a b jeek jles jgtr
  156. !if ${NSIS_PTR_SIZE} <= 4
  157. ${Int32CmpU} `${a}` `${b}` `${jeek}` `${jles}` `${jgtr}`
  158. !else
  159. ${Int64CmpU} `${a}` `${b}` `${jeek}` `${jles}` `${jgtr}`
  160. !endif
  161. !macroend
  162. !endif # !___UTIL__NSH___
  163. !verbose pop