~gaox/+junk/bash

« back to all changes in this revision

Viewing changes to src/bash.xq

  • Committer: Xiang Gao
  • Date: 2012-07-25 20:20:00 UTC
  • Revision ID: gaox@ethz.ch-20120725202000-xil3qaul8jnh4s01
change signature

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
(: A file descriptor set to bash:pipe-in can be read, and the input is taken from the third parameter
48
48
  (each xs:string item is used for an input pipe, in the same order) :)
49
49
(: A file descriptor set to bash:pipe-out can be written to, and the output produced is returned by the function (one item for each output pipe, in the file descriptor order) :)
50
 
declare %an:sequential function bash:exec($args as xs:string*, $mapping as xs:anyURI*, $input-pipes as xs:string*) as xs:string* external;
 
50
declare %an:sequential function bash:exec($args as xs:string*, $pipe-ins as xs:int*, 
 
51
  $input-streams as xs:string*, $pipe-outs as xs:int*) as xs:string* external;
 
52
 
 
53
declare %an:sequential function bash:exec($args as xs:string*, $pipe-ins as xs:int*, 
 
54
  $input-streams as xs:string*) as xs:string* {
 
55
  bash:exec($args, $pipe-ins, $input-streams, ())
 
56
};
51
57
 
52
58
(: Executes exec with the supplied parameters, with the supplied file descriptor mapping, piping in being disallowed :)
53
 
declare %an:sequential function bash:exec($args as xs:string*, $mapping as xs:anyURI*) as xs:string* {
54
 
  bash:exec($args, $mapping, ())
 
59
declare %an:sequential function bash:exec($args as xs:string*, $pipe-outs as xs:int*) as xs:string* {
 
60
  bash:exec($args, (), (), $pipe-outs)
55
61
};
56
62
 
57
63
(: Executes exec with the supplied parameters, with the default file descriptor mapping :)
58
64
declare %an:sequential function bash:exec($args as xs:string*) as empty-sequence() {
59
 
  bash:exec($args, $bash:default-fd-mapping, ())
60
 
};
61
 
 
62
 
declare function bash:redirect($mapping as xs:anyURI*, $index as xs:integer*, $target as xs:anyURI*) as xs:anyURI* {
63
 
  let $new_map := 
64
 
  if (fn:count($index) = 0 or fn:count($target) = 0) then
65
 
    $mapping
66
 
  else
67
 
    fn:insert-before(fn:subsequence($mapping, $index[1] + 1 + 1), 1, fn:insert-before($target[1], 1, fn:subsequence($mapping, 1, $index[1] + 1 - 1)))
68
 
  
69
 
  return 
70
 
  if (fn:count($index) = 0 or fn:count($target) = 0) then
71
 
    $new_map
72
 
  else
73
 
    bash:redirect($new_map, fn:subsequence($index, 2), fn:subsequence($target, 2))
 
65
  bash:exec($args, (), (), ())
74
66
};
75
67
 
76
68
(: Get the current directory path :)