X-Git-Url: https://mattmccutchen.net/match/match.git/blobdiff_plain/86e209954803086a9a880fe3cd538d2c866cb8d6..e5c5cbd9d48ecf8de5e7b0c20d7164b4b7bf340b:/program/Main.hs diff --git a/program/Main.hs b/program/Main.hs index d45755e..92c91fc 100644 --- a/program/Main.hs +++ b/program/Main.hs @@ -5,28 +5,15 @@ import System.IO import Data.Array.IArray import Data.Array.Unboxed import ArrayStuff -import Text.CSV +import TSV -- Command-line interface with simple tab-separated input/output formats. -- ./match if c == '\t' then ',' else if c == ',' then '\t' else c) s -removeQuotes s = filter (\c -> not (c == '"')) s - --- Some versions of Text.CSV do not use or accept a trailing newline; compensate for that. -removeTrailingNewline s = if not (null s) && last s == '\n' then init s else s -addTrailingNewline s = if not (null s) && last s /= '\n' then s ++ ['\n'] else s - -parseTSV fname str = case parseCSV fname (swapTabCommaIn $ removeTrailingNewline str) of - Left pe -> Left pe - Right ll -> Right $ map (map swapTabCommaIn) ll -printTSV ll = addTrailingNewline $ removeQuotes $ swapTabCommaIn $ printCSV $ map (map swapTabCommaIn) ll - main = do incsv <- hGetContents stdin -- handle errors another day, or let the platform do it - let Right inll = parseTSV "standard input" incsv + let inll = parseTSV incsv let loadList = tail (head inll) let numRvrs = length loadList let loadA = listArray (0, numRvrs-1) (map read loadList) @@ -45,4 +32,4 @@ main = do let pnrA = funcArray (0, numProps-1) (\j -> read $ pxarr ! (2*j, 0)) let theInst = PMInstance numRvrs numProps loadA prefA expA fixA pnrA let PMatching theMatching = doMatching pmDefaults theInst - hPutStr stdout $ printTSV $ map (\(i, j) -> map show [i, j]) theMatching + hPutStr stdout $ formatTSV $ map (\(i, j) -> map show [i, j]) theMatching