[script language = "jscript" runat = "server"]
/*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*
* FUNCTION:
fnDbugFileContents()
* DESCRIPTION:
Displays the contents of Text files in
a web page. Two files may be shown side by side
(in order to compare differences) and invisible
characters may be represented with escape characters.
(eg: a newline as \n).
* PARAMETERS:
sFile-- First file (required)
sFileB-- Second file
bShowInvisible-- determines if invisible text characters
are displayed.
* STATUS: working
* DOCUMENTATION:
http://www.geocities.com/matth3wbishop/eg/asp/
* SOURCE CODE:
http://www.geocities.com/matth3wbishop/eg/asp/
* DEPENDENCIES:
fnErrorMessage [fnErrorMessage.asp]
* NOTES: I am not sure if this really is a terribly useful
function. It was written in an odd frame of mind.
*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*/
function fnDbugFileContents(sFile, sFileB, bShowInvisible)
{
var path;
var fsoFile;
var fsoObject;
var sContents; //***Holds the contents of the file
var bShowControlChar;
if (bShowInvisible == null)
{bShowControlChar = false;}
else
{bShowControlChar = bShowInvisible;}
if (sFile == null)
{
fnErrorMessage(
"fnDbugFileContents", "sFile",
"The 'sFile' parameter was omitted. This parameter is required");
}
//***Note '\' is an escape character
var Pattern = /^(\\)(\\)^(\\)/gi;
Pattern = /\\/gi;
//path = sFile.replace(Pattern, "\\\\");
path = sFile;
fsoFile = Server.CreateObject("Scripting.FileSystemObject")
if (fsoFile.FileExists(path))
{
fsoObject = fsoFile.OpenTextFile(path);
sContents = fsoObject.ReadAll();
}
else
{
fnErrorMessage(
"fnDbugFileContents", "sFile ('" + path + "') ",
"The file could not be found,
" +
"please check the name and path ");
}
//***Display the file contents
Response.Clear();
Response.Write(
"
| " +
"THE CONTENTS OF THE FILE " + path + " "); var iBreakCounter = 0; for (var ii = 0; ii < sContents.length; ii++) { //***Inserts breaks for legibility iBreakCounter++; if (iBreakCounter > 100) { Response.Write(" "); iBreakCounter = 0; } if (sContents.substr(ii, 1) == "\r") { if (bShowControlChar) {Response.Write("[\\r]");} Response.Write(" "); iBreakCounter = 0; } else if (sContents.substr(ii, 1) == "\n") { if (bShowControlChar) {Response.Write("[\\n]");} } else if (sContents.substr(ii, 1) == "\f") { if (bShowControlChar) {Response.Write("[\\f]");} } else if (sContents.substr(ii, 1) == " ") { Response.Write(" ") } else if (sContents.substr(ii, 1) == "\t") { if (bShowControlChar) {Response.Write("[\\t]");} Response.Write(" ") } else if (sContents.substr(ii, 1) == " ") { Response.Write(" ") } else { Response.Write(Server.HTMLEncode(sContents.substr(ii, 1))); } /* if else */ } /* for */ /*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--* DISPLAY THE SECOND FILE (if any) *--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*/ if (sFileB != null) { path = sFileB; if (fsoFile.FileExists(path)) { fsoObject = fsoFile.OpenTextFile(path); sContents = fsoObject.ReadAll(); } else { fnErrorMessage( "fnDbugFileContents", "sFileB ('" + path + "') ", "The file could not be found, " + "please check the name and path "); } /* if else */ Response.Write( " | " +
"THE CONTENTS OF THE FILE " + path + " "); for (var ii = 0; ii < sContents.length; ii++) { if (sContents.substr(ii, 1) == "\r") { if (bShowControlChar) {Response.Write("[\\r]");} Response.Write(" "); } else if (sContents.substr(ii, 1) == "\n") { if (bShowControlChar) {Response.Write("[\\n]");} } else if (sContents.substr(ii, 1) == "\f") { if (bShowControlChar) {Response.Write("[\\f]");} } else if (sContents.substr(ii, 1) == " ") { Response.Write(" ") } else if (sContents.substr(ii, 1) == "\t") { if (bShowControlChar) {Response.Write("[\\t]");} Response.Write(" ") } else { Response.Write(Server.HTMLEncode(sContents.substr(ii, 1))); } /* if else */ } /* for */ } /* if there is another file */ Response.Write(" |