#include <stdio.h>
#include <sys/file.h>
#include <sys/types.h>

#include <sys/stat.h>

static int	textbuf_numline;
static int      textbuf_size = 0;
char *lineptrs[1000];
char *buf;

char *
textbuf_line(lineno)
int lineno;
{
	if (lineno == textbuf_numline)
	  return "---------------------------- END OF DOCUMENT ---------------------";
	if (lineno > textbuf_numline)
		return "";

	return lineptrs[lineno];
}
char *
get_buf()
{
char *bf;

  bf = (char *) malloc(32000);
return bf;
}

static int
textbuf_load(filename)
char filename[];
{
	struct stat   st;
	int	fd,line = 0, len, red,i;
	char *cp;


	textbuf_numline = 0;
	fd = open(filename, O_RDONLY,0644);
	if (fd < 0) {
		/* disp_syserr(filename); */
		return 0;
	}
	stat(filename,&st);
	printf("filesize = %d\n",st.st_size);
	/*  free(buf); */
	buf = (char *) malloc(st.st_size);
	printf("add of buf = %ld\n",buf);
	red = read(fd, buf, st.st_size);
	if (red == -1){
	  perror("reading file");
	  return 0;
	}
	printf("amount read = %d\n",red);
	lineptrs[0] = cp = buf;
	line = 1;
	printf("add of lineptrs[0] = %ld\n",lineptrs[0]);
	for ( i = 0; i < red; i++) {
	  if (*cp == '\n') {
	    *cp = '\0';
	    lineptrs[line] = cp + 1;
	/*   printf("line = %s\n",lineptrs[line-1]);  */
	    line++;
	  }
	  cp++;
	}
	printf("num of lies = %d\n",line);
	close(fd);
	return textbuf_numline = line;
	}

/* ---------------------------------------------------------------------- */
/* ---------------------------------------------------------------------- */
/* ---------------------------------------------------------------------- */

main()
{
int rc,i;
  
rc = textbuf_load("/mit/pips_dev/work/pdb.h");

for (i = 0; i < textbuf_numline;i++){

  printf("%s\n",textbuf_line(i));
 /*  printf("%s\n",lineptrs[i]); */
} 

}
