home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / prof_c / 09print / pr_line.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  1.0 KB  |  48 lines

  1. /*
  2.  *    pr_line -- ouput a buffered logical line and
  3.  *    return a count of physical lines produced
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <local\std.h>
  9. #include "print.h"
  10.  
  11. int
  12. pr_line(s, fout, rline)
  13. char *s;        /* buffered line of text */
  14. FILE *fout;        /* output stream */
  15. unsigned int rline;    /* file-relative line number */
  16. {
  17.     int c_cnt;    /* character position in output line */
  18.     int nlines;    /* number of lines output */
  19.     extern PRINT pcnf;
  20.  
  21.     extern int spaces(int, FILE *);    /* emit string of spaces */
  22.  
  23.     nlines = 1;
  24.     c_cnt = 0;
  25.  
  26.     /* output the left indentation, if any */
  27.     c_cnt += spaces(pcnf.p_lmarg, fout);
  28.  
  29.     /* output the line number if numbering enabled */
  30.     if (pcnf.p_lnum != 0)
  31.         c_cnt += fprintf(fout, "%6u  ", rline);
  32.  
  33.     /* output the text of the line */
  34.     while (*s != '\0') {
  35.         if (c_cnt > (pcnf.p_wid - pcnf.p_rmarg)) {
  36.             fputc('\n', fout);
  37.             ++nlines;
  38.             c_cnt = 0;
  39.             c_cnt = spaces(pcnf.p_lmarg, fout);
  40.         }
  41.         fputc(*s, fout);
  42.         ++s;
  43.         ++c_cnt;
  44.     }
  45.  
  46.     return (nlines);
  47. }
  48.