From 868de033ed2e68c4cf1bb16bd3f44e2dac0df526 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Sun, 13 Oct 2019 17:45:34 -0400 Subject: Better usage documentation. --- monkeypatch.hs | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/monkeypatch.hs b/monkeypatch.hs index d6ff1c2..7da9c7d 100644 --- a/monkeypatch.hs +++ b/monkeypatch.hs @@ -1867,13 +1867,47 @@ includeStack bs = foldr go (const emptyIncludes) incs [] | "2" `elem` B.words inc = xs (drop 1 stack) | otherwise = xs stack +usageString self = unlines + [ self ++ " [--cpp | -p | -t | --comments | --tohs ] [--nodo] [-v] [-f ] -- [gcc options] [modules] " + , "" + , "MODES" + , "" + , " default Generate a monkey-patchable Haskell interface to given C module." + , "" + , " --cpp Show Preprocessor include stack (debugging output)." + , "" + , " -p Preprocess. Output C with expanded macros (includes are NOT expanded)." + , "" + , " -t Tree. Output language-c parse tree (verbose!)." + , "" + , " --comments Output information about comment tokens occuring in file." + , "" + , " --tohs Attempt to translate C into Haskell (works on simple things)." + , "" + , "OPTIONS" + , "" + , " -v Verbose output." + , "" + , " -f Select a single function from the C file rather than the whole of it." + , " This affects the default and --tohs modes." + , "" + , " --nodo In --tohs mode, avoid outputting do-syntax sugar." + , "" + , "ARGUMENTS" + , "" + , " [gcc options] Options passed to gcc during preprocessing or linking." + , "" + , " [modules] Extra modules (.c or .o). When generating stubs, these symbols are excluded." + , "" + , " The .c module being interfaced or preprocessed." + ] + main :: IO () main = do self <- getProgName args <- getArgs - let usageString = self ++ " [--cpp | -p | -t ] [-v] [-f ] -- [gcc options] [modules] " let m = usage args - fromMaybe (putStrLn usageString) $ m <&> \(hopts,cargs,fname:fs) -> do + fromMaybe (putStrLn $ usageString self) $ m <&> \(hopts,cargs,fname:fs) -> do prer <- runPreprocessor (newGCC "gcc") (rawCppArgs cargs fname) let r :: Either (Either ExitCode ParseError) (IncludeStack, CTranslUnit) r = do @@ -1884,7 +1918,7 @@ main = do -- putStrLn $ "includes = " ++ ppShow (fmap fst r) -- cs <- readComments fname case () of - _ | oCommentsOnly hopts + _ | oCommentsOnly hopts -- --comments -> do cs <- readComments fname forM_ cs $ \c -> do putStrLn $ show c -- cgit v1.2.3