Change syntax for Format/FormatA, remove array in function to be friendlier to Pas2C
authorWuzzy <Wuzzy2@mail.ru>
Thu, 04 Oct 2018 19:04:27 +0200
changeset 13832 10a3b80130b5
parent 13831 b07610de9957
child 13833 664935d80668
Change syntax for Format/FormatA, remove array in function to be friendlier to Pas2C This fixes a problem with Pas2C, but the price to pay is uglier code. :(
hedgewars/uChat.pas
hedgewars/uGears.pas
hedgewars/uGearsHedgehog.pas
hedgewars/uIO.pas
hedgewars/uLocale.pas
hedgewars/uScript.pas
hedgewars/uStore.pas
hedgewars/uTeams.pas
--- a/hedgewars/uChat.pas	Thu Oct 04 17:55:08 2018 +0200
+++ b/hedgewars/uChat.pas	Thu Oct 04 19:04:27 2018 +0200
@@ -1130,7 +1130,7 @@
     if copy(s, 1, 4) = '/me ' then
         s:= #2 + '* ' + UserNick + ' ' + copy(s, 5, Length(s) - 4)
     else
-        s:= #1 + Format(trmsg[sidChat], [UserNick, s]);
+        s:= #1 + Format(trmsg[sidChat], UserNick, s);
 
     AddChatString(s)
 end;
@@ -1139,7 +1139,7 @@
 begin
     SendIPC('b' + s);
 
-    s:= #4 + Format(trmsg[sidChatTeam], [UserNick, s]);
+    s:= #4 + Format(trmsg[sidChatTeam], UserNick, s);
 
     AddChatString(s)
 end;
--- a/hedgewars/uGears.pas	Thu Oct 04 17:55:08 2018 +0200
+++ b/hedgewars/uGears.pas	Thu Oct 04 19:04:27 2018 +0200
@@ -1221,7 +1221,7 @@
                 Gear^.Text:= text;
                 Gear^.FrameTicks:= x
                 end;
-            AddChatString(#9+FormatA(trmsg[sidChatHog], [HH^.Name, text]));
+            AddChatString(#9+FormatA(trmsg[sidChatHog], HH^.Name, text));
             end
         end
     else if (x >= 4) then
--- a/hedgewars/uGearsHedgehog.pas	Thu Oct 04 17:55:08 2018 +0200
+++ b/hedgewars/uGearsHedgehog.pas	Thu Oct 04 19:04:27 2018 +0200
@@ -582,7 +582,7 @@
                     speech^.Text:= SpeechText;
                     speech^.Hedgehog:= Gear^.Hedgehog;
                     speech^.FrameTicks:= SpeechType;
-                    AddChatString(#9+FormatA(trmsg[sidChatHog], [Gear^.Hedgehog^.Name, SpeechText]));
+                    AddChatString(#9+FormatA(trmsg[sidChatHog], Gear^.Hedgehog^.Name, SpeechText));
                     end;
                 SpeechText:= ''
                 end;
--- a/hedgewars/uIO.pas	Thu Oct 04 17:55:08 2018 +0200
+++ b/hedgewars/uIO.pas	Thu Oct 04 19:04:27 2018 +0200
@@ -195,7 +195,7 @@
                 msg:= msg + s[i];
                 inc(i)
                 end;
-             s:= 'b' + Format(trmsg[sidChatTeam], [nick, msg]);
+             s:= 'b' + Format(trmsg[sidChatTeam], nick, msg);
              if (nick = '') or (msg = '') then
                  isProcessed:= false
              else
--- a/hedgewars/uLocale.pas	Thu Oct 04 17:55:08 2018 +0200
+++ b/hedgewars/uLocale.pas	Thu Oct 04 19:04:27 2018 +0200
@@ -23,15 +23,31 @@
 uses uTypes;
 
 const MAX_EVENT_STRINGS = 255;
-const MAX_FORMAT_STRING_SYMBOLS = 9;
 
 procedure LoadLocale(FileName: shortstring);
-function  Format(fmt: shortstring; args: array of shortstring): shortstring;
-function  FormatA(fmt: ansistring; args: array of ansistring): ansistring;
-function  Format(fmt: shortstring; arg: shortstring): shortstring;
-function  FormatA(fmt: ansistring; arg: ansistring): ansistring;
 function  GetEventString(e: TEventId): ansistring;
 
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9: shortstring; argCount: Byte): shortstring;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9: shortstring): shortstring;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8: shortstring): shortstring;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4, arg5, arg6, arg7: shortstring): shortstring;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4, arg5, arg6: shortstring): shortstring;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4, arg5: shortstring): shortstring;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4: shortstring): shortstring;
+function Format(fmt: shortstring; arg1, arg2, arg3: shortstring): shortstring;
+function Format(fmt: shortstring; arg1, arg2: shortstring): shortstring;
+function Format(fmt: shortstring; arg1: shortstring): shortstring;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9: ansistring; argCount: Byte): ansistring;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9: ansistring): ansistring;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8: ansistring): ansistring;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4, arg5, arg6, arg7: ansistring): ansistring;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4, arg5, arg6: ansistring): ansistring;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4, arg5: ansistring): ansistring;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4: ansistring): ansistring;
+function FormatA(fmt: ansistring; arg1, arg2, arg3: ansistring): ansistring;
+function FormatA(fmt: ansistring; arg1, arg2: ansistring): ansistring;
+function FormatA(fmt: ansistring; arg1: ansistring): ansistring;
+
 {$IFDEF HWLIBRARY}
 procedure LoadLocaleWrapper(path: pchar; userpath: pchar; filename: pchar); cdecl; export;
 {$ENDIF}
