home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / SOURCE / IBMLIB / PR_HANDL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-10  |  4.0 KB  |  240 lines

  1. /*********************
  2.  *
  3.  *  pr_handl.c - printer routines for the PC.
  4.  *
  5.  *  Purpose: This file contains the functions to print output to the
  6.  *           standard printer device.
  7.  *
  8.  *  Blackstar C Function Library
  9.  *  (c) Copyright 1985,1989 Sterling Castle Software
  10.  *
  11.  *******/
  12.  
  13. #include "blackstr.h"
  14. #include "sy_head.h"
  15. #include "pr_head.h"
  16. #include "pr_defs.h"
  17. #include "sc_head.h"
  18.  
  19.  
  20. /********
  21.  *
  22.  *   pr_putc(c) - raw character print
  23.  *
  24.  **/
  25.  
  26. int pr_putc(char c)
  27. {
  28.     return(pr_putc_(c));
  29. }
  30.  
  31.  
  32. /********
  33.  *
  34.  *   pr_putch(c) - print a character on standard out
  35.  *
  36.  **/
  37.  
  38. int pr_putch(char c)
  39. {
  40.     while((!pr_stat()) || (!pr_putc_(c))) {
  41.     if(!pr_pause())         /* try to continue if not ready */
  42.         return(FALSE);
  43.     }
  44.     return(TRUE);
  45. }
  46.  
  47.  
  48. /********
  49.  *
  50.  *   pr_puts(str) - print a string
  51.  *
  52.  **/
  53.  
  54. int pr_puts(char *str)
  55. {
  56.     char *p;
  57.  
  58.     for (p=str; *p!=NUL; p++) {
  59.     if(!pr_putch(*p))
  60.         return(FALSE);  /* printer not ready */
  61.     }
  62.     return(TRUE);
  63. }
  64.  
  65.  
  66. /********
  67.  *
  68.  *   pr_putl(buff) - print a line of text
  69.  *
  70.  **/
  71.  
  72. int pr_putl(char *buff)
  73. {
  74.     char *l;
  75.  
  76.     for(l=buff; (*l!='\0')&&(*l!=LF); l++) {
  77.     if((l-buff ) > MAX_PL)
  78.         break;
  79.     if(!pr_putch(*l))
  80.         return(FALSE);
  81.     }
  82.     if(!pr_putch(CR))
  83.     return(FALSE);
  84.     else if(!pr_putch(NEWLINE))
  85.     return(FALSE);
  86.     return(TRUE);                   /* everything went ok */
  87. }
  88.  
  89.  
  90. /********
  91.  *
  92.  *   pr_prtscr() - print the current screen
  93.  *
  94.  **/
  95.  
  96. void pr_prtscr(void)
  97. {
  98.     int ocol,orow,i,j;
  99.  
  100.     /* First, make sure the printer is ready */
  101.  
  102.     while(!pr_stat()) {
  103.     if(kb_hit())            /* to abort, hit any key */
  104.         return;
  105.     }
  106.     ocol = sc_col_;                 /* save previous cursor */
  107.     orow = sc_row_;
  108.     for(i = rowst_; i<=rowen_; i++) {
  109.     for(j=colst_; j<colen_; ++j)
  110.         if(!pr_putch(sc_getch(j,i)))
  111.         break;          /* if printer gets busy */
  112.     pr_puts("\r\n");
  113.     }
  114.     sc_setcur(ocol,orow);           /* restore cursor */
  115.     pr_putff();                     /* just do form feed */
  116. }
  117.  
  118.  
  119. /********
  120.  *
  121.  *   pr_signal(on) - set up printer interrupt service
  122.  *
  123.  **/
  124.  
  125. void pr_signal(int on)
  126. {
  127.     extern pr_prtsc_();
  128.     extern int dos_prvec_[2];
  129.  
  130.     if(on) {
  131.     sy_getintv(IPRINT,dos_prvec_);  /*save dos vector */
  132.     sy_setintf(IPRINT,pr_prtsc_);   /* set like a c function */
  133.     }
  134.     else
  135.     sy_setintv(IPRINT,dos_prvec_);  /* back to dos */
  136. }
  137.  
  138.  
  139. /********
  140.  *
  141.  *   pr_putff() - print a form feed
  142.  *
  143.  **/
  144.  
  145. void pr_putff(void)
  146. {
  147.     pr_putch(FORMF);
  148. }
  149.  
  150.  
  151. /********
  152.  *
  153.  *   pr_stat() - printer ready routine
  154.  *
  155.  **/
  156.  
  157. int pr_stat(void)
  158. {
  159.     int pstat;
  160.  
  161.     pstat = pr_stat_(0,2); /* get printer status */
  162.     if((pstat & 0x20)      /* out of paper */
  163.       || (pstat & 0x08)    /* i/o error */
  164.       || (!(pstat & 0x10)) /* not selected */
  165.       || (pstat & 0x01))   /* time out */
  166.     return(FALSE);
  167.     else
  168.     return(TRUE);      /* printer is ready */
  169. }
  170.  
  171.  
  172. /********
  173.  *
  174.  *   pr_init(prtype) - initialize printer
  175.  *
  176.  **/
  177.  
  178. void pr_init(int prtype)
  179. {
  180.     extern char *prattr_,*prtabs_,*tprattr_[],*tprtabs_[];
  181.  
  182.     prattr_ = tprattr_[prtype];
  183.     prtabs_ = tprtabs_[prtype];
  184. }
  185.  
  186.  
  187. /********
  188.  *
  189.  *   pr_attr(type) - return printer attribute string pointer
  190.  *
  191.  **/
  192.  
  193. char *pr_attr(int type)
  194. {
  195.     extern char *prattr_;
  196.  
  197.     return(prattr_+(type*3));
  198. }
  199.  
  200. /********
  201.  *
  202.  *   pr_sattr(type) - setup printer for type
  203.  *
  204.  **/
  205.  
  206. void pr_sattr(int type)
  207. {
  208.     extern char *prattr_;
  209.  
  210.     type*= 3;                       /* 2 bytes per type */
  211.     pr_putch(prattr_[type++]);
  212.     pr_putch(prattr_[type]);        /* 2 bytes of output */
  213. }
  214.  
  215. /********
  216.  *
  217.  *   pr_tabs() - return string for printer tabs
  218.  *
  219.  **/
  220.  
  221. char *pr_tabs(void)
  222. {
  223.     extern char *prtabs_;
  224.  
  225.     return(prtabs_);
  226. }
  227.  
  228.  
  229. /********
  230.  *
  231.  *   pr_pause() - printer paused
  232.  *
  233.  **/
  234.  
  235. int pr_pause(void)
  236. {
  237.     sc_puts("\nPrinter is not ready -- push any key to continue, [ESC] to stop.");
  238.     return ((kb_getc()==ESC)? FALSE : TRUE);
  239. }
  240.