/* Part of DoorLib v1.12

   Name   : TypeTextF
   Version: 1.12
   Date   : Saturday, 1st June 1996

   Purpose: DoorLib's textfile display functions.

   Creator: Richard Murray
*/

#include <stdio.h>
#include <stdlib.h>

#include "ctype.h"
#include "kernel.h"
#include "stdarg.h"
#include "strings.h"
#include "time.h"

#include "doorlib.h"

int doors_typetextfile(int bs_port, int bs_nonstop, char *bs_filename)
/* Will type the file 'bs_filename' to the specified port. If 'bs_nonstop' is true, then
   no prompting will be given. The lines will be terminated at the 79th characters. No
   checks made to see if user is still 'here'. It polls the wimp frequently - your check
   should be there... Returns TRUE when done, or FALSE if file cannot be opened. */
{
   FILE *bs_file;         /* File handle */
   int  bs_junk;          /* Temp variable, used in scroll request */
   int  bs_lines=1;       /* Lines displayed */
   int  bs_aborted=FALSE; /* Abort list? */
   char bs_buffer[256];   /* Space for lines read in... */
   int  bs_ns=FALSE;	  /* Nonstop? */

   if (( bs_file = fopen(bs_filename,"rb") ) == NULL)
   {
      return FALSE;
   }

   while (!feof(bs_file) && bs_aborted!=TRUE)
   {
      fgets(bs_buffer,254,bs_file);
      bs_buffer[(strlen(bs_buffer)-1)]='\0';  /* Hack to remove linefeeds */
      bs_buffer[78]='\0';
      doors_txf(bs_port,"%s\r\n",bs_buffer);
      bs_lines++;

      if (bs_lines>22 && bs_ns==FALSE)
      {
         doors_tx(bs_port," \rMore? [Return] continues, [N]onstop, [Ctrl+C] to abort...\r");
	 bs_junk=doors_scrollrq(bs_port);
	 if (bs_junk==TRUE)
	 {
	    doors_txf(bs_port,"Continue...\r");
	    bs_lines=1;
	 }
	 if (bs_junk==FALSE)
	 {
	    bs_ns=TRUE;
	    doors_txf(bs_port,"Nonstop...\r");
	 }
	 if (bs_junk==-1) bs_aborted=TRUE;
      }
   }
   fclose(bs_file);
   return TRUE;
}


void doors_includeX3(void)
{
   printf("BUDGIESOFT DOORLIB :: TYPETEXTF");
}
