Changeset 1159 for lang/haskell

Show
Ignore:
Timestamp:
11/06/07 00:51:28 (6 years ago)
Author:
jknaoya
Message:

lang/haskell/blosxkel/config.sample,
lang/haskell/blosxkel/blosxkel.hs:

config をよむようにしました

Location:
lang/haskell/blosxkel
Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • lang/haskell/blosxkel

    • Property svn:ignore
      •  

        old new  
        33blosxkel.o 
        44blosxkel.cgi 
         5config 
  • lang/haskell/blosxkel/blosxkel.hs

    r1158 r1159  
    3131        expand var = fromMaybe ('$':var) (lookup var params) 
    3232 
     33loadConfig :: String -> IO [(String, String)] 
     34loadConfig config = do 
     35    { 
     36    ; c <- readFile config 
     37    ; return $ concatMap parseLine $ lines c 
     38    } where 
     39        parseLine :: String -> [(String, String)] 
     40        parseLine l 
     41                  | all isSpace l = [] 
     42                  | otherwise = let (k, (':':v)) = (break (== ':') l) 
     43                                in [(strip k, strip v)] 
     44        strip     = rstrip . lstrip 
     45        rstrip    = reverse . lstrip . reverse 
     46        lstrip    = dropWhile isSpace 
     47 
     48getConfig :: [(String, String)] -> String -> String 
     49getConfig config key = fromJust $ lookup key config 
    3350 
    3451data Entry = Entry { 
     
    7895 
    7996 
    80 getResult :: [(String, String)] -> IO (String, String) 
    81 getResult cgiparams = do 
     97getResult :: [(String, String)] -> [(String, String)] -> IO (String, String) 
     98getResult cgiparams config = do 
    8299    { 
    83     ; entries <- getTextFileEntries "data" 
     100    ; entries <- getTextFileEntries $ getConfig config "data-dir" 
    84101    ; ct <- fill "content_type" [] 
    85102    ; ch <- fill "head" [] 
     
    94111    ; return $ (ct, concat $ [ch, concat cs, cf]) 
    95112    } where 
    96         fill place params = fillFlavour "html" place (params ++ [("title", "Blosxkel.hs"), 
     113        fill place params = fillFlavour "html" place (params ++ [("title", getConfig config "title"), 
     114                                                                 ("author", getConfig config "author"), 
    97115                                                                 ("version", "aaa")] ++ cgiparams) 
    98116 
     
    100118cgiMain =  do 
    101119    { 
     120    ; config  <- liftIO $ loadConfig "config" 
    102121    ; home <- scriptName 
    103122    ; pathinfo <- pathInfo 
    104     ; result <- liftIO $ getResult [("home", home), ("pathinfo", pathinfo)] 
    105     ; setHeader "Content-Type" $ fst result 
    106     ; output $ snd result 
     123    ; (ct, cb)  <- liftIO $ getResult [("home", home), ("pathinfo", pathinfo)] config 
     124    ; setHeader "Content-Type" $ ct 
     125    ; output $ cb 
    107126    } 
    108127