Skip to content

Instantly share code, notes, and snippets.

@KenDB3
Created August 30, 2017 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KenDB3/88749d4b67ec90c5c0e394c9c0067826 to your computer and use it in GitHub Desktop.
Save KenDB3/88749d4b67ec90c5c0e394c9c0067826 to your computer and use it in GitHub Desktop.
This script specifically cleans up the Fresh Water Fishing Simulation score file for a system running Synchronet BBS software.
/*FWS-Score-Fix.js -by- KenDB3 of KD3net (http://bbs.kd3.us)
This script is meant for use with Synchronet BBSes.
It requires JSexec.exe (from SBBS) to be run from command line.
Usage:
This script specifically cleans up the Fresh Water Fishing
Simulation score file. It removes the Erase Display/Clear Screen control
sequence (ESC[J), the Erase Line/Clear to End of Line control sequences
(ESC[K), and any bare CR alone on a line (Carriage Return with no Line Feed).
Add the FWS-Score-Fix.js script to your mods (/sbbs/mods/) or your
exec (/sbbs/exec/) directory.
Standard Command Line:
(be sure you're in the correct directory to call jsexec.exe, ie /sbbs/exec/)
jsexec.exe FWS-Score-Fix.js InputFile OutputFile
---InputFile and OutputFile arguments are required---
---InputFile cannot match OutputFile---
Optional Argument: "nocr"
This will also remove the bare Carriage Return that happens every 24th line
Your command line would look like this:
jsexec.exe FWS-Score-Fix.js InputFile OutputFile nocr
Version 1.0 2017-08-29 Initial Release
*/
//Make sure we have enough arguments to handle the conversion
if(argc < 2) {
alert(format("!!!Missing Argument!!! \r\n" +
"Format should look like this: \r\n" +
"jsexec.exe FWS-Score-Fix.js InputFile OutputFile \r\n\r\n" +
"InputFile = Fresh Water Sim ANSI Scores Bulletin that needs to be cleaned up.\r\n" +
"OutputFile = Fresh Water Sim Scores Bulletin you want saved after clean up.\r\n"
, errno, FWSscoresInput));
exit();
}
var FWSscoresInput = argv[0];
var FWSscoresOutput = argv[1];
if(argc > 2) {
var RemoveCR = argv[2];
} else {
var RemoveCR = "keep";
}
if(FWSscoresInput.toLowerCase() == FWSscoresOutput.toLowerCase()) {
alert(format("!!!InputeFile Cannot Match OutputFile!!! \r\n" +
"Format should look like this: \r\n" +
"jsexec.exe FWS-Score-Fix.js InputFile OutputFile \r\n\r\n" +
"InputFile = Fresh Water Sim ANSI Scores Bulletin that needs to be cleaned up.\r\n" +
"OutputFile = Fresh Water Sim Scores Bulletin you want saved after clean up.\r\n" +
"Sorry, but unfortunately these files cannot be the same.\r\n" +
"I suggest making this part of a script that later deletes the original file.\r\n"
, errno, FWSscoresInput));
exit();
}
//Our input file
var file = new File(FWSscoresInput);
//Does the file open? Or are you messing with me?
if(!file.open("r")) {
alert(format("Error %d opening %s\n", errno, FWSscoresInput));
exit();
}
var FWSscoresFix = file.readAll(4096);
var line_num;
var line_num_out;
//RegEx to find and replace the text
for(line_num in FWSscoresFix) {
//Remove the Erase Display/Clear Screen control sequence
FWSscoresFix[line_num] = FWSscoresFix[line_num].replace(/\033\[2J/g, '');
//Remove the Erase Line/Clear to End of Line control sequence
FWSscoresFix[line_num] = FWSscoresFix[line_num].replace(/\033\[K/, '');
//Remove any bare CR alone on a line if user adds the "nocr" argument
if(RemoveCR.toLowerCase() == "nocr") {
FWSscoresFix[line_num] = FWSscoresFix[line_num].replace(/^\r/, '');
}
}
var file = new File(FWSscoresOutput);
//Does the new file open?
if(!file.open("w")) {
alert(format("Error %d opening %s\n", errno, FWSscoresOutput));
exit();
}
for(line_num_out in FWSscoresFix) {
var lineout = FWSscoresFix[line_num_out];
file.writeln(lineout);
}
file.close();
print(FWSscoresInput + " successfully converted to " + FWSscoresOutput);
exit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment