Changeset 15324

Show
Ignore:
Timestamp:
02/22/07 09:47:16 (21 months ago)
Author:
audreyt
Message:

* Support for the full test of file test operators: oRWXOlpSbctugkTB

(the rest were already supported.) For example:

"README" :T # True

Thanks to jisom++ for prompting it.

Location:
src/Pugs/Prim
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Prim/FileTest.hs

    r14635 r15324  
    55    fileSize, sizeIsZero, 
    66    fileMTime, fileCTime, fileATime, 
     7    fileTestViaPerl5 
    78) where 
    89import Pugs.Internals 
     10import Pugs.Embed 
     11import Pugs.Types 
    912import Pugs.AST hiding (isWritable) 
    1013 
     
    4245fileATime    :: Val -> Eval Val 
    4346fileATime    = fileTime statFileATime 
     47 
     48fileTestViaPerl5 :: String -> Val -> Eval Val 
     49fileTestViaPerl5 testOp v = do 
     50    env     <- ask 
     51    envSV   <- liftIO $ mkEnv env 
     52    argSV   <- fromVal v 
     53    subSV   <- liftIO $ evalPerl5 ("sub { warn $_[0]; -" ++ testOp ++ " $_[0] }") envSV (enumCxt cxtItemAny) 
     54    rv      <- runInvokePerl5 subSV nullSV [argSV] 
     55    return $ case rv of 
     56        VStr "" -> VBool False 
     57        VNum 1  -> VBool True 
     58        VInt 1  -> VBool True 
     59        _       -> rv 
    4460 
    4561fileTime :: (FilePath -> IO Integer) -> Val -> Eval Val 
  • src/Pugs/Prim/Match.hs

    r15297 r15324  
    141141        "f" -> FileTest.isFile 
    142142        "d" -> FileTest.isDirectory 
     143        [op] | op `elem` "oRWXOlpSbctugkTB" -> FileTest.fileTestViaPerl5 testOp 
    143144        _   -> const $ die "Unknown file test operator" testOp 
    144145    if isTrue