Google
 

Trailing-Edge - PDP-10 Archives - decuslib20-04 - decus/20-0135/comp/sscan.lst
There are no other files named sscan.lst in the archive.
DECsystem-20 SIMULA  %4A(310)               25-JAN-1981  18:36				 PAGE    1
DSK:SSCAN.SIM	  16-JAN-1979  13:23	

	    1	OPTIONS(/E/C);
	    2	!
	    3	Integer procedure SSCAN will identify specified KEYs in a COMMAND text
	    4	string. SCAN performs - in order -
	    5	1. Does COMPRESS and storbokstav on the COMMAND string
	    6	2. If the parm. DEFAULTKEY belongs to [1:N] and COMMAND string does
	    7	   not start with the text KEY[DEFAULTKEY] then that key will
	    8	   be assumed present in front of COMMAND.
	    9	3. Locates (in order 1 to N) possible occurrences of the texts
	   10	   defined in text array KEY[1:N].
	   11	4. Makes ARG[x] :- whatever follows KEY[x] up to next KEY.
	   12	   If the KEY is just present, but with no text following
	   13	   then Blanks(1) is returned. Nonpresent KEY is indicated
	   14	   with ARG[x] == NOTEXT.
	   15	5. SCAN returns index for multiple used key in command string.
	   16	   Thus, normally SCAN should return zero, indicating no
	   17	   multiple used key.
	   18	
	   19	Differences between SCAN and SSCAN:
	   20	
	   21	a. SCAN makes fields not given to NOTEXT, SSCAN leaves them
	   22	   untouched.
	   23	b. SSCAN uses "storbokstav" instead of "upcase". This does not
	   24	   matter usually for english commands, but is better for
	   25	   swedish commands.
	   26	
	   27	Note that the contents of KEY must have Upper case letters only.
	   28	An example:
	   29	!       BEGIN
	   30	!           EXTERNAL TEXT PROCEDURE conc,storbokstav,compress,
	   31	!           rest,inline,checkextension;
	   32	!           EXTERNAL CHARACTER PROCEDURE findtrigger;
	   33	!           EXTERNAL INTEGER PROCEDURE search,scanint,scan;
	   34	!           EXTERNAL REF (Infile) PROCEDURE findinfile;
	   35	!           EXTERNAL REF (Outfile) PROCEDURE findoutfile;
	   36	!
	   37	!           TEXT ARRAY key,arg,default[1:6];
	   38	!           TEXT command,infilename,outfilename;
	   39	!           INTEGER avalue,index;
	   40	!           BOOLEAN na,nb;
	   41	!           REF (Infile) inf;
	   42	!           REF (Outfile) outf;
	   43	!
	   44	!           key[1]:- Copy("/DEFAULT:/A:/NA/NB/N=");
	   45	!           ! Save some space with this trick!;
	   46	!           key[2]:- key[1].Sub(10,3);  !/A: ;
	   47	!           key[3]:- key[1].Sub(13,3);  !/NA ;
	   48	!           key[4]:- key[1].Sub(16,3);  !/NB ;
	   49	!           ! This keyword (5) must come after /NA and /NB
	   50	!           ! else it will swamp those keys (if present);
	   51	!           key[5]:- key[1].Sub(19,2);  !/N  ;
	   52	!           key[6]:- key[1].Sub(21,1);  !=   ;
DECsystem-20 SIMULA  %4A(310)               25-JAN-1981  18:36				 PAGE   1-1
DSK:SSCAN.SIM	  16-JAN-1979  13:23	

	   53	!           key[1]:- key[1].Sub(1,9);   !/DEFAULT: ;
	   54	!
	   55	!           start:
	   56	!           FOR index:= sscan(inline("*",Sysin),6,arg,key,1)
	   57	!           WHILE index NE 0 DO
	   58	!           BEGIN   Outtext("? Keyword:");
	   59	!               Outtext(key[index]);
	   60	!               Outtext(" used more than once. Please try again.");
	   61	!               Outimage;
	   62	!           END loop;
	   63	!
	   64	!           ! Analyze result:;
	   65	!           ! Assume the user entered: abc=def/A:12/N  ;
	   66	!           ! The result will then be:
	   67	!           ! arg[1] = "ABC"
	   68	!           ! arg[2] = "12"
	   69	!           ! arg[3] == NOTEXT
	   70	!           ! arg[4] == NOTEXT
	   71	!           ! arg[5] = " "
	   72	!           ! arg[6] = "DEF"
	   73	!           ;
	   74	!
	   75	!           ! Test file information;
	   76	!           ! Default inputname is outputname;
	   77	!           IF arg[6] == NOTEXT THEN arg[6]:- arg[1];
	   78	!           infilename:- arg[6];
	   79	!
	   80	!           ! We also demonstrate a way of checking
	   81	!           ! entered file specifications;
	   82	!           IF infilename NE "TTY:" THEN
	   83	!           BEGIN
	   84	!               infilename:-
	   85	!               checkextension(infilename,".EXT");
	   86	!               FOR inf:- findinfile(infilename) WHILE
	   87	!               inf == NONE DO
	   88	!               BEGIN   Outtext("? Cannot find Infile:");
	   89	!                   Outtext(infilename);
	   90	!                   Outimage;
	   91	!                   infilename:-
	   92	!                   inline("Enter name of infile:",Sysin);
	   93	!                   infilename:-
	   94	!                   checkextension(infilename,".EXT");
	   95	!               END loop;
	   96	!           END not TTY ELSE
	   97	!           inf:- Sysin;
	   98	!
	   99	!           outfilename:- arg[1];
	  100	!           IF outfilename NE "TTY:" THEN
	  101	!           BEGIN
	  102	!               outfilename:-
	  103	!               checkextension(outfilename,".EXT");
	  104	!               FOR outf:-
DECsystem-20 SIMULA  %4A(310)               25-JAN-1981  18:36				 PAGE   1-2
DSK:SSCAN.SIM	  16-JAN-1979  13:23	

	  105	!               findoutfile(outfilename)  WHILE outf ==
	  106	!               NONE DO
	  107	!               BEGIN
	  108	!                   Outtext("? Cannot create Outfile:");
	  109	!                   Outtext(outfilename);
	  110	!                   Outimage;
	  111	!                   outfilename:-
	  112	!                   inline("Enter name of outfile:",Sysin);
	  113	!                   outfilename:- checkextension(outfilename,".EXT");
	  114	!               END loop
	  115	!           END ELSE outf:- Sysout;
	  116	!
	  117	!           ! Check value switch /A: ;
	  118	!           IF arg[2] == NOTEXT THEN
	  119	!           BEGIN   !.... Set default value arg[2]:- Copy("...");
	  120	!           END;
	  121	!           avalue:= scanint(arg[2]);
	  122	!           ! Assume range [1,99];
	  123	!           ! Check result, Pos = 1 is unsuccesfull
	  124	!           deediting, More indicates
	  125	!           ! superfluous information in value;
	  126	!           IF avalue < 0 OR avalue > 99 OR arg[2].Pos = 1
	  127	!           OR arg[2].More THEN
	  128	!           BEGIN   Outtext("? Illegal /A: value:");
	  129	!               Outtext(arg[2]);
	  130	!               Outimage;
	  131	!               GO TO start;
	  132	!           END;
	  133	!
	  134	!           ! Assume  /N short for /NA ;
	  135	!           IF arg[3] == NOTEXT THEN arg[3]:- arg[5];
	  136	!           na:= arg[3] =/= NOTEXT;
	  137	!           ! More strict: IF arg[3] = " " THEN na:= TRUE
	  138	!           ELSE Error;
	  139	!           ! Error would indicate the string
	  140	!           "/NAxxx/....";
	  141	!
	  142	!           nb:= arg[4] =/= NOTEXT;
	  143	!
	  144	!           !....;
	  145	!
	  146	!       END of program
	  147	;
	  148	EXTERNAL TEXT PROCEDURE conc,storbokstav,compress;
	  149	EXTERNAL INTEGER PROCEDURE search;
	  150	
	  151	INTEGER PROCEDURE sscan(command,n,arg,key,defaultkey);   TEXT command;
	  152	INTEGER n;   TEXT ARRAY arg,key;   INTEGER defaultkey;
B1	  153	BEGIN
	  154	    INTEGER ARRAY keypos[1:n];   INTEGER i,j,posmin,keyposi;
	  155	
	  156	    command:- compress(command,' ');
