La capacidad programable de ED se hace mediante lo que se denominan macros, que son el equivalente a un procedimiento en otros lenguajes de programación: una agrupación de instrucciones bajo un nombre que puede invocarse suministrándole parámetros. Las macros no se comportan como funciones, esto es, no pueden devolver ningún valor, pero pueden hacer algo parecido mediante almacenar valores en variables globales, por tanto en cierta manera las macros pueden usarse como funciones.
El lenguaje sí dispone de funciones que procesan una secuencia de números o caracteres, los transforman y devuelven un resultado, como veremos.
Las macros pueden considerarse un lenguaje de programación estructurado, pues, tal como lo definía IBM en 1978, un lenguaje es estructurado si se dan en él las siguientes posibilidades:
La manera de implementar esas estructuras es un tanto básica, pero disponemos de ellas.
Además de eso, ED dispone de instrucciones de dos tipos:
This command instructs @ED¨PC to store and repeatedly execute the commands which follow. It can also execute a loop that has already been stored.
Syntax: LOOP[?.!] [num1[!]] [num2] [num3] where ? if present displays the most recently entered loop. Any other arguments are ignored. ! if present causes the most recently entered loop to be executed. Without ! present, you are prompted for the text of a new loop. [num1] if present is a .numeric expression· denoting the number of times the loop is to repeat. The default is 0. [!] if present after num1 indicates that during this invocation, this loop is not to terminate if it reaches the end of the file being edited. [num2] if present is a numeric expression denoting the starting value to be assigned the internal loop counter. The default is 1. [num3] if present is is a numeric expression denoting the value by which the internal loop counter is incremented after each pass through the loop. The default is 1.
Considerations:
After a LOOP command, and until an . @EOF· control command, all commands are stored in a holding buffer. After the @EOF, the stored commands are executed if a nonzero repeat count (num1) has been specified.
Each active loop is controlled by a repeat counter, a loop counter, and an increment value. When the loop begins, these are set to num1, num2, and num3 respectively.
num1, num2, and num3 are positionally defined arguments. When num2 or num3 are present while num1 or num2 are defaulted, use commas as place holders to ensure that the proper values are used for the desired arguments.
num1 sets the “repeat count”. This is how many (more) times the loop is to repeat. During loop execution, the repeat count can be reset by the .LPX· command.
num2 sets the “loop counter”. @ED¨PC increments this counter for each iteration of the loop. The loop counter value can be obtained at any time by using the .L function· . The loop counter cannot be changed directly; it is altered only by the increment num3 during each loop cycle. In this way it is different from the repeat count set by num1, which can be reset directly during loop execution by the LPX command.
num3 is the increment to be applied to the loop counter at the end of each loop iteration. This may be a numeric expression equal to any positive or negative integer value. If the increment is equal to 1 (the default), the loop counter will contain the exact count of the times the loop has been executed.
Normally LOOPs repeat for the number of times specified by num1 unless they reach end-of-file first. To make a loop continue even though end-of-file is reached, you can use the exclamation mark (!) after num1, or execute the .LPX· command with a negative argument somewhere within the body of the loop.
Loops may be nested; that is, you may use the LOOP command within a LOOP. If you use nested loops, terminate the inner loops with the .LPEND· command, not . @EOF· . @EOF terminates the outer loop, which would force termination of all inner nest levels of the loop. Use @EOF only to terminate the outermost LOOP.
@ED¨PC supports nesting of loops and macros up to 20 deep. Each active loop and macro occupy one nest level. The current nest level or nest depth can be obtained at any time from the .LD· command.
For example, if a loop calls a macro that contains a loop with one nested loop within it, the innermost loop of the macro will execute at a loop nest level of 4.
loop (LD = 1) macro (LD = 2) loop (LD = 3) loop (LD = 4)
A loop may call macros if they are already loaded in .ED$MAC· . However, you cannot define macros within a loop (that is, the .MACRO· command is illegal within a LOOP); and you cannot force an automatic load of a macro from ED$PF within a loop.
You can use the LOOP command within a macro.
Interactive help via the .HELP· command is not available while entering a loop. If you use the HELP command while entering a loop, @ED¨PC simply inserts HELP as a command in the loop. When the loop executes, it displays help. If you press .F1· while entering a loop, you will not see the HELP command on your screen, but HELP is still inserted at that point of the loop text.
This command sets the number of additional times that a loop will iterate.
The LPX command has no effect outside of loops or macros.
Syntax: LPX [num] where num if present is a numeric expression which denotes the number of additional times that the loop is to iterate. If num is 0, no further iterations of the loop will be executed and control will pass to the command following the loop.
Considerations: When num is zero, the current loop iteration will be the last one, but execution of the current loop is not terminated.
Negative values of num cause the loop to continue operating after reaching end-of-file. -1 causes the loop to repeat an infinite number of times. Other negative values set the loop repeat count to the absolute value of num .
LPX resets the “repeat count” of the current loop. This is the value initially set by the num1 argument of the .LOOP· command.
Formato 1: LPTST,count [ expression1 {EQ | GEQ | GTR | LEQ | LSS | NEQ} expression2 ]
Formato 2: LPTST,count [ FIND | NOFIND | ADD | NOTADD ]
Uso: Salta la ejecución de las siguientes count líneas si se cumple la condición
Componentes:
Operadores
Formato 1: LPJUMP Etiqueta
Salta incondicionalmente a la siguiente instruccion a la etiqueta indicada y continua la ejecución de la macro desde ese punto.
Las etiquetas están constituidas por una serie de uno o más caracteres alfanuméricos precedidos de : (dos puntos)
No hay estructura IF-THEN-ELSE, pero con la combinación de las estructiras anteriores se puede simular.
Este seudocódigo contiene una estructura if-then-else Rem? SI o NO if (qu,1,1 eq 'S') { rem! Ha dicho SI else rem! Ha dicho NO } Y esta es la manera de hacerlo en @ED-PC MACRO SN REM? SI o NO LPTST QU,1,1 eq 'S' LPJUMP no REM! Ha dicho SI LPJUMP fin :no REM! Ha dicho NO :fin @EOF
Formato: LPSUB,count filtro_1 [ filtro_2 […filtro_n ] ]
Uso: Transforma las siguientes count líneas de código en la macro según indiquen los filtros
Las transformaciones consistirán en sustituir un determinado caracter por el resultado del filtro
Ahora es posible comparar el resultado de una función con el resultado de otra, y no solamente con un literal, como era el caso en el @ED de Univac. Esto permite usar las macros sin contenido como puras variables alfanuméricas que almacenan su valor en el argumento que se les pasa.
Es decir, que si yo tengo dos macros STR y NOL, y cada una ha sido utilizada como variable para almacenar un valor alfanumérico al invocarla, ahora puedo comparar si los valores almacenados coinciden.
Con las nuevas funciones para proceso de string en sus “tokens” (MP SC y SF) es posible hacer un uso completo de las macros como variables alfanuméricas.
MACRO STR @EOF MACRO NOL @EOF MACRO TST LPTST,2 MA,NOL EQ MA,STR REM! ** VALORES NO COINCIDEN ** LPJUMP FIN REM! ** OK ** :FIN @EOF @ED-PC 2R1 07-29-2004 Thu 11:45:24a (0,1) >0:>STR UNO >0:>NOL DOS >0:>TST ** VALORES NO COINCIDEN ** >0:>
En ED-1100 el segundo parámetro de LPTST debía de ser un literal, por lo que la manera de comparar dos funciones era “indirecta”:
MACRO TST LPSUB MA,$,NOL NLC $ LPSUB MA,$,NLC LPTST,2 MA,STR EQ $ REM! ** VALORES NO COINCIDEN ** LPJUMP FIN REM! ** OK ** :FIN @EOF
EN Environment Variable ET Element Type EX Extension portion of the name being edited M Name of the currently executing macro MA Retrieve Macro Arguments MO Returns the name of a month MP Retrieve Macro Argument Portion, a token NE Returns name and extension of the file being edited NM Returns name portion of the file being edited NN Returns "LN" if current loop or macro was prefixed with LN NX Returns text from the line following the current line P Returns a string containing the current path PN Returns the full path and name of @ED.EXE QU Returns the text of the last response to a REMARK? command SF Returns a specific subfield of a specific field of the arg passed to a specific macro TX Returns the text of the current line WD Returns the name of a day of the week
AL,m Argument Length of last call to macro m CC Column beginning the last change performed by the CHANGE command CT Count of string occurrences found by LOCATE / FIND FC,m Number of FIELDS in argument used in last call to macro m L Loop counter Ln Loop counter at depth n (L0 is outermost loop) LC Column beginning the last string located by LOCATE LD Loop depth of current macro LG Length of current text line LL Number of line containing text that satisfied the last LOCATE / FIND N Current line number PC Number of PARAMETERS (delimited by spaces) in argument to macro m SC,m,n Number of SUBFIELDS (delimited by commas) inside filed n in arg to macro m V Result of last COMP X Variable X XA Variable XA .. XZ Variable XZ
With the exception of the MP and the SF string functions, all the rest can use a pair of extra arguments that indicate the start point and the length of the desired substring.
Format: XX[,num1][,num2][*]
where XX is the name and parameters of a string function num1 is the start point and num2 is the length of the desired substring the optional asterisk indicates that trailing spaces should be removed from the returned value
BLANK LC SPLIT ADD LCHAR STATUS APPEND LIMIT STK ASCII LOCATE TAB AUTO LOOP TCCHAR BOTTOM LPEND TCHAR CASE LPJUMP TIME CC LPSUB TOP CHANGE LPTST TYPE CLC LPX UNDO CLIMIT MACRO UP COMP MAXLINE VERIFY COPY MCCHAR WAIT CSF MOVE WRAP CUC MSCHAR XPC CUT NEXT XTI DELETE OFF @ADD DITTO OMIT @ED DOC ON @EDIT DOS OUTPUT @EOF ED$PF PASTE @@BRKPT EXCHAR PLIMIT @@CONT EXIT PREFIX @@CQUE FC PRINT @@END FIND QUICK @@ESC GOTO READ @@FQUE HELP REMARK @@FRZ IB RETYPE @@INS INLINE RP @@LINES INPUT SCALE @@RLD INSERT SEQ @@RLU JCHAR SET @@SPAWN JOIN SITE @@TERM LAST SPAWN @@X
Any input that has an @ character in its very first column is considered by @ED¨PC to be a control command. Control commands are commands that are always interpreted as commands whether you are in .input mode· or .edit mode· . @ED¨PC recognizes several control commands.
Control commands always begin with one or two @ characters (“AT signs”). Those that begin with @@ are .environmental control commands· . Control commands with only one @ are called regular control commands.
Caution: @ED¨PC interprets any regular (non-environmental) control command that it cannot recognize as the name of another program that is to be executed. Therefore, if you issue a regular control command that @ED¨PC does not recognize, it terminates itself and passes the control command back to the operating system as the name of a program to execute.
If you issue an invalid environmental control command, you will receive an error message but @ED¨PC continues.
Command | Description |
---|---|
@ADD | Submits a file to @ED-PC as series of command or text lines |
@ED | Terminate current edit session and re-use it to edit another file |
@EDIT | Allows to submit edit commands while in input mode or leave input mode |
@EOF | Signals the end of text or command lines (loops, macros and the DOC command) |
Control commands that begin with @@ are called “environmental control commands”. They are used to alter an aspect of the @ED¨PC operating environment, such as how text is displayed on the screen or output redirection from within @ED¨PC. Certain environmental control commands can terminate an @ED¨PC command, .loop· , or .macro· , or @ED¨PC itself.
Environmental control commands are the only commands that are honored after pressing the .PAUSE key· ; all other commands, including regular (one @) .control commands· , are ignored at the PAUSE* prompt.
Command | Description |
---|---|
@@BRKPT | Redirects screen output to a file or device |
@@CONT | Continues the execution of a command, loop or macro after it has been paused |
@@CQUE | Suppress the SOE character and sets a queue for 15 chars of input from keyboard |
@@END | Terminates the effect of some environmental control commands |
@@ESC | Suppresses the scrolling effect on the screen |
@@FQUE | “Friendly Queue” - Same as @@CQUE but doesn't suppress the SOE prompt |
@@FRZ | Freezes a certain number of lines at the top or bottom of the screen |
@@INS | Specifies the line n the screen display where text is to appear |
@@LINES | Dinamically changes the number of lines displayed on some monitors (ussualy 25, 43 or 50) |
@@RLD | Causes the scrolling action of the @ED-PC display to move down |
@@RLU | Causes the scrolling action of the @ED-PC display to move up |
@@SPAWN | Allows the execution of DOS commands from the pause prompt or any other prompt |
@@TERM | Immediately terminates @ED-PC without any message - No changes saved to permanent files |
@@X | Terminates an active @ED-PC process, or @ED-PC itself |
ASCII A ASCII mode. When ON, all character comparisons are case sensitive. When OFF, case is ignored in character comparisons. Can be set by using the Q switch when @ED¨PC is launched. The default is OFF. ON ASCII has the same effect as ASCII ON. OFF ASCII has the same effect as ASCII OFF. BRIEF B BRIEF mode. When ON, CHANGE, FIND, GOTO, LOCATE and many other commands do not display their results after command execution, and FC and LC commands only echo the line numbers satisfying the search argument and not the found text. Can be set by using the N switch when @ED¨PC is launched. Can be cleared by the VERIFY command. The default if OFF. DSPLIT D DSPLIT mode. When ON, text lines transferred by the SPLIT command from the file being edited to another file are deleted. When OFF, transferred lines remain. The default is ON. EOF E EOF mode. When ON, a blank line does not toggle between INPUT and EDIT modes, and @EOF does not terminate @ED¨PC while in input mode but instead performs the INPUT/EDIT mode toggle. This is useful for data entry where blank lines are part of the input. The default is OFF. LSTINP L List-Input mode. When ON, all command and text lines are echoed. Can be set by using the L switch when @ED¨PC is launched. The default is OFF. MEMORY M MEMORY mode. Controls whether user modes are retained when . @ED· ¨PC is reused by the @ED command. When ON, the current set of user modes are retained through the @ED command, except for those modes controlled by switches on the @ED command. When OFF, all user modes are reset to default settings, except for those modes controlled by options on the @ED command. The default if OFF. NUMBER N Number mode. When ON, all displayed text lines are prefixed by their line numbers. The default is OFF. OVERWRITE O Overwrite mode. When ON, the SPLIT command overwrites its target file (if it exists) with the text being extracted from the file being edited. When OFF, the extracted text is appended to the end of the target file (if it exists). The default is ON. QUICK Q Quick mode. When ON, commands that display lines of text (GOTO, CHANGE, LOCATE, etc.) display them with all nonsignificant spaces removed. When OFF, text lines are displayed as they are. The default is OFF. SEQUENCE S Sequence mode. When ON, the @ED¨PC prompt includes the number of the .current line· . The default is ON. TREAD T Type-and-read mode. When ON, @ED¨PC displays a prompt when soliciting user input. When OFF, no prompt is displayed when @ED¨PC is soliciting input. The default is ON. XBRIEF X XBRIEF mode. When ON, text lines transferred by the ADD or SPLIT commands are not displayed. When OFF, text lines transferred by the ADD or SPLIT commands are displayed. The default is OFF.
@ED¨PC provides the .JOIN· and .WRAP· commands for wrapping text between left and right margins defined by the .LIMIT· command.
To set left and right margins for wrapping text, use the LIMIT W command. These margins are honored by the JOIN and WRAP commands. The default left and right margin are 1 and 65 respectively.
If the .current line· extends beyond the right margin, use the WRAP command to move the excess to a new line following. The WRAP command also advances the current line number, so if the newly inserted line is still too long, another WRAP command will shorten it.
If the current line is shorter than the right margin, use the JOIN command to combine the current line with the line following.
By combining these commands inside .loops· or .macros· , intricate word wrap and paragraph structure can be automatically imposed on your text.
The SITE command prints all or part of the file being edited in a report containing page headings and routing information.
Syntax: SITE[!] [column¨limit¨spec] [startline [endline]] [target] where ! if present causes all lines of the file to be output. column¨limit¨spec if present limits the generated output to only the text within the columns specified. column¨limit¨spec must follow the syntax for the .temporary column limits· spec and is enclosed in square brackets. startline and endline if both specified are the numbers of the first and last lines of the block of text to output. startline if specified alone is the number of text lines to output, beginning with the .current line· . If startline is not specified, the entire file is output. target is a DOS device name or file name. If not specified, LPT1: is assumed.
After issuing this command, you are prompted for a heading for the printed output. A second prompt, “MSG”, requests routing information to return the listing to its requestor when printing is at a remote location.
Either a file or a device may be specified as the target for SITE. Consideration: Do not use periods in your SITE heading unless you intend to specify a XPC subfunction. Periods in the SITE heading indicate that .XPC subfunctions· follow.
This command controls the characteristics of the print file produced by the SITE command. XPC can also submit environmental control commands from loops or macros.
Syntax:
XPC subfunction1,arguments[.[subfunction2,arguments] … ]
where subfunction# is the XPC subfunction to be invoked arguments are values as required by the invoked subfunction. . is a separator character to delimit multiple subfunctions
D,ecc ecc is a valid environmental control command. H,,pagenbr, pagenbr is the page number to show in the heading of the next page to be printed. M,pagelen,pagetop,pagebottom,linesperinch pagelen is the number of lines per page. pagetop is the line number where the page body begins. Any heading if specified prints between the top of the page and this line. pagebottom is the number of lines to leave blank at the bottom of the page. The page body ends at page line (pagelen - pagebottom). W,pagewidth pagewidth is the number of characters in the longest line. Characters beyond this column will be output on another
Notes. The first and third arguments of the H parameter are not implemented. Other platforms may implement XPC subfunctions not in @ED¨PC .
Your disk file is not changed while your @ED¨PC edit session is active. Edit work in progress is maintained by @ED¨PC in two working temporary files which are automatically deleted when @ED¨PC ends unless it terminates in error. This helps prevent loss of work and protects your file from being damaged in an edit session gone awry.
Work files are allocated in the .ED$WK subdirectory· .
@ED¨PC uses its work files as follows. As the input file begins being edited, its changed contents are copied to one of the work files. As edits progress the end of the input file is eventually reached, and the input file is closed without having been changed. The first work file is closed and reopened for input; the other work file is opened for output and becomes the working output file. Again, edit work eventually reaches the end of the input working file. The two working files exchange input and output roles and the process repeats until the edits are complete. This has the effect of automatically saving a complete copy of the file being edited every time you reach end-of- file.
Use the .AUTO· command at any time to save a complete copy of the file being edited to a work file, regardless of current end-of-file status.
Commands issued since the most recent time that end-of-file was reached may be undone with the .UNDO· command.
If you .EXIT· or issue a .control command· to leave @ED¨PC, edited text is saved to your target disk file. The target file is not rewritten or otherwise disturbed if no edits were made, if you quit @ED¨PC using the .OMIT· command, or if @ED¨PC is in read-only mode. (On some other platforms, the file is always automatically updated except in read- only mode.)
If an unrecoverable error occurs during access to the work files, the currently executing loop or macro (if any) is terminated. Edits made since the last .AUTO· command or automatic save are discarded because work file integrity can no longer be guaranteed, but @ED¨PC preserves all edits made earlier. Then it enters read-only mode and sets the .current line· to 0 (top of file).
If you .EXIT· or issue a .control command· to leave @ED¨PC after a work file error, and the work file contains changes, the changes will not be committed because you are in read-only mode. @ED¨PC warns when this occurs and sets the EDERR environment variable as described below.
If an error occurs when @ED¨PC is writing the final version of a file, @ED¨PC sets the environment variable EDERR to Y and changes the name of the latest work file to ED$SAV. .Batch files· can test EDERR and if desired copy this file to an available destination. The environment variable .ED$WK· will contain the path for ED$SAV .
See the section about “.Error handling· ” for an example of using EDERR and ED$SAV to invoke recovery from an @ED¨PC error.
The ED$WK subdirectory is the subdirectory where ED$PC will store its temporary .work files· during @ED¨PC execution.
@ED¨PC tries to use the ED$WK environment variable in DOS to determine the name of the ED$WK subdirectory. If the ED$WK environment variable is not set or invalid, the TEMP environment variable determines where the work files are to go. @ED¨PC will also try to use the TMP environment variable if TEMP is not set or invalid. If all these fail, the current subdirectory is used for work files. If even that fails, @ED¨PC will begin in read-only mode, which requires no work files.
Because @ED¨PC creates two work files, the work file directory must have available space equal to about two copies of the file that you will edit, and more (or less) according to how much text will be added (deleted) during the edit session. Proper placement of work files is a key to sastisfactory @ED¨PC performance. On stable systems supplied by reliable power sources, RAM disk is a fast and safe location for @ED¨PC work files. But when system stability is less than ideal, RAM drive data is at risk of unscheduled erasure.
When system stability is not guaranteed, or where file size makes RAM disk impractical for work file storage, cached hard disk drives are a good second choice. Regular hard disks and even floppy disks are acceptable but slower media will make most access times longer.
The user must have write privileges in the ED$WK directory. If a dynamic multiuser environment such as a network or a multi-user DOS denies the use of a ED$WK directory for update purposes during an active @ED¨PC session, data may be lost.
The ED$MAC file is a disk image of macros in @ED¨PC program memory. It contains macros in an internal format. This file is loaded automatically, if available, when @ED¨PC begins execution. During the edit session, if ED$MAC is available for update, its contents are changed to reflect additions and deletions that are made to the macros in program memory.
@ED¨PC “finds” its ED$MAC file as follows. When @ED¨PC is starting, it uses the value of the ED$MAC environment variable (if it is set) as the name of the ED$MAC file to open. If the file cannot be opened no warning is issued and no further attempt to open ED$MAC is made.
If the ED$MAC environment variable is not set, @ED¨PC looks in the following locations, in the order listed, and stops searching as soon as it finds a file named ED$MAC.
If the file is not found in any of these places then no warning is issued and no further attempt to open ED$MAC is made.
When for any reason no ED$MAC file is loaded at @ED¨PC startup, then no macros created during the @ED¨PC session will be saved, and no warning will be issued.
If low .memory· during @ED¨PC startup prohibits loading some or all of ED$MAC from being loaded, one or more warnings are displayed. If ED$MAC could not be loaded in its entirety, ED$MAC will not be updated after macro add or delete operations.
For example, if your ED$MAC file is C:\EDPC\MACRO.WRK, you can use the DOS statement SET ED$MAC=C:\EDPC\MACRO.WRK before launching @ED¨PC.
When @ED¨PC starts, it will find that file and automatically load the macros in it. Furthermore, any macros that you create during your edit session will be saved to this file (if it is available for update) when they are created. Macros loaded from the .ED$PF· subdirectory will also be saved in ED$MAC in this way.
If you want to use an ED$MAC file, the easiest way to begin is to use the starter ED$MAC file, named “ED$MAC”, which is released with @ED¨PC. This file contains several useful and instructive sample macros.
To create a completely new ED$MAC file, simply create a zero-length file by any means you prefer. Or, just delete all your macros from your current ED$MAC file by using the MAC* command for each macro, then start over. (Make a backup of your old ED$MAC file first.)
If you want @ED¨PC to find the file automatically, name it ED$MAC and put it in one of the subdirectories mentioned in the list above.
To call the file something besides ED$MAC or to put it in another location, set the ED$MAC environment variable to the desired value before launching @ED¨PC.
The ED$PF subdirectory is searched for macros by @ED¨PC when the user tries to start a macro that is not already loaded in memory. Macros stored singly in ASCII files can be started automatically by @ED¨PC when stored in the ED$PF subdirectory.
Use the .ED$PF command· to set any subdirectory to be the ED$PF subdirectory. If no ED$PF command has been issued, @ED¨PC uses the ED$PF environment variable in DOS to determine the name of the ED$PF subdirectory. If the ED$PF environment variable is not set, no ED$PF searches are performed until the user issues an ED$PF command.
An ASCII text file that contains a macro must have a one-to-three- character file name and the extension .MAC in order for @ED¨PC to automatically load that file as a macro. The one-to-three-character file is the macro name. @ED¨PC only loads macros from files that conform to this naming rule. Furthermore, @ED¨PC presumes that any file in the ED$PF subdirectory that conforms to this naming rule contains a macro.
When @ED¨PC is searching for a macro, it looks first in program memory (which normally corresponds to .ED$MAC· ). If that search fails, and the object macro was not started from within a loop or another macro, then @ED¨PC examines its ED$PF subdirectory for a file of appropriate name.
When a macro is loaded from ED$PF, it is also copied into ED$MAC unless that file is not available for update.
A macro that is not already in memory cannot be automatically loaded by being called from a loop or macro. A macro is loaded from ED$PF only if it is started directly by the user (that is, by keyboard input or from an . @ADD· file). Once it is loaded, however, it may be started at any time.
@ED¨PC does not automatically update files in the ED$PF subdirectory; only the update to ED$MAC is automatic.
Macros are created, displayed, and deleted by using the .MACRO· command.
Macros can be transient, or they can be stored and used in later edit sessions.
Between edit sessions, macros are stored in files dedicated to that purpose. @ED¨PC uses two methods to store and access macros in files.
In the first method, one or more macros is stored in an internal format in a single file called an .ED$MAC file· . In the second method, each macro is stored as ASCII text in its own file within a subdirectory called the .ED$PF subdirectory· .
The differences between ED$MAC and ED$PF are primarily in how the macros are searched for and started, and in how the macros are maintained.
When the user calls a macro, @ED¨PC searches for the macro in program memory. If the macro is not found there, the ED$PF subdirectory is searched for a file with extension .MAC whose name matches the name of the macro. When a match is found, the macro is read from ED$PF into program memory. (Because macro names are limited to three or fewer characters, names of macro files in ED$PF must also have three or fewer characters.)
The ED$MAC file is a snapshot of the latest macros in @ED¨PC program memory. After @ED¨PC terminates, the ED$MAC file remains, saving the memory image. When @ED¨PC is next executed, it reuses this memory image by loading ED$MAC into @ED¨PC program macro memory.
Under normal single-user conditions, ED$MAC is saved again in its entirety each time a macro is added or deleted in program memory.
In multi-user or .multi-tasking· operations, only one user can update ED$MAC at a time. If user A updates the file when a user B attempts to update it, user B's attempt fails and a second attempt is not made; meanwhile A's update proceeds to normal completion. This is acceptable in typical use because small ED$MAC files are quickly updated while large ED$MAC files are frequently made read-only.
Macros resident in memory take precedence over macros that must be read from disk, therefore macros in ED$MAC will take precedence over execution of macros by the same name in ED$PF.
You can replace a macro in ED$MAC with an updated version from ED$PF by deleting it with MAC*, then starting it. This loads the macro from ED$PF and, because @ED¨PC program memory has been changed, writes a new copy of ED$MAC to disk if possible.
When a macro is called from a loop or a macro, ED$PF is not searched. Only memory resident macros can be started during loop or macro execution.
Maintenance of macros in ED$PF is straightforward. Macro files may be created and modified by any ASCII text editor, including @ED¨PC. By re-using @ED¨PC, you can switch between a file containing a macro and the file which is to be operated upon by the macro. Any file whose extension is .MAC and whose name matches the one-, two- or three- letter name of the macro can be used to store a macro.
Maintenance of macros in ED$MAC is performed by the MACRO command.
Short macros can be entered or re-entered directly from the keyboard.
For loading more complex macros, use the . @ADD· command for single macros, or define the ED$PF subdirectory to access several macros.
Because the two methods store and process macros differently, they lend themselves to different applications. Macros under development are probably better stored as a macro file in the ED$PF subdirectory, because it is easier to change macro source when it is in an ASCII file. Macros that are not likely to change are good candidates for storage in ED$MAC, especially if ED$MAC is made read-only.
This command creates, displays, and deletes macros. Macros are @ED¨PC commands created and named by the user.
Syntax: MACRO[*] macroname MACRO{?.??} [macroname] where if none of *, ?, or ?? are specified, instructs @ED¨PC to create a macro of the specified name . @ED¨PC prompts the user for commands to store in the macro. Macro creation is terminated with . @EOF· . * instructs @ED¨PC to delete the macro having the specified name. ? instructs @ED¨PC to display information about the macros already defined. If macroname is specified, the text of that macro is printed. If no macroname is specified, the names of all macros already defined are displayed. ?? instructs @ED¨PC to display the text of all macros currently defined. Macroname if specified is ignored. macroname is the name of the macro to create or delete or display.
At macro creation, the MACRO command instructs @ED¨PC to store for later execution the commands which follow, and to assign a name to the group of stored commands. All commands appearing after a MACRO command and before an @EOF control command are stored in @ED¨PC program memory by the macro name. After the @EOF, you can use the new macro just like any @ED¨PC command. In other words, by issuing the macro's name as a command, the set of commands stored under that name are executed.
The commands contained within a macro may be any @ED¨PC command except the MACRO command. They may themselves be macros, provided that they are loaded before the calling macro begins execution. Macros cannot be automatically loaded from .ED$PF· when called from a macro or loop.
Because the MACRO command itself is illegal within a loop or macro, macros cannot be defined or deleted within a loop or macro.
Macros (and loops within macros) may be nested up to 20 deep. Each active macro and loop occupies one nest level. The current nest level or nest depth can be obtained at any time from the .LD· function.
For example, if a macro calls a macro that contains a loop with one nested loop within it, the innermost loop of the macro will execute at a loop nest level of 4.
macro (LD = 1) macro (LD = 2) loop (LD = 3) loop (LD = 4)
When .LOOP· commands are used within a macro, each loop nest level counts as a macro nest level. Use the .LPEND· command to terminate LOOPs nested within macros or within other LOOPs. Use @EOF only to terminate the MACRO command.
Considerations: If macroname is the name of a macro already in existence, the new macro will overwrite the old one. When this occurs @ED¨PC does not notify the user. Use this method to change an existing macro.
To change an existing macro, enter the altered text to the MACRO command in the same way you would for a new macro. The MACRO command does not edit existing macros; it only provides a means for overwriting them. For maintenance of complex macros, put the macro text into a macro file and during testing load it from the ED$PF subdirectory.
A convenient way of working on macros is to .nest· @ED¨PC executions using the .DOS· @ED command. For example, if you were to work on macro x, you could do it by using the following commands in an @ED¨PC session:
@ED,U TESTFILE ¨ ¨ input and commands to ¨ prepare text of testfile rem launch "nested" @ED execution DOS @ED,I X.MAC ¨ ¨ input and commands to ¨ prepare text of macro X exit rem back to original @ED session rem delete any copy of macro X now in ED$MAC mac*x rem execute new version of macro x x ¨ ¨ execution of macro x
The nested DOS @ED statement can be reexecuted readily by recalling entries from the .command history· .
Interactive help via the .HELP· command is not available while entering a .macro· . If you use the HELP command while entering a macro, @ED¨PC simply inserts HELP as a command in that macro. When the macro executes, it displays help. If you press .F1· while entering a macro, you will not see the HELP command on your screen, but HELP is still inserted at that point of the macro text.