Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions diffr.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: diffr
Version: 0.0
Version: 0.2
Description: Intelligent diff/patch tool that knows how to copy and move, has an 'r' at the end of its name.
License: GPL-3
License-file: LICENCE
Expand All @@ -8,12 +8,20 @@ Maintainer:
Build-Type: Simple
Cabal-Version: >=1.2

Library
Build-Depends: base >= 4
Hs-Source-Dirs: src
Exposed-Modules: Diffr.Util.ArgumentsProcessor
ghc-options: -Wall

Executable diffr
Main-is: src/diffr/diff/Main.hs
Main-is: Diffr/Diff/Main.hs
Build-Depends: base >= 4
ghc-options: -Wall
Other-Modules: Diffr.Util.ArgumentsProcessor
Hs-Source-Dirs: src
ghc-options: -Wall

Executable patchr
Main-is: src/diffr/patch/Main.hs
Main-is: src/Diffr/Patch/Main.hs
Build-Depends: base >= 4
ghc-options: -Wall
ghc-options: -Wall
11 changes: 6 additions & 5 deletions src/diffr/diff/Main.hs → src/Diffr/Diff/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,24 @@

module Main ( main ) where

import Data.Char( intToDigit )
import Diffr.Util.ArgumentsProcessor( containsHelpArgument, extractOutputFile )
import System.Environment( getArgs )
import System.Exit ( exitFailure, exitSuccess )

-- | 'main' runs the main program
-- | 'main' runs diffr.
main :: IO ()
main = do
args <- getArgs
if not ( 2 == length args || 4 == length args )
if ( containsHelpArgument args || not ( 2 == length args || 4 == length args ) )
then do
printUsage
exitFailure
else do
print ( length args )
print ( [intToDigit ( length args )] ++ " arguments" )
print ( extractOutputFile args )
exitSuccess



-- | 'printUsage' prints the usage information for diffr.
printUsage :: IO ()
printUsage = putStrLn ( "Usage: \n" ++
Expand Down
File renamed without changes.
44 changes: 44 additions & 0 deletions src/Diffr/Util/ArgumentsProcessor.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{- |
Module : Diffr.Util.ArgumentsProcessor
Description : Arguments processor for diffr.
Since : 0.2
Authors : William Martin
License : This file is part of diffr-h.

diffr-h 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 3 of the License, or
(at your option) any later version.

diffr-h 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 diffr-h. If not, see <http://www.gnu.org/licenses/>.
-}

module Diffr.Util.ArgumentsProcessor ( containsHelpArgument, extractOutputFile ) where

import Data.Char ( toLower )

-- | 'containsHelpArgument' checks if the given list of strings contains the help argument.
containsHelpArgument :: [[Char]] -> Bool
containsHelpArgument args = any isHelpArgument ( map ( map toLower ) args )

-- | 'extractOutputFile' extracts the output file argument from a list of strings.
extractOutputFile :: [[Char]] -> [Char]
extractOutputFile args = case args of
[] -> ""
("-o":[]) -> ""
("-o":xs) -> head ( xs )
_ -> extractOutputFile ( tail args )

-- | 'isHelpArgument' checks if a string is a help argument.
isHelpArgument :: [Char] -> Bool
isHelpArgument arg = case arg of
[] -> False
('-':[]) -> False
('-':xs) -> isHelpArgument( xs )
"help" -> True
_ -> False