Skip to content

Instantly share code, notes, and snippets.

@tsurushuu
Created November 30, 2011 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsurushuu/1408993 to your computer and use it in GitHub Desktop.
Save tsurushuu/1408993 to your computer and use it in GitHub Desktop.
module Main where
import System
import Data.List
import Control.Monad
separateDiffPatch :: String -> [String]
separateDiffPatch str = map unlines . map (head . filter patchEnd . inits) . (filter patchStart . tails) . lines $ str
where
patchStart (l0 : l1 : l2 : ls) = and [isPrefixOf "From " l0, isPrefixOf "From: " l1, isPrefixOf "Date: " l2]
patchStart _ = False
--
patchEnd ss = isSuffixOf ["1.7.5.1", ""] ss
main = do
args <- getArgs
let fn = args !! 0
contents <- readFile fn
let eachFNs = map (\n -> fn ++ "." ++ show n) [1..]
let eachPatches = separateDiffPatch contents
zipWithM (writeFile) eachFNs eachPatches
return ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment