stuff
This commit is contained in:
		
							parent
							
								
									d6d9ebb881
								
							
						
					
					
						commit
						bd4e79e064
					
				|  | @ -43,7 +43,7 @@ executable adiff | |||
|   main-is: MainDiff.hs | ||||
| 
 | ||||
|   -- Modules included in this executable, other than Main. | ||||
|   other-modules: Redfa, Version, Diff | ||||
|   other-modules: Redfa, Version, Diff, Merge | ||||
| 
 | ||||
|   -- LANGUAGE extensions used by modules in this package. | ||||
|   other-extensions: CPP | ||||
|  |  | |||
							
								
								
									
										108
									
								
								src/MainDiff.hs
									
									
									
									
									
								
							
							
						
						
									
										108
									
								
								src/MainDiff.hs
									
									
									
									
									
								
							|  | @ -1,38 +1,108 @@ | |||
| module Main where | ||||
| 
 | ||||
| import Data.ByteString.UTF8 (fromString) | ||||
| import qualified Data.ByteString as B | ||||
| import qualified Data.ByteString.Char8 as B8 | ||||
| import Data.ByteString.UTF8 (fromString) | ||||
| import qualified Data.Vector as V | ||||
| import Diff | ||||
| import Merge | ||||
| import Options.Applicative | ||||
| import Redfa | ||||
| import Version | ||||
| import Diff | ||||
| import qualified Data.Vector as V | ||||
| import System.IO.MMap | ||||
| import Version | ||||
| 
 | ||||
