#!/usr/bin/env node

var path = require('path'),
    mkdirp = require('mkdirp'),
    optimist = require('optimist'),
    es = require('event-stream'),
    argv = optimist
      .usage('Usage: $0')
      .alias('o', 'output')
      .describe('o', 'Output path for modified files')
      .alias('h', 'help')
      .describe('h', 'Print this usage')
      .argv,
    
    stdin = process.stdin,
    copy_files,
    print_files,
    filter_files;

if (argv.help) {
  optimist.showHelp();
  process.exit(0);
}

var file_list = [];
stdin.resume();
stdin.setEncoding('utf8');

var file_pipe = stdin
  .pipe(es.split())
  .pipe(es.map(function(file, callback) {
    var match = file.match(/^[AM]\s(.+)$/);

    if (match) {
      callback(null, match[1]);
    } else {
      callback();
    }
  }));

if (argv.output) {

} else {
  file_pipe
    .pipe(es.map(function(file, callback) {
      callback(null, file + '\n');
    }))
    .pipe(process.stdout);
}

@@ -385,16 +385,53 @@
 .stdin,%0A
+    global_domain = domain.create(),%0A
     copy
@@ -536,16 +536,538 @@
 (0);%0A%7D%0A%0A
+global_domain.run(run);%0A%0Aglobal_domain.on('error', function(error) %7B%0A  console.error(error);%0A  process.exit(1);%0A%7D);%0A%0Avar file_pipe;%0A%0Avar copy_file = function(out_dir, in_file) %7B%0A  var abs_out_dir = path.resolve(out_dir, process.cwd());%0A  var abs_out_file = path.join(abs_out_dir, in_file);%0A%0A  mkdirp(abs_out_dir, function(err) %7B%0A    if (err) %7B%0A      file_pipe.emit('error', new Error(err));%0A    %7D else %7B%0A      fs.createReadStream(in_file).pipe(fs.createWriteStream(abs_out_file));%0A    %7D%0A  %7D);%0A%7D;%0A%0Avar run = function() %7B%0A  
 var file
@@ -1078,16 +1078,18 @@
 t = %5B%5D;%0A
+  
 stdin.re
@@ -1096,16 +1096,18 @@
 sume();%0A
+  
 stdin.se
@@ -1122,27 +1122,25 @@
 g('utf8');%0A%0A
-var
+ 
  file_pipe =
@@ -1146,16 +1146,18 @@
 = stdin%0A
+  
   .pipe(
@@ -1168,16 +1168,18 @@
 plit())%0A
+  
   .pipe(
@@ -1216,16 +1216,18 @@
 ) %7B%0A    
+ 
+ 
 var matc
@@ -1259,24 +1259,26 @@
 +)$/);%0A%0A    
+  
 if (match) %7B
@@ -1274,24 +1274,26 @@
 f (match) %7B%0A
+  
       callba
@@ -1312,24 +1312,26 @@
 ch%5B1%5D);%0A    
+  
 %7D else %7B%0A   
@@ -1323,24 +1323,26 @@
    %7D else %7B%0A
+  
       callba
@@ -1355,18 +1355,22 @@
     
+ 
+ 
 %7D%0A
+  
   %7D));%0A%0A
 if (
@@ -1365,16 +1365,18 @@
   %7D));%0A%0A
+  
 if (argv
@@ -1386,17 +1386,120 @@
 tput) %7B%0A
-%0A
+    var copy_to_output = copy_file.bind(this, argv.output);%0A    file_pipe.on('data', copy_to_output);%0A  
 %7D else %7B
@@ -1499,16 +1499,18 @@
  else %7B%0A
+  
   file_p
@@ -1513,24 +1513,26 @@
 le_pipe%0A    
+  
 .pipe(es.map
@@ -1561,24 +1561,26 @@
 ck) %7B%0A      
+  
 callback(nul
@@ -1604,12 +1604,16 @@
     
+ 
+ 
 %7D))%0A
+  
     
@@ -1635,10 +1635,17 @@
 tdout);%0A
-%7D
+  %7D%0A%7D;%0A%0A
 %0A

add copy modified functionality