--- /dev/null
+/* A simple program that prints a single file, directly using\r
+ the Parallel Device Driver in MMURTL (Device No. 3 "LPT").\r
+ Print does perform some formatting, but it's crude.\r
+\r
+ Print File, Version 1.0\r
+ Usage: Print Filename /1 /2 /4 /8 /F /D /B\r
+ /1 /2 /4 /8 - Tab stop translation value\r
+ /F no FormFeed at end of file\r
+ /D Display file while printing\r
+ /B Binary print. NO translation, no FF\r
+\r
+ To build Print.run, Use Makeit.bat in DOS, or use CM32 and DASM:\r
+ CM32 Print.C\r
+ DASM Print.ATF\r
+*/\r
+\r
+\r
+#include <stdio.h>\r
+#include <ctype.h>\r
+#include <string.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+\r
+#include "\OSSource\MDevDrv.h"\r
+#include "\OSSource\MJob.h"\r
+#include "\OSSource\MKbd.h"\r
+#include "\OSSource\MTimer.h"\r
+#include "\OSSource\MVid.h"\r
+#include "\OSSource\Parallel.h"\r
+\r
+#define FF 0x0C\r
+#define LF 0x0A\r
+#define CR 0x0D\r
+#define TAB 0x09\r
+\r
+unsigned long key;\r
+\r
+long tabstops = 4;\r
+long NoFF = 0;\r
+long fDisplay = 0;\r
+long fBinary = 0;\r
+long col = 0;\r
+\r
+char name[80];\r
+FILE *f;\r
+\r
+struct statRecL lpt;\r
+\r
+/*****************************************************/\r
+\r
+void main(long argc, unsigned char *argv[])\r
+{\r
+long erc, erck, i, cl;\r
+unsigned char b, lastb;\r
+char fdone, *ptr;\r
+\r
+ SetJobName("Printing", 8);\r
+\r
+ name[0] = 0;\r
+\r
+ for(i=1; i < argc; ++i) /* start at arg 1 */\r
+ {\r
+ ptr = argv[i];\r
+ if (*ptr == '/')\r
+ {\r
+ ptr++;\r
+ switch(*ptr)\r
+ {\r
+ case '1' : /* Tab Translation Width */\r
+ case '2' :\r
+ case '4' :\r
+ case '8' :\r
+ tabstops = *ptr - 0x30;\r
+ break;\r
+ case 'F' : /* No FF at end of file */\r
+ case 'f' :\r
+ NoFF = 1;\r
+ break;\r
+ case 'D' : /* Display while printing */\r
+ case 'd' :\r
+ fDisplay = 1;\r
+ break;\r
+ case 'B' : /* BINARY - No translation at all! */\r
+ case 'b' :\r
+ fBinary = 1;\r
+ break;\r
+ default:\r
+ printf("Invalid switch");\r
+ exit(1);\r
+ break;\r
+ }\r
+ }\r
+ else if(!name[0])\r
+ strncpy (name, argv[i], 79);\r
+ }\r
+\r
+ if (!name[0])\r
+ {\r
+ /* Input file not explicitly named errors out */\r
+\r
+ printf("Print File, Version 1,0\r\n");\r
+ printf("Usage: Filename /1 /2 /4 /8 /F /D /B\r\n");\r
+ printf("/1 /2 /4 /8 - Tab stop translation value\r\n");\r
+ printf("/F no FormFeed at end of file\r\n");\r
+ printf("/D Display file while printing\r\n");\r
+ printf("/B Binary print. NO translation, no FF\r\n\n");\r
+ printf("Error: Source filename required\r\n");\r
+ exit(1);\r
+ }\r
+\r
+ /* Get the 64 byte device status block which is specific to the\r
+ parallel device driver. The structure is defined in parallel.h\r
+ We do this just to see if it's a valid device.\r
+ */\r
+\r
+ erc = DeviceStat(3, &lpt, 64, &i);\r
+\r
+ if (erc)\r
+ {\r
+ printf("Error getting LPT Device Status: %d\r\n", erc);\r
+ ExitJob(erc);\r
+ }\r
+\r
+ /* If device status went OK, we open the printer port */\r
+\r
+ /* device, dOpNum, dLBA, dnBlocks, pData */\r
+ erc = DeviceOp(3, CmdOpenL, 0, 0, &i);\r
+\r
+ if (erc)\r
+ {\r
+ printf("OpenLPT ERROR: %d \r\n", erc);\r
+ ExitJob(erc);\r
+ }\r
+\r
+ printf("Printing %s ...\r\n", name);\r
+\r
+ /* This is it... */\r
+\r
+ f = fopen(name, "r");\r
+\r
+ if (!f)\r
+ {\r
+ /* device, dOpNum, dLBA, dnBlocks, pData */\r
+ erc = DeviceOp(3, CmdCloseLU, 0, 0, &i);\r
+ printf("Can't open: %s\r\n", name);\r
+ ExitJob(erc);\r
+ }\r
+\r
+ col = 0;\r
+ i = 0;\r
+ b = 0;\r
+ fdone = 0;\r
+\r
+ while ((!fdone) && (!erc))\r
+ {\r
+ i++;\r
+ cl = fgetc(f);\r
+ lastb = b;\r
+ b = (cl & 0xff);\r
+\r
+ if (cl == EOF)\r
+ {\r
+ fdone = 1;\r
+ }\r
+ else if (fBinary)\r
+ {\r
+ erc = DeviceOp(3, CmdWriteB, 0, 1, &lastb);\r
+ }\r
+ else\r
+ {\r
+ switch (b)\r
+ { /* print/translate the char */\r
+ case CR:\r
+ erc = DeviceOp(3, CmdWriteB, 0, 1, &b);\r
+ break;\r
+ case LF:\r
+ if (lastb != CR)\r
+ {\r
+ lastb = CR;\r
+ erc = DeviceOp(3, CmdWriteB, 0, 1, &lastb);\r
+ }\r
+ erc = DeviceOp(3, CmdWriteB, 0, 1, &b);\r
+ if (fDisplay)\r
+ printf("\r\n", lastb);\r
+ col = 0; /* reset */\r
+ break;\r
+ case TAB:\r
+ do\r
+ {\r
+ erc = DeviceOp(3, CmdWriteB, 0, 1, " ");\r
+ col++;\r
+ if (fDisplay)\r
+ printf(" ");\r
+ } while (col % tabstops);\r
+ break;\r
+ default:\r
+ if (fDisplay)\r
+ printf("%c", b);\r
+ col++;\r
+ erc = DeviceOp(3, CmdWriteB, 0, 1, &b);\r
+ if (erc)\r
+ printf("Error Writing Byte: %d\r\n", erc);\r
+ break;\r
+ }\r
+ }\r
+\r
+ if (i%100==0) /* every 100 chars see if they want to abort */\r
+ {\r
+ erck = ReadKbd(&key, 0);\r
+ /* no wait */\r
+ if (!erck)\r
+ {\r
+ if (key & 0xff == 0x1b)\r
+ {\r
+ fdone = 1;\r
+ erc = 4;\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ if ((!fBinary) && (!NoFF))\r
+ {\r
+ erc = DeviceOp(3, CmdWriteB, 0, 1, "\f");\r
+ }\r
+\r
+ fclose(f);\r
+ /* device, dOpNum, dLBA, dnBlocks, pData */\r
+ erc = DeviceOp(3, CmdCloseL, 0, 0, &i);\r
+ if (erc)\r
+ printf("Can't close LPT. Error: %d\r\n", erc);\r
+ printf("Done\r\n");\r
+ ExitJob(erc);\r
+\r
+}\r