functor Driver(P: PPC): DRIVER = struct structure P = P type config = { file: string option, includeDirs: string list } val initConfig: config = { file = NONE, includeDirs = [] } fun die msg = (printLn msg; Posix.Process.exit $ Word8.fromInt 1) fun parseCmdArgs { file, includeDirs } [] = if file = NONE then die "missing input file" else { file, includeDirs = rev includeDirs } | parseCmdArgs _ ("-I" :: []) = die "-I: expected directory path after flag" | parseCmdArgs { file, includeDirs } ("-I" :: path :: tail) = parseCmdArgs { file, includeDirs = path :: includeDirs } tail | parseCmdArgs { file, includeDirs } (arg :: tail) = if String.sub (arg, 0) = #"-" then die $ arg ^ ": unknown flag" else case file of NONE => parseCmdArgs { file = SOME arg, includeDirs } tail | SOME _ => die $ arg ^ ": file already specified" fun exec () = let val config = parseCmdArgs initConfig (CommandLine.arguments ()) val fname = valOf $ #file config in P.debugPrint fname (#includeDirs config) end end