packages feed

splitter (empty) → 0.1.0.0

raw patch · 5 files changed

+254/−0 lines, 5 filesdep +basedep +directorydep +filepathsetup-changed

Dependencies added: base, directory, filepath, parsec, range

Files

+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2013 Robert Massaioli <robertmassaioli@gmail.com>++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be+included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Main.hs view
@@ -0,0 +1,83 @@+module Main (main) where++{-+ - This is a remake of 'tee' written in Haskell for the Cross Platform benefits.+ -}++import Control.Monad++import Data.List (intercalate)++import System.IO+import System.Environment ( getArgs )+import System.Exit+import System.Console.GetOpt+import System.FilePath+import System.Directory++import Text.Parsec.Error++import Data.Range.Range+import Data.Range.Parser++main :: IO ()+main = do+  args <- getArgs+  case getOpt Permute options args of+      (flags, nonOpts, [])     -> handleFlags flags nonOpts+      (_,     _,       msgs)   -> error $ concat msgs ++ usageInfo header options++data Flag +   = Version +   | Help +   | Numbered+   | Invert+   | Start Int +   | End Int+   deriving(Eq)++header :: String+header = "Usage: split [options] <input>"++versionInfo :: String+versionInfo = "splitter-0.1 by Robert Massaioli (2012-2013)"++options :: [OptDescr Flag] +options = +   [ Option "n" ["numbers"] (NoArg Numbered) "include line numbers in final output"+   , Option "i" ["invert"] (NoArg Invert) "get the opposite of the lines specified"+   , Option "Vv" ["version"] (NoArg Version) "print version number"+   , Option "Hh" ["help"] (NoArg Help) "print this help message"+   ]++handleFlags :: [Flag] -> [String] -> IO ()+handleFlags flags inputs+  | Help `elem` flags = putStrLn (usageInfo header options)+  | Version `elem` flags = putStrLn versionInfo+  | otherwise = case actualRanges of+                  Left error -> do+                     putStrLn . show $ error+                     exitWith (ExitFailure 1)+                  Right realRanges -> runSplit realRanges+  where+    actualRanges :: Either ParseError [Range Integer]+    actualRanges = parseRanges (intercalate "," inputs)++    runSplit :: [Range Integer] -> IO ()+    runSplit ranges  = do+         lines <- liftM lines getContents+         go 1 lines+      where+         go :: Integer -> [String] -> IO ()+         go _       []        = return ()+         go lineNum (line:ls) = do+            when (inRanges realRanges lineNum) $ do+               when includeNumbers . putStr $ show lineNum ++ " "+               putStrLn line+            go (lineNum + 1) ls++         includeNumbers = Numbered `elem` flags+         +         realRanges = if Invert `elem` flags+            then invert ranges+            else ranges
+ README.markdown view
@@ -0,0 +1,85 @@+# Splitter++Author: _Robert Massaioli_++Welcome to the splitter program written in Haskell. The purpose of this program is to+allow an easy way to extract ranges of lines from text files. Programs like head and tail+extract from the beginning and ends of files and programs like cat print out the entire+file. But what if you want to extract lines 101-127 in a file? This is the exact problem+that splitter was designed to solve and you can do that like this:++    splitter 101-127++Features include:++ - Written in Haskell and therefore Cross-Platform+ - Very Efficient / Very Fast+ - Does one job and does it well: in agreement with the [Unix Philosophy][1].++It is my hope that this tool becomes a valuable part of your toolkit and, if it does, then+please feel free to send me an email telling me about it.++## Example Invocations++Extract a few choice prime lines from a file:++    splitter 2,3,5,7,11,13++Semantically all of the arguments are concatenated together using the ',' symbol meaning+that the previous line is identical to this one:++    splitter 2 3 5 7 11 12++You can extract spans of lines. For example, getting lines ten to twenty and thirty to+eighty would be done like so:++    splitter 10-20 30-80++You can extract ranges of lines that are bound on only one end. So if you wanted to+extract everything from line fourty onwards then you could do the following:++    splitter 40-++You can of course perform the reverse operation and get all the lines counting upto and+including fourty:++    splitter -40++And, if you really want to then you can just get all of the lines in the file:++    splitter *    # This is the same as the 'cat' program++And that is all that there is to it. There are a few extra useful options such as the+invert range and number lines options that invert the ranges you selected and add original+line numbers next to the output. For more information run the help command.++*Important* All ranges you can select are inclusive, so 10-20 will include lines ten and+twenty. In mathematical notation all ranges are square brackets and not round brackets.++## Installation Instructions++Install it just like a normal haskell program. Download the source and then just:++    cabal install++And make sure that your cabal bin directory is in your environments PATH variable. That is all that+there is to it.++If you wish to have a play around with it first before installing it in your cabal/bin+directory then you may wish to install it first in a [cabal-dev][2] environment.++## Command Line Options++You can get these by simply asking for help:++    $ splitter -h+    Usage: split [options] <input>+      -n      --numbers  include line numbers in final output+      -i      --invert   get the opposite of the lines specified+      -V, -v  --version  print version number+      -H, -h  --help     print this help message++And that is everything that you can currently do with the splitter program.++ [1]: http://en.wikipedia.org/wiki/Unix_philosophy+ [2]: http://www.haskell.org/haskellwiki/Cabal-dev
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ splitter.cabal view
@@ -0,0 +1,64 @@+Name:                splitter+Version:             0.1.0.0++Synopsis:            Use numerical ranges to split out certain lines from a file.++Description:         +   Splitter lets you specify numerical ranges to split out certain lines+   from a file. This means that you can extract exactly what you want from a file and only+   the sections that you want. Or, if you are only interested in a log file after a certain+   preamble then you can specify that range of files too.++-- The license under which the package is released.+License:             MIT++License-file:        LICENSE++-- The package author+Author:              Robert Massaioli++Maintainer:          robertmassaioli@gmail.com++stability:           provisional++-- Project Information+homepage:            https://bitbucket.org/robertmassaioli/splitter++bug-reports:         https://bitbucket.org/robertmassaioli/splitter/issues++-- A copyright notice.+Copyright: (c) 2013 Robert Massaioli++Category:            Text++Build-type:          Simple++-- Extra files to be distributed with the package, such as examples or+-- a README.+Extra-source-files:  README.markdown++-- Constraint on the version of Cabal needed to build this package.+Cabal-version:       >=1.6++Source-repository head+   type:       git+   location:   git@bitbucket.org:robertmassaioli/splitter.git++Executable splitter+  -- .hs or .lhs file containing the Main module.+  Main-is:             Main.hs+  +  -- Packages needed in order to build this package.+  Build-depends: +    base >= 4 && < 5, +    directory >= 1.1 && < 1.3, +    filepath >= 1.2 && < 1.4,+    parsec >= 3, +    range >= 0.1 && <= 0.2 +  +  -- Modules not exported by this package.+  -- Other-modules:       +  +  -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.+  -- Build-tools:         +