home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / LASER / DJPRNT.ZIP / HEADER.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-10  |  1.1 KB  |  52 lines

  1. /*
  2.     HEADER.CPP
  3.     Copyright (c) Les Hancock 1990
  4. */
  5.  
  6. #include <time.h>
  7. #include <stream.hpp>
  8. #include <string.h>
  9. #include "header.hpp"
  10.  
  11. /*
  12.     Except for the page number, the header is constant: same
  13.     file name, same date (why change it for each page?), same
  14.     blank second line.
  15. */
  16. header::header(const char *file_name, unsigned int columns)
  17. {
  18.     bufptr = new char [ 2 * (cols = columns) ];
  19.     memset(bufptr, ' ', 2 * cols);
  20.     memcpy(bufptr, file_name, strlen(file_name));
  21.     page_no = 0;
  22.     time_t t; time (&t);                    // use library fns to get time/date
  23.     memcpy(bufptr + cols - 24, asctime(localtime(&t)), 24);
  24.     new_page();
  25. }
  26.  
  27. /*
  28.     Just bump the page number, really.
  29. */
  30. void
  31. header::new_page()
  32. {
  33.     char page[4]; strcpy(page, dec(++page_no, 0));    
  34.     memcpy(bufptr + cols / 2 - 1, page, strlen(page));
  35. }
  36.  
  37. /*
  38.     Print the header to ostream.
  39. */
  40. ostream& operator<<(ostream& out, header& hdr)
  41. {
  42.     for (int i = 0; i < 2; ++i)
  43.     {
  44.         out << ' ';
  45.         for (int j = 0; j < hdr.cols; ++j)
  46.                 out << *(hdr.bufptr + i * hdr.cols + j);
  47.         out << '\n';
  48.     }
  49.     hdr.new_page();
  50.     return out;
  51. }
  52.