The ScriptEase Processor

This chapter describes the ScriptEase program, how it interprets ScriptEase code, and the various methods for using ScriptEase to launch scripts.

The ScriptEase processor is the engine that reads, interprets, and executes a ScriptEase script. There is a different version of the processor for each operating system that ScriptEase supports. Each version interprets ScriptEase code in a manner appropriate to its operating system; for example, the Directory() function parses a DOS directory slightly differently that a UNIX directory because of the differences in the operating systems involved; however, the end result to the user is the same.

The ScriptEase processor contains the defined values and functions listed in this manual. You do not need to #include any files to use these functions. Each version of the ScriptEase processor has four internal libraries: the standard, extended and professional ScriptEase libraries are common to all versions of ScriptEase; and an operating system specific library that is different for each version. For a full list of the available functions, consult the chapter on The Standard ScriptEase Library.

ScriptEase is the generic term for the different versions of ScriptEase. For DOS, the ScriptEase executable is SEDOS.EXE or SEDOS32.EXE. For Windows it is SEWIN16.EXE, OS/2 is SEOS2.EXE, the Windows `95 and NT Console version is SECon32.exe, and the Windows `95 and NT GUI version is CEnviW32.exe. Although most of the examples in this chapter would work in any version of ScriptEase, SEDOS.EXE will be often be used in examples. For a different operating system substitute the ScriptEase executable name for that operating system (e.g., SEOS2.EXE, SEWIN16.EXE, etc...).

The CMMPATH

This environment variable affects where ScriptEase looks for .cmm source files and library files. When looking for files, ScriptEase uses the following rule. First look in the current directory, then the directory that contains the ScriptEase executable, followed by the directories specified by the CMMPATH variable, and finally the directories specified by the PATH environment variable. The CMMPATH variable is like the PATH variable. The CMMPATH is used exclusively by ScriptEase and lists the directories where ScriptEase scripts and libraries are stored. This keeps your PATH variable shorter and more manageable. The only exception to this rule is in ScriptEase for Windows. The CMMPATH profile value in win.ini (in Windows 3.x) or the Registry key for ScriptEase (in Windows 95 and NT) is checked after the current directory in the above scheme.

Environment variables

Operating systems that do not allow ScriptEase to directly modify environment variables (such as Windows `95 and `NT, and OS/2) have an additional environment variable, CENVI_ESET, that is used to store the name of a file for writing information for changing the system's environment variables indirectly.

CMMPATH :

This environment variable specifies a search path specific to ScriptEase.

PATH :

This environment variable is used by ScriptEase, and other application to search for files that are not in the current directory.

CENVI_ESET :

This environment variable points to the file ScriptEase will use to write the strings necessary for the command interpreter to set environment variables as altered by your ScriptEase code. See the description of ESet() for more information about this command.

The ScriptEase Shell

When any version of ScriptEase is run without command line arguments, the user is placed in a ScriptEase shell. The exception to this rule is ScriptEase for UNIX (see below). In the shell, ScriptEase scripts can be run as command line utilities. As an added bonus, other applications can be launched from the ScriptEase shell. For the Windows version this gives you a Windows command-line that looks similar to a DOS box, but also lets you launch Windows applications.

To exit the ScriptEase Shell, type EXIT at the shell command line. For windowed interfaces, you can exit by using the pulldown system menu.

The Windows and Windows NT versions of the ScriptEase Shell allow their look and feel to be customized. To control the color, font, and size of the ScriptEase Shell, use the pulldown system menu.

In UNIX there is no ScriptEase shell; if ScriptEase is run without command line arguments, the processor will read and execute lines from stdin until an end-of-file is reached.

Shell File Redirections (<, >, >>, and |)

The input and output of commands executed from the ScriptEase Shell may be redirected from or to a file with the redirection operators.

<

To redirect standard input from a file, instead of taking input from the keyboard, use the "<" redirection operator, as in

 

sort < C:\LIST.TXT

>

To redirect output to a file, instead of to the screen, use the ">" redirection operator, as in

 

DIR > C:\DIR.LST

