<commit_before>var exec = require('child_process').exec;
var spawn = require('child_process').spawn;
var fs = require('fs');
var http = require('http');

var util = require('./util');

var editorevent = require('./editor_event');
var remotehostevent = require('./remotehost_event');

var filedialog= require('./js/filedialog');
var RemoteFTP = require('./js/RemoteFTP');

//-------------------------------------
// Server request logic
//-------------------------------------
var server = http.createServer();
server.on('request', function(req,res){
	console.log("REQ>"+req.url);
	
	var url = req.url;
	var addrs = req.url.split("?");
	if (addrs)
		url = addrs[0]; // ignore args

	if (url == '/') {
		var html = fs.readFileSync('./home.html');
		res.writeHead(200,{'Content-Type':'text/html', charaset:'UTF-8'});
		res.end(html);
	} else {
		fs.readFile('.' + url, function (err,data){
			if (err) {
				res.writeHead(404,{'Content-Type':'text/html', charaset:'UTF-8'});
				res.end("<h1>not found<h1>");
				return;
			}
			var ext = util.getExtention(url);
			if (ext == "css")
				res.writeHead(200,{'Content-Type':'text/css',charaset:'UTF-8'});
			else if (ext == "html" || ext == "htm")
				res.writeHead(200,{'Content-Type':'text/html',charaset:'UTF-8'});
			else if (ext == "js" || ext == "json")
				res.writeHead(200,{'Content-Type':'text/javascript',charaset:'UTF-8'});
			else
				res.writeHead(200);//,{charaset:'UTF-8'});
			res.end(data);
		}); // fs.readFile
	}
});
server.listen(8080);
console.log('Server running on localhost:8080')

//---------------------------------------------------------------------------

function registerPTLEvent(socket)
{
	socket.on('ptl_launchapp', function(data) {
		console.log("ptl_launchapp:" + data.appname);
		
		var appcmd;
		if (data.appname == 'FXgen')
			appcmd = 'open /Applications/FXgen.app';
		else if(data.appname == 'PDI')
			appcmd = 'pdi';
		
		var child = exec(appcmd, function(err, stdout, stderr) {
			if (err) {
				console.log(err);
				console.log(err.code);
				console.log(err.signal);
			} else {
				console.log('stdout: ' + stdout);
				console.log('stderr: ' + stderr)
			}
		});
	});// ptl_launchapp
	
	filedialog.SocketEvent(socket,'homedlg');
	filedialog.SocketEvent(socket,'remotedlg');

	socket.on('registerProjectHistory', function(path){
		console.log("REGISTER_HISTORY:"+path);
		var historyFile = "project_history.json";
		fs.readFile(historyFile, function(err,data){
			var names = path.split("/");
			var name = names[names.length-1];
			console.log("ProjName="+name);
			if (err) {
				console.log('Error: ' + err);
				data = new Array();
				data.push({"name":name, "path":path});
			} else {
				data = JSON.parse(data);
				data.splice(0, 0,{"name":name, "path":path}); // Add first
			}
			data  = JSON.stringify(data);
			fs.writeFileSync(historyFile, data, 'utf8');
		});
	});

}


// socket.io setting
var io = require('socket.io').listen(server);
io.set('log level', 1);

io.sockets.on('connection', function (socket) {
	socket.emit('event', 'Server Connected.');
	console.log("[CONNECT] ID="+socket.id);

	RemoteFTP(socket);
	editorevent.registerEditorEvent(socket);
	remotehostevent.registerEditorEvent(socket);
	registerPTLEvent(socket);
});<commit_msg>beautify<commit_after>var exec = require('child_process').exec,
	spawn = require('child_process').spawn,
	fs = require('fs'),
	http = require('http'),
	util = require('./util'),
	editorevent = require('./editor_event'),
	remotehostevent = require('./remotehost_event'),
	filedialog = require('./js/filedialog'),
	RemoteFTP = require('./js/RemoteFTP');

//-------------------------------------
// Server request logic
//-------------------------------------
var server = http.createServer();
server.on('request', function (req, res) {
	"use strict";
	console.log("REQ>" + req.url);
	
	var url = req.url,
		addrs = req.url.split("?"),
		html,
		ext;
	if (addrs) {
		url = addrs[0]; // ignore args
	}
	
	if (url === '/') {
		html = fs.readFileSync('./home.html');
		res.writeHead(200, {'Content-Type': 'text/html', charaset: 'UTF-8'});
		res.end(html);
	} else {
		fs.readFile('.' + url, function (err, data) {
			if (err) {
				res.writeHead(404, {'Content-Type': 'text/html', charaset: 'UTF-8'});
				res.end("<h1>not found<h1>");
				return;
			}
			ext = util.getExtention(url);
			if (ext === "css") {
				res.writeHead(200, {'Content-Type': 'text/css', charaset: 'UTF-8'});
			} else if (ext === "html" || ext === "htm") {
				res.writeHead(200, {'Content-Type': 'text/html', charaset: 'UTF-8'});
			} else if (ext === "js" || ext === "json") {
				res.writeHead(200, {'Content-Type': 'text/javascript', charaset: 'UTF-8'});
			} else {
				res.writeHead(200);//,{charaset:'UTF-8'});
			}
			res.end(data);
		}); // fs.readFile
	}
});
server.listen(8080);
console.log('Server running on localhost:8080');

//---------------------------------------------------------------------------

function registerPTLEvent(socket) {
	"use strict";
	socket.on('ptl_launchapp', function (data) {
		console.log("ptl_launchapp:" + data.appname);
		
		var appcmd, child;
		if (data.appname === 'FXgen') {
			appcmd = 'open /Applications/FXgen.app';
		} else if (data.appname === 'PDI') {
			appcmd = 'pdi';
		}
		child = exec(appcmd, function (err, stdout, stderr) {
			if (err) {
				console.log(err);
				console.log(err.code);
				console.log(err.signal);
			} else {
				console.log('stdout: ' + stdout);
				console.log('stderr: ' + stderr);
			}
		});
	});// ptl_launchapp
	
	filedialog.SocketEvent(socket, 'homedlg');
	filedialog.SocketEvent(socket, 'remotedlg');

	socket.on('registerProjectHistory', function (path) {
		console.log("REGISTER_HISTORY:" + path);
		var historyFile = "project_history.json";
		fs.readFile(historyFile, function (err, data) {
			var names = path.split("/"),
				name = names[names.length - 1];
			console.log("ProjName=" + name);
			if (err) {
				console.log('Error: ' + err);
				data = [];
				data.push({"name": name, "path": path});
			} else {
				data = JSON.parse(data);
				data.splice(0, 0, {"name": name, "path": path}); // Add first
			}
			data  = JSON.stringify(data);
			fs.writeFileSync(historyFile, data, 'utf8');
		});
	});

}


// socket.io setting
var io = require('socket.io').listen(server);
io.set('log level', 1);

io.sockets.on('connection', function (socket) {
	"use strict";
	socket.emit('event', 'Server Connected.');
	console.log("[CONNECT] ID=" + socket.id);

	RemoteFTP(socket);
	editorevent.registerEditorEvent(socket);
	remotehostevent.registerEditorEvent(socket);
	registerPTLEvent(socket);
});
{'fraction_non_alphanumeric': 0.2449659348978047, 'fraction_numerical': 0.012112036336109008, 'mean_word_length': 3.215698787492023, 'pattern_counts': {'":': 8, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3170364', 'n_tokens_mistral': 2575, 'n_tokens_neox': 2264, 'n_words': 419}