#include "stdio.h"
#include "ed.h"

FILE *infile;
12345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890123
main()
{
   minline = sbrk(10000); maxline = sbrk(256);
   nxtline = minline;
   if (minline == 0) exit(1);
   linezero.lnext = -1; linezero.lprev = -1; linezero.llen = 6;
   infile = fopen("junk","r");
   fillup();
   topline = linezero.lnext;
   rfsh();
}

addafter(line,len)
struct LINE *line;
int len;
{
   nxtline->lnext = line->lnext;
   nxtline->lprev = line;
   line->lnext = nxtline;
   nxtline->llen = len;
   nxtline = (char *)nxtline + len + 6;
   return (nxtline >= maxline);
}

fillup()
{
   char *d;
   char *d;
   int c, l;
   struct LINE *line, *curline = &linezero;
   int c, l;
   struct LINE *line, *curline = &linezero;

   line = nxtline;
   while (1) {
      d = line->ldata; 
      l = 0;
      while ((c=getc(infile)) != '\n' && c != EOF) {
	 *d++ = c; l++;
      }
      *d = '\0';
      if (c == EOF) break;
      if (addafter(curline,l)) break;
      curline = line;
   }
}
