# 2.11BSD#431 - /usr/src/local/mp/io.c

##### Functions

    emptyline         X
    readline          X

       1:
       2: /*  @(#)io.c 1.4 92/02/17
       3:  *
       4:  *  Copyright (c) Steve Holden and Rich Burridge.
       5:  *                All rights reserved.
       6:  *
       7:  *  Permission is given to distribute these sources, as long as the
       8:  *  copyright messages are not removed, and no monies are exchanged.
       9:  *
      10:  *  No responsibility is taken for any errors inherent either
      11:  *  to the comments or the code of this program, but if reported
      12:  *  to me then an attempt will be made to fix them.
      13:  */
      14:
      15: #include "mp.h"
      16: #include "extern.h"
      17:
      18:
      19: /* Emptyline returns true if its argument is empty or whitespace only */
      20:
      21: bool
      22: emptyline(str)
      23: char *str ;
      24: {
      25:   while (*str)
      26:     {
      27:       if (!isspace(*str)) return(FALSE) ;
      28:       str++ ;
      29:     }
      30:   return(TRUE) ;
      31: }
      32:
      33:
      34: /*  Read an input line into nextline, setting end_of_file, end_of_page
      35:  *  and end_of_line appropriately.
      36:  */
      37:
      38: void
      39: readline()
      40: {
      41:   int c ;
      42:   int i = 0 ;      /* Index into current line being read. */
      43:   int len = 0 ;    /* Length of the current line. */
      44:
      45:   if (end_of_file) return ;
      46:   end_of_page = end_of_line = FALSE ;
      47:
      48:   while (len < llen && (c = getc(fp)) != EOF && c != '\n' && c != '\f')
      49:     {
      50:       if (c == '\t')
      51:         {
      52:           do
      53:             {
      54:               nextline[i++] = ' ' ;
      55:               len++ ;
      56:             }
      57:           while (len % 8 != 0 && len <= llen) ;
      58:         }
      59:       else
      60:         {
      61:           nextline[i++] = c ;
      62:           len++ ;
      63:         }
      64:       if (c == '\b')
      65:         {
      66:           len -= 2 ;
      67:           i -= 2 ;
      68:         }
      69:     }
      70:   nextline[i] = '\0' ;
      71:
      72:   if (len == llen && c != EOF && c != '\n' && c != '\f')
      73:     {
      74:       c = getc(fp) ;
      75:       if (c != EOF && c != '\n' && c != '\f') UNGETC(c, fp) ;
      76:     }
      77:
      78:   if (elm_if && c == '\f')
      79:     {
      80:       len-- ;
      81:       i-- ;
      82:     }
      83:
      84:   switch (c)
      85:     {
      86:       case EOF  : if (i == 0) end_of_file = TRUE ;
      87:                   else
      88:                     {
      89:                       UNGETC(c, fp) ;
      90:                       end_of_line = TRUE ;
      91:                     }
      92:                   break ;
      93:       case '\n' : end_of_line = TRUE ;
      94:                   break ;
      95:
      96: /*  /usr/ucb/mail for some unknown reason, appends a bogus formfeed at
      97:  *  the end of piped output. The next character is checked; if it's an
      98:  *  EOF, then end_of_file is set, else the character is put back.
      99:  */
     100:
     101:       case '\f' : if ((c = getc(fp)) == EOF) end_of_file = TRUE ;
     102:                   else UNGETC(c, fp) ;
     103:
     104:                   end_of_line = TRUE ;
     105:                   end_of_page = TRUE ;
     106:                   break ;
     107:     }
     108:   clen = len + 1 ;          /* Current line length (includes newline). */
     109: }

#### Defined functions

emptyline defined in line 21; never used
readline defined in line 38; never used

Last modified: 1992-02-17 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1254 |