Implement a bit of astring
authorunc0rr
Fri, 07 Feb 2014 22:42:57 +0400
changeset 10121 8b65699beb56
parent 10120 b7f632c12784
child 10122 cefede760264
Implement a bit of astring
hedgewars/uVisualGears.pas
project_files/hwc/rtl/misc.h
project_files/hwc/rtl/pas2c.h
tools/pas2c/Pas2C.hs
--- a/hedgewars/uVisualGears.pas	Fri Feb 07 15:44:27 2014 +0400
+++ b/hedgewars/uVisualGears.pas	Fri Feb 07 22:42:57 2014 +0400
@@ -51,18 +51,14 @@
     , uVisualGearsList;
 
 procedure AddDamageTag(X, Y, Damage, Color: LongWord);
-var s: shortstring;
-    Gear: PVisualGear;
+var Gear: PVisualGear;
 begin
 if cAltDamage then
     begin
     Gear:= AddVisualGear(X, Y, vgtSmallDamageTag);
     if Gear <> nil then
         with Gear^ do
-            begin
-            str(Damage, s);
-            Tex:= RenderStringTex(s, Color, fntSmall);
-            end
+            Tex:= RenderStringTex(ansistring(inttostr(Damage)), Color, fntSmall);
     end
 end;
 
--- a/project_files/hwc/rtl/misc.h	Fri Feb 07 15:44:27 2014 +0400
+++ b/project_files/hwc/rtl/misc.h	Fri Feb 07 22:42:57 2014 +0400
@@ -45,9 +45,9 @@
 bool        fpcrtl_strcomparec(string255 a, char b);
 bool        fpcrtl_strncompare(string255 a, string255 b);
 
-#define     fpcrtl__pchar(s)                        ((s).str)
+char*       fpcrtl__pchar(string255 s);
 string255   fpcrtl_pchar2str(char *s);
-
+astring     fpcrtl_str2astr(string255 s);
 #define     fpcrtl_TypeInfo                         sizeof // dummy
 
 #ifdef EMSCRIPTEN
--- a/project_files/hwc/rtl/pas2c.h	Fri Feb 07 15:44:27 2014 +0400
+++ b/project_files/hwc/rtl/pas2c.h	Fri Feb 07 22:42:57 2014 +0400
@@ -7,32 +7,35 @@
 #include <math.h>
 
 #define MAX_PARAMS 64
+#define MAX_ANSISTRING_LENGTH 16384
 
 typedef union string255_
     {
         struct {
-            unsigned char s[257];
+            unsigned char s[256];
         };
         struct {
             unsigned char len;
-            unsigned char str[256];
+            unsigned char str[255];
         };
     } string255;
-typedef struct string192_
-    {
-        unsigned char s[193];
-    } string192;
-typedef struct string31_
+
+typedef union astring_
     {
-        unsigned char s[32];
-    } string31;
-typedef struct string15_
-    {
-        unsigned char s[16];
-    } string15;
+        struct {
+            unsigned char _dummy1;
+            string255 str255;
+        };
+        struct {
+            unsigned char _dummy2;
+            unsigned char str[MAX_ANSISTRING_LENGTH];
+        };
+        struct {
+            uint16_t len;
+        };
+    } astring;
 
 typedef string255 shortstring;
-typedef string255 ansistring;
 
 typedef uint8_t Byte;
 typedef int8_t ShortInt;
--- a/tools/pas2c/Pas2C.hs	Fri Feb 07 15:44:27 2014 +0400
+++ b/tools/pas2c/Pas2C.hs	Fri Feb 07 22:42:57 2014 +0400
@@ -1200,6 +1200,7 @@
         ("pchar", BTString) -> ref2C $ FunCall [expr] (SimpleReference (Identifier "_pchar" $ BTPointerTo BTChar))
         ("pchar", BTAString) -> ref2C $ FunCall [expr] (SimpleReference (Identifier "_pcharA" $ BTPointerTo BTChar))
         ("shortstring", BTPointerTo _) -> ref2C $ FunCall [expr] (SimpleReference (Identifier "pchar2str" $ BTString))
+        ("ansistring", BTString) -> ref2C $ FunCall [expr] (SimpleReference (Identifier "str2astr" $ BTAString))
         (a, _) -> do
             e <- expr2C expr
             t <- id2C IOLookup t'