Any data that is in C:\DIR.LST will be overwritten with this command. If you want to add data to the end of the file while keeping the file contents intact, use the `>>' operator (described below).

Input and output redirection may be combined in the same command. You can redirect output to a file that does not exist; in such a case, the file will be created. The following example would make the SORT program (whether SORT.EXE or SORT.CMM) take input from the C:\LIST.TXT file and send its output to C:\DIRSORT.LST:

SORT < C:\LIST.TXT > C:\DIRSORT.LST

To redirect output and append that output to a file, instead of to the screen, use the ">>" redirection operator. This operator is similar to the ">" redirection operator except that it will append the output to the specified file if that file already exists. Example:

DIR >> C:\DIR.LST

To use the standard output of one program as the standard input of another program, use the "|" pipe redirection operator (this is often the shifted character above the backslash key "\"). In the following example, the output of the DIR command will be used as the input of the SORT command, which will then be redirected into the C:\DIRSORT.LST file:

DIR | SORT > C:\DIRSORT.LST

AUTOLOAD.CMM

When the ScriptEase shell starts, it loads the AUTOLOAD.CMM, AUTOEXEC.CMM, and SHELLCHR.CMM (if found). These files modify and extend to the ScriptEase shell. Extensions are implemented through the ShellFilterCommand() and ShellFilterCharacter() hooks (see the chapter on ScriptEase standard library extensions for descriptions of these two functions).

Here are some of the features implemented via the AUTOLOAD.CMM that is shipping with ScriptEase. To see a complete list of the shell commands, type "help" at the command prompt. For an explanation of a command, type "help command" where command is the name of the command you want help on.

HISTORY : Using the up and down arrows, you can scroll through the history of commands that have already been entered in that ScriptEase shell

CD, CHDIR, TYPE, CLS : These familiar commands are implemented within AUTOLOAD.CMM (in some operating systems these commands are passed to the default command processor)

TAB : You can use the tab key to complete directory names while in the ScriptEase shell. For example, if you are at the CD prompt, and you have a directory called "documents", you can type CD D and then hit the tab key. ScriptEase will search the directory for a subdirectory beginning with the letters you typed and complete the name for you. Note that if you also had a directory called "dinosaurs" you would be shown that instead, since `dinosaurs' comes alphabetically before `documents.' You could avoid this problem by entering CD DO before hitting the tab key, or by hitting the tab key twice to get to the second subdirectory beginning with `D'.

! : The exclamation point can be used with commands the same way the tab key can be used with directories. If you enter "!h", the processor will execute the last command given it that begins with `h'.

!! : This will repeat the last command you entered.

START : In operating systems that support multitasking, START is used run another program and return immediately to the ScriptEase shell before waiting for the other program to complete execution. To launch an application and then return to the ScriptEase shell immediately, enter the START command in front of the application name. For example, to start the Windows notepad as a separate process from the ScriptEase shell, type the following:

START NOTEPAD.EXE

Separate processes can only be started in operating systems that support multitasking such as Windows (all flavors) and OS/2. Another form of the START command is to put an ampersand after the call to the process:

NOTEPAD.EXE &

IMPLICIT CD : if you enter the name of a subdirectory or a path to a subdirectory on the ScriptEase shell prompt, ScriptEase will automatically change to that directory. The change directory command (CD) is optional; however, you must have a valid path for the directory to change to.

Running a ScriptEase script

There are three basic ways to execute a ScriptEase script: from a command line (either the operating system's or the ScriptEase shell's), by double clicking on a script's icon, or from within a batch file. The one you use will depend on your operating system, the task you're trying to accomplish, and your personal work habits.

Running a script from a command line

You can run a script directly from the command line, either from your operating system's command line or from the command line of the ScriptEase shell. For example, to run the script "scriptx22.cmm" from the DOS prompt, enter

SEDOS.exe scriptx22.cmm

followed by any parameters you are passing it. If you are working in the ScriptEase shell, you do not need to put the executable name, or include the .cmm extension. These are assumed, and all you need to run a script from the ScriptEase shell's prompt is the name of the script and the parameters being passed it.

Programs and Cmm scripts launched from the ScriptEase Shell are known as child processes. The ScriptEase Shell becomes inactive until the launched program is done executing. At that point, control returns to the ScriptEase Shell.

Very brief bits of ScriptEase code can be launched directly from a command line without being saved as a .cmm file first. The code must be enclosed in quotes. For example, the phrase "Hello, world!" can be printed with the following command:

SEDOS.exe "printf(\"Hello, world!\")"

This command will print "Hello, world!" ten times:

SEDOS.exe "for (i=0;i<10;i++) printf(`Hello, world!`);"

