home *** CD-ROM | disk | FTP | other *** search
- /*
- main.cpp
- Copyright (c) Les Hancock 1990
-
- Utility for listing files to HP DeskJet printer in landscape mode.
- Written in C++, compiled with Zortech 2.0.
-
- usage: djprint [[-]?][-n][-tx][-ofnam][-qx][-vx][-hxx] file... [file...]
-
- ? or -?: show help message
- -n: no page headers (headers by default)
- -tx: expand tabs to x spaces (default 3)
- -qx: printer quality 0, 1 or 2; 0 = lowest (default 0)
- -vx: x = 6 or 8 lines per inch (default 6)
- -hxx: xx = 10, 16 or 20 characters per inch (default 20);
- -ofnam: output to file 'fnam' (default: LPT1)
-
- parms can't be stacked (separate -[option] required for each)
- multiple output file specs: take only last file named
- order of options/filenames isn't significant
- minimal validation and error checking
-
- Author: Les Hancock, CIS 74156,3262
- Revision history: 1.0, 2/10/1990 -- original code
-
- */
-
- #include <ctype.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stream.hpp>
- #include "list.hpp"
- #include "parms.hpp"
- #include "line.hpp"
- #include "header.hpp"
- #include "page.hpp"
-
- static void init_printer(parms& parms);
- static void reset_printer(parms& parms);
-
- main(int argc, char *argv[])
- {
- const char *ptr;
- parms parms(argc, argv); // command-line options and file names
-
- ostream out(&parms.fp_out); // ...output to fp_out (file or printer)
- init_printer(parms);
- while ((ptr = parms.file_list.pop_file_name())
- != (char *) 0) // till no more file names on the fifo
- {
- filebuf fp_in; // instantiate file object
- if (fp_in.open((char *)ptr, input) == 0) // if can't open file
- cout << "can't open ";
- else
- {
- istream in(&fp_in); // input stream set to current file...
- page pg(parms, ptr); // create a new, blank scratch page
- while (pg.eof() == no)
- {
- in >> pg; // get page from input (sets eof flag)
- out << pg; // send page to output (clears page for more input)
- }
- }
- cout << ptr << '\n'; // list names of files as they're printed
- }
- out << chr(27) << "E"; // reset printer
- }
-
- /*
- See DeskJet Plus's owner's manual for control codes used here.
- */
- static void
- init_printer(parms& parms)
- {
- ostream out(&parms.fp_out);
- out << chr(27) << "E" // reset printer
- << chr(27) << "&l1O"; // landscape orientation
- if (parms.pq == 0)
- out << chr(27) << "&k1W"; // bidirectional printing
- out << chr(27) << form("(s%.2dH", parms.cpi); // pitch
- if (parms.pq < 2)
- out << chr(27) << "(s1Q"; // draft quality
- out << chr(27) << form("&l%.1dD", parms.lpi) // lines per inch
- << chr(27) << form("&%.2dP", parms.lpi * 85 / 10) // page length
- << chr(27) << "&l0L" // perforation skip mode OFF
- << chr(27) << "&a0L" // left margin = 0
- << chr(27) << "&a196M" // right margin = 0
- << chr(27) << "&l0E" // top margin = 0
- << chr(27) << form("&l%.2dF", parms.max_rows) // text length
- << chr(27) << "&k2G"; // see page 4-47; 0xa ends line
- }
-