-------------------------------------------------------------------------------- -- $Id: RepToRDFMain.hs,v 1.2 2004/03/26 21:20:07 graham Exp $ -- -- Copyright (c) 2004, G. KLYNE. All rights reserved. -- See end of this file for licence information. -------------------------------------------------------------------------------- -- | -- Module : RepToRDFMain -- Copyright : (c) 2004, Graham Klyne -- License : GPL V2 -- -- Maintainer : Graham Klyne -- Stability : provisional -- Portability : H98 -- -- RepToRDF: convert report definition to RDF/N3, -- for subsequent processing by N3Report. -- -------------------------------------------------------------------------------- module RepToRDFMain(runRepToRDF,runRepToRDFArgs) where import RepCommands ( repFormat , repInput , repOutput ) import RepMonad ( RepStateIO, RepState(..) , setFormat, setGraph, setExitcode , emptyState , RepFormat(..) , repError , reportLines, reportLine ) import ListHelpers ( breakAll ) import Control.Monad.State ( MonadState(..), modify, StateT(..), execStateT ) import Monad ( when ) import Data.Char ( isSpace ) import IO ( hPutStrLn, stderr ) import System ( ExitCode(ExitSuccess,ExitFailure) ) ------------------------------------------------------------ -- Command line description ------------------------------------------------------------ usageText = [ "RepToRDF 0.1" , "Convert report definition to RDF/N3." , "" , "Usage: RepToRDF option option ..." , "" , "where the options are processed from left to right, and may be" , "any of the following:" , "-? display this message." , "-n3 use Notation3 format for subsequent output." , "-i[=file] read and parse report definition file into an internal RDF graph" , "-o[=file] the graph workspace to a file in the selected format." , "" , " If an optional filename value is omitted, the standard input" , " or output stream is used, as appropriate." , "" , "Exit status codes:" , "Success - operation completed successfully/graphs compare equal" , "2 - input data format error" , "3 - file access problem" , "4 - command line error" , "" , "Examples:" , "" , "RepToRDF -i=file.rep -o=file.n3" , "RunHugs RepToRDF -i=file.rep -o=file.n3" , " read report from file.rep and write to file.n3 as Notation3." ] ------------------------------------------------------------ -- RepToRDF command line interpreter ------------------------------------------------------------ -- repCommands :: [String] -> RepStateIO () repCommands [] = do { repHelp } repCommands args = do { sequence_ (map repCommand args) } repCommand :: String -> RepStateIO () repCommand cmd = let (nam,more) = break (=='=') cmd arg = drop 1 more in case nam of "" -> return () -- do nothing "-?" -> repHelp "-n3" -> repFormat N3 "-i" -> repInput arg "-o" -> repOutput arg otherwise -> repError ("Invalid command line element: "++cmd) 4 repHelp :: RepStateIO () repHelp = reportLines usageText ------------------------------------------------------------ -- Interactive test function (e.g. for use in Hugs) ------------------------------------------------------------ runRepToRDF :: String -> IO ExitCode runRepToRDF cmdline = do { let args = breakAll isSpace cmdline ; ec <- runRepToRDFArgs args ; when (ec /= ExitSuccess) (putStrLn $ "RepToRDF exit: "++show ec) ; return ec } runRepToRDFArgs :: [String] -> IO ExitCode runRepToRDFArgs args = do { state <- execStateT (repCommands args) emptyState ; return $ exitcode state } run fnam = runRepToRDF ("-n3 -i="++fnam++".rep -o="++fnam++".n3") run1 = run "TinyReport" run2 = run "SimpleReport" run3 = run "GenHeaderRegistry" -------------------------------------------------------------------------------- -- -- Copyright (c) 2004, G. KLYNE. All rights reserved. -- -- This is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This software is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with RepToRDF; if not, write to: -- The Free Software Foundation, Inc., -- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- or view the web page at: -- http://www.gnu.org/copyleft/gpl.html -- -------------------------------------------------------------------------------- -- $Source: /file/cvsdev/CompileRDF/RepToRDFMain.hs,v $ -- $Author: graham $ -- $Revision: 1.2 $ -- $Log: RepToRDFMain.hs,v $ -- Revision 1.2 2004/03/26 21:20:07 graham -- Bug-fixes to support report generation. -- (The old Python code is a bit flakey in places.) -- -- Revision 1.1 2004/03/26 12:18:05 graham -- Created report description compiler --