#include "make.h"

char *getline( maxline, fp )
BPTR fp;
   {
   static   char   *buf;
   register char   *bp;
   char c;
   register int    lastc, rc;

   /* Use 2 buffers.                                           */
   /* This one is the max. length; later, correct size is used */
   bp = buf = cmdbuff;

   while(1)
      {
      Inputline++;      /* Update input line # */

      for ( lastc=0; (rc = Read(fp, &c, 1)) == 1 && c != '\n'; lastc = c)
         if ( --maxline  > 0 )
            *bp++ = c;

      if ( !( c == '\n' && lastc == '\\' ) )
         break;

      else if ( maxline > 0 )          /* erase the \ */
         --bp;
      }

   *bp = 0;

   if ( (rc == 0 && bp == buf) || !(bp = getmem((bp-buf)+1)) )
      {

      /* Quit if EOF was 1st char or if getmem fails */
      return (NULL);
      }

   /* Copy max buffer to smaller buffer */
   strcpy( bp, buf );
   return (bp);
   }
