home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1456 / addlines.c next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  1.6 KB  |  73 lines

  1. /*
  2.  * Copyright (C) 1990 Jay Konigsberg - see Makefile for details
  3.  * This is Free Software, distrubited under the GNU Software Aggrement.
  4.  *
  5.  */
  6.  
  7. /*
  8.  * addlines - add text to the text buffer. This routine
  9.  * does double service reading from stdin or a file.
  10.  * and handeles inserts and appends.
  11.  */
  12. #include "simped.h"
  13.  
  14. char **addlines(text, overflow, count, location, fd, newfile)
  15. char **text;
  16. char *overflow;
  17. int  *count;
  18. int  location;        /* the line number after which the add occures */
  19. int  newfile;        /* newfile flag to statt in insert mode */
  20. FILE *fd;
  21. {
  22. int    printf();
  23.  
  24. extern    char    *getline(),
  25.         **allocate();
  26.  
  27. char    buffer[LINELEN+2];
  28.  
  29. int    char_read_in=0,        /* characters read in from fd */
  30.     text_entered=TRUE;    /* boolean to determin when to allocate
  31.                    space AND the flag for EOF */
  32.  
  33. if (*count >= 0)
  34.     ++(*count);
  35. for(;;)
  36.     {
  37.     if (fd == stdin || newfile)
  38.     {
  39.     printf("%3d> ",location);
  40.     overflow = getline(buffer, &text_entered, stdin, '\0', FALSE);
  41.     }
  42.     else
  43.     {
  44.     overflow = getline(buffer, &text_entered, fd, '\0', FALSE);
  45.  
  46.     /* see if a blank line is being read in. if so, add 1 sp */
  47.     if (text_entered != EOF && buffer[0] == '\n')
  48.         {
  49.         buffer[0]=' ';
  50.         buffer[1]='\n';
  51.         buffer[2]='\0';
  52.         text_entered=TRUE;
  53.         }
  54.     }
  55.     if (text_entered && text_entered != EOF)
  56.     {
  57.     text = allocate(text, buffer, overflow, location, *count);
  58.     (*count)++;
  59.     location++;
  60.     char_read_in += (strlen(buffer));
  61.     }
  62.     else
  63.     break;
  64.     }
  65. if(fd != stdin && ! newfile)
  66.     {
  67.     printf("%d characters read in\n", char_read_in);
  68.     }
  69. if (*count >= 1)
  70.     --(*count);
  71. return(text);
  72. }
  73.