home *** CD-ROM | disk | FTP | other *** search
- /*
- HEADER.CPP
- Copyright (c) Les Hancock 1990
- */
-
- #include <time.h>
- #include <stream.hpp>
- #include <string.h>
- #include "header.hpp"
-
- /*
- Except for the page number, the header is constant: same
- file name, same date (why change it for each page?), same
- blank second line.
- */
- header::header(const char *file_name, unsigned int columns)
- {
- bufptr = new char [ 2 * (cols = columns) ];
- memset(bufptr, ' ', 2 * cols);
- memcpy(bufptr, file_name, strlen(file_name));
- page_no = 0;
- time_t t; time (&t); // use library fns to get time/date
- memcpy(bufptr + cols - 24, asctime(localtime(&t)), 24);
- new_page();
- }
-
- /*
- Just bump the page number, really.
- */
- void
- header::new_page()
- {
- char page[4]; strcpy(page, dec(++page_no, 0));
- memcpy(bufptr + cols / 2 - 1, page, strlen(page));
- }
-
- /*
- Print the header to ostream.
- */
- ostream& operator<<(ostream& out, header& hdr)
- {
- for (int i = 0; i < 2; ++i)
- {
- out << ' ';
- for (int j = 0; j < hdr.cols; ++j)
- out << *(hdr.bufptr + i * hdr.cols + j);
- out << '\n';
- }
- hdr.new_page();
- return out;
- }
-