# constant definitions include stdef.rat/nl # #------------------------------------------------------------------------------- # integer function length(strng) # ################################################################################ # # LENGTH returns the number of characters passed in the input vector # STRNG, excluding the terminating null byte. # ################################################################################ # char strng(arb) # Random length string. # for (I=0; strng(I+1)~=eos; I=I+1) { } # Null statement. # return(I) # end # # integer function getl(strng,max,lunin) # ################################################################################ # # GETL is an integer function that reads a random length character string # from the logical unit number specified in LUNIN. The string is stored in # the vector STRNG, and must be at most MAX-1 characters in length, as the # string is always terminated by a null byte (octal 0). The value of the # function return is the number of bytes (excluding the eos) that were read. # If, however, an end of file was read, (or a ^Z), then the functon returns # a value of -1. # ################################################################################ # char strng(max) # integer n, max, lunin # # read(lunin,10,end=100) n,strng # Random byte length read. 10 format(Q,255a1) # # if (n>=max) # Line is longer than max length. n=max-1 # Chop line at max-1 bytes. strng(n+1)=eos # Terminate the string with null. return(n) # # 100 strng(1)=eos # return(eof) # end of file read. end # # integer function getty(prompt,result) # ############################################################################### # # e.g. len=getty(,result) # or # len=getty("RAT>",result) # # The integer function GETTY is like GETL except that the input device # is assumed to be the terminal, and it is also possible to issue a prompt # for a given command. PROMPT is a random length string that should be # terminated with a null byte. The routine will append octal 200 to # the prompt string to inhibit a carriage return, line feed at # the end of the PROMPT. # A random length character string is returned # in STRNG and the string is terminated with a null byte. An optional prompt # may also be included. # NOTE: This function uses the RT-11 system subroutine GTLIN as described # on page 2-52 and 3-10 of the RT-11 V4.0 Programmer's Reference Manual. # #****************************************************************************** # # GETTY vs. GETL # # Please note there is a large difference in the two routines GETL and # GETTY. When input is with respect to the terminal, GETL will not read # from a command file, but GETTY will read from a command file. If calls # to GETL and GETTY are intermixed, and a command file is currently open, # GETL wil ignore the command file and allow input from the terminal, whereas # GETTY will always read the next line from the command file. When a command # file is not currently open, both GETL and GETTY function identically. # A further source of confusion, in GETL the input string can be of any # length and its maximum is specified in the call to the subroutine. # In GETTY, the input string MUST be 81 characters in length, (of course it # may be dimensioned as anything larger than 81 as well). # ############################################################################### # char prompt(arb), result(arb) # # if (iaddr(prompt)==-1) # No prompt provided. call gtlin(result) # just get response. else # { # lpmt=length(prompt)+1 # Length of the prompt. # LPMT points to null byte. prompt(lpmt)=128 # Put octal 200 in place of EOS. call gtlin(result,prompt) # prompt(lpmt)=eos # Put EOS back where it belongs. } # # return(length(result)) # end # # subroutine putl(strng,lunout) # ############################################################################### # # PUTL subroutine writes a random length string of ascii text passed in # STRNG (and terminated with a null byte) to the ouput logical unit number # passed in LUNOUT. If the first byte of the string is a null byte, (STRNG # is empty), then a null record is written to LUNOUT. # ############################################################################### # char strng(arb) # ARB length string. integer L, length, I, lunout # # L=length(strng) # Get the byte length of the string. if (L>>0) { # length of string greater than 0 write(lunout,10) (strng(I),I=1,L) # Write non-null record. 10 format(255a1) # return # Return after write. } # else # write(lunout,10) # Write a null record to the output LUN. # return # end # # subroutine lcuc(strng) # ############################################################################### # # This subroutine accepts a standard character string that is terminated # by an eos, and converts all lower case letters to upper case letters. # ############################################################################### # char strng(arb) # # for (I=1; strng(I)~=eos; I=I+1) # Repeat until an eos. if (strng(I)>='a'&strng(I)<='z') # If lower case letter... strng(I)=strng(I)-32 # convert to upper case return end # char function equal(s1,s2) # ################################################################################ # # Returns true if string S1 is exactly equal to S2, else returns false. # ################################################################################ # char s1(arb), s2(arb) # # for (I=1; s1(I)==s2(I); I=I+1) # check each byte for equality. if (s1(I)==eos) # if end of string, return(.true.) # strings are equal. return(.false.) # If break loop, not equal. end # # char function compar(s1,s2,nbytes) # ################################################################################ # # This routine compares the first NBYTES bytes of strings S1 and S2 # and returns true if they are identical, else it returns false. # ################################################################################ # char s1(arb), s2(arb) # # for (I=1; s1(I)==s2(I); I=I+1) # if (I==nbytes) # return(.true.) # # return(.false.) # end # integer function index(strng,c) # ################################################################################ # # Finds the first occurence of the character C in the string STRNG and # returns its index, else if the character is not found before the EOS, # the function returns -1. # ################################################################################ # char c, strng(arb) # # for (I=1; strng(I)~=eos; I=I+1) # if (strng(I)==c) # find byte? return(I) # yes, return index. return(-1) # character not found. end # subroutine copy(from,to,max) # ################################################################################ # # COPY copies up to max characters from string FROM to string TO. # ################################################################################ # char from(arb), to(arb) # # for (I=1; from(I)~=eos&I<>0) { # Then shift right. if (start<=0) # Start index out of range. return(-1) # for (I=length(strng)+1; I>=start; I=I-1) { # Copy trailing NULL byte too. strng(I+N)=strng(I) # Shift N bytes to left. if (strng(I)==eos) # REMOVE EOS that may show up in middle strng(I)=space # of the string, causing tail to be deleted. } # } # # If N=0 then don't do anything. # return(length(strng)) # Success, return length of string. end # integer function any(s1,s2) # ############################################################################### # # ANY will return the first occurence in S1 of any of the characters # listed in the input string S2. If none of the characters listed in S2 # can be found in S1, then the function returns -1. # ############################################################################### # char s1(arb), s2(arb) # # for (I=1; s1(I)~=eos; I=I+1) # Loop on each byte in string. if (index(s2,s1(I))>>0) # find match in s2 if one. return(I) # found a match. return(-1) # No matches found. end # # integer function notany(s1,s2) # ############################################################################### # # NOTANY will return the first position in S1 that contains none # of the characters listed in the string S2. The function returns -1 # of all characters in S1 match with any character in S2. # ############################################################################### # char s1(arb), s2(arb) # # for (I=1; s1(I)~=eos; I=I+1) # Loop on each byte in string. if (index(s2,s1(I))<<1) # find a non-match return(I) # found a match return(-1) # all matches end # # integer function remove(s1,s2) # ############################################################################### # # REMOVE will remove all occurences of characters listed in the string # S2 from the string S1 and return the remaining length of s1 as # the value of the function. Both S1 and S2 must be terminated with a null # byte. REMOVE must be declared as an integer in the calling routine. # ############################################################################### # integerfunction shrten, any # char s1(arb), s2(arb) # # repeat { # indx=any(s1,s2) # Get offset of first # match byte if (indx<<1) # If no more characters to be break # removed, then exit. else # len=shrten(s1(indx),s2) # Remove characters from string. } # len=length(s1) # return (len) # Return remaining length end # integer function shrten(s1,s2) # ############################################################################### # # This routine will remove all occurences of only characters specified # in the string S2 from the front of the char string S1. If there # are no characters in S2 that precede S1 then no action is taken. # S2 may be a literal or an array of characters. On a return from # the routine, SHRTEN will return the length of the string S1. # ############################################################################### # char s1(arb), s2(arb) # integerfunction shift, notany # # nskip=notany(s1,s2)-1 # notany returns the position # of the first non-match, however, # want to delete 1 less than this. # if (nskip==0) # No preceding S2 chars in S1. return(length(s1)) # else # if (nskip<<0) { # If the entire string S1 consists s1(1)=eos # of S2 chars, null the string. return(0) # length of string is 0. } # else # L=shift(s1,1,-nskip) # Delete first nskip characters. # return (length(s1)) # return string length end # # char function ascint(ascin,intout) # ############################################################################### # # This function converts a single string of ascii representing # a integer number to its integer equivalent. The function returns # true if the conversion was accomplished successfully, else it returns # false. If a null string is passed as an argument, the function # assigns an integer value of 0. # ############################################################################### # char ascin(arb) # Ascii input vector. integerfunction length # # L=length(ascin) # determine length of input string. # if (L==0) # Assume value is 0 intout=0 # else # if (L>>7) # string too long goto 110 # error out else # { # decode(L,100,ascin,err=110) intout # 100 format(i7) # } # return(.true.) # no error # 110 return (.false.) # error return. end # # integer function intget(minval,maxval) # ############################################################################### # # This function returns an integer number that is obtained from the terminal # or from a command file that has been opened previously by the monitor. # The parameters MINVAL and MAXVAL specify the minimum and maximum integer # values respectively and both must be specified. It is not possible # to specify only an upper or a lower limit. If an error occurs, either # an illegal number or a range error, the terminal is prompted and a new value # is obtained. The function will only return after a legal number # has been read successfully. # ############################################################################### # char ascin(82) # charfunction ascint # integerfunction getl, getty # integerfunction remove # # L=getty(,ascin) # Get the first command from terminal or # repeat { # Repeat until a good floating point # number has been read. # L=remove(ascin,tabspace) # Remove any tabs or spaces # if (length(ascin)==0) { # Only RETURN was entered, ascin(1)='0' # default value of 0 ascin(2)=EOS # } # # if (~ascint(ascin,intout)) { # Convert string to integer. write(5,10) # error. 10 format ('$ ** re-enter integer number: ') # Re-prompt. } # else # if (intout<>maxval) { # 99 write(5,11) minval, maxval # 11 format(' ** value out of range: [',i6,',',i6,']') write(5,10) # } # else # break # None of the above errors detected. # # ERROR, reprompt to terminal if (getl(ascin,8,5)==EOF) # If ^Z entered, call exit # then quit. } # # return (intout) # end