stuff
This commit is contained in:
		
							parent
							
								
									d6d9ebb881
								
							
						
					
					
						commit
						bd4e79e064
					
				|  | @ -43,7 +43,7 @@ executable adiff | ||||||
|   main-is: MainDiff.hs |   main-is: MainDiff.hs | ||||||
| 
 | 
 | ||||||
|   -- Modules included in this executable, other than Main. |   -- 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. |   -- LANGUAGE extensions used by modules in this package. | ||||||
|   other-extensions: CPP |   other-extensions: CPP | ||||||
|  |  | ||||||
							
								
								
									
										108
									
								
								src/MainDiff.hs
									
									
									
									
									
								
							
							
						
						
									
										108
									
								
								src/MainDiff.hs
									
									
									
									
									
								
							|  | @ -1,38 +1,108 @@ | ||||||
| module Main where | module Main where | ||||||
| 
 | 
 | ||||||
| import Data.ByteString.UTF8 (fromString) | import qualified Data.ByteString as B | ||||||
| import qualified Data.ByteString.Char8 as B8 | 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 Options.Applicative | ||||||
| import Redfa | import Redfa | ||||||
| import Version |  | ||||||
| import Diff |  | ||||||
| import qualified Data.Vector as V |  | ||||||
| import System.IO.MMap | import System.IO.MMap | ||||||
|  | import Version | ||||||
| 
 | 
 | ||||||
| data DiffOptions = | data ADiffOptions = | ||||||
|   DiffOptions |   ADiffOptions | ||||||
|     { diffRedfaOpt :: RedfaOption |     { adiffRedfaOpt :: RedfaOption | ||||||
|     , context :: Int |     , adiffCmdOpts :: ADiffCommandOpts | ||||||
|     , diffFile1 :: String |  | ||||||
|     , diffFile2 :: String |  | ||||||
|     } |     } | ||||||
|   deriving (Show) |   deriving (Show) | ||||||
| 
 | 
 | ||||||
| diffOpts = | data ADiffCommandOpts | ||||||
|   DiffOptions <$> redfaOption |   = CmdDiff | ||||||
|   <*> option auto (metavar "CONTEXT" <> short 'C' <> long "context" <> value 5) |       { context :: Int | ||||||
|   <*> strArgument (metavar "FROMFILE") |       , diffFile1 :: String | ||||||
|   <*> strArgument (metavar "TOFILE") |       , 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 :: IO () | ||||||
| main = | main = | ||||||
|   let opts :: ParserInfo DiffOptions |   let opts :: ParserInfo ADiffOptions | ||||||
|       opts = |       opts = | ||||||
|         info |         info | ||||||
|           (diffOpts <**> versionOption "adiff" <**> helperOption) |           (adiffOptions <**> versionOption "adiff" <**> helperOption) | ||||||
|           (fullDesc <> |           (fullDesc <> | ||||||
|            progDesc "Compare files by tokens and print out differences." <> |            progDesc | ||||||
|            header "adiff: arbitrary-token diff") |              "Compare, patch and merge files on arbitrarily-tokenized sequences." <> | ||||||
|  |            header "adiff: arbitrary-token diff utilities") | ||||||
|    in do o <- execParser opts |    in do o <- execParser opts | ||||||
|          redfa <- redfaPrepareRules (diffRedfaOpt o) |          redfa <- redfaPrepareRules (diffRedfaOpt o) | ||||||
|          data1 <- mmapFileByteString (diffFile1 o) Nothing |          data1 <- mmapFileByteString (diffFile1 o) Nothing | ||||||
|  |  | ||||||
							
								
								
									
										10
									
								
								src/Redfa.hs
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/Redfa.hs
									
									
									
									
									
								
							|  | @ -45,13 +45,13 @@ redfaOption = | ||||||
|   some |   some | ||||||
|     (strOption $ |     (strOption $ | ||||||
|      metavar "RULE" <> |      metavar "RULE" <> | ||||||
|      short 'r' <> |      short 'L' <> | ||||||
|      long "rule" <> help "Lexing rule (specify repeatedly for more rules)") <|> |      long "lex" <> help "Lexing rule (specify repeatedly for more rules)") <|> | ||||||
|   RedfaOptionFile <$> |   RedfaOptionFile <$> | ||||||
|   strOption |   strOption | ||||||
|     (metavar "RULESFILE" <> |     (metavar "FILE" <> | ||||||
|      short 'R' <> |      short 'l' <> | ||||||
|      long "rules-file" <> help "File from where to load the lexing rules") |      long "lexer" <> help "File from where to load the lexing rules") | ||||||
| 
 | 
 | ||||||
| redfaOptionToRuleStrings :: RedfaOption -> IO [BS] | redfaOptionToRuleStrings :: RedfaOption -> IO [BS] | ||||||
| redfaOptionToRuleStrings (RedfaOptionRules x) = return x | redfaOptionToRuleStrings (RedfaOptionRules x) = return x | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue