Google
 

Trailing-Edge - PDP-10 Archives - decuslib20-04 - decus/20-0135/comp/sscan.sim
There are 7 other files named sscan.sim in the archive. Click here to see a list.
OPTIONS(/E/C);
!
Integer procedure SSCAN will identify specified KEYs in a COMMAND text
string. SCAN performs - in order -
1. Does COMPRESS and storbokstav on the COMMAND string
2. If the parm. DEFAULTKEY belongs to [1:N] and COMMAND string does
   not start with the text KEY[DEFAULTKEY] then that key will
   be assumed present in front of COMMAND.
3. Locates (in order 1 to N) possible occurrences of the texts
   defined in text array KEY[1:N].
4. Makes ARG[x] :- whatever follows KEY[x] up to next KEY.
   If the KEY is just present, but with no text following
   then Blanks(1) is returned. Nonpresent KEY is indicated
   with ARG[x] == NOTEXT.
5. SCAN returns index for multiple used key in command string.
   Thus, normally SCAN should return zero, indicating no
   multiple used key.

Differences between SCAN and SSCAN:

a. SCAN makes fields not given to NOTEXT, SSCAN leaves them
   untouched.
b. SSCAN uses "storbokstav" instead of "upcase". This does not
   matter usually for english commands, but is better for
   swedish commands.

Note that the contents of KEY must have Upper case letters only.
An example:
!       BEGIN
!           EXTERNAL TEXT PROCEDURE conc,storbokstav,compress,
!           rest,inline,checkextension;
!           EXTERNAL CHARACTER PROCEDURE findtrigger;
!           EXTERNAL INTEGER PROCEDURE search,scanint,scan;
!           EXTERNAL REF (Infile) PROCEDURE findinfile;
!           EXTERNAL REF (Outfile) PROCEDURE findoutfile;
!
!           TEXT ARRAY key,arg,default[1:6];
!           TEXT command,infilename,outfilename;
!           INTEGER avalue,index;
!           BOOLEAN na,nb;
!           REF (Infile) inf;
!           REF (Outfile) outf;
!
!           key[1]:- Copy("/DEFAULT:/A:/NA/NB/N=");
!           ! Save some space with this trick!;
!           key[2]:- key[1].Sub(10,3);  !/A: ;
!           key[3]:- key[1].Sub(13,3);  !/NA ;
!           key[4]:- key[1].Sub(16,3);  !/NB ;
!           ! This keyword (5) must come after /NA and /NB
!           ! else it will swamp those keys (if present);
!           key[5]:- key[1].Sub(19,2);  !/N  ;
!           key[6]:- key[1].Sub(21,1);  !=   ;
!           key[1]:- key[1].Sub(1,9);   !/DEFAULT: ;
!
!           start:
!           FOR index:= sscan(inline("*",Sysin),6,arg,key,1)
!           WHILE index NE 0 DO
!           BEGIN   Outtext("? Keyword:");
!               Outtext(key[index]);
!               Outtext(" used more than once. Please try again.");
!               Outimage;
!           END loop;
!
!           ! Analyze result:;
!           ! Assume the user entered: abc=def/A:12/N  ;
!           ! The result will then be:
!           ! arg[1] = "ABC"
!           ! arg[2] = "12"
!           ! arg[3] == NOTEXT
!           ! arg[4] == NOTEXT
!           ! arg[5] = " "
!           ! arg[6] = "DEF"
!           ;
!
!           ! Test file information;
!           ! Default inputname is outputname;
!           IF arg[6] == NOTEXT THEN arg[6]:- arg[1];
!           infilename:- arg[6];
!
!           ! We also demonstrate a way of checking
!           ! entered file specifications;
!           IF infilename NE "TTY:" THEN
!           BEGIN
!               infilename:-
!               checkextension(infilename,".EXT");
!               FOR inf:- findinfile(infilename) WHILE
!               inf == NONE DO
!               BEGIN   Outtext("? Cannot find Infile:");
!                   Outtext(infilename);
!                   Outimage;
!                   infilename:-
!                   inline("Enter name of infile:",Sysin);
!                   infilename:-
!                   checkextension(infilename,".EXT");
!               END loop;
!           END not TTY ELSE
!           inf:- Sysin;
!
!           outfilename:- arg[1];
!           IF outfilename NE "TTY:" THEN
!           BEGIN
!               outfilename:-
!               checkextension(outfilename,".EXT");
!               FOR outf:-
!               findoutfile(outfilename)  WHILE outf ==
!               NONE DO
!               BEGIN
!                   Outtext("? Cannot create Outfile:");
!                   Outtext(outfilename);
!                   Outimage;
!                   outfilename:-
!                   inline("Enter name of outfile:",Sysin);
!                   outfilename:- checkextension(outfilename,".EXT");
!               END loop
!           END ELSE outf:- Sysout;
!
!           ! Check value switch /A: ;
!           IF arg[2] == NOTEXT THEN
!           BEGIN   !.... Set default value arg[2]:- Copy("...");
!           END;
!           avalue:= scanint(arg[2]);
!           ! Assume range [1,99];
!           ! Check result, Pos = 1 is unsuccesfull
!           deediting, More indicates
!           ! superfluous information in value;
!           IF avalue < 0 OR avalue > 99 OR arg[2].Pos = 1
!           OR arg[2].More THEN
!           BEGIN   Outtext("? Illegal /A: value:");
!               Outtext(arg[2]);
!               Outimage;
!               GO TO start;
!           END;
!
!           ! Assume  /N short for /NA ;
!           IF arg[3] == NOTEXT THEN arg[3]:- arg[5];
!           na:= arg[3] =/= NOTEXT;
!           ! More strict: IF arg[3] = " " THEN na:= TRUE
!           ELSE Error;
!           ! Error would indicate the string
!           "/NAxxx/....";
!
!           nb:= arg[4] =/= NOTEXT;
!
!           !....;
!
!       END of program
;
EXTERNAL TEXT PROCEDURE conc,storbokstav,compress;
EXTERNAL INTEGER PROCEDURE search;