| data DiffOptions = | ||||
|   DiffOptions | ||||
|     { diffRedfaOpt :: RedfaOption | ||||
|     , context :: Int | ||||
|     , diffFile1 :: String | ||||
|     , diffFile2 :: String | ||||
| data ADiffOptions = | ||||
|   ADiffOptions | ||||
|     { adiffRedfaOpt :: RedfaOption | ||||
|     , adiffCmdOpts :: ADiffCommandOpts | ||||
|     } | ||||
|   deriving (Show) | ||||
| 
 | ||||
| diffOpts = | ||||
|   DiffOptions <$> redfaOption | ||||
|   <*> option auto (metavar "CONTEXT" <> short 'C' <> long "context" <> value 5) | ||||
|   <*> strArgument (metavar "FROMFILE") | ||||
|   <*> strArgument (metavar "TOFILE") | ||||
| data ADiffCommandOpts | ||||
|   = CmdDiff | ||||
|       { context :: Int | ||||
|       , diffFile1 :: String | ||||
|       , diffFile2 :: String | ||||
|       } | ||||
|   | CmdPatch | ||||
|       { patchDryRun :: Bool | ||||
|       , patchInDir :: Maybe String | ||||
|       , patchInput :: String | ||||
|       , patchReverse :: Bool | ||||
|       , patchPathStrip :: Int | ||||
|       , patchMergeOpts :: MergeOpts | ||||
|       } | ||||
|   | CmdDiff3 | ||||
|       { diff3Mine :: String | ||||
|       , diff3Old :: String | ||||
|       , diff3Yours :: String | ||||
|       , diff3MergeOpts :: MergeOpts | ||||
|       } | ||||
|   deriving (Show) | ||||
| 
 | ||||
| diffCmdOptions = | ||||
|   CmdDiff <$> | ||||
|   option | ||||
|     auto | ||||
|     (metavar "CONTEXT" <> | ||||
|      short 'C' <> | ||||
|      long "context" <> | ||||
|      value 5 <> help "How many tokens around the change to include in the patch") <*> | ||||
|   strArgument (metavar "FROMFILE") <*> | ||||
|   strArgument (metavar "TOFILE") | ||||
| 
 | ||||
| patchCmdOptions = | ||||
|   CmdPatch <$> | ||||
|   switch | ||||
|     (short 'n' <> | ||||
|      long "dry-run" <> | ||||
|      help "Do not patch anything, just print what would happen") <*> | ||||
|   optional | ||||
|     (strOption $ | ||||
|      short 'd' <> long "directory" <> metavar "DIR" <> help "Work in DIR") <*> | ||||
|   strOption | ||||
|     (short 'i' <> | ||||
|      long "input" <> | ||||
|      metavar "INPUT" <> | ||||
|      help "Read the patchfile from INPUT, defaults to `-' for STDIN" <> | ||||
|      value "-") <*> | ||||
|   switch (short 'R' <> long "reverse" <> help "Unapply applied patches") <*> | ||||
|   option | ||||
|     auto | ||||
|     (short 'p' <> | ||||
|      long "strip" <> | ||||
|      metavar "NUM" <> help "Strip NUM leading components from the paths" <> | ||||
|      value 0) <*> | ||||
|   mergeOption True | ||||
| 
 | ||||
| diff3CmdOptions = | ||||
|   CmdDiff3 <$> strArgument (metavar "MYFILE") <*> | ||||
|   strArgument (metavar "OLDFILE") <*> | ||||
|   strArgument (metavar "YOURFILE") <*> | ||||
|   mergeOption False | ||||
| 
 | ||||
| actionOption :: Parser ADiffCommandOpts | ||||
| actionOption = | ||||
|   hsubparser $ | ||||
|   mconcat | ||||
|     [ command "diff" $ info diffCmdOptions $ progDesc "Compare two files" | ||||
|     , command "patch" $ info patchCmdOptions $ progDesc "Apply a patch to files" | ||||
|     , command "diff3" $ | ||||
|       info diff3CmdOptions $ progDesc "Compare and merge three files" | ||||
|     ] | ||||
| 
 | ||||
| adiffOptions = ADiffOptions <$> redfaOption <*> actionOption | ||||
| 
 | ||||
| main :: IO () | ||||
| main = | ||||
|   let opts :: ParserInfo DiffOptions | ||||
|   let opts :: ParserInfo ADiffOptions | ||||
|       opts = | ||||
|         info | ||||
|           (diffOpts <**> versionOption "adiff" <**> helperOption) | ||||
|           (adiffOptions <**> versionOption "adiff" <**> helperOption) | ||||
|           (fullDesc <> | ||||
|            progDesc "Compare files by tokens and print out differences." <> | ||||
|            header "adiff: arbitrary-token diff") | ||||
|            progDesc | ||||
|              "Compare, patch and merge files on arbitrarily-tokenized sequences." <> | ||||
|            header "adiff: arbitrary-token diff utilities") | ||||
|    in do o <- execParser opts | ||||
|          redfa <- redfaPrepareRules (diffRedfaOpt o) | ||||
|          data1 <- mmapFileByteString (diffFile1 o) Nothing | ||||
|  |  | |||
							
								
								
									
										10
									
								
								src/Redfa.hs
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/Redfa.hs
									
									
									
									
									
								
							|  | @ -45,13 +45,13 @@ redfaOption = | |||
|   some | ||||
|     (strOption $ | ||||
|      metavar "RULE" <> | ||||
|      short 'r' <> | ||||
|      long "rule" <> help "Lexing rule (specify repeatedly for more rules)") <|> | ||||
|      short 'L' <> | ||||
|      long "lex" <> help "Lexing rule (specify repeatedly for more rules)") <|> | ||||
|   RedfaOptionFile <$> | ||||
|   strOption | ||||
|     (metavar "RULESFILE" <> | ||||
|      short 'R' <> | ||||
|      long "rules-file" <> help "File from where to load the lexing rules") | ||||
|     (metavar "FILE" <> | ||||
|      short 'l' <> | ||||
|      long "lexer" <> help "File from where to load the lexing rules") | ||||
| 
 | ||||
| redfaOptionToRuleStrings :: RedfaOption -> IO [BS] | ||||
| redfaOptionToRuleStrings (RedfaOptionRules x) = return x | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue