File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+
3
+ import std/ os
4
+ import std/ strutils
5
+
6
+ using name: string
7
+ func toAllUpper(name): string {.inline.} =
8
+ for c in name:
9
+ case c
10
+ of 'a' .. 'z' : result .add chr(ord(c) or 0b 100000 )
11
+ else : discard # '_' is discarded, so for other chars
12
+ func toPyEnv* (name): string {.inline.} = " PYTHON" & name.toAllUpper
13
+ proc ib_i* [T](name; flagInit: T): T =
14
+ let v = getEnv(name)
15
+ if v.len == 0: return
16
+ max(flagInit, T(
17
+ try:
18
+ let val = parseInt(v)
19
+ if val < 0: 1 # PYTHONDEBUG=text and PYTHONDEBUG=-2 behave as PYTHONDEBUG=1
20
+ else: val
21
+ except ValueError: 1
22
+ ))
23
+ proc ib_e*[T](name; flagInit: T): T = flagInit or T existsEnv name
24
+ proc ib_b*(name; flagInit: int ): int = min 1, ib_i(name, flagInit)
25
+ proc ib_b*(name; flagInit: bool ): bool = ib_i(name, flagInit)
You can’t perform that action at this time.
0 commit comments