home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 270.img / FORUM25C.ZIP / IOSTRING.SUB < prev    next >
Text File  |  1988-12-27  |  5KB  |  236 lines

  1. Procedure getstr;
  2. VAR marker,cnt:integer;
  3.     p:byte absolute input;
  4.     k:char;
  5.     oldinput:anystr;
  6.     done,wrapped:boolean;
  7.     wordtowrap:lstr;
  8.  
  9.   Procedure bkspace;
  10.  
  11.     Procedure bkwrite (q:sstr);
  12.     begin
  13.       write (q);
  14.       if splitmode and dots then write (usr,q)
  15.     end;
  16.  
  17.   begin
  18.     if p<>0
  19.       then
  20.         begin
  21.           if input[p]=^Q
  22.             then bkwrite (' ')
  23.             else bkwrite (k+' '+k);
  24.           p:=p-1
  25.         end
  26.       else if wordwrap
  27.         then
  28.           begin
  29.             input:=k;
  30.             done:=true
  31.           end
  32.   end;
  33.  
  34.   Procedure sendit (k:char; n:integer);
  35.   VAR temp:anystr;
  36.   begin
  37.     temp[0]:=chr(n);
  38.     fillchar (temp[1],n,k);
  39.     nobreak:=true;
  40.     write (temp)
  41.   end;
  42.  
  43.   Procedure superbackspace (r1:integer);
  44.   VAR cnt,n:integer;
  45.   begin
  46.     n:=0;
  47.     for cnt:=r1 to p do
  48.       if input[cnt]=^Q
  49.         then n:=n-1
  50.         else n:=n+1;
  51.     if n<0 then sendit (' ',-n) else begin
  52.       sendit (^H,n);
  53.       sendit (' ',n);
  54.       sendit (^H,n)
  55.     end;
  56.     p:=r1-1
  57.   end;
  58.  
  59.   Procedure cancelent;
  60.   begin
  61.     superbackspace (1)
  62.   end;
  63.  
  64.   Function findspace:integer;
  65.   VAR s:integer;
  66.   begin
  67.     s:=p;
  68.     while (input[s]<>' ') and (s>0) do s:=s-1;
  69.     findspace:=s
  70.   end;
  71.  
  72.   Procedure wrapaword (q:char);
  73.   VAR s:integer;
  74.   begin
  75.     done:=true;
  76.     if q=' ' then exit;
  77.     s:=findspace;
  78.     if s=0 then exit;
  79.     wrapped:=true;
  80.     wordtowrap:=copy(input,s+1,255)+q;
  81.     superbackspace (s)
  82.   end;
  83.  
  84.   Procedure deleteword;
  85.   VAR s,n:integer;
  86.   begin
  87.     if p=0 then exit;
  88.     s:=findspace;
  89.     if s<>0 then s:=s-1;
  90.     n:=p-s;
  91.     p:=s;
  92.     sendit (^H,n);
  93.     sendit (' ',n);
  94.     sendit (^H,n)
  95.   end;
  96.  
  97.   Procedure addchar (k:char);
  98.   begin
  99.     if p<buflen
  100.       then if (k<>' ') or (p>0) or wordwrap or beginwithspacesok
  101.         then
  102.           begin
  103.             p:=p+1;
  104.             input[p]:=k;
  105.             if dots
  106.               then
  107.                 begin
  108.                   writechar (dotchar);
  109.                   if splitmode then write (usr,k)
  110.                 end
  111.               else writechar (k)
  112.           end
  113.         else
  114.       else if wordwrap then wrapaword (k)
  115.   end;
  116.  
  117.   Procedure repeatent;
  118.   VAR cnt:integer;
  119.   begin
  120.     for cnt:=1 to length(oldinput) do addchar (oldinput[cnt])
  121.   end;
  122.  
  123.   Procedure tab;
  124.   VAR n,c:integer;
  125.   begin
  126.     n:=(p+8) and 248;
  127.     if n>buflen then n:=buflen;
  128.     for c:=1 to n-p do addchar (' ')
  129.   end;
  130.  
  131.   Procedure getinput;
  132.   begin
  133.     oldinput:=input;
  134.     ingetstr:=true;
  135.     done:=false;
  136.     bottomline;
  137.     if splitmode and dots then top;
  138.     p:=0;
  139.     repeat
  140.       clearbreak;
  141.       nobreak:=true;
  142.       k:=getinputchar;
  143.       if hungupon then begin
  144.         input:='';
  145.         k:=#13;
  146.         done:=true
  147.       end;
  148.       case k of
  149.         ^I:tab;
  150.         ^H:bkspace;
  151.         ^M:done:=true;
  152.         ^R:repeatent;
  153.         ^X,#27:cancelent;
  154.         ^W:deleteword;
  155.         ' '..'~':addchar (k);
  156.         ^Q:if wordwrap and bkspinmsgs then addchar (k)
  157.       end;
  158. {      if requestchat then begin
  159.         p:=0;
  160.         writeln (^B^N^M^M^B);
  161.         chat (requestcom);
  162.         requestchat:=false
  163.       end  }
  164.     until done;
  165.     writeln;
  166.     if splitmode and dots then begin
  167.       writeln (usr);
  168.       bottom
  169.     end;
  170.     ingetstr:=false;
  171.     ansireset
  172.   end;
  173.  
  174.   Procedure divideinput;
  175.   VAR p:integer;
  176.   begin
  177.     p:=pos(',',input);
  178.     if p=0 then exit;
  179.     addtochain (copy(input,p+1,255)+#13);
  180.     input[0]:=chr(p-1)
  181.   end;
  182.  
  183. begin
  184.   che;
  185.   clearbreak;
  186.   linecount:=1;
  187.   wrapped:=false;
  188.   nochain:=nochain or wordwrap;
  189.   ansicolor (urec.inputcolor);
  190.   getinput;
  191.   if not nochain then divideinput;
  192.   while input[length(input)]=' ' do input[0]:=pred(input[0]);
  193.   if not wordwrap then
  194.     while (length(input)>0) and (input[1]=' ') do delete (input,1,1);
  195.   if wrapped then chainstr:=wordtowrap;
  196.   wordwrap:=false;
  197.   nochain:=false;
  198.   beginwithspacesok:=false;
  199.   dots:=false;
  200.   buflen:=80;
  201.   linecount:=1
  202. end;
  203.  
  204. Procedure writestr (s:anystr);
  205. VAR k:char;
  206.     ex:boolean;
  207. begin
  208.   che;
  209.   clearbreak;
  210.   ansireset;
  211.   uselinefeeds:=linefeeds in urec.config;
  212.   usecapsonly:=not (lowercase in urec.config);
  213.   k:=s[length(s)];
  214.   s:=copy(s,1,length(s)-1);
  215.   case k of
  216.     ':':begin
  217.           write (^P,s,': ');
  218.           lastprompt:=s+': ';
  219.           getstr
  220.         end;
  221.     ';':write (s);
  222.     '*':begin
  223.           write (^P,s);
  224.           lastprompt:=s;
  225.           getstr
  226.         end;
  227.     '&':begin
  228.           nochain:=true;
  229.           write (^P,s);
  230.           lastprompt:=s;
  231.           getstr
  232.         end
  233.     else writeln (s,k)
  234.   end;
  235.   clearbreak
  236. end;