DECsystem-20 SIMULA  %4A(310)               25-JAN-1981  18:36				 PAGE   1-3
DSK:SSCAN.SIM	  16-JAN-1979  13:23	

	  157	    storbokstav(command);
	  158	    IF defaultkey > 0 AND defaultkey <= n THEN
B2	  159	    BEGIN
	  160	        IF (IF command.Length < key[defaultkey].Length THEN TRUE
	  161	        ELSE command.Sub(1,key[defaultkey].Length) NE key[defaultkey]) THEN
	  162	        command:- conc(key[defaultkey],command);
E2	  163	    END default key ELSE command:- Copy(command);
	  164	
	  165	    FOR i:= 1 STEP 1 UNTIL n DO
B3	  166	    BEGIN
	  167	        command.Setpos(1);
	  168	        j:= search(command,key[i]);
	  169	        IF j <= command.Length THEN
B4	  170	        BEGIN
	  171	            command.Sub(j,key[i].Length):= NOTEXT;
	  172	            keypos[i]:= j;
	  173	            command.Setpos(j+key[i].Length);
	  174	            IF search(command,key[i]) <= command.Length THEN
B5  E5	  175	            BEGIN  sscan:= i;   GO TO exit;   END mult key;
E4	  176	        END key found;
E3	  177	    END i loop;
	  178	
	  179	    FOR i:= 1 STEP 1 UNTIL n DO
	  180	    IF keypos[i] > 0 THEN
B6	  181	    BEGIN
	  182	        keyposi:= keypos[i];
	  183	        ! Search smallest keypos[j] > keypos[i];
	  184	        posmin:= command.Length + 1;
	  185	        FOR j:= 1 STEP 1 UNTIL n DO
	  186	        IF keypos[j] > keyposi THEN
B7	  187	        BEGIN
	  188	            IF keypos[j] < posmin THEN posmin:= keypos[j];
E7	  189	        END j loop;
	  190	
	  191	        j:= keyposi + key[i].Length;
	  192	        arg[i]:- IF posmin = j THEN Blanks(1) ELSE
	  193	        command.Sub(j,posmin-j);
E6	  194	    END keypos[i] > 0;
	  195	
	  196	    exit:
E1	  197	END of scan;


SWITCHES CHANGED FROM DEFAULT:

  -A NO CHECK OF ARRAY INDEX
  -D NO SYMBOL TABLE GENERATED FOR DEBUG
   E EXTERNAL CLASS/PROCEDURE
  -I NO LINENUMBER TABLE GENERATED
  -Q NO CHECK OF QUALIFICATION

NO ERRORS DETECTED

DECsystem-20 SIMULA  %4A(310)               25-JAN-1981  18:36				 PAGE    2
DSK:SSCAN.SIM	  16-JAN-1979  13:23		LINE NUMBER TABLE

    0	000007
    0	000362

DECsystem-20 SIMULA  %4A(310)               25-JAN-1981  18:36				 PAGE    3
DSK:SSCAN.SIM	  16-JAN-1979  13:23		CROSS REFERENCE TABLE


ARG         	   151D     192   
BLANKS      	   192   
COMMAND     	   151D     156M     157      160      161      162M     163M     167      168      169   
		   171      173      174M     184      193   
COMPRESS    	   148DE    156   
CONC        	   148DE    162   
COPY        	   163   
DEFAULTKEY  	   151D     158M     160      161M     162   
EXIT        	   175      196D  
I           	   154D     165      168      171      172      173      174      175      179      180   
		   182      191      192   
J           	   154D     168      169      171      172      173      185      186      188M     191   
		   192      193M  
KEY         	   151D     160      161M     162      168      171      173      174      191   
KEYPOSI     	   154D     182      186      191   
KEYPOS      	   154D     172      180      182      186      188M  
LENGTH      	   160M     161      169      171      173      174      184      191   
N           	   151D     154      158      165      179      185   
POSMIN      	   154D     184      188M     192      193   
SEARCH      	   149DE    168      174   
SETPOS      	   167      173   
SSCAN       	   151D     175   
STORBOKSTAV 	   148DE    157   
SUB         	   161      171      193