multifile (empty) → 0.1.0.0
raw patch · 7 files changed
+178/−0 lines, 7 filesdep +HaXmldep +basesetup-changed
Dependencies added: HaXml, base
Files
- ChangeLog.md +5/−0
- LICENSE +30/−0
- README.md +4/−0
- Setup.hs +2/−0
- multifile.cabal +70/−0
- src/Extsubset.hs +51/−0
- src/Main.hs +16/−0
+ ChangeLog.md view
@@ -0,0 +1,5 @@+# Revision history for multifile++## 0.1.0.0 -- YYYY-mm-dd++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2016, Alan Hawkins++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Alan Hawkins nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,4 @@+# multifile+++cat test.xml | multifile
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ multifile.cabal view
@@ -0,0 +1,70 @@+-- Initial multifile.cabal generated by cabal init. For further +-- documentation, see http://haskell.org/cabal/users-guide/++-- The name of the package.+name: multifile++-- The package version. See the Haskell package versioning policy (PVP) +-- for standards guiding when and how versions should be incremented.+-- https://wiki.haskell.org/Package_versioning_policy+-- PVP summary: +-+------- breaking API changes+-- | | +----- non-breaking API additions+-- | | | +--- code changes with no API change+version: 0.1.0.0++-- A short (one-line) description of the package.+synopsis: create many files from one++-- A longer description of the package.+description: saves the contents of files from a spefically defined xml document++-- URL for the project homepage or repository.+homepage: xy30.com++-- The license under which the package is released.+license: BSD3++-- The file containing the license text.+license-file: LICENSE++-- The package author(s).+author: Alan Hawkins++-- An email address to which users can send suggestions, bug reports, and +-- patches.+maintainer: hawk.alan@gmail.com++-- A copyright notice.+-- copyright: ++category: Text++build-type: Simple++-- Extra files to be distributed with the package, such as examples or a +-- README.+extra-source-files: ChangeLog.md, README.md++-- Constraint on the version of Cabal needed to build this package.+cabal-version: >=1.10+++executable multifile+ -- .hs or .lhs file containing the Main module.+ main-is: Main.hs+ + -- Modules included in this executable, other than Main.+ other-modules: Extsubset+ + -- LANGUAGE extensions used by modules in this package.+ -- other-extensions: + + -- Other library packages from which modules are imported.+ build-depends: base >=4.9 && <4.10 , HaXml < 10000+ + -- Directories containing source files.+ hs-source-dirs: src+ + -- Base language which the package is written in.+ default-language: Haskell2010+
+ src/Extsubset.hs view
@@ -0,0 +1,51 @@+module Extsubset where++import Text.XML.HaXml.XmlContent+import Text.XML.HaXml.Types+import Text.XML.HaXml.OneOfN+++{-Type decls-}++newtype Multifile = Multifile [File] deriving (Eq,Show)+data File = File File_Attrs String+ deriving (Eq,Show)+data File_Attrs = File_Attrs+ { filePath :: String+ } deriving (Eq,Show)+++{-Instance decls-}++instance HTypeable Multifile where+ toHType x = Defined "multifile" [] []+instance XmlContent Multifile where+ toContents (Multifile a) =+ [CElem (Elem (N "multifile") [] (concatMap toContents a)) ()]+ parseContents = do+ { e@(Elem _ [] _) <- element ["multifile"]+ ; interior e $ return (Multifile) `apply` many parseContents+ } `adjustErr` ("in <multifile>, "++)++instance HTypeable File where+ toHType x = Defined "file" [] []+instance XmlContent File where+ toContents (File as a) =+ [CElem (Elem (N "file") (toAttrs as) (toText a)) ()]+ parseContents = do+ { e@(Elem _ as _) <- element ["file"]+ ; interior e $ return (File (fromAttrs as))+ `apply` (text `onFail` return "")+ } `adjustErr` ("in <file>, "++)+instance XmlAttributes File_Attrs where+ fromAttrs as =+ File_Attrs+ { filePath = definiteA fromAttrToStr "file" "path" as+ }+ toAttrs v = catMaybes + [ toAttrFrStr "path" (filePath v)+ ]++++{-Done-}
+ src/Main.hs view
@@ -0,0 +1,16 @@+module Main where++import System.Environment+import System.IO+import Text.XML.HaXml.XmlContent.Haskell+import Extsubset+import Data.Either++main :: IO ()+main = do + x <- getContents + let p = (readXml x :: Either String Multifile)+ either print processFiles p++processFiles (Multifile xs) = mapM_ processFile xs+processFile (File (File_Attrs path) content) = writeFile path content