FPRINT.CPP
上传用户:xr_qian
上传日期:2007-01-05
资源大小:443k
文件大小:5k
源码类别:

通讯/手机编程

开发平台:

DOS

  1. // ******************************************************************** //
  2. //                                                                      //
  3. //      FPRINT.CPP                                                      //
  4. //      Copyright (c) 1993, Michael Holmes and Bob Flanders             //
  5. //      C++ Communication Utilities                                     //
  6. //                                                                      //
  7. //      This file contains the routines under the PRINT main            //
  8. //      menu entry.                                                     //
  9. //                                                                      //
  10. // ******************************************************************** //
  11. /* ******************************************************************** *
  12.  *
  13.  *  f_lpt() -- format and print the fax to a printer
  14.  *
  15.  * ******************************************************************** */
  16. int     f_lpt(int c, int r,                 // column and row
  17.               int pn)                       // printer number
  18. {
  19. int     i, j, k, l,                         // loop counters
  20.         qf = 0;                             // quit flag
  21. char    huge *p, huge *q,                   // work pointer
  22.         buf[128];                           // ..and work buffer
  23. Window  p_win(c, r,                         // define temporary window
  24.             c + 40, r + 4,                  // ..to hold message
  25.             menu_cn, menu_cr);              // ..using system colors
  26. int     f;                                  // printer file number
  27. if (f_handle == -1)                         // q. file open?
  28.     return(ESC);                            // a. no .. just return
  29. p_win.Open(double_line);                    // open window with a border
  30. p_win.Display(print_msg);                   // give filename prompt
  31. sprintf(buf, "LPT%d", pn);                  // build printer name
  32. f = open(buf, O_WRONLY | O_BINARY);         // open file for binary output
  33. for (i = 1; f_read_g3(i) == 0 &&            // for each page..
  34.             NOT qf; i++)
  35.     {
  36.     sprintf(buf, page_msg, i, f_pgcnt);     // format page status
  37.     p_win.Display(buf);                     // ..and keep user informed
  38.     sprintf(buf, ESC_CHAR "E"               // reset printer
  39.                  ESC_CHAR "*p336x450Y"      // position printer cursor
  40.                  ESC_CHAR "*t300R"          // 300 dots per inch
  41.                  ESC_CHAR "*r0F"            // specify orientation
  42.                  ESC_CHAR "*r1A");          // start raster graphics
  43.     _write(f, buf, strlen(buf));            // ..write the line
  44.     for (j = 0, p = page; j < LINES;        // for each line
  45.                 j++, p += LINE)             // ..in the bitmap
  46.         {
  47.         for (k = LINE, q = &p[k-1];         // starting at the end of line
  48.                 k > 1 && NOT *q; k--, q--)  // ..and working backwards
  49.             ;                               // ..look for non-null data
  50.         sprintf(buf, ESC_CHAR "*b%dW", k);  // give graphic command
  51.         _write(f, buf, strlen(buf));        // ..send to the printer
  52.         l = _write(f, p, k);                // ..and print the data line
  53.         assert(l == k);
  54.         sprintf(buf, ESC_CHAR "*b%dW", k);  // give graphic command
  55.         _write(f, buf, strlen(buf));        // ..send to the printer
  56.         l = _write(f, p, k);                // ..and print the data line
  57.         assert(l == k);
  58.         if (get_key(ALLOW_ALT))             // q. key hit?
  59.             {
  60.             qf = 1;                         // a. yes .. set quit flag
  61.             break;                          // ..and exit loop
  62.             }
  63.         }
  64.     sprintf(buf, ESC_CHAR "*rB");           // end graphic mode
  65.     _write(f, buf, strlen(buf));            // ..write the line
  66.     }
  67. sprintf(buf, ESC_CHAR "E");                 // re-initialize printer
  68. _write(f, buf, strlen(buf));                // ..write the line
  69. close(f);                                   // ..and close file
  70. return(ESC);                                // finally, rtn to caller
  71. }
  72. /* ******************************************************************** *
  73.  *
  74.  *  f_lpt1() -- print the fax to LPT1:
  75.  *
  76.  * ******************************************************************** */
  77. int     f_lpt1(int c, int r)                // column and row
  78. {
  79. f_lpt(c, r, 1);                             // print on LPT1:
  80. return(ESC);                                // ..and return to menu
  81. }
  82. /* ******************************************************************** *
  83.  *
  84.  *  f_lpt2() -- print the fax to LPT2:
  85.  *
  86.  * ******************************************************************** */
  87. int     f_lpt2(int c, int r)                // column and row
  88. {
  89. f_lpt(c, r, 2);                             // print on LPT2:
  90. return(ESC);                                // ..and return to menu
  91. }
  92. /* ******************************************************************** *
  93.  *
  94.  *  f_lpt3() -- print the fax to LPT3:
  95.  *
  96.  * ******************************************************************** */
  97. int     f_lpt3(int c, int r)                // column and row
  98. {
  99. f_lpt(c, r, 3);                             // print on LPT3:
  100. return(ESC);                                // ..and return to menu
  101. }