GiveYouAHead (empty) → 0.2.2.0
raw patch · 18 files changed
+666/−0 lines, 18 filesdep +basedep +directorydep +extrasetup-changed
Dependencies added: base, directory, extra, old-time, process
Files
- ChangeLog.md +13/−0
- GiveYouAHead.cabal +36/−0
- LICENSE +20/−0
- Setup.hs +3/−0
- lib/Data/GiveYouAHead.hs +68/−0
- lib/GiveYouAHead.hs +49/−0
- lib/GiveYouAHead/Build.hs +93/−0
- lib/GiveYouAHead/Build/ExtraCompileOption.hs +60/−0
- lib/GiveYouAHead/Build/FilesList.hs +13/−0
- lib/GiveYouAHead/Clean.hs +26/−0
- lib/GiveYouAHead/Common.hs +38/−0
- lib/GiveYouAHead/Help.hs +43/−0
- lib/GiveYouAHead/New.hs +46/−0
- lib/GiveYouAHead/New/Import.hs +6/−0
- lib/GiveYouAHead/New/Note.hs +37/−0
- lib/GiveYouAHead/New/Template.hs +6/−0
- lib/GiveYouAHead/Settings.hs +98/−0
- lib/GiveYouAHead/Version.hs +11/−0
+ ChangeLog.md view
@@ -0,0 +1,13 @@+# Revision history for GiveYouAHead + +## 0.2.2.0 -- 2015-06-16 20:59:12 + +add UTF8 and others + +## 0.2.0.0 -- 2015.6.* + +* a new release version after 0.1.* . + +## 0.1.0.0 -- 2015.* + +* old edition
+ GiveYouAHead.cabal view
@@ -0,0 +1,36 @@+-- Initial GiveYouAHead.cabal generated by cabal init. For further +-- documentation, see http://haskell.org/cabal/users-guide/ + +name: GiveYouAHead +version: 0.2.2.0 +synopsis: to auto-do somethings +description: to auto-do somethings +homepage: https://github.com/Qinka/GiveYouAHead/ +license: MIT +license-file: LICENSE +author: Qinka +maintainer: qinka@live.com +-- copyright: +category: GiveYouAHead +bug-reports: https://github.com/Qinka/GiveYouAHead/issues +build-type: Simple +extra-source-files: ChangeLog.md +cabal-version: >=1.10 + +source-repository head + type: git + location: https://github/com/Qinka/GiveYouAHead.git + +library + exposed-modules: GiveYouAHead, GiveYouAHead.Version, GiveYouAHead.Settings, GiveYouAHead.New, GiveYouAHead.Help, GiveYouAHead.Common, GiveYouAHead.Clean, GiveYouAHead.Build, GiveYouAHead.New.Template, GiveYouAHead.New.Note, GiveYouAHead.New.Import, GiveYouAHead.Build.FilesList, GiveYouAHead.Build.ExtraCompileOption, Data.GiveYouAHead + -- other-modules: + -- other-extensions: + build-depends: base >=4.8 && <=5.1, + old-time >1.0 && <=2 , + directory >=1.2, + process >=1.2, + extra >=1.0 + + hs-source-dirs: lib + default-language: Haskell2010 + ghc-options: -Wall -O2
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2015 Qinka + +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.
+ Setup.hs view
@@ -0,0 +1,3 @@+import Distribution.Simple + +main = defaultMain
+ lib/Data/GiveYouAHead.hs view
@@ -0,0 +1,68 @@+--Data , IO , and FP + +module Data.GiveYouAHead where + +--import System.IO +import GiveYouAHead.Common +--Switch + +data Switch = Off | On + deriving (Show , Read , Eq , Ord) + + + +turnSwitch :: Switch -> Switch +turnSwitch On = Off +turnSwitch Off = On + +--CommandMap + +type CommandMap = [(Switch,String,String)] --switch key value + +findKey :: CommandMap -> String -> String + +findKey [] key = key +findKey ((On,k,v):xs) key + | key == k = v + | otherwise = findKey xs key +findKey (_:xs) key = findKey xs key + + +delNewLine :: String -> String +delNewLine = concat.lines + +getCmdMap :: FilePath -> IO CommandMap + +getCmdMap fpath = do + src' <- readF fpath + let src = delNewLine src' + return (read src :: CommandMap) + +changeSwitchStatus :: CommandMap -- command map + -> String -- key + -> Int -- count or index + -> CommandMap + +changeSwitchStatus [] _ _ = [] +changeSwitchStatus ((s,k,v):xs) key c + | key == k && c == 0 = (turnSwitch s,k,v):xs + | key == k && c /= 0 = (s,k,v):changeSwitchStatus xs key (c-1) + | otherwise = (s,k,v):changeSwitchStatus xs key c + + + +--Settings +data Settings = Settings + { + dfShell ::String, + dfFileName :: String, + sysShell ::String + } deriving (Read,Show) + + +getSettings :: FilePath + -> IO Settings + +getSettings fPath = do + src <- readF fPath + return (read src :: Settings)
+ lib/GiveYouAHead.hs view
@@ -0,0 +1,49 @@+--IO +module GiveYouAHead where + +import GiveYouAHead.New +import GiveYouAHead.Build +import GiveYouAHead.Clean +--import GiveYouAHead.Common +import GiveYouAHead.Help +--import Data.GiveYouAHead + +gyahMain :: [String] + -> IO () + +gyahMain args = case length args of + 0 -> help + _ -> doGyah args + +doGyah :: [String] + -> IO () +doGyah (cmd:xs) = + case cmd of + "new" -> if length xs >= 2 then newMain xs else help + "build" -> if length xs >= 2 then buildMain xs else help + "clean" -> if null xs then clean else help + "help" -> help + _ -> help +doGyah _ = help + +gyah :: IO() +gyah = do + args <- getLine + gyahMain $ words args + + +help :: IO () +help = helpMain + +new :: IO () +new = do + args <- getLine + if length args >= 2 then newMain $ words args else help + +build :: IO () +build = do + args <- getLine + if length args >= 2 then buildMain $ words args else help + +clean :: IO() +clean = cleanMain
+ lib/GiveYouAHead/Build.hs view
@@ -0,0 +1,93 @@+--IO + +module GiveYouAHead.Build where + + +--outside +import System.Directory +import qualified System.Process as SP +import GHC.IO.Exception + + +--inside +import GiveYouAHead.Build.FilesList +import GiveYouAHead.Build.ExtraCompileOption +import GiveYouAHead.Common +--import GiveYouAHead.Settings +import Data.GiveYouAHead + + +makeMakeFileStep :: Bool -- is DEBUG + -> String -- file name + -> [String] +makeMakeFile :: Bool -- isDebug + -> [String] -- files list + -> [String] + +buildMain :: [String] --args + -> IO () + +returnExtras :: String -> String ->String -> [String] -> IO [String] +returnExtras _ _ _ [] = return [] +returnExtras nM oB oE (x:xs) = do + rt <- getOptionsFromFile nM oB oE x + z <- returnExtras nM oB oE xs + return (rt:z) + + +buildMain (lang:isDB:list) = do + gC <- getDirectoryContents "." + gDD <- getDataDir + setting <- getSettings $ gDD ++ "/settings.dat" + shCMap <- getCmdMap $ gDD ++ "/shell/"++dfShell setting ++ ".cmap" + lCMap <- getCmdMap $ gDD ++ "/language/"++lang++".cmap" + cpCMap <- getCmdMap $ gDD ++ "/compiler/" ++ findKey lCMap "*DefaultCompiler" ++".cmap" + let allMap' = cpCMap ++ lCMap ++ shCMap ++ [] + let list' theid = concatMap (findKey lCMap) ["*SrcAhead", dfFileName setting, theid, "*SrcBack"] + let files = case list of + [] -> getFilesList (findKey lCMap "*FE") gC + _ -> getFilesList (findKey lCMap "*FE") $ map list' list + extras <- returnExtras (findKey lCMap "*NoteMark") (findKey lCMap "*COB") (findKey lCMap "*COE") files + let allMap = allMap' ++ zip3 (repeat On) (map ("*extra"++) files) extras + print files + writeF + (concatMap (findKey allMap) [".makefile", "*ShellFileBack"]) + (concatMap (findKey allMap) (makeMakeFile (read isDB :: Bool) files)) + (_,_,_,hp) <- SP.createProcess $ + SP.shell $ + concatMap (findKey allMap) + ["*SysShellRun", " ", ".makefile", "*ShellFileBack"] + exCode <- SP.waitForProcess hp + let + checkEC ExitSuccess = do + putStrLn "Build Successfully." + checkEC (ExitFailure num) =do + putStrLn $ "Build failure.. the ExitCode is " ++ show num + in + checkEC exCode + return () + +buildMain _ = putStrLn "bad command!" + +makeMakeFileStep isDebug fName=[ + "*Compiler", + " ", + if isDebug then "*Debug" else " ", + " ", + "*Object", + " ", + getFileMainName fName, + "*ExecutableFE", + " ", + fName, + " ", + "*extra"++fName, + "\n"] + +makeMakeFile isDebug files =[ + "*MakefileBegin", + "\n"] ++ + concat makes ++ + ["*MakefileEnd"] + where + makes = map (makeMakeFileStep isDebug) files
+ lib/GiveYouAHead/Build/ExtraCompileOption.hs view
@@ -0,0 +1,60 @@+--IO & FP + +module GiveYouAHead.Build.ExtraCompileOption where + +import GiveYouAHead.Common + +--import System.IO.Extra +getOptions :: String --note mark + -> String --option begin + -> String --option end + -> [String] --fileText + -> String + + +getOptionsFromFile :: String --note mark + -> String --option begin + -> String --option end + -> FilePath --fileText + -> IO String + +delNoteMark :: String --note mark + -> String + -> String + +getOptBegin :: String + -> [String] + -> [String] + +getOptEnd :: String + -> [String] + -> [String] + + +getOptionsFromFile nM oB oE fn = do + fSrc <- readF fn + return $ getOptions nM oB oE $ lines fSrc + +getOptBegin oB inStr = rt + where + rt' = dropWhile (/=oB) inStr + (_:rt) = case length rt' of + 0 -> ["",""] + 1 -> ["",""] + _ -> rt' + + +getOptEnd oE inStr = rt + where + rt = takeWhile (/=oE) inStr + +getOptions nM oB oE inStr = delNoteMark nM $ concat items + where + makeItems = getOptEnd (nM ++ oE) . getOptBegin (nM ++ oB) + items = makeItems inStr + +delNoteMark [] str = str +delNoteMark _ [] = [] +delNoteMark (n:nM) (s:str) + | n == s = delNoteMark nM str + | otherwise = s:str
+ lib/GiveYouAHead/Build/FilesList.hs view
@@ -0,0 +1,13 @@+--FP+module GiveYouAHead.Build.FilesList where++getFilesList :: String --file extension+ -> [String] --dir files list+ -> [String] --files list++getFilesList _ [] = []+getFilesList fe (x:xs)+ | x'fe x == fe = x:getFilesList fe xs+ | otherwise = getFilesList fe xs+ where+ x'fe = reverse . takeWhile (/= '.') . reverse
+ lib/GiveYouAHead/Clean.hs view
@@ -0,0 +1,26 @@+--IO +module GiveYouAHead.Clean where + +--outside +import qualified System.Process as SP + +--inside +import GiveYouAHead.Common +import Data.GiveYouAHead + +cleanMain :: IO () +makeCleanCmd :: [String] + +makeCleanCmd = ["*Del"," ","*DelForce"," ","*DelQuite"," ","*delList"] + + +cleanMain = do + gDD <- getDataDir + setting <- getSettings $ gDD ++ "/settings.dat" + ssCMap <- getCmdMap $ gDD ++ "/shell/"++sysShell setting ++ ".cmap" + delListSrc <-readF $ gDD ++ "/delList.dat" + let allCMap = ssCMap ++ [(On,"*delList",concatMap (" "++) (read delListSrc ::[String]) ) ] + (_,_,_,hp) <- SP.createProcess $ SP.shell $ concatMap (findKey allCMap) makeCleanCmd + _ <- SP.waitForProcess hp + putStrLn "Cleaned!" + return ()
+ lib/GiveYouAHead/Common.hs view
@@ -0,0 +1,38 @@+--IO and FP + +module GiveYouAHead.Common where + + +--outside +--import System.IO +import System.Directory +import System.IO.Extra + +getDataDir :: IO FilePath +getDataDir = getAppUserDataDirectory "GiveYouAHead" + + +getFileMainName :: String -> String +getFileMainName = reverse . dropWhile (/= '.') . reverse + +getDefaultEncoding :: IO String + +getDefaultEncoding = do + gDD <- getDataDir + ec <- readFile $ gDD ++ "/defaultencoding" + return ec + +readF :: FilePath -> IO String +readF fpath = do + ec <- getDefaultEncoding + case ec of + "UTF8" -> readFileUTF8 fpath + _ -> readFile fpath +writeF fpath str = do + ec <- getDefaultEncoding + case ec of + "UTF8" -> writeFileUTF8 fpath str + _ ->writeFile fpath str + + +writeF :: FilePath -> String -> IO()
+ lib/GiveYouAHead/Help.hs view
@@ -0,0 +1,43 @@+--IO +module GiveYouAHead.Help where + +--outside +import System.Environment + +--insdie +import GiveYouAHead.Version + + +helpMain ::IO() + +helpMain = do + progName <- getProgName + putStrLn $ unlines [ + "\n", + "\n\tGiveYouAHead\t\t\t version " ++ gyahver, + "\tCommand :", + "\tCreate a new file ", + "\t\t"++progName++" new [language] [id] [the list of import]", + "\tBuild the program(s) ", + "\t\t"++progName++" build [language] [isDebug]", + "\t\t"++progName++" build [language] [isDebug] [the list of id] ", + "\tClean the directory's useless files", + "\t\t"++progName++" clean", + "", + "\tGiveYouAHead\t\t\t版本 " ++ gyahver, + "\t使用帮助", + "\t命令:", + "\t创建新文件", + "\t\t"++progName++" new 【语言】【id】【引用列表】", + "\t构建", + "\t\t"++progName++" build 【语言】【是否调试】", + "\t\t"++progName++" build 【语言】【是否调试】【文件id列表】", + "\t清理", + "\t\t"++progName++" clean", + "", + "\tHomepage https://github.com/Qinka/GiveYouAHead/", + "\tBug report: https://github.com/Qinka/GiveYouAHead/issues", + "\t主页 https://github.com/Qinka/GiveYouAHead/", + "\tBUG报告 https://github.com/Qinka/GiveYouAHead/issues", + "" + ]
+ lib/GiveYouAHead/New.hs view
@@ -0,0 +1,46 @@+--IO + +module GiveYouAHead.New where + +--import GiveYouAHead.Settings +import GiveYouAHead.New.Import +import GiveYouAHead.New.Note +import GiveYouAHead.New.Template +import GiveYouAHead.Common + +import Data.GiveYouAHead + +--import System.Environment +import System.Time + + + + + +newMain :: [String] --args + -> IO () +newMain (lang:idNum:iL) = do + gDD <- getDataDir + sts <- getSettings $ gDD ++ "/settings.dat" + time <- getClockTime + langCMap <- getCmdMap $ gDD ++ "/language/"++lang++".cmap" + persionCMap <- getCmdMap $ gDD ++ "/person.cmap" + let allCMap = langCMap ++ persionCMap ++ [ + (On,"*noteMarkLine", concat $ replicate 30 $ findKey langCMap "*NoteMark" ), + (On,"*timeLine","\tCreated tIme :\t"++show time), + (On,"*probId",idNum)] + let fname = concatMap (findKey allCMap) ["*SrcAhead",dfFileName sts,idNum,"*SrcBack"] + writeF fname $ concat $ getSrc allCMap iL + putStrLn $ fname ++ " created" + return () +newMain _ = error "bad command!" +getSrc :: CommandMap -> [String] -> [String] +getSrc nMap iL = + (map f $ h noteText) ++ importText iL ++ templateText + where + f = (++"\n") . g + g = addNoteMark $ findKey nMap "*NoteMark" + h = lines.concat + noteText = map (findKey nMap) makeNotes + importText = map (findKey nMap) . concat .map addImport + templateText = map (findKey nMap) templateList
+ lib/GiveYouAHead/New/Import.hs view
@@ -0,0 +1,6 @@+--FP + +module GiveYouAHead.New.Import where +addImport :: String + -> [String] +addImport = ("*ImportAhead":) . (:["*ImportBack"])
+ lib/GiveYouAHead/New/Note.hs view
@@ -0,0 +1,37 @@+--FP +module GiveYouAHead.New.Note where + +import GiveYouAHead.Version + + +addNoteMark :: String --mk + -> String --lines + -> String + +makeNotes :: [String] + +addNoteMark = (++) + +makeNotes = [ + "*noteMarkLine","\n", + "*EOB","\n", + "\n", + "*EOE","\n", + "*noteMarkLine","\n", + "\n", + "*TitleLine","\n", + "*WriterLine","\n", + "*timeLine","\n", + "\tProblem\t","*probId","\n", + "\n", + "\tlicense type: ","*License","\n", + "\tlicense file: \n", + "\n", + "\tThis file is auto--created by GiveYouAHead.\n", + "\tGiveYouAHead is written by Qinka (qinka@live.com) in Haskell.\n", + "\tVersion "++ gyahver ++"\n", + "\n", + "\tHomepage: https://github.com/Qinka/GiveYouAHead\n", + "\tBug report: https://github.com/Qinka/GiveYouAHead/issues\n", + "\n", + "*noteMarkLine","\n"]
+ lib/GiveYouAHead/New/Template.hs view
@@ -0,0 +1,6 @@+--FP++module GiveYouAHead.New.Template where++templateList :: [String]+templateList = ["*Template"]
+ lib/GiveYouAHead/Settings.hs view
@@ -0,0 +1,98 @@+--IO + +module GiveYouAHead.Settings where + +--outside +import Control.Monad +import System.IO + +--inside +import GiveYouAHead.Common +import Data.GiveYouAHead +import Data.List + + + +getSetting :: IO Settings +getSetting = do + gDD <- getDataDir + stSrc <- readF (gDD++"/setting.dat") + return (read stSrc ::Settings) + +settings :: IO () +settings = do + putStrLn "GiveYouAHead settings shell" + forever $ do + putStr " Settings > " + cmd <- getLine + let (c:cmds) = words cmd + case c of + "base" -> baseSetting cmds + "cmdmapswitch" -> cmdSwitchSetting cmds + _ -> nullSetting cmds + +baseSetting :: [String] -> IO () +cmdSwitchSetting :: [String] -> IO () +nullSetting :: [String] -> IO () + +nullSetting _ = do + putStrLn "input error" -- + return () + +baseSetting (sh:fn:ss:_) = do + gDD <- getDataDir + hD <- openFile (gDD ++ "/setting.dat") ReadMode + stSrc <- hGetLine hD + let st = read stSrc :: Settings + hClose hD + let + sh' = if sh == "_" then dfShell st else sh + fn' = if fn == "_" then dfFileName st else fn + ss' = if ss == "-" then sysShell st else ss + in + writeF (gDD ++ "/setting.dat") (show (Settings sh' fn' ss')) + return () +baseSetting _ = putStrLn "bad command!" + +cmdSwitchSetting (fileName:key:count':_) = do + gDD <- getDataDir + iCMap <- getCmdMap (gDD ++ fileName) + let count = read count' :: Int + writeF (gDD ++ fileName) (show $ changeSwitchStatus iCMap key count) + return () + +cmdSwitchSetting _ = putStrLn "bad command!" +writeData :: FilePath -- %UAD%/GiveYouAHead/ + -> String -- the things you want to write + -> IO () +writeDataFrom :: Show a + => FilePath -- based on %UAD%/GiveYouAHead + -> a -- the one which can show + -> IO () +writeDataFrom fpath datas = do + writeData fpath $ show datas + return () + +writeData fpath' src = do + gDD <- getDataDir + let fpath = gDD ++ "/" ++ fpath' + writeF fpath src + return () + +dropRepeated :: (Eq a)=> [a] -> [a] +dropRepeated [] = [] +dropRepeated (x:[]) = [x] +dropRepeated (x:y:xs) + | x == y = dropRepeated (x:xs) + | otherwise = x:dropRepeated (y:xs) + + +dropDelListRepeatedAndAdd :: [String] -> IO () +dropDelListRepeatedAndAdd xs = do + dir <- getDataDir + hD <- openFile (dir++"/delList.dat") ReadMode + stSrc <- hGetLine hD + hClose hD + putStrLn stSrc + writeF (dir ++ "/delList.dat") $ show $ dropRepeated $ sort $ (++) xs (read stSrc ::[String]) + return ()
+ lib/GiveYouAHead/Version.hs view
@@ -0,0 +1,11 @@+--FP Data and IO + + +module GiveYouAHead.Version where + +import Data.Version + +gyah'ver :: Version +gyah'ver = Version { versionBranch = [0,2,2,0] , versionTags=[]} +gyahver :: String +gyahver = showVersion gyah'ver