<commit_before>#!/usr/bin/nodejs

'use strict';

global.DOMParser = require('xmldom').DOMParser; 
//require('../closure-library/closure/goog/bootstrap/nodejs')
global.Blockly = require('./blockly_wrapped.js');
//require('./blocks_compressed.js');
//require('./javascript_compressed.js');
//require('./msg/js/en.js');

Blockly.Events.Create = function() { this.isNull=function(){return 1}; };

var fname = process.argv[0] == 'blockly' ? process.argv[1] : process.argv[2];
var fs = require('fs');
var xmlText = fs.readFileSync(fname, 'utf8');

try {
    var xml = Blockly.Xml.textToDom(xmlText);
}
catch (e) {
    console.log(e);
    process.exit(2);
}

var workspace = new Blockly.Workspace();
Blockly.Xml.domToWorkspace(xml, workspace);
var code = Blockly.JavaScript.workspaceToCode(workspace);

var prepend = `
  var HKOIInput = {
    str : '',
    lines : []
  };
  var window = {
    'alert': function(x) {
      console.log(x);
    },
    'prompt': function(x) {
      while (true) {
        var buf = new Buffer(1024);
        var br = require('fs').readSync(process.stdin.fd, buf, 0, 1024);
        if (br == 0) break;
        HKOIInput.str += buf.toString(null, 0, br);
      }
      var lines = HKOIInput.str.split('\\n');
      for (var i in lines) {
        HKOIInput.lines.push(lines[i]);
      }
      return HKOIInput.lines.shift();
    }
  };
  var HKOIUpdateVar = function() {};
  var HKOIEnterScope = function() {};
  var HKOIExitScope = function() {};
`;
code = prepend + code;
code = code.replace(/^\s*HKOIUpdateVar.*/gm, '');

fs.writeFileSync('program.exe', code);
fs.chmodSync('program.exe', 493);
<commit_msg>improve input reading<commit_after>#!/usr/bin/nodejs

'use strict';

global.DOMParser = require('xmldom').DOMParser; 
//require('../closure-library/closure/goog/bootstrap/nodejs')
global.Blockly = require('./blockly_wrapped.js');
//require('./blocks_compressed.js');
//require('./javascript_compressed.js');
//require('./msg/js/en.js');

Blockly.Events.Create = function() { this.isNull=function(){return 1}; };

var fname = process.argv[0] == 'blockly' ? process.argv[1] : process.argv[2];
var fs = require('fs');
var xmlText = fs.readFileSync(fname, 'utf8');

try {
    var xml = Blockly.Xml.textToDom(xmlText);
}
catch (e) {
    console.log(e);
    process.exit(2);
}

var workspace = new Blockly.Workspace();
Blockly.Xml.domToWorkspace(xml, workspace);
var code = Blockly.JavaScript.workspaceToCode(workspace);

var prepend = `
var HKOIInput = {
  lines : []
};
var window = {
  'alert': function(x) {
    console.log(x);
  },
  'prompt': function(x) {
    return HKOIInput.lines.shift();
  }
};
var HKOIUpdateVar = function() {};
var HKOIEnterScope = function() {};
var HKOIExitScope = function() {};
(function() {
  var str = "";
  while (true) {
    var buf = new Buffer(1024);
    var br = require('fs').readSync(process.stdin.fd, buf, 0, 1024);
    if (br == 0) break;
    str += buf.toString(null, 0, br);
  }
  HKOIInput.lines = str.split('\\n');
})();

`;
code = prepend + code;
code = code.replace(/^\s*HKOIUpdateVar.*/gm, '');

fs.writeFileSync('program.exe', code);
fs.chmodSync('program.exe', 493);

{'fraction_non_alphanumeric': 0.1961220597584234, 'fraction_numerical': 0.012714558169103624, 'mean_word_length': 3.6830357142857144, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1936665', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1127, 'n_words': 211}