80-Bus News

  

July–October 1982, Volume 1, Issue 3











Page 12 of 51











12

well, whereas others don’t work at all even though they compile perfectly. It seems likely to me that Rory O’Farrell will write the definitive review of the compiler, and tell you all the things I should have, so I am going to change the subject, leaving you with a free gift in the form of a useful Pascal procedure that is all my own work. It is not particularly elegant, and is probably not the best way to do what it does, but it does have the great merit that it does work. It also proves that you can learn Pascal without having to

have as many brains as Zaphod Beeblebrox...

PROCEDURE JUSTIFY;

VAR PTRA, PTRB, I : INTEGER; LINEFULL : BOOLEAN;

BEGIN

LINEFULL := TRUE; PTRA : PTRB : REPEAT

BEGIN {Test to see if there’s more than a full line of text left.}

FOR I:= 0 TO WIDTH DO IF REPLY[PTRB+I| = CHR(13) THEN LINEFULL := FALSE; IF LINEFULL THEN {Do this if there is a full line.} BEGIN {Look one line ahead.} PTRA := PTRB + WIDTH; {If not at a space, come back a bit.} WHILE REPLY[PTRA] <> CHR(32) DO PTRA := PTRA – 1; {Now print what is between the pointers. } FOR I := PTRB TO PTRA – 1 DO WRITE(REPLY[I]); {Print a CR LF if necessary. } IF PTRA < PTRB + WIDTH THEN BEGIN WRITE(CHR(13)); WRITE(CHR(10)) END; {Set pointers to do next line.} PTRA := PTRA + 1; PTRB := PTRA END ELSE {Do this if there is not a full line. } BEGIN {Find the end of the text.} WHILE REPLY[PTRA| <> CHR(13) DO PTRA := PTRA + 13 {Print the remaining text.} FOR I := PTRB TO PTRA – 1 DO waree (Rerun); {Print a CR LF. WRITE(CHR(13)); WRITE(CHR(10)) END;

’ $ . ,

Woof ns aera

END UNTIL NOT LINEFULL END;


This is an OCR’d version of the scanned page and likely contains recognition errors.











Page 12 of 51