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

  1. /*
  2.    main.cpp
  3.     Copyright (c) Les Hancock 1990
  4.  
  5.     Utility for listing files to HP DeskJet printer in landscape mode.
  6.     Written in C++, compiled with Zortech 2.0.
  7.  
  8.     usage: djprint [[-]?][-n][-tx][-ofnam][-qx][-vx][-hxx] file... [file...]
  9.  
  10.         ? or -?:    show help message
  11.         -n:   no page headers (headers by default)
  12.         -tx:  expand tabs to x spaces (default 3)
  13.         -qx:  printer quality 0, 1 or 2; 0 = lowest (default 0)
  14.         -vx:  x = 6 or 8 lines per inch (default 6)
  15.         -hxx: xx = 10, 16 or 20 characters per inch (default 20);
  16.         -ofnam: output to file 'fnam' (default: LPT1)
  17.  
  18.     parms can't be stacked (separate -[option] required for each)
  19.     multiple output file specs: take only last file named
  20.    order of options/filenames isn't significant
  21.     minimal validation and error checking
  22.  
  23.     Author: Les Hancock, CIS 74156,3262
  24.     Revision history: 1.0, 2/10/1990 -- original code
  25.  
  26. */
  27.  
  28. #include <ctype.h>
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <string.h>
  32. #include <stream.hpp>
  33. #include "list.hpp"
  34. #include "parms.hpp"
  35. #include "line.hpp"
  36. #include "header.hpp"
  37. #include "page.hpp"
  38.  
  39. static void init_printer(parms& parms);
  40. static void reset_printer(parms& parms);
  41.  
  42. main(int argc, char *argv[])
  43. {
  44.     const char *ptr;
  45.     parms parms(argc, argv);             // command-line options and file names
  46.  
  47.     ostream out(&parms.fp_out);        // ...output to fp_out (file or printer)
  48.     init_printer(parms);
  49.     while ((ptr = parms.file_list.pop_file_name()) 
  50.         != (char *) 0)                    // till no more file names on the fifo
  51.     {
  52.         filebuf fp_in;                                // instantiate file object
  53.         if (fp_in.open((char *)ptr, input) == 0)           // if can't open file
  54.             cout << "can't open ";
  55.         else
  56.         {
  57.             istream in(&fp_in);           // input stream set to current file...
  58.             page pg(parms, ptr);              // create a new, blank scratch page
  59.             while (pg.eof() == no)
  60.             {
  61.                 in >> pg;                   // get page from input (sets eof flag)
  62.                 out << pg;     // send page to output (clears page for more input)
  63.             }
  64.         }
  65.         cout << ptr << '\n';        // list names of files as they're printed
  66.     }
  67.     out << chr(27) << "E";                                     // reset printer
  68. }
  69.  
  70. /*
  71.     See DeskJet Plus's owner's manual for control codes used here.
  72. */
  73. static void
  74. init_printer(parms& parms)
  75. {
  76.     ostream out(&parms.fp_out);
  77.     out << chr(27) << "E"                                      // reset printer
  78.         << chr(27) << "&l1O";                           // landscape orientation
  79.     if (parms.pq == 0)
  80.         out << chr(27) << "&k1W";                      // bidirectional printing
  81.     out << chr(27) << form("(s%.2dH", parms.cpi);                       // pitch
  82.     if (parms.pq < 2)
  83.         out << chr(27) << "(s1Q";                                 // draft quality
  84.     out << chr(27) << form("&l%.1dD", parms.lpi)               // lines per inch
  85.         << chr(27) << form("&%.2dP", parms.lpi * 85 / 10)         // page length
  86.         << chr(27) << "&l0L"                        // perforation skip mode OFF
  87.         << chr(27) << "&a0L"                                  // left margin = 0
  88.         << chr(27) << "&a196M"                               // right margin = 0
  89.         << chr(27) << "&l0E"                                   // top margin = 0
  90.         << chr(27) << form("&l%.2dF", parms.max_rows)             // text length
  91.         << chr(27) << "&k2G";                    // see page 4-47; 0xa ends line   
  92. }
  93.