home *** CD-ROM | disk | FTP | other *** search
- /*
- +--------------------------------------------------------+
- | SWPRT.C - sets printer port assignments for IBM PC |
- | R. Trevithick Last modified: 12/24/87 |
- +--------------------------------------------------------+
- */
-
- #include <stdio.h>
- #include <dos.h>
-
- #define PSEG 64 /* Printer table segment */
- #define PRN1 8 /* Printer 1 offset */
- #define PRN2 10 /* Printer 2 offset */
- #define PRN3 12 /* Printer 3 offset */
-
- FILE *msg; /* messages to user */
-
- int p1, p2, p3, new_port = 0;
-
-
- /* Function prototypes */
- void read_values(void), swap(int a, int b), normalize(void), set(void);
- void end_prog(int code), help_screen(void);
-
-
- main(int argc, char *argv[])
- {
- int i;
-
- msg = stderr; /* default to showing messages */
-
- for (i = 1; i < argc; i++) {
- if (argv[i][0] == '/') {
- if (tolower(argv[i][1]) == 'q')
- msg = NULL;
- else
- if (argv[i][1] > 0x30 && argv[i][1] < 0x34)
- new_port = argv[i][1];
- }
- }
-
- if (new_port == 0) help_screen();
-
- normalize();
- set();
- end_prog(0);
- }
-
-
-
- /********** set the requested printer by switching it with LPT1 ******/
- void set(void)
- {
- if (new_port == '1') return; /* already set by normalize */
- if (new_port == '2') swap(PRN1, PRN2);
- if (new_port == '3') swap(PRN1, PRN3);
- }
-
-
-
-
- /********** normalize all printer assignments ******************/
- void normalize(void)
- {
- read_values();
- if (p2 > p1) swap(PRN1, PRN2);
- read_values();
- if (p3 > p2) swap(PRN2, PRN3);
- read_values();
- if (p2 > p1) swap(PRN1, PRN2);
- }
-
-
-
-
- /********** swap the two addresses received ********************/
- void swap(int offset_1, int offset_2)
- {
- int temp1, temp2;
-
- temp1 = peek(PSEG, offset_1);
- temp2 = peek(PSEG, offset_2);
-
- poke(PSEG, offset_1, temp2);
- poke(PSEG, offset_2, temp1);
- }
-
-
-
-
- /********** read the actual port assignments *******************/
- void read_values(void)
- {
- p1 = peek(PSEG, PRN1);
- p2 = peek(PSEG, PRN2);
- p3 = peek(PSEG, PRN3);
- }
-
-
-
- /********** report the current printer assignment **************/
- void end_prog(code)
- int code;
- {
- read_values();
- fputs("\n---LPT1 output routed to parallel port #", msg);
- if (p1 > p2 && p2 >= p3) fputs("1 -normal", msg);
- if (p2 > p1 && p2 >= p3) fputs("2", msg);
- if (p3 > p1 && p3 >= p2) fputs("3", msg);
- fputs("\n", msg);
- _exit(code);
- }
-
-
-
- /********** display a help screen and call exit routine *********/
- void help_screen(void)
- {
- fputs("\nSWPRT - switch printer ports 12/24/87 R. Trevithick"
- "\r\n\n\tSWPRT [/1] [/2] [/3] [/q]\n\n"
- "\t/1 route LPT1 output normally\n"
- "\t/2 route LPT1 output to parallel port #2\n"
- "\t/3 route LPT1 output to parallel port #3\n"
- "\t/q quiet; suppress all messages\n", msg);
- end_prog(1);
- }
-
-