From d0d6aef247ab3baf68c4ad4b2689283c1b36b0f4 Mon Sep 17 00:00:00 2001 From: Goraf <22941576+Goraf@users.noreply.github.com> Date: Sat, 9 Dec 2017 15:53:48 +0100 Subject: lpgen: fix possible bugs... * fix logical operators * use strict comparisons * add missing '()' invoking constructor --- tools/lpgen/lpgen.js | 14 +++++++------- tools/lpgen/translate.js | 28 ++++++++++++++-------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tools/lpgen/lpgen.js b/tools/lpgen/lpgen.js index 20f885961b..a10870eda3 100644 --- a/tools/lpgen/lpgen.js +++ b/tools/lpgen/lpgen.js @@ -50,7 +50,7 @@ var langpack_en = FSO.BuildPath(trunk, "langpacks\\english"); //Crap.txt will contain strings, which are removed by filtering engine as a garbage, in case if this string are not garbage :) var crapfile = "Crap.txt"; //Crap array -var crap = new Array; +var crap = new Array(); //*********************************************************************************// // Checking command line parameters *// @@ -104,7 +104,7 @@ GenerateCore(); //Generate plugins\protocols, listed in mir_full.sln //Init array with files path -project_files = new Array; +project_files = new Array(); //open mir_full.sln sln_stream = FSO.GetFile(slnfile).OpenAsTextStream(ForReading, TristateUseDefault); //Reading line-by-line @@ -256,14 +256,14 @@ function GeneratePluginTranslate(pluginpath, langpackfilepath, vcxprojfile) { //OR head have only one string (version.h wasn't found and head have only MUUID) //AND didn't find anything in *.RC and source files, so: //we didn't find any string and generating file is useless, return from function and out log - if ((head.length == 7 || head.length == 1) && foundstrings.length == 0) { + if ((head.length == 7 || head.length == 1) && foundstrings.length === 0) { if (log) { WScript.Echo("!!!Nothing to translate in " + plugin + "!!!"); } return; } //Suppose that we parse Pascal plugin, thus head have only one string with MUUID, push a plugin name there - if (head.length == 1 & foundstrings.length > 0) { + if (head.length == 1 && foundstrings.length > 0) { head.push(";langpack template for " + plugin); } //We have all strings in "foundstrings", next we remove duplicate strings from array and put results into "nodupes" @@ -410,7 +410,7 @@ function GetMUUID(folder, array) { //read text file, removing all commented text for further processing function ReadFile(file) { //If file zero size, return; - if (FSO.GetFile(file).Size == 0) return; + if (FSO.GetFile(file).Size === 0) return; //reading current file file_stream = FSO.GetFile(file).OpenAsTextStream(ForReading, TristateUseDefault); //read file fully into var @@ -458,7 +458,7 @@ function ParseFiles(filelist, stringsarray, parsefunction) { function ParseRCFile(FileTextVar, array) { var find = /^(?!\/{1,2})\s*(CONTROL|(?:DEF)?PUSHBUTTON|[LRC]TEXT|(?:AUTO)?RADIOBUTTON|GROUPBOX|(?:AUTO)?CHECKBOX|CAPTION|MENUITEM|POPUP)\s*"((?:(?:""[^"]+?"")*[^"]*?)*)"\s*?(,|$|\\)/mgi; //now make a job, till end of matching regexp - while ((string = find.exec(FileTextVar)) != null) { + while ((string = find.exec(FileTextVar)) !== null) { // check for some garbage like "List1","Tab1" etc. in *.rc files, we do not need this. onestring = string[2].replace(/^(((List|Tab|Tree|Spin|Custom|Slider|DateTimePicker|Radio|Check|HotKey|Progress)\d)|(whiterect|IndSndList|&?[Oo][Kk]|AOL|APOP|BBS|Bing|CTCP|DCC|Foodnetwork|Google|Google Talk|GPG|Hotmail|ICQ|ICQ Corp|ID|IP|ISDN|iTunes|Jabber|JID|Miranda|Miranda NG|mRadio|MSN|NickServ|OSD|OTR|PCS|PGP|S.ms|SMS|SSL|Steam|Steam Guard|Tox|Twitter|Yahoo|Winamp \(\*\)|Windows|X400|&\w)|(%.(.*%)?))$/g, ""); // ignore some popup menu craps @@ -485,7 +485,7 @@ function ParseSourceFile(FileTextVar, array) { //comment previous line and uncomment following line to output templates without _T() function in source files. Too many garbage from _T().. var find = /(?:LPGEN[TW]?|Translate[TW]?)(?:\s*?\(\s*?L?\s*)((?:(?:"[^"\\]*(?:\\[\S\s][^"\\]*)*")\s*)*)(?:\s*?,?\s*?(?:tmp)?\))/gm; //now make a job, till end of matching regexp - while ((string = find.exec(FileTextVar)) != null) { + while ((string = find.exec(FileTextVar)) !== null) { //first, init empty var var string; //replace newlines and all spaces and tabs between two pairs of " or ' with the void string ("") in first [1] subregexp ([\S\s]*?), and Delphi newlines "'#13#10+" replace diff --git a/tools/lpgen/translate.js b/tools/lpgen/translate.js index 3c21961c5c..a62c838b81 100644 --- a/tools/lpgen/translate.js +++ b/tools/lpgen/translate.js @@ -63,10 +63,10 @@ CoreTranslateDict = WScript.CreateObject("Scripting.Dictionary"); DupesTranslateDict = WScript.CreateObject("Scripting.Dictionary"); LangpackTranslateDict = WScript.CreateObject("Scripting.Dictionary"); //init arrays -Translated_Core_Array = new Array; -UnTranslated_Core_Array = new Array; -full_langpack_array = new Array; -release_array = new Array; +Translated_Core_Array = new Array(); +UnTranslated_Core_Array = new Array(); +full_langpack_array = new Array(); +release_array = new Array(); //*********************************************************************************// // Checking command line parameters *// @@ -149,8 +149,8 @@ if (WScript.Arguments.Named.Item("plugin")) { //plugin from command line: var cmdline_file = new String(WScript.Arguments.Named.Item("plugin")); //init array for our file translation and untranslated strings - var cmdline_file_array = new Array; - var cmdline_untranslated_array = new Array; + var cmdline_file_array = new Array(); + var cmdline_untranslated_array = new Array(); //Output filename variable var traslated_cmdline_file = new String(FSO.BuildPath(scriptpath, FSO.GetFileName(cmdline_file))); var untranslated_cmdline_file = new String(FSO.BuildPath(scriptpath, "untranslated_" + FSO.GetFileName(cmdline_file))); @@ -213,9 +213,9 @@ if (out) { //Init array of template files -TemplateFilesArray = new Array; +TemplateFilesArray = new Array(); //Init array of weather.ini translation files -WeatherFilesArray = new Array; +WeatherFilesArray = new Array(); //Find all template files and put them to array FindFiles(FSO.BuildPath(trunk, langpackenglish + "plugins\\"), "\\.txt$", TemplateFilesArray); //Find all weather.ini template files and add them into array @@ -254,8 +254,8 @@ function ProcessFiles(FilesEnum) { //cycle through file list while (!FilesEnum.atEnd()) { //intit Array with translated strings and untranslated stings - TranslatedTemplate = new Array; - UnTranslatedStrings = new Array; + TranslatedTemplate = new Array(); + UnTranslatedStrings = new Array(); //curfile is our current file in files enumerator curfile = FilesEnum.item(); //Log output to console @@ -326,7 +326,7 @@ function OutputFiles(TranslatedArray, UntranslatedArray, FolderName, FileName) { } //Write untranslated array into file, if /untranslated specified and there is something in array - if (untranslated & UntranslatedArray.length > 0) { + if (untranslated && UntranslatedArray.length > 0) { //redefine Untranslated file path and name, if /untranslated:"/path/" specified if (UnTranslatedPath != "yes") { UnTranslatedFile = UnTranslatedPath + "\\" + FileName; @@ -340,7 +340,7 @@ function OutputFiles(TranslatedArray, UntranslatedArray, FolderName, FileName) { //when /sourcelang: and /path: are NOT specified, thus we don't have any langpack file(s) to get translated strings. Thus all other job are useless function checkparams() { - if (!WScript.Arguments.Named.Item("langpack") & !WScript.Arguments.Named.Item("path") & !sourcelang) { + if (!WScript.Arguments.Named.Exists("langpack") && !WScript.Arguments.Named.Exists("path") && !sourcelang) { WScript.Echo("you didn't specify /langpack:\"/path/to/langpack.txt\", /path:\"/path/to/plugnis/\" or /sourcelang:\"language\" parameter, there is no files with translated strings!"); WScript.Quit(); } @@ -397,7 +397,7 @@ function GenerateTransalteDict(file, dictionary) { //"find" - RegularExpression, first string have to start with [ and end with]. Next string - translation var find = /(^\[.+?\](?=$))\r?\n(^(?!;file|\r|\n).+?(?=$))/mg; //While our "find" RegExp return a results, add strings into dictionary. - while ((string = find.exec(translatefiletext)) != null) { + while ((string = find.exec(translatefiletext)) !== null) { //first, init empty var var string; //first match as original string [....], is a key of dictionary, second match is a translation - item of key in dictionary @@ -446,7 +446,7 @@ function TranslateTemplateFile(Template_file, translated_array, untranslated_arr GenerateTransalteDict(FSO.BuildPath(WScript.Arguments.Named.Item("path"), (FSO.GetBaseName(FSO.GetParentFolderName(Template_file)) + "\\" + FSO.GetFileName(Template_file))), PluginTranslateDict); } //If file zero size, return; - if (FSO.GetFile(Template_file).Size == 0) return; + if (FSO.GetFile(Template_file).Size === 0) return; //access file stream.Open(); stream.LoadFromFile(Template_file); -- cgit v1.2.3