!TITLE EMAS-3 Command Language - ECL (Preliminary version of User Note 81, 15 Mar 88) Any comments to Tony Gibbons please. ! filename for example Command:analyse a* > xa produces an analysis of all files whose names begin with a in file xa. Similarly, if a command normally reads data from the terminal, it can instead be made to read it from a file. To do this the command is followed by < filename for example Command:edit a < com applies the editing commands in file com to file a. Both forms may be combined, for example Command:edit a > xa < com applies the commands in file com to the file a with output to file xa. Use of ECL Statements --------------------- The ECL statements described below may be used at the terminal, in an obey file, in a batch job and within an ECL procedure. The sole exception to this is that control statements, i.e. cycle ... repeat and if ... else ... fi, cannot be used directly at the terminal. Action after an Error --------------------- If a command fails, that is, sets the return code non zero, the default action is to print an error message and continue with the next command. A different action can be specified by setting an ECL variable erroraction to the command to be executed. For example erroraction = 'stop' or erroraction = 'files p*' The default action is restored by setting erroraction to zero or a null string. !> ! variable (substring) variable For example, if the variable date has the value 08/01/87 then the following resolutions would succeed: Command:date -> day ('/') rest Command:date -> day ('/') Command:date -> day ('/') month ('/') year The value of an expression is displayed with Command:say expression (giving a simple calculator facility). If you wish to send control characters to the terminal (see function pos below) then saychs should be used. The values of all variables are given with Command:monitor !> !, is equivalent to imp s.util01,y.util Substitution never fails. If the text inside the brackets is not the name of a variable, no substitution is done. Thus, given the assignments above, imp , becomes imp ,y.util The only restriction on the use of substitution is that the command names in control statements cannot be substituted, specifically: IF, UNLESS, ELSE, FI, CYCLE, REPEAT, EXIT, CONTINUE and FOR. !> ! !s,y,l xref l,x list l+x,.lp end and the call would have the form Command:com conn The first parameter in emas3string is a PAM vector with fields prompt;qualifier;default;help For example emas3string "Input;file;?;the file containing the data", inf Values for integer and long real parameters are obtained with emas3integer and emas3longreal respectively. !> !.p1)* e ++++ Alternatively, a command may take the first part of its data, modified by substitution, from the procedure definition and the remainder from the interactive terminal, by replacing the '++++' by '....', for example: recall ---- m-/**** LOG-ON/ .... !> !) on one row, initially the first row. Flag is zero for success. Example emas3 window(1, "files(a*)", 0, 19, 0, 18, 0, flag) creates window 1 containing names of files beginning with 'a'. They are displayed in groups of 20 in lines 0-19. A cursor is displayed in column 0 and the (first part of the) name of each file is displayed in columns 1-18. !> ! ! ! ! !> ! --- --> pop --- --- --- queue --> --- hide adjusts the start and end of data pointers in the file header so that the stack file appears to be empty. Reveal resets them. exec does an 'obeyfile' on the stack with output optionally directed to the file given as parameter. !> ! ! ! ! ! !> !,t#junk ---- i/Occurrences of in / s ( m..u1 )* d-* e ++++ send t#junk end Example2 procedure types /* This procedure scans through a set of files and reports their /* filetype. If a group or a PD file is encountered, the procedure /* is called recursively to determine the types of the members. emas3string "Pattern;any,verbatim,nowild", pat say pat+newline for 'files('+pat+')' file = next type = filetype(file) say file - type + newline type = 0 if type = 6 if type = 0 types fi repeat end Example3 procedure wordcount /* This is a simple 'word' counting procedure emas3string "File;file,char,exist", file words = 0 for 'lines('+file+')' a=next /* a is now a line of the file cycle words = words + 1 /* assume at least one word per line repeat if a -> (' ') a /* chop off a word repeat /* to end of file say 'Number of words in' - file - 'is' - words + newline end Example4 procedure browse /* this procedure allows you to browse through a set of /* files and issue commands to examine them cycle /* outer cycle to get a pattern emas3string "Pattern;literal", pat return if pat = 'q' emas3clearscreen specifier = 'files('+pat+')' emas3window 1,specifier,0,19,0,18,0,flag /* down the LHS of the screen cycle saychs pos(22,0)+vdus(3) /* 'vdus(3)' is 'clear to end of line' emas3string "Now?;literal;;", x exit if x = 'q' if x = '' /* press 'return' to move cursor down in window 1 emas3movecursor 1,'d',flag continue fi if x = '-' /* - takes it up again emas3movecursor 1, 'u',flag continue fi if x='>' /* down on window 2, to get the next screen full emas3movecursor 2,'d',flag continue fi if x = '<' emas3movecursor 2,'u',flag continue fi emas3getlinefromwindow 1,s,flag /* referenced by the cursor if x -> left ('@') right x = left + s + right /* replace @ by filename else /* append filename unless 'command' includes a sp unless x -> (' ') x = x - s fi fi unless x -> x (' ') s then s = '' > T#X /* obey command with output to file T#X specifier = 'lines(t#x)' emas3window 2, specifier,0,19,20,79,-1,flag /* display output in window 2 repeat repeat end !>