INTEGER PROCEDURE sscan(command,n,arg,key,defaultkey);   TEXT command;
INTEGER n;   TEXT ARRAY arg,key;   INTEGER defaultkey;
BEGIN
    INTEGER ARRAY keypos[1:n];   INTEGER i,j,posmin,keyposi;

    command:- compress(command,' ');
    storbokstav(command);
    IF defaultkey > 0 AND defaultkey <= n THEN
    BEGIN
        IF (IF command.Length < key[defaultkey].Length THEN TRUE
        ELSE command.Sub(1,key[defaultkey].Length) NE key[defaultkey]) THEN
        command:- conc(key[defaultkey],command);
    END default key ELSE command:- Copy(command);

    FOR i:= 1 STEP 1 UNTIL n DO
    BEGIN
        command.Setpos(1);
        j:= search(command,key[i]);
        IF j <= command.Length THEN
        BEGIN
            command.Sub(j,key[i].Length):= NOTEXT;
            keypos[i]:= j;
            command.Setpos(j+key[i].Length);
            IF search(command,key[i]) <= command.Length THEN
            BEGIN  sscan:= i;   GO TO exit;   END mult key;
        END key found;
    END i loop;

    FOR i:= 1 STEP 1 UNTIL n DO
    IF keypos[i] > 0 THEN
    BEGIN
        keyposi:= keypos[i];
        ! Search smallest keypos[j] > keypos[i];
        posmin:= command.Length + 1;
        FOR j:= 1 STEP 1 UNTIL n DO
        IF keypos[j] > keyposi THEN
        BEGIN
            IF keypos[j] < posmin THEN posmin:= keypos[j];
        END j loop;

        j:= keyposi + key[i].Length;
        arg[i]:- IF posmin = j THEN Blanks(1) ELSE
        command.Sub(j,posmin-j);
    END keypos[i] > 0;

    exit:
END of scan;