@@ -119,60 +135,147 @@
 end;
 
 // Format the string fmt.
-// Take a shortstring with placeholders %1, %2, %3, etc. and replace
+// Take a shortstring with placeholders %1, %2, %3, ... %9. and replace
 // them with the corresponding elements of an array with up to
-// MAX_FORMAT_STRING_SYMBOLS. Important! Each placeholder can only be
-// used exactly once and numbers MUST NOT be skipped (e.g. using %1 and %3
-// but not %2.
-function Format(fmt: shortstring; args: array of shortstring): shortstring;
+// argCount. ArgCount must not be larger than 9.
+// Each placeholder must be used exactly once and numbers MUST NOT be
+// skipped (e.g. using %1 and %3 but not %2.
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9: shortstring; argCount: Byte): shortstring;
 var i, p: LongInt;
-tempstr: shortstring;
+tempstr, curArg: shortstring;
 begin
 tempstr:= fmt;
-for i:=0 to MAX_FORMAT_STRING_SYMBOLS - 1 do
+for i:=0 to argCount - 1 do
     begin
+        case i of
+            0: curArg:= arg1;
+            1: curArg:= arg2;
+            2: curArg:= arg3;
+            3: curArg:= arg4;
+            4: curArg:= arg5;
+            5: curArg:= arg6;
+            6: curArg:= arg7;
+            7: curArg:= arg8;
+            8: curArg:= arg9;
+        end;
+
         p:= Pos('%'+IntToStr(i+1), tempstr);
-        if (p = 0) or (i >= Length(args)) then
+        if (p = 0) then
             break
         else
             begin
             delete(tempstr, p, 2);
-            insert(args[i], tempstr, p);
+            insert(curArg, tempstr, p);
             end;
     end;
 Format:= tempstr;
 end;
 
 // Same as Format, but for ansistring
-function FormatA(fmt: ansistring; args: array of ansistring): ansistring;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9: ansistring; argCount: Byte): ansistring;
 var i, p: LongInt;
-tempstr: ansistring;
+tempstr, curArg: ansistring;
 begin
 tempstr:= fmt;
