Introduction to Mesa 2 Macros, Part III

Presented by Rollin White
Vice President, Sundial Systems Corporation


Overview

From this lesson forward, our macros will start to do more and more. When you look at the sample macros, you'll notice that 90% of macro is really a traditional REXX program with the other 10% serving as the glue that connects the program to Mesa. Generally we'll focus on the 10% that relates to Mesa, but you should also look at the other 90% because it will give you ideas about the types of things that you can do with Mesa 2 and macros.

In this lesson we have another departure. In the past we've looked at macros that do typical spreadsheet tasks. In this example we'll tackle a problem not usually associated with a spreadsheet for the purposes of demonstrating some of Mesa's formatting capability through macros.

This example will read and analyze your CONFIG.SYS file. It will group the different types of statements onto different layers of the spreadsheet. It will also do some elementary formatting of those layers.


A Dose of REXX

This example has a lot more REXX than our previous examples. That is because this macro actually does something more than just taking data from location X and putting it into location Y.

Here are a few comments about new REXX concepts used in this example:


The Main Program

Here is the basic part of our main program:

REXX Code Comments
File = 'D:\Config.Sys' This line simply identifies which file we wish to analyze.
SetList.0 = 0 DeviceList.0 = 0 BaseDevList.0 = 0 OtherList.0 = 0 RemList.0 = 0 These lines initialize our lists to be empty.
call ParseConfig call DisplayBaseDev call DisplayDevice call DisplaySet call DisplayOther call DisplayRem This third group calls subroutines to first read in the CONFIG.SYS file and then put the results into the appropriate layer of the spreadsheet.
return 0 This ends the function of the subroutine.
If you're interested you should look at the details of ParseConfig since it does most of the work of the program. Each of the Display routines are fairly similar with slight variations depending on the type of data that they are displaying.


DisplayBaseDev

Each of the Display functions are very similar. First they clear the layer, loop through the list and put the contents in the spreadsheet, and then format the column headers. Let's take a look at the first one of them: DisplayBaseDev: Layer = '[BaseDev]' call CLEAR "Contents" /* Setup titles */ call PUTC 'Driver name', Layer'A1' call PUTC 'Parameters', Layer'B1' do i = 1 to BaseDevList.0 PARSE VAR BaseDevList.i Driver Parameters call PUTC Drive, Layer'A'i+1 call PUTC Parameters, Layer'B'i+1 end call FormatHeader Layer'A1:B1' return 0 We start by putting the name of the layer into a variable named Layer so that we can use it throughout our subroutine. We call the Mesa 2 function CLEAR to remove the contents of the layer. Next, we put the titles into the first row of columns A and B.

Our loop is the meat of the subroutine. Let's translate it into English line by line:

do i = 1 to BaseDevList.0 This will create a variable i, initialize it to 1, and then execute the loop once. After executing the loop, it will increase the value of i and repeat the procedure until the value of i is equal to the number of items in the list BaseDevList. In plain English, "do the following once for each item in the list". PARSE VAR BaseDevList.i Driver Parameters The PARSE VAR command will take the text in BaseDevList.i (the current item in the list), and break it into two parts. The first part is put into the variable named Driver, and the second part is placed in the variable Parameters. call PUTC Drive, Layer'A'i+1 We're familiar with the PUTC function, but you may be confused by the syntax at the end of the line. REXX will concatenate variables when you place them next to each other. The first part will be the layer name stored in the Layer variable. The second part is the text A, and the third part is the current value of i plus one. We use one more than i, because our titles start on the first row. So, we want the first item in our list to be in A2, the second in A3, and so on. call PUTC Parameters, Layer'B'i+1 This line functions identically to the previous line except that column B is used instead of Column A. call FormatHeader Layer'A1:B1' Now that we're done with the loop, the last line calls the FormatHeader function. A parameter is created that is the range we want to format. We do that because some of our layers will have one column, others will have two. By passing the range as a parameter, we can use the same subroutine for both cases.


FormatHeader

The FormatHeader subroutine is straight-forward, but uses a few new Mesa 2 functions. FormatHeader: PARSE ARG Range call SETFONTATTRIBUTE "BOLD", Range call SETFONTATTRIBUTE "LARGER", Range call SETALIGNMENT "CENTER", Range call SIZECOL "SMART",Range return 0 Mesa has a number of formatting functions. Let's look at the three we're using for this subroutine: It's important to note that we've sized the columns last because the font changes might make the text big enough that the column width needs to be increased.


See for Yourself

The spreadsheet CfgSys.M2 includes the complete macro as well as the structured spreadsheet that the macro requires. Just change the File = statement at the beginning of the macro to refer to your CONFIG.SYS and run it for yourself.

A complete examination of this macro (mmacro3b.htm) is also provided so that you can work your way, line-by-line, through it at your leisure.