function writeln(text) { write(text + '\n'); } function emitMainWindow() { writeln(''); writeln(''); writeln(''); writeln(''); } function emitEntryForm() { writeln('
'); writeln('

'); writeln('
'); writeln('Source:'); writeln(' | '); writeln(' | Mode:'); writeln(' | '); writeln(' | '); writeln('
'); writeln('

'); writeln(''); writeln('
'); } function emitBlank() { writeln("
This page intentially left blank
"); } function emitFileContents(request) { var ErrorText = ""; var HexLine = ""; var AscLine = ""; var LineCount = 1; var ByteCount = 1; var Byte = 0; var In; if ((request.source == null) || (request.source == "")) ErrorText += "You must specify a source filename.
"; // Check to see wheter to continue processing, or emit error page. if (ErrorText.length == 0) { write("

    " + request.source.bold() + "\n

") In = new File(request.source); if (request.mode == "Ascii") { if (In.open("r")) { write("\n

    ");
                while (!In.eof()) {
                   AscLine = In.readln();
                   if (!In.eof())
                      write(LPad(LineCount + ": ", 5), AscLine, "\n");
                      LineCount++;
                      flush();
                }
                In.close();
                delete In;
             } else {
                EmitError("Unable to open source file , error #" + In.error());
             }
          } else {
             if (request.mode == "Hex") {
                if (In.open("rb")) {
                   write("\n<plaintext>");
                   while (!In.eof()) {
                      Byte = In.readByte();
                      if (!In.eof()) {
                         HexLine += IntToHex(Byte);
                         AscLine += (((Byte < 32) || (Byte > 127)) ? "." : File.byteToString(Byte));
                         if (ByteCount % 20 == 0) {
                            write(LPad((ByteCount - AscLine.length) + ": ", 8, "0"), HexLine, "    |    ", AscLine, "\n");
                            flush();
                            HexLine = "";
                            AscLine = "";
                         } else {
                            HexLine += " ";
                         }
                         ByteCount++;
                      } else {
                         ByteCount--;
                         if ((HexLine.length > 0) || (AscLine.length > 0))
                            write(LPad((ByteCount - AscLine.length) + ": ", 8, "0"), RPad(HexLine, 59), "    |    ", AscLine, "\n");
                         flush();
                      }
                   }
                   In.close();
                   delete In;
                } else {
                   EmitError("Unable to open source file , error #" + In.error());
                }
             } else {
                EmitError("Must specify Ascii or Hex mode.");
             }
          }
       } else {
          EmitError(ErrorText);
       }
    }

    function viewerMain(request)
    {
       if (request.cmd == "show") {
          emitFileContents(request);
       } else {
          if (request.cmd == "entry") {
             emitEntryForm();
          } else {
             if (request.cmd == "blank") {
                emitBlank();
             } else {
                emitMainWindow();
             }
          }
       }
    }

    viewerMain(request);
    </SERVER>