Thursday, February 02, 2006

[VBScript] CliVE - Command Language Interpreter VBScript Environment

A few years back ZATZ Publishing, in their DominoPower Magazine, published an article entitled Using Python to create a command line interpreter for Notes. Not being that au fait with Python I decided to have a go at doing the same thing in VBScript. CliVE is the result.

CliVE takes the basic CLI mechanism of my previous posting (
[VBScript] CLI Framework) and adds a couple of extra bits: Loading, Saving, and a shorthand for 'WScript.Echo'

First the code supporting the standard header.
Then support for putting script files on the commandline. Files specified on the command line are loaded and interpreted, one after the other.
This is the main interpreter loop.

The aSession array stores each line passed to Evaluate so that a given session's script can be stored.

In the main loop, a prompt is output and input received. The sLine is split into a two element list: the first element being the keyword; the second being all subsequent text.

There are a few keywords starting with a dot. These are peculiar to CliVE:
.quit
.exit
Synonyms for WScript.Quit
.echo
?
Synonyms for WScript.Echo. Unlike other dot commands, the line starting with this command is passed to the Evaluate function.
.save
Saves the contents of the aSession array to SaveClive.clive unless a filename is given as an argument.
.run
.load
Reads the filename given in the argument and executes the code therein by passing it to ExecuteGlobal.
.debug
An empty procedure. A place to put test code.
All other commands are treated as VBScript commands and are passed to the Evaluate subroutine.
Evaluate, Save, LoadRun and Debug.

Note that the code for Evaluate traps errors, and displays an error message. Note also that LoadRun has no such protection. It's something one might want to add ASAP!

Note also the call to AAdd, which adds the evaluated command to the aSession array if the command works without error.
Rather than reproduce the entire StandardLibrary (1500+ lines), here are the referenced routines (AAdd, Exists, ReadFile, WriteFile), plus supporting symbols.

1 comment:

GIS Services said...

Thanks for sharing..
regards
Orthophotography services