New patches: [#2053: add additional history functions alexander.dunlap@gmail.com**20080122050536 The following functions were added: readHistory, writeHistory, appendHistory, historyTruncateFile, clearHistory, stifleHistory, unstifleHistory, historyIsStifled, historyMaxEntries ] { hunk ./System/Console/Readline.hsc 43 + + -------------------------------------------------------------------- + -- History Functionality. + hunk ./System/Console/Readline.hsc 48 + readHistory, -- :: String -> IO () + writeHistory, -- :: String -> IO () + appendHistory, -- :: String -> IO () + historyTruncateFile, -- :: String -> IO () + clearHistory, -- :: IO () + stifleHistory, -- :: Int -> IO () + unstifleHistory, -- :: IO Int + historyIsStifled, -- :: IO Bool + historyMaxEntries, -- IO Int hunk ./System/Console/Readline.hsc 341 +-------------------------------------------------------------------------- +-- History functionality hunk ./System/Console/Readline.hsc 351 +-- |Read in a history file, throwing an error on failure. +readHistory :: FilePath -- ^ The file to read (if null, read ~/.history) + -> IO () +readHistory fp = do + ok <- withCString fp read_history + unless (ok == 0) $ fail "Can't read history file" +foreign import ccall unsafe read_history :: Ptr CChar -> IO CInt + +-- |Write out a history file, throwing an error on failure. +writeHistory :: FilePath -- ^ The file to write (if null, write ~/.history + -> IO () +writeHistory fp = do + ok <- withCString fp write_history + unless (ok == 0) $ fail "Can't write history file" +foreign import ccall unsafe write_history :: Ptr CChar -> IO CInt + +-- |Append the last @n@ history entries to a file, throwing an error on failure. +appendHistory :: Int -- ^ The number of history entries to append + -> FilePath -- ^ The file to append to + -> IO () +appendHistory n fp = do + ok <- withCString fp (append_history n) + unless (ok == 0) $ fail "Can't write history file" +foreign import ccall unsafe append_history :: Int -> Ptr CChar -> IO CInt + +-- |Truncate a history file, leaving only @n@ entries. Throw an error on +-- failure. +historyTruncateFile :: FilePath -- ^ The file to truncate + -> Int -- ^ The number of entries to leave + -> IO () +historyTruncateFile fp n = do + ok <- withCString fp (flip history_truncate_file $ n) + unless (ok == 0) $ fail "Can't write history file" +foreign import ccall unsafe history_truncate_file :: Ptr CChar -> Int -> IO CInt + +-- |Clear the history. +clearHistory :: IO () +clearHistory = clear_history +foreign import ccall unsafe clear_history :: IO () + +-- |Stifle the history list, remembering only a certain number of entries. +stifleHistory :: Int -> IO () +stifleHistory n = stifle_history n +foreign import ccall unsafe stifle_history :: Int -> IO () + +-- |Stop stifling the history, returning the previous amount the history was +-- stifled by. The value is positive if the history was stifled or negative +-- if it was not. +unstifleHistory :: IO Int +unstifleHistory = unstifle_history +foreign import ccall unsafe unstifle_history :: IO Int + +-- |Check whether the history is stifled or not. True if stifled, False if not. +historyIsStifled :: IO Bool +historyIsStifled = do + isStifledInt <- history_is_stifled + let isStifled = case isStifledInt of + 0 -> False + 1 -> True + _ -> error "historyIsStifled: history_is_stifled returned unexpected value (expected 0 or 1, received other)" -- just for completeness - there is no conceivable way readline would not return either 0 or 1 here + return isStifled +foreign import ccall unsafe history_is_stifled :: IO Int + +-- |Get the maximum number of history entries, returning 0 if the history is +-- unstifled. +historyMaxEntries :: IO Int +historyMaxEntries = liftM fromIntegral (peek history_max_entries) +foreign import ccall "&" history_max_entries :: Ptr CInt + + } [#2053: Make readHistory/writeHistory return a Bool instead of throwing an exception on failure. judah.jacobson@gmail.com**20080226233929] { hunk ./System/Console/Readline.hsc 48 - readHistory, -- :: String -> IO () - writeHistory, -- :: String -> IO () + readHistory, -- :: String -> IO Bool + writeHistory, -- :: String -> IO Bool hunk ./System/Console/Readline.hsc 351 --- |Read in a history file, throwing an error on failure. +-- |Read in a history file. Returns 'False' on failure +-- (for example, if the file does not exist). hunk ./System/Console/Readline.hsc 354 - -> IO () + -> IO Bool hunk ./System/Console/Readline.hsc 357 - unless (ok == 0) $ fail "Can't read history file" + return (ok==0) hunk ./System/Console/Readline.hsc 360 --- |Write out a history file, throwing an error on failure. -writeHistory :: FilePath -- ^ The file to write (if null, write ~/.history - -> IO () +-- |Write out a history file. Returns 'False' if there was a problem writing the file. +writeHistory :: FilePath -- ^ The file to write (if null, write ~/.history) + -> IO Bool hunk ./System/Console/Readline.hsc 365 - unless (ok == 0) $ fail "Can't write history file" + return (ok==0) } Context: [markup for URL Ross Paterson **20071107005425] [remove obsolete config.mk.in Ross Paterson **20071107005850 This was used when building in the GHC tree using the old fptools build system, to pass parameters from configure to the Makefile. With the new Cabal-based build system, they go via readline.buildinfo. ] [FIX: fix name of include file in sdist Ross Paterson **20071103163724] [Fix test for whether readline is really editline to work for MacOS 10.5 Manuel M T Chakravarty **20071031105453] [Use configurations to allow building with older ghc & base lib Duncan Coutts **20071018111417 Also specify build-type and cabal-version ] [bump the version number Ian Lynagh **20071014105053] [Add interface for rl_completion_word_break_hook (version 5.0 or higher). judah.jacobson@gmail.com**20070211231618] [Add get/set functions for the rl_attempted_completion_over variable. judah.jacobson@gmail.com**20070211230806] [Add HsReadlineConfig.h to install-includes Ian Lynagh **20070925214115 Patch from Audrey Tang ] [clean config.mk Simon Marlow **20070914140737] [Add more entries to boring file Ian Lynagh **20070913210720] [Add a boring file Ian Lynagh **20070913204656] [TAG ghc-6.8 branched 2007-09-03 Ian Lynagh **20070903155838] [Link against GNUreadline.framework, if it's available. judah.jacobson@gmail.com**20070906052628 This can be overridden by setting --with-readline-includes or --with-readline-libraries. ] [Remove redundant include/Makefile Ian Lynagh **20070828205711] [Call the license LICENSE rather than COPYING for consistency Ian Lynagh **20070828130747] [added a bit of documentation to the readline library ijones@syntaxpolice.org**20070819083106] [--configure-option and --ghc-option are now provided by Cabal Ross Paterson **20070604115727] [Remove Makefile and package.conf.in (used in the old build system) Ian Lynagh **20070524142629] [Remove unnecessary "import Prelude hiding (catch)" Ian Lynagh **20070523222119] [We now depend on process Ian Lynagh **20070523181523] [add install-includes: field Simon Marlow **20070517095014] [Make the Cabal build system honour configure flags Roman Leshchinskiy **20070504042130 The Cabal build system was ignoring --with-readline-includes and --with-readline-libraries. ] [Make configure fail if the package is not buildable Ian Lynagh **20070430190918] [Follow Cabal changes in Setup.hs Ian Lynagh **20070418114443] [readline no longer needs to hide build failure Ian Lynagh **20070415215805 The GHC build system now copes with it itself. ] [Fix configure with no --with-cc Ian Lynagh **20070415194819] [Fix -Wall warnings Ian Lynagh **20070411005013] [Add missing case in removePrefix Ian Lynagh **20070411002555] [Pass configure opts down to ./configure, and add a nasty hack not to fail Ian Lynagh **20070406182410 If readline doesn't build then we still want to build the rest of GHC. For now readline simply ignores any failure when asked to build, but we really need to do something better here! ] [parse (but don't pass on) options for ./configure Ian Lynagh **20070406153705] [Make syntax in .cabal file haddock-friendly Ian Lynagh **20070308163504] [make Setup suitable for building the libraries with GHC Ian Lynagh **20061112214707] [Match the types in the C source, not the documentation Ian Lynagh **20070404122733] [Fix C/Haskell type mismatch Ian Lynagh **20070404003613] [Give ld -Llibdir, not -Ilibdir Ian Lynagh **20070305143239] [copy/paste-o Ian Lynagh **20070305141749] [README about building from darcs Ross Paterson **20070218110201] [TAG 6.6 release Ian Lynagh **20061011124740] [add boilerplate Setup.hs Ross Paterson **20060928231526] [Typo (this is the readline, not unix, package) Ian Lynagh **20060823144042] [remove unnecessary #include "ghcconfig.h" Ross Paterson **20060809132127] [Make the configure test robust against libedit Simon Marlow **20060706120654 See #766 Thanks to Greg Wright for the fix. ] [make a start on Cabalizing readline Ross Paterson **20060609161024] [Move readline configuration into the readline package Simon Marlow **20060609135511 Configuration of the readline package is now done with a package-private configure script, which takes it a step closer to being a standalone Cabal package. At the same time I added --with-readline-includes and --with-readline-libraries options to cater for systems where these libraries live in non-std places. ] [TAG Initial conversion from CVS complete John Goerzen **20060112154138] Patch bundle hash: 36cd1448f8a2d9f64bf943d4644dcbfe037116c6