From 6d1f8e25353fd46b517c678a7d8cea4a8b153a11 Mon Sep 17 00:00:00 2001 From: iphydf Date: Fri, 4 Feb 2022 21:03:11 +0000 Subject: [PATCH] fix: Always encode output as UTF-8 in cimplefmt. --- cimple.cabal | 2 ++ tools/BUILD.bazel | 2 ++ tools/cimplefmt.hs | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/cimple.cabal b/cimple.cabal index 47a5cbd..056aeb8 100644 --- a/cimple.cabal +++ b/cimple.cabal @@ -69,7 +69,9 @@ executable cimplefmt main-is: cimplefmt.hs build-depends: base < 5 + , bytestring , cimple + , text executable dump-ast default-language: Haskell2010 diff --git a/tools/BUILD.bazel b/tools/BUILD.bazel index 6cd2c0b..138a919 100644 --- a/tools/BUILD.bazel +++ b/tools/BUILD.bazel @@ -8,6 +8,8 @@ haskell_binary( deps = [ "//hs-cimple", hazel_library("base"), + hazel_library("bytestring"), + hazel_library("text"), ], ) diff --git a/tools/cimplefmt.hs b/tools/cimplefmt.hs index 7a25635..ba0bc99 100644 --- a/tools/cimplefmt.hs +++ b/tools/cimplefmt.hs @@ -1,5 +1,8 @@ module Main (main) where +import qualified Data.ByteString as BS +import qualified Data.Text as Text +import qualified Data.Text.Encoding as Text import Language.Cimple.IO (parseFile) import Language.Cimple.Pretty (ppTranslationUnit) import System.Environment (getArgs) @@ -10,8 +13,15 @@ processFile source = do putStrLn $ "Processing " ++ source ast <- parseFile source case ast of - Left err -> fail err - Right ok -> print $ ppTranslationUnit $ snd ok + Left err -> fail err + Right ok -> + BS.putStr + . Text.encodeUtf8 + . Text.pack + . show + . ppTranslationUnit + . snd + $ ok main :: IO ()