diff options
author | Yuriy Glukhov <yglukhov@users.noreply.github.com> | 2017-01-18 21:17:53 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-01-18 20:17:53 +0100 |
commit | fe0291f12708edd0c85ac53b3bd84a3411b8dfae (patch) | |
tree | 3d39b9274f3b6ab56adf5ac487cb3307e0c4ed4c /lib | |
parent | 05dec08cead56a08a8bf2f25fb695340cd321070 (diff) | |
download | Nim-fe0291f12708edd0c85ac53b3bd84a3411b8dfae.tar.gz |
Import ospaths instead of include (#5233)
* Import ospaths instead of include * searchExtPos made public
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/os.nim | 7 | ||||
-rw-r--r-- | lib/pure/ospaths.nim | 19 |
2 files changed, 14 insertions, 12 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 8a5461567..4cd3870c7 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -26,7 +26,8 @@ elif defined(posix): else: {.error: "OS module not ported to your operating system!".} -include ospaths +import ospaths +export ospaths when defined(posix): when NoFakeVars: @@ -848,12 +849,12 @@ template walkCommon(pattern: string, filter) = res = findFirstFile(pattern, f) if res != -1: defer: findClose(res) + let dotPos = searchExtPos(pattern) while true: if not skipFindData(f) and filter(f): # Windows bug/gotcha: 't*.nim' matches 'tfoo.nims' -.- so we check # that the file extensions have the same length ... let ff = getFilename(f) - let dotPos = searchExtPos(pattern) let idx = ff.len - pattern.len + dotPos if dotPos < 0 or idx >= ff.len or ff[idx] == '.' or pattern[dotPos+1] == '*': @@ -1109,7 +1110,7 @@ proc createDir*(dir: string) {.rtl, extern: "nos$1", ## fail if the directory already exists because for most usages this does not ## indicate an error. var omitNext = false - when doslike: + when doslikeFileSystem: omitNext = isAbsolute(dir) for i in 1.. dir.len-1: if dir[i] in {DirSep, AltSep}: diff --git a/lib/pure/ospaths.nim b/lib/pure/ospaths.nim index 9f8d9aab3..87ece2582 100644 --- a/lib/pure/ospaths.nim +++ b/lib/pure/ospaths.nim @@ -40,8 +40,7 @@ when not declared(getEnv) or defined(nimscript): TOSErrorCode: OSErrorCode ].} const - doslike = defined(windows) or defined(OS2) or defined(DOS) - # DOS-like filesystem + doslikeFileSystem* = defined(windows) or defined(OS2) or defined(DOS) when defined(Nimdoc): # only for proper documentation: const @@ -120,7 +119,7 @@ when not declared(getEnv) or defined(nimscript): # waterproof. In case of equal names the first volume found will do. # Two colons "::" are the relative path to the parent. Three is to the # grandparent etc. - elif doslike: + elif doslikeFileSystem: const CurDir* = '.' ParDir* = ".." @@ -331,14 +330,16 @@ when not declared(getEnv) or defined(nimscript): if ext == "" or ext[0] == ExtSep: result = ext # no copy needed here else: result = ExtSep & ext - proc searchExtPos(s: string): int = + proc searchExtPos*(path: string): int = + ## Returns index of the '.' char in `path` if it signifies the beginning + ## of extension. Returns -1 otherwise. # BUGFIX: do not search until 0! .DS_Store is no file extension! result = -1 - for i in countdown(len(s)-1, 1): - if s[i] == ExtSep: + for i in countdown(len(path)-1, 1): + if path[i] == ExtSep: result = i break - elif s[i] in {DirSep, AltSep}: + elif path[i] in {DirSep, AltSep}: break # do not skip over path proc splitFile*(path: string): tuple[dir, name, ext: string] {. @@ -432,7 +433,7 @@ when not declared(getEnv) or defined(nimscript): ## Checks whether a given `path` is absolute. ## ## On Windows, network paths are considered absolute too. - when doslike: + when doslikeFileSystem: var len = len(path) result = (len > 0 and path[0] in {'/', '\\'}) or (len > 1 and path[0] in {'a'..'z', 'A'..'Z'} and path[1] == ':') @@ -461,7 +462,7 @@ when not declared(getEnv) or defined(nimscript): var start: int if path[0] == '/': # an absolute path - when doslike: + when doslikeFileSystem: if drive != "": result = drive & ":" & DirSep else: |