Browse Source

Merge branch 'main' into files-extractarchive

Martijn Laan 3 tháng trước cách đây
mục cha
commit
200c7c3f66

+ 6 - 7
Files/ISPPBuiltins.iss

@@ -229,14 +229,10 @@
     (Local[0] < 0 ? Local[1] : Local[0] + 1)
 
 #define ExtractFilePath(str PathName) \
-  (Local[0] = \
+  Local[0] = \
     !(Local[1] = RPos("\", PathName)) ? \
       "" : \
-      Copy(PathName, 1, Local[1] - 1)), \
-  Local[0] + \
-    ((Local[2] = Len(Local[0])) == 2 && Copy(Local[0], Local[2]) == ":" ? \
-      "\" : \
-      "")
+      Copy(PathName, 1, Local[1])
 
 #define ExtractFileDir(str PathName) \
   RemoveBackslash(ExtractFilePath(PathName))
@@ -263,7 +259,7 @@
 #define AddBackslash(str S) \
   Copy(S, Len(S)) == "\" ? S : S + "\"
 
-#define RemoveBackslash(str S) \
+#define RemoveBackslashUnlessRoot(str S) \
   Local[0] = Len(S), \
   Local[0] > 0 ? \
     Copy(S, Local[0]) == "\" ? \
@@ -272,6 +268,9 @@
         Copy(S, 1, Local[0] - 1)) : \
       S : \
     ""
+#define RemoveBackslash(str S) \
+  WarnRenamedVersion("RemoveBackslash", "RemoveBackslashUnlessRoot"), \
+  RemoveBackslashUnlessRoot(S)
 
 #define Delete(str *S, int Index, int Count = MaxInt) \
   S = Copy(S, 1, Index - 1) + Copy(S, Index + Count)

+ 19 - 11
ISHelp/ispp.xml

@@ -1661,9 +1661,12 @@ The first group of options (<tt>option</tt>) controls the general options, while
 					</pre>
 				</section>
 				<description>
-					<p>Returns the directory portion of the given filename with a backslash. If PathName doesn't contain a directory portion, the result is an empty string.</p>
+					<p>Returns the directory portion of the given filename, including a trailing backslash. If PathName doesn't contain a directory portion, the result is an empty string.</p>
           <p>Declared in &builtins;.</p>
 				</description>
+				<section title="See also">
+					<p><tt><link href="ExtractFileDir">ExtractFileDir</link></tt></p>
+				</section>
 			</topic>
 			<topic id="ExtractFileDir">
 				<title>ExtractFileDir</title>
@@ -1673,9 +1676,12 @@ The first group of options (<tt>option</tt>) controls the general options, while
 					</pre>
 				</section>
 				<description>
-					<p>Returns the directory portion of the given filename without a backslash (unless it is a root directory). If PathName doesn't contain a directory portion, the result is an empty string.</p>
+					<p>Returns the directory portion of the given filename, excluding a trailing backslash (unless it is a root directory). If PathName doesn't contain a directory portion, the result is an empty string.</p>
           <p>Declared in &builtins;.</p>
 				</description>
+				<section title="See also">
+					<p><tt><link href="ExtractFilePath">ExtractFilePath</link></tt></p>
+				</section>
 			</topic>
 			<topic id="ExtractFileExt">
 				<title>ExtractFileExt</title>
@@ -1737,11 +1743,11 @@ The first group of options (<tt>option</tt>) controls the general options, while
           <p>Declared in &builtins;.</p>
 				</description>
 			</topic>
-			<topic id="RemoveBackslash">
-				<title>RemoveBackslash</title>
+			<topic id="RemoveBackslashUnlessRoot">
+				<title>RemoveBackslashUnlessRoot</title>
 				<section title="Prototype">
 					<pre>
-						<line><b>str</b> RemoveBackslash(<b>str</b> S)</line>
+						<line><b>str</b> RemoveBackslashUnlessRoot(<b>str</b> S)</line>
 					</pre>
 				</section>
 				<description>
@@ -2000,15 +2006,16 @@ The first group of options (<tt>option</tt>) controls the general options, while
 		<topic id="predefinedvars">
 				<keywords>
 					<kwd>__COUNTER__</kwd>
-					<kwd>__FILE__</kwd>
+					<kwd>__FILENAME__</kwd>
 					<kwd>__INCLUDE__</kwd>
 					<kwd>__LINE__</kwd>
 					<kwd>__OPT_X__</kwd>
+					<kwd>__DIR__</kwd>
 					<kwd>__PATHFILENAME__</kwd>
 					<kwd>__POPT_X__</kwd>
 					<kwd>__WIN32__</kwd>
 					<kwd>ISPP_INVOKED</kwd>
-					<kwd>ISPPCC_INVOKED</kwd>
+					<kwd>ISCC_INVOKED</kwd>
 					<kwd>PREPROCVER</kwd>
 					<kwd>WINDOWS</kwd>
 					<kwd>UNICODE</kwd>
@@ -2023,20 +2030,21 @@ The first group of options (<tt>option</tt>) controls the general options, while
 				<p>There are a number of predefined variables provided ISPP:</p>
 				<table>
 					<tr><td><code>__COUNTER__</code></td><td><code><b>int</b></code>. Automatically increments each time it is used (afterwards).</td></tr>
-					<tr><td><code>__FILE__</code></td><td><code><b>str</b></code>. Returns the name of the current file. Empty string for the root file.</td></tr>
+					<tr><td><code>__FILENAME__</code></td><td><code><b>str</b></code>. Similar to __PATHFILENAME__, but returns only the filename portion.</td></tr>
 					<tr><td><code>__INCLUDE__</code></td><td><code><b>str</b></code>. Returns the current include path (or paths delimited with semicolons) set via <code>#pragma include</code>.</td></tr>
 					<tr><td><code>__LINE__</code></td><td><code><b>int</b></code>. Returns the number of the line in the current file.</td></tr>
 					<tr><td><code>__OPT_X__</code></td><td><code><b>void</b></code>. Defined if specified option set via <code>#pragma option -x+</code> is in effect. In place of "X" may be any letter from "A" to "Z." Use <link href="defined">Defined</link> function to test whether the variable is defined.</td></tr>
-					<tr><td><code>__PATHFILENAME__</code></td><td><code><b>str</b></code>. Similar to __FILE__, but returns the full pathname of the file. Empty string for the root file.</td></tr>
+					<tr><td><code>__DIR__</code></td><td><code><b>str</b></code>. Similar to __PATHFILENAME__, but returns only the directory portion, excluding a trailing backslash (unless it is a root directory).</td></tr>
+					<tr><td><code>__PATHFILENAME__</code></td><td><code><b>str</b></code>. Returns the full path of the current include file. Empty string for the root script file.</td></tr>
 					<tr><td><code>__POPT_X__</code></td><td><code><b>void</b></code>. Defined if specified parser option set via <code>#pragma parseroption -x+</code> is in effect. In place of "X" may be any letter from "A" to "Z." Use <link href="defined">Defined</link> function to test whether the variable is defined.</td></tr>
 					<tr><td><code>__WIN32__</code></td><td><code><b>void</b></code>. Always defined.</td></tr>
 					<tr><td><code>ISPP_INVOKED</code></td><td><code><b>void</b></code>. Always defined.</td></tr>
-					<tr><td><code>ISPPCC_INVOKED</code></td><td><code><b>void</b></code>. Defined if compilation was invoked using the console-mode compiler, ISCC.exe.</td></tr>
+					<tr><td><code>ISCC_INVOKED</code></td><td><code><b>void</b></code>. Defined if compilation was invoked using the console-mode compiler, ISCC.exe.</td></tr>
 					<tr><td><code>PREPROCVER</code></td><td><code><b>int</b></code>. Returns the 32-bit encoded version of ISPP. Highest byte holds the major version, lowest byte holds the build number.</td></tr>
 					<tr><td><code>WINDOWS</code></td><td><code><b>void</b></code>. Always defined.</td></tr>
 					<tr><td><code>UNICODE</code></td><td><code><b>void</b></code>. Always defined.</td></tr>
 					<tr><td><code>CompilerPath</code></td><td><code><b>str</b></code>. Points to the directory where the compiler is located.</td></tr>
-					<tr><td><code>SourcePath</code></td><td><code><b>str</b></code>. Points to the directory where the current script is located, or the My Documents directory if the script has not yet been saved.</td></tr>
+					<tr><td><code>SourcePath</code></td><td><code><b>str</b></code>. Points to the directory where the root script file is located, or the My Documents directory if the script has not yet been saved.</td></tr>
 					<tr><td><code>Ver</code></td><td><code><b>int</b></code>. Returns the 32-bit encoded version of Inno Setup compiler. Highest byte holds the major version, lowest byte the minor version.</td></tr>
 					<tr><td><code>NewLine</code></td><td><code><b>str</b></code>. Returns the newline character. Declared in &builtins;.</td></tr>
 					<tr><td><code>Tab</code></td><td><code><b>str</b></code>. Returns the tab character. Declared in &builtins;.</td></tr>

+ 4 - 2
ISHelp/isxfunc.xml

@@ -1082,12 +1082,14 @@ end;</pre></example>
       <function>
         <name>ExtractFileDir</name>
         <prototype>function ExtractFileDir(const FileName: String): String;</prototype>
-        <description><p>Extracts the drive and directory parts of the given file name. The resulting string is empty if FileName contains no drive and directory parts.</p></description>
+        <description><p>Extracts the drive and directory parts of the given file name, excluding a trailing backslash (unless it is a root directory). The resulting string is empty if FileName contains no drive and directory parts.</p></description>
+        <seealso><p><link topic="isxfunc_ExtractFilePath">ExtractFilePath</link></p></seealso>
       </function>
       <function>
         <name>ExtractFilePath</name>
         <prototype>function ExtractFilePath(const FileName: String): String;</prototype>
-        <description><p>Extracts the drive and directory parts of the given file name. The resulting string is the leftmost characters of FileName, up to and including the colon or backslash that separates the path information from the name and extension. The resulting string is empty if FileName contains no drive and directory parts.</p></description>
+        <description><p>Extracts the drive and directory parts of the given file name, including a trailing backslash. The resulting string is the leftmost characters of FileName, up to and including the colon or backslash that separates the path information from the name and extension. The resulting string is empty if FileName contains no drive and directory parts.</p></description>
+        <seealso><p><link topic="isxfunc_ExtractFileDir">ExtractFileDir</link></p></seealso>
       </function>
       <function>
         <name>ExtractFileName</name>

+ 1 - 1
Projects/ISCC.dpr

@@ -327,7 +327,7 @@ procedure ProcessCommandLine;
       InlineEnd := '}';
     end;
 
-    Definitions := 'ISPPCC_INVOKED'#1;
+    Definitions := 'ISCC_INVOKED'#1'ISPPCC_INVOKED'#1;
     IncludePath := ExtractFileDir(NewParamStr(0));
     IncludeFiles := '';
   end;

+ 5 - 1
Projects/Src/ISPP.Preprocessor.pas

@@ -1494,7 +1494,7 @@ function TPreprocessor.LookupPredefined(Name: string;
 begin
   Result := True;
   Name := UpperCase(Name);
-  if Name = '__FILE__' then
+  if (Name = '__FILENAME__') or (Name = '__FILE__') then
   begin
     if Value <> nil then MakeStr(Value^, ExtractFileName(FIncludes[FCurrentFile]))
   end
@@ -1502,6 +1502,10 @@ begin
   begin
     if Value <> nil then MakeStr(Value^, FIncludes[FCurrentFile])
   end
+  else if Name = '__DIR__' then
+  begin
+    if Value <> nil then MakeStr(Value^, ExtractFileDir(FIncludes[FCurrentFile]))
+  end
   else if Name = '__LINE__' then
   begin
     if Value <> nil then MakeInt(Value^, FCurrentLine)

+ 1 - 1
setup.allowedpublickeys.iss

@@ -3,5 +3,5 @@
 // To ignore this change consider using Git's assume-unchanged or skip-worktree functionality
 //
 [ISSigKeys]
-Name: mykey1; KeyID: def0147c3bbc17ab99bf7b7a9c2de1390283f38972152418d7c2a4a7d7131a38; KeyFile: {#ExtractFilePath(__PATHFILENAME__)}\def01.ispublickey
+Name: mykey1; KeyID: def0147c3bbc17ab99bf7b7a9c2de1390283f38972152418d7c2a4a7d7131a38; KeyFile: {#__DIR__}\def01.ispublickey
 Name: mykey2; KeyID: def020edee3c4835fd54d85eff8b66d4d899b22a777353ca4a114b652e5e7a28; PublicX: 515dc7d6c16d4a46272ceb3d158c5630a96466ab4d948e72c2029d737c823097; PublicY: f3c21f6b5156c52a35f6f28016ee3e31a3ded60c325b81fb7b1f88c221081a61

+ 8 - 0
whatsnew.htm

@@ -155,6 +155,14 @@ Source: "{tmp}\MyProg-ExtraReadmes.7z"; DestDir: "{app}"; Flags: external extrac
 <ul>
   <li>Compiler IDE: the <i>Find in Files</i> result list will now update its line numbers when you add or delete lines.</li>
   <li><tt>[Files]</tt> section parameter <tt>Excludes</tt> can now be combined with the <tt>external</tt> flag.</li>
+  <li>ISPP changes:
+    <ul>
+      <li>Added predefined variable <tt>__DIR__</tt>. Returns the directory of the current include file.</li>
+      <li>Renamed predefined variables <tt>__FILE__</tt> to <tt>__FILENAME__</tt> and <tt>ISPPCC_INVOKED</tt> to <tt>ISCC_INVOKED</tt>. The old names still work.</li>
+      <li>Renamed support function <tt>RemoveBackslash</tt> to <tt>RemoveBackslashUnlessRoot</tt>. The old name still works.</li>
+      <li><i>Fix:</i> The return value of support function <tt>ExtractFilePath</tt> did not always including a trailing backslash as intended.</li>
+    </ul>
+  </li>
   <li>Pascal Scripting change: Added new <tt>GetSHA256OfStream</tt> support function.</li>
   <li>All translations which still had a UTF-8 BOM had their BOM removed. Using a BOM in UTF-8 encoded files is not needed and not recommended since Inno Stup 6.3.0.</li>
   <li>Documentation improvements.</li>