@@ -31,45 +31,44 @@ main = do
3131 -- Get all the constants defined in the data file for the build tool.
3232 customDataFile <- getDataFileName " CustomBuildToolData.txt"
3333 customDataFileExists <- doesFileExist customDataFile
34- unless customDataFileExists $ do
35- cwd <- getCurrentDirectory
36- error $
37- unlines
38- [ " Custom preprocessor could not access its data file."
39- , " Tried to look in: " ++ customDataFile
40- , " cwd: " ++ show cwd ]
41- customDataLines <- lines <$> readFile customDataFile
34+ -- unless customDataFileExists $ do
35+ -- cwd <- getCurrentDirectory
36+ -- error $
37+ -- unlines
38+ -- [ "Custom preprocessor could not access its data file."
39+ -- , "Tried to look in: " ++ customDataFile
40+ -- , "cwd: " ++ show cwd ]
41+ -- customDataLines <- lines <$> readFile customDataFile
4242 let customConstants :: Map String Int
43- customConstants = Map. fromList $ map read customDataLines
43+ customConstants = Map. fromList $ [( " MyConstant " , 1717 )] -- map read customDataLines
4444
4545 -- Obtain input/output file paths from arguments to the preprocessor.
4646 args <- getArgs
47- (inputFile, outputFile) <-
48- case args of
49- [inputFile, outputFile] -> do
50- inputFileExists <- doesFileExist inputFile
51- unless inputFileExists $
52- error $
53- unlines
54- [ " Custom preprocess could not read input file."
55- , " Input file: " ++ inputFile ]
56- return (inputFile, outputFile)
57- _ ->
47+ case args of
48+ [inputFile, outputFile] -> do
49+ inputFileExists <- doesFileExist inputFile
50+ unless inputFileExists $
5851 error $
5952 unlines
60- [ " Custom preprocessor was given incorrect arguments."
61- , " Expected exactly two arguments (input and output file paths), but got " ++ what ++ " ." ]
62- where
63- what = case args of
64- [] -> " none"
65- [_] -> " a single argument"
66- _ -> show (length args) ++ " arguments"
67-
68- -- Read the input file, substitute constants for their values,
69- -- and write the result to the output file path.
70- inputLines <- lines <$> readFile inputFile
71- let outputLines = map ( preprocessLine customConstants ) ( zip [1 .. ] inputLines )
72- writeFile outputFile ( unlines outputLines )
53+ [ " Custom preprocessor could not read input file."
54+ , " Input file: " ++ inputFile ]
55+ -- Read the input file, substitute constants for their values,
56+ -- and write the result to the output file path.
57+ inputLines <- lines <$> readFile inputFile
58+ let outputLines = map ( preprocessLine customConstants ) ( zip [1 .. ] inputLines )
59+ writeFile outputFile ( unlines outputLines )
60+ [] ->
61+ putStrLn " Custom preprocessor: no arguments."
62+ _ ->
63+ error $
64+ unlines
65+ [ " Custom preprocessor was given incorrect arguments."
66+ , " Expected input and output file paths, but got " ++ what ++ " ." ]
67+ where
68+ what = case args of
69+ [] -> " none"
70+ [_] -> " a single argument"
71+ _ -> show (length args) ++ " arguments"
7372
7473-- | Substitute any occurrence of {# ConstantName #} with the value of ConstantName,
7574-- looked up in the data file for the preprocessor.
0 commit comments