1# Copyright 2018 The Emscripten Authors. All rights reserved. 2# Emscripten is available under two separate licenses, the MIT license and the 3# University of Illinois/NCSA Open Source License. Both these licenses can be 4# found in the LICENSE file. 5 6''' 7Performs a search-replace in all of js/ 8''' 9 10from __future__ import print_function 11import os 12 13 14def all_children(subdir): 15 return [os.path.join(dp, f) for dp, dn, fn in os.walk(subdir) for f in fn] 16 17 18for x in all_children('src') + all_children('tests') + all_children('tools') + all_children('system/lib') + ['emscripten.py', 'emcc.py']: 19 if 'update_js.py' in x: 20 continue 21 if not (x.endswith('.py') or x.endswith('.c') or x.endswith('.cpp') or x.endswith('.h') or x.endswith('.js') or x.endswith('.ll')): 22 continue 23 print(x) 24 orig = open(x).read() 25 fixed = orig[:] 26 fixed = fixed.replace('Module["print"](', 'out(') 27 fixed = fixed.replace('Module[\'print\'](', 'out(') 28 fixed = fixed.replace('Module.print(', 'out(') 29 30 fixed = fixed.replace('Module["printErr"](', 'err(') 31 fixed = fixed.replace('Module[\'printErr\'](', 'err(') 32 fixed = fixed.replace('Module.printErr(', 'err(') 33 34 fixed = fixed.replace(' = Module["print"]', ' = out') 35 fixed = fixed.replace(' = Module[\'print\']', ' = out') 36 fixed = fixed.replace('Module["print"] = ', 'out = ') 37 fixed = fixed.replace('Module[\'print\'] = ', 'out = ') 38 fixed = fixed.replace(' = Module.print', ' = out') 39 fixed = fixed.replace('Module.print = ', 'out = ') 40 41 fixed = fixed.replace(' = Module["printErr"]', ' = err') 42 fixed = fixed.replace(' = Module[\'printErr\']', ' = err') 43 fixed = fixed.replace('Module["printErr"] = ', 'err = ') 44 fixed = fixed.replace('Module[\'printErr\'] = ', 'err = ') 45 fixed = fixed.replace(' = Module.printErr', ' = err') 46 fixed = fixed.replace('Module.printErr = ', 'err = ') 47 48 if fixed != orig: 49 open(x, 'w').write(fixed) 50