// Shave and a Haircut // (c) 2019 Epic Games // US Patent 6720962 // // Script to create sample/include/shaveSDKFUNCS2.h & shaveSDKCALLBACKS2.h // // To execute: cscript mkSDKincludes.js // var fs = WScript.CreateObject("Scripting.FileSystemObject"); var altNamesFile; var sdkFuncsFile; var sdkCallbacksFile; try { altNamesFile = fs.OpenTextFile("shaveSDKALTNAMES.h", 1, false, 0); } catch(e) { WScript.Echo("Could not find shaveSDKALTNAMES.h"); WScript.Quit(); } try { sdkFuncsFile = fs.OpenTextFile("shaveSDKFUNCS.h", 1, false, 0); } catch(e) { WScript.Echo("Could not find shaveSDKFUNCS.h"); WScript.Quit(); } try { sdkCallbacksFile = fs.OpenTextFile("shaveSDKCALLBACKS.h", 1, false, 0); } catch(e) { WScript.Echo("Could not find shaveSDKCALLBACKS.h"); WScript.Quit(); } // // Find the '#ifdef ALTERNATE_DEFS' line. // var line; while (!altNamesFile.AtEndOfStream) { line = altNamesFile.ReadLine(); if ((line.indexOf("#ifdef") >= 0) && (line.indexOf("ALTERNATE_DEFS") >= 0)) break; } // // Store all the name pairs in a pair of arrays. // var names = new Array(); var altNames = new Array(); while (!altNamesFile.AtEndOfStream) { line = altNamesFile.ReadLine(); var words = line.split(/[ \t]/); if (words.length > 0) { if (words[0] == "#endif") break; if ((words[0] == "#define") && (words.length == 3)) { names[names.length] = new RegExp(words[1] + "[ \\t]*\\("); altNames[altNames.length] = words[2] + "("; } } } altNamesFile.Close(); // // Create the shaveSDKFUNCS2.h file in sample\include. // var sdkFuncs2File; try { sdkFuncs2File = fs.CreateTextFile("sample\\include\\shaveSDKFUNCS2.h", true); } catch(e) { WScript.Echo("Cannot create sample\\include\\shaveSDKFUNCS2.h."); } // // Step through each line of the original sdkFuncsFile, replacing the func // names with their alternate names. // while (!sdkFuncsFile.AtEndOfStream) { line = sdkFuncsFile.ReadLine(); // // Don't even both trying to do substitutions on blank lines or comment // lines. // if ((line.match(/^[ \t]*$/) == null) && (line.match(/^[ \t]*\/\//) == null)) { for (i = 0; i < names.length; i++) { line = line.replace(names[i], altNames[i]); } } sdkFuncs2File.WriteLine(line); } sdkFuncsFile.Close(); sdkFuncs2File.Close(); // // Create the shaveSDKCALLBACKS2.h file in sample\include. // var sdkCallbacks2File; try { sdkCallbacks2File = fs.CreateTextFile("sample\\include\\shaveSDKCALLBACKS2.h", true); } catch(e) { WScript.Echo("Cannot create sample\\include\\shaveSDKCALLBACKS2.h."); } // // Step through each line of the original sdkCallbacksFile, replacing the func // names with their alternate names. // while (!sdkCallbacksFile.AtEndOfStream) { line = sdkCallbacksFile.ReadLine(); // // Don't even both trying to do substitutions on blank lines or comment // lines. // if ((line.match(/^[ \t]*$/) == null) && (line.match(/^[ \t]*\/\//) == null)) { for (i = 0; i < names.length; i++) { line = line.replace(names[i], altNames[i]); } } sdkCallbacks2File.WriteLine(line); } sdkCallbacksFile.Close(); sdkCallbacks2File.Close();