home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / s / snip1292.zip / ASSIGNPR.C < prev    next >
C/C++ Source or Header  |  1991-09-14  |  2KB  |  55 lines

  1. /*
  2. **  ASSIGNPR.C
  3. **
  4. **  Multiple printer support with default to a single printer
  5. **  connected to the PRN device.
  6. **
  7. **  Original Copyright 1988-1991 by Bob Stout as part of
  8. **  the MicroFirm Function Library (MFL)
  9. **
  10. **  This subset version is functionally identical to the
  11. **  version originally published by the author in Tech Specialist
  12. **  magazine and is hereby donated to the public domain.
  13. */
  14.  
  15. #include <stdio.h>
  16.  
  17. #define NUM_OF_PRNTRS 6
  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 cdecl 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 DEBUG                                    /* 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. }
  55.