{$R-,S-,I-,D-,V-,B-,N-,L- }
{$O+}

unit mainr1;


{/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}

interface

uses gentypes,configrt,textret,gensubs,subs1,userret,statret;

{/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}


Procedure showinfoforms (uname:mstr);  { UNAME='' shows all }
Function validfname (name:lstr):boolean;
Function searchboard (name:sstr):integer;
Function numfeedback:integer;
Procedure trimmessage (VAR m:message);


{/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}

implementation

{/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}


Procedure showinfoforms (uname:mstr);  { UNAME='' shows all }
VAR lnum,un,cnt:integer;
    u:userrec;

  Procedure showone;
  VAR ff:text;
      fn:lstr;
      me:message;
      k:char;
      found:boolean;
  begin
    if u.infoform=-1 then begin
      writeln (^B'That user has no information form.');
      exit
    end;
    fn:=textfiledir+'infoform';
    assign (ff,fn);
    reset (ff);
    if ioresult<>0 then begin
      close (ff);
      lnum:=ioresult;
      writeln (^B'No information form is present.');
      exit
    end;
    reloadtext (u.infoform,me);
    writeln (^M,me.text[1],^M^M);
    lnum:=1;
    while not (break or eof(ff)) do begin
      read (ff,k);
      if k='*'
        then if lnum>me.numlines
          then writeln ('No answer')
          else begin
            lnum:=lnum+1;
            writeln (me.text[lnum])
          end
        else write (k)
    end;
    textclose (ff)
  end;

begin
  if uname='' then begin
    writeln (^B^M'          Showing All Forms');
    seek (ufile,1);
    for cnt:=1 to numusers do begin
      read (ufile,u);
      if u.infoform<>-1 then begin
        writeln (^M^M,u.handle,^M);
        showone
      end;
      if xpressed then exit
    end
  end else begin
    un:=lookupuser (uname);
    if un=0 then writeln (^B'No such user.') else begin
      seek (ufile,un);
      read (ufile,u);
      showone
    end
  end
end;

Function validfname (name:lstr):boolean;
const invalid:set of char=[#0..#31,'"',']','[',':','\','>','<','/','?','*',
  '|','+','=',';', ',' ,#127..#255];
VAR p,cnt:integer;
    k:char;
    dotfound:boolean;
begin
  validfname:=false;
  dotfound:=false;
  if (length(name)>12) or (length(name)<1) then exit;
  for p:=1 to length(name) do begin
    k:=upcase(name[p]);
    if k in invalid then exit;
    if k='.' then begin
      if dotfound then exit;
      dotfound:=true;
      if (p<length(name)-3) or (p=1) then exit
    end
  end;
  validfname:=not devicename(name)
end;

Function searchboard (name:sstr):integer;
VAR bi:sstr;
    cnt:integer;
begin
  seek (bifile,0);
  for cnt:=0 to filesize(bifile)-1 do begin
    read (bifile,bi);
    if match(bi,name) then begin
      searchboard:=cnt;
      exit
    end
  end;
  searchboard:=-1
end;

Function numfeedback:integer;
VAR ffile:file of mailrec;
begin
  assign (ffile,'Feedback');
  reset (ffile);
  if ioresult<>0 then begin
    numfeedback:=0;
    rewrite (ffile)
  end else numfeedback:=filesize (ffile);
  close (ffile)
end;

Procedure trimmessage (VAR m:message);
VAR cnt:integer;
begin
  for cnt:=1 to m.numlines do
    while m.text[cnt][length(m.text[cnt])]=' ' do
      m.text[cnt][0]:=pred(m.text[cnt][0]);
  while (m.numlines>0) and (m.text[m.numlines]='') do
    m.numlines:=m.numlines-1
end;

Begin
end.
