summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-11-07 23:25:34 +0100
committerAraq <rumpf_a@web.de>2011-11-07 23:25:34 +0100
commit0b4d5e45b9a6a78f1d661d119cd76f41fecaefea (patch)
tree5848807ddc889a5eea463108db8d1d7dd15955f5 /lib/pure
parent0ce9d4960144468c12de493487ada62e8eb04f5d (diff)
downloadNim-0b4d5e45b9a6a78f1d661d119cd76f41fecaefea.tar.gz
tester checks exitcode; osproc additions; DLL fixes; taint mode fixes
Diffstat (limited to 'lib/pure')
-rwxr-xr-xlib/pure/browsers.nim2
-rwxr-xr-xlib/pure/os.nim9
-rwxr-xr-xlib/pure/osproc.nim51
-rwxr-xr-xlib/pure/pegs.nim2
4 files changed, 50 insertions, 14 deletions
diff --git a/lib/pure/browsers.nim b/lib/pure/browsers.nim
index 243c07dad..529071107 100755
--- a/lib/pure/browsers.nim
+++ b/lib/pure/browsers.nim
@@ -34,7 +34,7 @@ proc openDefaultBrowser*(url: string) =
     var u = quoteIfContainsWhite(url)
     for a in items(attempts):
       if execShellCmd(a & u) == 0: return
-    for b in getEnv("BROWSER").split(PathSep):
+    for b in getEnv("BROWSER").string.split(PathSep):
       try:
         # we use ``startProcess`` here because we don't want to block!
         discard startProcess(command=b, args=[url], options={poUseShell})
diff --git a/lib/pure/os.nim b/lib/pure/os.nim
index 122b38c57..2edf999d3 100755
--- a/lib/pure/os.nim
+++ b/lib/pure/os.nim
@@ -74,6 +74,10 @@ when defined(Nimdoc): # only for proper documentation:
       ## The file extension of a script file. For example: "" for POSIX,
       ## "bat" on Windows.
 
+    DynlibFormat* = "lib$1.so"
+      ## The format string to turn a filename into a `DLL`:idx: file (also
+      ## called `shared object`:idx: on some operating systems).
+
 elif defined(macos):
   const
     curdir* = ':'
@@ -84,6 +88,7 @@ elif defined(macos):
     FileSystemCaseSensitive* = false
     ExeExt* = ""
     ScriptExt* = ""
+    DynlibFormat* = "$1.dylib"
 
   #  MacOS paths
   #  ===========
@@ -113,6 +118,7 @@ elif doslike:
     FileSystemCaseSensitive* = false
     ExeExt* = "exe"
     ScriptExt* = "bat"
+    DynlibFormat* = "$1.dll"
 elif defined(PalmOS) or defined(MorphOS):
   const
     dirsep* = '/'
@@ -122,6 +128,7 @@ elif defined(PalmOS) or defined(MorphOS):
     FileSystemCaseSensitive* = false
     ExeExt* = ""
     ScriptExt* = ""
+    DynlibFormat* = "$1.prc"
 elif defined(RISCOS):
   const
     dirsep* = '.'
@@ -131,6 +138,7 @@ elif defined(RISCOS):
     FileSystemCaseSensitive* = true
     ExeExt* = ""
     ScriptExt* = ""
+    DynlibFormat* = "lib$1.so"
 else: # UNIX-like operating system
   const
     curdir* = '.'
@@ -141,6 +149,7 @@ else: # UNIX-like operating system
     FileSystemCaseSensitive* = true
     ExeExt* = ""
     ScriptExt* = ""
+    DynlibFormat* = "lib$1.so"
 
 const
   ExtSep* = '.'
diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim
index 1b7d41908..dbf7b0e48 100755
--- a/lib/pure/osproc.nim
+++ b/lib/pure/osproc.nim
@@ -48,7 +48,8 @@ proc execProcess*(command: string,
 
 proc execCmd*(command: string): int {.rtl, extern: "nosp$1".}
   ## Executes ``command`` and returns its error code. Standard input, output,
-  ## error streams are inherited from the calling process.
+  ## error streams are inherited from the calling process. This operation
+  ## is also often called `system`:idx:.
 
 proc startProcess*(command: string,
                    workingDir: string = "",
@@ -70,6 +71,17 @@ proc startProcess*(command: string,
   ## Return value: The newly created process object. Nil is never returned,
   ## but ``EOS`` is raised in case of an error.
 
+proc startCmd*(command: string, options: set[TProcessOption] = {
+               poStdErrToStdOut, poUseShell}): PProcess =
+  ## a simpler version of `startProcess` that parses the command line into
+  ## program and arguments and then calls `startProcess` with the empty string
+  ## for `workingDir` and the nil string table for `env`.
+  var c = parseCmdLine(command)
+  var a: seq[string]
+  newSeq(a, c.len-1) # avoid slicing for now (still unstable)
+  for i in 1 .. c.len-1: a[i-1] = c[i]
+  result = startProcess(command=c[0], args=a, options=options)
+
 proc close*(p: PProcess) {.rtl, extern: "nosp$1".}
   ## When the process has finished executing, cleanup related handles
 
@@ -140,12 +152,6 @@ proc countProcessors*(): int {.rtl, extern: "nosp$1".} =
     result = sysconf(SC_NPROCESSORS_ONLN)
   if result <= 0: result = 1
 
-proc startProcessAux(cmd: string, options: set[TProcessOption]): PProcess =
-  var c = parseCmdLine(cmd)
-  var a: seq[string] = @[] # slicing is not yet implemented :-(
-  for i in 1 .. c.len-1: add(a, c[i])
-  result = startProcess(command=c[0], args=a, options=options)
-
 proc execProcesses*(cmds: openArray[string],
                     options = {poStdErrToStdOut, poParentStreams},
                     n = countProcessors()): int {.rtl, extern: "nosp$1".} =
@@ -158,7 +164,7 @@ proc execProcesses*(cmds: openArray[string],
     newSeq(q, n)
     var m = min(n, cmds.len)
     for i in 0..m-1:
-      q[i] = startProcessAux(cmds[i], options=options)
+      q[i] = startCmd(cmds[i], options=options)
     when defined(noBusyWaiting):
       var r = 0
       for i in m..high(cmds):
@@ -171,7 +177,7 @@ proc execProcesses*(cmds: openArray[string],
           echo(err)
         result = max(waitForExit(q[r]), result)
         if q[r] != nil: close(q[r])
-        q[r] = startProcessAux(cmds[i], options=options)
+        q[r] = startCmd(cmds[i], options=options)
         r = (r + 1) mod n
     else:
       var i = m
@@ -182,7 +188,7 @@ proc execProcesses*(cmds: openArray[string],
             #echo(outputStream(q[r]).readLine())
             result = max(waitForExit(q[r]), result)
             if q[r] != nil: close(q[r])
-            q[r] = startProcessAux(cmds[i], options=options)
+            q[r] = startCmd(cmds[i], options=options)
             inc(i)
             if i > high(cmds): break
     for i in 0..m-1:
@@ -190,7 +196,7 @@ proc execProcesses*(cmds: openArray[string],
       result = max(waitForExit(q[i]), result)
   else:
     for i in 0..high(cmds):
-      var p = startProcessAux(cmds[i], options=options)
+      var p = startCmd(cmds[i], options=options)
       result = max(waitForExit(p), result)
       close(p)
 
@@ -204,7 +210,7 @@ when not defined(useNimRtl):
   proc execProcess(command: string,
                    options: set[TProcessOption] = {poStdErrToStdOut,
                                                    poUseShell}): TaintedString =
-    var p = startProcessAux(command, options=options)
+    var p = startCmd(command, options=options)
     var outp = outputStream(p)
     result = TaintedString""
     while running(p) or not outp.atEnd(outp):
@@ -625,6 +631,27 @@ elif not defined(useNimRtl):
     
     pruneProcessSet(readfds, (rd))
 
+
+proc execCmdEx*(command: string, options: set[TProcessOption] = {
+                poStdErrToStdOut, poUseShell}): tuple[
+                output: TaintedString, 
+                exitCode: int] =
+  ## a convenience proc that runs the `command`, grabs all its output and
+  ## exit code and returns both.
+  var p = startCmd(command, options)
+  var outp = outputStream(p)
+  result = (TaintedString"", -1)
+  while not outp.atEnd(outp):
+    result[0].string.add(outp.readLine().string)
+    result[0].string.add("\n")
+    result[1] = peekExitCode(p)
+    if result[1] != -1: break
+  outp.close(outp)
+  if result[1] == -1:
+    result[1] = peekExitCode(p)
+  close(p)
+
+
 when isMainModule:
   var x = execProcess("gcc -v")
   echo "ECHO ", x
diff --git a/lib/pure/pegs.nim b/lib/pure/pegs.nim
index 25637cfee..4c4d3472a 100755
--- a/lib/pure/pegs.nim
+++ b/lib/pure/pegs.nim
@@ -969,7 +969,7 @@ proc transformFile*(infile, outfile: string,
   ## reads in the file `infile`, performs a parallel replacement (calls
   ## `parallelReplace`) and writes back to `outfile`. Raises ``EIO`` if an
   ## error occurs. This is supposed to be used for quick scripting.
-  var x = readFile(infile)
+  var x = readFile(infile).string
   writeFile(outfile, x.parallelReplace(subs))
   
 iterator split*(s: string, sep: TPeg): string =
de63853dc141b919dc853ade4380a478206'>^
3d1c6de63 ^
e25474154 ^
94f425681 ^
9a6f47ae6 ^
087b8621d ^
5b96eaa95 ^
69cc24cdf ^
087b8621d ^




5131b3cea ^
5b96eaa95 ^

5b28d0820 ^
9a6f47ae6 ^

92e49aeaa ^


e25474154 ^
3d1c6de63 ^
7a2b1a752 ^
92e49aeaa ^
e9d6f5a64 ^

7a2b1a752 ^
e9d6f5a64 ^
3d1c6de63 ^
7a2b1a752 ^
92e49aeaa ^
13c69f554 ^

5131b3cea ^
13c69f554 ^
b0c11d3ef ^

13c69f554 ^
3d1c6de63 ^

13c69f554 ^
3d1c6de63 ^

5b28d0820 ^
e25474154 ^
b0c11d3ef ^
3d1c6de63 ^
5b28d0820 ^
92e49aeaa ^
5b28d0820 ^
3d1c6de63 ^
e25474154 ^
f46870fe1 ^
e25474154 ^



3d1c6de63 ^
e25474154 ^
3d1c6de63 ^
e25474154 ^

f46870fe1 ^
e25474154 ^

6ff8752be ^
3d1c6de63 ^
b595fc834 ^

c7158af75 ^
6ff8752be ^



3d1c6de63 ^
b595fc834 ^

c7158af75 ^
b0c11d3ef ^


ade67f1ab ^
5b28d0820 ^
e25474154 ^

f46870fe1 ^


6ff8752be ^
f46870fe1 ^
e25474154 ^
6ff8752be ^

3d1c6de63 ^
f46870fe1 ^
b595fc834 ^
c7158af75 ^
5b28d0820 ^
ade67f1ab ^
6ff8752be ^
c7158af75 ^
e25474154 ^
ade67f1ab ^
5b28d0820 ^
e25474154 ^

f46870fe1 ^
e25474154 ^
13c69f554 ^
6ff8752be ^
e25474154 ^
6ff8752be ^

e25474154 ^

7a2b1a752 ^
e25474154 ^

f46870fe1 ^
b595fc834 ^
c7158af75 ^
b595fc834 ^


c7158af75 ^
6ff8752be ^
f46870fe1 ^
6ff8752be ^
e25474154 ^
d1d5fc825 ^
e25474154 ^
6ff8752be ^

af081f995 ^
e25474154 ^
af081f995 ^






d1d5fc825 ^
e25474154 ^
5b28d0820 ^
e25474154 ^

f46870fe1 ^
94f425681 ^
5b28d0820 ^
94f425681 ^
e25474154 ^
6ff8752be ^

e25474154 ^


7a2b1a752 ^
e25474154 ^



b595fc834 ^

c7158af75 ^
b5b5e6e76 ^
e25474154 ^

af081f995 ^
ade67f1ab ^

94f425681 ^

d1d5fc825 ^


cd0ae9726 ^
7a2b1a752 ^

d1d5fc825 ^
e25474154 ^
f46870fe1 ^
e25474154 ^



af081f995 ^





f46870fe1 ^
e25474154 ^


7a2b1a752 ^
e25474154 ^


af081f995 ^

ade67f1ab ^
af081f995 ^
b5b5e6e76 ^
94f425681 ^

af081f995 ^

94f425681 ^

af081f995 ^


94f425681 ^

af081f995 ^
94f425681 ^
af081f995 ^


94f425681 ^


13c69f554 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338