-for i:=0 to MAX_FORMAT_STRING_SYMBOLS - 1 do
+for i:=0 to argCount - 1 do
     begin
+        case i of
+            0: curArg:= arg1;
+            1: curArg:= arg2;
+            2: curArg:= arg3;
+            3: curArg:= arg4;
+            4: curArg:= arg5;
+            5: curArg:= arg6;
+            6: curArg:= arg7;
+            7: curArg:= arg8;
+            8: curArg:= arg9;
+        end;
+
         p:= Pos('%'+IntToStr(i+1), tempstr);
-        if (p = 0) or (i >= Length(args)) then
+        if (p = 0) then
             break
         else
             begin
             delete(tempstr, p, 2);
-            insert(args[i], tempstr, p);
+            insert(curArg, tempstr, p);
             end;
     end;
 FormatA:= tempstr;
 end;
 
-// Same as Format above, but with only one placeholder %1, replaced by arg.
-function Format(fmt: shortstring; arg: shortstring): shortstring;
+// The following functions are just shortcuts of Format/FormatA, with fewer argument counts
+function Format(fmt: shortstring; arg1: shortstring): shortstring;
+begin
+    Format:= Format(fmt, arg1, '', '', '', '', '', '', '', '', 1);
+end;
+function Format(fmt: shortstring; arg1, arg2: shortstring): shortstring;
+begin
+    Format:= Format(fmt, arg1, arg2, '', '', '', '', '', '', '', 2);
+end;
+function Format(fmt: shortstring; arg1, arg2, arg3: shortstring): shortstring;
+begin
+    Format:= Format(fmt, arg1, arg2, arg3, '', '', '', '', '', '', 3);
+end;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4: shortstring): shortstring;
 begin
-    Format:= Format(fmt, [arg]);
+    Format:= Format(fmt, arg1, arg2, arg3, arg4, '', '', '', '', '', 4);
+end;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4, arg5: shortstring): shortstring;
+begin
+    Format:= Format(fmt, arg1, arg2, arg3, arg4, arg5, '', '', '', '', 5);
+end;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4, arg5, arg6: shortstring): shortstring;
+begin
+    Format:= Format(fmt, arg1, arg2, arg3, arg4, arg5, arg6, '', '', '', 6);
+end;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4, arg5, arg6, arg7: shortstring): shortstring;
+begin
+    Format:= Format(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, '', '', 7);
+end;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8: shortstring): shortstring;
+begin
+    Format:= Format(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, '', 8);
+end;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9: shortstring): shortstring;
+begin
+    Format:= Format(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, 9);
 end;
 
-// Same as above, but for ansistring
-function FormatA(fmt: ansistring; arg: ansistring): ansistring;
+function FormatA(fmt: ansistring; arg1: ansistring): ansistring;
+begin
+    FormatA:= FormatA(fmt, arg1, '', '', '', '', '', '', '', '', 1);
+end;
+function FormatA(fmt: ansistring; arg1, arg2: ansistring): ansistring;
+begin
+    FormatA:= FormatA(fmt, arg1, arg2, '', '', '', '', '', '', '', 2);
+end;
+function FormatA(fmt: ansistring; arg1, arg2, arg3: ansistring): ansistring;
+begin
+    FormatA:= FormatA(fmt, arg1, arg2, arg3, '', '', '', '', '', '', 3);
+end;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4: ansistring): ansistring;
+begin
+    FormatA:= FormatA(fmt, arg1, arg2, arg3, arg4, '', '', '', '', '', 4);
+end;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4, arg5: ansistring): ansistring;
 begin
