#include <fcntl.h>
#include <stdio.h>
#include <proto/dlg.h>
#include <proto/dos.h>
#include <dialog/file.h>

extern struct Library  *DLGBase;
extern char           **SA;
extern struct USER_DATA StUser;


SHORT ListProtocols(int level,char *valid,int flags,char display)
{
  int fp;
  SHORT count=0;
  struct Protocol protocol;

  valid[count]='\0';
  if((fp=open("DLGCONFIG:Misc/Protocols.bbs",O_RDONLY))==EOF)
  {
    if(display) AFPrintf(&StUser,Output(),SA[3494]);
    return(-1);
  }

  if(display)
  {
    AFPrintf(&StUser,Output(),SA[3495],SA[3496]);
    Draw_Line(70);
  }

  while(read(fp,&protocol,sizeof(protocol))==sizeof(protocol))
  {
    if(protocol.level>level) continue;
    if(!((protocol.flags&flags) == flags)) continue;

    if(display)
      AFPrintf(&StUser,Output(),SA[3497],protocol.letter,
	protocol.name,
	(protocol.flags & PROTO_SEND)?'D':'-',
	(protocol.flags & PROTO_REC)?'U':'-',
	(protocol.flags & PROTO_BATCH)?'B':'-',
	(protocol.flags & PROTO_RESUME)?'R':'-',
	(protocol.flags & PROTO_FNAME)?'F':'-',
	protocol.sendrate,protocol.recrate);

    valid[count]=protocol.letter;
    count++;
  }

  if(display)
  {
    Draw_Line(70);
    AFPrintf(&StUser,Output(),"\n");
  }

  close(fp);
  valid[count]='\0';
  return(0);
}
