#include <stdio.h>#include <ctype.h>#include <string.h>#include <time.h>/* Arguments to setsoftwareiomode */#define   PSBAT_MODE        '0'#define   PSINT_MODE        '1'#define   LSJET_MODE        '5'#define   DIABL_MODE        '2'/* Arguments to setdostartpage */#define   STARTPAGE_OFF     0#define   STARTPAGE_ON      1/* Arguments to sethardwareiomode */#define   RS232_PORT        0#define   PARAL_PORT        1#define   APPLE_PORT        2#define   RS422_PORT        3#define   EOJ               4#define   ESC               27#define   DEL               127#define   ZERO              '0'void usage(void);void setsoftwareiomode(char);void Delay(int);FILE *p, *fopen();char strbuf[10];main (argc, argv)int  argc;char *argv[];{ int c; char smode; if ( argc < 2 ) {    usage(); } else {    if (argc == 3) {       for ( c = 0; c < 5; c++ )          strbuf[c] = toupper(argv[2][c]);  // convert to uppercase       strbuf[c] = '\0';       if ( !strcmp(strbuf, "LPT1" ) ||            !strcmp(strbuf, "LPT2" ) ||            !strcmp(strbuf, "COM1" ) ||            !strcmp(strbuf, "COM2" ))       ;       else {          fprintf(stderr,"\nUnknown Port %s!\n", strbuf);          fprintf(stderr,"ERROR - Please enter LPT1, LPT2, COM1 or COM2\n");          usage();          exit(1);       }    }    else       strcpy(strbuf, "LPT1");  // default to lpt1 port    // At this point we know which port the printer is connected    if ((p = fopen(strbuf, "r+w")) == NULL) {       fprintf(stderr,"ERROR - Can not open printer on %s\n",strbuf);       exit(1);    }    else       fprintf(stderr,"\nSwitching emulations on printer located at %s", strbuf);    // Check second argument for emulation switch    if ((argv[1][0] == '/') || (argv[1][0] == '-'))       switch( argv[1][1] ) {          case 's':          case 'S':                    smode = argv[1][2];                    if (((smode >= 0)&&(smode < '3'))||(smode == '5'))                       setsoftwareiomode(smode);                    else {                       fprintf(stderr,"\nERROR - Please use values 0, 1, 2, or 5 with the -s switch!\n");                       usage();                    }                    break;          default:                    fprintf(stderr,"\nERROR - Invalid switch %c!\n", argv[1][1]);                    usage();                    break;       }  /*switch */    else {       fprintf(stderr,"\nInvalid command line argument %s!\n", argv[1]);       usage();    } } /* End of else */}void usage(){    fprintf(stderr,"\nEESWITCH -s[value] <PORT> NEC PS printer remote emulation switch.\n\n");    fprintf(stderr,"-s[value]  0 = PostScript(R) Batch\n");    fprintf(stderr,"           1 = PostScript Interactive\n");    fprintf(stderr,"           2 = Diablo(R) 630\n");    fprintf(stderr,"           5 = HP LaserJet(R)\n\n");    fprintf(stderr,"<PORT>     Optional - Enter LPT1, LPT2, COM1 or COM2\n");    fprintf(stderr,"           If no entry is given LPT1 is used by default.\n\n");    fprintf(stderr,"Copyright 1989,1990 NEC Technologies, Inc. All Rights Reserved. v1.1\n");}void setsoftwareiomode(mode)char mode;{    switch (mode) {       case PSBAT_MODE:       case PSINT_MODE:       case DIABL_MODE:       case LSJET_MODE:               fprintf(stderr,"\nReturning to PostScript Batch mode...");               fprintf(p,"%c%c%cend\n", ESC, DEL, ZERO);               flushall();               fprintf(p,"Wait 2\n");               fprintf(p,"%c", EOJ);               flushall();               Delay(5);               fprintf(stderr,"\n");               if (mode != PSBAT_MODE) {                  fprintf(stderr,"Switching to %s mode...",                      (mode == PSINT_MODE) ? "PostScript Interactive" :                      (mode == DIABL_MODE) ? "Diablo 630" :                      (mode == LSJET_MODE) ? "HP LaserJet" : "INVALID ENTRY");                  fprintf(p," statusdict begin\n");                  fprintf(p," softwareiomode %c ne\n", mode);                  flushall();                  fprintf(p," { %c setsoftwareiomode}if end \n", mode);                  // fprintf(p," Wait 2\n");                  fprintf(p,"%c",EOJ);                  flushall();                  fprintf(stderr,"\n");               }               break;       default :               fprintf(stderr,"Invalid value %d used with -s switch!\n", mode);               break;    }}/*------------------------------------------------------------------------*/void Delay(secs)int secs;{   time_t t1, t2;   t1 = time(&t1);   while (difftime(time(&t2), t1) < (double)secs) continue;}/*----------------------------------------------------------------------------*/  ............