ISPPBuiltins.iss 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. ; BEGIN ISPPBUILTINS.ISS
  2. //
  3. // Inno Setup Preprocessor 5
  4. //
  5. // Copyright (C) 2001-2004 Alex Yackimoff. All Rights Reserved.
  6. // Portions by Martijn Laan.
  7. // http://ispp.sourceforge.net
  8. //
  9. // Inno Setup (C) 1997-2009 Jordan Russell. All Rights Reserved.
  10. // Portions by Martijn Laan.
  11. //
  12. // $Id: ISPPBuiltins.iss,v 1.3 2010/12/29 15:20:26 mlaan Exp $
  13. //
  14. #if defined(ISPP_INVOKED) && !defined(_BUILTINS_ISS_)
  15. //
  16. #if PREPROCVER < 0x01000000
  17. # error Inno Setup Preprocessor version is outdated
  18. #endif
  19. //
  20. #define _BUILTINS_ISS_
  21. //
  22. // ===========================================================================
  23. //
  24. // Default states for options.
  25. //
  26. //#pragma parseroption -b+ ; short circuit boolean evaluation: on
  27. //#pragma parseroption -m- ; short circuit multiplication evaluation (0 * A will not eval A): off
  28. //#pragma parseroption -p+ ; string literals without escape sequences: on
  29. //#pragma parseroption -u- ; allow undeclared identifiers: off
  30. //#pragma option -c+ ; pass script to the compiler: on
  31. //#pragma option -e- ; emit empty lines to translation: off
  32. //#pragma option -v- ; verbose mode: off
  33. //
  34. // ---------------------------------------------------------------------------
  35. //
  36. // Verbose levels:
  37. // 0 - #include and #file acknowledgements
  38. // 1 - information about any temp files created by #file
  39. // 2 - #insert and #append acknowledgements
  40. // 3 - reserved
  41. // 4 - #dim, #define and #undef acknowledgements
  42. // 5 - reserved
  43. // 6 - conditional inclusion acknowledgements
  44. // 7 - reserved
  45. // 8 - show strings emitted with #emit directive
  46. // 9 - macro and functions successfull call acknowledgements
  47. //10 - Local macro array allocation acknowledgements
  48. //
  49. //#pragma verboselevel 0
  50. //
  51. #ifndef __POPT_P__
  52. # define private CStrings
  53. # pragma parseroption -p+
  54. #endif
  55. //
  56. #pragma spansymbol "\"
  57. //
  58. #define True 1
  59. #define False 0
  60. #define Yes True
  61. #define No False
  62. //
  63. #define MaxInt 0x7FFFFFFFL
  64. #define MinInt 0x80000000L
  65. //
  66. #define NULL
  67. #define void
  68. //
  69. // TypeOf constants
  70. //
  71. #define TYPE_ERROR 0
  72. #define TYPE_NULL 1
  73. #define TYPE_INTEGER 2
  74. #define TYPE_STRING 3
  75. #define TYPE_MACRO 4
  76. #define TYPE_FUNC 5
  77. #define TYPE_ARRAY 6
  78. //
  79. // Helper macro to find out the type of an array element or expression. TypeOf
  80. // standard function only allows identifier as its parameter. Use this macro
  81. // to convert an expression to identifier.
  82. //
  83. #define TypeOf2(any Expr) TypeOf(Expr)
  84. //
  85. // ReadReg constants
  86. //
  87. #define HKEY_CLASSES_ROOT 0x80000000UL
  88. #define HKEY_CURRENT_USER 0x80000001UL
  89. #define HKEY_LOCAL_MACHINE 0x80000002UL
  90. #define HKEY_USERS 0x80000003UL
  91. //
  92. #define HKCR HKEY_CLASSES_ROOT
  93. #define HKCU HKEY_CURRENT_USER
  94. #define HKLM HKEY_LOCAL_MACHINE
  95. #define HKU HKEY_USERS
  96. //
  97. // Exec constants
  98. //
  99. #define SW_HIDE 0
  100. #define SW_SHOWNORMAL 1
  101. #define SW_NORMAL 1
  102. #define SW_SHOWMINIMIZED 2
  103. #define SW_SHOWMAXIMIZED 3
  104. #define SW_MAXIMIZE 3
  105. #define SW_SHOWNOACTIVATE 4
  106. #define SW_SHOW 5
  107. #define SW_MINIMIZE 6
  108. #define SW_SHOWMINNOACTIVE 7
  109. #define SW_SHOWNA 8
  110. #define SW_RESTORE 9
  111. #define SW_SHOWDEFAULT 10
  112. #define SW_MAX 10
  113. //
  114. // Find constants
  115. //
  116. #define FIND_MATCH 0x00
  117. #define FIND_BEGINS 0x01
  118. #define FIND_ENDS 0x02
  119. #define FIND_CONTAINS 0x03
  120. #define FIND_CASESENSITIVE 0x04
  121. #define FIND_SENSITIVE FIND_CASESENSITIVE
  122. #define FIND_AND 0x00
  123. #define FIND_OR 0x08
  124. #define FIND_NOT 0x10
  125. #define FIND_TRIM 0x20
  126. //
  127. // FindFirst constants
  128. //
  129. #define faReadOnly 0x00000001
  130. #define faHidden 0x00000002
  131. #define faSysFile 0x00000004
  132. #define faVolumeID 0x00000008
  133. #define faDirectory 0x00000010
  134. #define faArchive 0x00000020
  135. #define faSymLink 0x00000040
  136. #define faAnyFile 0x0000003F
  137. //
  138. // GetStringFileInfo standard names
  139. //
  140. #define COMPANY_NAME "CompanyName"
  141. #define FILE_DESCRIPTION "FileDescription"
  142. #define FILE_VERSION "FileVersion"
  143. #define INTERNAL_NAME "InternalName"
  144. #define LEGAL_COPYRIGHT "LegalCopyright"
  145. #define ORIGINAL_FILENAME "OriginalFilename"
  146. #define PRODUCT_NAME "ProductName"
  147. #define PRODUCT_VERSION "ProductVersion"
  148. //
  149. // GetStringFileInfo helpers
  150. //
  151. #define GetFileCompany(str FileName) GetStringFileInfo(FileName, COMPANY_NAME)
  152. #define GetFileCopyright(str FileName) GetStringFileInfo(FileName, LEGAL_COPYRIGHT)
  153. #define GetFileDescription(str FileName) GetStringFileInfo(FileName, FILE_DESCRIPTION)
  154. #define GetFileProductVersion(str FileName) GetStringFileInfo(FileName, PRODUCT_VERSION)
  155. #define GetFileVersionString(str FileName) GetStringFileInfo(FileName, FILE_VERSION)
  156. //
  157. // ParseVersion
  158. //
  159. // Macro internally calls GetFileVersion function and parses string returned
  160. // by that function (in form "0.0.0.0"). All four version elements are stored
  161. // in by-reference parameters Major, Minor, Rev, and Build. Macro returns
  162. // string returned by GetFileVersion.
  163. //
  164. #define DeleteToFirstPeriod(str *S) \
  165. Local[1] = Copy(S, 1, (Local[0] = Pos(".", S)) - 1), \
  166. S = Copy(S, Local[0] + 1), \
  167. Local[1]
  168. //
  169. #define ParseVersion(str FileName, *Major, *Minor, *Rev, *Build) \
  170. Local[1] = Local[0] = GetFileVersion(FileName), \
  171. Local[1] == "" ? "" : ( \
  172. Major = Int(DeleteToFirstPeriod(Local[1])), \
  173. Minor = Int(DeleteToFirstPeriod(Local[1])), \
  174. Rev = Int(DeleteToFirstPeriod(Local[1])), \
  175. Build = Int(Local[1]), \
  176. Local[0])
  177. //
  178. // EncodeVer
  179. //
  180. // Encodes given four version elements to a 32 bit integer number (8 bits for
  181. // each element, i.e. elements must be within 0...255 range).
  182. //
  183. #define EncodeVer(int Major, int Minor, int Revision = 0, int Build = -1) \
  184. Major << 24 | (Minor & 0xFF) << 16 | (Revision & 0xFF) << 8 | (Build >= 0 ? Build & 0xFF : 0)
  185. //
  186. // DecodeVer
  187. //
  188. // Decodes given 32 bit integer encoded version to its string representation,
  189. // Digits parameter indicates how many elements to show (if the fourth element
  190. // is 0, it won't be shown anyway).
  191. //
  192. #define DecodeVer(int Ver, int Digits = 3) \
  193. Str(Ver >> 0x18 & 0xFF) + (Digits > 1 ? "." : "") + \
  194. (Digits > 1 ? \
  195. Str(Ver >> 0x10 & 0xFF) + (Digits > 2 ? "." : "") : "") + \
  196. (Digits > 2 ? \
  197. Str(Ver >> 0x08 & 0xFF) + (Digits > 3 && (Local = Ver & 0xFF) ? "." : "") : "") + \
  198. (Digits > 3 && Local ? \
  199. Str(Ver & 0xFF) : "")
  200. //
  201. // FindSection
  202. //
  203. // Returns index of the line following the header of the section. This macro
  204. // is intended to be used with #insert directive.
  205. //
  206. #define FindSection(str Section = "Files") \
  207. Find(0, "[" + Section + "]", FIND_MATCH | FIND_TRIM) + 1
  208. //
  209. // FindSectionEnd
  210. //
  211. // Returns index of the line following last entry of the section. This macro
  212. // is intended to be used with #insert directive.
  213. //
  214. #if VER >= 0x03000000
  215. # define FindNextSection(int Line) \
  216. Find(Line, "[", FIND_BEGINS | FIND_TRIM, "]", FIND_ENDS | FIND_AND)
  217. # define FindSectionEnd(str Section = "Files") \
  218. FindNextSection(FindSection(Section))
  219. #else
  220. # define FindSectionEnd(str Section = "Files") \
  221. FindSection(Section) + EntryCount(Section)
  222. #endif
  223. //
  224. // FindCode
  225. //
  226. // Returns index of the line (of translation) following either [Code] section
  227. // header, or "program" keyword, if any.
  228. //
  229. #define FindCode() \
  230. Local[1] = FindSection("Code"), \
  231. Local[0] = Find(Local[1] - 1, "program", FIND_BEGINS, ";", FIND_ENDS | FIND_AND), \
  232. (Local[0] < 0 ? Local[1] : Local[0] + 1)
  233. //
  234. // ExtractFilePath
  235. //
  236. // Returns directory portion of the given filename without backslash (unless
  237. // it is a root directory). If PathName doesn't contain directory portion,
  238. // the result is an empty string.
  239. //
  240. #define ExtractFilePath(str PathName) \
  241. (Local[0] = \
  242. !(Local[1] = RPos("\", PathName)) ? \
  243. "" : \
  244. Copy(PathName, 1, Local[1] - 1)), \
  245. Local[0] + \
  246. ((Local[2] = Len(Local[0])) == 2 && Copy(Local[0], Local[2]) == ":" ? \
  247. "\" : \
  248. "")
  249. #define ExtractFileDir(str PathName) \
  250. RemoveBackslash(ExtractFilePath(PathName))
  251. #define ExtractFileExt(str PathName) \
  252. Local[0] = RPos(".", PathName), \
  253. Copy(PathName, Local[0] + 1)
  254. //
  255. // ExtractFileName
  256. //
  257. // Returns name portion of the given filename. If PathName ends with
  258. // a backslash, the result is an empty string.
  259. //
  260. #define ExtractFileName(str PathName) \
  261. !(Local[0] = RPos("\", PathName)) ? \
  262. PathName : \
  263. Copy(PathName, Local[0] + 1)
  264. //
  265. // ChangeFileExt
  266. //
  267. // Changes extension in FileName with NewExt. NewExt must not contain
  268. // period.
  269. //
  270. #define ChangeFileExt(str FileName, str NewExt) \
  271. !(Local[0] = RPos(".", FileName)) ? \
  272. FileName + "." + NewExt : \
  273. Copy(FileName, 1, Local[0]) + NewExt
  274. //
  275. // AddBackslash
  276. //
  277. // Adds a backslash to the string, if it's not already there.
  278. //
  279. #define AddBackslash(str S) \
  280. Copy(S, Len(S)) == "\" ? S : S + "\"
  281. //
  282. // RemoveBackslash
  283. //
  284. // Removes trailing backslash from the string unless the string points to
  285. // a root directory.
  286. //
  287. #define RemoveBackslash(str S) \
  288. Local[0] = Len(S), \
  289. Local[0] > 0 ? \
  290. Copy(S, Local[0]) == "\" ? \
  291. (Local[0] == 3 && Copy(S, 2, 1) == ":" ? \
  292. S : \
  293. Copy(S, 1, Local[0] - 1)) : \
  294. S : \
  295. ""
  296. //
  297. // Delete
  298. //
  299. // Deletes specified number of characters beginning with Index from S. S is
  300. // passed by reference (therefore is modified). Acts like Delete function in
  301. // Delphi (from System unit).
  302. //
  303. #define Delete(str *S, int Index, int Count = MaxInt) \
  304. S = Copy(S, 1, Index - 1) + Copy(S, Index + Count)
  305. //
  306. // Insert
  307. //
  308. // Inserts specified Substr at Index'th character into S. S is passed by
  309. // reference (therefore is modified).
  310. //
  311. #define Insert(str *S, int Index, str Substr) \
  312. Index > Len(S) + 1 ? \
  313. S : \
  314. S = Copy(S, 1, Index - 1) + SubStr + Copy(S, Index)
  315. //
  316. // YesNo, IsDirSet
  317. //
  318. // Returns nonzero value if given string is "yes", "true" or "1". Intended to
  319. // be used with SetupSetting function. This macro replaces YesNo function
  320. // available in previous releases.
  321. //
  322. #define YesNo(str S) \
  323. (S = LowerCase(S)) == "yes" || S == "true" || S == "1"
  324. //
  325. #define IsDirSet(str SetupDirective) \
  326. YesNo(SetupSetting(SetupDirective))
  327. //
  328. //
  329. #define Power(int X, int P = 2) \
  330. !P ? 1 : X * Power(X, P - 1)
  331. //
  332. #define Min(int A, int B, int C = MaxInt) \
  333. A < B ? A < C ? Int(A) : Int(C) : Int(B)
  334. //
  335. #define Max(int A, int B, int C = MinInt) \
  336. A > B ? A > C ? Int(A) : Int(C) : Int(B)
  337. //
  338. #ifdef CStrings
  339. # pragma parseroption -p-
  340. #endif
  341. #endif
  342. ; END ISPPBUILTINS.ISS