corre@csd4.csd.uwm.edu (Alan D Corre) (12/20/89)
By request I am posting the MS-DOS version of the procedures I posted recently for the Zenith terminal. I have added Chris Tenaglia's input procedure, and have gilded his lily by offering a variant, inputl, which insists on a response of a specific length. This can readily be modified to include other determinants, that the response must be an integer, for example. procedure banner(l[]) #Writes to the screen an arbitrary number of strings and encloses them. local n write();write();write() writes(char(201)) #top left right angle writes(repl(char(205),78)) #straight line writes(char(187)) #top right right angle writes(char(186)) #upright line at left writes(right(char(186),79)) #upright line at right every n := 1 to *l do { writes(char(186)) #upright line at left writes(center(l[n],78),char(186)) #string centered followed by upright line writes(char(186)) #upright line at left writes(right(char(186),79)) #upright line at right } writes(char(200)) #bottom left right angle writes(repl(char(205),78)) #straight line write(char(188)) #bottom right right angle write() return end procedure instructions(filename) #writes contents of a file to screen, allows user to stop after any screenful. local filvar,counter,line writes("Do you need instructions? y/n ") if upto('yY',read()) then { #The following if-statement fails if the file is not available counter := 0 if filvar := open(filename) then #Read the help file. It's a good idea to keep this kind of info in a #separate file because you can modify it easily without redoing the #program. In general---keep data out of programs! while line := read(filvar) do { #Write out a line and increment the counter write(line) counter +:= 1 #Now we have a screenful; ask if we should continue if counter >22 then { write() writes ("More? y/n ") #User has had enough; break out of loop if upto('nN',read()) then break else #User wants more; reset counter and continue counter := 0}} else #This else goes with the second if-statement; the attempt to open the #help file failed: write("Sorry, instructions not available.")} write ("Press return to continue.") read() #Close the file if it existed and was opened. If it was never opened #the value of filvar will be null. This check has to be made because #an attempt to use close() on a variable NOT valued at a file would #cause an error. /filvar | close(filvar) end procedure randomize() #deletes the colons from the clock time, and uses the resulting number as seed local clock clock := &clock clock[6] := "" clock[3] := "" &random := clock end procedure clear() #clears the screen writes("\e[2J") end procedure gotoxy(l,r) #sets the cursor at line l, row r writes("\e[",l,";",r,"H") end procedure input(s) #prints the prompt s and returns the user's response writes(s) return read() end procedure inputl(s,n) #prints the prompt s, indicates that the response must be n characters #max, and insists on appropriate response. local ans write(s) writes(n," characters maximum. ") #if ANSI driver is installed omit initial #-sign in following lines # writes("\e[7m\e[s", repl(" ",n),"\e[u\e[0m") #save cursor,reverse video, ##n blanks, restore cursor, normal video while *(ans := read()) > n do { write(s) writes(n," characters maximum. ") # writes("\e[7m\e[s", repl(" ",n),"\e[u\e[0m") } return ans end -- Alan D. Corre Department of Hebrew Studies University of Wisconsin-Milwaukee (414) 229-4245 PO Box 413, Milwaukee, WI 53201 corre@csd4.csd.uwm.edu