program wrap;
uses crt;

var testdata:array[1..10] of string;
    index:integer;

procedure dumbwrap(s:string);
const crlf:string[2]=#13#10;
var runlen:integer;
    position:integer;
begin
  repeat
    runlen:=78-wherex;
    if runlen>length(s) then begin write(s+' '); exit; end;
    position:=runlen;
    while (position>0) and (s[position]<>#32) do dec(position); {Work backward to space}
    if
      position>0
    then
      begin
        writeln(copy(s,1,position));
        delete(s,1,position);
      end
    else
      begin
        writeln('');
      end;
  until s[0]=#0;
end;

begin
  testdata[1]:='This is a test string.';
  testdata[2]:='This is another test string.';
  testdata[3]:='This is a string which is over 80 columns long, to demonstrate long string handling.';
  testdata[4]:='This is the fourth string.';
  testdata[5]:='This is the fifth string.';
  testdata[6]:='This is another very long string, in fact it is over 160 columns long in order to '
              +'assure that multiple wraps occur for this string, so that we will know for sure that '
              +'the routine can handle long strings!';
  testdata[7]:='This is the seventh string.';
  testdata[8]:='This somewhat longish string is just here to keep things asymmetrical.';
  testdata[9]:='String #9.';
  testdata[10]:='This is the tenth and final string.  It terminates with this period.';

  for index:=1 to 10 do dumbwrap(testdata[index]);


end.




