/** * include.jsee * * @author MALU * @version 0.5.2 */ var INCLUDE = [ //////////////////////////////////////////////////////////////////////////////// "C:/Program Files/Microsoft Visual Studio 9.0/VC/include", "C:/Program Files/Microsoft Visual Studio 9.0/VC/atlmfc/include", "C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/include", "C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/atlmfc/include", "C:/Program Files/Microsoft SDKs/Windows/v7.0/Include", "C:/usr/MinGW/include", "C:/usr/MinGW/include/c++/3.4.5", "C:/usr/dm/include", "C:/usr/dm/stlport/stlport", "C:/usr/lib/WTL80/include", "C:/usr/lib/boost", "C:/usr/lib/zlib", "C:/usr/lib/libpng", "C:/usr/lib/libjpeg", "C:/xampp/php/PEAR", //////////////////////////////////////////////////////////////////////////////// ""], INDEX = [ //////////////////////////////////////////////////////////////////////////////// "index.html", "index.htm", "index.shtml", "index.phtml", "Default.aspx", //////////////////////////////////////////////////////////////////////////////// ""]; function parse(txt, ext, cur) { var MSG = { INVALID_FORMAT: "Invalid format:\n\n%s", FILE_NOT_FOUDN: "File not found:\n\n%s" }; var FSO = new ActiveXObject("Scripting.FileSystemObject"); var SHO = new ActiveXObject("WScript.Shell"); function open(filename) { if (!filename.match(/^[A-Z]:/i)) filename = FSO.GetAbsolutePathName(FSO.BuildPath(document.Path, filename)); if (!FSO.FileExists(filename)) return false; editor.OpenFile(filename, 0, eeOpenAllowNewWindow); return true; } function any(match, n) { for (var i = 1; i <= n; i++) { if (match[i]) return match[i]; } return null; } function abort(msg, s) { alert(msg.replace("%s", s)); Quit(); } if (!Array.prototype.filter) { Array.prototype.filter = function (callback) { if (!callback) { callback = function (x) { return x && x != ""; }; } var r = new Array(); for (var i = 0; i < this.length; i++) { if (callback.call(this, this[i])) r.push(this[i]); } return r; }; } var env = [ "System", "User", "Process" ]; for (var i = 0; i < env.length; i++) { var inc = SHO.Environment(env[i])("INCLUDE"); if (inc) INCLUDE = INCLUDE.concat(inc.split(";")); } INCLUDE = INCLUDE.filter(); INDEX = INDEX.filter(); switch (ext) { //-------------------------------------------------------------------------------- // HTML //-------------------------------------------------------------------------------- case "htm": case "html": case "xht": case "xhtml": case "hta": case "shtml": case "phtml": var re = /src=(?:"(.+?)"|'(.+?)')|href=(?:"(.+?)"|'(.+?)')|action=(?:"(.+?)"|'(.+?)')/ig; var m, d = txt.length, inc = null; while (m = re.exec(txt)) { var t = any(m, 6); var s = m.index; var e = m.lastIndex - 1; if (s <= cur && cur <= e) { inc = t; break; } if (cur < s && s - cur < d) inc = t, d = s - cur; if (e < cur && cur - e < d) inc = t, d = cur - e; } if (inc) { inc = inc.replace(/[?;#].*$/, ""); if (inc.length == 0) Quit(); if (inc.charAt(inc.length - 1) != "/") { if (open(inc)) Quit(); } else { for (var i = 0; i < INDEX.length; i++) { if (open(inc + INDEX[i])) Quit(); } } abort(MSG.FILE_NOT_FOUDN, inc); } break; //-------------------------------------------------------------------------------- // CSS //-------------------------------------------------------------------------------- case "css": var m, re = /@import(?:\s*(?:"(.+?)"|'(.+?)')|\s+url\(\s*(?:"(.+?)"|'(.+?)')\s*\))/; if (m = txt.match(re)) { var inc = any(m, 4); if (open(inc)) Quit(); abort(MSG.FILE_NOT_FOUDN, inc); } break; //-------------------------------------------------------------------------------- // Smarty //-------------------------------------------------------------------------------- case "tpl": var m, re = /\{include\s+.*?file=(?:"(.+?)"|'(.+?)').*?\}/; if (m = txt.match(re)) { var inc = any(m, 2); if (open(inc)) Quit(); abort(MSG.FILE_NOT_FOUDN, inc); } break; //-------------------------------------------------------------------------------- // PHP //-------------------------------------------------------------------------------- case "php": case "php4": case "php5": var re = [ /(?:include|require)(?:_once)?\s*(\bdirname\(__FILE__\)\s*\.\s*)?'(.+?)'/, /(?:include|require)(?:_once)?\s*(\bdirname\(__FILE__\)\s*\.\s*)?"(.+?)"/, /(?:include|require)(?:_once)?\s*\((dirname\(__FILE__\)\s*\.\s*)?\s*'(.+?)'\s*\)/, /(?:include|require)(?:_once)?\s*\((dirname\(__FILE__\)\s*\.\s*)?\s*"(.+?)"\s*\)/ ], inc = null; for (var i = 0; i < re.length; i++) { if (txt.match(re[i])) { inc = RegExp.$2; break; } } if (inc) { if (open(inc)) Quit(); if (!RegExp.$1) { for (var i = 0; i < INCLUDE.length; i++) { if (open(FSO.BuildPath(INCLUDE[i], inc))) Quit(); } } abort(MSG.FILE_NOT_FOUDN, inc); } break; //-------------------------------------------------------------------------------- // ActionScript3.0 //-------------------------------------------------------------------------------- case "as": if (txt.match(/import\s+(.+)\s*;/)) { var imp = RegExp.$1.split('.'); var dir = document.Path.replace(/[\\\/]$/, ""); var all = (function () { var s = document.selection; var x = s.GetActivePointX(eePosView); var y = s.GetActivePointY(eePosView); s.SelectAll(); var t = s.Text; s.SetActivePoint(eePosView, x, y); return t.split(/\r\n|\r|\n/); })(); for (var l = 0; l < all.length; l++) { if (all[l].match(/package(?:\s+(\S+))?/)) { var pac = RegExp.$1; if (pac.length != 0) { pac = pac.split('.'); for (var i = 0; i < pac.length; i++) dir = FSO.GetParentFolderName(dir); } break; } } dir = dir + '/' + imp.slice(0, -1).join('/') + '/'; var cls = imp[imp.length - 1]; if (!FSO.FolderExists(dir)) abort(MSG.FILE_NOT_FOUDN, dir + cls); if (cls == '*') { var fnd = false; for (var e = new Enumerator(FSO.GetFolder(dir).Files); !e.atEnd(); e.moveNext()) { if (FSO.GetExtensionName(e.item()).toLowerCase() != "as") continue; if (open(e.item().Path)) fnd = true; } if (fnd) Quit(); abort(MSG.FILE_NOT_FOUDN, dir + cls); } else { if (open(dir + cls + ".as")) Quit(); abort(MSG.FILE_NOT_FOUDN, dir + cls + ".as"); } } break; //-------------------------------------------------------------------------------- // C/C++ //-------------------------------------------------------------------------------- default: if (txt.match(/#\s*include\s*"(.+)"/)) { var inc = RegExp.$1; if (open(inc)) Quit(); for (var i = 0; i < INCLUDE.length; i++) { if (open(FSO.BuildPath(INCLUDE[i], inc))) Quit(); } abort(MSG.FILE_NOT_FOUDN, inc); } if (txt.match(/#\s*include\s*<(.+)>/)) { var inc = RegExp.$1; for (var i = 0; i < INCLUDE.length; i++) { if (open(FSO.BuildPath(INCLUDE[i], inc))) Quit(); } abort(MSG.FILE_NOT_FOUDN, inc); } } switch (ext) { //-------------------------------------------------------------------------------- // C/C++ header -> source //-------------------------------------------------------------------------------- case "h": case "hh": case "hpp": case "hxx": case "h++": var c = [ "c", "cc", "cpp", "cxx", "c++" ]; var n = document.Name; var p = FSO.BuildPath(document.Path, n.substring(0, n.lastIndexOf("."))); if (FSO.FolderExists(p)) { var fnd = false; for (var e = new Enumerator(FSO.GetFolder(p).Files); !e.atEnd(); e.moveNext()) { var t = FSO.GetExtensionName(e.item()).toLowerCase(); for (var i = 0; i < c.length; i++) { if (t == c[i]) { if (open(e.item().Path)) fnd = true; break; } } } if (fnd) Quit(); } else { for (var i = 0; i < c.length; i++) { if (open(p + "." + c[i])) Quit(); } } break; //-------------------------------------------------------------------------------- // C/C++ source -> header //-------------------------------------------------------------------------------- case "c": case "cc": case "cpp": case "cxx": case "c++": var h = [ "h", "hh", "hpp", "hxx", "h++" ]; var n = document.Name; var p = FSO.BuildPath(document.Path, n.substring(0, n.lastIndexOf("."))); for (var i = 0; i < h.length; i++) { if (open(p + "." + h[i])) Quit(); } p = FSO.GetParentFolderName(p); for (var i = 0; i < h.length; i++) { if (open(p + "." + h[i])) Quit(); } break; //-------------------------------------------------------------------------------- // ASP.NET code behind -> aspx //-------------------------------------------------------------------------------- case "cs": case "vb": if (open(FSO.BuildPath(document.Path, document.Name.replace(/\.\w+?$/, "")))) Quit(); break; //-------------------------------------------------------------------------------- // ASP.NET aspx -> code behind //-------------------------------------------------------------------------------- case "aspx": var c = [ "cs", "vb" ]; var p = FSO.BuildPath(document.Path, document.Name); for (var i = 0; i < c.length; i++) { if (open(p + "." + c[i])) Quit(); } break; } abort(MSG.INVALID_FORMAT, txt); } var s = document.selection; var x = s.GetActivePointX(eePosView); var y = s.GetActivePointY(eePosView); s.SelectLine(); var t = s.Text; s.SetActivePoint(eePosView, x, y); var n = document.Name; var e = n.substring(n.lastIndexOf(".") + 1).toLowerCase(); parse(t, e, x - 1);