home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / ASSIGNPR.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  2KB  |  58 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  ASSIGNPR.C
  5. **
  6. **  Multiple printer support with default to a single printer
  7. **  connected to the PRN device.
  8. **
  9. **  Original Copyright 1988-1991 by Bob Stout as part of
  10. **  the MicroFirm Function Library (MFL)
  11. **
  12. **  The user is granted a free limited license to use this source file
  13. **  to create royalty-free programs, subject to the terms of the
  14. **  license restrictions specified in the LICENSE.MFL file.
  15. */
  16.  
  17. #include "sniprint.h"
  18.  
  19. FILE *printer[NUM_OF_PRNTRS] = {stdprn};
  20.  
  21. /*
  22. **  assign_printer()
  23. **
  24. **  Call with printer number and device name
  25. **
  26. **     printer number should be in the range of 0 to NUM_OF_PRNTRS-1
  27. **     device should be "LPT1", "LPT2", "LPT3", "COM1", COM2", or a log file
  28. **
  29. **  Returns 0 if successful, -1 if error
  30. **
  31. **  Then do all printer output with fprintf(), fputs(), fputc(), etc.
  32. **  using printer[printer_number] as the output stream
  33. */
  34.  
  35. int assign_printer(int number, char *device)
  36. {
  37.       FILE *fp;
  38.  
  39.       if (NUM_OF_PRNTRS <= number || NULL == (fp = fopen(device, "w")))
  40.             return -1;
  41.       printer[number] = fp;
  42.       return 0;
  43. }
  44.  
  45. #ifdef TEST                                     /* Test code follows    */
  46.  
  47. main()
  48. {                                       /* Leave printer[0] = stdprn    */
  49.       assign_printer(1, "CON");         /* Set printer[1] to the screen */
  50.       assign_printer(2, "p.log");       /* Set printer[2] to log file   */
  51.       fputs("This is a printer test\n", printer[0]);
  52.       fputs("This is a screen test\n", printer[1]);
  53.       fputs("This is a log test\n", printer[2]);
  54.       return 0;
  55. }
  56.  
  57. #endif /* TEST */
  58.