summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-04-03 23:12:03 +0200
committerAraq <rumpf_a@web.de>2011-04-03 23:12:03 +0200
commitb3e24382a025bfe2ca0f65cc46c8b9e5e652a26d (patch)
treef17f2fba88bdcf08d09ca0b25cd649e5c7921e54
parentb38c7adad1e153c8678c93098391cb2bd8d8fef6 (diff)
downloadNim-b3e24382a025bfe2ca0f65cc46c8b9e5e652a26d.tar.gz
added another system.open; bugfix: koch clean may not break .git dirs anymore
-rwxr-xr-xkoch.nim2
-rwxr-xr-xlib/system.nim18
-rwxr-xr-xtodo.txt1
-rwxr-xr-xweb/news.txt3
4 files changed, 15 insertions, 9 deletions
diff --git a/koch.nim b/koch.nim
index 4eddb06e4..0f9b42bec 100755
--- a/koch.nim
+++ b/koch.nim
@@ -180,7 +180,7 @@ proc cleanAux(dir: string) =
       of "nimcache": 
         echo "removing dir: ", path
         removeDir(path)
-      of "dist", ".bzr":
+      of "dist", ".git":
         nil
       else:
         cleanAux(path)
diff --git a/lib/system.nim b/lib/system.nim
index 3c31e65cd..c786e8355 100755
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -1477,15 +1477,22 @@ when not defined(EcmaScript) and not defined(NimrodVM):
     ## Opens a file named `filename` with given `mode`.
     ##
     ## Default mode is readonly. Returns true iff the file could be opened.
-    ## This throws no exception if the file could not be opened. The reason is
-    ## that the programmer needs to provide an appropriate error message 
-    ## anyway.
+    ## This throws no exception if the file could not be opened.
 
   proc Open*(f: var TFile, filehandle: TFileHandle,
              mode: TFileMode = fmRead): Bool
     ## Creates a ``TFile`` from a `filehandle` with given `mode`.
     ##
     ## Default mode is readonly. Returns true iff the file could be opened.
+    
+  proc Open*(filename: string,
+             mode: TFileMode = fmRead, bufSize: int = -1): TFile = 
+    ## Opens a file named `filename` with given `mode`.
+    ##
+    ## Default mode is readonly. Raises an ``IO`` exception if the file
+    ## could not be opened.
+    if not open(result, filename, mode, bufSize):
+      raise newException(EIO, "cannot open: " & filename)
 
   proc reopen*(f: TFile, filename: string, mode: TFileMode = fmRead): bool
     ## reopens the file `f` with given `filename` and `mode`. This 
@@ -1582,10 +1589,7 @@ when not defined(EcmaScript) and not defined(NimrodVM):
   iterator lines*(filename: string): string =
     ## Iterate over any line in the file named `filename`.
     ## If the file does not exist `EIO` is raised.
-    var
-      f: TFile
-    if not open(f, filename):
-      raise newException(EIO, "cannot open: " & filename)
+    var f = open(filename)
     var res = ""
     while not endOfFile(f):
       rawReadLine(f, res)
diff --git a/todo.txt b/todo.txt
index 09a9117dd..5d09ed710 100755
--- a/todo.txt
+++ b/todo.txt
@@ -1,3 +1,4 @@
+- clean up the tests!
 - thread support: threadvar on Windows seems broken; 
   add --deadlock_prevention:on|off switch
 - built-in serialization
diff --git a/web/news.txt b/web/news.txt
index 9b1979056..c28eef94e 100755
--- a/web/news.txt
+++ b/web/news.txt
@@ -67,7 +67,8 @@ Additions
 - The *interactive mode* (REPL) has been improved and documented for the 
   first time.
 - Added the ``linearScanEnd``, ``unroll``, ``shallow`` pragmas.
-- Added ``system.reset``.
+- Added ``system.reset`` and a version of ``system.open`` that 
+  returns a ``TFile`` and raises an exception in case of an error.
 - The compiler now might use a hashing for string case statements depending
   on the number of string literals in the case statement.