-    FormatA:= FormatA(fmt, [arg]);
+    FormatA:= FormatA(fmt, arg1, arg2, arg3, arg4, arg5, '', '', '', '', 5);
+end;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4, arg5, arg6: ansistring): ansistring;
+begin
+    FormatA:= FormatA(fmt, arg1, arg2, arg3, arg4, arg5, arg6, '', '', '', 6);
+end;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4, arg5, arg6, arg7: ansistring): ansistring;
+begin
+    FormatA:= FormatA(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, '', '', 7);
+end;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8: ansistring): ansistring;
+begin
+    FormatA:= FormatA(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, '', 8);
+end;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9: ansistring): ansistring;
+begin
+    FormatA:= FormatA(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, 9);
 end;
 
 {$IFDEF HWLIBRARY}
--- a/hedgewars/uScript.pas	Thu Oct 04 17:55:08 2018 +0200
+++ b/hedgewars/uScript.pas	Thu Oct 04 19:04:27 2018 +0200
@@ -1651,7 +1651,7 @@
                vgear^.Text:= lua_tostring(L, 2);
                if Gear^.Kind = gtHedgehog then
                    begin
-                   AddChatString(#9+FormatA(trmsg[sidChatHog], [gear^.Hedgehog^.Name, vgear^.text]));
+                   AddChatString(#9+FormatA(trmsg[sidChatHog], gear^.Hedgehog^.Name, vgear^.text));
                    vgear^.Hedgehog:= gear^.Hedgehog
                    end
                else vgear^.Frame:= gear^.uid;
--- a/hedgewars/uStore.pas	Thu Oct 04 17:55:08 2018 +0200
+++ b/hedgewars/uStore.pas	Thu Oct 04 19:04:27 2018 +0200
@@ -511,7 +511,7 @@
     AFKTexture:= RenderStringTex(trmsg[sidAFK], cCentralMessageColor, fntBig);
     keyConfirm:= KeyBindToName('confirm');
     keyQuit:= KeyBindToName('quit');
-    ConfirmTexture:= RenderStringTex(Format(trmsg[sidConfirm], [keyConfirm, keyQuit]), cCentralMessageColor, fntBig);
+    ConfirmTexture:= RenderStringTex(Format(trmsg[sidConfirm], keyConfirm, keyQuit), cCentralMessageColor, fntBig);
     SyncTexture:= RenderStringTex(trmsg[sidSync], cCentralMessageColor, fntBig);
 
     if not reload then
--- a/hedgewars/uTeams.pas	Thu Oct 04 17:55:08 2018 +0200
+++ b/hedgewars/uTeams.pas	Thu Oct 04 19:04:27 2018 +0200
@@ -129,7 +129,18 @@
                     end
                 else if (TeamsNumber >= 2) and (TeamsNumber < cMaxTeams) then
                     // List all winning teams in a list
-                    s:= FormatA(trmsg[TMsgStrId(Ord(sidWinner2) + (TeamsNumber - 2))], ts);
+                    if (TeamsNumber = 2) then
+                        s:= FormatA(trmsg[TMsgStrId(sidWinner2)], ts[0], ts[1])
+                    else if (TeamsNumber = 3) then
+                        s:= FormatA(trmsg[TMsgStrId(sidWinner3)], ts[0], ts[1], ts[2])
+                    else if (TeamsNumber = 4) then
+                        s:= FormatA(trmsg[TMsgStrId(sidWinner4)], ts[0], ts[1], ts[2], ts[3])
+                    else if (TeamsNumber = 5) then
+                        s:= FormatA(trmsg[TMsgStrId(sidWinner5)], ts[0], ts[1], ts[2], ts[3], ts[4])
+                    else if (TeamsNumber = 6) then
+                        s:= FormatA(trmsg[TMsgStrId(sidWinner6)], ts[0], ts[1], ts[2], ts[3], ts[4], ts[5])
+                    else if (TeamsNumber = 7) then
+                        s:= FormatA(trmsg[TMsgStrId(sidWinner7)], ts[0], ts[1], ts[2], ts[3], ts[4], ts[5], ts[6]);
 
                 // The winner caption is the same as the stats message and not randomized
                 cap:= s;