# HG changeset patch # User unc0rr # Date 1334261326 -14400 # Node ID 70aec33185e27f4ef4cb616a80285369705a5ed5 # Parent 0eb73121aa4cf911747c3ed8d8f1a39760583513 Support string constants diff -r 0eb73121aa4c -r 70aec33185e2 hedgewars/pas2c.h --- a/hedgewars/pas2c.h Thu Apr 12 23:10:35 2012 +0400 +++ b/hedgewars/pas2c.h Fri Apr 13 00:08:46 2012 +0400 @@ -2,7 +2,10 @@ #include -typedef char string255[]; +typedef struct string255_ + { + char s[256]; + } string255; typedef int SmallInt; typedef int Word; diff -r 0eb73121aa4c -r 70aec33185e2 tools/pas2c.hs --- a/tools/pas2c.hs Thu Apr 12 23:10:35 2012 +0400 +++ b/tools/pas2c.hs Fri Apr 13 00:08:46 2012 +0400 @@ -119,8 +119,8 @@ toCFiles' (fn, p@(Program {})) = writeFile (fn ++ ".c") $ (render2C initialState . pascal2C) p toCFiles' (fn, (Unit unitId interface implementation _ _)) = do let (a, s) = runState (id2C IOInsert (setBaseType BTUnit unitId) >> interface2C interface) initialState - writeFile (fn ++ ".h") $ "#pragma once\n\n" ++ (render (a $+$ text "")) - writeFile (fn ++ ".c") $ "#include \"pas2c.h\"\n#include \"" ++ fn ++ ".h\"\n" ++ (render2C s . implementation2C) implementation + writeFile (fn ++ ".h") $ "#pragma once\n\n#include \"pas2c.h\"\n\n" ++ (render (a $+$ text "")) + writeFile (fn ++ ".c") $ "#include \"" ++ fn ++ ".h\"\n" ++ (render2C s . implementation2C) implementation initialState = emptyState ns render2C :: RenderState -> State RenderState Doc -> String @@ -362,7 +362,7 @@ initExpr2C (InitFloat s) = return $ text s initExpr2C (InitHexNumber s) = return $ text "0x" <> (text . map toLower $ s) initExpr2C (InitString [a]) = return . quotes $ text [a] -initExpr2C (InitString s) = return $ doubleQuotes $ text s +initExpr2C (InitString s) = return $ braces $ text ".s = " <> doubleQuotes (text s) initExpr2C (InitChar a) = return $ quotes $ text "\\x" <> text (showHex (read a) "") initExpr2C (InitReference i) = id2C IOLookup i initExpr2C (InitRecord fields) = do