From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/CONTRIB/SNIP/assignpr.c | 56 +++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 reference/C/CONTRIB/SNIP/assignpr.c (limited to 'reference/C/CONTRIB/SNIP/assignpr.c') diff --git a/reference/C/CONTRIB/SNIP/assignpr.c b/reference/C/CONTRIB/SNIP/assignpr.c new file mode 100755 index 0000000..45fac83 --- /dev/null +++ b/reference/C/CONTRIB/SNIP/assignpr.c @@ -0,0 +1,56 @@ +/* +** ASSIGNPR.C +** +** Multiple printer support with default to a single printer +** connected to the PRN device. +** +** Original Copyright 1988-1991 by Bob Stout as part of +** the MicroFirm Function Library (MFL) +** +** This subset version is functionally identical to the +** version originally published by the author in Tech Specialist +** magazine and is hereby donated to the public domain. +*/ + +#include + +#define NUM_OF_PRNTRS 6 + +FILE *printer[NUM_OF_PRNTRS] = {stdprn}; + +/* +** assign_printer() +** +** Call with printer number and device name +** +** printer number should be in the range of 0 to NUM_OF_PRNTRS-1 +** device should be "LPT1", "LPT2", "LPT3", "COM1", COM2", or a log file +** +** Returns 0 if successful, -1 if error +** +** Then do all printer output with fprintf(), fputs(), fputc(), etc. +** using printer[printer_number] as the output stream +*/ + +int cdecl assign_printer(int number, char *device) +{ + FILE *fp; + + if (NUM_OF_PRNTRS <= number || NULL == (fp = fopen(device, "w"))) + return -1; + printer[number] = fp; + return 0; +} + +#ifdef TEST /* Test code follows */ + +main() +{ /* Leave printer[0] = stdprn */ + assign_printer(1, "CON"); /* Set printer[1] to the screen */ + assign_printer(2, "p.log"); /* Set printer[2] to log file */ + fputs("This is a printer test\n", printer[0]); + fputs("This is a screen test\n", printer[1]); + fputs("This is a log test\n", printer[2]); +} + +#endif /* TEST */ -- cgit v1.2.3-54-g00ecf