All statements in the code that appear surrounded by quotation marks must either use back-ticks or escape the quotation marks (by preceeding them with a `\' symbol) so the processor can distinguish interior quotes from exterior ones.

Remember that in DOS `%' has a special meaning for the batch file processor, so if you call the ScriptEase engine directly from a DOS batch file, you must escape any `%' symbols. For example, the following line:

SEDOS.exe "for (i=0;i<10;i++) printf(\"%d\n\", i)"

must be written

SEDOS.exe "for (i=0;i<10;i++) printf(\"%%d\n\", i)"

to prevent the batch processor from misinterpreting the `%' symbol.

Running a script by double-clicking its icon

You can launch a ScriptEase script by double clicking on its icon in operating systems that use this method. When you install a version of ScriptEase for such an operating system, the installer will create the association between .cmm files and ScriptEase. You cannot pass parameters to scripts with this method.

Running a script from a batch file

ScriptEase can be incorporated into batch files, REXX files, and .cmd files by including commands to tell the operating system that the script (or just certain sections of it) are to be handled by the ScriptEase processor instead of the operating system.

To run code from within a batch file, put the label ":GOTO SE_EXIT" where you want the processor to take over running the script, and ":SE_EXIT" where you want the operating system to resume control. The following example will print a table of printable characters and their ASCII key code:

:GOTO SE_EXIT

#define ROW_COUNT 20

#define COL_COUNT 13

Unprintables = "\a\b\t\r\n\032\033"

for ( row = 0; row < ROW_COUNT; row++ ) {

for ( col = 0; col < COL_COUNT; col++ ) {

c = ROW_COUNT*col + row

if c < 256

printf("%c-%-3d ",(NULL==strchr(Unprintables,c))?c:'.',c)

}

printf("\n")

}

 

:SE_EXIT

These two lines serve as labels, identifying where the ScriptEase processor is meant to take over and where it is to return control to the batch processor.

#! (for UNIX)

The ScriptEase processor for UNIX allows you to direct an external processor to handle execution of a batch file. The command `#!', followed by the full path and name of the processor, directs the computer to let the processor handle all subsequent code.

#! /usr/local/bin/se

printf("Hello, world!");

EXTPROC: *.CMD source file (for OS/2)

Under the OS/2 ScriptEase processor you can define an external processor to process a batch (*.cmd) file if the first statement is EXTPROC. EXTPROC is followed by one-and-only-one space and then the name of the processor, which in this case will be "SEOS2". This is an example file, ARGS.CMD, of a program to display all input parameters:

EXTPROC SEOS2

 

main(argc,argv)

{

r ( i = 0; i < argc; i++ )

intf("Input argument %d = \%s\n",i,argv[i]);

}

Running a script from a REXX-File (For OS/2)

Similar to running ScriptEase from a batch file described above, if the first argument to ScriptEase is the name of a REXX source file, then ScriptEase automatically executes the code between "SIGNALSE_EXIT" and "SE_EXIT:". This REXX file for OS/2 behaves the same as the previous batch program example (CEnviSet.cmd is an OS/2 batch file that helps run Cmm files if environment variables need to be altered--see ESet in the OS2Lib appendix):

/***************************************************************

** SUM.CMD - Use ScriptEase to sum lots of numbers together, **

** setting the SUM environment variable to the **

** value of the final sum. **

****************************************************************/

`call SESet %0.cmd %1 %2 %3 %4 %5 %6 %7 %8 %9'

SIGNAL SE_EXIT

main(argc,argv)

{

SUM = 0;

for ( i = 1; i < argc; i++ )

SUM += atoi(argv[i])

}

SE_EXIT:

/BIND = Create Stand-Alone Cmm Executables

The ScriptEase /BIND option lets you create stand-alone executables from ScriptEase code. The result of /BIND is a binary executable file that operates the same as if ScriptEase were invoked as an interpreter. ScriptEase.exe is not needed to execute the bound file, because ScriptEase.exe and your Cmm code are bound together in the created executable. For information on distribution of bound Cmm scripts contact Nombas.

The following line creates an executable named HELLOW.EXE that would print "Hello world!".

SEDOS /BIND=HELLOW printf("Hello world!");

As another example, you could create a stand-alone editor, which we'll call CMMEDIT.EXE, from the result of the ScriptEase tutorial with the following command:

SEDOS /BIND=CMMEDIT.EXE CMMEDIT.CMM

Now running "CMMEDIT.EXE C:\AUTOEXEC.BAT" from the command line would be identical to executing "SEDOS.EXE CMMEDIT.CMM C:\AUTOEXEC.BAT."

/BIND for OS/2 and SEOS2PM.EXE

When you /BIND Cmm source code that contains calls to PMDynamicLink(), or other PMxxx() calls that invoke SEOS2PM.exe, the resulting executable will still require SEOS2PM.exe. Users running the bound executable will still need SEOS2PM.exe in a directory in their search path. SEOS2PM.exe may be distributed royalty-free.