Friday, December 25, 2009

Batch MS DOS ASCII to Web Converter Script

A little script that converts MS DOS ASCII files, such as NFO's  or FILE_ID.DIZ text files (Code Page 437, USA) to Unicode  and HTML encoded files that can be used to display the ASCII art, specifically the "High ASCII" or block ASCII art on a web site. The script is written in VBScript, but the release package also includes a Windows executable, which is the VBScript converted via VBSEdit by Adersoft.

I used the same script to prepare the ASCIIs in my text art galleries on my web site, such as:

just to name a few.

NOTE: An Updated Version of the Script is also available now!

You can download the script here:   ROY-BATCHCONVERT-ASCII2WEB.ZIP (555 KB)

For example the top logo of this NFO file, which is in DOS ASCII Format and looks like this:

───────── ▄ ▄▄▄▄ ▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄ ▄ ▄▄▄ ▄ ▄▄▄ ▄▄▄▄▄ ▄ ─────────
·R·E·L·.· ▄ ▄▄▄▄ ▀▀▀▀▀▀███ ▀▀▀▀▀▀▀▀███ █ ███ ▀ ███ ▄▄▄▄ ▄ ·2·0·0·9·
─────────── ▄ ▄▄▄ ███ ▄▄██▀ █ ███ █ ███ █▄ ▀▀▀▀▀███ ▄▄▄ ▄ ───────────
▄▄ ███ ▄ ███ █ ███▄▄▄▄▄▄▄▄ ▄▄▄▄▄███ ▄▄
▀▀▀ ███ ▀ ▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀

would be converted to the following;

───────── ▄ ▄▄▄▄ ▄▄▄▄▄▄▄▄▄   ▄▄▄▄▄▄▄▄▄  ▄ ▄▄▄ ▄ ▄▄▄ ▄▄▄▄▄ ▄ ─────────
·R·E·L·.·  ▄ ▄▄▄▄ ▀▀▀▀▀▀███ ▀▀▀▀▀▀▀▀███ █ ███ ▀ ███ ▄▄▄▄ ▄  ·2·0·0·9·
─────────── ▄ ▄▄▄ ███ ▄▄██▀ █ ███ █ ███ █▄ ▀▀▀▀▀███ ▄▄▄ ▄ ───────────
               ▄▄ ███ ▄ ███ █ ███▄▄▄▄▄▄▄▄  ▄▄▄▄▄███ ▄▄
                  ▀▀▀   ███ ▀  ▀▀▀▀▀▀▀▀▀  ▀▀▀▀▀▀▀▀

Note: I included the release ZIP archive are the files roy.asc and roy.web as examples also.

It would look just like the ASCII above the blue code, if you use it properly in your HTML page.

The Web encoded ASCII does not include <BR> Tags for the line-breaks. You have to add those manually or do what I do on my web site and enclose the code in <PRE> </PRE> tags, which preserves the line-breaks within the enclosed text.

Since the result is Unicode and not DOS ASCII anymore, you can use any mono-space font to display the ASCII somewhat correctly. You won't get a 100% accurate result anyway, because the old MS DOS font set is not part of Windows anymore. What you can get is only a close approximation. I use on my web site the font "Lucida Console", which seems to be installed on many machines. If the Windows of the user who visits your page with the ASCII for example does not have that font installed, Windows will automatically pick another font that comes close. I use the following CSS formatting for the PRE tags where I show ASCIIs. 


   1: pre {
   2:    background-color:#000;
   3:    color:#FFF;
   4:    display:block;
   5:    font-family:"Lucida Console", monospace;
   6:    font-size:9pt;
   7:    line-height:12px;
   8:    padding:10px;
   9:    text-align:left;
  10:  } 

If the PRE Tag is also used for something else on your web site then you can also define it for a specific class selector like

   1: pre.asciiart {
   2: ...
   3: } 

You would then also have to extend the PRE HTML tag like this:

   1: <PRE class=asciiart>
   2: ...
   3: </PRE> 

The script is designed to convert all files with a specified extension (.ASC by default) to web ready files with a new extension (.WEB by default, but you could also make it .HTML or whatever).

There are two additional options, where I recommend to use the defaults (which is "yes").

The first one is "Sanitize?"

What that does, is removing ASCII characters with an ASCII code smaller than 32, which are special control characters that cannot be printed anyway, with 3 exceptions, chr(10) = line-feed, chr(13) = carriage-return and chr(9) = tab. LF and CR remain unchanged. Tab characters will be converted to 8 spaces, which is the default MS DOS tab-stop.

The second option is "HTML Encode?", which means that all non-US-ASCII characters (the 7 bit ASCII codes) will be converted to HTML codes like &#XXX;. Also standard ASCII characters that could be misinterpreted by HTML or DHTML and XML are also encoded, like the " becomes &quot;, & becomes &amp;, < becomes &lt; and > becomes &gt; etc.

Part of this package is the image "Batch-ASCII-2-Web-Steps.jpg", which shows screenshots of all the steps where the script goes through.

You can download the script here:   ROY-BATCHCONVERT-ASCII2WEB.ZIP (555 KB)


You can download the script here:   ROY-BATCHCONVERT-ASCII2WEB.ZIP (555 KB)

Carsten aka Roy/SAC

PS. This script is freeware. Do with it whatever you like, except selling it. You can use it free, copy it, share it, even modify it if you like to. You are using it at your own risk. You cannot make me liable for any damage or loss of data that might results directly or indirectly because of the use of my script.


No comments:

Post a Comment

Hi, thanks for taking the time to comment at my blog.

Due to spam issues comments are not immediately posted on the site and require my manual approval first, before they become visible.

I try to approve comments as quickly as possible and usually within 24 hours.

To be notified about follow up comments that are made after yours, use the subscribe option with your email address and you will receive an email alert, if somebody else comments at this post in the future.

Also check out the rest of the website beyond this blog, visit Also see my YouTube channels, SACReleases for intros and demos.

Carsten aka Roy/SAC

Note: Only a member of this blog may post a comment.